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>
36 #include <ShapeFix_Wire.hxx>
37 #include <ShapeFix_Edge.hxx>
38 #include <ShapeFix_Shape.hxx>
40 #include <BRep_Builder.hxx>
41 #include <BRep_Tool.hxx>
42 #include <BRepAdaptor_Curve.hxx>
43 #include <BRepAlgo_FaceRestrictor.hxx>
44 #include <BRepBuilderAPI_Copy.hxx>
45 #include <BRepBuilderAPI_Sewing.hxx>
46 #include <BRepBuilderAPI_MakeFace.hxx>
47 #include <BRepBuilderAPI_MakeWire.hxx>
48 #include <BRepBuilderAPI_MakeEdge.hxx>
49 #include <BRepBuilderAPI_MakeSolid.hxx>
50 #include <BRepCheck.hxx>
51 #include <BRepCheck_Analyzer.hxx>
52 #include <BRepCheck_Shell.hxx>
53 #include <BRepClass3d_SolidClassifier.hxx>
54 #include <BRepLib.hxx>
55 #include <BRepLib_MakeEdge.hxx>
56 #include <BRepTools_WireExplorer.hxx>
58 #include <ShapeAnalysis.hxx>
59 #include <ShapeAnalysis_FreeBounds.hxx>
63 #include <TopExp_Explorer.hxx>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Edge.hxx>
67 #include <TopoDS_Wire.hxx>
68 #include <TopoDS_Shell.hxx>
69 #include <TopoDS_Solid.hxx>
70 #include <TopoDS_Compound.hxx>
71 #include <TopoDS_Iterator.hxx>
73 #include <TopTools_MapOfShape.hxx>
74 #include <TopTools_HSequenceOfShape.hxx>
78 #include <GCPnts_AbscissaPoint.hxx>
80 #include <Geom_TrimmedCurve.hxx>
81 #include <Geom_RectangularTrimmedSurface.hxx>
82 #include <Geom_Surface.hxx>
83 #include <GeomAbs_CurveType.hxx>
84 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
85 #include <GeomConvert.hxx>
86 #include <GeomLProp.hxx>
88 #include <TColStd_SequenceOfReal.hxx>
89 #include <TColStd_HSequenceOfTransient.hxx>
90 #include <TColStd_Array1OfReal.hxx>
91 #include <TColGeom_SequenceOfCurve.hxx>
92 #include <TColGeom_Array1OfBSplineCurve.hxx>
93 #include <TColGeom_HArray1OfBSplineCurve.hxx>
95 #include <Precision.hxx>
97 #include <Standard_NullObject.hxx>
98 #include <Standard_TypeMismatch.hxx>
99 #include <Standard_ConstructionError.hxx>
101 #include <BOPAlgo_PaveFiller.hxx>
102 #include <BOPAlgo_MakerVolume.hxx>
106 //modified by NIZNHY-PKV Wed Dec 28 13:48:20 2011f
108 // void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
109 // const Handle(TopTools_HSequenceOfShape)& aWires);
110 //modified by NIZNHY-PKV Wed Dec 28 13:48:23 2011t
112 //=======================================================================
115 //=======================================================================
116 const Standard_GUID& GEOMImpl_ShapeDriver::GetID()
118 static Standard_GUID aShapeDriver("FF1BBB54-5D14-4df2-980B-3A668264EA16");
123 //=======================================================================
124 //function : GEOMImpl_ShapeDriver
126 //=======================================================================
127 GEOMImpl_ShapeDriver::GEOMImpl_ShapeDriver()
131 //=======================================================================
134 //=======================================================================
135 Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
137 if (Label().IsNull()) return 0;
138 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
140 GEOMImpl_IShapes aCI (aFunction);
141 Standard_Integer aType = aFunction->GetType();
144 TCollection_AsciiString aWarning;
145 std::list<TopAbs_ShapeEnum> anExpectedType;
149 if (aType == WIRE_EDGES) {
150 anExpectedType.push_back(TopAbs_WIRE);
152 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
154 Standard_Real aTolerance = aCI.GetTolerance();
155 if (aTolerance < Precision::Confusion())
156 aTolerance = Precision::Confusion();
158 aShape = MakeWireFromEdges(aShapes, aTolerance);
160 else if (aType == FACE_WIRE) {
161 anExpectedType.push_back(TopAbs_FACE);
163 Handle(GEOM_Function) aRefBase = aCI.GetBase();
164 TopoDS_Shape aShapeBase = aRefBase->GetValue();
165 if (aShapeBase.IsNull()) Standard_NullObject::Raise("Argument Shape is null");
167 if (aShapeBase.ShapeType() == TopAbs_WIRE) {
168 W = TopoDS::Wire(aShapeBase);
169 // check the wire is closed
170 TopoDS_Vertex aV1, aV2;
171 TopExp::Vertices(W, aV1, aV2);
172 if ( !aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2) )
173 aShapeBase.Closed(true);
175 Standard_NullObject::Raise
176 ("Shape for face construction is not closed");
178 else if (aShapeBase.ShapeType() == TopAbs_EDGE && BRep_Tool::IsClosed(aShapeBase)) {
179 BRepBuilderAPI_MakeWire MW;
180 MW.Add(TopoDS::Edge(aShapeBase));
182 Standard_ConstructionError::Raise("Wire construction failed");
187 Standard_NullObject::Raise
188 ("Shape for face construction is neither a wire nor a closed edge");
190 aWarning = GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), aShape);
191 if (aShape.IsNull()) {
192 Standard_ConstructionError::Raise("Face construction failed");
195 else if (aType == FACE_WIRES) {
196 anExpectedType.push_back(TopAbs_FACE);
198 // Try to build a face from a set of wires and edges
201 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
202 int nbshapes = aShapes->Length();
204 Standard_ConstructionError::Raise("No wires or edges given");
207 // 1. Extract all edges from the given arguments
208 TopTools_MapOfShape aMapEdges;
209 Handle(TopTools_HSequenceOfShape) aSeqEdgesIn = new TopTools_HSequenceOfShape;
211 for (ind = 1; ind <= nbshapes; ind++) {
212 Handle(GEOM_Function) aRefSh_i = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
213 TopoDS_Shape aSh_i = aRefSh_i->GetValue();
215 TopExp_Explorer anExpE_i (aSh_i, TopAbs_EDGE);
216 for (; anExpE_i.More(); anExpE_i.Next()) {
217 if (aMapEdges.Add(anExpE_i.Current())) {
218 aSeqEdgesIn->Append(anExpE_i.Current());
223 if (aSeqEdgesIn->IsEmpty()) {
224 Standard_ConstructionError::Raise("No edges given");
227 // 2. Connect edges to wires of maximum length
228 Handle(TopTools_HSequenceOfShape) aSeqWiresOut;
229 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdgesIn, Precision::Confusion(),
230 /*shared*/Standard_False, aSeqWiresOut);
231 //modified by NIZNHY-PKV Wed Dec 28 13:46:55 2011f
232 //KeepEdgesOrder(aSeqEdgesIn, aSeqWiresOut);
233 //modified by NIZNHY-PKV Wed Dec 28 13:46:59 2011t
235 // 3. Separate closed wires
236 Handle(TopTools_HSequenceOfShape) aSeqClosedWires = new TopTools_HSequenceOfShape;
237 Handle(TopTools_HSequenceOfShape) aSeqOpenWires = new TopTools_HSequenceOfShape;
238 for (ind = 1; ind <= aSeqWiresOut->Length(); ind++) {
239 if (aSeqWiresOut->Value(ind).Closed())
240 aSeqClosedWires->Append(aSeqWiresOut->Value(ind));
242 aSeqOpenWires->Append(aSeqWiresOut->Value(ind));
245 if (aSeqClosedWires->Length() < 1) {
246 Standard_ConstructionError::Raise
247 ("There is no closed contour can be built from the given arguments");
250 // 4. Build a face / list of faces from all the obtained closed wires
254 TopoDS_Wire aW1 = TopoDS::Wire(aSeqClosedWires->Value(1));
255 aWarning = GEOMImpl_Block6Explorer::MakeFace(aW1, aCI.GetIsPlanar(), aFFace);
256 if (aFFace.IsNull()) {
257 Standard_ConstructionError::Raise("Face construction failed");
260 // 4.b. Add other wires
261 if (aSeqClosedWires->Length() == 1) {
266 BRep_Builder aBuilder;
267 aBuilder.MakeCompound(C);
268 BRepAlgo_FaceRestrictor FR;
270 TopAbs_Orientation OriF = aFFace.Orientation();
271 TopoDS_Shape aLocalS = aFFace.Oriented(TopAbs_FORWARD);
272 FR.Init(TopoDS::Face(aLocalS), Standard_False, Standard_True);
274 for (ind = 1; ind <= aSeqClosedWires->Length(); ind++) {
275 TopoDS_Wire aW = TopoDS::Wire(aSeqClosedWires->Value(ind));
284 for (; FR.More(); FR.Next()) {
285 aFace = FR.Current().Oriented(OriF);
286 aBuilder.Add(C, aFace);
297 // 5. Add all open wires to the result
298 if (aSeqOpenWires->Length() > 0) {
299 //Standard_ConstructionError::Raise("There are some open wires");
301 BRep_Builder aBuilder;
302 if (aSeqClosedWires->Length() == 1) {
303 aBuilder.MakeCompound(C);
304 aBuilder.Add(C, aShape);
307 C = TopoDS::Compound(aShape);
310 for (ind = 1; ind <= aSeqOpenWires->Length(); ind++) {
311 aBuilder.Add(C, aSeqOpenWires->Value(ind));
317 else if (aType == FACE_FROM_SURFACE) {
318 anExpectedType.push_back(TopAbs_FACE);
320 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
322 if (aShapes.IsNull() == Standard_False) {
323 Standard_Integer aNbShapes = aShapes->Length();
325 if (aNbShapes == 2) {
326 Handle(GEOM_Function) aRefFace =
327 Handle(GEOM_Function)::DownCast(aShapes->Value(1));
328 Handle(GEOM_Function) aRefWire =
329 Handle(GEOM_Function)::DownCast(aShapes->Value(2));
331 if (aRefFace.IsNull() == Standard_False &&
332 aRefWire.IsNull() == Standard_False) {
333 TopoDS_Shape aShFace = aRefFace->GetValue();
334 TopoDS_Shape aShWire = aRefWire->GetValue();
336 if (aShFace.IsNull() == Standard_False &&
337 aShFace.ShapeType() == TopAbs_FACE &&
338 aShWire.IsNull() == Standard_False &&
339 aShWire.ShapeType() == TopAbs_WIRE) {
340 TopoDS_Face aFace = TopoDS::Face(aShFace);
341 TopoDS_Wire aWire = TopoDS::Wire(aShWire);
342 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
343 BRepBuilderAPI_MakeFace aMkFace(aSurf, aWire);
345 if (aMkFace.IsDone()) {
346 aShape = aMkFace.Shape();
353 else if (aType == SHELL_FACES) {
354 anExpectedType.push_back(TopAbs_SHELL);
356 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
357 unsigned int ind, nbshapes = aShapes->Length();
360 BRepBuilderAPI_Sewing aSewing (Precision::Confusion()*10.0);
361 for (ind = 1; ind <= nbshapes; ind++) {
362 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
363 TopoDS_Shape aShape_i = aRefShape->GetValue();
364 if (aShape_i.IsNull()) {
365 Standard_NullObject::Raise("Face for shell construction is null");
367 aSewing.Add(aShape_i);
372 TopoDS_Shape sh = aSewing.SewedShape();
374 if (sh.ShapeType()==TopAbs_FACE && nbshapes==1) {
375 // case for creation of shell from one face - PAL12722 (skl 26.06.2006)
382 //TopExp_Explorer exp (aSewing.SewedShape(), TopAbs_SHELL);
383 TopExp_Explorer exp (sh, TopAbs_SHELL);
384 Standard_Integer ish = 0;
385 for (; exp.More(); exp.Next()) {
386 aShape = exp.Current();
391 // try the case of one face (Mantis issue 0021809)
392 TopExp_Explorer expF (sh, TopAbs_FACE);
393 Standard_Integer ifa = 0;
394 for (; expF.More(); expF.Next()) {
395 aShape = expF.Current();
406 aShape = aSewing.SewedShape();
412 else if (aType == SOLID_SHELLS) {
413 anExpectedType.push_back(TopAbs_SOLID);
415 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
416 unsigned int ind, nbshapes = aShapes->Length();
417 Standard_Integer ish = 0;
418 BRepBuilderAPI_MakeSolid aMkSolid;
421 for (ind = 1; ind <= nbshapes; ind++) {
422 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
423 TopoDS_Shape aShapeShell = aRefShape->GetValue();
424 if (aShapeShell.IsNull()) {
425 Standard_NullObject::Raise("Shell for solid construction is null");
427 if (aShapeShell.ShapeType() == TopAbs_COMPOUND) {
428 TopoDS_Iterator It (aShapeShell, Standard_True, Standard_True);
429 if (It.More()) aShapeShell = It.Value();
431 if (aShapeShell.ShapeType() == TopAbs_SHELL) {
432 aMkSolid.Add(TopoDS::Shell(aShapeShell));
436 if (ish == 0 || !aMkSolid.IsDone()) return 0;
438 TopoDS_Solid Sol = aMkSolid.Solid();
439 BRepClass3d_SolidClassifier SC (Sol);
440 SC.PerformInfinitePoint(Precision::Confusion());
441 if (SC.State() == TopAbs_IN)
442 aShape = Sol.Reversed();
446 else if (aType == COMPOUND_SHAPES) {
447 anExpectedType.push_back(TopAbs_COMPOUND);
449 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
450 unsigned int ind, nbshapes = aShapes->Length();
455 for (ind = 1; ind <= nbshapes; ind++) {
456 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
457 TopoDS_Shape aShape_i = aRefShape->GetValue();
458 if (aShape_i.IsNull()) {
459 Standard_NullObject::Raise("Shape for compound construction is null");
467 else if (aType == EDGE_WIRE) {
468 anExpectedType.push_back(TopAbs_EDGE);
470 Handle(GEOM_Function) aRefBase = aCI.GetBase();
471 TopoDS_Shape aWire = aRefBase->GetValue();
472 Standard_Real LinTol = aCI.GetTolerance();
473 Standard_Real AngTol = aCI.GetAngularTolerance();
474 if (aWire.IsNull()) Standard_NullObject::Raise("Argument Wire is null");
476 aShape = MakeEdgeFromWire(aWire, LinTol, AngTol);
478 else if (aType == SOLID_FACES) {
479 anExpectedType.push_back(TopAbs_SOLID);
480 anExpectedType.push_back(TopAbs_COMPOUND);
481 anExpectedType.push_back(TopAbs_COMPSOLID);
483 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
484 unsigned int ind, nbshapes = aShapes->Length();
487 BOPCol_ListOfShape aLS;
488 for (ind = 1; ind <= nbshapes; ind++) {
489 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
490 TopoDS_Shape aShape_i = aRefShape->GetValue();
491 if (aShape_i.IsNull()) {
492 Standard_NullObject::Raise("Shape for solid construction is null");
494 aLS.Append(aShape_i);
497 BOPAlgo_MakerVolume aMV;
498 aMV.SetArguments(aLS);
499 aMV.SetIntersect(aCI.GetIsIntersect());
501 if (aMV.ErrorStatus()) return 0;
503 aShape = aMV.Shape();
505 else if (aType == EDGE_CURVE_LENGTH) {
506 anExpectedType.push_back(TopAbs_EDGE);
508 GEOMImpl_IVector aVI (aFunction);
511 Handle(GEOM_Function) aRefCurve = aVI.GetPoint1();
512 if (aRefCurve.IsNull()) Standard_NullObject::Raise("Argument Curve is null");
513 TopoDS_Shape aRefShape1 = aRefCurve->GetValue();
514 if (aRefShape1.ShapeType() != TopAbs_EDGE) {
515 Standard_TypeMismatch::Raise
516 ("Edge On Curve creation aborted : curve shape is not an edge");
518 TopoDS_Edge aRefEdge = TopoDS::Edge(aRefShape1);
519 TopoDS_Vertex V1, V2;
520 TopExp::Vertices(aRefEdge, V1, V2, Standard_True);
523 TopoDS_Vertex aRefVertex;
524 Handle(GEOM_Function) aRefPoint = aVI.GetPoint2();
525 if (aRefPoint.IsNull()) {
529 TopoDS_Shape aRefShape2 = aRefPoint->GetValue();
530 if (aRefShape2.ShapeType() != TopAbs_VERTEX) {
531 Standard_TypeMismatch::Raise
532 ("Edge On Curve creation aborted : start point shape is not a vertex");
534 aRefVertex = TopoDS::Vertex(aRefShape2);
536 gp_Pnt aRefPnt = BRep_Tool::Pnt(aRefVertex);
539 Standard_Real aLength = aVI.GetParameter();
540 //Standard_Real aCurveLength = IntTools::Length(aRefEdge);
541 //if (aLength > aCurveLength) {
542 // Standard_ConstructionError::Raise
543 // ("Edge On Curve creation aborted : given length is greater than edges length");
545 if (fabs(aLength) < Precision::Confusion()) {
546 Standard_ConstructionError::Raise
547 ("Edge On Curve creation aborted : given length is smaller than Precision::Confusion()");
551 Standard_Real UFirst, ULast;
552 Handle(Geom_Curve) EdgeCurve = BRep_Tool::Curve(aRefEdge, UFirst, ULast);
553 Handle(Geom_Curve) ReOrientedCurve = EdgeCurve;
555 Standard_Real dU = ULast - UFirst;
556 Standard_Real par1 = UFirst + 0.1 * dU;
557 Standard_Real par2 = ULast - 0.1 * dU;
559 gp_Pnt P1 = EdgeCurve->Value(par1);
560 gp_Pnt P2 = EdgeCurve->Value(par2);
562 if (aRefPnt.SquareDistance(P2) < aRefPnt.SquareDistance(P1)) {
563 ReOrientedCurve = EdgeCurve->Reversed();
564 UFirst = EdgeCurve->ReversedParameter(ULast);
567 // Get the point by length
568 GeomAdaptor_Curve AdapCurve = GeomAdaptor_Curve(ReOrientedCurve);
569 GCPnts_AbscissaPoint anAbsPnt (AdapCurve, aLength, UFirst);
570 Standard_Real aParam = anAbsPnt.Parameter();
572 if (AdapCurve.IsClosed() && aLength < 0.0) {
573 Standard_Real aTmp = aParam;
578 BRepBuilderAPI_MakeEdge aME (ReOrientedCurve, UFirst, aParam);
580 aShape = aME.Shape();
581 } else if (aType == SHAPE_ISOLINE) {
582 GEOMImpl_IIsoline aII (aFunction);
583 Handle(GEOM_Function) aRefFace = aII.GetFace();
584 TopoDS_Shape aShapeFace = aRefFace->GetValue();
586 if (aShapeFace.ShapeType() == TopAbs_FACE) {
587 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
588 bool isUIso = aII.GetIsUIso();
589 Standard_Real aParam = aII.GetParameter();
590 Standard_Real U1,U2,V1,V2;
592 // Construct a real geometric parameter.
593 aFace.Orientation(TopAbs_FORWARD);
594 ShapeAnalysis::GetFaceUVBounds(aFace,U1,U2,V1,V2);
597 aParam = U1 + (U2 - U1)*aParam;
599 aParam = V1 + (V2 - V1)*aParam;
602 aShape = MakeIsoline(aFace, isUIso, aParam);
604 Standard_NullObject::Raise
605 ("Shape for isoline construction is not a face");
607 } else if (aType == EDGE_UV) {
608 anExpectedType.push_back(TopAbs_EDGE);
609 GEOMImpl_IShapeExtend aSE (aFunction);
610 Handle(GEOM_Function) aRefEdge = aSE.GetShape();
611 TopoDS_Shape aShapeEdge = aRefEdge->GetValue();
613 if (aShapeEdge.ShapeType() == TopAbs_EDGE) {
614 TopoDS_Edge anEdge = TopoDS::Edge(aShapeEdge);
616 aShape = ExtendEdge(anEdge, aSE.GetUMin(), aSE.GetUMax());
618 } else if (aType == FACE_UV) {
619 anExpectedType.push_back(TopAbs_FACE);
621 GEOMImpl_IShapeExtend aSE (aFunction);
622 Handle(GEOM_Function) aRefFace = aSE.GetShape();
623 TopoDS_Shape aShapeFace = aRefFace->GetValue();
625 if (aShapeFace.ShapeType() == TopAbs_FACE) {
626 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
628 aFace.Orientation(TopAbs_FORWARD);
629 aShape = ExtendFace(aFace, aSE.GetUMin(), aSE.GetUMax(),
630 aSE.GetVMin(), aSE.GetVMax());
632 } else if (aType == SURFACE_FROM_FACE) {
633 anExpectedType.push_back(TopAbs_FACE);
635 GEOMImpl_IShapeExtend aSE (aFunction);
636 Handle(GEOM_Function) aRefFace = aSE.GetShape();
637 TopoDS_Shape aShapeFace = aRefFace->GetValue();
639 if (aShapeFace.ShapeType() == TopAbs_FACE) {
640 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
641 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
643 if (aSurface.IsNull() == Standard_False) {
644 Handle(Standard_Type) aType = aSurface->DynamicType();
650 // Get U, V bounds of the face.
651 aFace.Orientation(TopAbs_FORWARD);
652 ShapeAnalysis::GetFaceUVBounds(aFace, aU1, aU2, aV1, aV2);
654 // Get the surface of original type
655 while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
656 Handle(Geom_RectangularTrimmedSurface) aTrSurface =
657 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
659 aSurface = aTrSurface->BasisSurface();
660 aType = aSurface->DynamicType();
663 const Standard_Real aTol = BRep_Tool::Tolerance(aFace);
664 BRepBuilderAPI_MakeFace aMF(aSurface, aU1, aU2, aV1, aV2, aTol);
667 aShape = aMF.Shape();
675 if (aShape.IsNull()) return 0;
677 // Check shape validity
678 BRepCheck_Analyzer ana (aShape, false);
679 if (!ana.IsValid()) {
680 //Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
681 // For Mantis issue 0021772: EDF 2336 GEOM: Non valid face created from two circles
682 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape (aShape);
684 aShape = aSfs->Shape();
687 // Check if the result shape type is compatible with the expected.
688 const TopAbs_ShapeEnum aShType = aShape.ShapeType();
690 if (!anExpectedType.empty()) {
692 std::list<TopAbs_ShapeEnum>::const_iterator it;
693 for (it = anExpectedType.begin(); it != anExpectedType.end() && !ok; ++it)
694 ok = (*it == TopAbs_SHAPE || *it == aShType);
696 Standard_ConstructionError::Raise("Result type check failed");
699 aFunction->SetValue(aShape);
701 log.SetTouched(Label());
703 if (!aWarning.IsEmpty())
704 Standard_Failure::Raise(aWarning.ToCString());
709 TopoDS_Wire GEOMImpl_ShapeDriver::MakeWireFromEdges(const Handle(TColStd_HSequenceOfTransient)& theEdgesFuncs,
710 const Standard_Real theTolerance)
718 for (unsigned int ind = 1; ind <= theEdgesFuncs->Length(); ind++) {
719 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(theEdgesFuncs->Value(ind));
720 TopoDS_Shape aShape_i = aRefShape->GetValue();
721 if (aShape_i.IsNull()) {
722 Standard_NullObject::Raise("Shape for wire construction is null");
724 if (aShape_i.ShapeType() == TopAbs_EDGE || aShape_i.ShapeType() == TopAbs_WIRE) {
725 TopExp_Explorer exp (aShape_i, TopAbs_EDGE);
726 for (; exp.More(); exp.Next())
727 B.Add(aWire, TopoDS::Edge(exp.Current()));
729 Standard_TypeMismatch::Raise
730 ("Shape for wire construction is neither an edge nor a wire");
735 Handle(ShapeFix_Wire) aFW = new ShapeFix_Wire;
739 if (aFW->StatusReorder(ShapeExtend_FAIL1)) {
740 Standard_ConstructionError::Raise("Wire construction failed: several loops detected");
742 else if (aFW->StatusReorder(ShapeExtend_FAIL)) {
743 Standard_ConstructionError::Raise("Wire construction failed");
748 // IMP 0019766: Building a Wire from unconnected edges by introducing a tolerance
749 aFW->ClosedWireMode() = Standard_False;
750 aFW->FixConnected(theTolerance);
751 if (aFW->StatusConnected(ShapeExtend_FAIL)) {
752 Standard_ConstructionError::Raise("Wire construction failed: cannot build connected wire");
755 if (aFW->StatusConnected(ShapeExtend_DONE3)) {
756 // Confused with <prec> but not Analyzer.Precision(), set the same
757 aFW->FixGapsByRangesMode() = Standard_True;
758 if (aFW->FixGaps3d()) {
759 Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
760 Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
761 for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
762 TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
763 aFe->FixVertexTolerance(aEdge);
764 aFe->FixSameParameter(aEdge);
767 else if (aFW->StatusGaps3d(ShapeExtend_FAIL)) {
768 Standard_ConstructionError::Raise("Wire construction failed: cannot fix 3d gaps");
771 aWire = aFW->WireAPIMake();
776 TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
777 const Standard_Real LinTol,
778 const Standard_Real AngTol)
782 BRepLib::BuildCurves3d(aWire);
783 Handle(ShapeFix_Shape) Fixer = new ShapeFix_Shape(aWire);
784 Fixer->SetPrecision(LinTol);
785 Fixer->SetMaxTolerance(LinTol);
787 TopoDS_Wire theWire = TopoDS::Wire(Fixer->Shape());
789 TColGeom_SequenceOfCurve CurveSeq;
790 TopTools_SequenceOfShape LocSeq;
791 TColStd_SequenceOfReal FparSeq;
792 TColStd_SequenceOfReal LparSeq;
793 TColStd_SequenceOfReal TolSeq;
794 GeomAbs_CurveType CurType;
795 TopoDS_Vertex FirstVertex, LastVertex;
796 Standard_Real aPntShiftDist = 0.;
798 BRepTools_WireExplorer wexp(theWire) ;
799 for (; wexp.More(); wexp.Next())
801 TopoDS_Edge anEdge = wexp.Current();
802 Standard_Real fpar, lpar;
803 TopLoc_Location aLoc;
804 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aLoc, fpar, lpar);
808 BRepAdaptor_Curve BAcurve(anEdge);
809 GeomAbs_CurveType aType = BAcurve.GetType();
811 Handle(Geom_Curve) aBasisCurve = BAcurve.Curve().Curve();
813 if (aBasisCurve->IsPeriodic())
814 ElCLib::AdjustPeriodic(aBasisCurve->FirstParameter(), aBasisCurve->LastParameter(),
815 Precision::PConfusion(), fpar, lpar);
817 if (CurveSeq.IsEmpty())
819 CurveSeq.Append(aCurve);
820 TopoDS_Shape aLocShape;
821 aLocShape.Location(aLoc);
822 aLocShape.Orientation(wexp.Orientation());
823 LocSeq.Append(aLocShape);
824 FparSeq.Append(fpar);
825 LparSeq.Append(lpar);
827 FirstVertex = wexp.CurrentVertex();
831 Standard_Boolean Done = Standard_False;
832 Standard_Real NewFpar, NewLpar;
833 GeomAdaptor_Curve GAprevcurve(CurveSeq.Last());
834 TopoDS_Vertex CurVertex = wexp.CurrentVertex();
835 TopoDS_Vertex CurFirstVer = TopExp::FirstVertex(anEdge);
836 TopAbs_Orientation ConnectByOrigin = (CurVertex.IsSame(CurFirstVer))? TopAbs_FORWARD : TopAbs_REVERSED;
837 if (aCurve == CurveSeq.Last())
841 if (aBasisCurve->IsPeriodic())
843 if (NewLpar < NewFpar)
844 NewLpar += aBasisCurve->Period();
845 if (ConnectByOrigin == TopAbs_FORWARD)
846 ElCLib::AdjustPeriodic(FparSeq.Last(),
847 FparSeq.Last() + aBasisCurve->Period(),
848 Precision::PConfusion(), NewFpar, NewLpar);
850 ElCLib::AdjustPeriodic(FparSeq.Last() - aBasisCurve->Period(),
852 Precision::PConfusion(), NewFpar, NewLpar);
854 Done = Standard_True;
856 else if (aType == CurType &&
857 aType != GeomAbs_BezierCurve &&
858 aType != GeomAbs_BSplineCurve &&
859 aType != GeomAbs_OtherCurve)
865 gp_Lin aLine = BAcurve.Line();
866 gp_Lin PrevLine = GAprevcurve.Line();
867 if (aLine.Contains(PrevLine.Location(), LinTol) &&
868 aLine.Direction().IsParallel(PrevLine.Direction(), AngTol))
870 gp_Pnt P1 = ElCLib::Value(fpar, aLine);
871 gp_Pnt P2 = ElCLib::Value(lpar, aLine);
872 NewFpar = ElCLib::Parameter(PrevLine, P1);
873 NewLpar = ElCLib::Parameter(PrevLine, P2);
876 if (ConnectByOrigin == TopAbs_FORWARD) {
877 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevLine);
879 aPntShiftDist += P2.Distance(aNewP2);
881 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevLine);
883 aPntShiftDist += P1.Distance(aNewP1);
886 if (NewLpar < NewFpar)
888 Standard_Real MemNewFpar = NewFpar;
890 NewLpar = MemNewFpar;
891 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
893 Done = Standard_True;
899 gp_Circ aCircle = BAcurve.Circle();
900 gp_Circ PrevCircle = GAprevcurve.Circle();
901 if (aCircle.Location().Distance(PrevCircle.Location()) <= LinTol &&
902 Abs(aCircle.Radius() - PrevCircle.Radius()) <= LinTol &&
903 aCircle.Axis().IsParallel(PrevCircle.Axis(), AngTol))
905 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
907 if (aCircle.Axis().Direction() * PrevCircle.Axis().Direction() < 0.)
909 Standard_Real memfpar = fpar;
912 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
914 gp_Pnt P1 = ElCLib::Value(fpar, aCircle);
915 gp_Pnt P2 = ElCLib::Value(lpar, aCircle);
916 NewFpar = ElCLib::Parameter(PrevCircle, P1);
917 NewLpar = ElCLib::Parameter(PrevCircle, P2);
921 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevCircle);
923 aPntShiftDist += P2.Distance(aNewP2);
925 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevCircle);
927 aPntShiftDist += P1.Distance(aNewP1);
930 if (NewLpar < NewFpar)
932 //Standard_Real MemNewFpar = NewFpar, MemNewLpar = NewLpar;
933 if (ConnectByOrigin == TopAbs_FORWARD)
934 ElCLib::AdjustPeriodic(FparSeq.Last(),
935 FparSeq.Last() + 2.*M_PI,
936 Precision::PConfusion(), NewFpar, NewLpar);
938 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
940 Precision::PConfusion(), NewFpar, NewLpar);
941 Done = Standard_True;
945 case GeomAbs_Ellipse:
947 gp_Elips anEllipse = BAcurve.Ellipse();
948 gp_Elips PrevEllipse = GAprevcurve.Ellipse();
949 if (anEllipse.Focus1().Distance(PrevEllipse.Focus1()) <= LinTol &&
950 anEllipse.Focus2().Distance(PrevEllipse.Focus2()) <= LinTol &&
951 Abs(anEllipse.MajorRadius() - PrevEllipse.MajorRadius()) <= LinTol &&
952 Abs(anEllipse.MinorRadius() - PrevEllipse.MinorRadius()) <= LinTol &&
953 anEllipse.Axis().IsParallel(PrevEllipse.Axis(), AngTol))
955 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
957 if (anEllipse.Axis().Direction() * PrevEllipse.Axis().Direction() < 0.)
959 Standard_Real memfpar = fpar;
962 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
964 gp_Pnt P1 = ElCLib::Value(fpar, anEllipse);
965 gp_Pnt P2 = ElCLib::Value(lpar, anEllipse);
966 NewFpar = ElCLib::Parameter(PrevEllipse, P1);
967 NewLpar = ElCLib::Parameter(PrevEllipse, P2);
971 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevEllipse);
973 aPntShiftDist += P2.Distance(aNewP2);
975 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevEllipse);
977 aPntShiftDist += P1.Distance(aNewP1);
980 if (NewLpar < NewFpar)
982 if (ConnectByOrigin == TopAbs_FORWARD)
983 ElCLib::AdjustPeriodic(FparSeq.Last(),
984 FparSeq.Last() + 2.*M_PI,
985 Precision::PConfusion(), NewFpar, NewLpar);
987 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
989 Precision::PConfusion(), NewFpar, NewLpar);
990 Done = Standard_True;
994 case GeomAbs_Hyperbola:
996 gp_Hypr aHypr = BAcurve.Hyperbola();
997 gp_Hypr PrevHypr = GAprevcurve.Hyperbola();
998 if (aHypr.Focus1().Distance(PrevHypr.Focus1()) <= LinTol &&
999 aHypr.Focus2().Distance(PrevHypr.Focus2()) <= LinTol &&
1000 Abs(aHypr.MajorRadius() - PrevHypr.MajorRadius()) <= LinTol &&
1001 Abs(aHypr.MinorRadius() - PrevHypr.MinorRadius()) <= LinTol &&
1002 aHypr.Axis().IsParallel(PrevHypr.Axis(), AngTol))
1004 gp_Pnt P1 = ElCLib::Value(fpar, aHypr);
1005 gp_Pnt P2 = ElCLib::Value(lpar, aHypr);
1006 NewFpar = ElCLib::Parameter(PrevHypr, P1);
1007 NewLpar = ElCLib::Parameter(PrevHypr, P2);
1010 if (ConnectByOrigin == TopAbs_FORWARD) {
1011 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevHypr);
1013 aPntShiftDist += P2.Distance(aNewP2);
1015 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevHypr);
1017 aPntShiftDist += P1.Distance(aNewP1);
1020 if (NewLpar < NewFpar)
1022 Standard_Real MemNewFpar = NewFpar;
1024 NewLpar = MemNewFpar;
1025 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1027 Done = Standard_True;
1031 case GeomAbs_Parabola:
1033 gp_Parab aParab = BAcurve.Parabola();
1034 gp_Parab PrevParab = GAprevcurve.Parabola();
1035 if (aParab.Location().Distance(PrevParab.Location()) <= LinTol &&
1036 aParab.Focus().Distance(PrevParab.Focus()) <= LinTol &&
1037 Abs(aParab.Focal() - PrevParab.Focal()) <= LinTol &&
1038 aParab.Axis().IsParallel(PrevParab.Axis(), AngTol))
1040 gp_Pnt P1 = ElCLib::Value(fpar, aParab);
1041 gp_Pnt P2 = ElCLib::Value(lpar, aParab);
1042 NewFpar = ElCLib::Parameter(PrevParab, P1);
1043 NewLpar = ElCLib::Parameter(PrevParab, P2);
1046 if (ConnectByOrigin == TopAbs_FORWARD) {
1047 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevParab);
1049 aPntShiftDist += P2.Distance(aNewP2);
1051 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevParab);
1053 aPntShiftDist += P1.Distance(aNewP1);
1056 if (NewLpar < NewFpar)
1058 Standard_Real MemNewFpar = NewFpar;
1060 NewLpar = MemNewFpar;
1061 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1063 Done = Standard_True;
1067 } //end of switch (aType)
1068 } // end of else if (aType == CurType && ...
1071 if (NewFpar < FparSeq.Last())
1072 FparSeq(FparSeq.Length()) = NewFpar;
1074 LparSeq(LparSeq.Length()) = NewLpar;
1078 CurveSeq.Append(aCurve);
1079 TopoDS_Shape aLocShape;
1080 aLocShape.Location(aLoc);
1081 aLocShape.Orientation(wexp.Orientation());
1082 LocSeq.Append(aLocShape);
1083 FparSeq.Append(fpar);
1084 LparSeq.Append(lpar);
1085 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(CurVertex));
1089 } // end of else (CurveSeq.IsEmpty()) -> not first time
1090 } // end for (; wexp.More(); wexp.Next())
1092 LastVertex = wexp.CurrentVertex();
1093 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(LastVertex));
1095 FirstVertex.Orientation(TopAbs_FORWARD);
1096 LastVertex.Orientation(TopAbs_REVERSED);
1098 if (!CurveSeq.IsEmpty())
1100 Standard_Integer nb_curve = CurveSeq.Length(); //number of curves
1101 TColGeom_Array1OfBSplineCurve tab(0,nb_curve-1); //array of the curves
1102 TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2); //array of the tolerances
1108 for (i = 1; i <= nb_curve; i++)
1110 if (CurveSeq(i)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1111 CurveSeq(i) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(i))))->BasisCurve();
1113 Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(CurveSeq(i), FparSeq(i), LparSeq(i));
1114 tab(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve);
1115 tab(i-1)->Transform(LocSeq(i).Location().Transformation());
1116 GeomConvert::C0BSplineToC1BSplineCurve(tab(i-1), Precision::Confusion());
1117 if (LocSeq(i).Orientation() == TopAbs_REVERSED)
1118 tab(i-1)->Reverse();
1121 //char* name = new char[100];
1122 //sprintf(name, "c%d", i);
1123 //DrawTrSurf::Set(name, tab(i-1));
1126 tabtolvertex(i-2) = TolSeq(i-1);
1127 } // end for (i = 1; i <= nb_curve; i++)
1128 tabtolvertex(nb_curve-1) = TolSeq(TolSeq.Length());
1130 Standard_Boolean closed_flag = Standard_False;
1131 Standard_Real closed_tolerance = 0.;
1132 if (FirstVertex.IsSame(LastVertex) &&
1133 GeomLProp::Continuity(tab(0), tab(nb_curve-1),
1134 tab(0)->FirstParameter(),
1135 tab(nb_curve-1)->LastParameter(),
1136 Standard_False, Standard_False, LinTol, AngTol) >= GeomAbs_G1)
1138 closed_flag = Standard_True ;
1139 closed_tolerance = BRep_Tool::Tolerance(FirstVertex);
1142 Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves
1143 Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex
1144 GeomConvert::ConcatC1(tab,
1149 closed_tolerance); //C1 concatenation
1151 if (concatcurve->Length() > 1)
1153 GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower()));
1155 for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++)
1156 Concat.Add( concatcurve->Value(i), LinTol, Standard_True );
1158 concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve());
1160 // rnc : prevents the driver from building an edge without C1 continuity
1161 if (concatcurve->Value(concatcurve->Lower())->Continuity()==GeomAbs_C0){
1162 Standard_ConstructionError::Raise("Construction aborted : The given Wire has sharp bends between some Edges, no valid Edge can be built");
1165 Standard_Boolean isValidEndVtx = Standard_True;
1168 // Check if closed curve is reordered.
1169 Handle(Geom_Curve) aCurve = concatcurve->Value(concatcurve->Lower());
1170 Standard_Real aFPar = aCurve->FirstParameter();
1172 gp_Pnt aPntVtx = BRep_Tool::Pnt(FirstVertex);
1173 Standard_Real aTolVtx = BRep_Tool::Tolerance(FirstVertex);
1175 aCurve->D0(aFPar, aPFirst);
1177 if (!aPFirst.IsEqual(aPntVtx, aTolVtx)) {
1178 // The curve is reordered. Find the new first and last vertices.
1179 TopTools_IndexedMapOfShape aMapVtx;
1180 TopExp::MapShapes(theWire, TopAbs_VERTEX, aMapVtx);
1182 const Standard_Integer aNbVtx = aMapVtx.Extent();
1183 Standard_Integer iVtx;
1185 for (iVtx = 1; iVtx <= aNbVtx; iVtx++) {
1186 const TopoDS_Vertex aVtx = TopoDS::Vertex(aMapVtx.FindKey(iVtx));
1187 const gp_Pnt aPnt = BRep_Tool::Pnt(aVtx);
1188 const Standard_Real aTol = BRep_Tool::Tolerance(aVtx);
1190 if (aPFirst.IsEqual(aPnt, aTol)) {
1191 // The coinsident vertex is found.
1194 FirstVertex.Orientation(TopAbs_FORWARD);
1195 LastVertex.Orientation(TopAbs_REVERSED);
1200 if (iVtx > aNbVtx) {
1201 // It is necessary to create new vertices.
1202 isValidEndVtx = Standard_False;
1207 if (isValidEndVtx) {
1208 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1209 FirstVertex, LastVertex,
1210 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1211 concatcurve->Value(concatcurve->Lower())->LastParameter());
1213 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1214 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1215 concatcurve->Value(concatcurve->Lower())->LastParameter());
1220 if (CurveSeq(1)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1221 CurveSeq(1) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(1))))->BasisCurve();
1223 Handle(Geom_Curve) aNewCurve =
1224 Handle(Geom_Curve)::DownCast(CurveSeq(1)->Copy());
1226 aNewCurve->Transform(LocSeq(1).Location().Transformation());
1228 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1229 const TopoDS_Vertex aVtxTmp = FirstVertex;
1231 FirstVertex = LastVertex;
1232 LastVertex = aVtxTmp;
1233 FirstVertex.Orientation(TopAbs_FORWARD);
1234 LastVertex.Orientation(TopAbs_REVERSED);
1237 ResEdge = BRepLib_MakeEdge(aNewCurve,
1238 FirstVertex, LastVertex,
1239 FparSeq(1), LparSeq(1));
1241 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1250 //=============================================================================
1252 * \brief Returns an isoline for a face.
1254 //=============================================================================
1256 TopoDS_Shape GEOMImpl_ShapeDriver::MakeIsoline
1257 (const TopoDS_Face &theFace,
1259 const double theParameter) const
1261 TopoDS_Shape aResult;
1262 GEOMUtils::Hatcher aHatcher(theFace);
1263 const GeomAbs_IsoType aType = (IsUIso ? GeomAbs_IsoU : GeomAbs_IsoV);
1265 aHatcher.Init(aType, theParameter);
1268 if (!aHatcher.IsDone()) {
1269 Standard_ConstructionError::Raise("MakeIsoline : Hatcher failure");
1272 const Handle(TColStd_HArray1OfInteger) &anIndices =
1273 (IsUIso ? aHatcher.GetUIndices() : aHatcher.GetVIndices());
1275 if (anIndices.IsNull()) {
1276 Standard_ConstructionError::Raise("MakeIsoline : Null hatching indices");
1279 const Standard_Integer anIsoInd = anIndices->Lower();
1280 const Standard_Integer aHatchingIndex = anIndices->Value(anIsoInd);
1282 if (aHatchingIndex == 0) {
1283 Standard_ConstructionError::Raise("MakeIsoline : Invalid hatching index");
1286 const Standard_Integer aNbDomains =
1287 aHatcher.GetNbDomains(aHatchingIndex);
1289 if (aNbDomains < 0) {
1290 Standard_ConstructionError::Raise("MakeIsoline : Invalid number of domains");
1293 // The hatching is performed successfully. Create the 3d Curve.
1294 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1295 Handle(Geom_Curve) anIsoCurve = (IsUIso ?
1296 aSurface->UIso(theParameter) : aSurface->VIso(theParameter));
1297 Handle(Geom2d_Curve) aPIsoCurve =
1298 aHatcher.GetHatching(aHatchingIndex);
1299 const Standard_Real aTol = Precision::Confusion();
1300 Standard_Integer anIDom = 1;
1303 BRep_Builder aBuilder;
1304 Standard_Integer aNbEdges = 0;
1306 for (; anIDom <= aNbDomains; anIDom++) {
1307 if (aHatcher.GetDomain(aHatchingIndex, anIDom, aV1, aV2)) {
1308 // Check first and last parameters.
1309 if (!aHatcher.IsDomainInfinite(aHatchingIndex, anIDom)) {
1311 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(anIsoCurve, aV1, aV2);
1313 // Update it with a parametric curve on face.
1314 aBuilder.UpdateEdge(anEdge, aPIsoCurve, theFace, aTol);
1318 // Result is a compond.
1319 if (aNbEdges == 2) {
1320 // Create a new compound.
1321 TopoDS_Compound aCompound;
1323 aBuilder.MakeCompound(aCompound);
1324 aBuilder.Add(aCompound, aResult);
1325 aResult = aCompound;
1328 // Add an edge to the compound.
1329 aBuilder.Add(aResult, anEdge);
1331 // Result is the edge.
1338 if (aNbEdges == 0) {
1339 Standard_ConstructionError::Raise("MakeIsoline : Empty result");
1345 //=============================================================================
1347 * \brief Returns an extended edge.
1349 //=============================================================================
1351 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendEdge
1352 (const TopoDS_Edge &theEdge,
1353 const Standard_Real theMin,
1354 const Standard_Real theMax) const
1356 TopoDS_Shape aResult;
1359 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(theEdge, aF, aL);
1360 const Standard_Real aTol = BRep_Tool::Tolerance(theEdge);
1361 Standard_Real aRange2d = aL - aF;
1363 if (aCurve.IsNull() == Standard_False && aRange2d > aTol) {
1364 Standard_Real aMin = aF + aRange2d*theMin;
1365 Standard_Real aMax = aF + aRange2d*theMax;
1367 Handle(Standard_Type) aType = aCurve->DynamicType();
1369 // Get the curve of original type
1370 while (aType == STANDARD_TYPE(Geom_TrimmedCurve)) {
1371 Handle(Geom_TrimmedCurve) aTrCurve =
1372 Handle(Geom_TrimmedCurve)::DownCast(aCurve);
1374 aCurve = aTrCurve->BasisCurve();
1375 aType = aCurve->DynamicType();
1378 if (aCurve->IsPeriodic()) {
1379 // The curve is periodic. Check if a new range is less then a period.
1380 if (aMax - aMin > aCurve->Period()) {
1381 aMax = aMin + aCurve->Period();
1384 // The curve is not periodic. Check if aMin and aMax within bounds.
1385 aMin = Max(aMin, aCurve->FirstParameter());
1386 aMax = Min(aMax, aCurve->LastParameter());
1389 if (aMax - aMin > aTol) {
1390 // Create a new edge.
1391 BRepBuilderAPI_MakeEdge aME (aCurve, aMin, aMax);
1394 aResult = aME.Shape();
1402 //=============================================================================
1404 * \brief Returns an extended face.
1406 //=============================================================================
1408 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendFace
1409 (const TopoDS_Face &theFace,
1410 const Standard_Real theUMin,
1411 const Standard_Real theUMax,
1412 const Standard_Real theVMin,
1413 const Standard_Real theVMax) const
1415 TopoDS_Shape aResult;
1416 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1417 const Standard_Real aTol = BRep_Tool::Tolerance(theFace);
1423 // Get U, V bounds of the face.
1424 ShapeAnalysis::GetFaceUVBounds(theFace, aU1, aU2, aV1, aV2);
1426 const Standard_Real aURange = aU2 - aU1;
1427 const Standard_Real aVRange = aV2 - aV1;
1429 if (aSurface.IsNull() == Standard_False &&
1430 aURange > aTol && aURange > aTol) {
1431 Handle(Standard_Type) aType = aSurface->DynamicType();
1433 // Get the surface of original type
1434 while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1435 Handle(Geom_RectangularTrimmedSurface) aTrSurface =
1436 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
1438 aSurface = aTrSurface->BasisSurface();
1439 aType = aSurface->DynamicType();
1442 Standard_Real aUMin = aU1 + aURange*theUMin;
1443 Standard_Real aUMax = aU1 + aURange*theUMax;
1444 Standard_Real aVMin = aV1 + aVRange*theVMin;
1445 Standard_Real aVMax = aV1 + aVRange*theVMax;
1447 aSurface->Bounds(aU1, aU2, aV1, aV2);
1449 if (aSurface->IsUPeriodic()) {
1450 // The surface is U-periodic. Check if a new U range is less
1452 if (aUMax - aUMin > aSurface->UPeriod()) {
1453 aUMax = aUMin + aSurface->UPeriod();
1456 // The surface is not V-periodic. Check if aUMin and aUMax
1458 aUMin = Max(aUMin, aU1);
1459 aUMax = Min(aUMax, aU2);
1462 if (aSurface->IsVPeriodic()) {
1463 // The surface is V-periodic. Check if a new V range is less
1465 if (aVMax - aVMin > aSurface->VPeriod()) {
1466 aVMax = aVMin + aSurface->VPeriod();
1469 // The surface is not V-periodic. Check if aVMin and aVMax
1471 aVMin = Max(aVMin, aV1);
1472 aVMax = Min(aVMax, aV2);
1475 if (aUMax - aUMin > aTol && aVMax - aVMin > aTol) {
1476 // Create a new edge.
1477 BRepBuilderAPI_MakeFace aMF
1478 (aSurface, aUMin, aUMax, aVMin, aVMax, aTol);
1481 aResult = aMF.Shape();
1489 //================================================================================
1491 * \brief Returns a name of creation operation and names and values of creation parameters
1493 //================================================================================
1495 bool GEOMImpl_ShapeDriver::
1496 GetCreationInformation(std::string& theOperationName,
1497 std::vector<GEOM_Param>& theParams)
1499 if (Label().IsNull()) return 0;
1500 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
1502 GEOMImpl_IShapes aCI( function );
1503 Standard_Integer aType = function->GetType();
1507 theOperationName = "WIRE";
1508 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1509 AddParam( theParams, "Tolerance", aCI.GetTolerance() );
1512 theOperationName = "FACE";
1513 AddParam( theParams, "Wire/edge", aCI.GetBase() );
1514 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1517 theOperationName = "FACE";
1518 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1519 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1521 case FACE_FROM_SURFACE:
1523 theOperationName = "FACE";
1525 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1527 if (shapes.IsNull() == Standard_False) {
1528 Standard_Integer aNbShapes = shapes->Length();
1530 if (aNbShapes > 0) {
1531 AddParam(theParams, "Face", shapes->Value(1));
1533 if (aNbShapes > 1) {
1534 AddParam(theParams, "Wire", shapes->Value(2));
1541 theOperationName = "SHELL";
1542 AddParam( theParams, "Objects", aCI.GetShapes() );
1545 theOperationName = "SOLID";
1546 AddParam( theParams, "Objects", aCI.GetShapes() );
1549 theOperationName = "SOLID_FROM_FACES";
1550 AddParam( theParams, "Objects", aCI.GetShapes() );
1551 AddParam( theParams, "Is intersect", aCI.GetIsIntersect() );
1553 case COMPOUND_SHAPES:
1554 theOperationName = "COMPOUND";
1555 AddParam( theParams, "Objects", aCI.GetShapes() );
1558 theOperationName = "EDGE";
1559 AddParam( theParams, "Wire", aCI.GetBase() );
1560 AddParam( theParams, "Linear Tolerance", aCI.GetTolerance() );
1561 AddParam( theParams, "Angular Tolerance", aCI.GetAngularTolerance() );
1563 case EDGE_CURVE_LENGTH:
1564 theOperationName = "EDGE";
1566 GEOMImpl_IVector aCI( function );
1567 AddParam( theParams, "Edge", aCI.GetPoint1() );
1568 AddParam( theParams, "Start point", aCI.GetPoint2() );
1569 AddParam( theParams, "Length", aCI.GetParameter() );
1572 case SHAPES_ON_SHAPE:
1574 theOperationName = "GetShapesOnShapeAsCompound";
1575 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1576 if ( !shapes.IsNull() && shapes->Length() > 0 )
1577 AddParam( theParams, "Check shape", shapes->Value(1) );
1578 if ( !shapes.IsNull() && shapes->Length() > 1 )
1579 AddParam( theParams, "Shape", shapes->Value(2) );
1580 AddParam( theParams, "Shape type", TopAbs_ShapeEnum( aCI.GetSubShapeType() ));
1581 AddParam( theParams, "State", TopAbs_State((int) aCI.GetTolerance() ));
1586 GEOMImpl_IIsoline aII (function);
1588 theOperationName = "ISOLINE";
1589 AddParam(theParams, "Face", aII.GetFace());
1590 AddParam(theParams, "Isoline type", (aII.GetIsUIso() ? "U" : "V"));
1591 AddParam(theParams, "Parameter", aII.GetParameter());
1596 GEOMImpl_IShapeExtend aSE (function);
1598 theOperationName = "EDGE_EXTEND";
1599 AddParam(theParams, "Edge", aSE.GetShape());
1600 AddParam(theParams, "Min", aSE.GetUMin());
1601 AddParam(theParams, "Max", aSE.GetUMax());
1606 GEOMImpl_IShapeExtend aSE (function);
1608 theOperationName = "FACE_EXTEND";
1609 AddParam(theParams, "Face", aSE.GetShape());
1610 AddParam(theParams, "UMin", aSE.GetUMin());
1611 AddParam(theParams, "UMax", aSE.GetUMax());
1612 AddParam(theParams, "VMin", aSE.GetVMin());
1613 AddParam(theParams, "VMax", aSE.GetVMax());
1616 case SURFACE_FROM_FACE:
1618 GEOMImpl_IShapeExtend aSE (function);
1620 theOperationName = "SURFACE_FROM_FACE";
1621 AddParam(theParams, "Face", aSE.GetShape());
1631 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1632 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1634 //modified by NIZNHY-PKV Wed Dec 28 13:48:31 2011f
1635 #include <TopoDS_Iterator.hxx>
1636 #include <TopTools_HSequenceOfShape.hxx>
1637 #include <ShapeAnalysis_FreeBounds.hxx>
1638 #include <TopTools_MapOfShape.hxx>
1639 #include <TopTools_MapOfOrientedShape.hxx>
1640 #include <BRep_Builder.hxx>
1641 #include <TopoDS_Wire.hxx>
1643 //=======================================================================
1644 //function : KeepEdgesOrder
1646 //=======================================================================
1648 void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
1649 const Handle(TopTools_HSequenceOfShape)& aWires)
1651 Standard_Integer aNbWires, aNbEdges;
1653 if (aEdges.IsNull()) {
1657 if (aWires.IsNull()) {
1661 aNbEdges=aEdges->Length();
1662 aNbWires=aWires->Length();
1663 if (!aNbEdges || !aNbWires) {
1667 Standard_Boolean bClosed;
1668 Standard_Integer i, j;
1670 TopoDS_Iterator aIt;
1672 TopTools_MapOfOrientedShape aMEx;
1674 for (i=1; i<=aNbWires; ++i) {
1675 const TopoDS_Shape& aWx=aWires->Value(i);
1678 aIt.Initialize (aWx);
1679 for (; aIt.More(); aIt.Next()) {
1680 const TopoDS_Shape& aEx=aIt.Value();
1685 for (j=1; j<=aNbEdges; ++j) {
1686 const TopoDS_Shape& aE=aEdges->Value(j);
1687 if (aMEx.Contains(aE)) {
1692 bClosed=aWx.Closed();
1693 aWy.Closed(bClosed);
1695 aWires->Append(aWy);
1696 }// for (i=1; i<=aNbWires; ++i) {
1698 aWires->Remove(1, aNbWires);
1701 //modified by NIZNHY-PKV Wed Dec 28 13:48:34 2011t