b311480e |
1 | // Created on: 1998-09-07 |
2 | // Created by: Denis PASCAL |
3 | // Copyright (c) 1998-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 <BRep_Builder.hxx> |
19 | #include <BRep_Tool.hxx> |
7fd59977 |
20 | #include <DBRep.hxx> |
42cf5bc1 |
21 | #include <DBRep_DrawableShape.hxx> |
22 | #include <DDataStd.hxx> |
23 | #include <DDataStd_DrawDriver.hxx> |
24 | #include <Draw.hxx> |
7fd59977 |
25 | #include <Draw_Appli.hxx> |
42cf5bc1 |
26 | #include <Draw_Axis3D.hxx> |
7fd59977 |
27 | #include <Draw_Drawable3D.hxx> |
28 | #include <Draw_Marker3D.hxx> |
42cf5bc1 |
29 | #include <DrawDim_Angle.hxx> |
30 | #include <DrawDim_Distance.hxx> |
31 | #include <DrawDim_PlanarAngle.hxx> |
32 | #include <DrawDim_PlanarDiameter.hxx> |
33 | #include <DrawDim_PlanarDistance.hxx> |
34 | #include <DrawDim_PlanarRadius.hxx> |
35 | #include <DrawDim_Radius.hxx> |
36 | #include <DrawTrSurf_Surface.hxx> |
7fd59977 |
37 | #include <Geom_CartesianPoint.hxx> |
7fd59977 |
38 | #include <Geom_Plane.hxx> |
42cf5bc1 |
39 | #include <gp_Ax3.hxx> |
40 | #include <gp_Pln.hxx> |
41 | #include <Standard_Type.hxx> |
42 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
43 | #include <TDataStd.hxx> |
42cf5bc1 |
44 | #include <TDataStd_Integer.hxx> |
45 | #include <TDataStd_Real.hxx> |
7fd59977 |
46 | #include <TDataXtd_Axis.hxx> |
42cf5bc1 |
47 | #include <TDataXtd_Constraint.hxx> |
7fd59977 |
48 | #include <TDataXtd_Geometry.hxx> |
42cf5bc1 |
49 | #include <TDataXtd_GeometryEnum.hxx> |
50 | #include <TDataXtd_Plane.hxx> |
51 | #include <TDataXtd_Point.hxx> |
7fd59977 |
52 | #include <TDF_ChildIterator.hxx> |
42cf5bc1 |
53 | #include <TDF_Label.hxx> |
54 | #include <TDF_LabelList.hxx> |
7fd59977 |
55 | #include <TDF_ListIteratorOfLabelList.hxx> |
42cf5bc1 |
56 | #include <TDF_Tool.hxx> |
57 | #include <TNaming_NamedShape.hxx> |
58 | #include <TNaming_Tool.hxx> |
59 | #include <TopoDS.hxx> |
60 | #include <TopoDS_Compound.hxx> |
61 | #include <TopoDS_Shape.hxx> |
7fd59977 |
62 | |
42cf5bc1 |
63 | // attribut affichable |
64 | // drawable object |
7fd59977 |
65 | static Standard_Integer DISCRET = 100; |
66 | static Standard_Integer NBISOS = 10; |
67 | static Standard_Real THESIZE = 1000.; |
68 | |
7fd59977 |
69 | static Handle(DDataStd_DrawDriver) DrawDriver; |
70 | |
71 | |
72 | Handle(DDataStd_DrawDriver) DDataStd_DrawDriver::Get () {return DrawDriver; } |
73 | void DDataStd_DrawDriver::Set (const Handle(DDataStd_DrawDriver)& DD) {DrawDriver = DD; } |
74 | |
75 | //======================================================================= |
76 | //function : Displayer |
77 | //purpose : |
78 | //======================================================================= |
79 | |
80 | DDataStd_DrawDriver::DDataStd_DrawDriver () {} |
81 | |
82 | |
83 | //======================================================================= |
84 | //function : Geometry |
85 | //purpose : |
86 | //======================================================================= |
87 | |
88 | static TopoDS_Shape Geometry (const Handle(TDataXtd_Constraint)& A, |
89 | const Standard_Integer i, TopAbs_ShapeEnum T) |
90 | { |
91 | TopoDS_Shape S = TNaming_Tool::GetShape(A->GetGeometry(i)); |
92 | if (!S.IsNull()) { |
93 | if (T != TopAbs_SHAPE && T != S.ShapeType()) |
94 | S.Nullify(); |
95 | } |
96 | return S; |
97 | } |
98 | |
99 | //======================================================================= |
100 | //function : Drawable |
101 | //purpose : |
102 | //======================================================================= |
103 | |
104 | Handle(Draw_Drawable3D) DDataStd_DrawDriver::Drawable (const TDF_Label& L) const |
105 | { |
106 | // CONSTRAINT |
107 | |
108 | Handle(TDataXtd_Constraint) CTR; |
109 | if (L.FindAttribute(TDataXtd_Constraint::GetID(),CTR)) { |
110 | return DrawableConstraint(CTR); |
111 | } |
112 | |
113 | // OBJECT |
114 | |
115 | TopoDS_Shape s; |
116 | |
117 | //Handle(TDataStd_Object) OBJ; |
118 | //if (L.FindAttribute(TDataStd_Object::GetID(),OBJ)) { |
119 | // return DrawableShape (L,Draw_vert); |
120 | //} |
121 | |
122 | // DATUM |
123 | |
124 | |
125 | Handle(TDataXtd_Point) POINT; |
126 | if (L.FindAttribute(TDataXtd_Point::GetID(),POINT)) { |
127 | return DrawableShape (L,Draw_magenta,Standard_False); |
128 | } |
129 | |
130 | Handle(TDataXtd_Axis) AXIS; |
131 | if (L.FindAttribute(TDataXtd_Axis::GetID(),AXIS)) { |
132 | return DrawableShape (L,Draw_magenta,Standard_False); |
133 | } |
134 | |
135 | Handle(TDataXtd_Plane) PLANE; |
136 | if (L.FindAttribute(TDataXtd_Plane::GetID(),PLANE)) { |
137 | return DrawableShape(L,Draw_magenta,Standard_False); |
138 | } |
139 | |
140 | // Standard GEOMETRY |
141 | |
142 | |
143 | Handle(TDataXtd_Geometry) STD_GEOM; |
144 | if (L.FindAttribute(TDataXtd_Geometry::GetID(),STD_GEOM)) { |
145 | switch (STD_GEOM->GetType()) { |
146 | case TDataXtd_POINT : |
147 | { |
148 | return DrawableShape(L,Draw_jaune,Standard_False); |
7fd59977 |
149 | } |
150 | case TDataXtd_LINE : |
151 | case TDataXtd_CIRCLE : |
152 | case TDataXtd_ELLIPSE : |
153 | case TDataXtd_SPLINE : |
154 | { |
155 | return DrawableShape(L,Draw_cyan,Standard_False); |
7fd59977 |
156 | } |
157 | case TDataXtd_ANY_GEOM : |
158 | { |
159 | break; |
160 | } |
161 | default : |
162 | { |
163 | break; |
164 | } |
165 | } |
166 | } |
167 | |
168 | // PURE SHAPE |
169 | |
170 | Handle(TNaming_NamedShape) NS; |
171 | if (L.FindAttribute(TNaming_NamedShape::GetID(),NS)) { |
172 | return DrawableShape (NS->Label(),Draw_jaune); |
173 | } |
174 | |
175 | Handle(Draw_Drawable3D) D3D; |
176 | return D3D; |
177 | } |
178 | |
179 | |
180 | |
181 | |
182 | //======================================================================= |
183 | //function : DrawableConstraint |
184 | //purpose : |
185 | //======================================================================= |
186 | |
187 | Handle(Draw_Drawable3D) DDataStd_DrawDriver::DrawableConstraint (const Handle(TDataXtd_Constraint)& A) const |
188 | { |
189 | Handle(DrawDim_Dimension) D; |
190 | |
191 | switch (A->GetType()) { |
192 | |
193 | case TDataXtd_RADIUS: |
194 | { |
195 | if (A->IsPlanar()) { |
d3f26155 |
196 | D = new DrawDim_PlanarRadius (TNaming_Tool::GetShape(A->GetGeometry(1))); |
7fd59977 |
197 | } |
198 | else { |
d3f26155 |
199 | TopoDS_Shape aLocalShape = Geometry(A,1,TopAbs_FACE); |
200 | TopoDS_Face F1 = TopoDS::Face(aLocalShape); |
201 | // TopoDS_Face F1 = TopoDS::Face(Geometry(A,1,TopAbs_FACE)); |
202 | if (!F1.IsNull()) D = new DrawDim_Radius(F1); |
7fd59977 |
203 | } |
204 | } |
205 | break; |
206 | |
207 | case TDataXtd_DIAMETER: |
208 | if (A->IsPlanar()) { |
209 | D = new DrawDim_PlanarDiameter (TNaming_Tool::GetShape(A->GetGeometry(1))); |
210 | } |
211 | break; |
212 | |
213 | case TDataXtd_MINOR_RADIUS: |
214 | break; |
215 | |
216 | case TDataXtd_MAJOR_RADIUS: |
217 | break; |
218 | |
219 | case TDataXtd_TANGENT: |
220 | break; |
221 | |
222 | case TDataXtd_PARALLEL: |
223 | break; |
224 | |
225 | case TDataXtd_PERPENDICULAR: |
226 | break; |
227 | |
228 | case TDataXtd_CONCENTRIC: |
229 | break; |
230 | |
231 | case TDataXtd_COINCIDENT: |
232 | break; |
233 | |
234 | case TDataXtd_DISTANCE: |
235 | { |
236 | if (A->IsPlanar()) { |
d3f26155 |
237 | D = new DrawDim_PlanarDistance (TNaming_Tool::GetShape(A->GetGeometry(1)), |
238 | TNaming_Tool::GetShape(A->GetGeometry(2))); |
7fd59977 |
239 | } |
d3f26155 |
240 | break; |
7fd59977 |
241 | } |
7fd59977 |
242 | case TDataXtd_ANGLE: |
243 | { |
244 | if (A->IsPlanar()) { |
245 | Handle(DrawDim_PlanarAngle) DAng = new |
246 | DrawDim_PlanarAngle (TNaming_Tool::GetShape(A->GetGeometry(1)), |
247 | TNaming_Tool::GetShape(A->GetGeometry(2))); |
248 | DAng->Sector(A->Reversed(),A->Inverted()); |
249 | TopoDS_Shape aLocalShape = TNaming_Tool::GetShape(A->GetPlane()); |
250 | DAng->SetPlane(TopoDS::Face(aLocalShape)); |
251 | // DAng->SetPlane(TopoDS::Face(TNaming_Tool::GetShape(A->GetPlane()))); |
252 | D = DAng; |
253 | } |
254 | else { |
255 | TopoDS_Shape aLocalShape = Geometry(A,1,TopAbs_FACE); |
256 | TopoDS_Face F1 = TopoDS::Face(aLocalShape); |
257 | aLocalShape = Geometry(A,2,TopAbs_FACE); |
258 | TopoDS_Face F2 = TopoDS::Face(aLocalShape); |
259 | // TopoDS_Face F1 = TopoDS::Face(Geometry(A,1,TopAbs_FACE)); |
260 | // TopoDS_Face F2 = TopoDS::Face(Geometry(A,2,TopAbs_FACE)); |
261 | if (!F1.IsNull() && !F2.IsNull()) D = new DrawDim_Angle(F1,F2); |
262 | } |
263 | } |
264 | break; |
265 | |
266 | case TDataXtd_EQUAL_RADIUS: |
267 | { |
268 | |
269 | } |
270 | |
271 | break; |
272 | |
273 | case TDataXtd_SYMMETRY: |
274 | break; |
275 | |
276 | case TDataXtd_MIDPOINT: |
277 | break; |
278 | |
279 | case TDataXtd_EQUAL_DISTANCE: |
280 | break; |
281 | |
282 | case TDataXtd_FIX: |
283 | break; |
284 | |
285 | case TDataXtd_RIGID: |
286 | break; |
287 | |
288 | case TDataXtd_FROM: |
289 | break; |
290 | |
291 | case TDataXtd_AXIS: |
292 | break; |
293 | |
294 | case TDataXtd_MATE: |
295 | { |
296 | TopoDS_Shape aLocalShape = Geometry(A,1,TopAbs_FACE); |
297 | TopoDS_Face F1 = TopoDS::Face(aLocalShape); |
298 | aLocalShape = Geometry(A,2,TopAbs_FACE); |
299 | TopoDS_Face F2 = TopoDS::Face(aLocalShape); |
300 | // TopoDS_Face F1 = TopoDS::Face(Geometry(A,1,TopAbs_FACE)); |
301 | // TopoDS_Face F2 = TopoDS::Face(Geometry(A,2,TopAbs_FACE)); |
302 | if (!F1.IsNull() && !F2.IsNull()) |
303 | D = new DrawDim_Distance(F1,F2); |
304 | } |
305 | break; |
306 | |
307 | case TDataXtd_ALIGN_FACES: |
308 | { |
309 | TopoDS_Shape aLocalShape = Geometry(A,1,TopAbs_FACE) ; |
310 | TopoDS_Face F1 = TopoDS::Face(aLocalShape); |
311 | aLocalShape = Geometry(A,2,TopAbs_FACE) ; |
312 | TopoDS_Face F2 = TopoDS::Face(aLocalShape); |
313 | // TopoDS_Face F1 = TopoDS::Face(Geometry(A,1,TopAbs_FACE)); |
314 | // TopoDS_Face F2 = TopoDS::Face(Geometry(A,2,TopAbs_FACE)); |
315 | if (!F1.IsNull() && !F2.IsNull()) |
316 | D = new DrawDim_Distance(F1,F2); |
317 | } |
318 | break; |
319 | |
320 | case TDataXtd_ALIGN_AXES: |
321 | break; |
322 | |
323 | case TDataXtd_AXES_ANGLE: |
324 | break; |
325 | |
326 | case TDataXtd_FACES_ANGLE: |
327 | break; |
328 | |
329 | case TDataXtd_ROUND: |
330 | break; |
331 | |
332 | case TDataXtd_OFFSET : |
333 | break; |
334 | |
335 | } |
336 | |
337 | if (!D.IsNull()) { |
338 | if (!A->GetValue().IsNull()) { |
339 | Standard_Real val = A->GetValue()->Get(); |
c6541a0c |
340 | if (A->GetValue()->GetDimension() == TDataStd_ANGULAR) val = (180.*val)/M_PI; |
7fd59977 |
341 | D->SetValue(val); |
342 | } |
343 | // unverified constraints are red (default is white) |
344 | if (!A->Verified()) D->TextColor(Draw_rouge); |
345 | } |
346 | return D; |
347 | } |
348 | |
349 | //======================================================================= |
350 | //function : DrawableShape |
351 | //purpose : |
352 | //======================================================================= |
353 | |
354 | Handle(Draw_Drawable3D) DDataStd_DrawDriver::DrawableShape (const TDF_Label& L, |
355 | const Draw_ColorKind color, |
356 | const Standard_Boolean current) const |
357 | { |
358 | Handle(Draw_Drawable3D) DS; |
359 | Handle(TNaming_NamedShape) NS; |
360 | if (L.FindAttribute(TNaming_NamedShape::GetID(),NS)) { |
361 | TopoDS_Shape S; |
362 | if (current) S = TNaming_Tool::CurrentShape (NS); |
363 | else S = TNaming_Tool::GetShape (NS); |
364 | DS = DrawableShape (S,color); |
365 | } |
366 | return DS; |
367 | } |
368 | |
369 | //======================================================================= |
370 | //function : DrawableShape |
371 | //purpose : |
372 | //======================================================================= |
373 | |
374 | Handle(Draw_Drawable3D) DDataStd_DrawDriver::DrawableShape (const TopoDS_Shape& s, |
375 | const Draw_ColorKind color) |
376 | { |
377 | Handle(DBRep_DrawableShape) DS; |
378 | DS = new DBRep_DrawableShape (s,color,color,color,Draw_bleu,THESIZE,NBISOS,DISCRET); |
379 | return DS; |
380 | } |
381 | |