1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <GEOMImpl_ShapeDriver.hxx>
25 #include <GEOMImpl_IIsoline.hxx>
26 #include <GEOMImpl_IShapes.hxx>
27 #include <GEOMImpl_IShapeExtend.hxx>
28 #include <GEOMImpl_IVector.hxx>
29 #include <GEOMImpl_Types.hxx>
30 #include <GEOMImpl_Block6Explorer.hxx>
32 #include <GEOM_Function.hxx>
33 #include <GEOMUtils_Hatcher.hxx>
34 #include <GEOMAlgo_State.hxx>
37 #include <ShapeFix_Wire.hxx>
38 #include <ShapeFix_Edge.hxx>
39 #include <ShapeFix_Shape.hxx>
41 #include <BRep_Builder.hxx>
42 #include <BRep_Tool.hxx>
43 #include <BRepAdaptor_Curve.hxx>
44 #include <BRepAlgo_FaceRestrictor.hxx>
45 #include <BRepBuilderAPI_Copy.hxx>
46 #include <BRepBuilderAPI_Sewing.hxx>
47 #include <BRepBuilderAPI_MakeFace.hxx>
48 #include <BRepBuilderAPI_MakeWire.hxx>
49 #include <BRepBuilderAPI_MakeEdge.hxx>
50 #include <BRepBuilderAPI_MakeSolid.hxx>
51 #include <BRepCheck.hxx>
52 #include <BRepCheck_Analyzer.hxx>
53 #include <BRepCheck_Shell.hxx>
54 #include <BRepClass3d_SolidClassifier.hxx>
55 #include <BRepLib.hxx>
56 #include <BRepLib_MakeEdge.hxx>
57 #include <BRepTools_WireExplorer.hxx>
59 #include <ShapeAnalysis.hxx>
60 #include <ShapeAnalysis_FreeBounds.hxx>
62 #include <TNaming_CopyShape.hxx>
66 #include <TopExp_Explorer.hxx>
68 #include <TopoDS_Shape.hxx>
69 #include <TopoDS_Edge.hxx>
70 #include <TopoDS_Wire.hxx>
71 #include <TopoDS_Shell.hxx>
72 #include <TopoDS_Solid.hxx>
73 #include <TopoDS_Compound.hxx>
74 #include <TopoDS_Iterator.hxx>
76 #include <TopTools_MapOfShape.hxx>
77 #include <TopTools_HSequenceOfShape.hxx>
81 #include <GCPnts_AbscissaPoint.hxx>
83 #include <Geom_TrimmedCurve.hxx>
84 #include <Geom_RectangularTrimmedSurface.hxx>
85 #include <Geom_Surface.hxx>
86 #include <GeomAbs_CurveType.hxx>
87 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
88 #include <GeomConvert.hxx>
89 #include <GeomLProp.hxx>
91 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
92 #include <TColStd_SequenceOfReal.hxx>
93 #include <TColStd_HSequenceOfTransient.hxx>
94 #include <TColStd_Array1OfReal.hxx>
95 #include <TColGeom_SequenceOfCurve.hxx>
96 #include <TColGeom_Array1OfBSplineCurve.hxx>
97 #include <TColGeom_HArray1OfBSplineCurve.hxx>
99 #include <Precision.hxx>
101 #include <Standard_NullObject.hxx>
102 #include <Standard_TypeMismatch.hxx>
103 #include <Standard_ConstructionError.hxx>
105 #include <BOPAlgo_PaveFiller.hxx>
106 #include <BOPAlgo_MakerVolume.hxx>
112 // check that compound includes only shapes of expected type
113 bool checkCompound( TopoDS_Shape& c, TopAbs_ShapeEnum t )
115 TopoDS_Iterator it( c, Standard_True, Standard_True );
117 // empty compound is OK only if we explicitly create a compound of shapes
120 // => if expected type is TopAbs_SHAPE, we allow compound consisting of any shapes, this above check is enough
121 // => otherwise we have to check compound's content
122 // => compound sometimes can contain enclosed compound(s), we process them recursively and rebuild initial compound
124 if ( t != TopAbs_SHAPE ) {
126 std::list<TopoDS_Shape> compounds, shapes;
127 compounds.push_back( c );
128 while ( !compounds.empty() && result ) {
129 // check that compound contains only shapes of expected type
130 TopoDS_Shape cc = compounds.front();
131 compounds.pop_front();
132 it.Initialize( cc, Standard_True, Standard_True );
133 for ( ; it.More() && result; it.Next() ) {
134 TopAbs_ShapeEnum tt = it.Value().ShapeType();
135 if ( tt == TopAbs_COMPOUND || tt == TopAbs_COMPSOLID ) {
136 compounds.push_back( it.Value() );
139 shapes.push_back( it.Value() );
144 if ( shapes.empty() ) {
147 else if ( shapes.size() == 1 ) {
152 TopoDS_Compound newc;
153 b.MakeCompound( newc );
154 std::list<TopoDS_Shape> ::const_iterator sit;
155 for ( sit = shapes.begin(); sit != shapes.end(); ++sit )
166 //modified by NIZNHY-PKV Wed Dec 28 13:48:20 2011f
168 // void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
169 // const Handle(TopTools_HSequenceOfShape)& aWires);
170 //modified by NIZNHY-PKV Wed Dec 28 13:48:23 2011t
172 //=======================================================================
175 //=======================================================================
176 const Standard_GUID& GEOMImpl_ShapeDriver::GetID()
178 static Standard_GUID aShapeDriver("FF1BBB54-5D14-4df2-980B-3A668264EA16");
183 //=======================================================================
184 //function : GEOMImpl_ShapeDriver
186 //=======================================================================
187 GEOMImpl_ShapeDriver::GEOMImpl_ShapeDriver()
191 //=======================================================================
194 //=======================================================================
195 Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
197 if (Label().IsNull()) return 0;
198 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
200 GEOMImpl_IShapes aCI (aFunction);
201 Standard_Integer aType = aFunction->GetType();
204 TCollection_AsciiString aWarning;
206 // this is an exact type of expected shape, or shape in a compound if compound is allowed as a result (see below)
207 TopAbs_ShapeEnum anExpectedType = TopAbs_SHAPE;
208 // this should be true if result can be a compound of shapes of strict type (see above)
209 bool allowCompound = false;
213 if (aType == WIRE_EDGES) {
214 // result may be only a single wire
215 anExpectedType = TopAbs_WIRE;
217 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
219 Standard_Real aTolerance = aCI.GetTolerance();
220 if (aTolerance < Precision::Confusion())
221 aTolerance = Precision::Confusion();
223 aShape = MakeWireFromEdges(aShapes, aTolerance);
225 else if (aType == FACE_WIRE) {
226 // result may be a face or a compound of faces
227 anExpectedType = TopAbs_FACE;
228 allowCompound = true;
230 Handle(GEOM_Function) aRefBase = aCI.GetBase();
231 TopoDS_Shape aShapeBase = aRefBase->GetValue();
232 if (aShapeBase.IsNull()) Standard_NullObject::Raise("Argument Shape is null");
234 if (aShapeBase.ShapeType() == TopAbs_WIRE) {
235 W = TopoDS::Wire(aShapeBase);
236 // check the wire is closed
237 TopoDS_Vertex aV1, aV2;
238 TopExp::Vertices(W, aV1, aV2);
239 if ( !aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2) )
240 aShapeBase.Closed(true);
242 Standard_NullObject::Raise
243 ("Shape for face construction is not closed");
245 else if (aShapeBase.ShapeType() == TopAbs_EDGE && BRep_Tool::IsClosed(aShapeBase)) {
246 BRepBuilderAPI_MakeWire MW;
247 MW.Add(TopoDS::Edge(aShapeBase));
249 Standard_ConstructionError::Raise("Wire construction failed");
254 Standard_NullObject::Raise
255 ("Shape for face construction is neither a wire nor a closed edge");
257 aWarning = GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), aShape);
258 if (aShape.IsNull()) {
259 Standard_ConstructionError::Raise("Face construction failed");
262 else if (aType == FACE_WIRES) {
263 // result may be a face or a compound of faces
264 anExpectedType = TopAbs_FACE;
265 allowCompound = true;
267 // Try to build a face from a set of wires and edges
270 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
271 int nbshapes = aShapes->Length();
273 Standard_ConstructionError::Raise("No wires or edges given");
276 // 1. Extract all edges from the given arguments
277 TopTools_MapOfShape aMapEdges;
278 Handle(TopTools_HSequenceOfShape) aSeqEdgesIn = new TopTools_HSequenceOfShape;
279 TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
281 for (ind = 1; ind <= nbshapes; ind++) {
282 Handle(GEOM_Function) aRefSh_i = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
283 TopoDS_Shape aSh_i = aRefSh_i->GetValue();
285 TopExp_Explorer anExpE_i (aSh_i, TopAbs_EDGE);
286 for (; anExpE_i.More(); anExpE_i.Next()) {
287 if (aMapEdges.Add(anExpE_i.Current())) {
288 // Copy the original shape.
289 TopoDS_Shape aShapeCopy;
291 TNaming_CopyShape::CopyTool
292 (anExpE_i.Current(), aMapTShapes, aShapeCopy);
293 aSeqEdgesIn->Append(aShapeCopy);
298 if (aSeqEdgesIn->IsEmpty()) {
299 Standard_ConstructionError::Raise("No edges given");
302 // 2. Connect edges to wires of maximum length
303 Handle(TopTools_HSequenceOfShape) aSeqWiresOut;
304 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdgesIn, Precision::Confusion(),
305 /*shared*/Standard_False, aSeqWiresOut);
306 //modified by NIZNHY-PKV Wed Dec 28 13:46:55 2011f
307 //KeepEdgesOrder(aSeqEdgesIn, aSeqWiresOut);
308 //modified by NIZNHY-PKV Wed Dec 28 13:46:59 2011t
310 // 3. Separate closed wires
311 Handle(TopTools_HSequenceOfShape) aSeqClosedWires = new TopTools_HSequenceOfShape;
312 Handle(TopTools_HSequenceOfShape) aSeqOpenWires = new TopTools_HSequenceOfShape;
313 for (ind = 1; ind <= aSeqWiresOut->Length(); ind++) {
314 if (aSeqWiresOut->Value(ind).Closed())
315 aSeqClosedWires->Append(aSeqWiresOut->Value(ind));
317 aSeqOpenWires->Append(aSeqWiresOut->Value(ind));
320 if (aSeqClosedWires->Length() < 1) {
321 Standard_ConstructionError::Raise
322 ("There is no closed contour can be built from the given arguments");
325 // 4. Build a face / list of faces from all the obtained closed wires
329 TopoDS_Wire aW1 = TopoDS::Wire(aSeqClosedWires->Value(1));
330 aWarning = GEOMImpl_Block6Explorer::MakeFace(aW1, aCI.GetIsPlanar(), aFFace);
331 if (aFFace.IsNull()) {
332 Standard_ConstructionError::Raise("Face construction failed");
335 // 4.b. Add other wires
336 if (aSeqClosedWires->Length() == 1) {
341 BRep_Builder aBuilder;
342 aBuilder.MakeCompound(C);
343 BRepAlgo_FaceRestrictor FR;
345 TopAbs_Orientation OriF = aFFace.Orientation();
346 TopoDS_Shape aLocalS = aFFace.Oriented(TopAbs_FORWARD);
347 FR.Init(TopoDS::Face(aLocalS), Standard_False, Standard_True);
349 for (ind = 1; ind <= aSeqClosedWires->Length(); ind++) {
350 TopoDS_Wire aW = TopoDS::Wire(aSeqClosedWires->Value(ind));
359 for (; FR.More(); FR.Next()) {
360 aFace = FR.Current().Oriented(OriF);
361 aBuilder.Add(C, aFace);
372 // 5. Add all open wires to the result
373 if (aSeqOpenWires->Length() > 0) {
374 //Standard_ConstructionError::Raise("There are some open wires");
376 BRep_Builder aBuilder;
377 if (aSeqClosedWires->Length() == 1) {
378 aBuilder.MakeCompound(C);
379 aBuilder.Add(C, aShape);
382 C = TopoDS::Compound(aShape);
385 for (ind = 1; ind <= aSeqOpenWires->Length(); ind++) {
386 aBuilder.Add(C, aSeqOpenWires->Value(ind));
392 else if (aType == FACE_FROM_SURFACE) {
393 // result may be only a face
394 anExpectedType = TopAbs_FACE;
396 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
398 if (aShapes.IsNull() == Standard_False) {
399 Standard_Integer aNbShapes = aShapes->Length();
401 if (aNbShapes == 2) {
402 Handle(GEOM_Function) aRefFace =
403 Handle(GEOM_Function)::DownCast(aShapes->Value(1));
404 Handle(GEOM_Function) aRefWire =
405 Handle(GEOM_Function)::DownCast(aShapes->Value(2));
407 if (aRefFace.IsNull() == Standard_False &&
408 aRefWire.IsNull() == Standard_False) {
409 TopoDS_Shape aShFace = aRefFace->GetValue();
410 TopoDS_Shape aShWire = aRefWire->GetValue();
412 if (aShFace.IsNull() == Standard_False &&
413 aShFace.ShapeType() == TopAbs_FACE &&
414 aShWire.IsNull() == Standard_False &&
415 aShWire.ShapeType() == TopAbs_WIRE) {
416 TopoDS_Face aFace = TopoDS::Face(aShFace);
417 TopoDS_Wire aWire = TopoDS::Wire(aShWire);
418 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
419 BRepBuilderAPI_MakeFace aMkFace(aSurf, aWire);
421 if (aMkFace.IsDone()) {
422 aShape = aMkFace.Shape();
429 else if (aType == SHELL_FACES) {
430 // result may be only a shell or a compound of shells
431 anExpectedType = TopAbs_SHELL;
432 allowCompound = true;
434 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
435 unsigned int ind, nbshapes = aShapes->Length();
438 BRepBuilderAPI_Sewing aSewing (Precision::Confusion()*10.0);
439 for (ind = 1; ind <= nbshapes; ind++) {
440 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
441 TopoDS_Shape aShape_i = aRefShape->GetValue();
442 if (aShape_i.IsNull()) {
443 Standard_NullObject::Raise("Face for shell construction is null");
445 aSewing.Add(aShape_i);
450 TopoDS_Shape sh = aSewing.SewedShape();
452 if (sh.ShapeType()==TopAbs_FACE && nbshapes==1) {
453 // case for creation of shell from one face - PAL12722 (skl 26.06.2006)
460 //TopExp_Explorer exp (aSewing.SewedShape(), TopAbs_SHELL);
461 TopExp_Explorer exp (sh, TopAbs_SHELL);
462 Standard_Integer ish = 0;
463 for (; exp.More(); exp.Next()) {
464 aShape = exp.Current();
469 // try the case of one face (Mantis issue 0021809)
470 TopExp_Explorer expF (sh, TopAbs_FACE);
471 Standard_Integer ifa = 0;
472 for (; expF.More(); expF.Next()) {
473 aShape = expF.Current();
484 aShape = aSewing.SewedShape();
490 else if (aType == SOLID_SHELLS) {
491 // result may be only a solid or a compound of solids
492 anExpectedType = TopAbs_SOLID;
493 allowCompound = true;
495 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
496 unsigned int ind, nbshapes = aShapes->Length();
497 Standard_Integer ish = 0;
498 BRepBuilderAPI_MakeSolid aMkSolid;
501 for (ind = 1; ind <= nbshapes; ind++) {
502 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
503 TopoDS_Shape aShapeShell = aRefShape->GetValue();
504 if (aShapeShell.IsNull()) {
505 Standard_NullObject::Raise("Shell for solid construction is null");
507 if (aShapeShell.ShapeType() == TopAbs_COMPOUND) {
508 TopoDS_Iterator It (aShapeShell, Standard_True, Standard_True);
509 for (; It.More(); It.Next()) {
510 TopoDS_Shape aSubShape = It.Value();
511 if (aSubShape.ShapeType() == TopAbs_SHELL) {
512 aMkSolid.Add(TopoDS::Shell(aSubShape));
516 Standard_TypeMismatch::Raise
517 ("Shape for solid construction is neither a shell nor a compound of shells");
520 else if (aShapeShell.ShapeType() == TopAbs_SHELL) {
521 aMkSolid.Add(TopoDS::Shell(aShapeShell));
525 if (ish == 0 || !aMkSolid.IsDone()) return 0;
527 TopoDS_Solid Sol = aMkSolid.Solid();
528 BRepClass3d_SolidClassifier SC (Sol);
529 SC.PerformInfinitePoint(Precision::Confusion());
530 if (SC.State() == TopAbs_IN)
531 aShape = Sol.Reversed();
535 else if (aType == COMPOUND_SHAPES) {
536 // result may be only a compound of any shapes
537 allowCompound = true;
539 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
540 unsigned int ind, nbshapes = aShapes->Length();
545 for (ind = 1; ind <= nbshapes; ind++) {
546 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
547 TopoDS_Shape aShape_i = aRefShape->GetValue();
548 if (aShape_i.IsNull()) {
549 Standard_NullObject::Raise("Shape for compound construction is null");
557 else if (aType == EDGE_WIRE) {
558 // result may be only an edge
559 anExpectedType = TopAbs_EDGE;
561 Handle(GEOM_Function) aRefBase = aCI.GetBase();
562 TopoDS_Shape aWire = aRefBase->GetValue();
563 Standard_Real LinTol = aCI.GetTolerance();
564 Standard_Real AngTol = aCI.GetAngularTolerance();
565 if (aWire.IsNull()) Standard_NullObject::Raise("Argument Wire is null");
567 aShape = MakeEdgeFromWire(aWire, LinTol, AngTol);
569 else if (aType == SOLID_FACES) {
570 // result may be only a solid or a compound of solids
571 anExpectedType = TopAbs_SOLID;
572 allowCompound = true;
574 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
575 unsigned int ind, nbshapes = aShapes->Length();
578 BOPCol_ListOfShape aLS;
579 for (ind = 1; ind <= nbshapes; ind++) {
580 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
581 TopoDS_Shape aShape_i = aRefShape->GetValue();
582 if (aShape_i.IsNull()) {
583 Standard_NullObject::Raise("Shape for solid construction is null");
585 if (aShape_i.ShapeType() == TopAbs_COMPOUND) {
586 TopoDS_Iterator It (aShape_i, Standard_True, Standard_True);
587 for (; It.More(); It.Next()) {
588 TopoDS_Shape aSubShape = It.Value();
589 if (aSubShape.ShapeType() == TopAbs_FACE || aSubShape.ShapeType() == TopAbs_SHELL)
590 aLS.Append(aSubShape);
592 Standard_TypeMismatch::Raise
593 ("Shape for solid construction is neither a list of faces and/or shells "
594 "nor a compound of faces and/or shells");
597 aLS.Append(aShape_i);
600 BOPAlgo_MakerVolume aMV;
601 aMV.SetArguments(aLS);
602 aMV.SetIntersect(aCI.GetIsIntersect());
604 if (aMV.ErrorStatus()) return 0;
606 aShape = aMV.Shape();
608 else if (aType == EDGE_CURVE_LENGTH) {
609 // result may be only an edge
610 anExpectedType = TopAbs_EDGE;
612 GEOMImpl_IVector aVI (aFunction);
615 Handle(GEOM_Function) aRefCurve = aVI.GetPoint1();
616 if (aRefCurve.IsNull()) Standard_NullObject::Raise("Argument Curve is null");
617 TopoDS_Shape aRefShape1 = aRefCurve->GetValue();
618 if (aRefShape1.ShapeType() != TopAbs_EDGE) {
619 Standard_TypeMismatch::Raise
620 ("Edge On Curve creation aborted : curve shape is not an edge");
622 TopoDS_Edge aRefEdge = TopoDS::Edge(aRefShape1);
623 TopoDS_Vertex V1, V2;
624 TopExp::Vertices(aRefEdge, V1, V2, Standard_True);
627 TopoDS_Vertex aRefVertex;
628 Handle(GEOM_Function) aRefPoint = aVI.GetPoint2();
629 if (aRefPoint.IsNull()) {
633 TopoDS_Shape aRefShape2 = aRefPoint->GetValue();
634 if (aRefShape2.ShapeType() != TopAbs_VERTEX) {
635 Standard_TypeMismatch::Raise
636 ("Edge On Curve creation aborted : start point shape is not a vertex");
638 aRefVertex = TopoDS::Vertex(aRefShape2);
640 gp_Pnt aRefPnt = BRep_Tool::Pnt(aRefVertex);
643 Standard_Real aLength = aVI.GetParameter();
644 //Standard_Real aCurveLength = IntTools::Length(aRefEdge);
645 //if (aLength > aCurveLength) {
646 // Standard_ConstructionError::Raise
647 // ("Edge On Curve creation aborted : given length is greater than edges length");
649 if (fabs(aLength) < Precision::Confusion()) {
650 Standard_ConstructionError::Raise
651 ("Edge On Curve creation aborted : given length is smaller than Precision::Confusion()");
655 Standard_Real UFirst, ULast;
656 Handle(Geom_Curve) EdgeCurve = BRep_Tool::Curve(aRefEdge, UFirst, ULast);
657 Handle(Geom_Curve) ReOrientedCurve = EdgeCurve;
659 Standard_Real dU = ULast - UFirst;
660 Standard_Real par1 = UFirst + 0.1 * dU;
661 Standard_Real par2 = ULast - 0.1 * dU;
663 gp_Pnt P1 = EdgeCurve->Value(par1);
664 gp_Pnt P2 = EdgeCurve->Value(par2);
666 if (aRefPnt.SquareDistance(P2) < aRefPnt.SquareDistance(P1)) {
667 ReOrientedCurve = EdgeCurve->Reversed();
668 UFirst = EdgeCurve->ReversedParameter(ULast);
671 // Get the point by length
672 GeomAdaptor_Curve AdapCurve = GeomAdaptor_Curve(ReOrientedCurve);
673 GCPnts_AbscissaPoint anAbsPnt (AdapCurve, aLength, UFirst);
674 Standard_Real aParam = anAbsPnt.Parameter();
676 if (AdapCurve.IsClosed() && aLength < 0.0) {
677 Standard_Real aTmp = aParam;
682 BRepBuilderAPI_MakeEdge aME (ReOrientedCurve, UFirst, aParam);
684 aShape = aME.Shape();
686 else if (aType == SHAPE_ISOLINE) {
687 // result may be only an edge or compound of edges
688 anExpectedType = TopAbs_EDGE;
689 allowCompound = true;
691 GEOMImpl_IIsoline aII (aFunction);
692 Handle(GEOM_Function) aRefFace = aII.GetFace();
693 TopoDS_Shape aShapeFace = aRefFace->GetValue();
695 if (aShapeFace.ShapeType() == TopAbs_FACE) {
696 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
697 bool isUIso = aII.GetIsUIso();
698 Standard_Real aParam = aII.GetParameter();
699 Standard_Real U1,U2,V1,V2;
701 // Construct a real geometric parameter.
702 aFace.Orientation(TopAbs_FORWARD);
703 ShapeAnalysis::GetFaceUVBounds(aFace,U1,U2,V1,V2);
706 aParam = U1 + (U2 - U1)*aParam;
708 aParam = V1 + (V2 - V1)*aParam;
711 aShape = MakeIsoline(aFace, isUIso, aParam);
713 Standard_NullObject::Raise
714 ("Shape for isoline construction is not a face");
717 else if (aType == EDGE_UV) {
718 // result may be only an edge
719 anExpectedType = TopAbs_EDGE;
721 GEOMImpl_IShapeExtend aSE (aFunction);
722 Handle(GEOM_Function) aRefEdge = aSE.GetShape();
723 TopoDS_Shape aShapeEdge = aRefEdge->GetValue();
725 if (aShapeEdge.ShapeType() == TopAbs_EDGE) {
726 TopoDS_Edge anEdge = TopoDS::Edge(aShapeEdge);
728 aShape = ExtendEdge(anEdge, aSE.GetUMin(), aSE.GetUMax());
731 else if (aType == FACE_UV) {
732 // result may be only a face
733 anExpectedType = TopAbs_FACE;
735 GEOMImpl_IShapeExtend aSE (aFunction);
736 Handle(GEOM_Function) aRefFace = aSE.GetShape();
737 TopoDS_Shape aShapeFace = aRefFace->GetValue();
739 if (aShapeFace.ShapeType() == TopAbs_FACE) {
740 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
742 aFace.Orientation(TopAbs_FORWARD);
743 aShape = ExtendFace(aFace, aSE.GetUMin(), aSE.GetUMax(),
744 aSE.GetVMin(), aSE.GetVMax());
747 else if (aType == SURFACE_FROM_FACE) {
748 // result may be only a face
749 anExpectedType = TopAbs_FACE;
751 GEOMImpl_IShapeExtend aSE (aFunction);
752 Handle(GEOM_Function) aRefFace = aSE.GetShape();
753 TopoDS_Shape aShapeFace = aRefFace->GetValue();
755 if (aShapeFace.ShapeType() == TopAbs_FACE) {
756 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
757 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
759 if (aSurface.IsNull() == Standard_False) {
760 Handle(Standard_Type) aType = aSurface->DynamicType();
766 // Get U, V bounds of the face.
767 aFace.Orientation(TopAbs_FORWARD);
768 ShapeAnalysis::GetFaceUVBounds(aFace, aU1, aU2, aV1, aV2);
770 // Get the surface of original type
771 while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
772 Handle(Geom_RectangularTrimmedSurface) aTrSurface =
773 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
775 aSurface = aTrSurface->BasisSurface();
776 aType = aSurface->DynamicType();
779 const Standard_Real aTol = BRep_Tool::Tolerance(aFace);
780 BRepBuilderAPI_MakeFace aMF(aSurface, aU1, aU2, aV1, aV2, aTol);
783 aShape = aMF.Shape();
791 if (aShape.IsNull()) return 0;
793 // Check shape validity
794 BRepCheck_Analyzer ana (aShape, true);
795 if (!ana.IsValid()) {
796 //Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
797 // For Mantis issue 0021772: EDF 2336 GEOM: Non valid face created from two circles
798 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape (aShape);
800 aShape = aSfs->Shape();
803 // Check if the result shape is of expected type.
804 const TopAbs_ShapeEnum aShType = aShape.ShapeType();
807 if ( aShType == TopAbs_COMPOUND || aShType == TopAbs_COMPSOLID ) {
808 ok = allowCompound && checkCompound( aShape, anExpectedType );
811 ok = ( anExpectedType == TopAbs_SHAPE ) || ( aShType == anExpectedType );
814 Standard_ConstructionError::Raise("Result type check failed");
816 aFunction->SetValue(aShape);
818 log.SetTouched(Label());
820 if (!aWarning.IsEmpty())
821 Standard_Failure::Raise(aWarning.ToCString());
826 TopoDS_Wire GEOMImpl_ShapeDriver::MakeWireFromEdges(const Handle(TColStd_HSequenceOfTransient)& theEdgesFuncs,
827 const Standard_Real theTolerance)
835 for (unsigned int ind = 1; ind <= theEdgesFuncs->Length(); ind++) {
836 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(theEdgesFuncs->Value(ind));
837 TopoDS_Shape aShape_i = aRefShape->GetValue();
838 if (aShape_i.IsNull()) {
839 Standard_NullObject::Raise("Shape for wire construction is null");
841 if (aShape_i.ShapeType() == TopAbs_EDGE || aShape_i.ShapeType() == TopAbs_WIRE) {
842 TopExp_Explorer exp (aShape_i, TopAbs_EDGE);
843 for (; exp.More(); exp.Next())
844 B.Add(aWire, TopoDS::Edge(exp.Current()));
846 Standard_TypeMismatch::Raise
847 ("Shape for wire construction is neither an edge nor a wire");
852 Handle(ShapeFix_Wire) aFW = new ShapeFix_Wire;
856 if (aFW->StatusReorder(ShapeExtend_FAIL1)) {
857 Standard_ConstructionError::Raise("Wire construction failed: several loops detected");
859 else if (aFW->StatusReorder(ShapeExtend_FAIL)) {
860 Standard_ConstructionError::Raise("Wire construction failed");
865 // IMP 0019766: Building a Wire from unconnected edges by introducing a tolerance
866 aFW->ClosedWireMode() = Standard_False;
867 aFW->FixConnected(theTolerance);
868 if (aFW->StatusConnected(ShapeExtend_FAIL)) {
869 Standard_ConstructionError::Raise("Wire construction failed: cannot build connected wire");
872 if (aFW->StatusConnected(ShapeExtend_DONE3)) {
873 // Confused with <prec> but not Analyzer.Precision(), set the same
874 aFW->FixGapsByRangesMode() = Standard_True;
875 if (aFW->FixGaps3d()) {
876 Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
877 Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
878 for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
879 TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
880 aFe->FixVertexTolerance(aEdge);
881 aFe->FixSameParameter(aEdge);
884 else if (aFW->StatusGaps3d(ShapeExtend_FAIL)) {
885 Standard_ConstructionError::Raise("Wire construction failed: cannot fix 3d gaps");
888 aWire = aFW->WireAPIMake();
893 TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
894 const Standard_Real LinTol,
895 const Standard_Real AngTol)
899 BRepLib::BuildCurves3d(aWire);
900 Handle(ShapeFix_Shape) Fixer = new ShapeFix_Shape(aWire);
901 Fixer->SetPrecision(LinTol);
902 Fixer->SetMaxTolerance(LinTol);
904 TopoDS_Wire theWire = TopoDS::Wire(Fixer->Shape());
906 TColGeom_SequenceOfCurve CurveSeq;
907 TopTools_SequenceOfShape LocSeq;
908 TColStd_SequenceOfReal FparSeq;
909 TColStd_SequenceOfReal LparSeq;
910 TColStd_SequenceOfReal TolSeq;
911 GeomAbs_CurveType CurType;
912 TopoDS_Vertex FirstVertex, LastVertex;
913 Standard_Real aPntShiftDist = 0.;
915 BRepTools_WireExplorer wexp(theWire) ;
916 for (; wexp.More(); wexp.Next())
918 TopoDS_Edge anEdge = wexp.Current();
919 Standard_Real fpar, lpar;
920 TopLoc_Location aLoc;
921 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aLoc, fpar, lpar);
925 BRepAdaptor_Curve BAcurve(anEdge);
926 GeomAbs_CurveType aType = BAcurve.GetType();
928 Handle(Geom_Curve) aBasisCurve = BAcurve.Curve().Curve();
930 if (aBasisCurve->IsPeriodic())
931 ElCLib::AdjustPeriodic(aBasisCurve->FirstParameter(), aBasisCurve->LastParameter(),
932 Precision::PConfusion(), fpar, lpar);
934 if (CurveSeq.IsEmpty())
936 CurveSeq.Append(aCurve);
937 TopoDS_Shape aLocShape;
938 aLocShape.Location(aLoc);
939 aLocShape.Orientation(wexp.Orientation());
940 LocSeq.Append(aLocShape);
941 FparSeq.Append(fpar);
942 LparSeq.Append(lpar);
944 FirstVertex = wexp.CurrentVertex();
948 Standard_Boolean Done = Standard_False;
949 Standard_Real NewFpar, NewLpar;
950 Handle(Geom_Geometry) aTrsfGeom = CurveSeq.Last()->Transformed
951 (LocSeq.Last().Location().Transformation());
952 GeomAdaptor_Curve GAprevcurve(Handle(Geom_Curve)::DownCast(aTrsfGeom));
953 TopoDS_Vertex CurVertex = wexp.CurrentVertex();
954 TopoDS_Vertex CurFirstVer = TopExp::FirstVertex(anEdge);
955 TopAbs_Orientation ConnectByOrigin = (CurVertex.IsSame(CurFirstVer))? TopAbs_FORWARD : TopAbs_REVERSED;
956 if (aCurve == CurveSeq.Last() && aLoc.IsEqual(LocSeq.Last().Location()))
960 if (aBasisCurve->IsPeriodic())
962 if (NewLpar < NewFpar)
963 NewLpar += aBasisCurve->Period();
964 if (ConnectByOrigin == TopAbs_FORWARD)
965 ElCLib::AdjustPeriodic(FparSeq.Last(),
966 FparSeq.Last() + aBasisCurve->Period(),
967 Precision::PConfusion(), NewFpar, NewLpar);
969 ElCLib::AdjustPeriodic(FparSeq.Last() - aBasisCurve->Period(),
971 Precision::PConfusion(), NewFpar, NewLpar);
973 Done = Standard_True;
975 else if (aType == CurType &&
976 aType != GeomAbs_BezierCurve &&
977 aType != GeomAbs_BSplineCurve &&
978 aType != GeomAbs_OtherCurve)
984 gp_Lin aLine = BAcurve.Line();
985 gp_Lin PrevLine = GAprevcurve.Line();
986 if (aLine.Contains(PrevLine.Location(), LinTol) &&
987 aLine.Direction().IsParallel(PrevLine.Direction(), AngTol))
989 gp_Pnt P1 = ElCLib::Value(fpar, aLine);
990 gp_Pnt P2 = ElCLib::Value(lpar, aLine);
991 NewFpar = ElCLib::Parameter(PrevLine, P1);
992 NewLpar = ElCLib::Parameter(PrevLine, P2);
995 if (ConnectByOrigin == TopAbs_FORWARD) {
996 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevLine);
998 aPntShiftDist += P2.Distance(aNewP2);
1000 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevLine);
1002 aPntShiftDist += P1.Distance(aNewP1);
1005 if (NewLpar < NewFpar)
1007 Standard_Real MemNewFpar = NewFpar;
1009 NewLpar = MemNewFpar;
1010 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1012 Done = Standard_True;
1016 case GeomAbs_Circle:
1018 gp_Circ aCircle = BAcurve.Circle();
1019 gp_Circ PrevCircle = GAprevcurve.Circle();
1020 if (aCircle.Location().Distance(PrevCircle.Location()) <= LinTol &&
1021 Abs(aCircle.Radius() - PrevCircle.Radius()) <= LinTol &&
1022 aCircle.Axis().IsParallel(PrevCircle.Axis(), AngTol))
1024 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
1026 if (aCircle.Axis().Direction() * PrevCircle.Axis().Direction() < 0.)
1028 Standard_Real memfpar = fpar;
1031 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1033 gp_Pnt P1 = ElCLib::Value(fpar, aCircle);
1034 gp_Pnt P2 = ElCLib::Value(lpar, aCircle);
1035 NewFpar = ElCLib::Parameter(PrevCircle, P1);
1036 NewLpar = ElCLib::Parameter(PrevCircle, P2);
1040 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevCircle);
1042 aPntShiftDist += P2.Distance(aNewP2);
1044 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevCircle);
1046 aPntShiftDist += P1.Distance(aNewP1);
1049 if (NewLpar < NewFpar)
1051 //Standard_Real MemNewFpar = NewFpar, MemNewLpar = NewLpar;
1052 if (ConnectByOrigin == TopAbs_FORWARD)
1053 ElCLib::AdjustPeriodic(FparSeq.Last(),
1054 FparSeq.Last() + 2.*M_PI,
1055 Precision::PConfusion(), NewFpar, NewLpar);
1057 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
1059 Precision::PConfusion(), NewFpar, NewLpar);
1060 Done = Standard_True;
1064 case GeomAbs_Ellipse:
1066 gp_Elips anEllipse = BAcurve.Ellipse();
1067 gp_Elips PrevEllipse = GAprevcurve.Ellipse();
1068 if (anEllipse.Focus1().Distance(PrevEllipse.Focus1()) <= LinTol &&
1069 anEllipse.Focus2().Distance(PrevEllipse.Focus2()) <= LinTol &&
1070 Abs(anEllipse.MajorRadius() - PrevEllipse.MajorRadius()) <= LinTol &&
1071 Abs(anEllipse.MinorRadius() - PrevEllipse.MinorRadius()) <= LinTol &&
1072 anEllipse.Axis().IsParallel(PrevEllipse.Axis(), AngTol))
1074 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
1076 if (anEllipse.Axis().Direction() * PrevEllipse.Axis().Direction() < 0.)
1078 Standard_Real memfpar = fpar;
1081 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1083 gp_Pnt P1 = ElCLib::Value(fpar, anEllipse);
1084 gp_Pnt P2 = ElCLib::Value(lpar, anEllipse);
1085 NewFpar = ElCLib::Parameter(PrevEllipse, P1);
1086 NewLpar = ElCLib::Parameter(PrevEllipse, P2);
1090 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevEllipse);
1092 aPntShiftDist += P2.Distance(aNewP2);
1094 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevEllipse);
1096 aPntShiftDist += P1.Distance(aNewP1);
1099 if (NewLpar < NewFpar)
1101 if (ConnectByOrigin == TopAbs_FORWARD)
1102 ElCLib::AdjustPeriodic(FparSeq.Last(),
1103 FparSeq.Last() + 2.*M_PI,
1104 Precision::PConfusion(), NewFpar, NewLpar);
1106 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
1108 Precision::PConfusion(), NewFpar, NewLpar);
1109 Done = Standard_True;
1113 case GeomAbs_Hyperbola:
1115 gp_Hypr aHypr = BAcurve.Hyperbola();
1116 gp_Hypr PrevHypr = GAprevcurve.Hyperbola();
1117 if (aHypr.Focus1().Distance(PrevHypr.Focus1()) <= LinTol &&
1118 aHypr.Focus2().Distance(PrevHypr.Focus2()) <= LinTol &&
1119 Abs(aHypr.MajorRadius() - PrevHypr.MajorRadius()) <= LinTol &&
1120 Abs(aHypr.MinorRadius() - PrevHypr.MinorRadius()) <= LinTol &&
1121 aHypr.Axis().IsParallel(PrevHypr.Axis(), AngTol))
1123 gp_Pnt P1 = ElCLib::Value(fpar, aHypr);
1124 gp_Pnt P2 = ElCLib::Value(lpar, aHypr);
1125 NewFpar = ElCLib::Parameter(PrevHypr, P1);
1126 NewLpar = ElCLib::Parameter(PrevHypr, P2);
1129 if (ConnectByOrigin == TopAbs_FORWARD) {
1130 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevHypr);
1132 aPntShiftDist += P2.Distance(aNewP2);
1134 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevHypr);
1136 aPntShiftDist += P1.Distance(aNewP1);
1139 if (NewLpar < NewFpar)
1141 Standard_Real MemNewFpar = NewFpar;
1143 NewLpar = MemNewFpar;
1144 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1146 Done = Standard_True;
1150 case GeomAbs_Parabola:
1152 gp_Parab aParab = BAcurve.Parabola();
1153 gp_Parab PrevParab = GAprevcurve.Parabola();
1154 if (aParab.Location().Distance(PrevParab.Location()) <= LinTol &&
1155 aParab.Focus().Distance(PrevParab.Focus()) <= LinTol &&
1156 Abs(aParab.Focal() - PrevParab.Focal()) <= LinTol &&
1157 aParab.Axis().IsParallel(PrevParab.Axis(), AngTol))
1159 gp_Pnt P1 = ElCLib::Value(fpar, aParab);
1160 gp_Pnt P2 = ElCLib::Value(lpar, aParab);
1161 NewFpar = ElCLib::Parameter(PrevParab, P1);
1162 NewLpar = ElCLib::Parameter(PrevParab, P2);
1165 if (ConnectByOrigin == TopAbs_FORWARD) {
1166 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevParab);
1168 aPntShiftDist += P2.Distance(aNewP2);
1170 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevParab);
1172 aPntShiftDist += P1.Distance(aNewP1);
1175 if (NewLpar < NewFpar)
1177 Standard_Real MemNewFpar = NewFpar;
1179 NewLpar = MemNewFpar;
1180 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1182 Done = Standard_True;
1186 } //end of switch (aType)
1187 } // end of else if (aType == CurType && ...
1190 if (NewFpar < FparSeq.Last())
1191 FparSeq(FparSeq.Length()) = NewFpar;
1193 LparSeq(LparSeq.Length()) = NewLpar;
1197 CurveSeq.Append(aCurve);
1198 TopoDS_Shape aLocShape;
1199 aLocShape.Location(aLoc);
1200 aLocShape.Orientation(wexp.Orientation());
1201 LocSeq.Append(aLocShape);
1202 FparSeq.Append(fpar);
1203 LparSeq.Append(lpar);
1204 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(CurVertex));
1208 } // end of else (CurveSeq.IsEmpty()) -> not first time
1209 } // end for (; wexp.More(); wexp.Next())
1211 LastVertex = wexp.CurrentVertex();
1212 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(LastVertex));
1214 FirstVertex.Orientation(TopAbs_FORWARD);
1215 LastVertex.Orientation(TopAbs_REVERSED);
1217 if (!CurveSeq.IsEmpty())
1219 Standard_Integer nb_curve = CurveSeq.Length(); //number of curves
1220 TColGeom_Array1OfBSplineCurve tab(0,nb_curve-1); //array of the curves
1221 TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2); //array of the tolerances
1227 for (i = 1; i <= nb_curve; i++)
1229 if (CurveSeq(i)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1230 CurveSeq(i) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(i))))->BasisCurve();
1232 Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(CurveSeq(i), FparSeq(i), LparSeq(i));
1233 tab(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve);
1234 tab(i-1)->Transform(LocSeq(i).Location().Transformation());
1235 GeomConvert::C0BSplineToC1BSplineCurve(tab(i-1), Precision::Confusion());
1236 if (LocSeq(i).Orientation() == TopAbs_REVERSED)
1237 tab(i-1)->Reverse();
1240 //char* name = new char[100];
1241 //sprintf(name, "c%d", i);
1242 //DrawTrSurf::Set(name, tab(i-1));
1245 tabtolvertex(i-2) = TolSeq(i-1);
1246 } // end for (i = 1; i <= nb_curve; i++)
1247 tabtolvertex(nb_curve-1) = TolSeq(TolSeq.Length());
1249 Standard_Boolean closed_flag = Standard_False;
1250 Standard_Real closed_tolerance = 0.;
1251 if (FirstVertex.IsSame(LastVertex) &&
1252 GeomLProp::Continuity(tab(0), tab(nb_curve-1),
1253 tab(0)->FirstParameter(),
1254 tab(nb_curve-1)->LastParameter(),
1255 Standard_False, Standard_False, LinTol, AngTol) >= GeomAbs_G1)
1257 closed_flag = Standard_True ;
1258 closed_tolerance = BRep_Tool::Tolerance(FirstVertex);
1261 Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves
1262 Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex
1263 GeomConvert::ConcatC1(tab,
1268 closed_tolerance); //C1 concatenation
1270 if (concatcurve->Length() > 1)
1272 GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower()));
1274 for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++)
1275 Concat.Add( concatcurve->Value(i), LinTol, Standard_True );
1277 concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve());
1279 // rnc : prevents the driver from building an edge without C1 continuity
1280 if (concatcurve->Value(concatcurve->Lower())->Continuity()==GeomAbs_C0){
1281 Standard_ConstructionError::Raise("Construction aborted : The given Wire has sharp bends between some Edges, no valid Edge can be built");
1284 Standard_Boolean isValidEndVtx = Standard_True;
1287 // Check if closed curve is reordered.
1288 Handle(Geom_Curve) aCurve = concatcurve->Value(concatcurve->Lower());
1289 Standard_Real aFPar = aCurve->FirstParameter();
1291 gp_Pnt aPntVtx = BRep_Tool::Pnt(FirstVertex);
1292 Standard_Real aTolVtx = BRep_Tool::Tolerance(FirstVertex);
1294 aCurve->D0(aFPar, aPFirst);
1296 if (!aPFirst.IsEqual(aPntVtx, aTolVtx)) {
1297 // The curve is reordered. Find the new first and last vertices.
1298 TopTools_IndexedMapOfShape aMapVtx;
1299 TopExp::MapShapes(theWire, TopAbs_VERTEX, aMapVtx);
1301 const Standard_Integer aNbVtx = aMapVtx.Extent();
1302 Standard_Integer iVtx;
1304 for (iVtx = 1; iVtx <= aNbVtx; iVtx++) {
1305 const TopoDS_Vertex aVtx = TopoDS::Vertex(aMapVtx.FindKey(iVtx));
1306 const gp_Pnt aPnt = BRep_Tool::Pnt(aVtx);
1307 const Standard_Real aTol = BRep_Tool::Tolerance(aVtx);
1309 if (aPFirst.IsEqual(aPnt, aTol)) {
1310 // The coinsident vertex is found.
1313 FirstVertex.Orientation(TopAbs_FORWARD);
1314 LastVertex.Orientation(TopAbs_REVERSED);
1319 if (iVtx > aNbVtx) {
1320 // It is necessary to create new vertices.
1321 isValidEndVtx = Standard_False;
1326 if (isValidEndVtx) {
1327 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1328 FirstVertex, LastVertex,
1329 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1330 concatcurve->Value(concatcurve->Lower())->LastParameter());
1332 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1333 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1334 concatcurve->Value(concatcurve->Lower())->LastParameter());
1339 if (CurveSeq(1)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1340 CurveSeq(1) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(1))))->BasisCurve();
1342 Handle(Geom_Curve) aNewCurve =
1343 Handle(Geom_Curve)::DownCast(CurveSeq(1)->Copy());
1345 aNewCurve->Transform(LocSeq(1).Location().Transformation());
1347 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1348 const TopoDS_Vertex aVtxTmp = FirstVertex;
1350 FirstVertex = LastVertex;
1351 LastVertex = aVtxTmp;
1352 FirstVertex.Orientation(TopAbs_FORWARD);
1353 LastVertex.Orientation(TopAbs_REVERSED);
1356 ResEdge = BRepLib_MakeEdge(aNewCurve,
1357 FirstVertex, LastVertex,
1358 FparSeq(1), LparSeq(1));
1360 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1369 //=============================================================================
1371 * \brief Returns an isoline for a face.
1373 //=============================================================================
1375 TopoDS_Shape GEOMImpl_ShapeDriver::MakeIsoline
1376 (const TopoDS_Face &theFace,
1378 const double theParameter) const
1380 TopoDS_Shape aResult;
1381 GEOMUtils::Hatcher aHatcher(theFace);
1382 const GeomAbs_IsoType aType = (IsUIso ? GeomAbs_IsoU : GeomAbs_IsoV);
1384 aHatcher.Init(aType, theParameter);
1387 if (!aHatcher.IsDone()) {
1388 Standard_ConstructionError::Raise("MakeIsoline : Hatcher failure");
1391 const Handle(TColStd_HArray1OfInteger) &anIndices =
1392 (IsUIso ? aHatcher.GetUIndices() : aHatcher.GetVIndices());
1394 if (anIndices.IsNull()) {
1395 Standard_ConstructionError::Raise("MakeIsoline : Null hatching indices");
1398 const Standard_Integer anIsoInd = anIndices->Lower();
1399 const Standard_Integer aHatchingIndex = anIndices->Value(anIsoInd);
1401 if (aHatchingIndex == 0) {
1402 Standard_ConstructionError::Raise("MakeIsoline : Invalid hatching index");
1405 const Standard_Integer aNbDomains =
1406 aHatcher.GetNbDomains(aHatchingIndex);
1408 if (aNbDomains < 0) {
1409 Standard_ConstructionError::Raise("MakeIsoline : Invalid number of domains");
1412 // The hatching is performed successfully. Create the 3d Curve.
1413 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1414 Handle(Geom_Curve) anIsoCurve = (IsUIso ?
1415 aSurface->UIso(theParameter) : aSurface->VIso(theParameter));
1416 Handle(Geom2d_Curve) aPIsoCurve =
1417 aHatcher.GetHatching(aHatchingIndex);
1418 const Standard_Real aTol = Precision::Confusion();
1419 Standard_Integer anIDom = 1;
1422 BRep_Builder aBuilder;
1423 Standard_Integer aNbEdges = 0;
1425 for (; anIDom <= aNbDomains; anIDom++) {
1426 if (aHatcher.GetDomain(aHatchingIndex, anIDom, aV1, aV2)) {
1427 // Check first and last parameters.
1428 if (!aHatcher.IsDomainInfinite(aHatchingIndex, anIDom)) {
1430 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(anIsoCurve, aV1, aV2);
1432 // Update it with a parametric curve on face.
1433 aBuilder.UpdateEdge(anEdge, aPIsoCurve, theFace, aTol);
1437 // Result is a compond.
1438 if (aNbEdges == 2) {
1439 // Create a new compound.
1440 TopoDS_Compound aCompound;
1442 aBuilder.MakeCompound(aCompound);
1443 aBuilder.Add(aCompound, aResult);
1444 aResult = aCompound;
1447 // Add an edge to the compound.
1448 aBuilder.Add(aResult, anEdge);
1450 // Result is the edge.
1457 if (aNbEdges == 0) {
1458 Standard_ConstructionError::Raise("MakeIsoline : Empty result");
1464 //=============================================================================
1466 * \brief Returns an extended edge.
1468 //=============================================================================
1470 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendEdge
1471 (const TopoDS_Edge &theEdge,
1472 const Standard_Real theMin,
1473 const Standard_Real theMax) const
1475 TopoDS_Shape aResult;
1478 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(theEdge, aF, aL);
1479 const Standard_Real aTol = BRep_Tool::Tolerance(theEdge);
1480 Standard_Real aRange2d = aL - aF;
1482 if (aCurve.IsNull() == Standard_False && aRange2d > aTol) {
1483 Standard_Real aMin = aF + aRange2d*theMin;
1484 Standard_Real aMax = aF + aRange2d*theMax;
1486 Handle(Standard_Type) aType = aCurve->DynamicType();
1488 // Get the curve of original type
1489 while (aType == STANDARD_TYPE(Geom_TrimmedCurve)) {
1490 Handle(Geom_TrimmedCurve) aTrCurve =
1491 Handle(Geom_TrimmedCurve)::DownCast(aCurve);
1493 aCurve = aTrCurve->BasisCurve();
1494 aType = aCurve->DynamicType();
1497 if (aCurve->IsPeriodic()) {
1498 // The curve is periodic. Check if a new range is less then a period.
1499 if (aMax - aMin > aCurve->Period()) {
1500 aMax = aMin + aCurve->Period();
1503 // The curve is not periodic. Check if aMin and aMax within bounds.
1504 aMin = Max(aMin, aCurve->FirstParameter());
1505 aMax = Min(aMax, aCurve->LastParameter());
1508 if (aMax - aMin > aTol) {
1509 // Create a new edge.
1510 BRepBuilderAPI_MakeEdge aME (aCurve, aMin, aMax);
1513 aResult = aME.Shape();
1521 //=============================================================================
1523 * \brief Returns an extended face.
1525 //=============================================================================
1527 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendFace
1528 (const TopoDS_Face &theFace,
1529 const Standard_Real theUMin,
1530 const Standard_Real theUMax,
1531 const Standard_Real theVMin,
1532 const Standard_Real theVMax) const
1534 TopoDS_Shape aResult;
1535 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1536 const Standard_Real aTol = BRep_Tool::Tolerance(theFace);
1542 // Get U, V bounds of the face.
1543 ShapeAnalysis::GetFaceUVBounds(theFace, aU1, aU2, aV1, aV2);
1545 const Standard_Real aURange = aU2 - aU1;
1546 const Standard_Real aVRange = aV2 - aV1;
1548 if (aSurface.IsNull() == Standard_False &&
1549 aURange > aTol && aURange > aTol) {
1550 Handle(Standard_Type) aType = aSurface->DynamicType();
1552 // Get the surface of original type
1553 while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1554 Handle(Geom_RectangularTrimmedSurface) aTrSurface =
1555 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
1557 aSurface = aTrSurface->BasisSurface();
1558 aType = aSurface->DynamicType();
1561 Standard_Real aUMin = aU1 + aURange*theUMin;
1562 Standard_Real aUMax = aU1 + aURange*theUMax;
1563 Standard_Real aVMin = aV1 + aVRange*theVMin;
1564 Standard_Real aVMax = aV1 + aVRange*theVMax;
1566 aSurface->Bounds(aU1, aU2, aV1, aV2);
1568 if (aSurface->IsUPeriodic()) {
1569 // The surface is U-periodic. Check if a new U range is less
1571 if (aUMax - aUMin > aSurface->UPeriod()) {
1572 aUMax = aUMin + aSurface->UPeriod();
1575 // The surface is not V-periodic. Check if aUMin and aUMax
1577 aUMin = Max(aUMin, aU1);
1578 aUMax = Min(aUMax, aU2);
1581 if (aSurface->IsVPeriodic()) {
1582 // The surface is V-periodic. Check if a new V range is less
1584 if (aVMax - aVMin > aSurface->VPeriod()) {
1585 aVMax = aVMin + aSurface->VPeriod();
1588 // The surface is not V-periodic. Check if aVMin and aVMax
1590 aVMin = Max(aVMin, aV1);
1591 aVMax = Min(aVMax, aV2);
1594 if (aUMax - aUMin > aTol && aVMax - aVMin > aTol) {
1595 // Create a new edge.
1596 BRepBuilderAPI_MakeFace aMF
1597 (aSurface, aUMin, aUMax, aVMin, aVMax, aTol);
1600 aResult = aMF.Shape();
1608 //================================================================================
1610 * \brief Returns a name of creation operation and names and values of creation parameters
1612 //================================================================================
1614 bool GEOMImpl_ShapeDriver::
1615 GetCreationInformation(std::string& theOperationName,
1616 std::vector<GEOM_Param>& theParams)
1618 if (Label().IsNull()) return 0;
1619 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
1621 GEOMImpl_IShapes aCI( function );
1622 Standard_Integer aType = function->GetType();
1626 theOperationName = "WIRE";
1627 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1628 AddParam( theParams, "Tolerance", aCI.GetTolerance() );
1631 theOperationName = "FACE";
1632 AddParam( theParams, "Wire/edge", aCI.GetBase() );
1633 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1636 theOperationName = "FACE";
1637 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1638 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1640 case FACE_FROM_SURFACE:
1642 theOperationName = "FACE";
1644 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1646 if (shapes.IsNull() == Standard_False) {
1647 Standard_Integer aNbShapes = shapes->Length();
1649 if (aNbShapes > 0) {
1650 AddParam(theParams, "Face", shapes->Value(1));
1652 if (aNbShapes > 1) {
1653 AddParam(theParams, "Wire", shapes->Value(2));
1660 theOperationName = "SHELL";
1661 AddParam( theParams, "Objects", aCI.GetShapes() );
1664 theOperationName = "SOLID";
1665 AddParam( theParams, "Objects", aCI.GetShapes() );
1668 theOperationName = "SOLID_FROM_FACES";
1669 AddParam( theParams, "Objects", aCI.GetShapes() );
1670 AddParam( theParams, "Is intersect", aCI.GetIsIntersect() );
1672 case COMPOUND_SHAPES:
1673 theOperationName = "COMPOUND";
1674 AddParam( theParams, "Objects", aCI.GetShapes() );
1677 theOperationName = "EDGE";
1678 AddParam( theParams, "Wire", aCI.GetBase() );
1679 AddParam( theParams, "Linear Tolerance", aCI.GetTolerance() );
1680 AddParam( theParams, "Angular Tolerance", aCI.GetAngularTolerance() );
1682 case EDGE_CURVE_LENGTH:
1683 theOperationName = "EDGE";
1685 GEOMImpl_IVector aCI( function );
1686 AddParam( theParams, "Edge", aCI.GetPoint1() );
1687 AddParam( theParams, "Start point", aCI.GetPoint2() );
1688 AddParam( theParams, "Length", aCI.GetParameter() );
1691 case SHAPES_ON_SHAPE:
1693 theOperationName = "GetShapesOnShapeAsCompound";
1694 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1695 if ( !shapes.IsNull() && shapes->Length() > 0 )
1696 AddParam( theParams, "Check shape", shapes->Value(1) );
1697 if ( !shapes.IsNull() && shapes->Length() > 1 )
1698 AddParam( theParams, "Shape", shapes->Value(2) );
1699 AddParam( theParams, "Shape type", TopAbs_ShapeEnum( aCI.GetSubShapeType() ));
1700 AddParam( theParams, "State" );
1701 GEOMAlgo_State st = GEOMAlgo_State( (int) ( aCI.GetTolerance()+0.1 ) );
1702 const char* stName[] = { "UNKNOWN","IN","OUT","ON","ONIN","ONOUT","INOUT" };
1703 if ( 0 <= st && st <= GEOMAlgo_ST_INOUT )
1704 theParams.back() << stName[ st ];
1706 theParams.back() << (int) st;
1711 GEOMImpl_IIsoline aII (function);
1713 theOperationName = "ISOLINE";
1714 AddParam(theParams, "Face", aII.GetFace());
1715 AddParam(theParams, "Isoline type", (aII.GetIsUIso() ? "U" : "V"));
1716 AddParam(theParams, "Parameter", aII.GetParameter());
1721 GEOMImpl_IShapeExtend aSE (function);
1723 theOperationName = "EDGE_EXTEND";
1724 AddParam(theParams, "Edge", aSE.GetShape());
1725 AddParam(theParams, "Min", aSE.GetUMin());
1726 AddParam(theParams, "Max", aSE.GetUMax());
1731 GEOMImpl_IShapeExtend aSE (function);
1733 theOperationName = "FACE_EXTEND";
1734 AddParam(theParams, "Face", aSE.GetShape());
1735 AddParam(theParams, "UMin", aSE.GetUMin());
1736 AddParam(theParams, "UMax", aSE.GetUMax());
1737 AddParam(theParams, "VMin", aSE.GetVMin());
1738 AddParam(theParams, "VMax", aSE.GetVMax());
1741 case SURFACE_FROM_FACE:
1743 GEOMImpl_IShapeExtend aSE (function);
1745 theOperationName = "SURFACE_FROM_FACE";
1746 AddParam(theParams, "Face", aSE.GetShape());
1756 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1757 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1759 //modified by NIZNHY-PKV Wed Dec 28 13:48:31 2011f
1760 #include <TopoDS_Iterator.hxx>
1761 #include <TopTools_HSequenceOfShape.hxx>
1762 #include <ShapeAnalysis_FreeBounds.hxx>
1763 #include <TopTools_MapOfShape.hxx>
1764 #include <TopTools_MapOfOrientedShape.hxx>
1765 #include <BRep_Builder.hxx>
1766 #include <TopoDS_Wire.hxx>
1768 //=======================================================================
1769 //function : KeepEdgesOrder
1771 //=======================================================================
1773 void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
1774 const Handle(TopTools_HSequenceOfShape)& aWires)
1776 Standard_Integer aNbWires, aNbEdges;
1778 if (aEdges.IsNull()) {
1782 if (aWires.IsNull()) {
1786 aNbEdges=aEdges->Length();
1787 aNbWires=aWires->Length();
1788 if (!aNbEdges || !aNbWires) {
1792 Standard_Boolean bClosed;
1793 Standard_Integer i, j;
1795 TopoDS_Iterator aIt;
1797 TopTools_MapOfOrientedShape aMEx;
1799 for (i=1; i<=aNbWires; ++i) {
1800 const TopoDS_Shape& aWx=aWires->Value(i);
1803 aIt.Initialize (aWx);
1804 for (; aIt.More(); aIt.Next()) {
1805 const TopoDS_Shape& aEx=aIt.Value();
1810 for (j=1; j<=aNbEdges; ++j) {
1811 const TopoDS_Shape& aE=aEdges->Value(j);
1812 if (aMEx.Contains(aE)) {
1817 bClosed=aWx.Closed();
1818 aWy.Closed(bClosed);
1820 aWires->Append(aWy);
1821 }// for (i=1; i<=aNbWires; ++i) {
1823 aWires->Remove(1, aNbWires);
1826 //modified by NIZNHY-PKV Wed Dec 28 13:48:34 2011t