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>
64 #include <TopExp_Explorer.hxx>
66 #include <TopoDS_Shape.hxx>
67 #include <TopoDS_Edge.hxx>
68 #include <TopoDS_Wire.hxx>
69 #include <TopoDS_Shell.hxx>
70 #include <TopoDS_Solid.hxx>
71 #include <TopoDS_Compound.hxx>
72 #include <TopoDS_Iterator.hxx>
74 #include <TopTools_MapOfShape.hxx>
75 #include <TopTools_HSequenceOfShape.hxx>
79 #include <GCPnts_AbscissaPoint.hxx>
81 #include <Geom_TrimmedCurve.hxx>
82 #include <Geom_RectangularTrimmedSurface.hxx>
83 #include <Geom_Surface.hxx>
84 #include <GeomAbs_CurveType.hxx>
85 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
86 #include <GeomConvert.hxx>
87 #include <GeomLProp.hxx>
89 #include <TColStd_SequenceOfReal.hxx>
90 #include <TColStd_HSequenceOfTransient.hxx>
91 #include <TColStd_Array1OfReal.hxx>
92 #include <TColGeom_SequenceOfCurve.hxx>
93 #include <TColGeom_Array1OfBSplineCurve.hxx>
94 #include <TColGeom_HArray1OfBSplineCurve.hxx>
96 #include <Precision.hxx>
98 #include <Standard_NullObject.hxx>
99 #include <Standard_TypeMismatch.hxx>
100 #include <Standard_ConstructionError.hxx>
102 #include <BOPAlgo_PaveFiller.hxx>
103 #include <BOPAlgo_MakerVolume.hxx>
107 //modified by NIZNHY-PKV Wed Dec 28 13:48:20 2011f
109 // void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
110 // const Handle(TopTools_HSequenceOfShape)& aWires);
111 //modified by NIZNHY-PKV Wed Dec 28 13:48:23 2011t
113 //=======================================================================
116 //=======================================================================
117 const Standard_GUID& GEOMImpl_ShapeDriver::GetID()
119 static Standard_GUID aShapeDriver("FF1BBB54-5D14-4df2-980B-3A668264EA16");
124 //=======================================================================
125 //function : GEOMImpl_ShapeDriver
127 //=======================================================================
128 GEOMImpl_ShapeDriver::GEOMImpl_ShapeDriver()
132 //=======================================================================
135 //=======================================================================
136 Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
138 if (Label().IsNull()) return 0;
139 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
141 GEOMImpl_IShapes aCI (aFunction);
142 Standard_Integer aType = aFunction->GetType();
145 TCollection_AsciiString aWarning;
146 std::list<TopAbs_ShapeEnum> anExpectedType;
150 if (aType == WIRE_EDGES) {
151 anExpectedType.push_back(TopAbs_WIRE);
153 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
155 Standard_Real aTolerance = aCI.GetTolerance();
156 if (aTolerance < Precision::Confusion())
157 aTolerance = Precision::Confusion();
159 aShape = MakeWireFromEdges(aShapes, aTolerance);
161 else if (aType == FACE_WIRE) {
162 anExpectedType.push_back(TopAbs_FACE);
164 Handle(GEOM_Function) aRefBase = aCI.GetBase();
165 TopoDS_Shape aShapeBase = aRefBase->GetValue();
166 if (aShapeBase.IsNull()) Standard_NullObject::Raise("Argument Shape is null");
168 if (aShapeBase.ShapeType() == TopAbs_WIRE) {
169 W = TopoDS::Wire(aShapeBase);
170 // check the wire is closed
171 TopoDS_Vertex aV1, aV2;
172 TopExp::Vertices(W, aV1, aV2);
173 if ( !aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2) )
174 aShapeBase.Closed(true);
176 Standard_NullObject::Raise
177 ("Shape for face construction is not closed");
179 else if (aShapeBase.ShapeType() == TopAbs_EDGE && BRep_Tool::IsClosed(aShapeBase)) {
180 BRepBuilderAPI_MakeWire MW;
181 MW.Add(TopoDS::Edge(aShapeBase));
183 Standard_ConstructionError::Raise("Wire construction failed");
188 Standard_NullObject::Raise
189 ("Shape for face construction is neither a wire nor a closed edge");
191 aWarning = GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), aShape);
192 if (aShape.IsNull()) {
193 Standard_ConstructionError::Raise("Face construction failed");
196 else if (aType == FACE_WIRES) {
197 anExpectedType.push_back(TopAbs_FACE);
199 // Try to build a face from a set of wires and edges
202 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
203 int nbshapes = aShapes->Length();
205 Standard_ConstructionError::Raise("No wires or edges given");
208 // 1. Extract all edges from the given arguments
209 TopTools_MapOfShape aMapEdges;
210 Handle(TopTools_HSequenceOfShape) aSeqEdgesIn = new TopTools_HSequenceOfShape;
212 for (ind = 1; ind <= nbshapes; ind++) {
213 Handle(GEOM_Function) aRefSh_i = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
214 TopoDS_Shape aSh_i = aRefSh_i->GetValue();
216 TopExp_Explorer anExpE_i (aSh_i, TopAbs_EDGE);
217 for (; anExpE_i.More(); anExpE_i.Next()) {
218 if (aMapEdges.Add(anExpE_i.Current())) {
219 aSeqEdgesIn->Append(anExpE_i.Current());
224 if (aSeqEdgesIn->IsEmpty()) {
225 Standard_ConstructionError::Raise("No edges given");
228 // 2. Connect edges to wires of maximum length
229 Handle(TopTools_HSequenceOfShape) aSeqWiresOut;
230 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdgesIn, Precision::Confusion(),
231 /*shared*/Standard_False, aSeqWiresOut);
232 //modified by NIZNHY-PKV Wed Dec 28 13:46:55 2011f
233 //KeepEdgesOrder(aSeqEdgesIn, aSeqWiresOut);
234 //modified by NIZNHY-PKV Wed Dec 28 13:46:59 2011t
236 // 3. Separate closed wires
237 Handle(TopTools_HSequenceOfShape) aSeqClosedWires = new TopTools_HSequenceOfShape;
238 Handle(TopTools_HSequenceOfShape) aSeqOpenWires = new TopTools_HSequenceOfShape;
239 for (ind = 1; ind <= aSeqWiresOut->Length(); ind++) {
240 if (aSeqWiresOut->Value(ind).Closed())
241 aSeqClosedWires->Append(aSeqWiresOut->Value(ind));
243 aSeqOpenWires->Append(aSeqWiresOut->Value(ind));
246 if (aSeqClosedWires->Length() < 1) {
247 Standard_ConstructionError::Raise
248 ("There is no closed contour can be built from the given arguments");
251 // 4. Build a face / list of faces from all the obtained closed wires
255 TopoDS_Wire aW1 = TopoDS::Wire(aSeqClosedWires->Value(1));
256 aWarning = GEOMImpl_Block6Explorer::MakeFace(aW1, aCI.GetIsPlanar(), aFFace);
257 if (aFFace.IsNull()) {
258 Standard_ConstructionError::Raise("Face construction failed");
261 // 4.b. Add other wires
262 if (aSeqClosedWires->Length() == 1) {
267 BRep_Builder aBuilder;
268 aBuilder.MakeCompound(C);
269 BRepAlgo_FaceRestrictor FR;
271 TopAbs_Orientation OriF = aFFace.Orientation();
272 TopoDS_Shape aLocalS = aFFace.Oriented(TopAbs_FORWARD);
273 FR.Init(TopoDS::Face(aLocalS), Standard_False, Standard_True);
275 for (ind = 1; ind <= aSeqClosedWires->Length(); ind++) {
276 TopoDS_Wire aW = TopoDS::Wire(aSeqClosedWires->Value(ind));
285 for (; FR.More(); FR.Next()) {
286 aFace = FR.Current().Oriented(OriF);
287 aBuilder.Add(C, aFace);
298 // 5. Add all open wires to the result
299 if (aSeqOpenWires->Length() > 0) {
300 //Standard_ConstructionError::Raise("There are some open wires");
302 BRep_Builder aBuilder;
303 if (aSeqClosedWires->Length() == 1) {
304 aBuilder.MakeCompound(C);
305 aBuilder.Add(C, aShape);
308 C = TopoDS::Compound(aShape);
311 for (ind = 1; ind <= aSeqOpenWires->Length(); ind++) {
312 aBuilder.Add(C, aSeqOpenWires->Value(ind));
318 else if (aType == FACE_FROM_SURFACE) {
319 anExpectedType.push_back(TopAbs_FACE);
321 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
323 if (aShapes.IsNull() == Standard_False) {
324 Standard_Integer aNbShapes = aShapes->Length();
326 if (aNbShapes == 2) {
327 Handle(GEOM_Function) aRefFace =
328 Handle(GEOM_Function)::DownCast(aShapes->Value(1));
329 Handle(GEOM_Function) aRefWire =
330 Handle(GEOM_Function)::DownCast(aShapes->Value(2));
332 if (aRefFace.IsNull() == Standard_False &&
333 aRefWire.IsNull() == Standard_False) {
334 TopoDS_Shape aShFace = aRefFace->GetValue();
335 TopoDS_Shape aShWire = aRefWire->GetValue();
337 if (aShFace.IsNull() == Standard_False &&
338 aShFace.ShapeType() == TopAbs_FACE &&
339 aShWire.IsNull() == Standard_False &&
340 aShWire.ShapeType() == TopAbs_WIRE) {
341 TopoDS_Face aFace = TopoDS::Face(aShFace);
342 TopoDS_Wire aWire = TopoDS::Wire(aShWire);
343 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
344 BRepBuilderAPI_MakeFace aMkFace(aSurf, aWire);
346 if (aMkFace.IsDone()) {
347 aShape = aMkFace.Shape();
354 else if (aType == SHELL_FACES) {
355 anExpectedType.push_back(TopAbs_SHELL);
357 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
358 unsigned int ind, nbshapes = aShapes->Length();
361 BRepBuilderAPI_Sewing aSewing (Precision::Confusion()*10.0);
362 for (ind = 1; ind <= nbshapes; ind++) {
363 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
364 TopoDS_Shape aShape_i = aRefShape->GetValue();
365 if (aShape_i.IsNull()) {
366 Standard_NullObject::Raise("Face for shell construction is null");
368 aSewing.Add(aShape_i);
373 TopoDS_Shape sh = aSewing.SewedShape();
375 if (sh.ShapeType()==TopAbs_FACE && nbshapes==1) {
376 // case for creation of shell from one face - PAL12722 (skl 26.06.2006)
383 //TopExp_Explorer exp (aSewing.SewedShape(), TopAbs_SHELL);
384 TopExp_Explorer exp (sh, TopAbs_SHELL);
385 Standard_Integer ish = 0;
386 for (; exp.More(); exp.Next()) {
387 aShape = exp.Current();
392 // try the case of one face (Mantis issue 0021809)
393 TopExp_Explorer expF (sh, TopAbs_FACE);
394 Standard_Integer ifa = 0;
395 for (; expF.More(); expF.Next()) {
396 aShape = expF.Current();
407 aShape = aSewing.SewedShape();
413 else if (aType == SOLID_SHELLS) {
414 anExpectedType.push_back(TopAbs_SOLID);
416 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
417 unsigned int ind, nbshapes = aShapes->Length();
418 Standard_Integer ish = 0;
419 BRepBuilderAPI_MakeSolid aMkSolid;
422 for (ind = 1; ind <= nbshapes; ind++) {
423 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
424 TopoDS_Shape aShapeShell = aRefShape->GetValue();
425 if (aShapeShell.IsNull()) {
426 Standard_NullObject::Raise("Shell for solid construction is null");
428 if (aShapeShell.ShapeType() == TopAbs_COMPOUND) {
429 TopoDS_Iterator It (aShapeShell, Standard_True, Standard_True);
430 for (; It.More(); It.Next()) {
431 TopoDS_Shape aSubShape = It.Value();
432 if (aSubShape.ShapeType() == TopAbs_SHELL) {
433 aMkSolid.Add(TopoDS::Shell(aSubShape));
437 Standard_TypeMismatch::Raise
438 ("Shape for solid construction is neither a shell nor a compound of shells");
441 else if (aShapeShell.ShapeType() == TopAbs_SHELL) {
442 aMkSolid.Add(TopoDS::Shell(aShapeShell));
446 if (ish == 0 || !aMkSolid.IsDone()) return 0;
448 TopoDS_Solid Sol = aMkSolid.Solid();
449 BRepClass3d_SolidClassifier SC (Sol);
450 SC.PerformInfinitePoint(Precision::Confusion());
451 if (SC.State() == TopAbs_IN)
452 aShape = Sol.Reversed();
456 else if (aType == COMPOUND_SHAPES) {
457 anExpectedType.push_back(TopAbs_COMPOUND);
459 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
460 unsigned int ind, nbshapes = aShapes->Length();
465 for (ind = 1; ind <= nbshapes; ind++) {
466 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
467 TopoDS_Shape aShape_i = aRefShape->GetValue();
468 if (aShape_i.IsNull()) {
469 Standard_NullObject::Raise("Shape for compound construction is null");
477 else if (aType == EDGE_WIRE) {
478 anExpectedType.push_back(TopAbs_EDGE);
480 Handle(GEOM_Function) aRefBase = aCI.GetBase();
481 TopoDS_Shape aWire = aRefBase->GetValue();
482 Standard_Real LinTol = aCI.GetTolerance();
483 Standard_Real AngTol = aCI.GetAngularTolerance();
484 if (aWire.IsNull()) Standard_NullObject::Raise("Argument Wire is null");
486 aShape = MakeEdgeFromWire(aWire, LinTol, AngTol);
488 else if (aType == SOLID_FACES) {
489 anExpectedType.push_back(TopAbs_SOLID);
490 anExpectedType.push_back(TopAbs_COMPOUND);
491 anExpectedType.push_back(TopAbs_COMPSOLID);
493 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
494 unsigned int ind, nbshapes = aShapes->Length();
497 BOPCol_ListOfShape aLS;
498 for (ind = 1; ind <= nbshapes; ind++) {
499 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
500 TopoDS_Shape aShape_i = aRefShape->GetValue();
501 if (aShape_i.IsNull()) {
502 Standard_NullObject::Raise("Shape for solid construction is null");
504 if (aShape_i.ShapeType() == TopAbs_COMPOUND) {
505 TopoDS_Iterator It (aShape_i, Standard_True, Standard_True);
506 for (; It.More(); It.Next()) {
507 TopoDS_Shape aSubShape = It.Value();
508 if (aSubShape.ShapeType() == TopAbs_FACE || aSubShape.ShapeType() == TopAbs_SHELL)
509 aLS.Append(aSubShape);
511 Standard_TypeMismatch::Raise
512 ("Shape for solid construction is neither a list of faces and/or shells "
513 "nor a compound of faces and/or shells");
516 aLS.Append(aShape_i);
519 BOPAlgo_MakerVolume aMV;
520 aMV.SetArguments(aLS);
521 aMV.SetIntersect(aCI.GetIsIntersect());
523 if (aMV.ErrorStatus()) return 0;
525 aShape = aMV.Shape();
527 else if (aType == EDGE_CURVE_LENGTH) {
528 anExpectedType.push_back(TopAbs_EDGE);
530 GEOMImpl_IVector aVI (aFunction);
533 Handle(GEOM_Function) aRefCurve = aVI.GetPoint1();
534 if (aRefCurve.IsNull()) Standard_NullObject::Raise("Argument Curve is null");
535 TopoDS_Shape aRefShape1 = aRefCurve->GetValue();
536 if (aRefShape1.ShapeType() != TopAbs_EDGE) {
537 Standard_TypeMismatch::Raise
538 ("Edge On Curve creation aborted : curve shape is not an edge");
540 TopoDS_Edge aRefEdge = TopoDS::Edge(aRefShape1);
541 TopoDS_Vertex V1, V2;
542 TopExp::Vertices(aRefEdge, V1, V2, Standard_True);
545 TopoDS_Vertex aRefVertex;
546 Handle(GEOM_Function) aRefPoint = aVI.GetPoint2();
547 if (aRefPoint.IsNull()) {
551 TopoDS_Shape aRefShape2 = aRefPoint->GetValue();
552 if (aRefShape2.ShapeType() != TopAbs_VERTEX) {
553 Standard_TypeMismatch::Raise
554 ("Edge On Curve creation aborted : start point shape is not a vertex");
556 aRefVertex = TopoDS::Vertex(aRefShape2);
558 gp_Pnt aRefPnt = BRep_Tool::Pnt(aRefVertex);
561 Standard_Real aLength = aVI.GetParameter();
562 //Standard_Real aCurveLength = IntTools::Length(aRefEdge);
563 //if (aLength > aCurveLength) {
564 // Standard_ConstructionError::Raise
565 // ("Edge On Curve creation aborted : given length is greater than edges length");
567 if (fabs(aLength) < Precision::Confusion()) {
568 Standard_ConstructionError::Raise
569 ("Edge On Curve creation aborted : given length is smaller than Precision::Confusion()");
573 Standard_Real UFirst, ULast;
574 Handle(Geom_Curve) EdgeCurve = BRep_Tool::Curve(aRefEdge, UFirst, ULast);
575 Handle(Geom_Curve) ReOrientedCurve = EdgeCurve;
577 Standard_Real dU = ULast - UFirst;
578 Standard_Real par1 = UFirst + 0.1 * dU;
579 Standard_Real par2 = ULast - 0.1 * dU;
581 gp_Pnt P1 = EdgeCurve->Value(par1);
582 gp_Pnt P2 = EdgeCurve->Value(par2);
584 if (aRefPnt.SquareDistance(P2) < aRefPnt.SquareDistance(P1)) {
585 ReOrientedCurve = EdgeCurve->Reversed();
586 UFirst = EdgeCurve->ReversedParameter(ULast);
589 // Get the point by length
590 GeomAdaptor_Curve AdapCurve = GeomAdaptor_Curve(ReOrientedCurve);
591 GCPnts_AbscissaPoint anAbsPnt (AdapCurve, aLength, UFirst);
592 Standard_Real aParam = anAbsPnt.Parameter();
594 if (AdapCurve.IsClosed() && aLength < 0.0) {
595 Standard_Real aTmp = aParam;
600 BRepBuilderAPI_MakeEdge aME (ReOrientedCurve, UFirst, aParam);
602 aShape = aME.Shape();
603 } else if (aType == SHAPE_ISOLINE) {
604 GEOMImpl_IIsoline aII (aFunction);
605 Handle(GEOM_Function) aRefFace = aII.GetFace();
606 TopoDS_Shape aShapeFace = aRefFace->GetValue();
608 if (aShapeFace.ShapeType() == TopAbs_FACE) {
609 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
610 bool isUIso = aII.GetIsUIso();
611 Standard_Real aParam = aII.GetParameter();
612 Standard_Real U1,U2,V1,V2;
614 // Construct a real geometric parameter.
615 aFace.Orientation(TopAbs_FORWARD);
616 ShapeAnalysis::GetFaceUVBounds(aFace,U1,U2,V1,V2);
619 aParam = U1 + (U2 - U1)*aParam;
621 aParam = V1 + (V2 - V1)*aParam;
624 aShape = MakeIsoline(aFace, isUIso, aParam);
626 Standard_NullObject::Raise
627 ("Shape for isoline construction is not a face");
629 } else if (aType == EDGE_UV) {
630 anExpectedType.push_back(TopAbs_EDGE);
631 GEOMImpl_IShapeExtend aSE (aFunction);
632 Handle(GEOM_Function) aRefEdge = aSE.GetShape();
633 TopoDS_Shape aShapeEdge = aRefEdge->GetValue();
635 if (aShapeEdge.ShapeType() == TopAbs_EDGE) {
636 TopoDS_Edge anEdge = TopoDS::Edge(aShapeEdge);
638 aShape = ExtendEdge(anEdge, aSE.GetUMin(), aSE.GetUMax());
640 } else if (aType == FACE_UV) {
641 anExpectedType.push_back(TopAbs_FACE);
643 GEOMImpl_IShapeExtend aSE (aFunction);
644 Handle(GEOM_Function) aRefFace = aSE.GetShape();
645 TopoDS_Shape aShapeFace = aRefFace->GetValue();
647 if (aShapeFace.ShapeType() == TopAbs_FACE) {
648 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
650 aFace.Orientation(TopAbs_FORWARD);
651 aShape = ExtendFace(aFace, aSE.GetUMin(), aSE.GetUMax(),
652 aSE.GetVMin(), aSE.GetVMax());
654 } else if (aType == SURFACE_FROM_FACE) {
655 anExpectedType.push_back(TopAbs_FACE);
657 GEOMImpl_IShapeExtend aSE (aFunction);
658 Handle(GEOM_Function) aRefFace = aSE.GetShape();
659 TopoDS_Shape aShapeFace = aRefFace->GetValue();
661 if (aShapeFace.ShapeType() == TopAbs_FACE) {
662 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
663 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
665 if (aSurface.IsNull() == Standard_False) {
666 Handle(Standard_Type) aType = aSurface->DynamicType();
672 // Get U, V bounds of the face.
673 aFace.Orientation(TopAbs_FORWARD);
674 ShapeAnalysis::GetFaceUVBounds(aFace, aU1, aU2, aV1, aV2);
676 // Get the surface of original type
677 while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
678 Handle(Geom_RectangularTrimmedSurface) aTrSurface =
679 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
681 aSurface = aTrSurface->BasisSurface();
682 aType = aSurface->DynamicType();
685 const Standard_Real aTol = BRep_Tool::Tolerance(aFace);
686 BRepBuilderAPI_MakeFace aMF(aSurface, aU1, aU2, aV1, aV2, aTol);
689 aShape = aMF.Shape();
697 if (aShape.IsNull()) return 0;
699 // Check shape validity
700 BRepCheck_Analyzer ana (aShape, false);
701 if (!ana.IsValid()) {
702 //Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
703 // For Mantis issue 0021772: EDF 2336 GEOM: Non valid face created from two circles
704 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape (aShape);
706 aShape = aSfs->Shape();
709 // Check if the result shape type is compatible with the expected.
710 const TopAbs_ShapeEnum aShType = aShape.ShapeType();
712 if (!anExpectedType.empty()) {
714 std::list<TopAbs_ShapeEnum>::const_iterator it;
715 for (it = anExpectedType.begin(); it != anExpectedType.end() && !ok; ++it)
716 ok = (*it == TopAbs_SHAPE || *it == aShType);
718 Standard_ConstructionError::Raise("Result type check failed");
721 aFunction->SetValue(aShape);
723 log.SetTouched(Label());
725 if (!aWarning.IsEmpty())
726 Standard_Failure::Raise(aWarning.ToCString());
731 TopoDS_Wire GEOMImpl_ShapeDriver::MakeWireFromEdges(const Handle(TColStd_HSequenceOfTransient)& theEdgesFuncs,
732 const Standard_Real theTolerance)
740 for (unsigned int ind = 1; ind <= theEdgesFuncs->Length(); ind++) {
741 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(theEdgesFuncs->Value(ind));
742 TopoDS_Shape aShape_i = aRefShape->GetValue();
743 if (aShape_i.IsNull()) {
744 Standard_NullObject::Raise("Shape for wire construction is null");
746 if (aShape_i.ShapeType() == TopAbs_EDGE || aShape_i.ShapeType() == TopAbs_WIRE) {
747 TopExp_Explorer exp (aShape_i, TopAbs_EDGE);
748 for (; exp.More(); exp.Next())
749 B.Add(aWire, TopoDS::Edge(exp.Current()));
751 Standard_TypeMismatch::Raise
752 ("Shape for wire construction is neither an edge nor a wire");
757 Handle(ShapeFix_Wire) aFW = new ShapeFix_Wire;
761 if (aFW->StatusReorder(ShapeExtend_FAIL1)) {
762 Standard_ConstructionError::Raise("Wire construction failed: several loops detected");
764 else if (aFW->StatusReorder(ShapeExtend_FAIL)) {
765 Standard_ConstructionError::Raise("Wire construction failed");
770 // IMP 0019766: Building a Wire from unconnected edges by introducing a tolerance
771 aFW->ClosedWireMode() = Standard_False;
772 aFW->FixConnected(theTolerance);
773 if (aFW->StatusConnected(ShapeExtend_FAIL)) {
774 Standard_ConstructionError::Raise("Wire construction failed: cannot build connected wire");
777 if (aFW->StatusConnected(ShapeExtend_DONE3)) {
778 // Confused with <prec> but not Analyzer.Precision(), set the same
779 aFW->FixGapsByRangesMode() = Standard_True;
780 if (aFW->FixGaps3d()) {
781 Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
782 Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
783 for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
784 TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
785 aFe->FixVertexTolerance(aEdge);
786 aFe->FixSameParameter(aEdge);
789 else if (aFW->StatusGaps3d(ShapeExtend_FAIL)) {
790 Standard_ConstructionError::Raise("Wire construction failed: cannot fix 3d gaps");
793 aWire = aFW->WireAPIMake();
798 TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
799 const Standard_Real LinTol,
800 const Standard_Real AngTol)
804 BRepLib::BuildCurves3d(aWire);
805 Handle(ShapeFix_Shape) Fixer = new ShapeFix_Shape(aWire);
806 Fixer->SetPrecision(LinTol);
807 Fixer->SetMaxTolerance(LinTol);
809 TopoDS_Wire theWire = TopoDS::Wire(Fixer->Shape());
811 TColGeom_SequenceOfCurve CurveSeq;
812 TopTools_SequenceOfShape LocSeq;
813 TColStd_SequenceOfReal FparSeq;
814 TColStd_SequenceOfReal LparSeq;
815 TColStd_SequenceOfReal TolSeq;
816 GeomAbs_CurveType CurType;
817 TopoDS_Vertex FirstVertex, LastVertex;
818 Standard_Real aPntShiftDist = 0.;
820 BRepTools_WireExplorer wexp(theWire) ;
821 for (; wexp.More(); wexp.Next())
823 TopoDS_Edge anEdge = wexp.Current();
824 Standard_Real fpar, lpar;
825 TopLoc_Location aLoc;
826 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aLoc, fpar, lpar);
830 BRepAdaptor_Curve BAcurve(anEdge);
831 GeomAbs_CurveType aType = BAcurve.GetType();
833 Handle(Geom_Curve) aBasisCurve = BAcurve.Curve().Curve();
835 if (aBasisCurve->IsPeriodic())
836 ElCLib::AdjustPeriodic(aBasisCurve->FirstParameter(), aBasisCurve->LastParameter(),
837 Precision::PConfusion(), fpar, lpar);
839 if (CurveSeq.IsEmpty())
841 CurveSeq.Append(aCurve);
842 TopoDS_Shape aLocShape;
843 aLocShape.Location(aLoc);
844 aLocShape.Orientation(wexp.Orientation());
845 LocSeq.Append(aLocShape);
846 FparSeq.Append(fpar);
847 LparSeq.Append(lpar);
849 FirstVertex = wexp.CurrentVertex();
853 Standard_Boolean Done = Standard_False;
854 Standard_Real NewFpar, NewLpar;
855 GeomAdaptor_Curve GAprevcurve(CurveSeq.Last());
856 TopoDS_Vertex CurVertex = wexp.CurrentVertex();
857 TopoDS_Vertex CurFirstVer = TopExp::FirstVertex(anEdge);
858 TopAbs_Orientation ConnectByOrigin = (CurVertex.IsSame(CurFirstVer))? TopAbs_FORWARD : TopAbs_REVERSED;
859 if (aCurve == CurveSeq.Last())
863 if (aBasisCurve->IsPeriodic())
865 if (NewLpar < NewFpar)
866 NewLpar += aBasisCurve->Period();
867 if (ConnectByOrigin == TopAbs_FORWARD)
868 ElCLib::AdjustPeriodic(FparSeq.Last(),
869 FparSeq.Last() + aBasisCurve->Period(),
870 Precision::PConfusion(), NewFpar, NewLpar);
872 ElCLib::AdjustPeriodic(FparSeq.Last() - aBasisCurve->Period(),
874 Precision::PConfusion(), NewFpar, NewLpar);
876 Done = Standard_True;
878 else if (aType == CurType &&
879 aType != GeomAbs_BezierCurve &&
880 aType != GeomAbs_BSplineCurve &&
881 aType != GeomAbs_OtherCurve)
887 gp_Lin aLine = BAcurve.Line();
888 gp_Lin PrevLine = GAprevcurve.Line();
889 if (aLine.Contains(PrevLine.Location(), LinTol) &&
890 aLine.Direction().IsParallel(PrevLine.Direction(), AngTol))
892 gp_Pnt P1 = ElCLib::Value(fpar, aLine);
893 gp_Pnt P2 = ElCLib::Value(lpar, aLine);
894 NewFpar = ElCLib::Parameter(PrevLine, P1);
895 NewLpar = ElCLib::Parameter(PrevLine, P2);
898 if (ConnectByOrigin == TopAbs_FORWARD) {
899 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevLine);
901 aPntShiftDist += P2.Distance(aNewP2);
903 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevLine);
905 aPntShiftDist += P1.Distance(aNewP1);
908 if (NewLpar < NewFpar)
910 Standard_Real MemNewFpar = NewFpar;
912 NewLpar = MemNewFpar;
913 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
915 Done = Standard_True;
921 gp_Circ aCircle = BAcurve.Circle();
922 gp_Circ PrevCircle = GAprevcurve.Circle();
923 if (aCircle.Location().Distance(PrevCircle.Location()) <= LinTol &&
924 Abs(aCircle.Radius() - PrevCircle.Radius()) <= LinTol &&
925 aCircle.Axis().IsParallel(PrevCircle.Axis(), AngTol))
927 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
929 if (aCircle.Axis().Direction() * PrevCircle.Axis().Direction() < 0.)
931 Standard_Real memfpar = fpar;
934 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
936 gp_Pnt P1 = ElCLib::Value(fpar, aCircle);
937 gp_Pnt P2 = ElCLib::Value(lpar, aCircle);
938 NewFpar = ElCLib::Parameter(PrevCircle, P1);
939 NewLpar = ElCLib::Parameter(PrevCircle, P2);
943 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevCircle);
945 aPntShiftDist += P2.Distance(aNewP2);
947 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevCircle);
949 aPntShiftDist += P1.Distance(aNewP1);
952 if (NewLpar < NewFpar)
954 //Standard_Real MemNewFpar = NewFpar, MemNewLpar = NewLpar;
955 if (ConnectByOrigin == TopAbs_FORWARD)
956 ElCLib::AdjustPeriodic(FparSeq.Last(),
957 FparSeq.Last() + 2.*M_PI,
958 Precision::PConfusion(), NewFpar, NewLpar);
960 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
962 Precision::PConfusion(), NewFpar, NewLpar);
963 Done = Standard_True;
967 case GeomAbs_Ellipse:
969 gp_Elips anEllipse = BAcurve.Ellipse();
970 gp_Elips PrevEllipse = GAprevcurve.Ellipse();
971 if (anEllipse.Focus1().Distance(PrevEllipse.Focus1()) <= LinTol &&
972 anEllipse.Focus2().Distance(PrevEllipse.Focus2()) <= LinTol &&
973 Abs(anEllipse.MajorRadius() - PrevEllipse.MajorRadius()) <= LinTol &&
974 Abs(anEllipse.MinorRadius() - PrevEllipse.MinorRadius()) <= LinTol &&
975 anEllipse.Axis().IsParallel(PrevEllipse.Axis(), AngTol))
977 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
979 if (anEllipse.Axis().Direction() * PrevEllipse.Axis().Direction() < 0.)
981 Standard_Real memfpar = fpar;
984 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
986 gp_Pnt P1 = ElCLib::Value(fpar, anEllipse);
987 gp_Pnt P2 = ElCLib::Value(lpar, anEllipse);
988 NewFpar = ElCLib::Parameter(PrevEllipse, P1);
989 NewLpar = ElCLib::Parameter(PrevEllipse, P2);
993 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevEllipse);
995 aPntShiftDist += P2.Distance(aNewP2);
997 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevEllipse);
999 aPntShiftDist += P1.Distance(aNewP1);
1002 if (NewLpar < NewFpar)
1004 if (ConnectByOrigin == TopAbs_FORWARD)
1005 ElCLib::AdjustPeriodic(FparSeq.Last(),
1006 FparSeq.Last() + 2.*M_PI,
1007 Precision::PConfusion(), NewFpar, NewLpar);
1009 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
1011 Precision::PConfusion(), NewFpar, NewLpar);
1012 Done = Standard_True;
1016 case GeomAbs_Hyperbola:
1018 gp_Hypr aHypr = BAcurve.Hyperbola();
1019 gp_Hypr PrevHypr = GAprevcurve.Hyperbola();
1020 if (aHypr.Focus1().Distance(PrevHypr.Focus1()) <= LinTol &&
1021 aHypr.Focus2().Distance(PrevHypr.Focus2()) <= LinTol &&
1022 Abs(aHypr.MajorRadius() - PrevHypr.MajorRadius()) <= LinTol &&
1023 Abs(aHypr.MinorRadius() - PrevHypr.MinorRadius()) <= LinTol &&
1024 aHypr.Axis().IsParallel(PrevHypr.Axis(), AngTol))
1026 gp_Pnt P1 = ElCLib::Value(fpar, aHypr);
1027 gp_Pnt P2 = ElCLib::Value(lpar, aHypr);
1028 NewFpar = ElCLib::Parameter(PrevHypr, P1);
1029 NewLpar = ElCLib::Parameter(PrevHypr, P2);
1032 if (ConnectByOrigin == TopAbs_FORWARD) {
1033 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevHypr);
1035 aPntShiftDist += P2.Distance(aNewP2);
1037 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevHypr);
1039 aPntShiftDist += P1.Distance(aNewP1);
1042 if (NewLpar < NewFpar)
1044 Standard_Real MemNewFpar = NewFpar;
1046 NewLpar = MemNewFpar;
1047 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1049 Done = Standard_True;
1053 case GeomAbs_Parabola:
1055 gp_Parab aParab = BAcurve.Parabola();
1056 gp_Parab PrevParab = GAprevcurve.Parabola();
1057 if (aParab.Location().Distance(PrevParab.Location()) <= LinTol &&
1058 aParab.Focus().Distance(PrevParab.Focus()) <= LinTol &&
1059 Abs(aParab.Focal() - PrevParab.Focal()) <= LinTol &&
1060 aParab.Axis().IsParallel(PrevParab.Axis(), AngTol))
1062 gp_Pnt P1 = ElCLib::Value(fpar, aParab);
1063 gp_Pnt P2 = ElCLib::Value(lpar, aParab);
1064 NewFpar = ElCLib::Parameter(PrevParab, P1);
1065 NewLpar = ElCLib::Parameter(PrevParab, P2);
1068 if (ConnectByOrigin == TopAbs_FORWARD) {
1069 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevParab);
1071 aPntShiftDist += P2.Distance(aNewP2);
1073 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevParab);
1075 aPntShiftDist += P1.Distance(aNewP1);
1078 if (NewLpar < NewFpar)
1080 Standard_Real MemNewFpar = NewFpar;
1082 NewLpar = MemNewFpar;
1083 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1085 Done = Standard_True;
1089 } //end of switch (aType)
1090 } // end of else if (aType == CurType && ...
1093 if (NewFpar < FparSeq.Last())
1094 FparSeq(FparSeq.Length()) = NewFpar;
1096 LparSeq(LparSeq.Length()) = NewLpar;
1100 CurveSeq.Append(aCurve);
1101 TopoDS_Shape aLocShape;
1102 aLocShape.Location(aLoc);
1103 aLocShape.Orientation(wexp.Orientation());
1104 LocSeq.Append(aLocShape);
1105 FparSeq.Append(fpar);
1106 LparSeq.Append(lpar);
1107 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(CurVertex));
1111 } // end of else (CurveSeq.IsEmpty()) -> not first time
1112 } // end for (; wexp.More(); wexp.Next())
1114 LastVertex = wexp.CurrentVertex();
1115 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(LastVertex));
1117 FirstVertex.Orientation(TopAbs_FORWARD);
1118 LastVertex.Orientation(TopAbs_REVERSED);
1120 if (!CurveSeq.IsEmpty())
1122 Standard_Integer nb_curve = CurveSeq.Length(); //number of curves
1123 TColGeom_Array1OfBSplineCurve tab(0,nb_curve-1); //array of the curves
1124 TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2); //array of the tolerances
1130 for (i = 1; i <= nb_curve; i++)
1132 if (CurveSeq(i)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1133 CurveSeq(i) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(i))))->BasisCurve();
1135 Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(CurveSeq(i), FparSeq(i), LparSeq(i));
1136 tab(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve);
1137 tab(i-1)->Transform(LocSeq(i).Location().Transformation());
1138 GeomConvert::C0BSplineToC1BSplineCurve(tab(i-1), Precision::Confusion());
1139 if (LocSeq(i).Orientation() == TopAbs_REVERSED)
1140 tab(i-1)->Reverse();
1143 //char* name = new char[100];
1144 //sprintf(name, "c%d", i);
1145 //DrawTrSurf::Set(name, tab(i-1));
1148 tabtolvertex(i-2) = TolSeq(i-1);
1149 } // end for (i = 1; i <= nb_curve; i++)
1150 tabtolvertex(nb_curve-1) = TolSeq(TolSeq.Length());
1152 Standard_Boolean closed_flag = Standard_False;
1153 Standard_Real closed_tolerance = 0.;
1154 if (FirstVertex.IsSame(LastVertex) &&
1155 GeomLProp::Continuity(tab(0), tab(nb_curve-1),
1156 tab(0)->FirstParameter(),
1157 tab(nb_curve-1)->LastParameter(),
1158 Standard_False, Standard_False, LinTol, AngTol) >= GeomAbs_G1)
1160 closed_flag = Standard_True ;
1161 closed_tolerance = BRep_Tool::Tolerance(FirstVertex);
1164 Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves
1165 Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex
1166 GeomConvert::ConcatC1(tab,
1171 closed_tolerance); //C1 concatenation
1173 if (concatcurve->Length() > 1)
1175 GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower()));
1177 for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++)
1178 Concat.Add( concatcurve->Value(i), LinTol, Standard_True );
1180 concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve());
1182 // rnc : prevents the driver from building an edge without C1 continuity
1183 if (concatcurve->Value(concatcurve->Lower())->Continuity()==GeomAbs_C0){
1184 Standard_ConstructionError::Raise("Construction aborted : The given Wire has sharp bends between some Edges, no valid Edge can be built");
1187 Standard_Boolean isValidEndVtx = Standard_True;
1190 // Check if closed curve is reordered.
1191 Handle(Geom_Curve) aCurve = concatcurve->Value(concatcurve->Lower());
1192 Standard_Real aFPar = aCurve->FirstParameter();
1194 gp_Pnt aPntVtx = BRep_Tool::Pnt(FirstVertex);
1195 Standard_Real aTolVtx = BRep_Tool::Tolerance(FirstVertex);
1197 aCurve->D0(aFPar, aPFirst);
1199 if (!aPFirst.IsEqual(aPntVtx, aTolVtx)) {
1200 // The curve is reordered. Find the new first and last vertices.
1201 TopTools_IndexedMapOfShape aMapVtx;
1202 TopExp::MapShapes(theWire, TopAbs_VERTEX, aMapVtx);
1204 const Standard_Integer aNbVtx = aMapVtx.Extent();
1205 Standard_Integer iVtx;
1207 for (iVtx = 1; iVtx <= aNbVtx; iVtx++) {
1208 const TopoDS_Vertex aVtx = TopoDS::Vertex(aMapVtx.FindKey(iVtx));
1209 const gp_Pnt aPnt = BRep_Tool::Pnt(aVtx);
1210 const Standard_Real aTol = BRep_Tool::Tolerance(aVtx);
1212 if (aPFirst.IsEqual(aPnt, aTol)) {
1213 // The coinsident vertex is found.
1216 FirstVertex.Orientation(TopAbs_FORWARD);
1217 LastVertex.Orientation(TopAbs_REVERSED);
1222 if (iVtx > aNbVtx) {
1223 // It is necessary to create new vertices.
1224 isValidEndVtx = Standard_False;
1229 if (isValidEndVtx) {
1230 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1231 FirstVertex, LastVertex,
1232 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1233 concatcurve->Value(concatcurve->Lower())->LastParameter());
1235 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1236 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1237 concatcurve->Value(concatcurve->Lower())->LastParameter());
1242 if (CurveSeq(1)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1243 CurveSeq(1) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(1))))->BasisCurve();
1245 Handle(Geom_Curve) aNewCurve =
1246 Handle(Geom_Curve)::DownCast(CurveSeq(1)->Copy());
1248 aNewCurve->Transform(LocSeq(1).Location().Transformation());
1250 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1251 const TopoDS_Vertex aVtxTmp = FirstVertex;
1253 FirstVertex = LastVertex;
1254 LastVertex = aVtxTmp;
1255 FirstVertex.Orientation(TopAbs_FORWARD);
1256 LastVertex.Orientation(TopAbs_REVERSED);
1259 ResEdge = BRepLib_MakeEdge(aNewCurve,
1260 FirstVertex, LastVertex,
1261 FparSeq(1), LparSeq(1));
1263 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1272 //=============================================================================
1274 * \brief Returns an isoline for a face.
1276 //=============================================================================
1278 TopoDS_Shape GEOMImpl_ShapeDriver::MakeIsoline
1279 (const TopoDS_Face &theFace,
1281 const double theParameter) const
1283 TopoDS_Shape aResult;
1284 GEOMUtils::Hatcher aHatcher(theFace);
1285 const GeomAbs_IsoType aType = (IsUIso ? GeomAbs_IsoU : GeomAbs_IsoV);
1287 aHatcher.Init(aType, theParameter);
1290 if (!aHatcher.IsDone()) {
1291 Standard_ConstructionError::Raise("MakeIsoline : Hatcher failure");
1294 const Handle(TColStd_HArray1OfInteger) &anIndices =
1295 (IsUIso ? aHatcher.GetUIndices() : aHatcher.GetVIndices());
1297 if (anIndices.IsNull()) {
1298 Standard_ConstructionError::Raise("MakeIsoline : Null hatching indices");
1301 const Standard_Integer anIsoInd = anIndices->Lower();
1302 const Standard_Integer aHatchingIndex = anIndices->Value(anIsoInd);
1304 if (aHatchingIndex == 0) {
1305 Standard_ConstructionError::Raise("MakeIsoline : Invalid hatching index");
1308 const Standard_Integer aNbDomains =
1309 aHatcher.GetNbDomains(aHatchingIndex);
1311 if (aNbDomains < 0) {
1312 Standard_ConstructionError::Raise("MakeIsoline : Invalid number of domains");
1315 // The hatching is performed successfully. Create the 3d Curve.
1316 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1317 Handle(Geom_Curve) anIsoCurve = (IsUIso ?
1318 aSurface->UIso(theParameter) : aSurface->VIso(theParameter));
1319 Handle(Geom2d_Curve) aPIsoCurve =
1320 aHatcher.GetHatching(aHatchingIndex);
1321 const Standard_Real aTol = Precision::Confusion();
1322 Standard_Integer anIDom = 1;
1325 BRep_Builder aBuilder;
1326 Standard_Integer aNbEdges = 0;
1328 for (; anIDom <= aNbDomains; anIDom++) {
1329 if (aHatcher.GetDomain(aHatchingIndex, anIDom, aV1, aV2)) {
1330 // Check first and last parameters.
1331 if (!aHatcher.IsDomainInfinite(aHatchingIndex, anIDom)) {
1333 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(anIsoCurve, aV1, aV2);
1335 // Update it with a parametric curve on face.
1336 aBuilder.UpdateEdge(anEdge, aPIsoCurve, theFace, aTol);
1340 // Result is a compond.
1341 if (aNbEdges == 2) {
1342 // Create a new compound.
1343 TopoDS_Compound aCompound;
1345 aBuilder.MakeCompound(aCompound);
1346 aBuilder.Add(aCompound, aResult);
1347 aResult = aCompound;
1350 // Add an edge to the compound.
1351 aBuilder.Add(aResult, anEdge);
1353 // Result is the edge.
1360 if (aNbEdges == 0) {
1361 Standard_ConstructionError::Raise("MakeIsoline : Empty result");
1367 //=============================================================================
1369 * \brief Returns an extended edge.
1371 //=============================================================================
1373 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendEdge
1374 (const TopoDS_Edge &theEdge,
1375 const Standard_Real theMin,
1376 const Standard_Real theMax) const
1378 TopoDS_Shape aResult;
1381 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(theEdge, aF, aL);
1382 const Standard_Real aTol = BRep_Tool::Tolerance(theEdge);
1383 Standard_Real aRange2d = aL - aF;
1385 if (aCurve.IsNull() == Standard_False && aRange2d > aTol) {
1386 Standard_Real aMin = aF + aRange2d*theMin;
1387 Standard_Real aMax = aF + aRange2d*theMax;
1389 Handle(Standard_Type) aType = aCurve->DynamicType();
1391 // Get the curve of original type
1392 while (aType == STANDARD_TYPE(Geom_TrimmedCurve)) {
1393 Handle(Geom_TrimmedCurve) aTrCurve =
1394 Handle(Geom_TrimmedCurve)::DownCast(aCurve);
1396 aCurve = aTrCurve->BasisCurve();
1397 aType = aCurve->DynamicType();
1400 if (aCurve->IsPeriodic()) {
1401 // The curve is periodic. Check if a new range is less then a period.
1402 if (aMax - aMin > aCurve->Period()) {
1403 aMax = aMin + aCurve->Period();
1406 // The curve is not periodic. Check if aMin and aMax within bounds.
1407 aMin = Max(aMin, aCurve->FirstParameter());
1408 aMax = Min(aMax, aCurve->LastParameter());
1411 if (aMax - aMin > aTol) {
1412 // Create a new edge.
1413 BRepBuilderAPI_MakeEdge aME (aCurve, aMin, aMax);
1416 aResult = aME.Shape();
1424 //=============================================================================
1426 * \brief Returns an extended face.
1428 //=============================================================================
1430 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendFace
1431 (const TopoDS_Face &theFace,
1432 const Standard_Real theUMin,
1433 const Standard_Real theUMax,
1434 const Standard_Real theVMin,
1435 const Standard_Real theVMax) const
1437 TopoDS_Shape aResult;
1438 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1439 const Standard_Real aTol = BRep_Tool::Tolerance(theFace);
1445 // Get U, V bounds of the face.
1446 ShapeAnalysis::GetFaceUVBounds(theFace, aU1, aU2, aV1, aV2);
1448 const Standard_Real aURange = aU2 - aU1;
1449 const Standard_Real aVRange = aV2 - aV1;
1451 if (aSurface.IsNull() == Standard_False &&
1452 aURange > aTol && aURange > aTol) {
1453 Handle(Standard_Type) aType = aSurface->DynamicType();
1455 // Get the surface of original type
1456 while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1457 Handle(Geom_RectangularTrimmedSurface) aTrSurface =
1458 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
1460 aSurface = aTrSurface->BasisSurface();
1461 aType = aSurface->DynamicType();
1464 Standard_Real aUMin = aU1 + aURange*theUMin;
1465 Standard_Real aUMax = aU1 + aURange*theUMax;
1466 Standard_Real aVMin = aV1 + aVRange*theVMin;
1467 Standard_Real aVMax = aV1 + aVRange*theVMax;
1469 aSurface->Bounds(aU1, aU2, aV1, aV2);
1471 if (aSurface->IsUPeriodic()) {
1472 // The surface is U-periodic. Check if a new U range is less
1474 if (aUMax - aUMin > aSurface->UPeriod()) {
1475 aUMax = aUMin + aSurface->UPeriod();
1478 // The surface is not V-periodic. Check if aUMin and aUMax
1480 aUMin = Max(aUMin, aU1);
1481 aUMax = Min(aUMax, aU2);
1484 if (aSurface->IsVPeriodic()) {
1485 // The surface is V-periodic. Check if a new V range is less
1487 if (aVMax - aVMin > aSurface->VPeriod()) {
1488 aVMax = aVMin + aSurface->VPeriod();
1491 // The surface is not V-periodic. Check if aVMin and aVMax
1493 aVMin = Max(aVMin, aV1);
1494 aVMax = Min(aVMax, aV2);
1497 if (aUMax - aUMin > aTol && aVMax - aVMin > aTol) {
1498 // Create a new edge.
1499 BRepBuilderAPI_MakeFace aMF
1500 (aSurface, aUMin, aUMax, aVMin, aVMax, aTol);
1503 aResult = aMF.Shape();
1511 //================================================================================
1513 * \brief Returns a name of creation operation and names and values of creation parameters
1515 //================================================================================
1517 bool GEOMImpl_ShapeDriver::
1518 GetCreationInformation(std::string& theOperationName,
1519 std::vector<GEOM_Param>& theParams)
1521 if (Label().IsNull()) return 0;
1522 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
1524 GEOMImpl_IShapes aCI( function );
1525 Standard_Integer aType = function->GetType();
1529 theOperationName = "WIRE";
1530 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1531 AddParam( theParams, "Tolerance", aCI.GetTolerance() );
1534 theOperationName = "FACE";
1535 AddParam( theParams, "Wire/edge", aCI.GetBase() );
1536 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1539 theOperationName = "FACE";
1540 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1541 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1543 case FACE_FROM_SURFACE:
1545 theOperationName = "FACE";
1547 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1549 if (shapes.IsNull() == Standard_False) {
1550 Standard_Integer aNbShapes = shapes->Length();
1552 if (aNbShapes > 0) {
1553 AddParam(theParams, "Face", shapes->Value(1));
1555 if (aNbShapes > 1) {
1556 AddParam(theParams, "Wire", shapes->Value(2));
1563 theOperationName = "SHELL";
1564 AddParam( theParams, "Objects", aCI.GetShapes() );
1567 theOperationName = "SOLID";
1568 AddParam( theParams, "Objects", aCI.GetShapes() );
1571 theOperationName = "SOLID_FROM_FACES";
1572 AddParam( theParams, "Objects", aCI.GetShapes() );
1573 AddParam( theParams, "Is intersect", aCI.GetIsIntersect() );
1575 case COMPOUND_SHAPES:
1576 theOperationName = "COMPOUND";
1577 AddParam( theParams, "Objects", aCI.GetShapes() );
1580 theOperationName = "EDGE";
1581 AddParam( theParams, "Wire", aCI.GetBase() );
1582 AddParam( theParams, "Linear Tolerance", aCI.GetTolerance() );
1583 AddParam( theParams, "Angular Tolerance", aCI.GetAngularTolerance() );
1585 case EDGE_CURVE_LENGTH:
1586 theOperationName = "EDGE";
1588 GEOMImpl_IVector aCI( function );
1589 AddParam( theParams, "Edge", aCI.GetPoint1() );
1590 AddParam( theParams, "Start point", aCI.GetPoint2() );
1591 AddParam( theParams, "Length", aCI.GetParameter() );
1594 case SHAPES_ON_SHAPE:
1596 theOperationName = "GetShapesOnShapeAsCompound";
1597 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1598 if ( !shapes.IsNull() && shapes->Length() > 0 )
1599 AddParam( theParams, "Check shape", shapes->Value(1) );
1600 if ( !shapes.IsNull() && shapes->Length() > 1 )
1601 AddParam( theParams, "Shape", shapes->Value(2) );
1602 AddParam( theParams, "Shape type", TopAbs_ShapeEnum( aCI.GetSubShapeType() ));
1603 AddParam( theParams, "State" );
1604 GEOMAlgo_State st = GEOMAlgo_State( (int) ( aCI.GetTolerance()+0.1 ) );
1605 const char* stName[] = { "UNKNOWN","IN","OUT","ON","ONIN","ONOUT","INOUT" };
1606 if ( 0 <= st && st <= GEOMAlgo_ST_INOUT )
1607 theParams.back() << stName[ st ];
1609 theParams.back() << (int) st;
1614 GEOMImpl_IIsoline aII (function);
1616 theOperationName = "ISOLINE";
1617 AddParam(theParams, "Face", aII.GetFace());
1618 AddParam(theParams, "Isoline type", (aII.GetIsUIso() ? "U" : "V"));
1619 AddParam(theParams, "Parameter", aII.GetParameter());
1624 GEOMImpl_IShapeExtend aSE (function);
1626 theOperationName = "EDGE_EXTEND";
1627 AddParam(theParams, "Edge", aSE.GetShape());
1628 AddParam(theParams, "Min", aSE.GetUMin());
1629 AddParam(theParams, "Max", aSE.GetUMax());
1634 GEOMImpl_IShapeExtend aSE (function);
1636 theOperationName = "FACE_EXTEND";
1637 AddParam(theParams, "Face", aSE.GetShape());
1638 AddParam(theParams, "UMin", aSE.GetUMin());
1639 AddParam(theParams, "UMax", aSE.GetUMax());
1640 AddParam(theParams, "VMin", aSE.GetVMin());
1641 AddParam(theParams, "VMax", aSE.GetVMax());
1644 case SURFACE_FROM_FACE:
1646 GEOMImpl_IShapeExtend aSE (function);
1648 theOperationName = "SURFACE_FROM_FACE";
1649 AddParam(theParams, "Face", aSE.GetShape());
1659 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1660 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1662 //modified by NIZNHY-PKV Wed Dec 28 13:48:31 2011f
1663 #include <TopoDS_Iterator.hxx>
1664 #include <TopTools_HSequenceOfShape.hxx>
1665 #include <ShapeAnalysis_FreeBounds.hxx>
1666 #include <TopTools_MapOfShape.hxx>
1667 #include <TopTools_MapOfOrientedShape.hxx>
1668 #include <BRep_Builder.hxx>
1669 #include <TopoDS_Wire.hxx>
1671 //=======================================================================
1672 //function : KeepEdgesOrder
1674 //=======================================================================
1676 void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
1677 const Handle(TopTools_HSequenceOfShape)& aWires)
1679 Standard_Integer aNbWires, aNbEdges;
1681 if (aEdges.IsNull()) {
1685 if (aWires.IsNull()) {
1689 aNbEdges=aEdges->Length();
1690 aNbWires=aWires->Length();
1691 if (!aNbEdges || !aNbWires) {
1695 Standard_Boolean bClosed;
1696 Standard_Integer i, j;
1698 TopoDS_Iterator aIt;
1700 TopTools_MapOfOrientedShape aMEx;
1702 for (i=1; i<=aNbWires; ++i) {
1703 const TopoDS_Shape& aWx=aWires->Value(i);
1706 aIt.Initialize (aWx);
1707 for (; aIt.More(); aIt.Next()) {
1708 const TopoDS_Shape& aEx=aIt.Value();
1713 for (j=1; j<=aNbEdges; ++j) {
1714 const TopoDS_Shape& aE=aEdges->Value(j);
1715 if (aMEx.Contains(aE)) {
1720 bClosed=aWx.Closed();
1721 aWy.Closed(bClosed);
1723 aWires->Append(aWy);
1724 }// for (i=1; i<=aNbWires; ++i) {
1726 aWires->Remove(1, aNbWires);
1729 //modified by NIZNHY-PKV Wed Dec 28 13:48:34 2011t