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> |
bf5f0ca2 |
31 | #include <Graphic3d_ArrayOfSegments.hxx> |
42cf5bc1 |
32 | #include <gp_Circ.hxx> |
33 | #include <gp_Lin.hxx> |
34 | #include <gp_Pnt.hxx> |
35 | #include <Graphic3d_Group.hxx> |
36 | #include <Precision.hxx> |
37 | #include <Prs3d_DimensionAspect.hxx> |
6262338c |
38 | #include <Prs3d_Drawer.hxx> |
7fd59977 |
39 | #include <Prs3d_LineAspect.hxx> |
7fd59977 |
40 | #include <Prs3d_PointAspect.hxx> |
42cf5bc1 |
41 | #include <Prs3d_Presentation.hxx> |
7fd59977 |
42 | #include <Prs3d_TextAspect.hxx> |
42cf5bc1 |
43 | #include <Quantity_Color.hxx> |
44 | #include <Standard_Type.hxx> |
7fd59977 |
45 | #include <StdPrs_Point.hxx> |
5ad8c033 |
46 | #include <StdPrs_WFShape.hxx> |
42cf5bc1 |
47 | #include <TCollection_ExtendedString.hxx> |
48 | #include <TopExp.hxx> |
7fd59977 |
49 | #include <TopoDS.hxx> |
50 | #include <TopoDS_Edge.hxx> |
42cf5bc1 |
51 | #include <TopoDS_Shape.hxx> |
52 | #include <TopoDS_Vertex.hxx> |
7fd59977 |
53 | |
92efcf78 |
54 | IMPLEMENT_STANDARD_RTTIEXT(AIS_Relation,AIS_InteractiveObject) |
55 | |
7fd59977 |
56 | //======================================================================= |
57 | //function : AIS_Relation |
58 | //purpose : |
59 | //======================================================================= |
60 | AIS_Relation::AIS_Relation(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d) |
61 | :AIS_InteractiveObject(aTypeOfPresentation3d), |
62 | myVal(1.), |
63 | myPosition(0.,0.,0.), |
7fd59977 |
64 | myArrowSize( myVal / 10. ), |
7fd59977 |
65 | myAutomaticPosition(Standard_True), |
66 | myExtShape(0), |
67 | myFirstOffset(0.),mySecondOffset(0.), |
d2094e11 |
68 | myIsSetBndBox( Standard_False ), |
69 | myArrowSizeIsDefined( Standard_False) |
7fd59977 |
70 | { |
71 | } |
72 | |
73 | |
74 | |
75 | //======================================================================= |
76 | //function : ComputeProjEdgePresentation |
77 | //purpose : |
78 | //======================================================================= |
79 | |
80 | void AIS_Relation::ComputeProjEdgePresentation(const Handle(Prs3d_Presentation)& aPrs, |
81 | const TopoDS_Edge& anEdge, |
82 | const Handle(Geom_Curve)& ProjCurv, |
83 | const gp_Pnt& FirstP, |
84 | const gp_Pnt& LastP, |
85 | const Quantity_NameOfColor aColor, |
86 | const Standard_Real width, |
87 | const Aspect_TypeOfLine aProjTOL, |
88 | const Aspect_TypeOfLine aCallTOL) const |
89 | { |
6262338c |
90 | if (!myDrawer->HasOwnWireAspect()){ |
7fd59977 |
91 | myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aProjTOL,2.));} |
92 | else { |
93 | const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect(); |
94 | li->SetColor(aColor); |
95 | li->SetTypeOfLine(aProjTOL); |
96 | li->SetWidth(width); |
97 | } |
98 | |
99 | Standard_Real pf, pl; |
100 | TopLoc_Location loc; |
101 | Handle(Geom_Curve) curve; |
102 | Standard_Boolean isInfinite; |
103 | curve = BRep_Tool::Curve(anEdge,loc,pf,pl); |
104 | isInfinite = (Precision::IsInfinite(pf) || Precision::IsInfinite(pl)); |
105 | |
106 | TopoDS_Edge E; |
107 | |
108 | // Calcul de la presentation de l'edge |
109 | if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Line)) ) { |
c5f3a425 |
110 | Handle(Geom_Line) gl (Handle(Geom_Line)::DownCast (ProjCurv)); |
7fd59977 |
111 | if ( !isInfinite) { |
112 | pf = ElCLib::Parameter(gl->Lin(),FirstP); |
113 | pl = ElCLib::Parameter(gl->Lin(),LastP); |
114 | BRepBuilderAPI_MakeEdge MakEd(gl->Lin(), pf, pl); |
115 | E = MakEd.Edge(); |
116 | } |
117 | else { |
118 | BRepBuilderAPI_MakeEdge MakEd(gl->Lin()); |
119 | E = MakEd.Edge(); |
120 | } |
121 | } |
122 | else if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Circle)) ) { |
c5f3a425 |
123 | Handle(Geom_Circle) gc (Handle(Geom_Circle)::DownCast (ProjCurv)); |
7fd59977 |
124 | pf = ElCLib::Parameter(gc->Circ(),FirstP); |
125 | pl = ElCLib::Parameter(gc->Circ(),LastP); |
126 | BRepBuilderAPI_MakeEdge MakEd(gc->Circ(),pf, pl); |
127 | E = MakEd.Edge(); |
128 | } |
5ad8c033 |
129 | StdPrs_WFShape::Add (aPrs, E, myDrawer); |
7fd59977 |
130 | |
131 | //Calcul de la presentation des lignes de raccord |
132 | myDrawer->WireAspect()->SetTypeOfLine(aCallTOL); |
133 | if (!isInfinite) { |
134 | gp_Pnt ppf, ppl; |
135 | ppf = BRep_Tool::Pnt( TopExp::FirstVertex(TopoDS::Edge(anEdge))); |
136 | ppl = BRep_Tool::Pnt( TopExp::LastVertex(TopoDS::Edge(anEdge))); |
5ad8c033 |
137 | if (FirstP.Distance (ppf) > gp::Resolution()) |
138 | { |
139 | BRepBuilderAPI_MakeEdge MakEd1 (FirstP, ppf); |
140 | StdPrs_WFShape::Add (aPrs, MakEd1.Edge(), myDrawer); |
141 | } |
7fd59977 |
142 | else |
5ad8c033 |
143 | { |
144 | BRepBuilderAPI_MakeVertex MakVert1 (FirstP); |
145 | StdPrs_WFShape::Add (aPrs, MakVert1.Vertex(), myDrawer); |
146 | } |
147 | if (LastP.Distance (ppl) > gp::Resolution()) |
148 | { |
149 | BRepBuilderAPI_MakeEdge MakEd2 (LastP, ppl); |
150 | StdPrs_WFShape::Add (aPrs, MakEd2.Edge(), myDrawer); |
151 | } |
7fd59977 |
152 | else |
5ad8c033 |
153 | { |
154 | BRepBuilderAPI_MakeVertex MakVert2 (LastP); |
155 | StdPrs_WFShape::Add (aPrs, MakVert2.Vertex(), myDrawer); |
156 | } |
7fd59977 |
157 | /* |
5ad8c033 |
158 | BRepBuilderAPI_MakeEdge MakEd1 (FirstP, ppf); |
159 | StdPrs_WFShape::Add (aPrs, MakEd1.Edge(), myDrawer); |
160 | BRepBuilderAPI_MakeEdge MakEd2 (LastP, ppl); |
161 | StdPrs_WFShape::Add (aPrs, MakEd2.Edge(), myDrawer); |
7fd59977 |
162 | */ |
163 | } |
164 | } |
165 | |
166 | |
167 | //======================================================================= |
168 | //function : ComputeProjVertexPresentation |
169 | //purpose : |
170 | //======================================================================= |
171 | |
172 | void AIS_Relation::ComputeProjVertexPresentation(const Handle(Prs3d_Presentation)& aPrs, |
173 | const TopoDS_Vertex& aVertex, |
174 | const gp_Pnt& ProjPoint, |
175 | const Quantity_NameOfColor aColor, |
176 | const Standard_Real width, |
177 | const Aspect_TypeOfMarker aProjTOM, |
178 | const Aspect_TypeOfLine aCallTOL) const |
179 | { |
6262338c |
180 | if (!myDrawer->HasOwnPointAspect()){ |
7fd59977 |
181 | myDrawer->SetPointAspect(new Prs3d_PointAspect(aProjTOM, aColor,1));} |
182 | else { |
183 | const Handle(Prs3d_PointAspect)& pa = myDrawer->PointAspect(); |
184 | pa->SetColor(aColor); |
185 | pa->SetTypeOfMarker(aProjTOM); |
186 | } |
187 | |
bf5f0ca2 |
188 | { |
189 | Handle(Graphic3d_Group) aGroup = aPrs->NewGroup(); |
190 | Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1); |
191 | anArrayOfPoints->AddVertex (ProjPoint); |
192 | aGroup->SetGroupPrimitivesAspect (myDrawer->PointAspect()->Aspect()); |
193 | aGroup->AddPrimitiveArray (anArrayOfPoints); |
194 | } |
7fd59977 |
195 | |
6262338c |
196 | if (!myDrawer->HasOwnWireAspect()){ |
7fd59977 |
197 | myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aCallTOL,2.));} |
198 | else { |
199 | const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect(); |
200 | li->SetColor(aColor); |
201 | li->SetTypeOfLine(aCallTOL); |
202 | li->SetWidth(width); |
203 | } |
204 | |
205 | // Si les points ne sont pas confondus... |
bf5f0ca2 |
206 | if (!ProjPoint.IsEqual (BRep_Tool::Pnt(aVertex),Precision::Confusion())) |
207 | { |
208 | Handle(Graphic3d_Group) aGroup = aPrs->NewGroup(); |
209 | Handle(Graphic3d_ArrayOfSegments) anArrayOfLines = new Graphic3d_ArrayOfSegments (2); |
210 | anArrayOfLines->AddVertex (ProjPoint); |
211 | anArrayOfLines->AddVertex (BRep_Tool::Pnt(aVertex)); |
212 | aGroup->SetGroupPrimitivesAspect (myDrawer->WireAspect()->Aspect()); |
213 | aGroup->AddPrimitiveArray (anArrayOfLines); |
7fd59977 |
214 | } |
215 | } |
216 | |
217 | //======================================================================= |
218 | //function : SetColor |
219 | //purpose : |
220 | //======================================================================= |
7fd59977 |
221 | void AIS_Relation::SetColor(const Quantity_Color &aCol) |
7fd59977 |
222 | { |
f838dac4 |
223 | if(hasOwnColor && myDrawer->Color() == aCol) return; |
7fd59977 |
224 | |
6262338c |
225 | if (!myDrawer->HasOwnTextAspect()) myDrawer->SetTextAspect(new Prs3d_TextAspect()); |
7fd59977 |
226 | hasOwnColor=Standard_True; |
f838dac4 |
227 | myDrawer->SetColor (aCol); |
7fd59977 |
228 | myDrawer->TextAspect()->SetColor(aCol); |
229 | |
6262338c |
230 | Standard_Real WW = HasWidth()? Width(): myDrawer->HasLink() ? |
231 | AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.; |
232 | if (!myDrawer->HasOwnLineAspect()) { |
7fd59977 |
233 | myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW)); |
234 | } |
6262338c |
235 | if (!myDrawer->HasOwnDimensionAspect()) { |
a6eb515f |
236 | myDrawer->SetDimensionAspect(new Prs3d_DimensionAspect); |
7fd59977 |
237 | } |
a6eb515f |
238 | |
7fd59977 |
239 | myDrawer->LineAspect()->SetColor(aCol); |
a6eb515f |
240 | const Handle(Prs3d_DimensionAspect)& DIMENSION = myDrawer->DimensionAspect(); |
7fd59977 |
241 | const Handle(Prs3d_LineAspect)& LINE = myDrawer->LineAspect(); |
242 | const Handle(Prs3d_TextAspect)& TEXT = myDrawer->TextAspect(); |
243 | |
a6eb515f |
244 | DIMENSION->SetLineAspect(LINE); |
245 | DIMENSION->SetTextAspect(TEXT); |
7fd59977 |
246 | } |
247 | |
248 | //======================================================================= |
249 | //function : UnsetColor |
250 | //purpose : |
251 | //======================================================================= |
252 | void AIS_Relation::UnsetColor() |
253 | { |
254 | if (!hasOwnColor) return; |
255 | hasOwnColor = Standard_False; |
256 | const Handle(Prs3d_LineAspect)& LA = myDrawer->LineAspect(); |
6262338c |
257 | Quantity_Color CC = Quantity_NOC_YELLOW; |
258 | if (myDrawer->HasLink()) |
259 | { |
260 | AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC); |
261 | myDrawer->SetTextAspect(myDrawer->Link()->TextAspect()); |
262 | } |
7fd59977 |
263 | LA->SetColor(CC); |
a6eb515f |
264 | myDrawer->DimensionAspect()->SetLineAspect(LA); |
7fd59977 |
265 | } |
266 | |
267 | //======================================================================= |
268 | //function : AcceptDisplayMode |
269 | //purpose : |
270 | //======================================================================= |
271 | |
272 | Standard_Boolean AIS_Relation:: |
273 | AcceptDisplayMode(const Standard_Integer aMode) const |
274 | {return aMode == 0;} |
275 | |
276 | |
277 | //======================================================================= |
278 | //function : SetFirstShape |
279 | //purpose : |
280 | //======================================================================= |
281 | |
282 | void AIS_Relation::SetFirstShape(const TopoDS_Shape& aFShape) |
283 | { |
284 | myFShape = aFShape; |
285 | } |
286 | |
287 | |
288 | //======================================================================= |
289 | //function : SetSecondShape |
290 | //purpose : |
291 | //======================================================================= |
292 | |
293 | void AIS_Relation::SetSecondShape(const TopoDS_Shape& aSShape) |
294 | { |
295 | mySShape = aSShape; |
296 | } |
297 | |
298 | //======================================================================= |
299 | //function : KindOfDimension |
300 | //purpose : |
301 | //======================================================================= |
302 | AIS_KindOfDimension AIS_Relation::KindOfDimension() const |
303 | {return AIS_KOD_NONE;} |
304 | |
305 | //======================================================================= |
306 | //function : IsMovable |
307 | //purpose : |
308 | //======================================================================= |
309 | Standard_Boolean AIS_Relation::IsMovable() const |
310 | {return Standard_False;} |
311 | |
312 | |