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