973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | // Language: C++ |
15 | // Version: Euclid Designer 2.0 |
16 | // Purpose: Update AIS object from a TDataXtd_Constraint. |
17 | // Modified Mon 30 10:15:43 1998 by SZY |
7fd59977 |
18 | |
19 | |
20 | #include <TPrsStd_ConstraintTools.ixx> |
21 | |
22 | #include <stdio.h> |
23 | #include <UnitsAPI.hxx> |
24 | #include <TCollection_ExtendedString.hxx> |
25 | |
26 | #include <TNaming_Tool.hxx> |
27 | #include <TNaming_Iterator.hxx> |
28 | #include <TNaming_NamedShape.hxx> |
29 | #include <TDF_Label.hxx> |
30 | #include <TDataStd_Real.hxx> |
31 | #include <TDataStd_Name.hxx> |
32 | #include <TDataXtd_Geometry.hxx> |
33 | #include <TDF_Reference.hxx> |
34 | |
35 | |
36 | #include <AIS_OffsetDimension.hxx> |
37 | #include <AIS_LengthDimension.hxx> |
38 | #include <AIS_ParallelRelation.hxx> |
39 | #include <AIS_TangentRelation.hxx> |
40 | #include <AIS_IdenticRelation.hxx> |
41 | #include <AIS_AngleDimension.hxx> |
42 | #include <AIS_RadiusDimension.hxx> |
43 | #include <AIS_DiameterDimension.hxx> |
44 | #include <AIS_FixRelation.hxx> |
45 | #include <AIS_PerpendicularRelation.hxx> |
46 | #include <AIS_ConcentricRelation.hxx> |
47 | #include <AIS_SymmetricRelation.hxx> |
48 | #include <AIS_MidPointRelation.hxx> |
49 | #include <AIS_InteractiveContext.hxx> |
50 | #include <AIS_Drawer.hxx> |
51 | #include <AIS_EqualRadiusRelation.hxx> |
52 | #include <AIS_EqualDistanceRelation.hxx> |
53 | #include <AIS_MinRadiusDimension.hxx> |
54 | #include <AIS_MaxRadiusDimension.hxx> |
55 | |
56 | #include <TopoDS.hxx> |
57 | #include <TopoDS_Edge.hxx> |
58 | #include <TopoDS_Shape.hxx> |
59 | #include <TopoDS_Face.hxx> |
60 | #include <TopoDS_Vertex.hxx> |
61 | #include <TopExp.hxx> |
62 | #include <TopExp_Explorer.hxx> |
63 | |
64 | #include <BRep_Tool.hxx> |
65 | #include <BRep_Builder.hxx> |
66 | #include <BRepBuilderAPI_MakeFace.hxx> |
67 | #include <BRepAdaptor_Curve.hxx> |
68 | #include <BRepAdaptor_Surface.hxx> |
69 | |
70 | #include <GeomAbs_SurfaceType.hxx> |
71 | #include <Geom_Geometry.hxx> |
72 | #include <Geom_Line.hxx> |
73 | #include <Geom_Plane.hxx> |
74 | #include <Geom_CartesianPoint.hxx> |
75 | #include <Geom_Circle.hxx> |
76 | #include <gp_Pln.hxx> |
77 | #include <gp_Dir.hxx> |
78 | #include <gp_Ax1.hxx> |
79 | #include <gp_Lin.hxx> |
80 | #include <gp_Pnt.hxx> |
81 | #include <gp_Cylinder.hxx> |
82 | #include <gp_Cone.hxx> |
83 | #include <gp_Torus.hxx> |
84 | #include <GC_MakePlane.hxx> |
85 | |
86 | #include <Precision.hxx> |
87 | #include <IntAna_QuadQuadGeo.hxx> |
88 | |
89 | #include <Standard_ProgramError.hxx> |
90 | #include <Standard_ErrorHandler.hxx> |
91 | |
92 | #include <TopTools_IndexedMapOfShape.hxx> |
93 | |
94 | #define BUC60846 |
95 | |
96 | static Standard_Boolean CheckShapesPair(const TopoDS_Shape& , const TopoDS_Shape& ); //ota |
97 | |
98 | //======================================================================= |
99 | //function : static NullifyAIS |
100 | //purpose : |
101 | //======================================================================= |
102 | static void NullifyAIS ( Handle(AIS_InteractiveObject)& anais) |
103 | { |
104 | if (anais.IsNull()) return; |
105 | anais.Nullify(); |
106 | } |
107 | |
108 | |
109 | |
110 | //======================================================================= |
111 | //function : static FindExternalShape |
112 | //purpose : |
113 | //======================================================================= |
114 | static void FindExternalShape(const Handle(TDataXtd_Constraint)& aConst, |
115 | Standard_Integer& extShape) |
116 | { |
117 | extShape = 0; |
118 | const TDF_Label& L = aConst->Label(); |
119 | if (!aConst->GetGeometry(1)->Label().IsDescendant(L)) extShape = 1; |
120 | else if (!aConst->GetGeometry(2)->Label().IsDescendant(L)) extShape = 2; |
121 | } |
122 | |
123 | //======================================================================= |
124 | //function : static GetGoodShape for planar constraint |
125 | //purpose : |
126 | //======================================================================= |
011b361d |
127 | static void GetGoodShape(TopoDS_Shape& theShape) |
7fd59977 |
128 | { |
011b361d |
129 | switch (theShape.ShapeType()) |
130 | { |
7fd59977 |
131 | case TopAbs_EDGE: |
132 | case TopAbs_VERTEX: { return; } |
133 | default: |
134 | { |
011b361d |
135 | TopExp_Explorer anExp (theShape,TopAbs_EDGE); |
136 | if (anExp.More()) |
137 | { |
138 | theShape = anExp.Current(); |
139 | return; |
7fd59977 |
140 | } |
011b361d |
141 | else |
142 | { |
143 | anExp.Init (theShape, TopAbs_VERTEX); |
144 | if (anExp.More()) |
145 | { |
146 | theShape = anExp.Current(); |
147 | } |
7fd59977 |
148 | } |
149 | } |
150 | } |
151 | } |
152 | |
153 | // Pour le cas ou S est un compound |
154 | static Standard_Boolean IsFace (const TopoDS_Shape& S) |
155 | { |
156 | Standard_Boolean findface = Standard_False; |
157 | TopExp_Explorer EXP (S,TopAbs_FACE); |
158 | if (EXP.More()) findface = Standard_True; |
159 | return findface; |
160 | } |
161 | |
162 | static TopoDS_Face GetFace (const TopoDS_Shape& S) |
163 | { |
164 | TopoDS_Face F; |
165 | TopExp_Explorer EXP (S,TopAbs_FACE); |
166 | if (EXP.More()) F = TopoDS::Face (EXP.Current()); |
167 | return F; |
168 | } |
169 | |
170 | static TopoDS_Edge GetEdge (const TopoDS_Shape& S) |
171 | { |
172 | TopoDS_Edge E; |
173 | TopExp_Explorer EXP (S, TopAbs_EDGE); |
174 | if (EXP.More()) E = TopoDS::Edge (EXP.Current()); |
175 | return E; |
176 | } |
177 | |
178 | |
179 | |
180 | //======================================================================= |
181 | //Function : ComputeAndTextValue |
182 | //purpose : |
183 | //======================================================================= |
184 | void TPrsStd_ConstraintTools::ComputeTextAndValue(const Handle(TDataXtd_Constraint)& aConst, |
185 | Standard_Real& val, |
186 | TCollection_ExtendedString& txt, |
187 | const Standard_Boolean anIsAngle ) |
188 | { |
189 | Standard_Real outvalue; |
190 | const Handle(TDataStd_Real)& VAL = aConst->GetValue(); |
191 | val = VAL->Get(); |
192 | if(anIsAngle){ |
193 | outvalue = UnitsAPI::CurrentFromLS(Abs(val),"PLANE ANGLE"); |
194 | } |
195 | else { |
196 | outvalue = UnitsAPI::CurrentFromLS(val,"LENGTH"); |
197 | } |
198 | char res[1000]; |
199 | sprintf(res,"%g",outvalue); |
200 | txt = TCollection_ExtendedString(res); |
201 | |
202 | if (VAL->IsCaptured()) { |
203 | Handle(TDF_Reference) ref; |
204 | VAL->Label().FindAttribute(TDF_Reference::GetID(),ref); |
205 | Handle(TDataStd_Name) name; |
206 | const TDF_Label& L = ref->Get(); |
207 | if (ref->Get().FindAttribute(TDataStd_Name::GetID(),name)) { |
208 | TCollection_ExtendedString fullname; |
209 | Handle(TDataStd_Name) Fathername; |
210 | if (L.Father().FindAttribute(TDataStd_Name::GetID(),Fathername)) { |
211 | fullname = Fathername->Get() + TCollection_ExtendedString(".") + name->Get(); |
212 | } |
213 | else fullname = name->Get(); |
214 | txt = fullname + TCollection_ExtendedString("=") + txt; |
215 | } |
216 | } |
217 | } |
218 | |
219 | |
220 | //======================================================================= |
221 | //function : UpdateOnlyValue |
222 | //purpose : |
223 | //======================================================================= |
224 | |
225 | void TPrsStd_ConstraintTools::UpdateOnlyValue(const Handle(TDataXtd_Constraint)& aConst, |
226 | const Handle(AIS_InteractiveObject)& anAIS) |
227 | { |
228 | if (anAIS.IsNull()) return; |
229 | if (!aConst->IsDimension()) return; |
230 | Standard_Real val; |
231 | TCollection_ExtendedString txt; |
232 | TPrsStd_ConstraintTools:: ComputeTextAndValue(aConst,val,txt,aConst->GetType() == TDataXtd_ANGLE); |
233 | Handle(AIS_Relation) rel = Handle(AIS_Relation)::DownCast(anAIS); |
234 | if (!rel.IsNull()) rel->SetText(txt); |
235 | } |
236 | |
237 | |
238 | //======================================================================= |
239 | //function : ComputeDistance |
011b361d |
240 | //purpose : Build an AIS_LengthDimension. |
7fd59977 |
241 | //======================================================================= |
011b361d |
242 | void TPrsStd_ConstraintTools::ComputeDistance (const Handle(TDataXtd_Constraint)& theConst, |
243 | Handle(AIS_InteractiveObject)& theAIS) |
7fd59977 |
244 | { |
011b361d |
245 | Standard_Integer aGeomNum = theConst->NbGeometries(); |
246 | |
247 | // Dimension is build on one or two shapes. |
248 | if (aGeomNum < 1 || aGeomNum > 2) |
249 | { |
0797d9d3 |
250 | #ifdef OCCT_DEBUG |
011b361d |
251 | cout << "TPrsStd_ConstraintTools::ComputeDistance: 1 or 2 geometries are needed" << endl; |
7fd59977 |
252 | #endif |
011b361d |
253 | NullifyAIS(theAIS); |
7fd59977 |
254 | return; |
255 | } |
011b361d |
256 | |
257 | TopoDS_Shape aShape1, aShape2; |
258 | Handle(Geom_Geometry) aGeom3; |
259 | Standard_Boolean isPlanar (theConst->IsPlanar()); |
7fd59977 |
260 | |
261 | // Get shapes and geometry |
011b361d |
262 | if (aGeomNum == 1) |
263 | { |
264 | GetOneShape (theConst, aShape1); |
265 | |
266 | if (aShape1.IsNull()) |
267 | { |
0797d9d3 |
268 | #ifdef OCCT_DEBUG |
011b361d |
269 | cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << endl; |
270 | #endif |
271 | NullifyAIS (theAIS); |
272 | return; |
273 | } |
7fd59977 |
274 | } |
011b361d |
275 | else //aGeomNum == 2 |
276 | { |
277 | GetTwoShapes (theConst, aShape1, aShape2); |
7fd59977 |
278 | |
011b361d |
279 | if (aShape1.IsNull() || aShape2.IsNull()) |
280 | { |
0797d9d3 |
281 | #ifdef OCCT_DEBUG |
011b361d |
282 | cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << endl; |
283 | #endif |
284 | NullifyAIS (theAIS); |
285 | return; |
286 | } |
7fd59977 |
287 | } |
288 | |
011b361d |
289 | // Get plane from constraint |
290 | Handle(Geom_Plane) aPlane; |
291 | if (isPlanar) |
292 | { |
293 | GetGeom (theConst, aGeom3); |
294 | |
295 | GetGoodShape (aShape1); |
296 | |
297 | if (aGeomNum == 2) |
298 | { |
299 | GetGoodShape (aShape2); |
7fd59977 |
300 | } |
301 | |
011b361d |
302 | aPlane = Handle(Geom_Plane)::DownCast (aGeom3); |
303 | } |
7fd59977 |
304 | |
011b361d |
305 | // Get custom value |
306 | Standard_Real aValue; |
307 | TCollection_ExtendedString aText; |
308 | ComputeTextAndValue (theConst, aValue, aText,Standard_False); |
309 | |
310 | Standard_Boolean isFaces = Standard_False; |
311 | Standard_Boolean isEdges = Standard_False; |
312 | Standard_Boolean isEdgeFace = Standard_False; |
313 | Standard_Boolean isVertices = Standard_False; |
314 | Standard_Boolean isEdge = Standard_False; |
315 | |
316 | Standard_Boolean SaveDrw = Standard_False; |
317 | Handle(AIS_Drawer) aDrawer; |
318 | Handle(AIS_LengthDimension) aDim; |
319 | |
320 | if (!theAIS.IsNull()) |
321 | { |
322 | aDim = Handle(AIS_LengthDimension)::DownCast (theAIS); |
323 | } |
324 | |
325 | // Check shapes for AIS dimension |
326 | if (aGeomNum == 1) |
327 | { |
328 | if (aShape1.ShapeType () != TopAbs_EDGE) |
329 | { |
0797d9d3 |
330 | #ifdef OCCT_DEBUG |
011b361d |
331 | cout << "TPrsStd_ConstraintTools::ComputeDistance : shape should be edge" << endl; |
332 | #endif |
333 | NullifyAIS (theAIS); |
7fd59977 |
334 | return; |
335 | } |
011b361d |
336 | |
337 | isEdge = Standard_True; |
7fd59977 |
338 | } |
011b361d |
339 | else // nbgeom == 2 |
340 | { |
341 | isFaces = IsFace (aShape1) && IsFace (aShape2); |
7fd59977 |
342 | |
011b361d |
343 | isEdges = (aShape1.ShapeType() == TopAbs_EDGE) && (aShape2.ShapeType() == TopAbs_EDGE); |
344 | |
345 | isEdgeFace = ((aShape1.ShapeType() == TopAbs_FACE) && (aShape2.ShapeType() == TopAbs_EDGE)) |
346 | || ((aShape1.ShapeType() == TopAbs_EDGE) && (aShape2.ShapeType() == TopAbs_FACE)); |
347 | |
348 | isVertices = (aShape1.ShapeType() == TopAbs_VERTEX) && (aShape2.ShapeType() == TopAbs_VERTEX); |
349 | |
350 | if (!isPlanar && !isFaces && !isEdges && !isVertices) |
351 | { |
352 | // Search suitable geometry for dimension |
353 | if (aShape1.ShapeType() == aShape2.ShapeType()) |
354 | { |
355 | TopoDS_Vertex aV1, aV2, aV3, aV4; |
356 | if (aShape1.ShapeType() == TopAbs_WIRE) |
357 | { |
358 | TopExp::Vertices (TopoDS::Wire(aShape1), aV1, aV2); |
359 | TopExp::Vertices (TopoDS::Wire(aShape2), aV3, aV4); |
360 | } |
361 | aShape1 = aV1; |
362 | gp_Pnt aP1 = BRep_Tool::Pnt(aV1); |
363 | gp_Pnt aP2 = BRep_Tool::Pnt(aV3); |
364 | gp_Pnt aP3 = BRep_Tool::Pnt (aV4); |
365 | if (aP1.Distance (aP2) < aP1.Distance (aP3)) |
366 | { |
367 | aShape2 = aV3; |
368 | gp_Ax2 ax2 (aP1, gp_Dir (aP2.XYZ() - aP1.XYZ())); |
369 | aPlane = new Geom_Plane (aP1, ax2.XDirection()); |
370 | } |
371 | else |
372 | { |
373 | aShape2 = aV4; |
374 | gp_Ax2 anAx2 (aP1, gp_Dir (aP3.XYZ() - aP1.XYZ())); |
375 | aPlane = new Geom_Plane (aP1, anAx2.XDirection()); |
376 | } |
7fd59977 |
377 | } |
011b361d |
378 | else if (!isEdgeFace) |
379 | { |
380 | NullifyAIS (theAIS); |
381 | return; |
7fd59977 |
382 | } |
383 | } |
384 | } |
385 | |
011b361d |
386 | // Check plane |
387 | Standard_Boolean isCheckPlane = (aDim.IsNull() && !isFaces) || isPlanar; |
388 | if ((isVertices || isEdges) && !isPlanar) |
389 | { |
390 | gp_Pnt aP1, aP2, aP3; |
7fd59977 |
391 | |
011b361d |
392 | if (isVertices) |
393 | { |
394 | aP1 = BRep_Tool::Pnt (TopoDS::Vertex (aShape1)); |
395 | aP2 = BRep_Tool::Pnt (TopoDS::Vertex (aShape2)); |
396 | aP3 = gp_Pnt (aP1.Y() - 1.0, aP2.X() + 1.0, 0.0); |
397 | } |
398 | |
399 | if (isEdges) |
400 | { |
401 | TopoDS_Vertex aV1, aV2, aV3, aV4; |
402 | TopExp::Vertices (TopoDS::Edge(aShape1), aV1, aV2); |
403 | TopExp::Vertices (TopoDS::Edge(aShape2), aV3, aV4); |
404 | aP1 = BRep_Tool::Pnt (aV1); |
405 | aP2 = BRep_Tool::Pnt (aV2); |
406 | aP3 = BRep_Tool::Pnt (aV3); |
407 | } |
408 | |
409 | GC_MakePlane aPlaneMaker (aP1, aP2, aP3); |
410 | if (aPlaneMaker.IsDone() && !isPlanar) |
411 | { |
412 | aPlane = aPlaneMaker.Value(); |
413 | } |
414 | } |
415 | |
416 | if (isCheckPlane && aPlane.IsNull()) |
417 | { |
0797d9d3 |
418 | #ifdef OCCT_DEBUG |
011b361d |
419 | cout << "TPrsStd_ConstraintTools::ComputeDistance : null plane" << endl; |
420 | #endif |
421 | NullifyAIS (theAIS); |
422 | return; |
7fd59977 |
423 | } |
424 | |
011b361d |
425 | // Update of AIS |
426 | if (aDim.IsNull()) |
427 | { |
428 | if (isEdge) |
429 | { |
430 | aDim = new AIS_LengthDimension (GetEdge (aShape1), aPlane->Pln()); |
7fd59977 |
431 | } |
011b361d |
432 | else if (isFaces) |
a6eb515f |
433 | { |
011b361d |
434 | aDim = new AIS_LengthDimension (GetFace (aShape1), GetFace (aShape2)); |
7fd59977 |
435 | } |
011b361d |
436 | else |
437 | { |
438 | aDim = new AIS_LengthDimension (aShape1, aShape2, aPlane->Pln()); |
7fd59977 |
439 | } |
011b361d |
440 | |
441 | if (SaveDrw) |
442 | { |
443 | aDim->SetAttributes (aDrawer); |
7fd59977 |
444 | } |
7fd59977 |
445 | } |
011b361d |
446 | else |
447 | { |
448 | if (isEdge) |
60bf98ae |
449 | { |
011b361d |
450 | aDim->SetMeasuredGeometry (GetEdge(aShape1), aPlane->Pln()); |
7fd59977 |
451 | } |
60bf98ae |
452 | else |
453 | { |
011b361d |
454 | aDim->SetMeasuredShapes (aShape1, aShape2); |
7fd59977 |
455 | } |
456 | |
011b361d |
457 | aDim->SetCustomValue (aValue); |
7fd59977 |
458 | } |
011b361d |
459 | |
460 | if (!aPlane.IsNull()) |
a6eb515f |
461 | { |
011b361d |
462 | aDim->SetCustomPlane (aPlane->Pln()); |
7fd59977 |
463 | } |
011b361d |
464 | |
465 | theAIS = aDim; |
7fd59977 |
466 | } |
467 | |
468 | //======================================================================= |
469 | //function : ComputePerpendicular |
470 | //purpose : |
471 | //======================================================================= |
472 | void TPrsStd_ConstraintTools::ComputePerpendicular(const Handle(TDataXtd_Constraint)& aConst, |
473 | Handle(AIS_InteractiveObject)& anAIS) |
474 | { |
475 | Standard_Integer nbgeom = aConst->NbGeometries(); |
476 | if (nbgeom < 2) { |
0797d9d3 |
477 | #ifdef OCCT_DEBUG |
7fd59977 |
478 | cout << "TPrsStd_ConstraintTools::ComputePerpendicular: at leat two constraintes are needed" << endl; |
479 | #endif |
480 | NullifyAIS(anAIS); |
481 | return; |
482 | } |
483 | |
484 | TopoDS_Shape shape1,shape2 ; |
485 | Handle(Geom_Geometry) ageom3; |
486 | Standard_Boolean is_planar(aConst->IsPlanar()); |
487 | |
488 | if (is_planar) GetShapesAndGeom(aConst,shape1,shape2,ageom3); |
489 | else GetTwoShapes(aConst,shape1,shape2); |
490 | if (shape1.IsNull() || shape2.IsNull()) { |
0797d9d3 |
491 | #ifdef OCCT_DEBUG |
7fd59977 |
492 | cout << "TPrsStd_ConstraintTools::ComputePerpendicular : null shape" << endl; |
493 | #endif |
494 | NullifyAIS(anAIS); |
495 | return; |
496 | } |
497 | GetGoodShape(shape1); |
498 | GetGoodShape(shape2); |
499 | // Update de l'AIS |
500 | Handle(AIS_PerpendicularRelation) ais; |
501 | if (anAIS.IsNull()) ais = new AIS_PerpendicularRelation(shape1,shape2); |
502 | else { |
503 | ais = Handle(AIS_PerpendicularRelation)::DownCast(anAIS); |
504 | if (ais.IsNull()) { |
505 | ais = new AIS_PerpendicularRelation(shape1,shape2); |
506 | } |
507 | else { |
508 | ais->SetFirstShape(shape1); |
509 | ais->SetSecondShape(shape2); |
510 | } |
511 | } |
512 | |
513 | if (is_planar) { |
514 | Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3); |
515 | if (aplane.IsNull()) { |
0797d9d3 |
516 | #ifdef OCCT_DEBUG |
7fd59977 |
517 | cout << "TPrsStd_ConstraintTools::ComputePerpendicular: nul plane" << endl; |
518 | #endif |
519 | NullifyAIS(anAIS); |
520 | return; |
521 | } |
522 | ais->SetPlane(aplane); |
523 | } |
524 | anAIS = ais; |
525 | } |
526 | |
527 | //======================================================================= |
528 | //function : ComputeParallel |
529 | //purpose : |
530 | //======================================================================= |
531 | void TPrsStd_ConstraintTools::ComputeParallel(const Handle(TDataXtd_Constraint)& aConst, |
532 | Handle(AIS_InteractiveObject)& anAIS) |
533 | { |
534 | Standard_Integer nbgeom = aConst->NbGeometries(); |
535 | if (nbgeom < 2) { |
0797d9d3 |
536 | #ifdef OCCT_DEBUG |
7fd59977 |
537 | cout << "TPrsStd_ConstraintTools::ComputeParallel: at least 2 constraintes are needed" << endl; |
538 | #endif |
539 | NullifyAIS(anAIS); |
540 | return; |
541 | } |
542 | |
543 | if (!aConst->IsPlanar()) { |
0797d9d3 |
544 | #ifdef OCCT_DEBUG |
7fd59977 |
545 | cout << "TPrsStd_ConstraintTools::ComputeParallel: must be a planar constraint" << endl; |
546 | #endif |
547 | NullifyAIS(anAIS); |
548 | return; |
549 | } |
550 | |
551 | TopoDS_Shape shape1,shape2 ; |
552 | Handle(Geom_Geometry) ageom3; |
553 | |
554 | GetShapesAndGeom(aConst,shape1,shape2,ageom3); |
555 | if (shape1.IsNull() || shape2.IsNull()) { |
0797d9d3 |
556 | #ifdef OCCT_DEBUG |
7fd59977 |
557 | cout << "TPrsStd_ConstraintTools::ComputeParallel : null shape" << endl; |
558 | #endif |
559 | NullifyAIS(anAIS); |
560 | return; |
561 | } |
562 | Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3); |
563 | if (aplane.IsNull()) { |
0797d9d3 |
564 | #ifdef OCCT_DEBUG |
7fd59977 |
565 | cout << "TPrsStd_ConstraintTools::ComputeParallel: nul plane" << endl; |
566 | #endif |
567 | NullifyAIS(anAIS); |
568 | return; |
569 | } |
570 | // Update de l'AIS |
571 | GetGoodShape(shape1); |
572 | GetGoodShape(shape2); |
573 | Handle(AIS_ParallelRelation) ais; |
574 | if (anAIS.IsNull()) ais = new AIS_ParallelRelation(shape1,shape2,aplane); |
575 | else { |
576 | ais = Handle(AIS_ParallelRelation)::DownCast(anAIS); |
577 | if (ais.IsNull()) { |
578 | ais = new AIS_ParallelRelation(shape1,shape2,aplane); |
579 | } |
580 | else { |
581 | ais->SetFirstShape(shape1); |
582 | ais->SetSecondShape(shape2); |
583 | ais->SetPlane(aplane); |
584 | } |
585 | } |
586 | anAIS = ais; |
587 | } |
588 | //======================================================================= |
589 | //function : ComputeSymmetry |
590 | //purpose : |
591 | //======================================================================= |
592 | void TPrsStd_ConstraintTools::ComputeSymmetry(const Handle(TDataXtd_Constraint)& aConst, |
593 | Handle(AIS_InteractiveObject)& anAIS) |
594 | { |
595 | Standard_Integer nbgeom = aConst->NbGeometries(); |
596 | if (nbgeom < 3) { |
0797d9d3 |
597 | #ifdef OCCT_DEBUG |
7fd59977 |
598 | cout << "TPrsStd_ConstraintTools::ComputeSymmetry: at least 3 constraintes are needed" << endl; |
599 | #endif |
600 | NullifyAIS(anAIS); |
601 | return; |
602 | } |
603 | |
604 | Standard_Boolean is_planar(aConst->IsPlanar()); |
605 | if (!is_planar) { |
0797d9d3 |
606 | #ifdef OCCT_DEBUG |
7fd59977 |
607 | cout << "TPrsStd_ConstraintTools::ComputeSymmetry: must be a planar constraint" << endl; |
608 | #endif |
609 | NullifyAIS(anAIS); |
610 | return; |
611 | } |
612 | |
613 | TopoDS_Shape shape1,shape2,shape3 ; |
614 | Handle(Geom_Geometry) ageom3; |
615 | GetShapesAndGeom(aConst,shape1,shape2,shape3,ageom3); |
616 | |
617 | if (shape1.IsNull() || shape2.IsNull() || shape3.IsNull()) { |
0797d9d3 |
618 | #ifdef OCCT_DEBUG |
7fd59977 |
619 | cout << "TPrsStd_ConstraintTools::ComputeSymmetry : null shape" << endl; |
620 | #endif |
621 | NullifyAIS(anAIS); |
622 | return; |
623 | } |
624 | GetGoodShape(shape1); |
625 | GetGoodShape(shape2); |
626 | GetGoodShape(shape3); |
627 | Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3); |
628 | if (aplane.IsNull()) { |
0797d9d3 |
629 | #ifdef OCCT_DEBUG |
7fd59977 |
630 | cout << "TPrsStd_ConstraintTools::ComputeSymmetry: null plane" << endl; |
631 | #endif |
632 | NullifyAIS(anAIS); |
633 | return; |
634 | } |
635 | // Update de l'AIS |
636 | Handle(AIS_SymmetricRelation) ais; |
637 | if (anAIS.IsNull()) ais = new AIS_SymmetricRelation(shape3,shape1,shape2,aplane); |
638 | else { |
639 | ais = Handle(AIS_SymmetricRelation)::DownCast(anAIS); |
640 | if (ais.IsNull()) { |
641 | ais = new AIS_SymmetricRelation(shape3,shape1,shape2,aplane); |
642 | } |
643 | else { |
644 | ais->SetFirstShape(shape1); |
645 | ais->SetSecondShape(shape2); |
646 | ais->SetPlane(aplane); |
647 | ais->SetTool(shape3); |
648 | } |
649 | } |
650 | anAIS = ais; |
651 | } |
652 | |
653 | //======================================================================= |
654 | //function : ComputeMidPoint |
655 | //purpose : |
656 | //======================================================================= |
657 | void TPrsStd_ConstraintTools::ComputeMidPoint(const Handle(TDataXtd_Constraint)& aConst, |
658 | Handle(AIS_InteractiveObject)& anAIS) |
659 | { |
660 | Standard_Integer nbgeom = aConst->NbGeometries(); |
661 | if (nbgeom < 3) |
662 | { |
0797d9d3 |
663 | #ifdef OCCT_DEBUG |
7fd59977 |
664 | cout << "TPrsStd_ConstraintTools::ComputeSymmetry: at least 3 constraints are needed" << endl; |
665 | #endif |
666 | NullifyAIS(anAIS); |
667 | return; |
668 | } |
669 | |
670 | Standard_Boolean is_planar(aConst->IsPlanar()); |
671 | if ( !is_planar ) |
672 | { |
0797d9d3 |
673 | #ifdef OCCT_DEBUG |
7fd59977 |
674 | cout << "TPrsStd_ConstraintTools::ComputeSymmetry: must be a planar constraint" << endl; |
675 | #endif |
676 | NullifyAIS(anAIS); |
677 | return; |
678 | } |
679 | |
680 | TopoDS_Shape shape1,shape2,shape3; |
681 | Handle(Geom_Geometry) ageom3; |
682 | GetShapesAndGeom(aConst,shape1,shape2,shape3,ageom3); |
683 | |
684 | if (shape1.IsNull() || shape2.IsNull() || shape3.IsNull()) |
685 | { |
0797d9d3 |
686 | #ifdef OCCT_DEBUG |
7fd59977 |
687 | cout << "TPrsStd_ConstraintTools::ComputeSymmetry : null shape" << endl; |
688 | #endif |
689 | NullifyAIS(anAIS); |
690 | return; |
691 | } |
692 | GetGoodShape(shape1); |
693 | GetGoodShape(shape2); |
694 | GetGoodShape(shape3); |
695 | |
696 | Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3); |
697 | if (aplane.IsNull()) |
698 | { |
0797d9d3 |
699 | #ifdef OCCT_DEBUG |
7fd59977 |
700 | cout << "TPrsStd_ConstraintTools::ComputeSymmetry: null plane" << endl; |
701 | #endif |
702 | NullifyAIS(anAIS); |
703 | return; |
704 | } |
705 | |
706 | // Update de l'AIS |
707 | Handle(AIS_MidPointRelation) ais; |
708 | if ( anAIS.IsNull() ) ais = new AIS_MidPointRelation(shape3,shape1,shape2,aplane); |
709 | else |
710 | { |
711 | ais = Handle(AIS_MidPointRelation)::DownCast(anAIS); |
712 | if (ais.IsNull()) |
713 | { |
714 | ais = new AIS_MidPointRelation(shape3,shape1,shape2,aplane); |
715 | } |
716 | else |
717 | { |
718 | ais->SetFirstShape(shape1); |
719 | ais->SetSecondShape(shape2); |
720 | ais->SetPlane(aplane); |
721 | ais->SetTool(shape3); |
722 | } |
723 | } |
724 | anAIS = ais; |
725 | } |
726 | |
727 | //======================================================================= |
728 | //function : ComputeTangent |
729 | //purpose : |
730 | //======================================================================= |
731 | void TPrsStd_ConstraintTools::ComputeTangent (const Handle(TDataXtd_Constraint)& aConst, |
732 | Handle(AIS_InteractiveObject)& anAIS) |
733 | { |
734 | Standard_Integer nbgeom = aConst->NbGeometries(); |
735 | if (nbgeom < 2) { |
0797d9d3 |
736 | #ifdef OCCT_DEBUG |
7fd59977 |
737 | cout << "TPrsStd_ConstraintTools::ComputeTangent: at leat two constraintes are needed" << endl; |
738 | #endif |
739 | NullifyAIS(anAIS); |
740 | return; |
741 | } |
742 | if (!aConst->IsPlanar()) { |
0797d9d3 |
743 | #ifdef OCCT_DEBUG |
7fd59977 |
744 | cout << "TPrsStd_ConstraintTools::ComputeTangent: must be a planar constraint" << endl; |
745 | #endif |
746 | NullifyAIS(anAIS); |
747 | return; |
748 | } |
749 | TopoDS_Shape shape1,shape2 ; |
750 | Handle(Geom_Geometry) ageom3; |
751 | |
752 | GetShapesAndGeom(aConst,shape1,shape2,ageom3); |
753 | if (shape1.IsNull() || shape2.IsNull()) { |
0797d9d3 |
754 | #ifdef OCCT_DEBUG |
7fd59977 |
755 | cout << "TPrsStd_ConstraintTools::ComputeTangent : null shape" << endl; |
756 | #endif |
757 | NullifyAIS(anAIS); |
758 | return; |
759 | } |
760 | GetGoodShape(shape1); |
761 | GetGoodShape(shape2); |
762 | Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3); |
763 | if (aplane.IsNull()) { |
0797d9d3 |
764 | #ifdef OCCT_DEBUG |
7fd59977 |
765 | cout << "TPrsStd_ConstraintTools::ComputeTangent: nul plane" << endl; |
766 | #endif |
767 | NullifyAIS(anAIS); |
768 | return; |
769 | } |
770 | // Update de l'AIS |
771 | Handle(AIS_TangentRelation) ais; |
772 | if (anAIS.IsNull()) |
773 | { |
774 | ais = new AIS_TangentRelation(shape1,shape2,aplane); |
775 | ais->SetArrowSize(10000000); // jfa 9/10/2000 |
776 | } |
777 | else |
778 | { |
779 | ais = Handle(AIS_TangentRelation)::DownCast(anAIS); |
780 | if (ais.IsNull()) |
781 | { |
782 | ais = new AIS_TangentRelation(shape1,shape2,aplane); |
783 | ais->SetArrowSize(10000000); // jfa 9/10/2000 |
784 | } |
785 | else |
786 | { |
787 | ais->SetFirstShape(shape1); |
788 | ais->SetSecondShape(shape2); |
789 | ais->SetPlane(aplane); |
790 | ais->SetArrowSize(10000000); // jfa 9/10/2000 |
791 | } |
792 | } |
793 | anAIS = ais; |
794 | } |
795 | |
796 | //======================================================================= |
797 | //function : ComputeAngleForOneFace |
798 | //purpose : computes AngleDimension for one-conical-face case |
799 | //======================================================================= |
800 | void TPrsStd_ConstraintTools::ComputeAngleForOneFace (const Handle(TDataXtd_Constraint)& aConst, |
801 | Handle(AIS_InteractiveObject)& anAIS) |
802 | { |
803 | |
804 | TopoDS_Shape shape; |
805 | Handle(Geom_Geometry) ageom3; |
806 | |
807 | GetOneShape( aConst, shape ); |
808 | if (shape.IsNull() ) { |
0797d9d3 |
809 | #ifdef OCCT_DEBUG |
7fd59977 |
810 | cout << "TPrsStd_ConstraintTools::ComputeAngleForOneFace : null shape" << endl; |
811 | #endif |
812 | NullifyAIS(anAIS); |
813 | return; |
814 | } |
815 | |
816 | Standard_Real val1; |
817 | TCollection_ExtendedString txt; |
818 | TPrsStd_ConstraintTools::ComputeTextAndValue (aConst,val1,txt,Standard_True); |
819 | |
7fd59977 |
820 | Handle(AIS_AngleDimension) ais; |
821 | TopoDS_Face face; |
822 | if (!anAIS.IsNull()) { |
823 | ais = Handle(AIS_AngleDimension)::DownCast(anAIS); |
824 | if(ais.IsNull()) { |
825 | face = TopoDS::Face( shape ); |
a6eb515f |
826 | ais = new AIS_AngleDimension (face); |
7fd59977 |
827 | } |
828 | else { |
60bf98ae |
829 | ais->SetMeasuredGeometry(TopoDS::Face( shape )); |
7fd59977 |
830 | } |
831 | } |
832 | else { |
a6eb515f |
833 | face = TopoDS::Face (shape); |
834 | ais = new AIS_AngleDimension (face); |
7fd59977 |
835 | } |
836 | |
7fd59977 |
837 | anAIS = ais; |
838 | } |
839 | |
a6eb515f |
840 | //======================================================================= |
841 | //function : CheckIsShapeCompound |
842 | //purpose : |
843 | //======================================================================= |
844 | |
7fd59977 |
845 | static Standard_Boolean CheckIsShapeCompound(TopoDS_Shape& shape, TopoDS_Face& aFace) |
846 | { |
847 | if (shape.ShapeType() == TopAbs_COMPOUND) { |
848 | TopTools_IndexedMapOfShape aFaceMap; |
849 | TopExp::MapShapes(shape, TopAbs_FACE, aFaceMap); |
850 | for(Standard_Integer i = 1;i <= aFaceMap.Extent();i++) |
851 | { |
852 | aFace = TopoDS::Face(aFaceMap.FindKey(i)); |
853 | if(!aFace.IsNull()) { |
854 | shape = aFace; |
855 | return (Standard_True); |
856 | } |
857 | } |
858 | } |
0797d9d3 |
859 | #ifdef OCCT_DEBUG |
7fd59977 |
860 | cout << "TPrsStd::Compute angle : Shape is not Compound or is Null" <<endl; |
861 | #endif |
862 | return (Standard_False); |
863 | } |
a6eb515f |
864 | |
7fd59977 |
865 | //======================================================================= |
866 | //function : ComputeAngle |
867 | //purpose : |
868 | //======================================================================= |
a6eb515f |
869 | |
7fd59977 |
870 | void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& aConst, |
871 | Handle(AIS_InteractiveObject)& anAIS) |
872 | { |
873 | Standard_Integer nbgeom = aConst->NbGeometries(); |
874 | if (nbgeom < 2) { |
875 | if( nbgeom == 1 ) { ComputeAngleForOneFace( aConst, anAIS ); return; } |
0797d9d3 |
876 | #ifdef OCCT_DEBUG |
7fd59977 |
877 | cout << "TPrsStd_ConstraintTools::ComputeAngle: at least 2 constraints are needed" << endl; |
878 | #endif |
879 | NullifyAIS(anAIS); |
880 | return; |
881 | } |
882 | |
883 | TopoDS_Shape shape1,shape2 ; |
884 | Handle(Geom_Geometry) ageom3; |
885 | |
886 | GetShapesAndGeom (aConst,shape1,shape2,ageom3); |
887 | if (shape1.IsNull() || shape2.IsNull()) { |
0797d9d3 |
888 | #ifdef OCCT_DEBUG |
7fd59977 |
889 | cout << "TPrsStd_ConstraintTools::ComputeAngle : null shape" << endl; |
890 | #endif |
891 | NullifyAIS(anAIS); |
892 | return; |
893 | } |
894 | |
895 | Standard_Boolean isCurvilinear = Standard_False; |
896 | if (ageom3.IsNull()) { |
897 | // on essaie de le calculer |
898 | |
899 | TopoDS_Face aFace; |
900 | if (shape1.ShapeType() == TopAbs_WIRE) { |
901 | BRepBuilderAPI_MakeFace MkF (TopoDS::Wire(shape1),Standard_True); |
902 | if (MkF.IsDone()) { |
903 | aFace = MkF.Face(); |
904 | shape1 = aFace; |
905 | } |
906 | } |
907 | else |
908 | if (shape1.ShapeType() == TopAbs_FACE) |
909 | aFace = TopoDS::Face(shape1); |
910 | else |
911 | if(!CheckIsShapeCompound(shape1, aFace)) { |
0797d9d3 |
912 | #ifdef OCCT_DEBUG |
7fd59977 |
913 | cout << "Compute angle : Geom type = " << shape1.ShapeType() |
914 | << " non traite"<<endl; |
915 | #endif |
916 | NullifyAIS(anAIS); |
917 | return; |
918 | } |
919 | |
920 | gp_Ax1 anax1aFace1; |
921 | gp_Pln aPlnaFace1; |
922 | |
923 | BRepAdaptor_Surface aSurfaFace (aFace); |
924 | GeomAbs_SurfaceType aTypeaFace = aSurfaFace.GetType(); |
925 | if (aTypeaFace == GeomAbs_Plane) { |
926 | aPlnaFace1 = aSurfaFace.Plane(); |
927 | anax1aFace1 = aPlnaFace1.Axis(); // Normale au plan |
928 | } else if (aTypeaFace == GeomAbs_Cylinder) { |
929 | gp_Cylinder aCylaFace = aSurfaFace.Cylinder(); |
930 | anax1aFace1 = aCylaFace.Axis(); |
931 | } else if (aTypeaFace == GeomAbs_Cone) { |
932 | gp_Cone aCone = aSurfaFace.Cone(); |
933 | anax1aFace1 = aCone.Axis(); |
934 | } else if (aTypeaFace == GeomAbs_Torus) { |
935 | gp_Torus aTore = aSurfaFace.Torus(); |
936 | anax1aFace1 = aTore.Axis(); |
937 | } else { |
0797d9d3 |
938 | #ifdef OCCT_DEBUG |
7fd59977 |
939 | cout<<"Compute angle"<<aTypeaFace<<" non traite"<<endl; |
940 | #endif |
941 | NullifyAIS(anAIS); |
942 | return; |
943 | } |
944 | |
945 | gp_Ax1 anax1aFace2; |
946 | gp_Pln aPlnaFace2; |
947 | if (shape2.ShapeType() == TopAbs_WIRE) { |
948 | BRepBuilderAPI_MakeFace MkF (TopoDS::Wire(shape2),Standard_True); |
949 | if (MkF.IsDone()) { |
950 | aFace = MkF.Face(); |
951 | shape2 = aFace; |
952 | } |
953 | } |
954 | else |
955 | if (shape2.ShapeType() == TopAbs_FACE) |
956 | aFace = TopoDS::Face(shape2); |
957 | else |
958 | if(!CheckIsShapeCompound(shape2, aFace)) { |
0797d9d3 |
959 | #ifdef OCCT_DEBUG |
7fd59977 |
960 | cout << "Compute angle : Geom type = " << shape2.ShapeType() |
961 | << " non traite"<<endl; |
962 | #endif |
963 | NullifyAIS(anAIS); |
964 | return; |
965 | } |
966 | |
967 | aSurfaFace.Initialize(aFace); |
968 | aTypeaFace = aSurfaFace.GetType(); |
969 | if (aTypeaFace == GeomAbs_Plane) { |
970 | aPlnaFace2 = aSurfaFace.Plane(); |
971 | anax1aFace2 = aPlnaFace2.Axis(); // Normale au plan |
972 | } else if (aTypeaFace == GeomAbs_Cylinder) { |
973 | gp_Cylinder aCylaFace = aSurfaFace.Cylinder(); |
974 | anax1aFace2 = aCylaFace.Axis(); |
975 | } else if (aTypeaFace == GeomAbs_Cone) { |
976 | gp_Cone aCone = aSurfaFace.Cone(); |
977 | anax1aFace2 = aCone.Axis(); |
978 | } else if (aTypeaFace == GeomAbs_Torus) { |
979 | gp_Torus aTore = aSurfaFace.Torus(); |
980 | anax1aFace2 = aTore.Axis(); |
981 | } else { |
0797d9d3 |
982 | #ifdef OCCT_DEBUG |
7fd59977 |
983 | cout << "Compute angle " << aTypeaFace << " non traite"<<endl; |
984 | #endif |
985 | NullifyAIS(anAIS); |
986 | return; |
987 | } |
988 | |
989 | if (aTypeaFace==GeomAbs_Plane) { |
990 | if (!anax1aFace1.IsParallel(anax1aFace2, Precision::Angular())) { |
991 | |
992 | IntAna_QuadQuadGeo IntersectPlane (aPlnaFace1, aPlnaFace2, Precision::Angular(), Precision::Angular()); |
993 | if (IntersectPlane.IsDone() && |
994 | (IntersectPlane.TypeInter() != IntAna_Empty)) { |
995 | gp_Lin aLine = IntersectPlane.Line(1); |
996 | Handle(Geom_Line) computedgeom3 = new Geom_Line (aLine); |
997 | ageom3 = computedgeom3; |
998 | } else { |
0797d9d3 |
999 | #ifdef OCCT_DEBUG |
7fd59977 |
1000 | cout<<"Compute angle insertection of planes failed"<<endl; |
1001 | #endif |
1002 | NullifyAIS(anAIS); |
1003 | return; |
1004 | } |
1005 | } else { |
1006 | |
0797d9d3 |
1007 | #ifdef OCCT_DEBUG |
7fd59977 |
1008 | cout<<"Compute angle faces are //"<<endl; |
1009 | #endif |
1010 | NullifyAIS(anAIS); |
1011 | return; |
1012 | } |
1013 | } else { |
1014 | // Curvilinear faces... |
1015 | isCurvilinear = Standard_True; |
1016 | } |
1017 | } // endif (ageom3.IsNull()) |
1018 | |
1019 | |
1020 | Standard_Boolean isplan(Standard_False); |
1021 | |
1022 | if (!isCurvilinear) { |
1023 | if (ageom3->IsKind(STANDARD_TYPE(Geom_Plane))) isplan = Standard_True; |
1024 | else if (ageom3->IsKind(STANDARD_TYPE(Geom_Line))) isplan = Standard_False; |
1025 | else { |
0797d9d3 |
1026 | #ifdef OCCT_DEBUG |
7fd59977 |
1027 | cout << "TPrsStd_ConstraintTools::ComputeAngle: unknown 3rd arg " << endl; |
1028 | #endif |
1029 | NullifyAIS(anAIS); |
1030 | return; |
1031 | } |
1032 | } |
1033 | Standard_Real val1; |
1034 | TCollection_ExtendedString txt; |
1035 | ComputeTextAndValue (aConst,val1,txt,Standard_True); |
1036 | |
1037 | Standard_Boolean toCreate (Standard_True); |
1038 | Standard_Boolean isface(shape1.ShapeType()==TopAbs_FACE); |
1039 | |
1040 | Handle(AIS_AngleDimension) ais; |
1041 | if (!anAIS.IsNull()) { |
1042 | ais = Handle(AIS_AngleDimension)::DownCast(anAIS); |
1043 | if( ais.IsNull() ) { |
1044 | toCreate = Standard_True; |
1045 | } |
1046 | else toCreate = Standard_False; |
1047 | } |
1048 | |
1049 | Standard_Integer ExtShape(0); |
1050 | if (toCreate) { |
1051 | // Creation de l'AIS |
1052 | if (isplan) { |
1053 | if(!isface) { |
1054 | FindExternalShape(aConst,ExtShape); |
1055 | GetGoodShape(shape1); |
1056 | GetGoodShape(shape2); |
1057 | ais = new AIS_AngleDimension (TopoDS::Edge(shape1), |
60bf98ae |
1058 | TopoDS::Edge(shape2)); |
7fd59977 |
1059 | } |
1060 | } |
1061 | else { |
1062 | if (isCurvilinear) { |
a6eb515f |
1063 | ais = new AIS_AngleDimension (TopoDS::Face(shape1), |
60bf98ae |
1064 | TopoDS::Face(shape2)); |
7fd59977 |
1065 | } |
1066 | else if (isface) { |
a6eb515f |
1067 | ais = new AIS_AngleDimension (TopoDS::Face(shape1), |
60bf98ae |
1068 | TopoDS::Face(shape2)); |
7fd59977 |
1069 | } |
1070 | } |
1071 | } |
1072 | else { |
1073 | // Update de l'AIS |
1074 | if (isplan) { |
1075 | GetGoodShape(shape1); |
1076 | GetGoodShape(shape2); |
1077 | } |
60bf98ae |
1078 | ais->SetMeasuredGeometry (TopoDS::Face (shape1), TopoDS::Face (shape2)); |
7fd59977 |
1079 | if (isplan) |
60bf98ae |
1080 | ais->SetCustomPlane (((Handle(Geom_Plane)&) ageom3)->Pln()); |
7fd59977 |
1081 | else if (!isCurvilinear) |
a6eb515f |
1082 | { |
1083 | gp_Pln aPlane; |
1084 | aPlane.SetAxis (((Handle(Geom_Line)&) ageom3)->Position()); |
60bf98ae |
1085 | ais->SetCustomPlane (aPlane); |
a6eb515f |
1086 | } |
7fd59977 |
1087 | } |
1088 | anAIS = ais; |
1089 | } |
1090 | |
1091 | |
1092 | //======================================================================= |
1093 | //function : ComputeConcentric |
1094 | //purpose : |
1095 | //======================================================================= |
1096 | void TPrsStd_ConstraintTools::ComputeConcentric(const Handle(TDataXtd_Constraint)& aConst, |
1097 | Handle(AIS_InteractiveObject)& anAIS) |
1098 | { |
1099 | Standard_Integer nbgeom = aConst->NbGeometries(); |
1100 | if (nbgeom < 2) { |
1101 | Standard_ProgramError::Raise ("TPrsStd_ConstraintTools::ComputeConcentric: at least 2 constraintes are needed"); |
1102 | } |
1103 | if (!aConst->IsPlanar()) { |
0797d9d3 |
1104 | #ifdef OCCT_DEBUG |
7fd59977 |
1105 | cout << "TPrsStd_ConstraintTools::ComputeConcentric: must be a planar constraint" << endl; |
1106 | #endif |
1107 | NullifyAIS(anAIS); |
1108 | return; |
1109 | } |
1110 | TopoDS_Shape shape1,shape2 ; |
1111 | Handle(Geom_Geometry) ageom3; |
1112 | |
1113 | GetShapesAndGeom(aConst,shape1,shape2,ageom3); |
1114 | if (shape1.IsNull() || shape2.IsNull()) { |
0797d9d3 |
1115 | #ifdef OCCT_DEBUG |
7fd59977 |
1116 | cout << "TPrsStd_ConstraintTools::ComputeConcentric : null shape" << endl; |
1117 | #endif |
1118 | NullifyAIS(anAIS); |
1119 | return; |
1120 | } |
1121 | |
1122 | GetGoodShape(shape1); |
1123 | GetGoodShape(shape2); |
1124 | |
1125 | //ota : to allow concentric constraint display between vertex and edge |
1126 | if (shape1.ShapeType() != TopAbs_EDGE && shape2.ShapeType() != TopAbs_EDGE) { |
0797d9d3 |
1127 | #ifdef OCCT_DEBUG |
7fd59977 |
1128 | cout << "TPrsStd_ConstraintTools::ComputeConcentric: concentric between two vertexes : NOT DISPLAYED" << endl;; |
1129 | #endif |
1130 | NullifyAIS(anAIS); |
1131 | return; |
1132 | } |
1133 | |
1134 | Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3); |
1135 | if (aplane.IsNull()) { |
0797d9d3 |
1136 | #ifdef OCCT_DEBUG |
7fd59977 |
1137 | cout << "TPrsStd_ConstraintTools::ComputeConcentric: nul plane" << endl;; |
1138 | #endif |
1139 | NullifyAIS(anAIS); |
1140 | return; |
1141 | } |
1142 | // Update de l'AIS |
1143 | Handle(AIS_ConcentricRelation) ais; |
1144 | if (!anAIS.IsNull()) { |
1145 | ais = Handle(AIS_ConcentricRelation)::DownCast(anAIS); |
1146 | if (ais.IsNull()) { |
1147 | ais = new AIS_ConcentricRelation (shape1,shape2,aplane); |
1148 | } |
1149 | else { |
1150 | ais->SetFirstShape(shape1); |
1151 | ais->SetSecondShape(shape2); |
1152 | ais->SetPlane(aplane); |
1153 | } |
1154 | } |
1155 | else { |
1156 | ais = new AIS_ConcentricRelation (shape1,shape2,aplane); |
1157 | } |
1158 | |
1159 | anAIS = ais; |
1160 | } |
1161 | |
1162 | //======================================================================= |
1163 | //function : ComputeRadius |
1164 | //purpose : |
1165 | //======================================================================= |
1166 | void TPrsStd_ConstraintTools::ComputeRadius (const Handle(TDataXtd_Constraint)& aConst, |
1167 | Handle(AIS_InteractiveObject)& anAIS) |
1168 | { |
1169 | Standard_Integer nbgeom = aConst->NbGeometries(); |
1170 | if (nbgeom < 1) { |
0797d9d3 |
1171 | #ifdef OCCT_DEBUG |
7fd59977 |
1172 | cout << "TPrsStd_ConstraintTools::ComputeRadius: at least one constrainte is needed" << endl; |
1173 | #endif |
1174 | NullifyAIS(anAIS); |
1175 | return; |
1176 | } |
1177 | |
1178 | TopoDS_Shape shape1 ; |
1179 | GetOneShape (aConst,shape1); |
1180 | if (shape1.IsNull()) { |
0797d9d3 |
1181 | #ifdef OCCT_DEBUG |
7fd59977 |
1182 | cout << "TPrsStd_ConstraintTools::ComputeRadius: null shape" << endl; |
1183 | #endif |
1184 | NullifyAIS(anAIS); |
1185 | return; |
1186 | } |
1187 | |
1188 | // POP on teste si ce n'est pas un compound |
1189 | if (shape1.ShapeType()==TopAbs_COMPOUND || |
1190 | shape1.ShapeType()==TopAbs_COMPSOLID || |
1191 | shape1.ShapeType()==TopAbs_SOLID || |
1192 | shape1.ShapeType()==TopAbs_SHELL ) { |
0797d9d3 |
1193 | #ifdef OCCT_DEBUG |
7fd59977 |
1194 | cout << "TPrsStd_ConstraintTools::ComputeRadius: not good shape" << endl; |
1195 | #endif |
1196 | NullifyAIS(anAIS); |
1197 | return; |
1198 | } |
1199 | |
1200 | if (IsFace(shape1)) |
1201 | shape1 = GetFace(shape1); |
1202 | |
1203 | Standard_Real val1; |
1204 | TCollection_ExtendedString txt; |
1205 | ComputeTextAndValue(aConst,val1,txt,Standard_False); |
1206 | |
1207 | // Update de l'AIS |
7fd59977 |
1208 | Standard_Boolean isplanar(aConst->IsPlanar()); |
1209 | if (isplanar) GetGoodShape(shape1); |
1210 | |
1211 | Handle(AIS_RadiusDimension) ais; |
1212 | if (!anAIS.IsNull()) { |
1213 | ais = Handle(AIS_RadiusDimension)::DownCast(anAIS); |
1214 | if (ais.IsNull()) { |
a6eb515f |
1215 | ais = new AIS_RadiusDimension (shape1); |
7fd59977 |
1216 | } |
1217 | else { |
60bf98ae |
1218 | ais->SetMeasuredGeometry(shape1); |
7fd59977 |
1219 | } |
1220 | } |
a6eb515f |
1221 | else ais = new AIS_RadiusDimension (shape1); |
7fd59977 |
1222 | |
1223 | if (isplanar) { |
1224 | Handle(Geom_Geometry) ageom2; |
1225 | GetGeom(aConst,ageom2); |
1226 | Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2); |
1227 | if (aplane.IsNull()) { |
0797d9d3 |
1228 | #ifdef OCCT_DEBUG |
7fd59977 |
1229 | cout << "TPrsStd_ConstraintTools::ComputeRadius: nul plane" << endl; |
1230 | #endif |
1231 | NullifyAIS(anAIS); |
1232 | return; |
1233 | } |
60bf98ae |
1234 | ais->SetCustomPlane(aplane->Pln()); |
7fd59977 |
1235 | } |
1236 | anAIS = ais; |
1237 | } |
1238 | // ota -- begin -- |
1239 | //======================================================================= |
1240 | //function : ComputeMinRadius |
1241 | //purpose : |
1242 | //======================================================================= |
1243 | void TPrsStd_ConstraintTools::ComputeMinRadius (const Handle(TDataXtd_Constraint)& aConst, |
1244 | Handle(AIS_InteractiveObject)& anAIS) |
1245 | { |
1246 | Standard_Integer nbgeom = aConst->NbGeometries(); |
1247 | if (nbgeom < 1) { |
0797d9d3 |
1248 | #ifdef OCCT_DEBUG |
7fd59977 |
1249 | cout << "TPrsStd_ConstraintTools::ComputeMinRadius: at least one constrainte is needed" << endl; |
1250 | #endif |
1251 | NullifyAIS(anAIS); |
1252 | return; |
1253 | } |
1254 | |
1255 | TopoDS_Shape shape1 ; |
1256 | GetOneShape (aConst,shape1); |
1257 | if (shape1.IsNull()) { |
0797d9d3 |
1258 | #ifdef OCCT_DEBUG |
7fd59977 |
1259 | cout << "TPrsStd_ConstraintTools::ComputeMinradius: null shape" << endl; |
1260 | #endif |
1261 | NullifyAIS(anAIS); |
1262 | return; |
1263 | } |
1264 | |
1265 | // POP on teste si ce n'est pas un compound |
1266 | if (shape1.ShapeType()==TopAbs_COMPOUND || |
1267 | shape1.ShapeType()==TopAbs_COMPSOLID || |
1268 | shape1.ShapeType()==TopAbs_SOLID || |
1269 | shape1.ShapeType()==TopAbs_SHELL ) { |
0797d9d3 |
1270 | #ifdef OCCT_DEBUG |
7fd59977 |
1271 | cout << "TPrsStd_ConstraintTools::ComputeMinRadius: not good shape" << endl; |
1272 | #endif |
1273 | NullifyAIS(anAIS); |
1274 | return; |
1275 | } |
1276 | |
1277 | if (IsFace(shape1)) |
1278 | shape1 = GetFace(shape1); |
1279 | |
1280 | Standard_Real val1; |
1281 | TCollection_ExtendedString txt; |
1282 | ComputeTextAndValue(aConst,val1,txt,Standard_False); |
1283 | |
1284 | // Update de l'AIS |
7fd59977 |
1285 | Standard_Boolean isplanar(aConst->IsPlanar()); |
1286 | if (isplanar) GetGoodShape(shape1); |
1287 | |
1288 | Handle(AIS_MinRadiusDimension) ais; |
1289 | if (!anAIS.IsNull()) { |
1290 | ais = Handle(AIS_MinRadiusDimension)::DownCast(anAIS); |
1291 | if (ais.IsNull()) { |
1292 | ais = new AIS_MinRadiusDimension (shape1,val1,txt); |
1293 | } |
1294 | else { |
1295 | ais->SetValue(val1); |
1296 | ais->SetFirstShape(shape1); |
1297 | ais->SetText(txt); |
1298 | } |
1299 | } |
1300 | else ais = new AIS_MinRadiusDimension (shape1,val1,txt); |
1301 | |
1302 | if (isplanar) { |
1303 | Handle(Geom_Geometry) ageom2; |
1304 | GetGeom(aConst,ageom2); |
1305 | Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2); |
1306 | if (aplane.IsNull()) { |
0797d9d3 |
1307 | #ifdef OCCT_DEBUG |
7fd59977 |
1308 | cout << "TPrsStd_ConstraintTools::ComputeMinRadius: nul plane" << endl; |
1309 | #endif |
1310 | NullifyAIS(anAIS); |
1311 | return; |
1312 | } |
1313 | ais->SetPlane(aplane); |
1314 | } |
1315 | anAIS = ais; |
1316 | } |
1317 | |
1318 | //======================================================================= |
1319 | //function : ComputeMaxRadius |
1320 | //purpose : |
1321 | //======================================================================= |
1322 | void TPrsStd_ConstraintTools::ComputeMaxRadius (const Handle(TDataXtd_Constraint)& aConst, |
1323 | Handle(AIS_InteractiveObject)& anAIS) |
1324 | { |
1325 | Standard_Integer nbgeom = aConst->NbGeometries(); |
1326 | if (nbgeom < 1) { |
0797d9d3 |
1327 | #ifdef OCCT_DEBUG |
7fd59977 |
1328 | cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: at least one constrainte is needed" << endl; |
1329 | #endif |
1330 | NullifyAIS(anAIS); |
1331 | return; |
1332 | } |
1333 | |
1334 | TopoDS_Shape shape1 ; |
1335 | GetOneShape (aConst,shape1); |
1336 | if (shape1.IsNull()) { |
0797d9d3 |
1337 | #ifdef OCCT_DEBUG |
7fd59977 |
1338 | cout << "TPrsStd_ConstraintTools::ComputeMaxradius: null shape" << endl; |
1339 | #endif |
1340 | NullifyAIS(anAIS); |
1341 | return; |
1342 | } |
1343 | |
1344 | // POP on teste si ce n'est pas un compound |
1345 | if (shape1.ShapeType()==TopAbs_COMPOUND || |
1346 | shape1.ShapeType()==TopAbs_COMPSOLID || |
1347 | shape1.ShapeType()==TopAbs_SOLID || |
1348 | shape1.ShapeType()==TopAbs_SHELL ) { |
0797d9d3 |
1349 | #ifdef OCCT_DEBUG |
7fd59977 |
1350 | cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: not good shape" << endl; |
1351 | #endif |
1352 | NullifyAIS(anAIS); |
1353 | return; |
1354 | } |
1355 | |
1356 | if (IsFace(shape1)) |
1357 | shape1 = GetFace(shape1); |
1358 | |
1359 | Standard_Real val1; |
1360 | TCollection_ExtendedString txt; |
1361 | ComputeTextAndValue(aConst,val1,txt,Standard_False); |
1362 | |
1363 | // Update de l'AIS |
7fd59977 |
1364 | Standard_Boolean isplanar(aConst->IsPlanar()); |
1365 | if (isplanar) GetGoodShape(shape1); |
1366 | |
1367 | Handle(AIS_MaxRadiusDimension) ais; |
1368 | if (!anAIS.IsNull()) { |
1369 | ais = Handle(AIS_MaxRadiusDimension)::DownCast(anAIS); |
1370 | if (ais.IsNull()) { |
1371 | ais = new AIS_MaxRadiusDimension (shape1,val1,txt); |
1372 | } |
1373 | else { |
1374 | ais->SetValue(val1); |
1375 | ais->SetFirstShape(shape1); |
1376 | ais->SetText(txt); |
1377 | } |
1378 | } |
1379 | else ais = new AIS_MaxRadiusDimension (shape1,val1,txt); |
1380 | |
1381 | if (isplanar) { |
1382 | Handle(Geom_Geometry) ageom2; |
1383 | GetGeom(aConst,ageom2); |
1384 | Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2); |
1385 | if (aplane.IsNull()) { |
0797d9d3 |
1386 | #ifdef OCCT_DEBUG |
7fd59977 |
1387 | cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: nul plane" << endl; |
1388 | #endif |
1389 | NullifyAIS(anAIS); |
1390 | return; |
1391 | } |
1392 | ais->SetPlane(aplane); |
1393 | } |
1394 | anAIS = ais; |
1395 | } |
1396 | |
1397 | //======================================================================= |
1398 | //function : ComputeEqualDistance |
1399 | //purpose : |
1400 | //======================================================================= |
1401 | void TPrsStd_ConstraintTools::ComputeEqualDistance(const Handle(TDataXtd_Constraint)& aConst, |
1402 | Handle(AIS_InteractiveObject)& anAIS) |
1403 | { |
1404 | Standard_Integer nbgeom = aConst->NbGeometries(); |
1405 | if (nbgeom < 4) { |
0797d9d3 |
1406 | #ifdef OCCT_DEBUG |
7fd59977 |
1407 | cout << "TPrsStd_ConstraintTools::ComputeEqual: at least four geometries are needed" << endl;; |
63c629aa |
1408 | #endif |
7fd59977 |
1409 | NullifyAIS(anAIS); |
1410 | return; |
1411 | } |
1412 | TopoDS_Shape aShape1, aShape2, aShape3, aShape4; |
1413 | Handle(Geom_Geometry) aGeom; |
1414 | GetShapesAndGeom(aConst, aShape1, aShape2, aShape3, aShape4, aGeom); |
1415 | if (aShape1.IsNull()||aShape2.IsNull()|| |
1416 | aShape3.IsNull()||aShape4.IsNull()) { |
0797d9d3 |
1417 | #ifdef OCCT_DEBUG |
7fd59977 |
1418 | cout << "TPrsStd_ConstraintTools::ComputeEqualDistance : null shape" << endl; |
1419 | #endif |
1420 | NullifyAIS(anAIS); |
1421 | return; |
1422 | } |
1423 | |
1424 | GetGoodShape(aShape1); |
1425 | GetGoodShape(aShape2); |
1426 | GetGoodShape(aShape3); |
1427 | GetGoodShape(aShape4); |
1428 | |
1429 | if (!CheckShapesPair(aShape1, aShape2) || |
1430 | !CheckShapesPair(aShape3, aShape4)){ |
0797d9d3 |
1431 | #ifdef OCCT_DEBUG |
7fd59977 |
1432 | cout << "TPrsStd_ConstraintTools::ComputeEqualDistance : at least one pair of shapes is incorrect"<<endl; |
1433 | #endif |
1434 | NullifyAIS(anAIS); |
1435 | return; |
1436 | } |
1437 | |
1438 | //Get the plane |
1439 | Standard_Boolean IsPlanar(aConst->IsPlanar()); |
1440 | Handle(Geom_Plane) aPlane ; |
1441 | if(IsPlanar) aPlane = Handle(Geom_Plane)::DownCast(aGeom) ; |
1442 | |
1443 | if (!IsPlanar || aPlane.IsNull()) { |
1444 | //create the plane |
0797d9d3 |
1445 | #ifdef OCCT_DEBUG |
7fd59977 |
1446 | cout<< "The constraint plane is not assigned "<< endl; |
1447 | #endif |
1448 | NullifyAIS(anAIS); |
1449 | return; |
1450 | } |
1451 | |
1452 | //Update AIS |
1453 | Handle(AIS_EqualDistanceRelation) ais; |
1454 | if (!anAIS.IsNull()) { |
1455 | { |
1456 | ais = Handle(AIS_EqualDistanceRelation)::DownCast(anAIS); |
1457 | |
1458 | if (ais.IsNull()) |
1459 | ais = new AIS_EqualDistanceRelation(aShape1, aShape2, aShape3, aShape4, aPlane); |
1460 | |
1461 | else { |
1462 | ais->SetFirstShape(aShape1); |
1463 | ais->SetSecondShape(aShape2); |
1464 | ais->SetShape3(aShape3); |
1465 | ais->SetShape4(aShape4); |
1466 | ais->SetPlane(aPlane); |
1467 | } |
1468 | } |
1469 | } |
1470 | else ais = new AIS_EqualDistanceRelation(aShape1, aShape2, aShape3, aShape4, aPlane); |
1471 | |
1472 | anAIS = ais; |
1473 | |
1474 | return; |
1475 | } |
1476 | |
1477 | //====================================================================== |
1478 | // function : CheckShapesPair |
1479 | // purpose : checks the types of two shapes. |
1480 | // If the types aShape1 and aShape2 are EDGE - EDGE, |
1481 | // or EDGE - VERTEX, |
1482 | // or VERTEX - VERTEX, |
1483 | // or CIRCLE - CIRCLE, |
1484 | // or CIRCLE - VERTEX, |
1485 | // then function returns TRUE, otherwise FALSE. |
1486 | //====================================================================== |
1487 | static Standard_Boolean CheckShapesPair(const TopoDS_Shape& aShape1, |
1488 | const TopoDS_Shape& aShape2) |
1489 | { |
1490 | //Check whether the shapes form a correct pair. |
1491 | if (aShape1.ShapeType() == TopAbs_EDGE && aShape2.ShapeType() == TopAbs_EDGE) |
1492 | { |
1493 | BRepAdaptor_Curve aCurve1(TopoDS::Edge(aShape1)); |
1494 | BRepAdaptor_Curve aCurve2(TopoDS::Edge(aShape2)); |
1495 | if (aCurve1.GetType() == GeomAbs_Line && aCurve2.GetType() == GeomAbs_Line) |
1496 | { //Are lines parallel ? |
1497 | gp_Dir aDir1 = aCurve1.Line().Direction(); |
1498 | gp_Dir aDir2 = aCurve2.Line().Direction(); |
1499 | if (!(aDir1.IsParallel(aDir2, Precision::Confusion()))) { |
0797d9d3 |
1500 | #ifdef OCCT_DEBUG |
7fd59977 |
1501 | cout << " Lines are not parallel"<<endl; |
1502 | #endif |
1503 | return Standard_False; |
1504 | } |
1505 | } |
1506 | else if (aCurve1.GetType() == GeomAbs_Circle && aCurve2.GetType() == GeomAbs_Circle) |
1507 | { |
1508 | gp_Pnt aCntr1 = aCurve1.Circle().Location(); //get the circle center |
1509 | gp_Pnt aCntr2 = aCurve2.Circle().Location(); //get the circle center |
1510 | if (!aCntr1.IsEqual(aCntr2,Precision::Confusion())){ |
0797d9d3 |
1511 | #ifdef OCCT_DEBUG |
7fd59977 |
1512 | cout << " Circles are not concentric"<<endl; |
1513 | #endif |
1514 | return Standard_False; |
1515 | } |
1516 | } |
1517 | else { |
0797d9d3 |
1518 | #ifdef OCCT_DEBUG |
7fd59977 |
1519 | cout << "Incorrect pair of curves "<<endl; |
1520 | #endif |
1521 | return Standard_False; |
1522 | } |
1523 | } |
1524 | else if ( aShape1.ShapeType() != TopAbs_VERTEX || aShape2.ShapeType() != TopAbs_VERTEX) |
1525 | { |
1526 | gp_Pnt aPnt; |
1527 | BRepAdaptor_Curve aCurve; |
1528 | if ( aShape1.ShapeType() == TopAbs_VERTEX) { |
1529 | aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape1)); |
1530 | aCurve.Initialize(TopoDS::Edge(aShape2)); |
1531 | } |
1532 | else { |
1533 | aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape2)); |
1534 | aCurve.Initialize(TopoDS::Edge(aShape1)); |
1535 | } |
1536 | if ( aCurve.GetType() == GeomAbs_Circle) |
1537 | { |
1538 | gp_Pnt aCntr = aCurve.Circle().Location(); |
1539 | if (!aCntr.IsEqual(aPnt, Precision::Confusion())){ |
0797d9d3 |
1540 | #ifdef OCCT_DEBUG |
7fd59977 |
1541 | cout << " The point doesn't coincide with the circle center"<<endl; |
1542 | #endif |
1543 | return Standard_False; |
1544 | } |
1545 | } |
1546 | } |
1547 | return Standard_True; |
1548 | } |
1549 | |
1550 | //======================================================================= |
1551 | //function : ComputeEqualRadius |
1552 | //purpose : |
1553 | //======================================================================= |
1554 | void TPrsStd_ConstraintTools::ComputeEqualRadius(const Handle(TDataXtd_Constraint)& aConst, |
1555 | Handle(AIS_InteractiveObject)& anAIS) |
1556 | { |
1557 | Standard_Integer nbgeom = aConst->NbGeometries(); |
1558 | if (nbgeom < 2) { |
0797d9d3 |
1559 | #ifdef OCCT_DEBUG |
7fd59977 |
1560 | cout << "TPrsStd_ConstraintTools::ComputeEqualRadius: at least two geometries are needed" << endl;; |
1561 | #endif |
1562 | NullifyAIS(anAIS); |
1563 | return; |
1564 | } |
1565 | TopoDS_Shape shape1, shape2; |
1566 | Handle(Geom_Geometry) ageom3; |
1567 | |
1568 | GetShapesAndGeom(aConst, shape1, shape2, ageom3); |
1569 | if (shape1.IsNull()||shape2.IsNull()) { |
0797d9d3 |
1570 | #ifdef OCCT_DEBUG |
7fd59977 |
1571 | cout << "TPrsStd_ConstraintTools::ComputeEqualRadius : null shape" << endl; |
1572 | #endif |
1573 | NullifyAIS(anAIS); |
1574 | return; |
1575 | } |
1576 | |
1577 | // Update AIS |
1578 | Standard_Boolean IsPlanar(aConst->IsPlanar()); |
1579 | |
1580 | GetGoodShape(shape1); |
1581 | GetGoodShape(shape2); |
1582 | const TopoDS_Edge edge1 = TopoDS::Edge(shape1); |
1583 | const TopoDS_Edge edge2 = TopoDS::Edge(shape2); |
1584 | Handle(Geom_Plane) aplane ; |
1585 | |
1586 | if (IsPlanar) aplane = Handle(Geom_Plane)::DownCast(ageom3) ; |
1587 | |
1588 | if (!IsPlanar || aplane.IsNull()) { |
1589 | // check are the planes of edge1 and edge2 coincident |
1590 | BRepAdaptor_Curve aCurve( edge1 ); |
1591 | Handle( Geom_Curve ) aProjCurve = aCurve.Curve().Curve(); |
1592 | gp_Circ aCircle = (Handle( Geom_Circle )::DownCast( aProjCurve ))->Circ(); |
1593 | gp_Ax3 anAx31(aCircle.Position()); //get the circle axis |
1594 | // get the circle plane |
1595 | Handle(Geom_Plane) aPlane1 = new Geom_Plane (anAx31); |
1596 | |
1597 | aCurve.Initialize(edge2); |
1598 | aProjCurve = aCurve.Curve().Curve(); |
1599 | aCircle = (Handle( Geom_Circle )::DownCast( aProjCurve ))->Circ(); |
1600 | gp_Ax3 anAx32(aCircle.Position()); //get the circle axis |
1601 | // get the circle plane |
1602 | Handle(Geom_Plane) aPlane2 = new Geom_Plane (anAx32); |
1603 | |
1604 | Standard_Real A, B, C ,D1, D2; |
1605 | aPlane1->Coefficients(A, B, C, D1);//Get normalized coefficients |
1606 | aPlane2->Coefficients(A, B, C, D2);//Get normalized coefficients |
1607 | const gp_Dir& aDir1 = anAx31.Direction(); |
1608 | const gp_Dir& aDir2 = anAx32.Direction(); |
1609 | |
1610 | if(Abs(D1 - D2) < Precision::Confusion() && |
1611 | aDir1.IsParallel(aDir2, Precision::Confusion())) |
1612 | aplane = aPlane2; |
1613 | else { |
0797d9d3 |
1614 | #ifdef OCCT_DEBUG |
7fd59977 |
1615 | cout << "TPrsStd_ConstraintTools::ComputeRadiusRelation: nul plane" << endl; |
1616 | #endif |
1617 | NullifyAIS(anAIS); |
1618 | return; |
1619 | } |
1620 | } |
1621 | Handle(AIS_EqualRadiusRelation) ais; |
1622 | if (!anAIS.IsNull()) { |
1623 | ais = Handle(AIS_EqualRadiusRelation)::DownCast(anAIS); |
1624 | |
1625 | if (ais.IsNull()) { |
1626 | ais = new AIS_EqualRadiusRelation(edge1, edge2, aplane); |
1627 | } |
1628 | else { |
1629 | ais->SetFirstShape(shape1); |
1630 | ais->SetSecondShape(shape2); |
1631 | ais->SetPlane(aplane); |
1632 | } |
1633 | } |
1634 | else { |
1635 | ais = new AIS_EqualRadiusRelation(edge1, edge2, aplane); |
1636 | } |
1637 | |
1638 | anAIS = ais; |
1639 | } |
1640 | //ota -- end -- |
1641 | |
1642 | //======================================================================= |
1643 | //function : ComputeDiameter |
1644 | //purpose : |
1645 | //======================================================================= |
1646 | void TPrsStd_ConstraintTools::ComputeDiameter(const Handle(TDataXtd_Constraint)& aConst, |
1647 | Handle(AIS_InteractiveObject)& anAIS) |
1648 | { |
1649 | Standard_Integer nbgeom = aConst->NbGeometries(); |
1650 | if (nbgeom < 1) { |
0797d9d3 |
1651 | #ifdef OCCT_DEBUG |
7fd59977 |
1652 | cout << "TPrsStd_ConstraintTools::ComputeDiameter: at least one constrainte is needed" << endl;; |
1653 | #endif |
1654 | NullifyAIS(anAIS); |
1655 | return; |
1656 | } |
1657 | TopoDS_Shape shape1 ; |
1658 | |
1659 | GetOneShape(aConst,shape1); |
1660 | if (shape1.IsNull()) { |
0797d9d3 |
1661 | #ifdef OCCT_DEBUG |
7fd59977 |
1662 | cout << "TPrsStd_ConstraintTools::ComputeDiameter : null shape" << endl; |
1663 | #endif |
1664 | NullifyAIS(anAIS); |
1665 | return; |
1666 | } |
1667 | Standard_Real val1; |
1668 | TCollection_ExtendedString txt; |
1669 | ComputeTextAndValue(aConst,val1,txt,Standard_False); |
1670 | |
1671 | // Update de l'AIS |
1672 | Standard_Boolean IsPlanar(aConst->IsPlanar()); |
1673 | if (IsPlanar) GetGoodShape(shape1); |
1674 | Handle(AIS_DiameterDimension) ais; |
1675 | if (!anAIS.IsNull()) { |
1676 | ais = Handle(AIS_DiameterDimension)::DownCast(anAIS); |
1677 | if (ais.IsNull()) { |
a6eb515f |
1678 | ais = new AIS_DiameterDimension (shape1); |
7fd59977 |
1679 | } |
1680 | else { |
60bf98ae |
1681 | ais->SetMeasuredGeometry(shape1); |
7fd59977 |
1682 | } |
1683 | } |
a6eb515f |
1684 | else ais = new AIS_DiameterDimension (shape1); |
7fd59977 |
1685 | |
1686 | if (IsPlanar) { |
1687 | Handle(Geom_Geometry) ageom2; |
1688 | GetGeom(aConst,ageom2); |
1689 | Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2); |
1690 | if (aplane.IsNull()) { |
0797d9d3 |
1691 | #ifdef OCCT_DEBUG |
7fd59977 |
1692 | cout << "TPrsStd_ConstraintTools::ComputeDiameter: nul plane" << endl; |
1693 | #endif |
1694 | NullifyAIS(anAIS); |
1695 | return; |
1696 | } |
60bf98ae |
1697 | //ais->SetCustomPlane(aplane); |
7fd59977 |
1698 | } |
1699 | anAIS = ais; |
1700 | } |
1701 | |
1702 | |
1703 | //======================================================================= |
1704 | //function : ComputeFix |
1705 | //purpose : |
1706 | //======================================================================= |
1707 | void TPrsStd_ConstraintTools::ComputeFix(const Handle(TDataXtd_Constraint)& aConst, |
1708 | Handle(AIS_InteractiveObject)& anAIS) |
1709 | { |
1710 | Standard_Integer nbgeom = aConst->NbGeometries(); |
1711 | if (nbgeom < 1) { |
0797d9d3 |
1712 | #ifdef OCCT_DEBUG |
7fd59977 |
1713 | cout << "TPrsStd_ConstraintTools::ComputeFix: at least one constrainte is needed" << endl;; |
1714 | #endif |
1715 | NullifyAIS(anAIS); |
1716 | return; |
1717 | } |
1718 | if (!aConst->IsPlanar()) { |
0797d9d3 |
1719 | #ifdef OCCT_DEBUG |
7fd59977 |
1720 | cout << "TPrsStd_ConstraintTools::ComputeFix: must be a planar constraint" << endl;; |
1721 | #endif |
1722 | NullifyAIS(anAIS); |
1723 | return; |
1724 | } |
1725 | |
1726 | TopoDS_Shape shape1 ; |
1727 | Handle(Geom_Geometry) ageom2; |
1728 | |
1729 | GetOneShape(aConst,shape1); |
1730 | if (shape1.IsNull()) { |
0797d9d3 |
1731 | #ifdef OCCT_DEBUG |
7fd59977 |
1732 | cout << "TPrsStd_ConstraintTools::ComputeFix : null shape" << endl; |
1733 | #endif |
1734 | NullifyAIS(anAIS); |
1735 | return; |
1736 | } |
1737 | GetGoodShape(shape1); |
1738 | GetGeom(aConst,ageom2); |
1739 | Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2); |
1740 | if (aplane.IsNull()) { |
0797d9d3 |
1741 | #ifdef OCCT_DEBUG |
7fd59977 |
1742 | cout << "TPrsStd_ConstraintTools::ComputeFix: nul plane" << endl; |
1743 | #endif |
1744 | NullifyAIS(anAIS); |
1745 | return; |
1746 | } |
1747 | // Update de l'AIS |
1748 | Handle(AIS_FixRelation) ais; |
1749 | if (!anAIS.IsNull()) { |
1750 | ais = Handle(AIS_FixRelation)::DownCast(anAIS); |
1751 | if (ais.IsNull()) { |
1752 | ais = new AIS_FixRelation (shape1,aplane); |
1753 | } |
1754 | else { |
1755 | ais->SetFirstShape(shape1); |
1756 | ais->SetPlane(aplane); |
1757 | } |
1758 | } |
1759 | else ais = new AIS_FixRelation (shape1,aplane); |
1760 | |
1761 | anAIS = ais; |
1762 | } |
1763 | |
1764 | //======================================================================= |
1765 | //function : ComputeOffset |
1766 | //purpose : |
1767 | //======================================================================= |
1768 | void TPrsStd_ConstraintTools::ComputeOffset (const Handle(TDataXtd_Constraint)& aConst, |
1769 | Handle(AIS_InteractiveObject)& anAIS) |
1770 | { |
1771 | // Get plane for planar constraint |
1772 | Standard_Boolean is_planar (aConst->IsPlanar()); |
1773 | Handle(Geom_Plane) aplane; |
1774 | if (is_planar) { |
1775 | GetGeom (aConst,aplane); |
1776 | if (aplane.IsNull()) { |
0797d9d3 |
1777 | #ifdef OCCT_DEBUG |
7fd59977 |
1778 | cout << "TPrsStd_ConstraintTools::ComputeOffset: null plane" << endl; |
1779 | #endif |
1780 | NullifyAIS(anAIS); |
1781 | return; |
1782 | } |
1783 | } |
1784 | |
1785 | // Get shapes |
1786 | TopoDS_Shape S1, S2; |
1787 | Standard_Integer nbgeom = aConst->NbGeometries(); |
1788 | if (nbgeom == 1) { |
1789 | Handle(TNaming_NamedShape) ageom1 = aConst->GetGeometry(1); |
1790 | // c'est une shape qui contient les faces generees par les faces d'origines |
1791 | TNaming_Iterator It (ageom1); |
1792 | if (It.More()) { |
1793 | S1 = It.OldShape(); |
1794 | S2 = It.NewShape(); |
1795 | } |
1796 | } |
1797 | else |
1798 | if (nbgeom == 2) { |
1799 | // Get geometry of the constraint |
1800 | GetTwoShapes (aConst,S1,S2); |
1801 | } |
1802 | |
1803 | if (S1.IsNull() || S2.IsNull()) { |
0797d9d3 |
1804 | #ifdef OCCT_DEBUG |
7fd59977 |
1805 | cout << "TPrsStd_ConstraintTools::ComputeOffset: null shape" << endl; |
1806 | #endif |
1807 | NullifyAIS(anAIS); |
1808 | return; |
1809 | } |
1810 | |
1811 | |
1812 | Standard_Real val1; |
1813 | TCollection_ExtendedString txt; |
1814 | Handle(AIS_LengthDimension) ais; |
1815 | //Handle(AIS_Drawer) aDrawer; |
7fd59977 |
1816 | |
a6eb515f |
1817 | if (nbgeom == 1) |
1818 | { |
7fd59977 |
1819 | ComputeTextAndValue (aConst,val1,txt,Standard_False); |
a6eb515f |
1820 | if (!anAIS.IsNull()) |
1821 | { |
7fd59977 |
1822 | ais = Handle(AIS_LengthDimension)::DownCast(anAIS); |
7fd59977 |
1823 | } |
a6eb515f |
1824 | |
1825 | if (S1.ShapeType() == TopAbs_FACE && S2.ShapeType() == TopAbs_FACE) |
1826 | { |
1827 | if (ais.IsNull()) |
1828 | { |
1829 | ais = new AIS_LengthDimension (TopoDS::Face(S1),TopoDS::Face(S2)); |
7fd59977 |
1830 | } |
a6eb515f |
1831 | else |
1832 | { |
60bf98ae |
1833 | ais->SetMeasuredShapes (S1, S2); |
a6eb515f |
1834 | ais->SetCustomValue(val1); |
7fd59977 |
1835 | } |
1836 | |
a6eb515f |
1837 | if (is_planar) |
60bf98ae |
1838 | ais->SetCustomPlane (aplane->Pln()); |
a6eb515f |
1839 | anAIS = ais; |
7fd59977 |
1840 | return; |
1841 | } |
1842 | else |
1843 | if (S1.ShapeType() == TopAbs_EDGE && S2.ShapeType() == TopAbs_EDGE) { |
1844 | // Find a plane for the dimension |
1845 | TopoDS_Edge OE = TopoDS::Edge(S1); |
1846 | BRepAdaptor_Curve CURVE(OE); |
1847 | if (CURVE.GetType() == GeomAbs_Line) { |
1848 | // Works only with line !! |
0797d9d3 |
1849 | //#ifndef OCCT_DEBUG |
857ffd5e |
1850 | Handle(Geom_Geometry) aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ; |
7fd59977 |
1851 | gp_Lin OLin = ((Handle(Geom_Line)&) aGeomGeometry)->Lin(); |
1852 | //#else |
1853 | // gp_Lin OLin = ((Handle(Geom_Line)&) CURVE.Curve().Curve()->Transformed(CURVE.Trsf()))->Lin(); |
1854 | //#endif |
1855 | TopoDS_Edge NE = TopoDS::Edge(S2); |
1856 | CURVE.Initialize (NE); |
0797d9d3 |
1857 | //#ifndef OCCT_DEBUG |
7fd59977 |
1858 | aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ; |
1859 | gp_Lin NLin = ((Handle(Geom_Line)&)aGeomGeometry)->Lin(); |
1860 | //#else |
1861 | // gp_Lin NLin = ((Handle(Geom_Line)&) CURVE.Curve().Curve()->Transformed(CURVE.Trsf()))->Lin(); |
1862 | //#endif |
1863 | gp_Dir TDir (NLin.Location().XYZ() - OLin.Location().XYZ()); |
1864 | aplane = new Geom_Plane (NLin.Location(),NLin.Direction()^TDir); |
1865 | |
1866 | if (ais.IsNull()) { |
a6eb515f |
1867 | ais = new AIS_LengthDimension (S1,S2,aplane->Pln()); |
7fd59977 |
1868 | } |
1869 | else { |
60bf98ae |
1870 | ais->SetMeasuredShapes (S1, S2); |
a6eb515f |
1871 | ais->SetCustomValue(val1); |
1872 | |
60bf98ae |
1873 | ais->SetCustomPlane (aplane->Pln()); |
7fd59977 |
1874 | } |
1875 | anAIS = ais; |
1876 | return; |
1877 | } |
1878 | else |
1879 | if (CURVE.GetType() == GeomAbs_Circle) { |
0797d9d3 |
1880 | //#ifndef OCCT_DEBUG |
857ffd5e |
1881 | Handle(Geom_Geometry) aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ; |
7fd59977 |
1882 | gp_Ax1 ax = ((Handle(Geom_Circle)&) aGeomGeometry)->Circ().Axis(); |
1883 | //#else |
1884 | // gp_Ax1 ax = ((Handle(Geom_Circle)&) CURVE.Curve().Curve()->Transformed(CURVE.Trsf()))->Circ().Axis(); |
1885 | //#endif |
1886 | aplane = new Geom_Plane (ax.Location(),ax.Direction()); |
1887 | is_planar = Standard_True; |
1888 | } |
1889 | } |
1890 | } |
1891 | |
1892 | |
1893 | if (!is_planar) { |
1894 | if (S1.ShapeType() == TopAbs_COMPOUND && |
1895 | S2.ShapeType() == TopAbs_COMPOUND) { |
1896 | // Resultat d'un offset - on reconstruit un wire pour determiner un plan |
1897 | TopoDS_Wire w1; |
1898 | BRep_Builder B; |
1899 | B.MakeWire (w1); |
1900 | TopExp_Explorer exp (S1,TopAbs_EDGE); |
1901 | for (;exp.More();exp.Next()) |
1902 | B.Add (w1,exp.Current()); |
1903 | |
1904 | BRepBuilderAPI_MakeFace MkF (w1,Standard_True); |
1905 | if (MkF.IsDone()) { |
0797d9d3 |
1906 | //#ifndef OCCT_DEBUG |
857ffd5e |
1907 | Handle(Geom_Surface) aGeomSurface = BRep_Tool::Surface(MkF.Face()); |
7fd59977 |
1908 | aplane = (Handle(Geom_Plane)&) aGeomSurface ; |
1909 | //#else |
1910 | // aplane = ((Handle(Geom_Plane)&) BRep_Tool::Surface(MkF.Face())); |
1911 | //#endif |
1912 | is_planar = Standard_True; |
1913 | } |
1914 | } |
1915 | } |
1916 | |
1917 | if (is_planar) { |
1918 | ComputeTextAndValue (aConst,val1,txt,Standard_False); |
1919 | TopExp_Explorer EXP1 (S1,TopAbs_VERTEX); |
1920 | S1 = EXP1.Current(); |
1921 | gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(S1)); |
1922 | |
1923 | TopoDS_Vertex nearest; |
1924 | Standard_Real dist(RealLast()); |
1925 | |
1926 | for (TopExp_Explorer EXP2(S2,TopAbs_VERTEX); EXP2.More(); EXP2.Next()) { |
1927 | const TopoDS_Vertex& current = TopoDS::Vertex(EXP2.Current()); |
1928 | gp_Pnt curpnt = BRep_Tool::Pnt(current); |
1929 | Standard_Real curdist = P.SquareDistance(curpnt); |
1930 | if (curdist < dist) { |
1931 | nearest= current; |
1932 | dist = curdist; |
1933 | } |
1934 | } |
1935 | S2 = nearest; |
7fd59977 |
1936 | ais = Handle(AIS_LengthDimension)::DownCast(anAIS); |
1937 | if (ais.IsNull()) { |
a6eb515f |
1938 | ais = new AIS_LengthDimension (S1,S2,aplane->Pln()); |
7fd59977 |
1939 | } |
1940 | else { |
60bf98ae |
1941 | ais->SetMeasuredShapes (S1, S2); |
a6eb515f |
1942 | ais->SetCustomValue (val1); |
60bf98ae |
1943 | ais->SetCustomPlane (aplane->Pln ()); |
7fd59977 |
1944 | } |
1945 | anAIS = ais; |
1946 | return; |
1947 | } |
1948 | |
0797d9d3 |
1949 | #ifdef OCCT_DEBUG |
7fd59977 |
1950 | cout << "TPrsStd_ConstraintTools::ComputeOffset: Case not implemented" << endl; |
1951 | #endif |
1952 | NullifyAIS(anAIS); |
1953 | } |
1954 | |
1955 | |
1956 | //======================================================================= |
1957 | //function : ComputePlacement |
1958 | //purpose : |
1959 | //======================================================================= |
1960 | void TPrsStd_ConstraintTools::ComputePlacement |
1961 | (const Handle(TDataXtd_Constraint)& aConst, |
1962 | Handle(AIS_InteractiveObject)& anAIS) |
1963 | { |
1964 | Standard_Integer nbgeom = aConst->NbGeometries(); |
1965 | if (nbgeom < 2) |
1966 | Standard_ProgramError::Raise |
1967 | ("TPrsStd_ConstraintTools::ComputePlacement: at leat two constraints are needed"); |
1968 | |
1969 | TopoDS_Shape shape1,shape2 ; |
1970 | GetTwoShapes(aConst,shape1,shape2); |
1971 | if (shape1.IsNull() || shape2.IsNull()) { |
0797d9d3 |
1972 | #ifdef OCCT_DEBUG |
7fd59977 |
1973 | cout << "TPrsStd_ConstraintTools::ComputePlacement: nul shape" << endl; |
1974 | #endif |
1975 | NullifyAIS(anAIS); |
1976 | return; |
1977 | } |
1978 | |
1979 | Standard_Real val1=0.0; |
1980 | TCollection_ExtendedString txt= " "; |
1981 | if (aConst->IsDimension()) { |
1982 | ComputeTextAndValue(aConst,val1,txt,Standard_False); |
1983 | } |
1984 | // Update de l'AIS |
1985 | Handle(AIS_OffsetDimension) ais; |
1986 | if (anAIS.IsNull()) { |
1987 | ais = new AIS_OffsetDimension(GetFace(shape1),GetFace(shape2),val1,txt); |
1988 | ais->SetArrowSize(val1/20.); |
1989 | } else { |
1990 | ais = Handle(AIS_OffsetDimension)::DownCast(anAIS); |
1991 | if (ais.IsNull()) { |
1992 | ais = new AIS_OffsetDimension(GetFace(shape1),GetFace(shape2),val1,txt); |
1993 | ais->SetArrowSize(val1/20.); |
1994 | } else { |
1995 | ais->SetFirstShape(GetFace(shape1)); |
1996 | ais->SetSecondShape(GetFace(shape2)); |
1997 | ais->SetValue(val1); |
1998 | ais->SetText(txt); |
1999 | ais->SetArrowSize(val1/20.); |
2000 | } |
2001 | } |
2002 | if (GetFace(shape1).IsNull() || GetFace(shape2).IsNull()) ais.Nullify(); |
2003 | anAIS = ais; |
2004 | } |
2005 | |
2006 | //======================================================================= |
2007 | //function : ComputeOthers |
2008 | //purpose : |
2009 | //======================================================================= |
2010 | void TPrsStd_ConstraintTools::ComputeOthers |
302f96fb |
2011 | (const Handle(TDataXtd_Constraint)& /*aConst*/, |
35e08fe8 |
2012 | Handle(AIS_InteractiveObject)& /*anAIS*/) |
7fd59977 |
2013 | { |
2014 | } |
2015 | |
2016 | //======================================================================= |
2017 | //function : GetOneShape |
2018 | //purpose : |
2019 | //======================================================================= |
2020 | void TPrsStd_ConstraintTools::GetOneShape |
2021 | (const Handle(TDataXtd_Constraint)& aConst, |
2022 | TopoDS_Shape& aShape) |
2023 | { |
2024 | const Handle(TNaming_NamedShape)& ageom1 = aConst->GetGeometry(1); |
2025 | if (!ageom1.IsNull()) aShape = TNaming_Tool::CurrentShape(ageom1); |
2026 | } |
2027 | |
2028 | //======================================================================= |
2029 | //function : GetTwoShapes |
2030 | //purpose : |
2031 | //======================================================================= |
2032 | void TPrsStd_ConstraintTools::GetTwoShapes |
2033 | (const Handle(TDataXtd_Constraint)& aConst, |
2034 | TopoDS_Shape& aShape1, |
2035 | TopoDS_Shape& aShape2) |
2036 | { |
2037 | const Handle(TNaming_NamedShape)& ageom1 = aConst->GetGeometry(1); |
2038 | if (!ageom1.IsNull()) aShape1 = TNaming_Tool::CurrentShape(aConst->GetGeometry(1)); |
2039 | const Handle(TNaming_NamedShape)& ageom2 = aConst->GetGeometry(2); |
2040 | if (!ageom2.IsNull()) aShape2 = TNaming_Tool::CurrentShape(aConst->GetGeometry(2)); |
2041 | } |
2042 | |
2043 | //======================================================================= |
2044 | //function : GetShapesAndGeom |
2045 | //purpose : |
2046 | //======================================================================= |
2047 | void TPrsStd_ConstraintTools::GetShapesAndGeom |
2048 | (const Handle(TDataXtd_Constraint)& aConst, |
2049 | TopoDS_Shape& aShape1, |
2050 | TopoDS_Shape& aShape2, |
2051 | Handle(Geom_Geometry)& aGeom) |
2052 | { |
2053 | GetTwoShapes(aConst,aShape1,aShape2); |
2054 | GetGeom(aConst,aGeom); |
2055 | } |
2056 | |
2057 | //======================================================================= |
2058 | //function : GetShapesAndGeom |
2059 | //purpose : |
2060 | //======================================================================= |
2061 | void TPrsStd_ConstraintTools::GetShapesAndGeom |
2062 | (const Handle(TDataXtd_Constraint)& aConst, |
2063 | TopoDS_Shape& aShape1, |
2064 | TopoDS_Shape& aShape2, |
2065 | TopoDS_Shape& aShape3, |
2066 | Handle(Geom_Geometry)& aGeom) |
2067 | { |
2068 | GetTwoShapes(aConst,aShape1,aShape2); |
2069 | const Handle(TNaming_NamedShape)& ageom3 = aConst->GetGeometry(3);//ota: GetGeometry(2) was |
2070 | if (!ageom3.IsNull()) aShape3 = TNaming_Tool::CurrentShape(aConst->GetGeometry(3)); |
2071 | GetGeom(aConst,aGeom); |
2072 | } |
2073 | |
2074 | //======================================================================= |
2075 | //function : GetShapesAndGeom |
2076 | //purpose : |
2077 | //======================================================================= |
2078 | void TPrsStd_ConstraintTools::GetShapesAndGeom |
2079 | (const Handle(TDataXtd_Constraint)& aConst, |
2080 | TopoDS_Shape& aShape1, |
2081 | TopoDS_Shape& aShape2, |
2082 | TopoDS_Shape& aShape3, |
2083 | TopoDS_Shape& aShape4, |
2084 | Handle(Geom_Geometry)& aGeom) |
2085 | { |
2086 | GetTwoShapes(aConst,aShape1, aShape2 ); |
2087 | const Handle(TNaming_NamedShape)& ageom3 = aConst->GetGeometry(3); |
2088 | if (!ageom3.IsNull()) aShape3 = TNaming_Tool::CurrentShape(aConst->GetGeometry(3)); |
2089 | const Handle(TNaming_NamedShape)& ageom4 = aConst->GetGeometry(4); |
2090 | if (!ageom4.IsNull()) aShape4 = TNaming_Tool::CurrentShape(aConst->GetGeometry(4)); |
2091 | GetGeom(aConst,aGeom); |
2092 | } |
2093 | |
2094 | //======================================================================= |
2095 | //function : ComputeCoincident |
2096 | //purpose : |
2097 | //======================================================================= |
2098 | void TPrsStd_ConstraintTools::ComputeCoincident(const Handle(TDataXtd_Constraint)& aConst, |
2099 | Handle(AIS_InteractiveObject)& anAIS) |
2100 | { |
2101 | Standard_Integer nbgeom = aConst->NbGeometries(); |
2102 | if (nbgeom < 2) { |
0797d9d3 |
2103 | #ifdef OCCT_DEBUG |
7fd59977 |
2104 | cout << "TPrsStd_ConstraintTools::ComputeCoincident: at leat two constraintes are needed" << endl; |
2105 | #endif |
2106 | NullifyAIS(anAIS); |
2107 | return; |
2108 | } |
2109 | |
2110 | if (!aConst->IsPlanar()) { |
0797d9d3 |
2111 | #ifdef OCCT_DEBUG |
7fd59977 |
2112 | cout << "TPrsStd_ConstraintTools::ComputeCoincident: must be a planar constraint" << endl; |
2113 | #endif |
2114 | anAIS.Nullify() ; |
2115 | return; |
2116 | } |
2117 | |
2118 | TopoDS_Shape shape1,shape2 ; |
2119 | Handle(Geom_Plane) aplane; |
2120 | GetShapesAndGeom(aConst,shape1,shape2,aplane); |
2121 | if (shape1.IsNull() || shape2.IsNull()) { |
0797d9d3 |
2122 | #ifdef OCCT_DEBUG |
7fd59977 |
2123 | cout << "TPrsStd_ConstraintTools::ComputeCoincident: nul shape" << endl; |
2124 | #endif |
2125 | NullifyAIS(anAIS); |
2126 | return; |
2127 | } |
2128 | |
2129 | GetGoodShape(shape1); |
2130 | GetGoodShape(shape2); |
2131 | if (aplane.IsNull()) { |
0797d9d3 |
2132 | #ifdef OCCT_DEBUG |
7fd59977 |
2133 | cout << "TPrsStd_ConstraintTools::ComputeCoincident: nul plane" << endl; |
2134 | #endif |
2135 | NullifyAIS(anAIS); |
2136 | return; |
2137 | } |
2138 | |
2139 | // Update de l'AIS |
2140 | Handle(AIS_IdenticRelation) ais; |
2141 | if (anAIS.IsNull()) ais = new AIS_IdenticRelation(shape1,shape2,aplane); |
2142 | else { |
2143 | ais = Handle(AIS_IdenticRelation)::DownCast(anAIS); |
2144 | if (ais.IsNull()) { |
2145 | ais = new AIS_IdenticRelation(shape1,shape2,aplane); |
2146 | } |
2147 | else { |
2148 | ais->SetFirstShape(shape1); |
2149 | ais->SetSecondShape(shape2); |
2150 | ais->SetPlane(aplane); |
2151 | } |
2152 | } |
2153 | anAIS = ais; |
2154 | } |
2155 | |
2156 | //======================================================================= |
2157 | //function : ComputeRound |
2158 | //purpose : |
2159 | //======================================================================= |
2160 | void TPrsStd_ConstraintTools::ComputeRound(const Handle(TDataXtd_Constraint)& aConst, |
2161 | Handle(AIS_InteractiveObject)& anAIS) |
2162 | { |
2163 | Standard_Integer nbgeom = aConst->NbGeometries(); |
2164 | if (nbgeom < 1) { |
0797d9d3 |
2165 | #ifdef OCCT_DEBUG |
7fd59977 |
2166 | cout << "TPrsStd_ConstraintTools::ComputeRound: at leat one geometry is needed" << endl; |
2167 | #endif |
2168 | NullifyAIS(anAIS); |
2169 | return; |
2170 | } |
2171 | TopoDS_Shape shape1; |
2172 | GetOneShape (aConst,shape1); |
2173 | if (shape1.IsNull()) { |
0797d9d3 |
2174 | #ifdef OCCT_DEBUG |
7fd59977 |
2175 | cout << "TPrsStd_ConstraintTools::ComputePlacement: nul shape" << endl; |
2176 | #endif |
2177 | NullifyAIS(anAIS); |
2178 | return; |
2179 | } |
2180 | |
2181 | Standard_Real val1; |
2182 | TCollection_ExtendedString txt; |
2183 | ComputeTextAndValue(aConst,val1,txt,Standard_False); |
2184 | |
2185 | // Update de l'AIS |
2186 | Handle(AIS_RadiusDimension) ais; |
2187 | |
2188 | { |
2189 | try { |
2190 | OCC_CATCH_SIGNALS |
2191 | if (anAIS.IsNull()) ais = |
a6eb515f |
2192 | new AIS_RadiusDimension(shape1); |
7fd59977 |
2193 | else { |
2194 | ais = Handle(AIS_RadiusDimension)::DownCast(anAIS); |
2195 | if (ais.IsNull()) { |
a6eb515f |
2196 | ais = new AIS_RadiusDimension(shape1); |
7fd59977 |
2197 | } |
2198 | else { |
60bf98ae |
2199 | ais->SetMeasuredGeometry(shape1); |
7fd59977 |
2200 | } |
2201 | } |
2202 | } |
2203 | catch(Standard_Failure) { |
2204 | ais.Nullify(); |
2205 | } |
2206 | } |
2207 | anAIS = ais; |
2208 | } |
2209 | |
2210 | //======================================================================= |
2211 | //function : GetGeom |
2212 | //purpose : |
2213 | //======================================================================= |
2214 | void TPrsStd_ConstraintTools::GetGeom(const Handle(TDataXtd_Constraint)& aConst, |
2215 | Handle(Geom_Geometry)& aGeom) |
2216 | { |
2217 | Handle(TNaming_NamedShape) atgeom = aConst->GetPlane(); |
2218 | if (atgeom.IsNull()) { |
0797d9d3 |
2219 | #ifdef OCCT_DEBUG |
7fd59977 |
2220 | cout<<"TPrsStd_ConstraintTools::GetGeom : aConst->GetPlane().IsNull()"<<endl; |
2221 | #endif |
2222 | return; |
2223 | } |
2224 | gp_Pln aplane; |
2225 | gp_Lin anaxis; |
2226 | gp_Pnt apoint; |
2227 | |
2228 | TDF_Label label = atgeom->Label(); |
2229 | |
2230 | Handle(TNaming_NamedShape) NS; |
2231 | if(label.FindAttribute(TNaming_NamedShape::GetID(),NS)){ |
2232 | TopoDS_Shape s = TNaming_Tool::GetShape(NS); |
2233 | if(s.IsNull()) return; |
2234 | } |
2235 | |
2236 | if (TDataXtd_Geometry::Plane(label,aplane)) aGeom = new Geom_Plane(aplane); |
2237 | else if (TDataXtd_Geometry::Line(label,anaxis)) aGeom = new Geom_Line(anaxis); |
2238 | else if (TDataXtd_Geometry::Point(label,apoint)) aGeom = new Geom_CartesianPoint(apoint); |
0797d9d3 |
2239 | #ifdef OCCT_DEBUG |
7fd59977 |
2240 | else { |
2241 | cout << "TPrsStd_ConstraintTools::GetGeom no geom on label " << endl; |
2242 | } |
2243 | #endif |
2244 | } |
2245 | |