b311480e |
1 | // Created on: 1996-12-05 |
2 | // Created by: Arnaud BOUZY/Odile Olivier |
3 | // Copyright (c) 1996-1999 Matra Datavision |
a6eb515f |
4 | // Copyright (c) 1999-2013 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
a6eb515f |
17 | #include <AIS_LengthDimension.hxx> |
7fd59977 |
18 | |
19 | #include <AIS.hxx> |
a6eb515f |
20 | #include <BRep_Tool.hxx> |
7fd59977 |
21 | #include <BRepAdaptor_Curve.hxx> |
a6eb515f |
22 | #include <BRepLib_MakeVertex.hxx> |
23 | #include <BRepTopAdaptor_FClass2d.hxx> |
60bf98ae |
24 | #include <BRepTools.hxx> |
7fd59977 |
25 | #include <ElCLib.hxx> |
26 | #include <ElSLib.hxx> |
a6eb515f |
27 | #include <gce_MakeDir.hxx> |
60bf98ae |
28 | #include <gce_MakePln.hxx> |
29 | #include <GeomAPI_ExtremaCurveCurve.hxx> |
30 | #include <GeomAPI_ExtremaCurveSurface.hxx> |
31 | #include <GeomAPI_ExtremaSurfaceSurface.hxx> |
32 | #include <Geom_Curve.hxx> |
33 | #include <Geom_Line.hxx> |
7fd59977 |
34 | #include <TopExp.hxx> |
35 | #include <TopExp_Explorer.hxx> |
7fd59977 |
36 | |
a6eb515f |
37 | IMPLEMENT_STANDARD_HANDLE(AIS_LengthDimension, AIS_Dimension) |
38 | IMPLEMENT_STANDARD_RTTIEXT(AIS_LengthDimension, AIS_Dimension) |
7fd59977 |
39 | |
40 | //======================================================================= |
41 | //function : Constructor |
60bf98ae |
42 | //purpose : Dimension between two faces |
43 | //======================================================================= |
44 | AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Face& theFirstFace, |
45 | const TopoDS_Face& theSecondFace) |
46 | : AIS_Dimension (AIS_KOD_LENGTH) |
47 | { |
48 | SetMeasuredGeometry (theFirstFace, theSecondFace); |
49 | SetFlyout (15.0); |
50 | } |
51 | |
52 | //======================================================================= |
53 | //function : Constructor |
54 | //purpose : Dimension between two shape |
7fd59977 |
55 | //======================================================================= |
60bf98ae |
56 | AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Face& theFace, |
57 | const TopoDS_Edge& theEdge) |
58 | : AIS_Dimension (AIS_KOD_LENGTH) |
59 | { |
60 | SetMeasuredGeometry (theFace, theEdge); |
61 | SetFlyout (15.0); |
62 | } |
7fd59977 |
63 | |
60bf98ae |
64 | //======================================================================= |
65 | //function : Constructor |
66 | //purpose : Dimension between two points |
67 | //======================================================================= |
a6eb515f |
68 | AIS_LengthDimension::AIS_LengthDimension (const gp_Pnt& theFirstPoint, |
69 | const gp_Pnt& theSecondPoint, |
60bf98ae |
70 | const gp_Pln& thePlane) |
71 | : AIS_Dimension (AIS_KOD_LENGTH) |
7fd59977 |
72 | { |
60bf98ae |
73 | SetMeasuredGeometry (theFirstPoint, theSecondPoint, thePlane); |
d7bffd44 |
74 | SetFlyout (15.0); |
7fd59977 |
75 | } |
76 | |
7fd59977 |
77 | //======================================================================= |
78 | //function : Constructor |
a6eb515f |
79 | //purpose : Dimension between two shape |
7fd59977 |
80 | //======================================================================= |
a6eb515f |
81 | AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Shape& theFirstShape, |
82 | const TopoDS_Shape& theSecondShape, |
60bf98ae |
83 | const gp_Pln& thePlane) |
84 | : AIS_Dimension (AIS_KOD_LENGTH) |
7fd59977 |
85 | { |
60bf98ae |
86 | SetCustomPlane (thePlane); |
87 | SetMeasuredShapes (theFirstShape, theSecondShape); |
d7bffd44 |
88 | SetFlyout (15.0); |
7fd59977 |
89 | } |
90 | |
91 | //======================================================================= |
92 | //function : Constructor |
a6eb515f |
93 | //purpose : Dimension of one edge |
7fd59977 |
94 | //======================================================================= |
a6eb515f |
95 | AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Edge& theEdge, |
60bf98ae |
96 | const gp_Pln& thePlane) |
97 | : AIS_Dimension (AIS_KOD_LENGTH) |
7fd59977 |
98 | { |
60bf98ae |
99 | SetMeasuredGeometry (theEdge, thePlane); |
d7bffd44 |
100 | SetFlyout (15.0); |
7fd59977 |
101 | } |
102 | |
7fd59977 |
103 | //======================================================================= |
60bf98ae |
104 | //function : SetMeasuredGeometry |
105 | //purpose : |
7fd59977 |
106 | //======================================================================= |
60bf98ae |
107 | void AIS_LengthDimension::SetMeasuredGeometry (const gp_Pnt& theFirstPoint, |
108 | const gp_Pnt& theSecondPoint, |
109 | const gp_Pln& thePlane) |
110 | { |
91b16a64 |
111 | myFirstPoint = theFirstPoint; |
112 | mySecondPoint = theSecondPoint; |
113 | myFirstShape = BRepLib_MakeVertex (myFirstPoint); |
114 | mySecondShape = BRepLib_MakeVertex (mySecondPoint); |
115 | myGeometryType = GeometryType_Points; |
60bf98ae |
116 | SetCustomPlane (thePlane); |
91b16a64 |
117 | myIsGeometryValid = IsValidPoints (theFirstPoint, theSecondPoint); |
60bf98ae |
118 | |
119 | SetToUpdate(); |
120 | } |
7fd59977 |
121 | |
60bf98ae |
122 | //======================================================================= |
123 | //function : SetMeasuredGeometry |
124 | //purpose : |
125 | //======================================================================= |
126 | void AIS_LengthDimension::SetMeasuredGeometry (const TopoDS_Edge& theEdge, |
127 | const gp_Pln& thePlane) |
7fd59977 |
128 | { |
91b16a64 |
129 | myFirstShape = theEdge; |
130 | mySecondShape = TopoDS_Shape(); |
131 | myGeometryType = GeometryType_Edge; |
60bf98ae |
132 | SetCustomPlane (thePlane); |
91b16a64 |
133 | myIsGeometryValid = InitOneShapePoints (myFirstShape); |
60bf98ae |
134 | |
135 | SetToUpdate(); |
7fd59977 |
136 | } |
137 | |
138 | //======================================================================= |
60bf98ae |
139 | //function : SetMeasuredGeometry |
140 | //purpose : |
7fd59977 |
141 | //======================================================================= |
60bf98ae |
142 | void AIS_LengthDimension::SetMeasuredGeometry (const TopoDS_Face& theFirstFace, |
143 | const TopoDS_Face& theSecondFace) |
144 | { |
145 | SetMeasuredShapes (theFirstFace, theSecondFace); |
146 | } |
7fd59977 |
147 | |
60bf98ae |
148 | //======================================================================= |
149 | //function : SetMeasuredGeometry |
150 | //purpose : |
151 | //======================================================================= |
152 | void AIS_LengthDimension::SetMeasuredGeometry (const TopoDS_Face& theFace, |
153 | const TopoDS_Edge& theEdge) |
7fd59977 |
154 | { |
60bf98ae |
155 | SetMeasuredShapes (theFace, theEdge); |
156 | } |
157 | |
158 | //======================================================================= |
159 | //function : SetMeasuredShapes |
160 | //purpose : |
161 | //======================================================================= |
162 | void AIS_LengthDimension::SetMeasuredShapes (const TopoDS_Shape& theFirstShape, |
163 | const TopoDS_Shape& theSecondShape) |
164 | { |
165 | gp_Pln aComputedPlane; |
166 | Standard_Boolean isPlaneReturned = Standard_False; |
60bf98ae |
167 | |
91b16a64 |
168 | myFirstShape = theFirstShape; |
169 | mySecondShape = theSecondShape; |
170 | myIsGeometryValid = InitTwoShapesPoints (myFirstShape, mySecondShape, aComputedPlane, isPlaneReturned); |
171 | |
172 | if (myIsGeometryValid && !myIsPlaneCustom) |
60bf98ae |
173 | { |
174 | if (isPlaneReturned) |
175 | { |
176 | myPlane = aComputedPlane; |
177 | } |
178 | else |
179 | { |
91b16a64 |
180 | myIsGeometryValid = Standard_False; |
60bf98ae |
181 | } |
182 | } |
183 | |
60bf98ae |
184 | SetToUpdate(); |
185 | } |
186 | |
187 | //======================================================================= |
188 | //function : CheckPlane |
189 | //purpose : |
190 | //======================================================================= |
191 | Standard_Boolean AIS_LengthDimension::CheckPlane (const gp_Pln& thePlane) const |
192 | { |
193 | if (!thePlane.Contains (myFirstPoint, Precision::Confusion()) && |
194 | !thePlane.Contains (mySecondPoint, Precision::Confusion())) |
195 | { |
196 | return Standard_False; |
197 | } |
198 | |
199 | return Standard_True; |
200 | } |
201 | |
202 | //======================================================================= |
203 | //function : ComputePlane |
204 | //purpose : |
205 | //======================================================================= |
206 | gp_Pln AIS_LengthDimension::ComputePlane (const gp_Dir& theAttachDir) const |
207 | { |
208 | if (!IsValidPoints (myFirstPoint, mySecondPoint)) |
209 | { |
210 | return gp_Pln(); |
211 | } |
212 | |
213 | gp_Pnt aThirdPoint (myFirstPoint.Translated (gp_Vec(theAttachDir))); |
214 | gce_MakePln aPlaneConstrustor (myFirstPoint, mySecondPoint, aThirdPoint); |
215 | return aPlaneConstrustor.Value(); |
216 | } |
217 | |
218 | //======================================================================= |
219 | //function : GetModelUnits |
220 | //purpose : |
221 | //======================================================================= |
222 | const TCollection_AsciiString& AIS_LengthDimension::GetModelUnits() const |
223 | { |
224 | return myDrawer->DimLengthModelUnits(); |
7fd59977 |
225 | } |
226 | |
227 | //======================================================================= |
60bf98ae |
228 | //function : GetDisplayUnits |
229 | //purpose : |
7fd59977 |
230 | //======================================================================= |
60bf98ae |
231 | const TCollection_AsciiString& AIS_LengthDimension::GetDisplayUnits() const |
232 | { |
233 | return myDrawer->DimLengthDisplayUnits(); |
234 | } |
235 | |
236 | //======================================================================= |
237 | //function : SetModelUnits |
238 | //purpose : |
239 | //======================================================================= |
240 | void AIS_LengthDimension::SetModelUnits (const TCollection_AsciiString& theUnits) |
241 | { |
242 | myDrawer->SetDimLengthModelUnits (theUnits); |
243 | } |
244 | |
245 | //======================================================================= |
246 | //function : SetDisplayUnits |
247 | //purpose : |
248 | //======================================================================= |
249 | void AIS_LengthDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits) |
250 | { |
251 | myDrawer->SetDimLengthDisplayUnits (theUnits); |
252 | } |
7fd59977 |
253 | |
60bf98ae |
254 | //======================================================================= |
255 | //function : ComputeValue |
256 | //purpose : |
257 | //======================================================================= |
258 | Standard_Real AIS_LengthDimension::ComputeValue() const |
259 | { |
260 | return IsValid() ? myFirstPoint.Distance (mySecondPoint) : 0.0; |
261 | } |
262 | |
263 | //======================================================================= |
264 | //function : Compute |
265 | //purpose : |
266 | //======================================================================= |
267 | void AIS_LengthDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/, |
268 | const Handle(Prs3d_Presentation)& thePresentation, |
269 | const Standard_Integer theMode) |
270 | { |
271 | thePresentation->Clear(); |
272 | mySelectionGeom.Clear (theMode); |
273 | |
274 | if (!IsValid()) |
275 | { |
276 | return; |
277 | } |
278 | |
279 | DrawLinearDimension (thePresentation, theMode, myFirstPoint, mySecondPoint); |
280 | } |
281 | |
282 | //======================================================================= |
283 | //function : ComputeFlyoutSelection |
284 | //purpose : |
285 | //======================================================================= |
286 | void AIS_LengthDimension::ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection, |
287 | const Handle(SelectMgr_EntityOwner)& theEntityOwner) |
288 | { |
289 | if (!IsValid()) |
290 | { |
291 | return; |
292 | } |
293 | |
294 | ComputeLinearFlyouts (theSelection, theEntityOwner, myFirstPoint, mySecondPoint); |
295 | } |
296 | |
297 | //======================================================================= |
298 | //function : IsValidPoints |
299 | //purpose : |
300 | //======================================================================= |
301 | Standard_Boolean AIS_LengthDimension::IsValidPoints (const gp_Pnt& theFirstPoint, |
302 | const gp_Pnt& theSecondPoint) const |
303 | { |
304 | return theFirstPoint.Distance (theSecondPoint) > Precision::Confusion(); |
305 | } |
306 | |
307 | //======================================================================= |
308 | //function : InitTwoEdgesLength |
309 | //purpose : Initialization of dimension between two linear edges |
310 | //======================================================================= |
311 | Standard_Boolean AIS_LengthDimension::InitTwoEdgesLength (const TopoDS_Edge& theFirstEdge, |
d7bffd44 |
312 | const TopoDS_Edge& theSecondEdge, |
313 | gp_Dir& theDirAttach) |
7fd59977 |
314 | { |
a6eb515f |
315 | BRepAdaptor_Curve aFirstCurveAdapt (theFirstEdge); |
316 | if (aFirstCurveAdapt.GetType() != GeomAbs_Line) |
60bf98ae |
317 | { |
a6eb515f |
318 | return Standard_False; |
60bf98ae |
319 | } |
320 | |
a6eb515f |
321 | BRepAdaptor_Curve aSecondCurveAdapt (theSecondEdge); |
322 | if (aSecondCurveAdapt.GetType() != GeomAbs_Line) |
60bf98ae |
323 | { |
a6eb515f |
324 | return Standard_False; |
60bf98ae |
325 | } |
a6eb515f |
326 | |
60bf98ae |
327 | Handle(Geom_Curve) aFirstCurve; |
328 | Handle(Geom_Curve) aSecondCurve; |
329 | |
330 | gp_Pnt aPoint11 (gp::Origin()); |
331 | gp_Pnt aPoint12 (gp::Origin()); |
332 | gp_Pnt aPoint21 (gp::Origin()); |
333 | gp_Pnt aPoint22 (gp::Origin()); |
334 | Standard_Boolean isFirstInfinite = Standard_False; |
335 | Standard_Boolean isSecondInfinite = Standard_False; |
336 | |
337 | if (!AIS::ComputeGeometry (theFirstEdge, theSecondEdge, |
338 | aFirstCurve, aSecondCurve, |
339 | aPoint11, aPoint12, |
340 | aPoint21, aPoint22, |
341 | isFirstInfinite, |
342 | isSecondInfinite)) |
a6eb515f |
343 | { |
60bf98ae |
344 | return Standard_False; |
a6eb515f |
345 | } |
60bf98ae |
346 | |
347 | const Handle(Geom_Line) aFirstLine = Handle(Geom_Line)::DownCast (aFirstCurve); |
348 | const Handle(Geom_Line) aSecondLine = Handle(Geom_Line)::DownCast (aSecondCurve); |
349 | |
350 | if (!aFirstLine->Lin().Direction().IsParallel (aSecondLine->Lin().Direction(),Precision::Angular())) |
a6eb515f |
351 | { |
60bf98ae |
352 | return Standard_False; |
7fd59977 |
353 | } |
60bf98ae |
354 | |
355 | theDirAttach = aFirstLine->Lin().Direction(); |
356 | |
357 | gp_Pnt aPoint; |
358 | |
a6eb515f |
359 | if (!isFirstInfinite) |
360 | { |
60bf98ae |
361 | if (AIS::Nearest (aSecondCurve, aPoint11, aPoint21, aPoint22, aPoint)) |
362 | { |
a6eb515f |
363 | myFirstPoint = aPoint11; |
60bf98ae |
364 | mySecondPoint = aPoint; |
365 | return IsValidPoints (myFirstPoint, mySecondPoint); |
366 | } |
367 | else if (AIS::Nearest (aSecondCurve, aPoint12, aPoint21, aPoint22, aPoint)) |
368 | { |
369 | myFirstPoint = aPoint12; |
370 | mySecondPoint = aPoint; |
371 | return IsValidPoints (myFirstPoint, mySecondPoint); |
372 | } |
7fd59977 |
373 | } |
374 | |
a6eb515f |
375 | if (!isSecondInfinite) |
376 | { |
60bf98ae |
377 | if (AIS::Nearest (aFirstCurve, aPoint21, aPoint11, aPoint12, aPoint)) |
378 | { |
379 | myFirstPoint = aPoint; |
a6eb515f |
380 | mySecondPoint = aPoint21; |
60bf98ae |
381 | return IsValidPoints (myFirstPoint, mySecondPoint); |
382 | } |
383 | if (AIS::Nearest (aFirstCurve, aPoint22, aPoint11, aPoint12, aPoint)) |
384 | { |
385 | myFirstPoint = aPoint; |
386 | mySecondPoint = aPoint22; |
387 | return IsValidPoints (myFirstPoint, mySecondPoint); |
388 | } |
a6eb515f |
389 | } |
7fd59977 |
390 | |
60bf98ae |
391 | GeomAPI_ExtremaCurveCurve anExtrema (aFirstCurve, aSecondCurve); |
392 | anExtrema.NearestPoints (myFirstPoint, mySecondPoint); |
393 | return IsValidPoints (myFirstPoint, mySecondPoint); |
7fd59977 |
394 | } |
395 | |
7fd59977 |
396 | //======================================================================= |
60bf98ae |
397 | //function : InitEdgeVertexLength |
a6eb515f |
398 | //purpose : for first edge and second vertex shapes |
7fd59977 |
399 | //======================================================================= |
60bf98ae |
400 | Standard_Boolean AIS_LengthDimension::InitEdgeVertexLength (const TopoDS_Edge& theEdge, |
401 | const TopoDS_Vertex& theVertex, |
402 | gp_Dir& theEdgeDir, |
d7bffd44 |
403 | Standard_Boolean isInfinite) |
7fd59977 |
404 | { |
60bf98ae |
405 | gp_Pnt anEdgePoint1 (gp::Origin()); |
406 | gp_Pnt anEdgePoint2 (gp::Origin()); |
a6eb515f |
407 | Handle(Geom_Curve) aCurve; |
60bf98ae |
408 | |
409 | if (!AIS::ComputeGeometry (theEdge, aCurve, anEdgePoint1, anEdgePoint2, isInfinite)) |
410 | { |
a6eb515f |
411 | return Standard_False; |
60bf98ae |
412 | } |
413 | |
414 | myFirstPoint = BRep_Tool::Pnt (theVertex); |
a6eb515f |
415 | |
416 | const Handle(Geom_Line)& aGeomLine = (Handle(Geom_Line)&) aCurve; |
417 | const gp_Lin& aLin = aGeomLine->Lin(); |
418 | |
60bf98ae |
419 | // Get direction of edge to build plane automatically. |
420 | theEdgeDir = aLin.Direction(); |
a6eb515f |
421 | |
60bf98ae |
422 | mySecondPoint = AIS::Nearest (aLin, myFirstPoint); |
a6eb515f |
423 | |
60bf98ae |
424 | return IsValidPoints (myFirstPoint, mySecondPoint); |
7fd59977 |
425 | } |
426 | |
7fd59977 |
427 | //======================================================================= |
60bf98ae |
428 | //function : InitEdgeFaceLength |
7fd59977 |
429 | //purpose : |
430 | //======================================================================= |
60bf98ae |
431 | Standard_Boolean AIS_LengthDimension::InitEdgeFaceLength (const TopoDS_Edge& theEdge, |
a6eb515f |
432 | const TopoDS_Face& theFace, |
60bf98ae |
433 | gp_Dir& theEdgeDir) |
7fd59977 |
434 | { |
60bf98ae |
435 | Handle(Geom_Curve) aCurve; |
436 | gp_Pnt aFirstPoint, aSecondPoint; |
437 | Standard_Boolean isInfinite = Standard_False; |
438 | |
439 | if (!AIS::ComputeGeometry (theEdge, aCurve, aFirstPoint, aSecondPoint, isInfinite)) |
a6eb515f |
440 | { |
60bf98ae |
441 | return Standard_False; |
7fd59977 |
442 | } |
60bf98ae |
443 | theEdgeDir = gce_MakeDir (aFirstPoint, aSecondPoint); |
444 | gp_Pln aPlane; |
445 | Handle(Geom_Surface) aSurface; |
446 | AIS_KindOfSurface aSurfType; |
447 | Standard_Real anOffset; |
7fd59977 |
448 | |
60bf98ae |
449 | if (!AIS::GetPlaneFromFace (theFace, aPlane, aSurface, aSurfType, anOffset)) |
a6eb515f |
450 | { |
60bf98ae |
451 | return Standard_False; |
7fd59977 |
452 | } |
7fd59977 |
453 | |
60bf98ae |
454 | GeomAPI_ExtremaCurveSurface aDistAdaptor (aCurve, aSurface); |
fe83e1ea |
455 | |
60bf98ae |
456 | aDistAdaptor.NearestPoints (myFirstPoint, mySecondPoint); |
457 | |
458 | return IsValidPoints (myFirstPoint, mySecondPoint); |
7fd59977 |
459 | } |
460 | |
461 | //======================================================================= |
60bf98ae |
462 | //function : InitTwoShapesPoints |
a6eb515f |
463 | //purpose : Initialization of two points where dimension layouts |
464 | // will be attached |
7fd59977 |
465 | //======================================================================= |
60bf98ae |
466 | Standard_Boolean AIS_LengthDimension::InitTwoShapesPoints (const TopoDS_Shape& theFirstShape, |
467 | const TopoDS_Shape& theSecondShape, |
468 | gp_Pln& theComputedPlane, |
469 | Standard_Boolean& theIsPlaneComputed) |
7fd59977 |
470 | { |
60bf98ae |
471 | theIsPlaneComputed = Standard_False; |
a6eb515f |
472 | gp_Dir aDirAttach; |
473 | Standard_Boolean isInfinite = Standard_False; |
60bf98ae |
474 | Standard_Boolean isSuccess = Standard_False; |
a6eb515f |
475 | switch (theFirstShape.ShapeType()) |
476 | { |
60bf98ae |
477 | case TopAbs_FACE: |
7fd59977 |
478 | { |
a6eb515f |
479 | // Initialization for face |
480 | gp_Pln aFirstPlane; |
481 | Handle(Geom_Surface) aFirstSurface; |
482 | AIS_KindOfSurface aFirstSurfKind; |
483 | Standard_Real aFirstOffset; |
60bf98ae |
484 | |
a6eb515f |
485 | TopoDS_Face aFirstFace = TopoDS::Face (theFirstShape); |
a6eb515f |
486 | |
60bf98ae |
487 | AIS::InitFaceLength (TopoDS::Face (theFirstShape), |
488 | aFirstPlane, |
489 | aFirstSurface, |
490 | aFirstSurfKind, |
491 | aFirstOffset); |
492 | |
493 | if (theSecondShape.ShapeType() == TopAbs_FACE) |
a6eb515f |
494 | { |
495 | // Initialization for face |
60bf98ae |
496 | myGeometryType = GeometryType_Faces; |
a6eb515f |
497 | gp_Pln aSecondPlane; |
498 | Handle(Geom_Surface) aSecondSurface; |
499 | AIS_KindOfSurface aSecondSurfKind; |
500 | Standard_Real aSecondOffset; |
60bf98ae |
501 | |
a6eb515f |
502 | TopoDS_Face aSecondFace = TopoDS::Face (theSecondShape); |
60bf98ae |
503 | |
504 | AIS::InitFaceLength (aSecondFace, |
505 | aSecondPlane, |
506 | aSecondSurface, |
507 | aSecondSurfKind, |
508 | aSecondOffset); |
509 | |
a6eb515f |
510 | if (aFirstSurfKind == AIS_KOS_Plane) |
7fd59977 |
511 | { |
60bf98ae |
512 | if (!aFirstPlane.Axis().Direction().IsParallel (aSecondPlane.Axis().Direction(), Precision::Angular())) |
513 | { |
514 | return Standard_False; |
515 | } |
516 | |
a6eb515f |
517 | TopExp_Explorer anExplorer (theFirstShape, TopAbs_VERTEX); |
60bf98ae |
518 | |
a6eb515f |
519 | // In case of infinite planes |
520 | if (!anExplorer.More()) |
60bf98ae |
521 | { |
a6eb515f |
522 | myFirstPoint = aFirstPlane.Location(); |
60bf98ae |
523 | } |
524 | else |
525 | { |
526 | myFirstPoint = BRep_Tool::Pnt (TopoDS::Vertex (anExplorer.Current())); |
527 | } |
528 | |
a6eb515f |
529 | mySecondPoint = AIS::ProjectPointOnPlane (myFirstPoint, aSecondPlane); |
530 | |
a6eb515f |
531 | Quantity_Parameter anU, aV; |
532 | ElSLib::Parameters (aSecondPlane, mySecondPoint, anU, aV); |
60bf98ae |
533 | |
a6eb515f |
534 | BRepTopAdaptor_FClass2d aClassifier (aSecondFace, Precision::Confusion()); |
535 | TopAbs_State aState = aClassifier.Perform (gp_Pnt2d (anU, aV), Standard_False); |
60bf98ae |
536 | |
a6eb515f |
537 | if (aState == TopAbs_OUT || aState == TopAbs_UNKNOWN) |
538 | { |
60bf98ae |
539 | mySecondPoint = AIS::Nearest (aSecondFace, myFirstPoint); |
540 | } |
541 | |
542 | isSuccess = IsValidPoints (myFirstPoint, mySecondPoint); |
543 | if (isSuccess) |
544 | { |
545 | theComputedPlane = ComputePlane (aFirstPlane.Position().XDirection()); |
546 | theIsPlaneComputed = Standard_True; |
a6eb515f |
547 | } |
7fd59977 |
548 | } |
a6eb515f |
549 | else // curvilinear faces |
7fd59977 |
550 | { |
60bf98ae |
551 | Standard_Real aU1Min, aV1Min, aU1Max, aV1Max; |
552 | Standard_Real aU2Min, aV2Min, aU2Max, aV2Max; |
553 | BRepTools::UVBounds (aFirstFace, aU1Min, aU1Max, aV1Min, aV1Max); |
554 | BRepTools::UVBounds (aSecondFace, aU2Min, aU2Max, aV2Min, aV2Max); |
555 | |
556 | GeomAPI_ExtremaSurfaceSurface anExtrema (aFirstSurface, aSecondSurface, |
557 | aU1Min, aU1Max, aV1Min, aV1Max, |
558 | aU2Min, aU2Max, aV2Min, aV2Max); |
559 | |
560 | Standard_Real aU1, aV1, aU2, aV2; |
561 | anExtrema.LowerDistanceParameters (aU1, aV1, aU2, aV2); |
562 | myFirstPoint = BRep_Tool::Surface (aFirstFace)->Value (aU1, aV1); |
563 | mySecondPoint = BRep_Tool::Surface (aSecondFace)->Value (aU2, aV2); |
564 | |
565 | // Adjust automatic plane |
566 | gp_Ax2 aLocalAxes (myFirstPoint, gce_MakeDir (myFirstPoint, mySecondPoint)); |
567 | aDirAttach = gce_MakeDir (aLocalAxes.XDirection ()); |
568 | |
569 | // Check points |
570 | isSuccess = IsValidPoints (myFirstPoint, mySecondPoint); |
571 | if (isSuccess) |
572 | { |
573 | theComputedPlane = ComputePlane (aDirAttach); |
574 | theIsPlaneComputed = Standard_True; |
575 | } |
7fd59977 |
576 | } |
60bf98ae |
577 | |
578 | return isSuccess && IsValidPoints (myFirstPoint, mySecondPoint); |
a6eb515f |
579 | } |
580 | else if (theFirstShape.ShapeType() == TopAbs_EDGE) |
581 | { |
60bf98ae |
582 | myGeometryType = GeometryType_EdgeFace; |
583 | isSuccess = InitEdgeFaceLength (TopoDS::Edge (theFirstShape), |
a6eb515f |
584 | TopoDS::Face (theSecondShape), |
585 | aDirAttach); |
60bf98ae |
586 | |
587 | if (isSuccess) |
588 | { |
589 | theComputedPlane = ComputePlane (aDirAttach); |
590 | theIsPlaneComputed = Standard_True; |
591 | } |
592 | |
593 | return isSuccess; |
a6eb515f |
594 | } |
7fd59977 |
595 | } |
a6eb515f |
596 | break; |
60bf98ae |
597 | |
598 | case TopAbs_EDGE: |
7fd59977 |
599 | { |
a6eb515f |
600 | if (theSecondShape.ShapeType() == TopAbs_VERTEX) |
601 | { |
60bf98ae |
602 | myGeometryType = GeometryType_EdgeVertex; |
603 | isSuccess = InitEdgeVertexLength (TopoDS::Edge (theFirstShape), |
604 | TopoDS::Vertex (theSecondShape), |
605 | aDirAttach, |
606 | isInfinite); |
607 | |
608 | if (isSuccess) |
609 | { |
610 | theComputedPlane = ComputePlane (aDirAttach); |
611 | theIsPlaneComputed = Standard_True; |
612 | } |
613 | |
614 | return isSuccess; |
a6eb515f |
615 | } |
616 | else if (theSecondShape.ShapeType() == TopAbs_EDGE) |
617 | { |
60bf98ae |
618 | myGeometryType = GeometryType_Edges; |
619 | isSuccess = InitTwoEdgesLength (TopoDS::Edge (theFirstShape), |
620 | TopoDS::Edge (theSecondShape), |
621 | aDirAttach); |
622 | |
623 | if (isSuccess) |
624 | { |
625 | theComputedPlane = ComputePlane (aDirAttach); |
626 | theIsPlaneComputed = Standard_True; |
627 | } |
628 | |
629 | return isSuccess; |
a6eb515f |
630 | } |
7fd59977 |
631 | } |
a6eb515f |
632 | break; |
60bf98ae |
633 | |
634 | case TopAbs_VERTEX: |
7fd59977 |
635 | { |
a6eb515f |
636 | if (theSecondShape.ShapeType() == TopAbs_VERTEX) |
637 | { |
60bf98ae |
638 | myGeometryType = GeometryType_Points; |
639 | myFirstPoint = BRep_Tool::Pnt (TopoDS::Vertex (theFirstShape)); |
a6eb515f |
640 | mySecondPoint = BRep_Tool::Pnt (TopoDS::Vertex (theSecondShape)); |
60bf98ae |
641 | |
642 | return IsValidPoints (myFirstPoint, mySecondPoint); |
a6eb515f |
643 | } |
644 | else if (theSecondShape.ShapeType() == TopAbs_EDGE) |
645 | { |
60bf98ae |
646 | myGeometryType = GeometryType_EdgeVertex; |
647 | Standard_Boolean isSuccess = InitEdgeVertexLength (TopoDS::Edge(theSecondShape), |
648 | TopoDS::Vertex(theFirstShape), |
649 | aDirAttach, |
650 | isInfinite); |
651 | if (isSuccess) |
652 | { |
653 | theComputedPlane = ComputePlane (aDirAttach); |
654 | theIsPlaneComputed = Standard_True; |
655 | } |
656 | |
657 | return isSuccess; |
a6eb515f |
658 | } |
7fd59977 |
659 | } |
a6eb515f |
660 | break; |
60bf98ae |
661 | |
662 | case TopAbs_COMPOUND: |
663 | case TopAbs_COMPSOLID: |
664 | case TopAbs_SOLID: |
665 | case TopAbs_SHELL: |
666 | case TopAbs_WIRE: |
667 | case TopAbs_SHAPE: |
668 | break; |
a6eb515f |
669 | } |
60bf98ae |
670 | |
671 | return Standard_False; |
7fd59977 |
672 | } |
673 | |
674 | //======================================================================= |
60bf98ae |
675 | //function : InitOneShapePoints |
a6eb515f |
676 | //purpose : Initialization of two points where dimension layouts |
677 | // will be attached |
678 | // Attention: 1) <theShape> can be only the edge in currect implementation |
679 | // 2) No length for infinite edge |
7fd59977 |
680 | //======================================================================= |
60bf98ae |
681 | Standard_Boolean AIS_LengthDimension::InitOneShapePoints (const TopoDS_Shape& theShape) |
7fd59977 |
682 | { |
60bf98ae |
683 | if (theShape.ShapeType() != TopAbs_EDGE) |
a6eb515f |
684 | { |
a6eb515f |
685 | return Standard_False; |
60bf98ae |
686 | } |
7fd59977 |
687 | |
60bf98ae |
688 | TopoDS_Edge anEdge = TopoDS::Edge (theShape); |
7fd59977 |
689 | |
60bf98ae |
690 | BRepAdaptor_Curve aBrepCurve(anEdge); |
691 | Standard_Real aFirst = aBrepCurve.FirstParameter(); |
692 | Standard_Real aLast = aBrepCurve.LastParameter(); |
fe83e1ea |
693 | |
60bf98ae |
694 | if (aBrepCurve.GetType() != GeomAbs_Line) |
a6eb515f |
695 | { |
60bf98ae |
696 | return Standard_False; |
7fd59977 |
697 | } |
d7bffd44 |
698 | |
60bf98ae |
699 | Standard_Boolean isInfinite = (Precision::IsInfinite (aFirst) || Precision::IsInfinite (aLast)); |
700 | if (isInfinite) |
d7bffd44 |
701 | { |
60bf98ae |
702 | return Standard_False; |
d7bffd44 |
703 | } |
7fd59977 |
704 | |
60bf98ae |
705 | myFirstPoint = aBrepCurve.Value (aBrepCurve.FirstParameter()); |
706 | mySecondPoint = aBrepCurve.Value (aBrepCurve.LastParameter()); |
7fd59977 |
707 | |
60bf98ae |
708 | return IsValidPoints (myFirstPoint, mySecondPoint); |
7fd59977 |
709 | } |
af203d54 |
710 | |
711 | //======================================================================= |
712 | //function : GetTextPosition |
713 | //purpose : |
714 | //======================================================================= |
715 | const gp_Pnt AIS_LengthDimension::GetTextPosition() const |
716 | { |
717 | if (IsTextPositionCustom()) |
718 | { |
719 | return myFixedTextPosition; |
720 | } |
721 | |
722 | // Counts text position according to the dimension parameters |
723 | return GetTextPositionForLinear (myFirstPoint, mySecondPoint); |
724 | } |
725 | |
726 | //======================================================================= |
727 | //function : SetTextPosition |
728 | //purpose : |
729 | //======================================================================= |
730 | void AIS_LengthDimension::SetTextPosition (const gp_Pnt& theTextPos) |
731 | { |
91b16a64 |
732 | if (!IsValid()) |
af203d54 |
733 | { |
734 | return; |
735 | } |
736 | |
737 | myIsTextPositionFixed = Standard_True; |
738 | myFixedTextPosition = theTextPos; |
739 | |
740 | SetToUpdate(); |
741 | } |