0026411: Necessary to improve XCAF to store and querying GD&T data.
[occt.git] / src / AIS / AIS_Relation.cxx
CommitLineData
b311480e 1// Created on: 1996-12-05
2// Created by: Odile Olivier
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
42cf5bc1 18#include <AIS.hxx>
7fd59977 19#include <AIS_GraphicTool.hxx>
42cf5bc1 20#include <AIS_Relation.hxx>
7fd59977 21#include <BRep_Tool.hxx>
42cf5bc1 22#include <BRepBuilderAPI_MakeEdge.hxx>
23#include <BRepBuilderAPI_MakeVertex.hxx>
24#include <ElCLib.hxx>
25#include <Geom_CartesianPoint.hxx>
7fd59977 26#include <Geom_Circle.hxx>
42cf5bc1 27#include <Geom_Curve.hxx>
7fd59977 28#include <Geom_Line.hxx>
42cf5bc1 29#include <Geom_Plane.hxx>
30#include <Geom_Surface.hxx>
31#include <gp_Circ.hxx>
32#include <gp_Lin.hxx>
33#include <gp_Pnt.hxx>
34#include <Graphic3d_Group.hxx>
35#include <Precision.hxx>
36#include <Prs3d_DimensionAspect.hxx>
6262338c 37#include <Prs3d_Drawer.hxx>
7fd59977 38#include <Prs3d_LineAspect.hxx>
7fd59977 39#include <Prs3d_PointAspect.hxx>
42cf5bc1 40#include <Prs3d_Presentation.hxx>
7fd59977 41#include <Prs3d_TextAspect.hxx>
42cf5bc1 42#include <Quantity_Color.hxx>
43#include <Standard_Type.hxx>
7fd59977 44#include <StdPrs_Point.hxx>
42cf5bc1 45#include <StdPrs_WFDeflectionShape.hxx>
46#include <TCollection_ExtendedString.hxx>
47#include <TopExp.hxx>
7fd59977 48#include <TopoDS.hxx>
49#include <TopoDS_Edge.hxx>
42cf5bc1 50#include <TopoDS_Shape.hxx>
51#include <TopoDS_Vertex.hxx>
7fd59977 52
53//=======================================================================
54//function : AIS_Relation
55//purpose :
56//=======================================================================
57AIS_Relation::AIS_Relation(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d)
58:AIS_InteractiveObject(aTypeOfPresentation3d),
59 myVal(1.),
60 myPosition(0.,0.,0.),
7fd59977 61 myArrowSize( myVal / 10. ),
7fd59977 62 myAutomaticPosition(Standard_True),
63 myExtShape(0),
64 myFirstOffset(0.),mySecondOffset(0.),
d2094e11 65 myIsSetBndBox( Standard_False ),
66 myArrowSizeIsDefined( Standard_False)
7fd59977 67{
68}
69
70
71
72//=======================================================================
73//function : ComputeProjEdgePresentation
74//purpose :
75//=======================================================================
76
77void AIS_Relation::ComputeProjEdgePresentation(const Handle(Prs3d_Presentation)& aPrs,
78 const TopoDS_Edge& anEdge,
79 const Handle(Geom_Curve)& ProjCurv,
80 const gp_Pnt& FirstP,
81 const gp_Pnt& LastP,
82 const Quantity_NameOfColor aColor,
83 const Standard_Real width,
84 const Aspect_TypeOfLine aProjTOL,
85 const Aspect_TypeOfLine aCallTOL) const
86{
6262338c 87 if (!myDrawer->HasOwnWireAspect()){
7fd59977 88 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aProjTOL,2.));}
89 else {
90 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
91 li->SetColor(aColor);
92 li->SetTypeOfLine(aProjTOL);
93 li->SetWidth(width);
94 }
95
96 Standard_Real pf, pl;
97 TopLoc_Location loc;
98 Handle(Geom_Curve) curve;
99 Standard_Boolean isInfinite;
100 curve = BRep_Tool::Curve(anEdge,loc,pf,pl);
101 isInfinite = (Precision::IsInfinite(pf) || Precision::IsInfinite(pl));
102
103 TopoDS_Edge E;
104
105 // Calcul de la presentation de l'edge
106 if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
c5f3a425 107 Handle(Geom_Line) gl (Handle(Geom_Line)::DownCast (ProjCurv));
7fd59977 108 if ( !isInfinite) {
109 pf = ElCLib::Parameter(gl->Lin(),FirstP);
110 pl = ElCLib::Parameter(gl->Lin(),LastP);
111 BRepBuilderAPI_MakeEdge MakEd(gl->Lin(), pf, pl);
112 E = MakEd.Edge();
113 }
114 else {
115 BRepBuilderAPI_MakeEdge MakEd(gl->Lin());
116 E = MakEd.Edge();
117 }
118 }
119 else if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
c5f3a425 120 Handle(Geom_Circle) gc (Handle(Geom_Circle)::DownCast (ProjCurv));
7fd59977 121 pf = ElCLib::Parameter(gc->Circ(),FirstP);
122 pl = ElCLib::Parameter(gc->Circ(),LastP);
123 BRepBuilderAPI_MakeEdge MakEd(gc->Circ(),pf, pl);
124 E = MakEd.Edge();
125 }
126 StdPrs_WFDeflectionShape::Add(aPrs, E, myDrawer);
127
128 //Calcul de la presentation des lignes de raccord
129 myDrawer->WireAspect()->SetTypeOfLine(aCallTOL);
130 if (!isInfinite) {
131 gp_Pnt ppf, ppl;
132 ppf = BRep_Tool::Pnt( TopExp::FirstVertex(TopoDS::Edge(anEdge)));
133 ppl = BRep_Tool::Pnt( TopExp::LastVertex(TopoDS::Edge(anEdge)));
134 if (FirstP.Distance( ppf ) > gp::Resolution())
135 {
136 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
137 StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer);
138 }
139 else
140 {
141 BRepBuilderAPI_MakeVertex MakVert1( FirstP );
142 StdPrs_WFDeflectionShape::Add(aPrs, MakVert1.Vertex(), myDrawer);
143 }
144 if (LastP.Distance( ppl ) > gp::Resolution())
145 {
146 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
147 StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer);
148 }
149 else
150 {
151 BRepBuilderAPI_MakeVertex MakVert2( LastP );
152 StdPrs_WFDeflectionShape::Add(aPrs, MakVert2.Vertex(), myDrawer);
153 }
154/*
155 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
156 StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer);
157 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
158 StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer);
159*/
160 }
161}
162
163
164//=======================================================================
165//function : ComputeProjVertexPresentation
166//purpose :
167//=======================================================================
168
169void AIS_Relation::ComputeProjVertexPresentation(const Handle(Prs3d_Presentation)& aPrs,
170 const TopoDS_Vertex& aVertex,
171 const gp_Pnt& ProjPoint,
172 const Quantity_NameOfColor aColor,
173 const Standard_Real width,
174 const Aspect_TypeOfMarker aProjTOM,
175 const Aspect_TypeOfLine aCallTOL) const
176{
6262338c 177 if (!myDrawer->HasOwnPointAspect()){
7fd59977 178 myDrawer->SetPointAspect(new Prs3d_PointAspect(aProjTOM, aColor,1));}
179 else {
180 const Handle(Prs3d_PointAspect)& pa = myDrawer->PointAspect();
181 pa->SetColor(aColor);
182 pa->SetTypeOfMarker(aProjTOM);
183 }
184
185 // calcul du projete
186 StdPrs_Point::Add(aPrs, new Geom_CartesianPoint(ProjPoint), myDrawer);
187
6262338c 188 if (!myDrawer->HasOwnWireAspect()){
7fd59977 189 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aCallTOL,2.));}
190 else {
191 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
192 li->SetColor(aColor);
193 li->SetTypeOfLine(aCallTOL);
194 li->SetWidth(width);
195 }
196
197 // Si les points ne sont pas confondus...
198 if (!ProjPoint.IsEqual (BRep_Tool::Pnt(aVertex),Precision::Confusion())) {
199 // calcul des lignes de rappel
200 BRepBuilderAPI_MakeEdge MakEd(ProjPoint,BRep_Tool::Pnt(aVertex));
201 StdPrs_WFDeflectionShape::Add(aPrs, MakEd.Edge(), myDrawer);
202 }
203}
204
205//=======================================================================
206//function : SetColor
207//purpose :
208//=======================================================================
209
210void AIS_Relation::SetColor(const Quantity_NameOfColor aCol)
7fd59977 211{
212 SetColor(Quantity_Color(aCol));
213}
214
215void AIS_Relation::SetColor(const Quantity_Color &aCol)
7fd59977 216{
217 if(hasOwnColor && myOwnColor==aCol) return;
218
6262338c 219 if (!myDrawer->HasOwnTextAspect()) myDrawer->SetTextAspect(new Prs3d_TextAspect());
7fd59977 220 hasOwnColor=Standard_True;
221 myOwnColor=aCol;
222 myDrawer->TextAspect()->SetColor(aCol);
223
6262338c 224 Standard_Real WW = HasWidth()? Width(): myDrawer->HasLink() ?
225 AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.;
226 if (!myDrawer->HasOwnLineAspect()) {
7fd59977 227 myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
228 }
6262338c 229 if (!myDrawer->HasOwnDimensionAspect()) {
a6eb515f 230 myDrawer->SetDimensionAspect(new Prs3d_DimensionAspect);
7fd59977 231 }
a6eb515f 232
7fd59977 233 myDrawer->LineAspect()->SetColor(aCol);
a6eb515f 234 const Handle(Prs3d_DimensionAspect)& DIMENSION = myDrawer->DimensionAspect();
7fd59977 235 const Handle(Prs3d_LineAspect)& LINE = myDrawer->LineAspect();
236 const Handle(Prs3d_TextAspect)& TEXT = myDrawer->TextAspect();
237
a6eb515f 238 DIMENSION->SetLineAspect(LINE);
239 DIMENSION->SetTextAspect(TEXT);
7fd59977 240}
241
242//=======================================================================
243//function : UnsetColor
244//purpose :
245//=======================================================================
246void AIS_Relation::UnsetColor()
247{
248 if (!hasOwnColor) return;
249 hasOwnColor = Standard_False;
250 const Handle(Prs3d_LineAspect)& LA = myDrawer->LineAspect();
6262338c 251 Quantity_Color CC = Quantity_NOC_YELLOW;
252 if (myDrawer->HasLink())
253 {
254 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
255 myDrawer->SetTextAspect(myDrawer->Link()->TextAspect());
256 }
7fd59977 257 LA->SetColor(CC);
a6eb515f 258 myDrawer->DimensionAspect()->SetLineAspect(LA);
7fd59977 259}
260
261//=======================================================================
262//function : AcceptDisplayMode
263//purpose :
264//=======================================================================
265
266 Standard_Boolean AIS_Relation::
267AcceptDisplayMode(const Standard_Integer aMode) const
268{return aMode == 0;}
269
270
271//=======================================================================
272//function : SetFirstShape
273//purpose :
274//=======================================================================
275
276void AIS_Relation::SetFirstShape(const TopoDS_Shape& aFShape)
277{
278 myFShape = aFShape;
279}
280
281
282//=======================================================================
283//function : SetSecondShape
284//purpose :
285//=======================================================================
286
287void AIS_Relation::SetSecondShape(const TopoDS_Shape& aSShape)
288{
289 mySShape = aSShape;
290}
291
292//=======================================================================
293//function : KindOfDimension
294//purpose :
295//=======================================================================
296AIS_KindOfDimension AIS_Relation::KindOfDimension() const
297{return AIS_KOD_NONE;}
298
299//=======================================================================
300//function : IsMovable
301//purpose :
302//=======================================================================
303Standard_Boolean AIS_Relation::IsMovable() const
304{return Standard_False;}
305
306