1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <GEOMImpl_ShapeDriver.hxx>
25 #include <GEOMImpl_IIsoline.hxx>
26 #include <GEOMImpl_IShapes.hxx>
27 #include <GEOMImpl_IShapeExtend.hxx>
28 #include <GEOMImpl_IVector.hxx>
29 #include <GEOMImpl_Types.hxx>
30 #include <GEOMImpl_Block6Explorer.hxx>
32 #include <GEOM_Function.hxx>
33 #include <GEOMUtils_Hatcher.hxx>
34 #include <GEOMAlgo_State.hxx>
37 #include <ShapeFix_Wire.hxx>
38 #include <ShapeFix_Edge.hxx>
39 #include <ShapeFix_Shape.hxx>
41 #include <BRep_Builder.hxx>
42 #include <BRep_Tool.hxx>
43 #include <BRepAdaptor_Curve.hxx>
44 #include <BRepAlgo_FaceRestrictor.hxx>
45 #include <BRepBuilderAPI_Copy.hxx>
46 #include <BRepBuilderAPI_Sewing.hxx>
47 #include <BRepBuilderAPI_MakeFace.hxx>
48 #include <BRepBuilderAPI_MakeWire.hxx>
49 #include <BRepBuilderAPI_MakeEdge.hxx>
50 #include <BRepBuilderAPI_MakeSolid.hxx>
51 #include <BRepCheck.hxx>
52 #include <BRepCheck_Analyzer.hxx>
53 #include <BRepCheck_Shell.hxx>
54 #include <BRepClass3d_SolidClassifier.hxx>
55 #include <BRepLib.hxx>
56 #include <BRepLib_MakeEdge.hxx>
57 #include <BRepTools_WireExplorer.hxx>
59 #include <ShapeAnalysis.hxx>
60 #include <ShapeAnalysis_FreeBounds.hxx>
62 #include <TNaming_CopyShape.hxx>
66 #include <TopExp_Explorer.hxx>
68 #include <TopoDS_Shape.hxx>
69 #include <TopoDS_Edge.hxx>
70 #include <TopoDS_Wire.hxx>
71 #include <TopoDS_Shell.hxx>
72 #include <TopoDS_Solid.hxx>
73 #include <TopoDS_Compound.hxx>
74 #include <TopoDS_Iterator.hxx>
76 #include <TopTools_MapOfShape.hxx>
77 #include <TopTools_HSequenceOfShape.hxx>
81 #include <GCPnts_AbscissaPoint.hxx>
83 #include <Geom_TrimmedCurve.hxx>
84 #include <Geom_RectangularTrimmedSurface.hxx>
85 #include <Geom_Surface.hxx>
86 #include <GeomAbs_CurveType.hxx>
87 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
88 #include <GeomConvert.hxx>
89 #include <GeomLProp.hxx>
91 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
92 #include <TColStd_SequenceOfReal.hxx>
93 #include <TColStd_HSequenceOfTransient.hxx>
94 #include <TColStd_Array1OfReal.hxx>
95 #include <TColGeom_SequenceOfCurve.hxx>
96 #include <TColGeom_Array1OfBSplineCurve.hxx>
97 #include <TColGeom_HArray1OfBSplineCurve.hxx>
99 #include <Precision.hxx>
101 #include <Standard_NullObject.hxx>
102 #include <Standard_TypeMismatch.hxx>
103 #include <Standard_ConstructionError.hxx>
105 #include <BOPAlgo_PaveFiller.hxx>
106 #include <BOPAlgo_MakerVolume.hxx>
110 //modified by NIZNHY-PKV Wed Dec 28 13:48:20 2011f
112 // void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
113 // const Handle(TopTools_HSequenceOfShape)& aWires);
114 //modified by NIZNHY-PKV Wed Dec 28 13:48:23 2011t
116 //=======================================================================
119 //=======================================================================
120 const Standard_GUID& GEOMImpl_ShapeDriver::GetID()
122 static Standard_GUID aShapeDriver("FF1BBB54-5D14-4df2-980B-3A668264EA16");
127 //=======================================================================
128 //function : GEOMImpl_ShapeDriver
130 //=======================================================================
131 GEOMImpl_ShapeDriver::GEOMImpl_ShapeDriver()
135 //=======================================================================
138 //=======================================================================
139 Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
141 if (Label().IsNull()) return 0;
142 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
144 GEOMImpl_IShapes aCI (aFunction);
145 Standard_Integer aType = aFunction->GetType();
148 TCollection_AsciiString aWarning;
149 std::list<TopAbs_ShapeEnum> anExpectedType;
153 if (aType == WIRE_EDGES) {
154 anExpectedType.push_back(TopAbs_WIRE);
156 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
158 Standard_Real aTolerance = aCI.GetTolerance();
159 if (aTolerance < Precision::Confusion())
160 aTolerance = Precision::Confusion();
162 aShape = MakeWireFromEdges(aShapes, aTolerance);
164 else if (aType == FACE_WIRE) {
165 anExpectedType.push_back(TopAbs_FACE);
167 Handle(GEOM_Function) aRefBase = aCI.GetBase();
168 TopoDS_Shape aShapeBase = aRefBase->GetValue();
169 if (aShapeBase.IsNull()) Standard_NullObject::Raise("Argument Shape is null");
171 if (aShapeBase.ShapeType() == TopAbs_WIRE) {
172 W = TopoDS::Wire(aShapeBase);
173 // check the wire is closed
174 TopoDS_Vertex aV1, aV2;
175 TopExp::Vertices(W, aV1, aV2);
176 if ( !aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2) )
177 aShapeBase.Closed(true);
179 Standard_NullObject::Raise
180 ("Shape for face construction is not closed");
182 else if (aShapeBase.ShapeType() == TopAbs_EDGE && BRep_Tool::IsClosed(aShapeBase)) {
183 BRepBuilderAPI_MakeWire MW;
184 MW.Add(TopoDS::Edge(aShapeBase));
186 Standard_ConstructionError::Raise("Wire construction failed");
191 Standard_NullObject::Raise
192 ("Shape for face construction is neither a wire nor a closed edge");
194 aWarning = GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), aShape);
195 if (aShape.IsNull()) {
196 Standard_ConstructionError::Raise("Face construction failed");
199 else if (aType == FACE_WIRES) {
200 anExpectedType.push_back(TopAbs_FACE);
202 // Try to build a face from a set of wires and edges
205 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
206 int nbshapes = aShapes->Length();
208 Standard_ConstructionError::Raise("No wires or edges given");
211 // 1. Extract all edges from the given arguments
212 TopTools_MapOfShape aMapEdges;
213 Handle(TopTools_HSequenceOfShape) aSeqEdgesIn = new TopTools_HSequenceOfShape;
214 TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
216 for (ind = 1; ind <= nbshapes; ind++) {
217 Handle(GEOM_Function) aRefSh_i = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
218 TopoDS_Shape aSh_i = aRefSh_i->GetValue();
220 TopExp_Explorer anExpE_i (aSh_i, TopAbs_EDGE);
221 for (; anExpE_i.More(); anExpE_i.Next()) {
222 if (aMapEdges.Add(anExpE_i.Current())) {
223 // Copy the original shape.
224 TopoDS_Shape aShapeCopy;
226 TNaming_CopyShape::CopyTool
227 (anExpE_i.Current(), aMapTShapes, aShapeCopy);
228 aSeqEdgesIn->Append(aShapeCopy);
233 if (aSeqEdgesIn->IsEmpty()) {
234 Standard_ConstructionError::Raise("No edges given");
237 // 2. Connect edges to wires of maximum length
238 Handle(TopTools_HSequenceOfShape) aSeqWiresOut;
239 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdgesIn, Precision::Confusion(),
240 /*shared*/Standard_False, aSeqWiresOut);
241 //modified by NIZNHY-PKV Wed Dec 28 13:46:55 2011f
242 //KeepEdgesOrder(aSeqEdgesIn, aSeqWiresOut);
243 //modified by NIZNHY-PKV Wed Dec 28 13:46:59 2011t
245 // 3. Separate closed wires
246 Handle(TopTools_HSequenceOfShape) aSeqClosedWires = new TopTools_HSequenceOfShape;
247 Handle(TopTools_HSequenceOfShape) aSeqOpenWires = new TopTools_HSequenceOfShape;
248 for (ind = 1; ind <= aSeqWiresOut->Length(); ind++) {
249 if (aSeqWiresOut->Value(ind).Closed())
250 aSeqClosedWires->Append(aSeqWiresOut->Value(ind));
252 aSeqOpenWires->Append(aSeqWiresOut->Value(ind));
255 if (aSeqClosedWires->Length() < 1) {
256 Standard_ConstructionError::Raise
257 ("There is no closed contour can be built from the given arguments");
260 // 4. Build a face / list of faces from all the obtained closed wires
264 TopoDS_Wire aW1 = TopoDS::Wire(aSeqClosedWires->Value(1));
265 aWarning = GEOMImpl_Block6Explorer::MakeFace(aW1, aCI.GetIsPlanar(), aFFace);
266 if (aFFace.IsNull()) {
267 Standard_ConstructionError::Raise("Face construction failed");
270 // 4.b. Add other wires
271 if (aSeqClosedWires->Length() == 1) {
276 BRep_Builder aBuilder;
277 aBuilder.MakeCompound(C);
278 BRepAlgo_FaceRestrictor FR;
280 TopAbs_Orientation OriF = aFFace.Orientation();
281 TopoDS_Shape aLocalS = aFFace.Oriented(TopAbs_FORWARD);
282 FR.Init(TopoDS::Face(aLocalS), Standard_False, Standard_True);
284 for (ind = 1; ind <= aSeqClosedWires->Length(); ind++) {
285 TopoDS_Wire aW = TopoDS::Wire(aSeqClosedWires->Value(ind));
294 for (; FR.More(); FR.Next()) {
295 aFace = FR.Current().Oriented(OriF);
296 aBuilder.Add(C, aFace);
307 // 5. Add all open wires to the result
308 if (aSeqOpenWires->Length() > 0) {
309 //Standard_ConstructionError::Raise("There are some open wires");
311 BRep_Builder aBuilder;
312 if (aSeqClosedWires->Length() == 1) {
313 aBuilder.MakeCompound(C);
314 aBuilder.Add(C, aShape);
317 C = TopoDS::Compound(aShape);
320 for (ind = 1; ind <= aSeqOpenWires->Length(); ind++) {
321 aBuilder.Add(C, aSeqOpenWires->Value(ind));
327 else if (aType == FACE_FROM_SURFACE) {
328 anExpectedType.push_back(TopAbs_FACE);
330 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
332 if (aShapes.IsNull() == Standard_False) {
333 Standard_Integer aNbShapes = aShapes->Length();
335 if (aNbShapes == 2) {
336 Handle(GEOM_Function) aRefFace =
337 Handle(GEOM_Function)::DownCast(aShapes->Value(1));
338 Handle(GEOM_Function) aRefWire =
339 Handle(GEOM_Function)::DownCast(aShapes->Value(2));
341 if (aRefFace.IsNull() == Standard_False &&
342 aRefWire.IsNull() == Standard_False) {
343 TopoDS_Shape aShFace = aRefFace->GetValue();
344 TopoDS_Shape aShWire = aRefWire->GetValue();
346 if (aShFace.IsNull() == Standard_False &&
347 aShFace.ShapeType() == TopAbs_FACE &&
348 aShWire.IsNull() == Standard_False &&
349 aShWire.ShapeType() == TopAbs_WIRE) {
350 TopoDS_Face aFace = TopoDS::Face(aShFace);
351 TopoDS_Wire aWire = TopoDS::Wire(aShWire);
352 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
353 BRepBuilderAPI_MakeFace aMkFace(aSurf, aWire);
355 if (aMkFace.IsDone()) {
356 aShape = aMkFace.Shape();
363 else if (aType == SHELL_FACES) {
364 anExpectedType.push_back(TopAbs_SHELL);
366 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
367 unsigned int ind, nbshapes = aShapes->Length();
370 BRepBuilderAPI_Sewing aSewing (Precision::Confusion()*10.0);
371 for (ind = 1; ind <= nbshapes; ind++) {
372 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
373 TopoDS_Shape aShape_i = aRefShape->GetValue();
374 if (aShape_i.IsNull()) {
375 Standard_NullObject::Raise("Face for shell construction is null");
377 aSewing.Add(aShape_i);
382 TopoDS_Shape sh = aSewing.SewedShape();
384 if (sh.ShapeType()==TopAbs_FACE && nbshapes==1) {
385 // case for creation of shell from one face - PAL12722 (skl 26.06.2006)
392 //TopExp_Explorer exp (aSewing.SewedShape(), TopAbs_SHELL);
393 TopExp_Explorer exp (sh, TopAbs_SHELL);
394 Standard_Integer ish = 0;
395 for (; exp.More(); exp.Next()) {
396 aShape = exp.Current();
401 // try the case of one face (Mantis issue 0021809)
402 TopExp_Explorer expF (sh, TopAbs_FACE);
403 Standard_Integer ifa = 0;
404 for (; expF.More(); expF.Next()) {
405 aShape = expF.Current();
416 aShape = aSewing.SewedShape();
422 else if (aType == SOLID_SHELLS) {
423 anExpectedType.push_back(TopAbs_SOLID);
425 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
426 unsigned int ind, nbshapes = aShapes->Length();
427 Standard_Integer ish = 0;
428 BRepBuilderAPI_MakeSolid aMkSolid;
431 for (ind = 1; ind <= nbshapes; ind++) {
432 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
433 TopoDS_Shape aShapeShell = aRefShape->GetValue();
434 if (aShapeShell.IsNull()) {
435 Standard_NullObject::Raise("Shell for solid construction is null");
437 if (aShapeShell.ShapeType() == TopAbs_COMPOUND) {
438 TopoDS_Iterator It (aShapeShell, Standard_True, Standard_True);
439 for (; It.More(); It.Next()) {
440 TopoDS_Shape aSubShape = It.Value();
441 if (aSubShape.ShapeType() == TopAbs_SHELL) {
442 aMkSolid.Add(TopoDS::Shell(aSubShape));
446 Standard_TypeMismatch::Raise
447 ("Shape for solid construction is neither a shell nor a compound of shells");
450 else if (aShapeShell.ShapeType() == TopAbs_SHELL) {
451 aMkSolid.Add(TopoDS::Shell(aShapeShell));
455 if (ish == 0 || !aMkSolid.IsDone()) return 0;
457 TopoDS_Solid Sol = aMkSolid.Solid();
458 BRepClass3d_SolidClassifier SC (Sol);
459 SC.PerformInfinitePoint(Precision::Confusion());
460 if (SC.State() == TopAbs_IN)
461 aShape = Sol.Reversed();
465 else if (aType == COMPOUND_SHAPES) {
466 anExpectedType.push_back(TopAbs_COMPOUND);
468 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
469 unsigned int ind, nbshapes = aShapes->Length();
474 for (ind = 1; ind <= nbshapes; ind++) {
475 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
476 TopoDS_Shape aShape_i = aRefShape->GetValue();
477 if (aShape_i.IsNull()) {
478 Standard_NullObject::Raise("Shape for compound construction is null");
486 else if (aType == EDGE_WIRE) {
487 anExpectedType.push_back(TopAbs_EDGE);
489 Handle(GEOM_Function) aRefBase = aCI.GetBase();
490 TopoDS_Shape aWire = aRefBase->GetValue();
491 Standard_Real LinTol = aCI.GetTolerance();
492 Standard_Real AngTol = aCI.GetAngularTolerance();
493 if (aWire.IsNull()) Standard_NullObject::Raise("Argument Wire is null");
495 aShape = MakeEdgeFromWire(aWire, LinTol, AngTol);
497 else if (aType == SOLID_FACES) {
498 anExpectedType.push_back(TopAbs_SOLID);
499 anExpectedType.push_back(TopAbs_COMPOUND);
500 anExpectedType.push_back(TopAbs_COMPSOLID);
502 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
503 unsigned int ind, nbshapes = aShapes->Length();
506 BOPCol_ListOfShape aLS;
507 for (ind = 1; ind <= nbshapes; ind++) {
508 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
509 TopoDS_Shape aShape_i = aRefShape->GetValue();
510 if (aShape_i.IsNull()) {
511 Standard_NullObject::Raise("Shape for solid construction is null");
513 if (aShape_i.ShapeType() == TopAbs_COMPOUND) {
514 TopoDS_Iterator It (aShape_i, Standard_True, Standard_True);
515 for (; It.More(); It.Next()) {
516 TopoDS_Shape aSubShape = It.Value();
517 if (aSubShape.ShapeType() == TopAbs_FACE || aSubShape.ShapeType() == TopAbs_SHELL)
518 aLS.Append(aSubShape);
520 Standard_TypeMismatch::Raise
521 ("Shape for solid construction is neither a list of faces and/or shells "
522 "nor a compound of faces and/or shells");
525 aLS.Append(aShape_i);
528 BOPAlgo_MakerVolume aMV;
529 aMV.SetArguments(aLS);
530 aMV.SetIntersect(aCI.GetIsIntersect());
532 if (aMV.ErrorStatus()) return 0;
534 aShape = aMV.Shape();
536 else if (aType == EDGE_CURVE_LENGTH) {
537 anExpectedType.push_back(TopAbs_EDGE);
539 GEOMImpl_IVector aVI (aFunction);
542 Handle(GEOM_Function) aRefCurve = aVI.GetPoint1();
543 if (aRefCurve.IsNull()) Standard_NullObject::Raise("Argument Curve is null");
544 TopoDS_Shape aRefShape1 = aRefCurve->GetValue();
545 if (aRefShape1.ShapeType() != TopAbs_EDGE) {
546 Standard_TypeMismatch::Raise
547 ("Edge On Curve creation aborted : curve shape is not an edge");
549 TopoDS_Edge aRefEdge = TopoDS::Edge(aRefShape1);
550 TopoDS_Vertex V1, V2;
551 TopExp::Vertices(aRefEdge, V1, V2, Standard_True);
554 TopoDS_Vertex aRefVertex;
555 Handle(GEOM_Function) aRefPoint = aVI.GetPoint2();
556 if (aRefPoint.IsNull()) {
560 TopoDS_Shape aRefShape2 = aRefPoint->GetValue();
561 if (aRefShape2.ShapeType() != TopAbs_VERTEX) {
562 Standard_TypeMismatch::Raise
563 ("Edge On Curve creation aborted : start point shape is not a vertex");
565 aRefVertex = TopoDS::Vertex(aRefShape2);
567 gp_Pnt aRefPnt = BRep_Tool::Pnt(aRefVertex);
570 Standard_Real aLength = aVI.GetParameter();
571 //Standard_Real aCurveLength = IntTools::Length(aRefEdge);
572 //if (aLength > aCurveLength) {
573 // Standard_ConstructionError::Raise
574 // ("Edge On Curve creation aborted : given length is greater than edges length");
576 if (fabs(aLength) < Precision::Confusion()) {
577 Standard_ConstructionError::Raise
578 ("Edge On Curve creation aborted : given length is smaller than Precision::Confusion()");
582 Standard_Real UFirst, ULast;
583 Handle(Geom_Curve) EdgeCurve = BRep_Tool::Curve(aRefEdge, UFirst, ULast);
584 Handle(Geom_Curve) ReOrientedCurve = EdgeCurve;
586 Standard_Real dU = ULast - UFirst;
587 Standard_Real par1 = UFirst + 0.1 * dU;
588 Standard_Real par2 = ULast - 0.1 * dU;
590 gp_Pnt P1 = EdgeCurve->Value(par1);
591 gp_Pnt P2 = EdgeCurve->Value(par2);
593 if (aRefPnt.SquareDistance(P2) < aRefPnt.SquareDistance(P1)) {
594 ReOrientedCurve = EdgeCurve->Reversed();
595 UFirst = EdgeCurve->ReversedParameter(ULast);
598 // Get the point by length
599 GeomAdaptor_Curve AdapCurve = GeomAdaptor_Curve(ReOrientedCurve);
600 GCPnts_AbscissaPoint anAbsPnt (AdapCurve, aLength, UFirst);
601 Standard_Real aParam = anAbsPnt.Parameter();
603 if (AdapCurve.IsClosed() && aLength < 0.0) {
604 Standard_Real aTmp = aParam;
609 BRepBuilderAPI_MakeEdge aME (ReOrientedCurve, UFirst, aParam);
611 aShape = aME.Shape();
612 } else if (aType == SHAPE_ISOLINE) {
613 GEOMImpl_IIsoline aII (aFunction);
614 Handle(GEOM_Function) aRefFace = aII.GetFace();
615 TopoDS_Shape aShapeFace = aRefFace->GetValue();
617 if (aShapeFace.ShapeType() == TopAbs_FACE) {
618 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
619 bool isUIso = aII.GetIsUIso();
620 Standard_Real aParam = aII.GetParameter();
621 Standard_Real U1,U2,V1,V2;
623 // Construct a real geometric parameter.
624 aFace.Orientation(TopAbs_FORWARD);
625 ShapeAnalysis::GetFaceUVBounds(aFace,U1,U2,V1,V2);
628 aParam = U1 + (U2 - U1)*aParam;
630 aParam = V1 + (V2 - V1)*aParam;
633 aShape = MakeIsoline(aFace, isUIso, aParam);
635 Standard_NullObject::Raise
636 ("Shape for isoline construction is not a face");
638 } else if (aType == EDGE_UV) {
639 anExpectedType.push_back(TopAbs_EDGE);
640 GEOMImpl_IShapeExtend aSE (aFunction);
641 Handle(GEOM_Function) aRefEdge = aSE.GetShape();
642 TopoDS_Shape aShapeEdge = aRefEdge->GetValue();
644 if (aShapeEdge.ShapeType() == TopAbs_EDGE) {
645 TopoDS_Edge anEdge = TopoDS::Edge(aShapeEdge);
647 aShape = ExtendEdge(anEdge, aSE.GetUMin(), aSE.GetUMax());
649 } else if (aType == FACE_UV) {
650 anExpectedType.push_back(TopAbs_FACE);
652 GEOMImpl_IShapeExtend aSE (aFunction);
653 Handle(GEOM_Function) aRefFace = aSE.GetShape();
654 TopoDS_Shape aShapeFace = aRefFace->GetValue();
656 if (aShapeFace.ShapeType() == TopAbs_FACE) {
657 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
659 aFace.Orientation(TopAbs_FORWARD);
660 aShape = ExtendFace(aFace, aSE.GetUMin(), aSE.GetUMax(),
661 aSE.GetVMin(), aSE.GetVMax());
663 } else if (aType == SURFACE_FROM_FACE) {
664 anExpectedType.push_back(TopAbs_FACE);
666 GEOMImpl_IShapeExtend aSE (aFunction);
667 Handle(GEOM_Function) aRefFace = aSE.GetShape();
668 TopoDS_Shape aShapeFace = aRefFace->GetValue();
670 if (aShapeFace.ShapeType() == TopAbs_FACE) {
671 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
672 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
674 if (aSurface.IsNull() == Standard_False) {
675 Handle(Standard_Type) aType = aSurface->DynamicType();
681 // Get U, V bounds of the face.
682 aFace.Orientation(TopAbs_FORWARD);
683 ShapeAnalysis::GetFaceUVBounds(aFace, aU1, aU2, aV1, aV2);
685 // Get the surface of original type
686 while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
687 Handle(Geom_RectangularTrimmedSurface) aTrSurface =
688 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
690 aSurface = aTrSurface->BasisSurface();
691 aType = aSurface->DynamicType();
694 const Standard_Real aTol = BRep_Tool::Tolerance(aFace);
695 BRepBuilderAPI_MakeFace aMF(aSurface, aU1, aU2, aV1, aV2, aTol);
698 aShape = aMF.Shape();
706 if (aShape.IsNull()) return 0;
708 // Check shape validity
709 BRepCheck_Analyzer ana (aShape, false);
710 if (!ana.IsValid()) {
711 //Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
712 // For Mantis issue 0021772: EDF 2336 GEOM: Non valid face created from two circles
713 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape (aShape);
715 aShape = aSfs->Shape();
718 // Check if the result shape type is compatible with the expected.
719 const TopAbs_ShapeEnum aShType = aShape.ShapeType();
721 if (!anExpectedType.empty()) {
723 std::list<TopAbs_ShapeEnum>::const_iterator it;
724 for (it = anExpectedType.begin(); it != anExpectedType.end() && !ok; ++it)
725 ok = (*it == TopAbs_SHAPE || *it == aShType);
727 Standard_ConstructionError::Raise("Result type check failed");
730 aFunction->SetValue(aShape);
732 log.SetTouched(Label());
734 if (!aWarning.IsEmpty())
735 Standard_Failure::Raise(aWarning.ToCString());
740 TopoDS_Wire GEOMImpl_ShapeDriver::MakeWireFromEdges(const Handle(TColStd_HSequenceOfTransient)& theEdgesFuncs,
741 const Standard_Real theTolerance)
749 for (unsigned int ind = 1; ind <= theEdgesFuncs->Length(); ind++) {
750 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(theEdgesFuncs->Value(ind));
751 TopoDS_Shape aShape_i = aRefShape->GetValue();
752 if (aShape_i.IsNull()) {
753 Standard_NullObject::Raise("Shape for wire construction is null");
755 if (aShape_i.ShapeType() == TopAbs_EDGE || aShape_i.ShapeType() == TopAbs_WIRE) {
756 TopExp_Explorer exp (aShape_i, TopAbs_EDGE);
757 for (; exp.More(); exp.Next())
758 B.Add(aWire, TopoDS::Edge(exp.Current()));
760 Standard_TypeMismatch::Raise
761 ("Shape for wire construction is neither an edge nor a wire");
766 Handle(ShapeFix_Wire) aFW = new ShapeFix_Wire;
770 if (aFW->StatusReorder(ShapeExtend_FAIL1)) {
771 Standard_ConstructionError::Raise("Wire construction failed: several loops detected");
773 else if (aFW->StatusReorder(ShapeExtend_FAIL)) {
774 Standard_ConstructionError::Raise("Wire construction failed");
779 // IMP 0019766: Building a Wire from unconnected edges by introducing a tolerance
780 aFW->ClosedWireMode() = Standard_False;
781 aFW->FixConnected(theTolerance);
782 if (aFW->StatusConnected(ShapeExtend_FAIL)) {
783 Standard_ConstructionError::Raise("Wire construction failed: cannot build connected wire");
786 if (aFW->StatusConnected(ShapeExtend_DONE3)) {
787 // Confused with <prec> but not Analyzer.Precision(), set the same
788 aFW->FixGapsByRangesMode() = Standard_True;
789 if (aFW->FixGaps3d()) {
790 Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
791 Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
792 for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
793 TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
794 aFe->FixVertexTolerance(aEdge);
795 aFe->FixSameParameter(aEdge);
798 else if (aFW->StatusGaps3d(ShapeExtend_FAIL)) {
799 Standard_ConstructionError::Raise("Wire construction failed: cannot fix 3d gaps");
802 aWire = aFW->WireAPIMake();
807 TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
808 const Standard_Real LinTol,
809 const Standard_Real AngTol)
813 BRepLib::BuildCurves3d(aWire);
814 Handle(ShapeFix_Shape) Fixer = new ShapeFix_Shape(aWire);
815 Fixer->SetPrecision(LinTol);
816 Fixer->SetMaxTolerance(LinTol);
818 TopoDS_Wire theWire = TopoDS::Wire(Fixer->Shape());
820 TColGeom_SequenceOfCurve CurveSeq;
821 TopTools_SequenceOfShape LocSeq;
822 TColStd_SequenceOfReal FparSeq;
823 TColStd_SequenceOfReal LparSeq;
824 TColStd_SequenceOfReal TolSeq;
825 GeomAbs_CurveType CurType;
826 TopoDS_Vertex FirstVertex, LastVertex;
827 Standard_Real aPntShiftDist = 0.;
829 BRepTools_WireExplorer wexp(theWire) ;
830 for (; wexp.More(); wexp.Next())
832 TopoDS_Edge anEdge = wexp.Current();
833 Standard_Real fpar, lpar;
834 TopLoc_Location aLoc;
835 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aLoc, fpar, lpar);
839 BRepAdaptor_Curve BAcurve(anEdge);
840 GeomAbs_CurveType aType = BAcurve.GetType();
842 Handle(Geom_Curve) aBasisCurve = BAcurve.Curve().Curve();
844 if (aBasisCurve->IsPeriodic())
845 ElCLib::AdjustPeriodic(aBasisCurve->FirstParameter(), aBasisCurve->LastParameter(),
846 Precision::PConfusion(), fpar, lpar);
848 if (CurveSeq.IsEmpty())
850 CurveSeq.Append(aCurve);
851 TopoDS_Shape aLocShape;
852 aLocShape.Location(aLoc);
853 aLocShape.Orientation(wexp.Orientation());
854 LocSeq.Append(aLocShape);
855 FparSeq.Append(fpar);
856 LparSeq.Append(lpar);
858 FirstVertex = wexp.CurrentVertex();
862 Standard_Boolean Done = Standard_False;
863 Standard_Real NewFpar, NewLpar;
864 Handle(Geom_Geometry) aTrsfGeom = CurveSeq.Last()->Transformed
865 (LocSeq.Last().Location().Transformation());
866 GeomAdaptor_Curve GAprevcurve(Handle(Geom_Curve)::DownCast(aTrsfGeom));
867 TopoDS_Vertex CurVertex = wexp.CurrentVertex();
868 TopoDS_Vertex CurFirstVer = TopExp::FirstVertex(anEdge);
869 TopAbs_Orientation ConnectByOrigin = (CurVertex.IsSame(CurFirstVer))? TopAbs_FORWARD : TopAbs_REVERSED;
870 if (aCurve == CurveSeq.Last() && aLoc.IsEqual(LocSeq.Last().Location()))
874 if (aBasisCurve->IsPeriodic())
876 if (NewLpar < NewFpar)
877 NewLpar += aBasisCurve->Period();
878 if (ConnectByOrigin == TopAbs_FORWARD)
879 ElCLib::AdjustPeriodic(FparSeq.Last(),
880 FparSeq.Last() + aBasisCurve->Period(),
881 Precision::PConfusion(), NewFpar, NewLpar);
883 ElCLib::AdjustPeriodic(FparSeq.Last() - aBasisCurve->Period(),
885 Precision::PConfusion(), NewFpar, NewLpar);
887 Done = Standard_True;
889 else if (aType == CurType &&
890 aType != GeomAbs_BezierCurve &&
891 aType != GeomAbs_BSplineCurve &&
892 aType != GeomAbs_OtherCurve)
898 gp_Lin aLine = BAcurve.Line();
899 gp_Lin PrevLine = GAprevcurve.Line();
900 if (aLine.Contains(PrevLine.Location(), LinTol) &&
901 aLine.Direction().IsParallel(PrevLine.Direction(), AngTol))
903 gp_Pnt P1 = ElCLib::Value(fpar, aLine);
904 gp_Pnt P2 = ElCLib::Value(lpar, aLine);
905 NewFpar = ElCLib::Parameter(PrevLine, P1);
906 NewLpar = ElCLib::Parameter(PrevLine, P2);
909 if (ConnectByOrigin == TopAbs_FORWARD) {
910 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevLine);
912 aPntShiftDist += P2.Distance(aNewP2);
914 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevLine);
916 aPntShiftDist += P1.Distance(aNewP1);
919 if (NewLpar < NewFpar)
921 Standard_Real MemNewFpar = NewFpar;
923 NewLpar = MemNewFpar;
924 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
926 Done = Standard_True;
932 gp_Circ aCircle = BAcurve.Circle();
933 gp_Circ PrevCircle = GAprevcurve.Circle();
934 if (aCircle.Location().Distance(PrevCircle.Location()) <= LinTol &&
935 Abs(aCircle.Radius() - PrevCircle.Radius()) <= LinTol &&
936 aCircle.Axis().IsParallel(PrevCircle.Axis(), AngTol))
938 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
940 if (aCircle.Axis().Direction() * PrevCircle.Axis().Direction() < 0.)
942 Standard_Real memfpar = fpar;
945 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
947 gp_Pnt P1 = ElCLib::Value(fpar, aCircle);
948 gp_Pnt P2 = ElCLib::Value(lpar, aCircle);
949 NewFpar = ElCLib::Parameter(PrevCircle, P1);
950 NewLpar = ElCLib::Parameter(PrevCircle, P2);
954 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevCircle);
956 aPntShiftDist += P2.Distance(aNewP2);
958 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevCircle);
960 aPntShiftDist += P1.Distance(aNewP1);
963 if (NewLpar < NewFpar)
965 //Standard_Real MemNewFpar = NewFpar, MemNewLpar = NewLpar;
966 if (ConnectByOrigin == TopAbs_FORWARD)
967 ElCLib::AdjustPeriodic(FparSeq.Last(),
968 FparSeq.Last() + 2.*M_PI,
969 Precision::PConfusion(), NewFpar, NewLpar);
971 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
973 Precision::PConfusion(), NewFpar, NewLpar);
974 Done = Standard_True;
978 case GeomAbs_Ellipse:
980 gp_Elips anEllipse = BAcurve.Ellipse();
981 gp_Elips PrevEllipse = GAprevcurve.Ellipse();
982 if (anEllipse.Focus1().Distance(PrevEllipse.Focus1()) <= LinTol &&
983 anEllipse.Focus2().Distance(PrevEllipse.Focus2()) <= LinTol &&
984 Abs(anEllipse.MajorRadius() - PrevEllipse.MajorRadius()) <= LinTol &&
985 Abs(anEllipse.MinorRadius() - PrevEllipse.MinorRadius()) <= LinTol &&
986 anEllipse.Axis().IsParallel(PrevEllipse.Axis(), AngTol))
988 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
990 if (anEllipse.Axis().Direction() * PrevEllipse.Axis().Direction() < 0.)
992 Standard_Real memfpar = fpar;
995 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
997 gp_Pnt P1 = ElCLib::Value(fpar, anEllipse);
998 gp_Pnt P2 = ElCLib::Value(lpar, anEllipse);
999 NewFpar = ElCLib::Parameter(PrevEllipse, P1);
1000 NewLpar = ElCLib::Parameter(PrevEllipse, P2);
1004 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevEllipse);
1006 aPntShiftDist += P2.Distance(aNewP2);
1008 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevEllipse);
1010 aPntShiftDist += P1.Distance(aNewP1);
1013 if (NewLpar < NewFpar)
1015 if (ConnectByOrigin == TopAbs_FORWARD)
1016 ElCLib::AdjustPeriodic(FparSeq.Last(),
1017 FparSeq.Last() + 2.*M_PI,
1018 Precision::PConfusion(), NewFpar, NewLpar);
1020 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
1022 Precision::PConfusion(), NewFpar, NewLpar);
1023 Done = Standard_True;
1027 case GeomAbs_Hyperbola:
1029 gp_Hypr aHypr = BAcurve.Hyperbola();
1030 gp_Hypr PrevHypr = GAprevcurve.Hyperbola();
1031 if (aHypr.Focus1().Distance(PrevHypr.Focus1()) <= LinTol &&
1032 aHypr.Focus2().Distance(PrevHypr.Focus2()) <= LinTol &&
1033 Abs(aHypr.MajorRadius() - PrevHypr.MajorRadius()) <= LinTol &&
1034 Abs(aHypr.MinorRadius() - PrevHypr.MinorRadius()) <= LinTol &&
1035 aHypr.Axis().IsParallel(PrevHypr.Axis(), AngTol))
1037 gp_Pnt P1 = ElCLib::Value(fpar, aHypr);
1038 gp_Pnt P2 = ElCLib::Value(lpar, aHypr);
1039 NewFpar = ElCLib::Parameter(PrevHypr, P1);
1040 NewLpar = ElCLib::Parameter(PrevHypr, P2);
1043 if (ConnectByOrigin == TopAbs_FORWARD) {
1044 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevHypr);
1046 aPntShiftDist += P2.Distance(aNewP2);
1048 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevHypr);
1050 aPntShiftDist += P1.Distance(aNewP1);
1053 if (NewLpar < NewFpar)
1055 Standard_Real MemNewFpar = NewFpar;
1057 NewLpar = MemNewFpar;
1058 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1060 Done = Standard_True;
1064 case GeomAbs_Parabola:
1066 gp_Parab aParab = BAcurve.Parabola();
1067 gp_Parab PrevParab = GAprevcurve.Parabola();
1068 if (aParab.Location().Distance(PrevParab.Location()) <= LinTol &&
1069 aParab.Focus().Distance(PrevParab.Focus()) <= LinTol &&
1070 Abs(aParab.Focal() - PrevParab.Focal()) <= LinTol &&
1071 aParab.Axis().IsParallel(PrevParab.Axis(), AngTol))
1073 gp_Pnt P1 = ElCLib::Value(fpar, aParab);
1074 gp_Pnt P2 = ElCLib::Value(lpar, aParab);
1075 NewFpar = ElCLib::Parameter(PrevParab, P1);
1076 NewLpar = ElCLib::Parameter(PrevParab, P2);
1079 if (ConnectByOrigin == TopAbs_FORWARD) {
1080 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevParab);
1082 aPntShiftDist += P2.Distance(aNewP2);
1084 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevParab);
1086 aPntShiftDist += P1.Distance(aNewP1);
1089 if (NewLpar < NewFpar)
1091 Standard_Real MemNewFpar = NewFpar;
1093 NewLpar = MemNewFpar;
1094 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1096 Done = Standard_True;
1100 } //end of switch (aType)
1101 } // end of else if (aType == CurType && ...
1104 if (NewFpar < FparSeq.Last())
1105 FparSeq(FparSeq.Length()) = NewFpar;
1107 LparSeq(LparSeq.Length()) = NewLpar;
1111 CurveSeq.Append(aCurve);
1112 TopoDS_Shape aLocShape;
1113 aLocShape.Location(aLoc);
1114 aLocShape.Orientation(wexp.Orientation());
1115 LocSeq.Append(aLocShape);
1116 FparSeq.Append(fpar);
1117 LparSeq.Append(lpar);
1118 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(CurVertex));
1122 } // end of else (CurveSeq.IsEmpty()) -> not first time
1123 } // end for (; wexp.More(); wexp.Next())
1125 LastVertex = wexp.CurrentVertex();
1126 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(LastVertex));
1128 FirstVertex.Orientation(TopAbs_FORWARD);
1129 LastVertex.Orientation(TopAbs_REVERSED);
1131 if (!CurveSeq.IsEmpty())
1133 Standard_Integer nb_curve = CurveSeq.Length(); //number of curves
1134 TColGeom_Array1OfBSplineCurve tab(0,nb_curve-1); //array of the curves
1135 TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2); //array of the tolerances
1141 for (i = 1; i <= nb_curve; i++)
1143 if (CurveSeq(i)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1144 CurveSeq(i) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(i))))->BasisCurve();
1146 Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(CurveSeq(i), FparSeq(i), LparSeq(i));
1147 tab(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve);
1148 tab(i-1)->Transform(LocSeq(i).Location().Transformation());
1149 GeomConvert::C0BSplineToC1BSplineCurve(tab(i-1), Precision::Confusion());
1150 if (LocSeq(i).Orientation() == TopAbs_REVERSED)
1151 tab(i-1)->Reverse();
1154 //char* name = new char[100];
1155 //sprintf(name, "c%d", i);
1156 //DrawTrSurf::Set(name, tab(i-1));
1159 tabtolvertex(i-2) = TolSeq(i-1);
1160 } // end for (i = 1; i <= nb_curve; i++)
1161 tabtolvertex(nb_curve-1) = TolSeq(TolSeq.Length());
1163 Standard_Boolean closed_flag = Standard_False;
1164 Standard_Real closed_tolerance = 0.;
1165 if (FirstVertex.IsSame(LastVertex) &&
1166 GeomLProp::Continuity(tab(0), tab(nb_curve-1),
1167 tab(0)->FirstParameter(),
1168 tab(nb_curve-1)->LastParameter(),
1169 Standard_False, Standard_False, LinTol, AngTol) >= GeomAbs_G1)
1171 closed_flag = Standard_True ;
1172 closed_tolerance = BRep_Tool::Tolerance(FirstVertex);
1175 Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves
1176 Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex
1177 GeomConvert::ConcatC1(tab,
1182 closed_tolerance); //C1 concatenation
1184 if (concatcurve->Length() > 1)
1186 GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower()));
1188 for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++)
1189 Concat.Add( concatcurve->Value(i), LinTol, Standard_True );
1191 concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve());
1193 // rnc : prevents the driver from building an edge without C1 continuity
1194 if (concatcurve->Value(concatcurve->Lower())->Continuity()==GeomAbs_C0){
1195 Standard_ConstructionError::Raise("Construction aborted : The given Wire has sharp bends between some Edges, no valid Edge can be built");
1198 Standard_Boolean isValidEndVtx = Standard_True;
1201 // Check if closed curve is reordered.
1202 Handle(Geom_Curve) aCurve = concatcurve->Value(concatcurve->Lower());
1203 Standard_Real aFPar = aCurve->FirstParameter();
1205 gp_Pnt aPntVtx = BRep_Tool::Pnt(FirstVertex);
1206 Standard_Real aTolVtx = BRep_Tool::Tolerance(FirstVertex);
1208 aCurve->D0(aFPar, aPFirst);
1210 if (!aPFirst.IsEqual(aPntVtx, aTolVtx)) {
1211 // The curve is reordered. Find the new first and last vertices.
1212 TopTools_IndexedMapOfShape aMapVtx;
1213 TopExp::MapShapes(theWire, TopAbs_VERTEX, aMapVtx);
1215 const Standard_Integer aNbVtx = aMapVtx.Extent();
1216 Standard_Integer iVtx;
1218 for (iVtx = 1; iVtx <= aNbVtx; iVtx++) {
1219 const TopoDS_Vertex aVtx = TopoDS::Vertex(aMapVtx.FindKey(iVtx));
1220 const gp_Pnt aPnt = BRep_Tool::Pnt(aVtx);
1221 const Standard_Real aTol = BRep_Tool::Tolerance(aVtx);
1223 if (aPFirst.IsEqual(aPnt, aTol)) {
1224 // The coinsident vertex is found.
1227 FirstVertex.Orientation(TopAbs_FORWARD);
1228 LastVertex.Orientation(TopAbs_REVERSED);
1233 if (iVtx > aNbVtx) {
1234 // It is necessary to create new vertices.
1235 isValidEndVtx = Standard_False;
1240 if (isValidEndVtx) {
1241 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1242 FirstVertex, LastVertex,
1243 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1244 concatcurve->Value(concatcurve->Lower())->LastParameter());
1246 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1247 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1248 concatcurve->Value(concatcurve->Lower())->LastParameter());
1253 if (CurveSeq(1)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1254 CurveSeq(1) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(1))))->BasisCurve();
1256 Handle(Geom_Curve) aNewCurve =
1257 Handle(Geom_Curve)::DownCast(CurveSeq(1)->Copy());
1259 aNewCurve->Transform(LocSeq(1).Location().Transformation());
1261 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1262 const TopoDS_Vertex aVtxTmp = FirstVertex;
1264 FirstVertex = LastVertex;
1265 LastVertex = aVtxTmp;
1266 FirstVertex.Orientation(TopAbs_FORWARD);
1267 LastVertex.Orientation(TopAbs_REVERSED);
1270 ResEdge = BRepLib_MakeEdge(aNewCurve,
1271 FirstVertex, LastVertex,
1272 FparSeq(1), LparSeq(1));
1274 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1283 //=============================================================================
1285 * \brief Returns an isoline for a face.
1287 //=============================================================================
1289 TopoDS_Shape GEOMImpl_ShapeDriver::MakeIsoline
1290 (const TopoDS_Face &theFace,
1292 const double theParameter) const
1294 TopoDS_Shape aResult;
1295 GEOMUtils::Hatcher aHatcher(theFace);
1296 const GeomAbs_IsoType aType = (IsUIso ? GeomAbs_IsoU : GeomAbs_IsoV);
1298 aHatcher.Init(aType, theParameter);
1301 if (!aHatcher.IsDone()) {
1302 Standard_ConstructionError::Raise("MakeIsoline : Hatcher failure");
1305 const Handle(TColStd_HArray1OfInteger) &anIndices =
1306 (IsUIso ? aHatcher.GetUIndices() : aHatcher.GetVIndices());
1308 if (anIndices.IsNull()) {
1309 Standard_ConstructionError::Raise("MakeIsoline : Null hatching indices");
1312 const Standard_Integer anIsoInd = anIndices->Lower();
1313 const Standard_Integer aHatchingIndex = anIndices->Value(anIsoInd);
1315 if (aHatchingIndex == 0) {
1316 Standard_ConstructionError::Raise("MakeIsoline : Invalid hatching index");
1319 const Standard_Integer aNbDomains =
1320 aHatcher.GetNbDomains(aHatchingIndex);
1322 if (aNbDomains < 0) {
1323 Standard_ConstructionError::Raise("MakeIsoline : Invalid number of domains");
1326 // The hatching is performed successfully. Create the 3d Curve.
1327 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1328 Handle(Geom_Curve) anIsoCurve = (IsUIso ?
1329 aSurface->UIso(theParameter) : aSurface->VIso(theParameter));
1330 Handle(Geom2d_Curve) aPIsoCurve =
1331 aHatcher.GetHatching(aHatchingIndex);
1332 const Standard_Real aTol = Precision::Confusion();
1333 Standard_Integer anIDom = 1;
1336 BRep_Builder aBuilder;
1337 Standard_Integer aNbEdges = 0;
1339 for (; anIDom <= aNbDomains; anIDom++) {
1340 if (aHatcher.GetDomain(aHatchingIndex, anIDom, aV1, aV2)) {
1341 // Check first and last parameters.
1342 if (!aHatcher.IsDomainInfinite(aHatchingIndex, anIDom)) {
1344 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(anIsoCurve, aV1, aV2);
1346 // Update it with a parametric curve on face.
1347 aBuilder.UpdateEdge(anEdge, aPIsoCurve, theFace, aTol);
1351 // Result is a compond.
1352 if (aNbEdges == 2) {
1353 // Create a new compound.
1354 TopoDS_Compound aCompound;
1356 aBuilder.MakeCompound(aCompound);
1357 aBuilder.Add(aCompound, aResult);
1358 aResult = aCompound;
1361 // Add an edge to the compound.
1362 aBuilder.Add(aResult, anEdge);
1364 // Result is the edge.
1371 if (aNbEdges == 0) {
1372 Standard_ConstructionError::Raise("MakeIsoline : Empty result");
1378 //=============================================================================
1380 * \brief Returns an extended edge.
1382 //=============================================================================
1384 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendEdge
1385 (const TopoDS_Edge &theEdge,
1386 const Standard_Real theMin,
1387 const Standard_Real theMax) const
1389 TopoDS_Shape aResult;
1392 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(theEdge, aF, aL);
1393 const Standard_Real aTol = BRep_Tool::Tolerance(theEdge);
1394 Standard_Real aRange2d = aL - aF;
1396 if (aCurve.IsNull() == Standard_False && aRange2d > aTol) {
1397 Standard_Real aMin = aF + aRange2d*theMin;
1398 Standard_Real aMax = aF + aRange2d*theMax;
1400 Handle(Standard_Type) aType = aCurve->DynamicType();
1402 // Get the curve of original type
1403 while (aType == STANDARD_TYPE(Geom_TrimmedCurve)) {
1404 Handle(Geom_TrimmedCurve) aTrCurve =
1405 Handle(Geom_TrimmedCurve)::DownCast(aCurve);
1407 aCurve = aTrCurve->BasisCurve();
1408 aType = aCurve->DynamicType();
1411 if (aCurve->IsPeriodic()) {
1412 // The curve is periodic. Check if a new range is less then a period.
1413 if (aMax - aMin > aCurve->Period()) {
1414 aMax = aMin + aCurve->Period();
1417 // The curve is not periodic. Check if aMin and aMax within bounds.
1418 aMin = Max(aMin, aCurve->FirstParameter());
1419 aMax = Min(aMax, aCurve->LastParameter());
1422 if (aMax - aMin > aTol) {
1423 // Create a new edge.
1424 BRepBuilderAPI_MakeEdge aME (aCurve, aMin, aMax);
1427 aResult = aME.Shape();
1435 //=============================================================================
1437 * \brief Returns an extended face.
1439 //=============================================================================
1441 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendFace
1442 (const TopoDS_Face &theFace,
1443 const Standard_Real theUMin,
1444 const Standard_Real theUMax,
1445 const Standard_Real theVMin,
1446 const Standard_Real theVMax) const
1448 TopoDS_Shape aResult;
1449 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1450 const Standard_Real aTol = BRep_Tool::Tolerance(theFace);
1456 // Get U, V bounds of the face.
1457 ShapeAnalysis::GetFaceUVBounds(theFace, aU1, aU2, aV1, aV2);
1459 const Standard_Real aURange = aU2 - aU1;
1460 const Standard_Real aVRange = aV2 - aV1;
1462 if (aSurface.IsNull() == Standard_False &&
1463 aURange > aTol && aURange > aTol) {
1464 Handle(Standard_Type) aType = aSurface->DynamicType();
1466 // Get the surface of original type
1467 while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1468 Handle(Geom_RectangularTrimmedSurface) aTrSurface =
1469 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
1471 aSurface = aTrSurface->BasisSurface();
1472 aType = aSurface->DynamicType();
1475 Standard_Real aUMin = aU1 + aURange*theUMin;
1476 Standard_Real aUMax = aU1 + aURange*theUMax;
1477 Standard_Real aVMin = aV1 + aVRange*theVMin;
1478 Standard_Real aVMax = aV1 + aVRange*theVMax;
1480 aSurface->Bounds(aU1, aU2, aV1, aV2);
1482 if (aSurface->IsUPeriodic()) {
1483 // The surface is U-periodic. Check if a new U range is less
1485 if (aUMax - aUMin > aSurface->UPeriod()) {
1486 aUMax = aUMin + aSurface->UPeriod();
1489 // The surface is not V-periodic. Check if aUMin and aUMax
1491 aUMin = Max(aUMin, aU1);
1492 aUMax = Min(aUMax, aU2);
1495 if (aSurface->IsVPeriodic()) {
1496 // The surface is V-periodic. Check if a new V range is less
1498 if (aVMax - aVMin > aSurface->VPeriod()) {
1499 aVMax = aVMin + aSurface->VPeriod();
1502 // The surface is not V-periodic. Check if aVMin and aVMax
1504 aVMin = Max(aVMin, aV1);
1505 aVMax = Min(aVMax, aV2);
1508 if (aUMax - aUMin > aTol && aVMax - aVMin > aTol) {
1509 // Create a new edge.
1510 BRepBuilderAPI_MakeFace aMF
1511 (aSurface, aUMin, aUMax, aVMin, aVMax, aTol);
1514 aResult = aMF.Shape();
1522 //================================================================================
1524 * \brief Returns a name of creation operation and names and values of creation parameters
1526 //================================================================================
1528 bool GEOMImpl_ShapeDriver::
1529 GetCreationInformation(std::string& theOperationName,
1530 std::vector<GEOM_Param>& theParams)
1532 if (Label().IsNull()) return 0;
1533 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
1535 GEOMImpl_IShapes aCI( function );
1536 Standard_Integer aType = function->GetType();
1540 theOperationName = "WIRE";
1541 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1542 AddParam( theParams, "Tolerance", aCI.GetTolerance() );
1545 theOperationName = "FACE";
1546 AddParam( theParams, "Wire/edge", aCI.GetBase() );
1547 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1550 theOperationName = "FACE";
1551 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1552 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1554 case FACE_FROM_SURFACE:
1556 theOperationName = "FACE";
1558 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1560 if (shapes.IsNull() == Standard_False) {
1561 Standard_Integer aNbShapes = shapes->Length();
1563 if (aNbShapes > 0) {
1564 AddParam(theParams, "Face", shapes->Value(1));
1566 if (aNbShapes > 1) {
1567 AddParam(theParams, "Wire", shapes->Value(2));
1574 theOperationName = "SHELL";
1575 AddParam( theParams, "Objects", aCI.GetShapes() );
1578 theOperationName = "SOLID";
1579 AddParam( theParams, "Objects", aCI.GetShapes() );
1582 theOperationName = "SOLID_FROM_FACES";
1583 AddParam( theParams, "Objects", aCI.GetShapes() );
1584 AddParam( theParams, "Is intersect", aCI.GetIsIntersect() );
1586 case COMPOUND_SHAPES:
1587 theOperationName = "COMPOUND";
1588 AddParam( theParams, "Objects", aCI.GetShapes() );
1591 theOperationName = "EDGE";
1592 AddParam( theParams, "Wire", aCI.GetBase() );
1593 AddParam( theParams, "Linear Tolerance", aCI.GetTolerance() );
1594 AddParam( theParams, "Angular Tolerance", aCI.GetAngularTolerance() );
1596 case EDGE_CURVE_LENGTH:
1597 theOperationName = "EDGE";
1599 GEOMImpl_IVector aCI( function );
1600 AddParam( theParams, "Edge", aCI.GetPoint1() );
1601 AddParam( theParams, "Start point", aCI.GetPoint2() );
1602 AddParam( theParams, "Length", aCI.GetParameter() );
1605 case SHAPES_ON_SHAPE:
1607 theOperationName = "GetShapesOnShapeAsCompound";
1608 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1609 if ( !shapes.IsNull() && shapes->Length() > 0 )
1610 AddParam( theParams, "Check shape", shapes->Value(1) );
1611 if ( !shapes.IsNull() && shapes->Length() > 1 )
1612 AddParam( theParams, "Shape", shapes->Value(2) );
1613 AddParam( theParams, "Shape type", TopAbs_ShapeEnum( aCI.GetSubShapeType() ));
1614 AddParam( theParams, "State" );
1615 GEOMAlgo_State st = GEOMAlgo_State( (int) ( aCI.GetTolerance()+0.1 ) );
1616 const char* stName[] = { "UNKNOWN","IN","OUT","ON","ONIN","ONOUT","INOUT" };
1617 if ( 0 <= st && st <= GEOMAlgo_ST_INOUT )
1618 theParams.back() << stName[ st ];
1620 theParams.back() << (int) st;
1625 GEOMImpl_IIsoline aII (function);
1627 theOperationName = "ISOLINE";
1628 AddParam(theParams, "Face", aII.GetFace());
1629 AddParam(theParams, "Isoline type", (aII.GetIsUIso() ? "U" : "V"));
1630 AddParam(theParams, "Parameter", aII.GetParameter());
1635 GEOMImpl_IShapeExtend aSE (function);
1637 theOperationName = "EDGE_EXTEND";
1638 AddParam(theParams, "Edge", aSE.GetShape());
1639 AddParam(theParams, "Min", aSE.GetUMin());
1640 AddParam(theParams, "Max", aSE.GetUMax());
1645 GEOMImpl_IShapeExtend aSE (function);
1647 theOperationName = "FACE_EXTEND";
1648 AddParam(theParams, "Face", aSE.GetShape());
1649 AddParam(theParams, "UMin", aSE.GetUMin());
1650 AddParam(theParams, "UMax", aSE.GetUMax());
1651 AddParam(theParams, "VMin", aSE.GetVMin());
1652 AddParam(theParams, "VMax", aSE.GetVMax());
1655 case SURFACE_FROM_FACE:
1657 GEOMImpl_IShapeExtend aSE (function);
1659 theOperationName = "SURFACE_FROM_FACE";
1660 AddParam(theParams, "Face", aSE.GetShape());
1670 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1671 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1673 //modified by NIZNHY-PKV Wed Dec 28 13:48:31 2011f
1674 #include <TopoDS_Iterator.hxx>
1675 #include <TopTools_HSequenceOfShape.hxx>
1676 #include <ShapeAnalysis_FreeBounds.hxx>
1677 #include <TopTools_MapOfShape.hxx>
1678 #include <TopTools_MapOfOrientedShape.hxx>
1679 #include <BRep_Builder.hxx>
1680 #include <TopoDS_Wire.hxx>
1682 //=======================================================================
1683 //function : KeepEdgesOrder
1685 //=======================================================================
1687 void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
1688 const Handle(TopTools_HSequenceOfShape)& aWires)
1690 Standard_Integer aNbWires, aNbEdges;
1692 if (aEdges.IsNull()) {
1696 if (aWires.IsNull()) {
1700 aNbEdges=aEdges->Length();
1701 aNbWires=aWires->Length();
1702 if (!aNbEdges || !aNbWires) {
1706 Standard_Boolean bClosed;
1707 Standard_Integer i, j;
1709 TopoDS_Iterator aIt;
1711 TopTools_MapOfOrientedShape aMEx;
1713 for (i=1; i<=aNbWires; ++i) {
1714 const TopoDS_Shape& aWx=aWires->Value(i);
1717 aIt.Initialize (aWx);
1718 for (; aIt.More(); aIt.Next()) {
1719 const TopoDS_Shape& aEx=aIt.Value();
1724 for (j=1; j<=aNbEdges; ++j) {
1725 const TopoDS_Shape& aE=aEdges->Value(j);
1726 if (aMEx.Contains(aE)) {
1731 bClosed=aWx.Closed();
1732 aWy.Closed(bClosed);
1734 aWires->Append(aWy);
1735 }// for (i=1; i<=aNbWires; ++i) {
1737 aWires->Remove(1, aNbWires);
1740 //modified by NIZNHY-PKV Wed Dec 28 13:48:34 2011t