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