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 GeomAdaptor_Curve GAprevcurve(CurveSeq.Last());
865 TopoDS_Vertex CurVertex = wexp.CurrentVertex();
866 TopoDS_Vertex CurFirstVer = TopExp::FirstVertex(anEdge);
867 TopAbs_Orientation ConnectByOrigin = (CurVertex.IsSame(CurFirstVer))? TopAbs_FORWARD : TopAbs_REVERSED;
868 if (aCurve == CurveSeq.Last())
872 if (aBasisCurve->IsPeriodic())
874 if (NewLpar < NewFpar)
875 NewLpar += aBasisCurve->Period();
876 if (ConnectByOrigin == TopAbs_FORWARD)
877 ElCLib::AdjustPeriodic(FparSeq.Last(),
878 FparSeq.Last() + aBasisCurve->Period(),
879 Precision::PConfusion(), NewFpar, NewLpar);
881 ElCLib::AdjustPeriodic(FparSeq.Last() - aBasisCurve->Period(),
883 Precision::PConfusion(), NewFpar, NewLpar);
885 Done = Standard_True;
887 else if (aType == CurType &&
888 aType != GeomAbs_BezierCurve &&
889 aType != GeomAbs_BSplineCurve &&
890 aType != GeomAbs_OtherCurve)
896 gp_Lin aLine = BAcurve.Line();
897 gp_Lin PrevLine = GAprevcurve.Line();
898 if (aLine.Contains(PrevLine.Location(), LinTol) &&
899 aLine.Direction().IsParallel(PrevLine.Direction(), AngTol))
901 gp_Pnt P1 = ElCLib::Value(fpar, aLine);
902 gp_Pnt P2 = ElCLib::Value(lpar, aLine);
903 NewFpar = ElCLib::Parameter(PrevLine, P1);
904 NewLpar = ElCLib::Parameter(PrevLine, P2);
907 if (ConnectByOrigin == TopAbs_FORWARD) {
908 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevLine);
910 aPntShiftDist += P2.Distance(aNewP2);
912 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevLine);
914 aPntShiftDist += P1.Distance(aNewP1);
917 if (NewLpar < NewFpar)
919 Standard_Real MemNewFpar = NewFpar;
921 NewLpar = MemNewFpar;
922 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
924 Done = Standard_True;
930 gp_Circ aCircle = BAcurve.Circle();
931 gp_Circ PrevCircle = GAprevcurve.Circle();
932 if (aCircle.Location().Distance(PrevCircle.Location()) <= LinTol &&
933 Abs(aCircle.Radius() - PrevCircle.Radius()) <= LinTol &&
934 aCircle.Axis().IsParallel(PrevCircle.Axis(), AngTol))
936 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
938 if (aCircle.Axis().Direction() * PrevCircle.Axis().Direction() < 0.)
940 Standard_Real memfpar = fpar;
943 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
945 gp_Pnt P1 = ElCLib::Value(fpar, aCircle);
946 gp_Pnt P2 = ElCLib::Value(lpar, aCircle);
947 NewFpar = ElCLib::Parameter(PrevCircle, P1);
948 NewLpar = ElCLib::Parameter(PrevCircle, P2);
952 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevCircle);
954 aPntShiftDist += P2.Distance(aNewP2);
956 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevCircle);
958 aPntShiftDist += P1.Distance(aNewP1);
961 if (NewLpar < NewFpar)
963 //Standard_Real MemNewFpar = NewFpar, MemNewLpar = NewLpar;
964 if (ConnectByOrigin == TopAbs_FORWARD)
965 ElCLib::AdjustPeriodic(FparSeq.Last(),
966 FparSeq.Last() + 2.*M_PI,
967 Precision::PConfusion(), NewFpar, NewLpar);
969 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
971 Precision::PConfusion(), NewFpar, NewLpar);
972 Done = Standard_True;
976 case GeomAbs_Ellipse:
978 gp_Elips anEllipse = BAcurve.Ellipse();
979 gp_Elips PrevEllipse = GAprevcurve.Ellipse();
980 if (anEllipse.Focus1().Distance(PrevEllipse.Focus1()) <= LinTol &&
981 anEllipse.Focus2().Distance(PrevEllipse.Focus2()) <= LinTol &&
982 Abs(anEllipse.MajorRadius() - PrevEllipse.MajorRadius()) <= LinTol &&
983 Abs(anEllipse.MinorRadius() - PrevEllipse.MinorRadius()) <= LinTol &&
984 anEllipse.Axis().IsParallel(PrevEllipse.Axis(), AngTol))
986 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
988 if (anEllipse.Axis().Direction() * PrevEllipse.Axis().Direction() < 0.)
990 Standard_Real memfpar = fpar;
993 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
995 gp_Pnt P1 = ElCLib::Value(fpar, anEllipse);
996 gp_Pnt P2 = ElCLib::Value(lpar, anEllipse);
997 NewFpar = ElCLib::Parameter(PrevEllipse, P1);
998 NewLpar = ElCLib::Parameter(PrevEllipse, P2);
1002 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevEllipse);
1004 aPntShiftDist += P2.Distance(aNewP2);
1006 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevEllipse);
1008 aPntShiftDist += P1.Distance(aNewP1);
1011 if (NewLpar < NewFpar)
1013 if (ConnectByOrigin == TopAbs_FORWARD)
1014 ElCLib::AdjustPeriodic(FparSeq.Last(),
1015 FparSeq.Last() + 2.*M_PI,
1016 Precision::PConfusion(), NewFpar, NewLpar);
1018 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
1020 Precision::PConfusion(), NewFpar, NewLpar);
1021 Done = Standard_True;
1025 case GeomAbs_Hyperbola:
1027 gp_Hypr aHypr = BAcurve.Hyperbola();
1028 gp_Hypr PrevHypr = GAprevcurve.Hyperbola();
1029 if (aHypr.Focus1().Distance(PrevHypr.Focus1()) <= LinTol &&
1030 aHypr.Focus2().Distance(PrevHypr.Focus2()) <= LinTol &&
1031 Abs(aHypr.MajorRadius() - PrevHypr.MajorRadius()) <= LinTol &&
1032 Abs(aHypr.MinorRadius() - PrevHypr.MinorRadius()) <= LinTol &&
1033 aHypr.Axis().IsParallel(PrevHypr.Axis(), AngTol))
1035 gp_Pnt P1 = ElCLib::Value(fpar, aHypr);
1036 gp_Pnt P2 = ElCLib::Value(lpar, aHypr);
1037 NewFpar = ElCLib::Parameter(PrevHypr, P1);
1038 NewLpar = ElCLib::Parameter(PrevHypr, P2);
1041 if (ConnectByOrigin == TopAbs_FORWARD) {
1042 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevHypr);
1044 aPntShiftDist += P2.Distance(aNewP2);
1046 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevHypr);
1048 aPntShiftDist += P1.Distance(aNewP1);
1051 if (NewLpar < NewFpar)
1053 Standard_Real MemNewFpar = NewFpar;
1055 NewLpar = MemNewFpar;
1056 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1058 Done = Standard_True;
1062 case GeomAbs_Parabola:
1064 gp_Parab aParab = BAcurve.Parabola();
1065 gp_Parab PrevParab = GAprevcurve.Parabola();
1066 if (aParab.Location().Distance(PrevParab.Location()) <= LinTol &&
1067 aParab.Focus().Distance(PrevParab.Focus()) <= LinTol &&
1068 Abs(aParab.Focal() - PrevParab.Focal()) <= LinTol &&
1069 aParab.Axis().IsParallel(PrevParab.Axis(), AngTol))
1071 gp_Pnt P1 = ElCLib::Value(fpar, aParab);
1072 gp_Pnt P2 = ElCLib::Value(lpar, aParab);
1073 NewFpar = ElCLib::Parameter(PrevParab, P1);
1074 NewLpar = ElCLib::Parameter(PrevParab, P2);
1077 if (ConnectByOrigin == TopAbs_FORWARD) {
1078 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevParab);
1080 aPntShiftDist += P2.Distance(aNewP2);
1082 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevParab);
1084 aPntShiftDist += P1.Distance(aNewP1);
1087 if (NewLpar < NewFpar)
1089 Standard_Real MemNewFpar = NewFpar;
1091 NewLpar = MemNewFpar;
1092 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1094 Done = Standard_True;
1098 } //end of switch (aType)
1099 } // end of else if (aType == CurType && ...
1102 if (NewFpar < FparSeq.Last())
1103 FparSeq(FparSeq.Length()) = NewFpar;
1105 LparSeq(LparSeq.Length()) = NewLpar;
1109 CurveSeq.Append(aCurve);
1110 TopoDS_Shape aLocShape;
1111 aLocShape.Location(aLoc);
1112 aLocShape.Orientation(wexp.Orientation());
1113 LocSeq.Append(aLocShape);
1114 FparSeq.Append(fpar);
1115 LparSeq.Append(lpar);
1116 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(CurVertex));
1120 } // end of else (CurveSeq.IsEmpty()) -> not first time
1121 } // end for (; wexp.More(); wexp.Next())
1123 LastVertex = wexp.CurrentVertex();
1124 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(LastVertex));
1126 FirstVertex.Orientation(TopAbs_FORWARD);
1127 LastVertex.Orientation(TopAbs_REVERSED);
1129 if (!CurveSeq.IsEmpty())
1131 Standard_Integer nb_curve = CurveSeq.Length(); //number of curves
1132 TColGeom_Array1OfBSplineCurve tab(0,nb_curve-1); //array of the curves
1133 TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2); //array of the tolerances
1139 for (i = 1; i <= nb_curve; i++)
1141 if (CurveSeq(i)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1142 CurveSeq(i) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(i))))->BasisCurve();
1144 Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(CurveSeq(i), FparSeq(i), LparSeq(i));
1145 tab(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve);
1146 tab(i-1)->Transform(LocSeq(i).Location().Transformation());
1147 GeomConvert::C0BSplineToC1BSplineCurve(tab(i-1), Precision::Confusion());
1148 if (LocSeq(i).Orientation() == TopAbs_REVERSED)
1149 tab(i-1)->Reverse();
1152 //char* name = new char[100];
1153 //sprintf(name, "c%d", i);
1154 //DrawTrSurf::Set(name, tab(i-1));
1157 tabtolvertex(i-2) = TolSeq(i-1);
1158 } // end for (i = 1; i <= nb_curve; i++)
1159 tabtolvertex(nb_curve-1) = TolSeq(TolSeq.Length());
1161 Standard_Boolean closed_flag = Standard_False;
1162 Standard_Real closed_tolerance = 0.;
1163 if (FirstVertex.IsSame(LastVertex) &&
1164 GeomLProp::Continuity(tab(0), tab(nb_curve-1),
1165 tab(0)->FirstParameter(),
1166 tab(nb_curve-1)->LastParameter(),
1167 Standard_False, Standard_False, LinTol, AngTol) >= GeomAbs_G1)
1169 closed_flag = Standard_True ;
1170 closed_tolerance = BRep_Tool::Tolerance(FirstVertex);
1173 Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves
1174 Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex
1175 GeomConvert::ConcatC1(tab,
1180 closed_tolerance); //C1 concatenation
1182 if (concatcurve->Length() > 1)
1184 GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower()));
1186 for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++)
1187 Concat.Add( concatcurve->Value(i), LinTol, Standard_True );
1189 concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve());
1191 // rnc : prevents the driver from building an edge without C1 continuity
1192 if (concatcurve->Value(concatcurve->Lower())->Continuity()==GeomAbs_C0){
1193 Standard_ConstructionError::Raise("Construction aborted : The given Wire has sharp bends between some Edges, no valid Edge can be built");
1196 Standard_Boolean isValidEndVtx = Standard_True;
1199 // Check if closed curve is reordered.
1200 Handle(Geom_Curve) aCurve = concatcurve->Value(concatcurve->Lower());
1201 Standard_Real aFPar = aCurve->FirstParameter();
1203 gp_Pnt aPntVtx = BRep_Tool::Pnt(FirstVertex);
1204 Standard_Real aTolVtx = BRep_Tool::Tolerance(FirstVertex);
1206 aCurve->D0(aFPar, aPFirst);
1208 if (!aPFirst.IsEqual(aPntVtx, aTolVtx)) {
1209 // The curve is reordered. Find the new first and last vertices.
1210 TopTools_IndexedMapOfShape aMapVtx;
1211 TopExp::MapShapes(theWire, TopAbs_VERTEX, aMapVtx);
1213 const Standard_Integer aNbVtx = aMapVtx.Extent();
1214 Standard_Integer iVtx;
1216 for (iVtx = 1; iVtx <= aNbVtx; iVtx++) {
1217 const TopoDS_Vertex aVtx = TopoDS::Vertex(aMapVtx.FindKey(iVtx));
1218 const gp_Pnt aPnt = BRep_Tool::Pnt(aVtx);
1219 const Standard_Real aTol = BRep_Tool::Tolerance(aVtx);
1221 if (aPFirst.IsEqual(aPnt, aTol)) {
1222 // The coinsident vertex is found.
1225 FirstVertex.Orientation(TopAbs_FORWARD);
1226 LastVertex.Orientation(TopAbs_REVERSED);
1231 if (iVtx > aNbVtx) {
1232 // It is necessary to create new vertices.
1233 isValidEndVtx = Standard_False;
1238 if (isValidEndVtx) {
1239 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1240 FirstVertex, LastVertex,
1241 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1242 concatcurve->Value(concatcurve->Lower())->LastParameter());
1244 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1245 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1246 concatcurve->Value(concatcurve->Lower())->LastParameter());
1251 if (CurveSeq(1)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1252 CurveSeq(1) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(1))))->BasisCurve();
1254 Handle(Geom_Curve) aNewCurve =
1255 Handle(Geom_Curve)::DownCast(CurveSeq(1)->Copy());
1257 aNewCurve->Transform(LocSeq(1).Location().Transformation());
1259 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1260 const TopoDS_Vertex aVtxTmp = FirstVertex;
1262 FirstVertex = LastVertex;
1263 LastVertex = aVtxTmp;
1264 FirstVertex.Orientation(TopAbs_FORWARD);
1265 LastVertex.Orientation(TopAbs_REVERSED);
1268 ResEdge = BRepLib_MakeEdge(aNewCurve,
1269 FirstVertex, LastVertex,
1270 FparSeq(1), LparSeq(1));
1272 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1281 //=============================================================================
1283 * \brief Returns an isoline for a face.
1285 //=============================================================================
1287 TopoDS_Shape GEOMImpl_ShapeDriver::MakeIsoline
1288 (const TopoDS_Face &theFace,
1290 const double theParameter) const
1292 TopoDS_Shape aResult;
1293 GEOMUtils::Hatcher aHatcher(theFace);
1294 const GeomAbs_IsoType aType = (IsUIso ? GeomAbs_IsoU : GeomAbs_IsoV);
1296 aHatcher.Init(aType, theParameter);
1299 if (!aHatcher.IsDone()) {
1300 Standard_ConstructionError::Raise("MakeIsoline : Hatcher failure");
1303 const Handle(TColStd_HArray1OfInteger) &anIndices =
1304 (IsUIso ? aHatcher.GetUIndices() : aHatcher.GetVIndices());
1306 if (anIndices.IsNull()) {
1307 Standard_ConstructionError::Raise("MakeIsoline : Null hatching indices");
1310 const Standard_Integer anIsoInd = anIndices->Lower();
1311 const Standard_Integer aHatchingIndex = anIndices->Value(anIsoInd);
1313 if (aHatchingIndex == 0) {
1314 Standard_ConstructionError::Raise("MakeIsoline : Invalid hatching index");
1317 const Standard_Integer aNbDomains =
1318 aHatcher.GetNbDomains(aHatchingIndex);
1320 if (aNbDomains < 0) {
1321 Standard_ConstructionError::Raise("MakeIsoline : Invalid number of domains");
1324 // The hatching is performed successfully. Create the 3d Curve.
1325 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1326 Handle(Geom_Curve) anIsoCurve = (IsUIso ?
1327 aSurface->UIso(theParameter) : aSurface->VIso(theParameter));
1328 Handle(Geom2d_Curve) aPIsoCurve =
1329 aHatcher.GetHatching(aHatchingIndex);
1330 const Standard_Real aTol = Precision::Confusion();
1331 Standard_Integer anIDom = 1;
1334 BRep_Builder aBuilder;
1335 Standard_Integer aNbEdges = 0;
1337 for (; anIDom <= aNbDomains; anIDom++) {
1338 if (aHatcher.GetDomain(aHatchingIndex, anIDom, aV1, aV2)) {
1339 // Check first and last parameters.
1340 if (!aHatcher.IsDomainInfinite(aHatchingIndex, anIDom)) {
1342 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(anIsoCurve, aV1, aV2);
1344 // Update it with a parametric curve on face.
1345 aBuilder.UpdateEdge(anEdge, aPIsoCurve, theFace, aTol);
1349 // Result is a compond.
1350 if (aNbEdges == 2) {
1351 // Create a new compound.
1352 TopoDS_Compound aCompound;
1354 aBuilder.MakeCompound(aCompound);
1355 aBuilder.Add(aCompound, aResult);
1356 aResult = aCompound;
1359 // Add an edge to the compound.
1360 aBuilder.Add(aResult, anEdge);
1362 // Result is the edge.
1369 if (aNbEdges == 0) {
1370 Standard_ConstructionError::Raise("MakeIsoline : Empty result");
1376 //=============================================================================
1378 * \brief Returns an extended edge.
1380 //=============================================================================
1382 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendEdge
1383 (const TopoDS_Edge &theEdge,
1384 const Standard_Real theMin,
1385 const Standard_Real theMax) const
1387 TopoDS_Shape aResult;
1390 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(theEdge, aF, aL);
1391 const Standard_Real aTol = BRep_Tool::Tolerance(theEdge);
1392 Standard_Real aRange2d = aL - aF;
1394 if (aCurve.IsNull() == Standard_False && aRange2d > aTol) {
1395 Standard_Real aMin = aF + aRange2d*theMin;
1396 Standard_Real aMax = aF + aRange2d*theMax;
1398 Handle(Standard_Type) aType = aCurve->DynamicType();
1400 // Get the curve of original type
1401 while (aType == STANDARD_TYPE(Geom_TrimmedCurve)) {
1402 Handle(Geom_TrimmedCurve) aTrCurve =
1403 Handle(Geom_TrimmedCurve)::DownCast(aCurve);
1405 aCurve = aTrCurve->BasisCurve();
1406 aType = aCurve->DynamicType();
1409 if (aCurve->IsPeriodic()) {
1410 // The curve is periodic. Check if a new range is less then a period.
1411 if (aMax - aMin > aCurve->Period()) {
1412 aMax = aMin + aCurve->Period();
1415 // The curve is not periodic. Check if aMin and aMax within bounds.
1416 aMin = Max(aMin, aCurve->FirstParameter());
1417 aMax = Min(aMax, aCurve->LastParameter());
1420 if (aMax - aMin > aTol) {
1421 // Create a new edge.
1422 BRepBuilderAPI_MakeEdge aME (aCurve, aMin, aMax);
1425 aResult = aME.Shape();
1433 //=============================================================================
1435 * \brief Returns an extended face.
1437 //=============================================================================
1439 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendFace
1440 (const TopoDS_Face &theFace,
1441 const Standard_Real theUMin,
1442 const Standard_Real theUMax,
1443 const Standard_Real theVMin,
1444 const Standard_Real theVMax) const
1446 TopoDS_Shape aResult;
1447 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1448 const Standard_Real aTol = BRep_Tool::Tolerance(theFace);
1454 // Get U, V bounds of the face.
1455 ShapeAnalysis::GetFaceUVBounds(theFace, aU1, aU2, aV1, aV2);
1457 const Standard_Real aURange = aU2 - aU1;
1458 const Standard_Real aVRange = aV2 - aV1;
1460 if (aSurface.IsNull() == Standard_False &&
1461 aURange > aTol && aURange > aTol) {
1462 Handle(Standard_Type) aType = aSurface->DynamicType();
1464 // Get the surface of original type
1465 while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1466 Handle(Geom_RectangularTrimmedSurface) aTrSurface =
1467 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
1469 aSurface = aTrSurface->BasisSurface();
1470 aType = aSurface->DynamicType();
1473 Standard_Real aUMin = aU1 + aURange*theUMin;
1474 Standard_Real aUMax = aU1 + aURange*theUMax;
1475 Standard_Real aVMin = aV1 + aVRange*theVMin;
1476 Standard_Real aVMax = aV1 + aVRange*theVMax;
1478 aSurface->Bounds(aU1, aU2, aV1, aV2);
1480 if (aSurface->IsUPeriodic()) {
1481 // The surface is U-periodic. Check if a new U range is less
1483 if (aUMax - aUMin > aSurface->UPeriod()) {
1484 aUMax = aUMin + aSurface->UPeriod();
1487 // The surface is not V-periodic. Check if aUMin and aUMax
1489 aUMin = Max(aUMin, aU1);
1490 aUMax = Min(aUMax, aU2);
1493 if (aSurface->IsVPeriodic()) {
1494 // The surface is V-periodic. Check if a new V range is less
1496 if (aVMax - aVMin > aSurface->VPeriod()) {
1497 aVMax = aVMin + aSurface->VPeriod();
1500 // The surface is not V-periodic. Check if aVMin and aVMax
1502 aVMin = Max(aVMin, aV1);
1503 aVMax = Min(aVMax, aV2);
1506 if (aUMax - aUMin > aTol && aVMax - aVMin > aTol) {
1507 // Create a new edge.
1508 BRepBuilderAPI_MakeFace aMF
1509 (aSurface, aUMin, aUMax, aVMin, aVMax, aTol);
1512 aResult = aMF.Shape();
1520 //================================================================================
1522 * \brief Returns a name of creation operation and names and values of creation parameters
1524 //================================================================================
1526 bool GEOMImpl_ShapeDriver::
1527 GetCreationInformation(std::string& theOperationName,
1528 std::vector<GEOM_Param>& theParams)
1530 if (Label().IsNull()) return 0;
1531 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
1533 GEOMImpl_IShapes aCI( function );
1534 Standard_Integer aType = function->GetType();
1538 theOperationName = "WIRE";
1539 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1540 AddParam( theParams, "Tolerance", aCI.GetTolerance() );
1543 theOperationName = "FACE";
1544 AddParam( theParams, "Wire/edge", aCI.GetBase() );
1545 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1548 theOperationName = "FACE";
1549 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1550 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1552 case FACE_FROM_SURFACE:
1554 theOperationName = "FACE";
1556 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1558 if (shapes.IsNull() == Standard_False) {
1559 Standard_Integer aNbShapes = shapes->Length();
1561 if (aNbShapes > 0) {
1562 AddParam(theParams, "Face", shapes->Value(1));
1564 if (aNbShapes > 1) {
1565 AddParam(theParams, "Wire", shapes->Value(2));
1572 theOperationName = "SHELL";
1573 AddParam( theParams, "Objects", aCI.GetShapes() );
1576 theOperationName = "SOLID";
1577 AddParam( theParams, "Objects", aCI.GetShapes() );
1580 theOperationName = "SOLID_FROM_FACES";
1581 AddParam( theParams, "Objects", aCI.GetShapes() );
1582 AddParam( theParams, "Is intersect", aCI.GetIsIntersect() );
1584 case COMPOUND_SHAPES:
1585 theOperationName = "COMPOUND";
1586 AddParam( theParams, "Objects", aCI.GetShapes() );
1589 theOperationName = "EDGE";
1590 AddParam( theParams, "Wire", aCI.GetBase() );
1591 AddParam( theParams, "Linear Tolerance", aCI.GetTolerance() );
1592 AddParam( theParams, "Angular Tolerance", aCI.GetAngularTolerance() );
1594 case EDGE_CURVE_LENGTH:
1595 theOperationName = "EDGE";
1597 GEOMImpl_IVector aCI( function );
1598 AddParam( theParams, "Edge", aCI.GetPoint1() );
1599 AddParam( theParams, "Start point", aCI.GetPoint2() );
1600 AddParam( theParams, "Length", aCI.GetParameter() );
1603 case SHAPES_ON_SHAPE:
1605 theOperationName = "GetShapesOnShapeAsCompound";
1606 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1607 if ( !shapes.IsNull() && shapes->Length() > 0 )
1608 AddParam( theParams, "Check shape", shapes->Value(1) );
1609 if ( !shapes.IsNull() && shapes->Length() > 1 )
1610 AddParam( theParams, "Shape", shapes->Value(2) );
1611 AddParam( theParams, "Shape type", TopAbs_ShapeEnum( aCI.GetSubShapeType() ));
1612 AddParam( theParams, "State" );
1613 GEOMAlgo_State st = GEOMAlgo_State( (int) ( aCI.GetTolerance()+0.1 ) );
1614 const char* stName[] = { "UNKNOWN","IN","OUT","ON","ONIN","ONOUT","INOUT" };
1615 if ( 0 <= st && st <= GEOMAlgo_ST_INOUT )
1616 theParams.back() << stName[ st ];
1618 theParams.back() << (int) st;
1623 GEOMImpl_IIsoline aII (function);
1625 theOperationName = "ISOLINE";
1626 AddParam(theParams, "Face", aII.GetFace());
1627 AddParam(theParams, "Isoline type", (aII.GetIsUIso() ? "U" : "V"));
1628 AddParam(theParams, "Parameter", aII.GetParameter());
1633 GEOMImpl_IShapeExtend aSE (function);
1635 theOperationName = "EDGE_EXTEND";
1636 AddParam(theParams, "Edge", aSE.GetShape());
1637 AddParam(theParams, "Min", aSE.GetUMin());
1638 AddParam(theParams, "Max", aSE.GetUMax());
1643 GEOMImpl_IShapeExtend aSE (function);
1645 theOperationName = "FACE_EXTEND";
1646 AddParam(theParams, "Face", aSE.GetShape());
1647 AddParam(theParams, "UMin", aSE.GetUMin());
1648 AddParam(theParams, "UMax", aSE.GetUMax());
1649 AddParam(theParams, "VMin", aSE.GetVMin());
1650 AddParam(theParams, "VMax", aSE.GetVMax());
1653 case SURFACE_FROM_FACE:
1655 GEOMImpl_IShapeExtend aSE (function);
1657 theOperationName = "SURFACE_FROM_FACE";
1658 AddParam(theParams, "Face", aSE.GetShape());
1668 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1669 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1671 //modified by NIZNHY-PKV Wed Dec 28 13:48:31 2011f
1672 #include <TopoDS_Iterator.hxx>
1673 #include <TopTools_HSequenceOfShape.hxx>
1674 #include <ShapeAnalysis_FreeBounds.hxx>
1675 #include <TopTools_MapOfShape.hxx>
1676 #include <TopTools_MapOfOrientedShape.hxx>
1677 #include <BRep_Builder.hxx>
1678 #include <TopoDS_Wire.hxx>
1680 //=======================================================================
1681 //function : KeepEdgesOrder
1683 //=======================================================================
1685 void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
1686 const Handle(TopTools_HSequenceOfShape)& aWires)
1688 Standard_Integer aNbWires, aNbEdges;
1690 if (aEdges.IsNull()) {
1694 if (aWires.IsNull()) {
1698 aNbEdges=aEdges->Length();
1699 aNbWires=aWires->Length();
1700 if (!aNbEdges || !aNbWires) {
1704 Standard_Boolean bClosed;
1705 Standard_Integer i, j;
1707 TopoDS_Iterator aIt;
1709 TopTools_MapOfOrientedShape aMEx;
1711 for (i=1; i<=aNbWires; ++i) {
1712 const TopoDS_Shape& aWx=aWires->Value(i);
1715 aIt.Initialize (aWx);
1716 for (; aIt.More(); aIt.Next()) {
1717 const TopoDS_Shape& aEx=aIt.Value();
1722 for (j=1; j<=aNbEdges; ++j) {
1723 const TopoDS_Shape& aE=aEdges->Value(j);
1724 if (aMEx.Contains(aE)) {
1729 bClosed=aWx.Closed();
1730 aWy.Closed(bClosed);
1732 aWires->Append(aWy);
1733 }// for (i=1; i<=aNbWires; ++i) {
1735 aWires->Remove(1, aNbWires);
1738 //modified by NIZNHY-PKV Wed Dec 28 13:48:34 2011t