1 // Copyright (C) 2007-2014 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 //modified by NIZNHY-PKV Wed Dec 28 13:48:20 2011f
103 // void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
104 // const Handle(TopTools_HSequenceOfShape)& aWires);
105 //modified by NIZNHY-PKV Wed Dec 28 13:48:23 2011t
107 //=======================================================================
110 //=======================================================================
111 const Standard_GUID& GEOMImpl_ShapeDriver::GetID()
113 static Standard_GUID aShapeDriver("FF1BBB54-5D14-4df2-980B-3A668264EA16");
118 //=======================================================================
119 //function : GEOMImpl_ShapeDriver
121 //=======================================================================
122 GEOMImpl_ShapeDriver::GEOMImpl_ShapeDriver()
126 //=======================================================================
129 //=======================================================================
130 Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
132 if (Label().IsNull()) return 0;
133 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
135 GEOMImpl_IShapes aCI (aFunction);
136 Standard_Integer aType = aFunction->GetType();
139 TCollection_AsciiString aWarning;
140 TopAbs_ShapeEnum anExpectedType = TopAbs_SHAPE;
144 if (aType == WIRE_EDGES) {
145 anExpectedType = TopAbs_WIRE;
147 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
149 Standard_Real aTolerance = aCI.GetTolerance();
150 if (aTolerance < Precision::Confusion())
151 aTolerance = Precision::Confusion();
153 aShape = MakeWireFromEdges(aShapes, aTolerance);
155 else if (aType == FACE_WIRE) {
156 anExpectedType = TopAbs_FACE;
158 Handle(GEOM_Function) aRefBase = aCI.GetBase();
159 TopoDS_Shape aShapeBase = aRefBase->GetValue();
160 if (aShapeBase.IsNull()) Standard_NullObject::Raise("Argument Shape is null");
162 if (aShapeBase.ShapeType() == TopAbs_WIRE) {
163 W = TopoDS::Wire(aShapeBase);
164 // check the wire is closed
165 TopoDS_Vertex aV1, aV2;
166 TopExp::Vertices(W, aV1, aV2);
167 if ( !aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2) )
168 aShapeBase.Closed(true);
170 Standard_NullObject::Raise
171 ("Shape for face construction is not closed");
173 else if (aShapeBase.ShapeType() == TopAbs_EDGE && aShapeBase.Closed()) {
174 BRepBuilderAPI_MakeWire MW;
175 MW.Add(TopoDS::Edge(aShapeBase));
177 Standard_ConstructionError::Raise("Wire construction failed");
182 Standard_NullObject::Raise
183 ("Shape for face construction is neither a wire nor a closed edge");
185 aWarning = GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), aShape);
186 if (aShape.IsNull()) {
187 Standard_ConstructionError::Raise("Face construction failed");
190 else if (aType == FACE_WIRES) {
191 anExpectedType = TopAbs_FACE;
193 // Try to build a face from a set of wires and edges
196 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
197 int nbshapes = aShapes->Length();
199 Standard_ConstructionError::Raise("No wires or edges given");
202 // 1. Extract all edges from the given arguments
203 TopTools_MapOfShape aMapEdges;
204 Handle(TopTools_HSequenceOfShape) aSeqEdgesIn = new TopTools_HSequenceOfShape;
206 for (ind = 1; ind <= nbshapes; ind++) {
207 Handle(GEOM_Function) aRefSh_i = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
208 TopoDS_Shape aSh_i = aRefSh_i->GetValue();
210 TopExp_Explorer anExpE_i (aSh_i, TopAbs_EDGE);
211 for (; anExpE_i.More(); anExpE_i.Next()) {
212 if (aMapEdges.Add(anExpE_i.Current())) {
213 aSeqEdgesIn->Append(anExpE_i.Current());
218 if (aSeqEdgesIn->IsEmpty()) {
219 Standard_ConstructionError::Raise("No edges given");
222 // 2. Connect edges to wires of maximum length
223 Handle(TopTools_HSequenceOfShape) aSeqWiresOut;
224 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdgesIn, Precision::Confusion(),
225 /*shared*/Standard_False, aSeqWiresOut);
226 //modified by NIZNHY-PKV Wed Dec 28 13:46:55 2011f
227 //KeepEdgesOrder(aSeqEdgesIn, aSeqWiresOut);
228 //modified by NIZNHY-PKV Wed Dec 28 13:46:59 2011t
230 // 3. Separate closed wires
231 Handle(TopTools_HSequenceOfShape) aSeqClosedWires = new TopTools_HSequenceOfShape;
232 Handle(TopTools_HSequenceOfShape) aSeqOpenWires = new TopTools_HSequenceOfShape;
233 for (ind = 1; ind <= aSeqWiresOut->Length(); ind++) {
234 if (aSeqWiresOut->Value(ind).Closed())
235 aSeqClosedWires->Append(aSeqWiresOut->Value(ind));
237 aSeqOpenWires->Append(aSeqWiresOut->Value(ind));
240 if (aSeqClosedWires->Length() < 1) {
241 Standard_ConstructionError::Raise
242 ("There is no closed contour can be built from the given arguments");
245 // 4. Build a face / list of faces from all the obtained closed wires
249 TopoDS_Wire aW1 = TopoDS::Wire(aSeqClosedWires->Value(1));
250 aWarning = GEOMImpl_Block6Explorer::MakeFace(aW1, aCI.GetIsPlanar(), aFFace);
251 if (aFFace.IsNull()) {
252 Standard_ConstructionError::Raise("Face construction failed");
255 // 4.b. Add other wires
256 if (aSeqClosedWires->Length() == 1) {
261 BRep_Builder aBuilder;
262 aBuilder.MakeCompound(C);
263 BRepAlgo_FaceRestrictor FR;
265 TopAbs_Orientation OriF = aFFace.Orientation();
266 TopoDS_Shape aLocalS = aFFace.Oriented(TopAbs_FORWARD);
267 FR.Init(TopoDS::Face(aLocalS), Standard_False, Standard_True);
269 for (ind = 1; ind <= aSeqClosedWires->Length(); ind++) {
270 TopoDS_Wire aW = TopoDS::Wire(aSeqClosedWires->Value(ind));
279 for (; FR.More(); FR.Next()) {
280 aFace = FR.Current().Oriented(OriF);
281 aBuilder.Add(C, aFace);
292 // 5. Add all open wires to the result
293 if (aSeqOpenWires->Length() > 0) {
294 //Standard_ConstructionError::Raise("There are some open wires");
296 BRep_Builder aBuilder;
297 if (aSeqClosedWires->Length() == 1) {
298 aBuilder.MakeCompound(C);
299 aBuilder.Add(C, aShape);
302 C = TopoDS::Compound(aShape);
305 for (ind = 1; ind <= aSeqOpenWires->Length(); ind++) {
306 aBuilder.Add(C, aSeqOpenWires->Value(ind));
312 else if (aType == FACE_FROM_SURFACE) {
313 #ifdef RESULT_TYPE_CHECK
314 anExpectedType = TopAbs_FACE;
317 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
319 if (aShapes.IsNull() == Standard_False) {
320 Standard_Integer aNbShapes = aShapes->Length();
322 if (aNbShapes == 2) {
323 Handle(GEOM_Function) aRefFace =
324 Handle(GEOM_Function)::DownCast(aShapes->Value(1));
325 Handle(GEOM_Function) aRefWire =
326 Handle(GEOM_Function)::DownCast(aShapes->Value(2));
328 if (aRefFace.IsNull() == Standard_False &&
329 aRefWire.IsNull() == Standard_False) {
330 TopoDS_Shape aShFace = aRefFace->GetValue();
331 TopoDS_Shape aShWire = aRefWire->GetValue();
333 if (aShFace.IsNull() == Standard_False &&
334 aShFace.ShapeType() == TopAbs_FACE &&
335 aShWire.IsNull() == Standard_False &&
336 aShWire.ShapeType() == TopAbs_WIRE) {
337 TopoDS_Face aFace = TopoDS::Face(aShFace);
338 TopoDS_Wire aWire = TopoDS::Wire(aShWire);
339 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
340 BRepBuilderAPI_MakeFace aMkFace(aSurf, aWire);
342 if (aMkFace.IsDone()) {
343 aShape = aMkFace.Shape();
350 else if (aType == SHELL_FACES) {
351 anExpectedType = TopAbs_SHELL;
353 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
354 unsigned int ind, nbshapes = aShapes->Length();
357 BRepBuilderAPI_Sewing aSewing (Precision::Confusion()*10.0);
358 for (ind = 1; ind <= nbshapes; ind++) {
359 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
360 TopoDS_Shape aShape_i = aRefShape->GetValue();
361 if (aShape_i.IsNull()) {
362 Standard_NullObject::Raise("Face for shell construction is null");
364 aSewing.Add(aShape_i);
369 TopoDS_Shape sh = aSewing.SewedShape();
371 if (sh.ShapeType()==TopAbs_FACE && nbshapes==1) {
372 // case for creation of shell from one face - PAL12722 (skl 26.06.2006)
379 //TopExp_Explorer exp (aSewing.SewedShape(), TopAbs_SHELL);
380 TopExp_Explorer exp (sh, TopAbs_SHELL);
381 Standard_Integer ish = 0;
382 for (; exp.More(); exp.Next()) {
383 aShape = exp.Current();
388 // try the case of one face (Mantis issue 0021809)
389 TopExp_Explorer expF (sh, TopAbs_FACE);
390 Standard_Integer ifa = 0;
391 for (; expF.More(); expF.Next()) {
392 aShape = expF.Current();
403 aShape = aSewing.SewedShape();
409 else if (aType == SOLID_SHELLS) {
410 anExpectedType = TopAbs_SOLID;
412 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
413 unsigned int ind, nbshapes = aShapes->Length();
414 Standard_Integer ish = 0;
415 BRepBuilderAPI_MakeSolid aMkSolid;
418 for (ind = 1; ind <= nbshapes; ind++) {
419 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
420 TopoDS_Shape aShapeShell = aRefShape->GetValue();
421 if (aShapeShell.IsNull()) {
422 Standard_NullObject::Raise("Shell for solid construction is null");
424 if (aShapeShell.ShapeType() == TopAbs_COMPOUND) {
425 TopoDS_Iterator It (aShapeShell, Standard_True, Standard_True);
426 if (It.More()) aShapeShell = It.Value();
428 if (aShapeShell.ShapeType() == TopAbs_SHELL) {
429 aMkSolid.Add(TopoDS::Shell(aShapeShell));
433 if (ish == 0 || !aMkSolid.IsDone()) return 0;
435 TopoDS_Solid Sol = aMkSolid.Solid();
436 BRepClass3d_SolidClassifier SC (Sol);
437 SC.PerformInfinitePoint(Precision::Confusion());
438 if (SC.State() == TopAbs_IN)
439 aShape = Sol.Reversed();
443 else if (aType == COMPOUND_SHAPES) {
444 anExpectedType = TopAbs_COMPOUND;
446 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
447 unsigned int ind, nbshapes = aShapes->Length();
452 for (ind = 1; ind <= nbshapes; ind++) {
453 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
454 TopoDS_Shape aShape_i = aRefShape->GetValue();
455 if (aShape_i.IsNull()) {
456 Standard_NullObject::Raise("Shape for compound construction is null");
464 else if (aType == EDGE_WIRE) {
465 anExpectedType = TopAbs_EDGE;
467 Handle(GEOM_Function) aRefBase = aCI.GetBase();
468 TopoDS_Shape aWire = aRefBase->GetValue();
469 Standard_Real LinTol = aCI.GetTolerance();
470 Standard_Real AngTol = aCI.GetAngularTolerance();
471 if (aWire.IsNull()) Standard_NullObject::Raise("Argument Wire is null");
473 aShape = MakeEdgeFromWire(aWire, LinTol, AngTol);
475 else if (aType == EDGE_CURVE_LENGTH) {
476 anExpectedType = TopAbs_EDGE;
478 GEOMImpl_IVector aVI (aFunction);
481 Handle(GEOM_Function) aRefCurve = aVI.GetPoint1();
482 if (aRefCurve.IsNull()) Standard_NullObject::Raise("Argument Curve is null");
483 TopoDS_Shape aRefShape1 = aRefCurve->GetValue();
484 if (aRefShape1.ShapeType() != TopAbs_EDGE) {
485 Standard_TypeMismatch::Raise
486 ("Edge On Curve creation aborted : curve shape is not an edge");
488 TopoDS_Edge aRefEdge = TopoDS::Edge(aRefShape1);
489 TopoDS_Vertex V1, V2;
490 TopExp::Vertices(aRefEdge, V1, V2, Standard_True);
493 TopoDS_Vertex aRefVertex;
494 Handle(GEOM_Function) aRefPoint = aVI.GetPoint2();
495 if (aRefPoint.IsNull()) {
499 TopoDS_Shape aRefShape2 = aRefPoint->GetValue();
500 if (aRefShape2.ShapeType() != TopAbs_VERTEX) {
501 Standard_TypeMismatch::Raise
502 ("Edge On Curve creation aborted : start point shape is not a vertex");
504 aRefVertex = TopoDS::Vertex(aRefShape2);
506 gp_Pnt aRefPnt = BRep_Tool::Pnt(aRefVertex);
509 Standard_Real aLength = aVI.GetParameter();
510 //Standard_Real aCurveLength = IntTools::Length(aRefEdge);
511 //if (aLength > aCurveLength) {
512 // Standard_ConstructionError::Raise
513 // ("Edge On Curve creation aborted : given length is greater than edges length");
515 if (fabs(aLength) < Precision::Confusion()) {
516 Standard_ConstructionError::Raise
517 ("Edge On Curve creation aborted : given length is smaller than Precision::Confusion()");
521 Standard_Real UFirst, ULast;
522 Handle(Geom_Curve) EdgeCurve = BRep_Tool::Curve(aRefEdge, UFirst, ULast);
523 Handle(Geom_Curve) ReOrientedCurve = EdgeCurve;
525 Standard_Real dU = ULast - UFirst;
526 Standard_Real par1 = UFirst + 0.1 * dU;
527 Standard_Real par2 = ULast - 0.1 * dU;
529 gp_Pnt P1 = EdgeCurve->Value(par1);
530 gp_Pnt P2 = EdgeCurve->Value(par2);
532 if (aRefPnt.SquareDistance(P2) < aRefPnt.SquareDistance(P1)) {
533 ReOrientedCurve = EdgeCurve->Reversed();
534 UFirst = EdgeCurve->ReversedParameter(ULast);
537 // Get the point by length
538 GeomAdaptor_Curve AdapCurve = GeomAdaptor_Curve(ReOrientedCurve);
539 GCPnts_AbscissaPoint anAbsPnt (AdapCurve, aLength, UFirst);
540 Standard_Real aParam = anAbsPnt.Parameter();
542 if (AdapCurve.IsClosed() && aLength < 0.0) {
543 Standard_Real aTmp = aParam;
548 BRepBuilderAPI_MakeEdge aME (ReOrientedCurve, UFirst, aParam);
550 aShape = aME.Shape();
551 } else if (aType == SHAPE_ISOLINE) {
552 GEOMImpl_IIsoline aII (aFunction);
553 Handle(GEOM_Function) aRefFace = aII.GetFace();
554 TopoDS_Shape aShapeFace = aRefFace->GetValue();
556 if (aShapeFace.ShapeType() == TopAbs_FACE) {
557 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
558 bool isUIso = aII.GetIsUIso();
559 Standard_Real aParam = aII.GetParameter();
560 Standard_Real U1,U2,V1,V2;
562 // Construct a real geometric parameter.
563 aFace.Orientation(TopAbs_FORWARD);
564 ShapeAnalysis::GetFaceUVBounds(aFace,U1,U2,V1,V2);
567 aParam = U1 + (U2 - U1)*aParam;
569 aParam = V1 + (V2 - V1)*aParam;
572 aShape = MakeIsoline(aFace, isUIso, aParam);
574 Standard_NullObject::Raise
575 ("Shape for isoline construction is not a face");
577 } else if (aType == EDGE_UV) {
578 #ifdef RESULT_TYPE_CHECK
579 anExpectedType = TopAbs_EDGE;
581 GEOMImpl_IShapeExtend aSE (aFunction);
582 Handle(GEOM_Function) aRefEdge = aSE.GetShape();
583 TopoDS_Shape aShapeEdge = aRefEdge->GetValue();
585 if (aShapeEdge.ShapeType() == TopAbs_EDGE) {
586 TopoDS_Edge anEdge = TopoDS::Edge(aShapeEdge);
588 aShape = ExtendEdge(anEdge, aSE.GetUMin(), aSE.GetUMax());
590 } else if (aType == FACE_UV) {
591 #ifdef RESULT_TYPE_CHECK
592 anExpectedType = TopAbs_FACE;
595 GEOMImpl_IShapeExtend aSE (aFunction);
596 Handle(GEOM_Function) aRefFace = aSE.GetShape();
597 TopoDS_Shape aShapeFace = aRefFace->GetValue();
599 if (aShapeFace.ShapeType() == TopAbs_FACE) {
600 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
602 aFace.Orientation(TopAbs_FORWARD);
603 aShape = ExtendFace(aFace, aSE.GetUMin(), aSE.GetUMax(),
604 aSE.GetVMin(), aSE.GetVMax());
610 if (aShape.IsNull()) return 0;
612 // Check shape validity
613 BRepCheck_Analyzer ana (aShape, false);
614 if (!ana.IsValid()) {
615 //Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
616 // For Mantis issue 0021772: EDF 2336 GEOM: Non valid face created from two circles
617 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape (aShape);
619 aShape = aSfs->Shape();
622 // Check if the result shape type is compatible with the expected.
623 const TopAbs_ShapeEnum aShType = aShape.ShapeType();
625 if (anExpectedType != TopAbs_SHAPE && anExpectedType != aShType) {
626 Standard_ConstructionError::Raise("Result type check failed");
629 aFunction->SetValue(aShape);
631 log.SetTouched(Label());
633 if (!aWarning.IsEmpty())
634 Standard_Failure::Raise(aWarning.ToCString());
639 TopoDS_Wire GEOMImpl_ShapeDriver::MakeWireFromEdges(const Handle(TColStd_HSequenceOfTransient)& theEdgesFuncs,
640 const Standard_Real theTolerance)
648 for (unsigned int ind = 1; ind <= theEdgesFuncs->Length(); ind++) {
649 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(theEdgesFuncs->Value(ind));
650 TopoDS_Shape aShape_i = aRefShape->GetValue();
651 if (aShape_i.IsNull()) {
652 Standard_NullObject::Raise("Shape for wire construction is null");
654 if (aShape_i.ShapeType() == TopAbs_EDGE || aShape_i.ShapeType() == TopAbs_WIRE) {
655 TopExp_Explorer exp (aShape_i, TopAbs_EDGE);
656 for (; exp.More(); exp.Next())
657 B.Add(aWire, TopoDS::Edge(exp.Current()));
659 Standard_TypeMismatch::Raise
660 ("Shape for wire construction is neither an edge nor a wire");
665 Handle(ShapeFix_Wire) aFW = new ShapeFix_Wire;
669 if (aFW->StatusReorder(ShapeExtend_FAIL1)) {
670 Standard_ConstructionError::Raise("Wire construction failed: several loops detected");
672 else if (aFW->StatusReorder(ShapeExtend_FAIL)) {
673 Standard_ConstructionError::Raise("Wire construction failed");
678 // IMP 0019766: Building a Wire from unconnected edges by introducing a tolerance
679 aFW->ClosedWireMode() = Standard_False;
680 aFW->FixConnected(theTolerance);
681 if (aFW->StatusConnected(ShapeExtend_FAIL)) {
682 Standard_ConstructionError::Raise("Wire construction failed: cannot build connected wire");
685 if (aFW->StatusConnected(ShapeExtend_DONE3)) {
686 // Confused with <prec> but not Analyzer.Precision(), set the same
687 aFW->FixGapsByRangesMode() = Standard_True;
688 if (aFW->FixGaps3d()) {
689 Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
690 Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
691 for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
692 TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
693 aFe->FixVertexTolerance(aEdge);
694 aFe->FixSameParameter(aEdge);
697 else if (aFW->StatusGaps3d(ShapeExtend_FAIL)) {
698 Standard_ConstructionError::Raise("Wire construction failed: cannot fix 3d gaps");
701 aWire = aFW->WireAPIMake();
706 TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
707 const Standard_Real LinTol,
708 const Standard_Real AngTol)
712 BRepLib::BuildCurves3d(aWire);
713 Handle(ShapeFix_Shape) Fixer = new ShapeFix_Shape(aWire);
714 Fixer->SetPrecision(LinTol);
715 Fixer->SetMaxTolerance(LinTol);
717 TopoDS_Wire theWire = TopoDS::Wire(Fixer->Shape());
719 TColGeom_SequenceOfCurve CurveSeq;
720 TopTools_SequenceOfShape LocSeq;
721 TColStd_SequenceOfReal FparSeq;
722 TColStd_SequenceOfReal LparSeq;
723 TColStd_SequenceOfReal TolSeq;
724 GeomAbs_CurveType CurType;
725 TopoDS_Vertex FirstVertex, LastVertex;
726 Standard_Real aPntShiftDist = 0.;
728 BRepTools_WireExplorer wexp(theWire) ;
729 for (; wexp.More(); wexp.Next())
731 TopoDS_Edge anEdge = wexp.Current();
732 Standard_Real fpar, lpar;
733 TopLoc_Location aLoc;
734 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aLoc, fpar, lpar);
738 BRepAdaptor_Curve BAcurve(anEdge);
739 GeomAbs_CurveType aType = BAcurve.GetType();
741 Handle(Geom_Curve) aBasisCurve = BAcurve.Curve().Curve();
743 if (aBasisCurve->IsPeriodic())
744 ElCLib::AdjustPeriodic(aBasisCurve->FirstParameter(), aBasisCurve->LastParameter(),
745 Precision::PConfusion(), fpar, lpar);
747 if (CurveSeq.IsEmpty())
749 CurveSeq.Append(aCurve);
750 TopoDS_Shape aLocShape;
751 aLocShape.Location(aLoc);
752 aLocShape.Orientation(wexp.Orientation());
753 LocSeq.Append(aLocShape);
754 FparSeq.Append(fpar);
755 LparSeq.Append(lpar);
757 FirstVertex = wexp.CurrentVertex();
761 Standard_Boolean Done = Standard_False;
762 Standard_Real NewFpar, NewLpar;
763 GeomAdaptor_Curve GAprevcurve(CurveSeq.Last());
764 TopoDS_Vertex CurVertex = wexp.CurrentVertex();
765 TopoDS_Vertex CurFirstVer = TopExp::FirstVertex(anEdge);
766 TopAbs_Orientation ConnectByOrigin = (CurVertex.IsSame(CurFirstVer))? TopAbs_FORWARD : TopAbs_REVERSED;
767 if (aCurve == CurveSeq.Last())
771 if (aBasisCurve->IsPeriodic())
773 if (NewLpar < NewFpar)
774 NewLpar += aBasisCurve->Period();
775 if (ConnectByOrigin == TopAbs_FORWARD)
776 ElCLib::AdjustPeriodic(FparSeq.Last(),
777 FparSeq.Last() + aBasisCurve->Period(),
778 Precision::PConfusion(), NewFpar, NewLpar);
780 ElCLib::AdjustPeriodic(FparSeq.Last() - aBasisCurve->Period(),
782 Precision::PConfusion(), NewFpar, NewLpar);
784 Done = Standard_True;
786 else if (aType == CurType &&
787 aType != GeomAbs_BezierCurve &&
788 aType != GeomAbs_BSplineCurve &&
789 aType != GeomAbs_OtherCurve)
795 gp_Lin aLine = BAcurve.Line();
796 gp_Lin PrevLine = GAprevcurve.Line();
797 if (aLine.Contains(PrevLine.Location(), LinTol) &&
798 aLine.Direction().IsParallel(PrevLine.Direction(), AngTol))
800 gp_Pnt P1 = ElCLib::Value(fpar, aLine);
801 gp_Pnt P2 = ElCLib::Value(lpar, aLine);
802 NewFpar = ElCLib::Parameter(PrevLine, P1);
803 NewLpar = ElCLib::Parameter(PrevLine, P2);
806 if (ConnectByOrigin == TopAbs_FORWARD) {
807 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevLine);
809 aPntShiftDist += P2.Distance(aNewP2);
811 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevLine);
813 aPntShiftDist += P1.Distance(aNewP1);
816 if (NewLpar < NewFpar)
818 Standard_Real MemNewFpar = NewFpar;
820 NewLpar = MemNewFpar;
821 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
823 Done = Standard_True;
829 gp_Circ aCircle = BAcurve.Circle();
830 gp_Circ PrevCircle = GAprevcurve.Circle();
831 if (aCircle.Location().Distance(PrevCircle.Location()) <= LinTol &&
832 Abs(aCircle.Radius() - PrevCircle.Radius()) <= LinTol &&
833 aCircle.Axis().IsParallel(PrevCircle.Axis(), AngTol))
835 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
837 if (aCircle.Axis().Direction() * PrevCircle.Axis().Direction() < 0.)
839 Standard_Real memfpar = fpar;
842 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
844 gp_Pnt P1 = ElCLib::Value(fpar, aCircle);
845 gp_Pnt P2 = ElCLib::Value(lpar, aCircle);
846 NewFpar = ElCLib::Parameter(PrevCircle, P1);
847 NewLpar = ElCLib::Parameter(PrevCircle, P2);
851 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevCircle);
853 aPntShiftDist += P2.Distance(aNewP2);
855 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevCircle);
857 aPntShiftDist += P1.Distance(aNewP1);
860 if (NewLpar < NewFpar)
862 //Standard_Real MemNewFpar = NewFpar, MemNewLpar = NewLpar;
863 if (ConnectByOrigin == TopAbs_FORWARD)
864 ElCLib::AdjustPeriodic(FparSeq.Last(),
865 FparSeq.Last() + 2.*M_PI,
866 Precision::PConfusion(), NewFpar, NewLpar);
868 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
870 Precision::PConfusion(), NewFpar, NewLpar);
871 Done = Standard_True;
875 case GeomAbs_Ellipse:
877 gp_Elips anEllipse = BAcurve.Ellipse();
878 gp_Elips PrevEllipse = GAprevcurve.Ellipse();
879 if (anEllipse.Focus1().Distance(PrevEllipse.Focus1()) <= LinTol &&
880 anEllipse.Focus2().Distance(PrevEllipse.Focus2()) <= LinTol &&
881 Abs(anEllipse.MajorRadius() - PrevEllipse.MajorRadius()) <= LinTol &&
882 Abs(anEllipse.MinorRadius() - PrevEllipse.MinorRadius()) <= LinTol &&
883 anEllipse.Axis().IsParallel(PrevEllipse.Axis(), AngTol))
885 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
887 if (anEllipse.Axis().Direction() * PrevEllipse.Axis().Direction() < 0.)
889 Standard_Real memfpar = fpar;
892 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
894 gp_Pnt P1 = ElCLib::Value(fpar, anEllipse);
895 gp_Pnt P2 = ElCLib::Value(lpar, anEllipse);
896 NewFpar = ElCLib::Parameter(PrevEllipse, P1);
897 NewLpar = ElCLib::Parameter(PrevEllipse, P2);
901 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevEllipse);
903 aPntShiftDist += P2.Distance(aNewP2);
905 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevEllipse);
907 aPntShiftDist += P1.Distance(aNewP1);
910 if (NewLpar < NewFpar)
912 if (ConnectByOrigin == TopAbs_FORWARD)
913 ElCLib::AdjustPeriodic(FparSeq.Last(),
914 FparSeq.Last() + 2.*M_PI,
915 Precision::PConfusion(), NewFpar, NewLpar);
917 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
919 Precision::PConfusion(), NewFpar, NewLpar);
920 Done = Standard_True;
924 case GeomAbs_Hyperbola:
926 gp_Hypr aHypr = BAcurve.Hyperbola();
927 gp_Hypr PrevHypr = GAprevcurve.Hyperbola();
928 if (aHypr.Focus1().Distance(PrevHypr.Focus1()) <= LinTol &&
929 aHypr.Focus2().Distance(PrevHypr.Focus2()) <= LinTol &&
930 Abs(aHypr.MajorRadius() - PrevHypr.MajorRadius()) <= LinTol &&
931 Abs(aHypr.MinorRadius() - PrevHypr.MinorRadius()) <= LinTol &&
932 aHypr.Axis().IsParallel(PrevHypr.Axis(), AngTol))
934 gp_Pnt P1 = ElCLib::Value(fpar, aHypr);
935 gp_Pnt P2 = ElCLib::Value(lpar, aHypr);
936 NewFpar = ElCLib::Parameter(PrevHypr, P1);
937 NewLpar = ElCLib::Parameter(PrevHypr, P2);
940 if (ConnectByOrigin == TopAbs_FORWARD) {
941 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevHypr);
943 aPntShiftDist += P2.Distance(aNewP2);
945 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevHypr);
947 aPntShiftDist += P1.Distance(aNewP1);
950 if (NewLpar < NewFpar)
952 Standard_Real MemNewFpar = NewFpar;
954 NewLpar = MemNewFpar;
955 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
957 Done = Standard_True;
961 case GeomAbs_Parabola:
963 gp_Parab aParab = BAcurve.Parabola();
964 gp_Parab PrevParab = GAprevcurve.Parabola();
965 if (aParab.Location().Distance(PrevParab.Location()) <= LinTol &&
966 aParab.Focus().Distance(PrevParab.Focus()) <= LinTol &&
967 Abs(aParab.Focal() - PrevParab.Focal()) <= LinTol &&
968 aParab.Axis().IsParallel(PrevParab.Axis(), AngTol))
970 gp_Pnt P1 = ElCLib::Value(fpar, aParab);
971 gp_Pnt P2 = ElCLib::Value(lpar, aParab);
972 NewFpar = ElCLib::Parameter(PrevParab, P1);
973 NewLpar = ElCLib::Parameter(PrevParab, P2);
976 if (ConnectByOrigin == TopAbs_FORWARD) {
977 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevParab);
979 aPntShiftDist += P2.Distance(aNewP2);
981 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevParab);
983 aPntShiftDist += P1.Distance(aNewP1);
986 if (NewLpar < NewFpar)
988 Standard_Real MemNewFpar = NewFpar;
990 NewLpar = MemNewFpar;
991 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
993 Done = Standard_True;
997 } //end of switch (aType)
998 } // end of else if (aType == CurType && ...
1001 if (NewFpar < FparSeq.Last())
1002 FparSeq(FparSeq.Length()) = NewFpar;
1004 LparSeq(LparSeq.Length()) = NewLpar;
1008 CurveSeq.Append(aCurve);
1009 TopoDS_Shape aLocShape;
1010 aLocShape.Location(aLoc);
1011 aLocShape.Orientation(wexp.Orientation());
1012 LocSeq.Append(aLocShape);
1013 FparSeq.Append(fpar);
1014 LparSeq.Append(lpar);
1015 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(CurVertex));
1019 } // end of else (CurveSeq.IsEmpty()) -> not first time
1020 } // end for (; wexp.More(); wexp.Next())
1022 LastVertex = wexp.CurrentVertex();
1023 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(LastVertex));
1025 FirstVertex.Orientation(TopAbs_FORWARD);
1026 LastVertex.Orientation(TopAbs_REVERSED);
1028 if (!CurveSeq.IsEmpty())
1030 Standard_Integer nb_curve = CurveSeq.Length(); //number of curves
1031 TColGeom_Array1OfBSplineCurve tab(0,nb_curve-1); //array of the curves
1032 TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2); //array of the tolerances
1038 for (i = 1; i <= nb_curve; i++)
1040 if (CurveSeq(i)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1041 CurveSeq(i) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(i))))->BasisCurve();
1043 Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(CurveSeq(i), FparSeq(i), LparSeq(i));
1044 tab(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve);
1045 tab(i-1)->Transform(LocSeq(i).Location().Transformation());
1046 GeomConvert::C0BSplineToC1BSplineCurve(tab(i-1), Precision::Confusion());
1047 if (LocSeq(i).Orientation() == TopAbs_REVERSED)
1048 tab(i-1)->Reverse();
1051 //char* name = new char[100];
1052 //sprintf(name, "c%d", i);
1053 //DrawTrSurf::Set(name, tab(i-1));
1056 tabtolvertex(i-2) = TolSeq(i-1);
1057 } // end for (i = 1; i <= nb_curve; i++)
1058 tabtolvertex(nb_curve-1) = TolSeq(TolSeq.Length());
1060 Standard_Boolean closed_flag = Standard_False;
1061 Standard_Real closed_tolerance = 0.;
1062 if (FirstVertex.IsSame(LastVertex) &&
1063 GeomLProp::Continuity(tab(0), tab(nb_curve-1),
1064 tab(0)->FirstParameter(),
1065 tab(nb_curve-1)->LastParameter(),
1066 Standard_False, Standard_False, LinTol, AngTol) >= GeomAbs_G1)
1068 closed_flag = Standard_True ;
1069 closed_tolerance = BRep_Tool::Tolerance(FirstVertex);
1072 Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves
1073 Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex
1074 GeomConvert::ConcatC1(tab,
1079 closed_tolerance); //C1 concatenation
1081 if (concatcurve->Length() > 1)
1083 GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower()));
1085 for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++)
1086 Concat.Add( concatcurve->Value(i), LinTol, Standard_True );
1088 concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve());
1090 // rnc : prevents the driver from building an edge without C1 continuity
1091 if (concatcurve->Value(concatcurve->Lower())->Continuity()==GeomAbs_C0){
1092 Standard_ConstructionError::Raise("Construction aborted : The given Wire has sharp bends between some Edges, no valid Edge can be built");
1095 Standard_Boolean isValidEndVtx = Standard_True;
1098 // Check if closed curve is reordered.
1099 Handle(Geom_Curve) aCurve = concatcurve->Value(concatcurve->Lower());
1100 Standard_Real aFPar = aCurve->FirstParameter();
1102 gp_Pnt aPntVtx = BRep_Tool::Pnt(FirstVertex);
1103 Standard_Real aTolVtx = BRep_Tool::Tolerance(FirstVertex);
1105 aCurve->D0(aFPar, aPFirst);
1107 if (!aPFirst.IsEqual(aPntVtx, aTolVtx)) {
1108 // The curve is reordered. Find the new first and last vertices.
1109 TopTools_IndexedMapOfShape aMapVtx;
1110 TopExp::MapShapes(theWire, TopAbs_VERTEX, aMapVtx);
1112 const Standard_Integer aNbVtx = aMapVtx.Extent();
1113 Standard_Integer iVtx;
1115 for (iVtx = 1; iVtx <= aNbVtx; iVtx++) {
1116 const TopoDS_Vertex aVtx = TopoDS::Vertex(aMapVtx.FindKey(iVtx));
1117 const gp_Pnt aPnt = BRep_Tool::Pnt(aVtx);
1118 const Standard_Real aTol = BRep_Tool::Tolerance(aVtx);
1120 if (aPFirst.IsEqual(aPnt, aTol)) {
1121 // The coinsident vertex is found.
1124 FirstVertex.Orientation(TopAbs_FORWARD);
1125 LastVertex.Orientation(TopAbs_REVERSED);
1130 if (iVtx > aNbVtx) {
1131 // It is necessary to create new vertices.
1132 isValidEndVtx = Standard_False;
1137 if (isValidEndVtx) {
1138 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1139 FirstVertex, LastVertex,
1140 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1141 concatcurve->Value(concatcurve->Lower())->LastParameter());
1143 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1144 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1145 concatcurve->Value(concatcurve->Lower())->LastParameter());
1150 if (CurveSeq(1)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1151 CurveSeq(1) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(1))))->BasisCurve();
1153 Handle(Geom_Curve) aNewCurve =
1154 Handle(Geom_Curve)::DownCast(CurveSeq(1)->Copy());
1156 aNewCurve->Transform(LocSeq(1).Location().Transformation());
1158 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1159 const TopoDS_Vertex aVtxTmp = FirstVertex;
1161 FirstVertex = LastVertex;
1162 LastVertex = aVtxTmp;
1163 FirstVertex.Orientation(TopAbs_FORWARD);
1164 LastVertex.Orientation(TopAbs_REVERSED);
1167 ResEdge = BRepLib_MakeEdge(aNewCurve,
1168 FirstVertex, LastVertex,
1169 FparSeq(1), LparSeq(1));
1171 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1180 //=============================================================================
1182 * \brief Returns an isoline for a face.
1184 //=============================================================================
1186 TopoDS_Shape GEOMImpl_ShapeDriver::MakeIsoline
1187 (const TopoDS_Face &theFace,
1189 const double theParameter) const
1191 TopoDS_Shape aResult;
1192 GEOMUtils::Hatcher aHatcher(theFace);
1193 const GeomAbs_IsoType aType = (IsUIso ? GeomAbs_IsoU : GeomAbs_IsoV);
1195 aHatcher.Init(aType, theParameter);
1198 if (!aHatcher.IsDone()) {
1199 Standard_ConstructionError::Raise("MakeIsoline : Hatcher failure");
1202 const Handle(TColStd_HArray1OfInteger) &anIndices =
1203 (IsUIso ? aHatcher.GetUIndices() : aHatcher.GetVIndices());
1205 if (anIndices.IsNull()) {
1206 Standard_ConstructionError::Raise("MakeIsoline : Null hatching indices");
1209 const Standard_Integer anIsoInd = anIndices->Lower();
1210 const Standard_Integer aHatchingIndex = anIndices->Value(anIsoInd);
1212 if (aHatchingIndex == 0) {
1213 Standard_ConstructionError::Raise("MakeIsoline : Invalid hatching index");
1216 const Standard_Integer aNbDomains =
1217 aHatcher.GetNbDomains(aHatchingIndex);
1219 if (aNbDomains < 0) {
1220 Standard_ConstructionError::Raise("MakeIsoline : Invalid number of domains");
1223 // The hatching is performed successfully. Create the 3d Curve.
1224 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1225 Handle(Geom_Curve) anIsoCurve = (IsUIso ?
1226 aSurface->UIso(theParameter) : aSurface->VIso(theParameter));
1227 Handle(Geom2d_Curve) aPIsoCurve =
1228 aHatcher.GetHatching(aHatchingIndex);
1229 const Standard_Real aTol = Precision::Confusion();
1230 Standard_Integer anIDom = 1;
1233 BRep_Builder aBuilder;
1234 Standard_Integer aNbEdges = 0;
1236 for (; anIDom <= aNbDomains; anIDom++) {
1237 if (aHatcher.GetDomain(aHatchingIndex, anIDom, aV1, aV2)) {
1238 // Check first and last parameters.
1239 if (!aHatcher.IsDomainInfinite(aHatchingIndex, anIDom)) {
1241 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(anIsoCurve, aV1, aV2);
1243 // Update it with a parametric curve on face.
1244 aBuilder.UpdateEdge(anEdge, aPIsoCurve, theFace, aTol);
1248 // Result is a compond.
1249 if (aNbEdges == 2) {
1250 // Create a new compound.
1251 TopoDS_Compound aCompound;
1253 aBuilder.MakeCompound(aCompound);
1254 aBuilder.Add(aCompound, aResult);
1255 aResult = aCompound;
1258 // Add an edge to the compound.
1259 aBuilder.Add(aResult, anEdge);
1261 // Result is the edge.
1268 if (aNbEdges == 0) {
1269 Standard_ConstructionError::Raise("MakeIsoline : Empty result");
1275 //=============================================================================
1277 * \brief Returns an extended edge.
1279 //=============================================================================
1281 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendEdge
1282 (const TopoDS_Edge &theEdge,
1283 const Standard_Real theMin,
1284 const Standard_Real theMax) const
1286 TopoDS_Shape aResult;
1289 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(theEdge, aF, aL);
1290 const Standard_Real aTol = BRep_Tool::Tolerance(theEdge);
1291 Standard_Real aRange2d = aL - aF;
1293 if (aCurve.IsNull() == Standard_False && aRange2d > aTol) {
1294 Standard_Real aMin = aF + aRange2d*theMin;
1295 Standard_Real aMax = aF + aRange2d*theMax;
1297 Handle(Standard_Type) aType = aCurve->DynamicType();
1299 // Get the curve of original type
1300 while (aType == STANDARD_TYPE(Geom_TrimmedCurve)) {
1301 Handle(Geom_TrimmedCurve) aTrCurve =
1302 Handle(Geom_TrimmedCurve)::DownCast(aCurve);
1304 aCurve = aTrCurve->BasisCurve();
1305 aType = aCurve->DynamicType();
1308 if (aCurve->IsPeriodic()) {
1309 // The curve is periodic. Check if a new range is less then a period.
1310 if (aMax - aMin > aCurve->Period()) {
1311 aMax = aMin + aCurve->Period();
1314 // The curve is not periodic. Check if aMin and aMax within bounds.
1315 aMin = Max(aMin, aCurve->FirstParameter());
1316 aMax = Min(aMax, aCurve->LastParameter());
1319 if (aMax - aMin > aTol) {
1320 // Create a new edge.
1321 BRepBuilderAPI_MakeEdge aME (aCurve, aMin, aMax);
1324 aResult = aME.Shape();
1332 //=============================================================================
1334 * \brief Returns an extended face.
1336 //=============================================================================
1338 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendFace
1339 (const TopoDS_Face &theFace,
1340 const Standard_Real theUMin,
1341 const Standard_Real theUMax,
1342 const Standard_Real theVMin,
1343 const Standard_Real theVMax) const
1345 TopoDS_Shape aResult;
1346 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1347 const Standard_Real aTol = BRep_Tool::Tolerance(theFace);
1353 // Get U, V bounds of the face.
1354 ShapeAnalysis::GetFaceUVBounds(theFace, aU1, aU2, aV1, aV2);
1356 const Standard_Real aURange = aU2 - aU1;
1357 const Standard_Real aVRange = aV2 - aV1;
1359 if (aSurface.IsNull() == Standard_False &&
1360 aURange > aTol && aURange > aTol) {
1361 Handle(Standard_Type) aType = aSurface->DynamicType();
1363 // Get the surface of original type
1364 while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1365 Handle(Geom_RectangularTrimmedSurface) aTrSurface =
1366 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
1368 aSurface = aTrSurface->BasisSurface();
1369 aType = aSurface->DynamicType();
1372 Standard_Real aUMin = aU1 + aURange*theUMin;
1373 Standard_Real aUMax = aU1 + aURange*theUMax;
1374 Standard_Real aVMin = aV1 + aVRange*theVMin;
1375 Standard_Real aVMax = aV1 + aVRange*theVMax;
1377 aSurface->Bounds(aU1, aU2, aV1, aV2);
1379 if (aSurface->IsUPeriodic()) {
1380 // The surface is U-periodic. Check if a new U range is less
1382 if (aUMax - aUMin > aSurface->UPeriod()) {
1383 aUMax = aUMin + aSurface->UPeriod();
1386 // The surface is not V-periodic. Check if aUMin and aUMax
1388 aUMin = Max(aUMin, aU1);
1389 aUMax = Min(aUMax, aU2);
1392 if (aSurface->IsVPeriodic()) {
1393 // The surface is V-periodic. Check if a new V range is less
1395 if (aVMax - aVMin > aSurface->VPeriod()) {
1396 aVMax = aVMin + aSurface->VPeriod();
1399 // The surface is not V-periodic. Check if aVMin and aVMax
1401 aVMin = Max(aVMin, aV1);
1402 aVMax = Min(aVMax, aV2);
1405 if (aUMax - aUMin > aTol && aVMax - aVMin > aTol) {
1406 // Create a new edge.
1407 BRepBuilderAPI_MakeFace aMF
1408 (aSurface, aUMin, aUMax, aVMin, aVMax, aTol);
1411 aResult = aMF.Shape();
1419 //================================================================================
1421 * \brief Returns a name of creation operation and names and values of creation parameters
1423 //================================================================================
1425 bool GEOMImpl_ShapeDriver::
1426 GetCreationInformation(std::string& theOperationName,
1427 std::vector<GEOM_Param>& theParams)
1429 if (Label().IsNull()) return 0;
1430 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
1432 GEOMImpl_IShapes aCI( function );
1433 Standard_Integer aType = function->GetType();
1437 theOperationName = "WIRE";
1438 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1439 AddParam( theParams, "Tolerance", aCI.GetTolerance() );
1442 theOperationName = "FACE";
1443 AddParam( theParams, "Wire/edge", aCI.GetBase() );
1444 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1447 theOperationName = "FACE";
1448 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1449 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1451 case FACE_FROM_SURFACE:
1453 theOperationName = "FACE";
1455 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1457 if (shapes.IsNull() == Standard_False) {
1458 Standard_Integer aNbShapes = shapes->Length();
1460 if (aNbShapes > 0) {
1461 AddParam(theParams, "Face", shapes->Value(1));
1463 if (aNbShapes > 1) {
1464 AddParam(theParams, "Wire", shapes->Value(2));
1471 theOperationName = "SHELL";
1472 AddParam( theParams, "Objects", aCI.GetShapes() );
1475 theOperationName = "SOLID";
1476 AddParam( theParams, "Objects", aCI.GetShapes() );
1478 case COMPOUND_SHAPES:
1479 theOperationName = "COMPOUND";
1480 AddParam( theParams, "Objects", aCI.GetShapes() );
1483 theOperationName = "EDGE";
1484 AddParam( theParams, "Wire", aCI.GetBase() );
1485 AddParam( theParams, "Linear Tolerance", aCI.GetTolerance() );
1486 AddParam( theParams, "Angular Tolerance", aCI.GetAngularTolerance() );
1488 case EDGE_CURVE_LENGTH:
1489 theOperationName = "EDGE";
1491 GEOMImpl_IVector aCI( function );
1492 AddParam( theParams, "Edge", aCI.GetPoint1() );
1493 AddParam( theParams, "Start point", aCI.GetPoint2() );
1494 AddParam( theParams, "Length", aCI.GetParameter() );
1497 case SHAPES_ON_SHAPE:
1499 theOperationName = "GetShapesOnShapeAsCompound";
1500 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1501 if ( !shapes.IsNull() && shapes->Length() > 0 )
1502 AddParam( theParams, "Check shape", shapes->Value(1) );
1503 if ( !shapes.IsNull() && shapes->Length() > 1 )
1504 AddParam( theParams, "Shape", shapes->Value(2) );
1505 AddParam( theParams, "Shape type", TopAbs_ShapeEnum( aCI.GetSubShapeType() ));
1506 AddParam( theParams, "State", TopAbs_State((int) aCI.GetTolerance() ));
1511 GEOMImpl_IIsoline aII (function);
1513 theOperationName = "ISOLINE";
1514 AddParam(theParams, "Face", aII.GetFace());
1515 AddParam(theParams, "Isoline type", (aII.GetIsUIso() ? "U" : "V"));
1516 AddParam(theParams, "Parameter", aII.GetParameter());
1521 GEOMImpl_IShapeExtend aSE (function);
1523 theOperationName = "EDGE_EXTEND";
1524 AddParam(theParams, "Edge", aSE.GetShape());
1525 AddParam(theParams, "Min", aSE.GetUMin());
1526 AddParam(theParams, "Max", aSE.GetUMax());
1531 GEOMImpl_IShapeExtend aSE (function);
1533 theOperationName = "FACE_EXTEND";
1534 AddParam(theParams, "Face", aSE.GetShape());
1535 AddParam(theParams, "UMin", aSE.GetUMin());
1536 AddParam(theParams, "UMax", aSE.GetUMax());
1537 AddParam(theParams, "VMin", aSE.GetVMin());
1538 AddParam(theParams, "VMax", aSE.GetVMax());
1548 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1549 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1551 //modified by NIZNHY-PKV Wed Dec 28 13:48:31 2011f
1552 #include <TopoDS_Iterator.hxx>
1553 #include <TopTools_HSequenceOfShape.hxx>
1554 #include <ShapeAnalysis_FreeBounds.hxx>
1555 #include <TopTools_MapOfShape.hxx>
1556 #include <TopTools_MapOfOrientedShape.hxx>
1557 #include <BRep_Builder.hxx>
1558 #include <TopoDS_Wire.hxx>
1560 //=======================================================================
1561 //function : KeepEdgesOrder
1563 //=======================================================================
1565 void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
1566 const Handle(TopTools_HSequenceOfShape)& aWires)
1568 Standard_Integer aNbWires, aNbEdges;
1570 if (aEdges.IsNull()) {
1574 if (aWires.IsNull()) {
1578 aNbEdges=aEdges->Length();
1579 aNbWires=aWires->Length();
1580 if (!aNbEdges || !aNbWires) {
1584 Standard_Boolean bClosed;
1585 Standard_Integer i, j;
1587 TopoDS_Iterator aIt;
1589 TopTools_MapOfOrientedShape aMEx;
1591 for (i=1; i<=aNbWires; ++i) {
1592 const TopoDS_Shape& aWx=aWires->Value(i);
1595 aIt.Initialize (aWx);
1596 for (; aIt.More(); aIt.Next()) {
1597 const TopoDS_Shape& aEx=aIt.Value();
1602 for (j=1; j<=aNbEdges; ++j) {
1603 const TopoDS_Shape& aE=aEdges->Value(j);
1604 if (aMEx.Contains(aE)) {
1609 bClosed=aWx.Closed();
1610 aWy.Closed(bClosed);
1612 aWires->Append(aWy);
1613 }// for (i=1; i<=aNbWires; ++i) {
1615 aWires->Remove(1, aNbWires);
1618 //modified by NIZNHY-PKV Wed Dec 28 13:48:34 2011t