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_ListIteratorOfListOfShape.hxx>
77 #include <TopTools_ListOfShape.hxx>
78 #include <TopTools_MapOfShape.hxx>
79 #include <TopTools_HSequenceOfShape.hxx>
83 #include <GCPnts_AbscissaPoint.hxx>
85 #include <Geom_TrimmedCurve.hxx>
86 #include <Geom_RectangularTrimmedSurface.hxx>
87 #include <Geom_Surface.hxx>
88 #include <GeomAbs_CurveType.hxx>
89 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
90 #include <GeomConvert.hxx>
91 #include <GeomLProp.hxx>
93 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
94 #include <TColStd_SequenceOfReal.hxx>
95 #include <TColStd_HSequenceOfTransient.hxx>
96 #include <TColStd_Array1OfReal.hxx>
97 #include <TColGeom_SequenceOfCurve.hxx>
98 #include <TColGeom_Array1OfBSplineCurve.hxx>
99 #include <TColGeom_HArray1OfBSplineCurve.hxx>
101 #include <Precision.hxx>
103 #include <Standard_NullObject.hxx>
104 #include <Standard_TypeMismatch.hxx>
105 #include <Standard_ConstructionError.hxx>
107 #include <BOPAlgo_PaveFiller.hxx>
108 #include <BOPAlgo_MakerVolume.hxx>
114 // check that compound includes only shapes of expected type
115 bool checkCompound( TopoDS_Shape& c, TopAbs_ShapeEnum t )
117 TopoDS_Iterator it( c, Standard_True, Standard_True );
119 // empty compound is OK only if we explicitly create a compound of shapes
122 // => if expected type is TopAbs_SHAPE, we allow compound consisting of any shapes, this above check is enough
123 // => otherwise we have to check compound's content
124 // => compound sometimes can contain enclosed compound(s), we process them recursively and rebuild initial compound
126 if ( t != TopAbs_SHAPE ) {
128 std::list<TopoDS_Shape> compounds, shapes;
129 compounds.push_back( c );
130 while ( !compounds.empty() && result ) {
131 // check that compound contains only shapes of expected type
132 TopoDS_Shape cc = compounds.front();
133 compounds.pop_front();
134 it.Initialize( cc, Standard_True, Standard_True );
135 for ( ; it.More() && result; it.Next() ) {
136 TopAbs_ShapeEnum tt = it.Value().ShapeType();
137 if ( tt == TopAbs_COMPOUND || tt == TopAbs_COMPSOLID ) {
138 compounds.push_back( it.Value() );
141 shapes.push_back( it.Value() );
146 if ( shapes.empty() ) {
149 else if ( shapes.size() == 1 ) {
154 TopoDS_Compound newc;
155 b.MakeCompound( newc );
156 std::list<TopoDS_Shape> ::const_iterator sit;
157 for ( sit = shapes.begin(); sit != shapes.end(); ++sit )
168 * This function constructs a shell or a compound of shells from a set of faces and/or shells.
170 * @param theShapes is a set of faces and/or shells.
171 * @return a shell or a compound of shells.
173 TopoDS_Shape makeShellFromFaces
174 (const Handle(TColStd_HSequenceOfTransient) &theShapes)
176 const Standard_Integer aNbShapes = theShapes->Length();
178 TopTools_ListOfShape aListFaces;
179 TopTools_MapOfShape aMapFence;
180 BRep_Builder aBuilder;
182 // Fill the list of unique faces
183 for (i = 1; i <= aNbShapes; ++i) {
185 const Handle(GEOM_Function) aRefShape =
186 Handle(GEOM_Function)::DownCast(theShapes->Value(i));
188 if (aRefShape.IsNull()) {
189 Standard_NullObject::Raise("Face for shell construction is null");
193 const TopoDS_Shape aShape = aRefShape->GetValue();
195 if (aShape.IsNull()) {
196 Standard_NullObject::Raise("Face for shell construction is null");
200 const TopAbs_ShapeEnum aType = aShape.ShapeType();
202 if (aType == TopAbs_SHELL) {
204 TopExp_Explorer anExp(aShape, TopAbs_FACE);
206 for (; anExp.More(); anExp.Next()) {
207 const TopoDS_Shape &aFace = anExp.Current();
209 if (aMapFence.Add(aFace)) {
210 aListFaces.Append(aFace);
213 } else if (aType == TopAbs_FACE) {
214 // Append the face in the list
215 if (aMapFence.Add(aShape)) {
216 aListFaces.Append(aShape);
219 Standard_TypeMismatch::Raise
220 ("Shape for shell construction is neither a shell nor a face");
224 // Perform computation of shells.
225 TopTools_ListOfShape aListShells;
226 TopTools_ListIteratorOfListOfShape anIter;
228 while (!aListFaces.IsEmpty()) {
230 BRepBuilderAPI_Sewing aSewing(Precision::Confusion()*10.0);
232 for (anIter.Initialize(aListFaces); anIter.More(); anIter.Next()) {
233 aSewing.Add(anIter.Value());
238 // Fill list of shells.
239 const TopoDS_Shape &aSewed = aSewing.SewedShape();
240 TopExp_Explorer anExp(aSewed, TopAbs_SHELL);
241 Standard_Boolean isNewShells = Standard_False;
244 for (; anExp.More(); anExp.Next()) {
245 aListShells.Append(anExp.Current());
246 isNewShells = Standard_True;
249 // Append single faces.
250 anExp.Init(aSewed, TopAbs_FACE, TopAbs_SHELL);
252 for (; anExp.More(); anExp.Next()) {
255 aBuilder.MakeShell(aShell);
256 aBuilder.Add(aShell, anExp.Current());
257 aListShells.Append(aShell);
258 isNewShells = Standard_True;
262 // There are no more shell can be obtained. Break the loop.
266 // Remove faces that are in the result from the list.
267 TopTools_IndexedMapOfShape aMapFaces;
269 TopExp::MapShapes(aSewed, TopAbs_FACE, aMapFaces);
271 // Add deleted faces to the map
272 const Standard_Integer aNbDelFaces = aSewing.NbDeletedFaces();
274 for (i = 1; i <= aNbDelFaces; ++i) {
275 aMapFaces.Add(aSewing.DeletedFace(i));
278 for (anIter.Initialize(aListFaces); anIter.More();) {
279 const TopoDS_Shape &aFace = anIter.Value();
280 Standard_Boolean isFaceUsed = Standard_False;
282 if (aMapFaces.Contains(aFace) || aSewing.IsModified(aFace)) {
283 // Remove face from the list.
284 aListFaces.Remove(anIter);
286 // Go to the next face.
292 // If there are faces not used in shells create a shell for each face.
293 for (anIter.Initialize(aListFaces); anIter.More(); anIter.Next()) {
296 aBuilder.MakeShell(aShell);
297 aBuilder.Add(aShell, anIter.Value());
298 aListShells.Append(aShell);
301 // Construct the result that can be either a shell or a compound of shells
302 TopoDS_Shape aResult;
304 if (!aListShells.IsEmpty()) {
305 if (aListShells.Extent() == 1) {
306 aResult = aListShells.First();
308 // There are more then one shell.
309 TopoDS_Compound aCompound;
311 aBuilder.MakeCompound(aCompound);
313 for (anIter.Initialize(aListShells); anIter.More(); anIter.Next()) {
314 aBuilder.Add(aCompound, anIter.Value());
327 //modified by NIZNHY-PKV Wed Dec 28 13:48:20 2011f
329 // void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
330 // const Handle(TopTools_HSequenceOfShape)& aWires);
331 //modified by NIZNHY-PKV Wed Dec 28 13:48:23 2011t
333 //=======================================================================
336 //=======================================================================
337 const Standard_GUID& GEOMImpl_ShapeDriver::GetID()
339 static Standard_GUID aShapeDriver("FF1BBB54-5D14-4df2-980B-3A668264EA16");
344 //=======================================================================
345 //function : GEOMImpl_ShapeDriver
347 //=======================================================================
348 GEOMImpl_ShapeDriver::GEOMImpl_ShapeDriver()
352 //=======================================================================
355 //=======================================================================
356 Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
358 if (Label().IsNull()) return 0;
359 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
361 GEOMImpl_IShapes aCI (aFunction);
362 Standard_Integer aType = aFunction->GetType();
365 TCollection_AsciiString aWarning;
367 // this is an exact type of expected shape, or shape in a compound if compound is allowed as a result (see below)
368 TopAbs_ShapeEnum anExpectedType = TopAbs_SHAPE;
369 // this should be true if result can be a compound of shapes of strict type (see above)
370 bool allowCompound = false;
374 if (aType == WIRE_EDGES) {
375 // result may be only a single wire
376 anExpectedType = TopAbs_WIRE;
378 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
380 Standard_Real aTolerance = aCI.GetTolerance();
381 if (aTolerance < Precision::Confusion())
382 aTolerance = Precision::Confusion();
384 aShape = MakeWireFromEdges(aShapes, aTolerance);
386 else if (aType == FACE_WIRE) {
387 // result may be a face or a compound of faces
388 anExpectedType = TopAbs_FACE;
389 allowCompound = true;
391 Handle(GEOM_Function) aRefBase = aCI.GetBase();
392 TopoDS_Shape aShapeBase = aRefBase->GetValue();
393 if (aShapeBase.IsNull()) Standard_NullObject::Raise("Argument Shape is null");
395 if (aShapeBase.ShapeType() == TopAbs_WIRE) {
396 W = TopoDS::Wire(aShapeBase);
397 // check the wire is closed
398 TopoDS_Vertex aV1, aV2;
399 TopExp::Vertices(W, aV1, aV2);
400 if ( !aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2) )
401 aShapeBase.Closed(true);
403 Standard_NullObject::Raise
404 ("Shape for face construction is not closed");
406 else if (aShapeBase.ShapeType() == TopAbs_EDGE && BRep_Tool::IsClosed(aShapeBase)) {
407 BRepBuilderAPI_MakeWire MW;
408 MW.Add(TopoDS::Edge(aShapeBase));
410 Standard_ConstructionError::Raise("Wire construction failed");
415 Standard_NullObject::Raise
416 ("Shape for face construction is neither a wire nor a closed edge");
418 aWarning = GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), aShape);
419 if (aShape.IsNull()) {
420 Standard_ConstructionError::Raise("Face construction failed");
423 else if (aType == FACE_WIRES) {
424 // result may be a face or a compound of faces
425 anExpectedType = TopAbs_FACE;
426 allowCompound = true;
428 // Try to build a face from a set of wires and edges
431 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
432 int nbshapes = aShapes->Length();
434 Standard_ConstructionError::Raise("No wires or edges given");
437 // 1. Extract all edges from the given arguments
438 TopTools_MapOfShape aMapEdges;
439 Handle(TopTools_HSequenceOfShape) aSeqEdgesIn = new TopTools_HSequenceOfShape;
440 TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
442 for (ind = 1; ind <= nbshapes; ind++) {
443 Handle(GEOM_Function) aRefSh_i = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
444 TopoDS_Shape aSh_i = aRefSh_i->GetValue();
446 TopExp_Explorer anExpE_i (aSh_i, TopAbs_EDGE);
447 for (; anExpE_i.More(); anExpE_i.Next()) {
448 if (aMapEdges.Add(anExpE_i.Current())) {
449 // Copy the original shape.
450 TopoDS_Shape aShapeCopy;
452 TNaming_CopyShape::CopyTool
453 (anExpE_i.Current(), aMapTShapes, aShapeCopy);
454 aSeqEdgesIn->Append(aShapeCopy);
459 if (aSeqEdgesIn->IsEmpty()) {
460 Standard_ConstructionError::Raise("No edges given");
463 // 2. Connect edges to wires of maximum length
464 Handle(TopTools_HSequenceOfShape) aSeqWiresOut;
465 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdgesIn, Precision::Confusion(),
466 /*shared*/Standard_False, aSeqWiresOut);
467 //modified by NIZNHY-PKV Wed Dec 28 13:46:55 2011f
468 //KeepEdgesOrder(aSeqEdgesIn, aSeqWiresOut);
469 //modified by NIZNHY-PKV Wed Dec 28 13:46:59 2011t
471 // 3. Separate closed wires
472 Handle(TopTools_HSequenceOfShape) aSeqClosedWires = new TopTools_HSequenceOfShape;
473 Handle(TopTools_HSequenceOfShape) aSeqOpenWires = new TopTools_HSequenceOfShape;
474 for (ind = 1; ind <= aSeqWiresOut->Length(); ind++) {
475 if (aSeqWiresOut->Value(ind).Closed())
476 aSeqClosedWires->Append(aSeqWiresOut->Value(ind));
478 aSeqOpenWires->Append(aSeqWiresOut->Value(ind));
481 if (aSeqClosedWires->Length() < 1) {
482 Standard_ConstructionError::Raise
483 ("There is no closed contour can be built from the given arguments");
486 // 4. Build a face / list of faces from all the obtained closed wires
490 TopoDS_Wire aW1 = TopoDS::Wire(aSeqClosedWires->Value(1));
491 aWarning = GEOMImpl_Block6Explorer::MakeFace(aW1, aCI.GetIsPlanar(), aFFace);
492 if (aFFace.IsNull()) {
493 Standard_ConstructionError::Raise("Face construction failed");
496 // 4.b. Add other wires
497 if (aSeqClosedWires->Length() == 1) {
502 BRep_Builder aBuilder;
503 aBuilder.MakeCompound(C);
504 BRepAlgo_FaceRestrictor FR;
506 TopAbs_Orientation OriF = aFFace.Orientation();
507 TopoDS_Shape aLocalS = aFFace.Oriented(TopAbs_FORWARD);
508 FR.Init(TopoDS::Face(aLocalS), Standard_False, Standard_True);
510 for (ind = 1; ind <= aSeqClosedWires->Length(); ind++) {
511 TopoDS_Wire aW = TopoDS::Wire(aSeqClosedWires->Value(ind));
520 for (; FR.More(); FR.Next()) {
521 aFace = FR.Current().Oriented(OriF);
522 aBuilder.Add(C, aFace);
533 // 5. Add all open wires to the result
534 if (aSeqOpenWires->Length() > 0) {
535 //Standard_ConstructionError::Raise("There are some open wires");
537 BRep_Builder aBuilder;
538 if (aSeqClosedWires->Length() == 1) {
539 aBuilder.MakeCompound(C);
540 aBuilder.Add(C, aShape);
543 C = TopoDS::Compound(aShape);
546 for (ind = 1; ind <= aSeqOpenWires->Length(); ind++) {
547 aBuilder.Add(C, aSeqOpenWires->Value(ind));
553 else if (aType == FACE_FROM_SURFACE) {
554 // result may be only a face
555 anExpectedType = TopAbs_FACE;
557 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
559 if (aShapes.IsNull() == Standard_False) {
560 Standard_Integer aNbShapes = aShapes->Length();
562 if (aNbShapes == 2) {
563 Handle(GEOM_Function) aRefFace =
564 Handle(GEOM_Function)::DownCast(aShapes->Value(1));
565 Handle(GEOM_Function) aRefWire =
566 Handle(GEOM_Function)::DownCast(aShapes->Value(2));
568 if (aRefFace.IsNull() == Standard_False &&
569 aRefWire.IsNull() == Standard_False) {
570 TopoDS_Shape aShFace = aRefFace->GetValue();
571 TopoDS_Shape aShWire = aRefWire->GetValue();
573 if (aShFace.IsNull() == Standard_False &&
574 aShFace.ShapeType() == TopAbs_FACE &&
575 aShWire.IsNull() == Standard_False &&
576 aShWire.ShapeType() == TopAbs_WIRE) {
577 TopoDS_Face aFace = TopoDS::Face(aShFace);
578 TopoDS_Wire aWire = TopoDS::Wire(aShWire);
579 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
580 BRepBuilderAPI_MakeFace aMkFace(aSurf, aWire);
582 if (aMkFace.IsDone()) {
583 aShape = aMkFace.Shape();
590 else if (aType == SHELL_FACES) {
591 // result may be only a shell or a compound of shells
592 anExpectedType = TopAbs_SHELL;
593 allowCompound = true;
595 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
597 if (aShapes.IsNull()) {
598 Standard_NullObject::Raise("Argument Shapes is null");
601 // Compute a shell or a compound of shells.
602 aShape = makeShellFromFaces(aShapes);
604 else if (aType == SOLID_SHELLS) {
605 // result may be only a solid or a compound of solids
606 anExpectedType = TopAbs_SOLID;
607 allowCompound = true;
609 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
610 unsigned int ind, nbshapes = aShapes->Length();
611 Standard_Integer ish = 0;
612 BRepBuilderAPI_MakeSolid aMkSolid;
615 for (ind = 1; ind <= nbshapes; ind++) {
616 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
617 TopoDS_Shape aShapeShell = aRefShape->GetValue();
618 if (aShapeShell.IsNull()) {
619 Standard_NullObject::Raise("Shell for solid construction is null");
621 if (aShapeShell.ShapeType() == TopAbs_COMPOUND) {
622 TopoDS_Iterator It (aShapeShell, Standard_True, Standard_True);
623 for (; It.More(); It.Next()) {
624 TopoDS_Shape aSubShape = It.Value();
625 if (aSubShape.ShapeType() == TopAbs_SHELL) {
626 aMkSolid.Add(TopoDS::Shell(aSubShape));
630 Standard_TypeMismatch::Raise
631 ("Shape for solid construction is neither a shell nor a compound of shells");
634 else if (aShapeShell.ShapeType() == TopAbs_SHELL) {
635 aMkSolid.Add(TopoDS::Shell(aShapeShell));
639 if (ish == 0 || !aMkSolid.IsDone()) return 0;
641 TopoDS_Solid Sol = aMkSolid.Solid();
642 BRepClass3d_SolidClassifier SC (Sol);
643 SC.PerformInfinitePoint(Precision::Confusion());
644 if (SC.State() == TopAbs_IN)
645 aShape = Sol.Reversed();
649 else if (aType == COMPOUND_SHAPES) {
650 // result may be only a compound of any shapes
651 allowCompound = true;
653 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
654 unsigned int ind, nbshapes = aShapes->Length();
659 for (ind = 1; ind <= nbshapes; ind++) {
660 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
661 TopoDS_Shape aShape_i = aRefShape->GetValue();
662 if (aShape_i.IsNull()) {
663 Standard_NullObject::Raise("Shape for compound construction is null");
671 else if (aType == EDGE_WIRE) {
672 // result may be only an edge
673 anExpectedType = TopAbs_EDGE;
675 Handle(GEOM_Function) aRefBase = aCI.GetBase();
676 TopoDS_Shape aWire = aRefBase->GetValue();
677 Standard_Real LinTol = aCI.GetTolerance();
678 Standard_Real AngTol = aCI.GetAngularTolerance();
679 if (aWire.IsNull()) Standard_NullObject::Raise("Argument Wire is null");
681 aShape = MakeEdgeFromWire(aWire, LinTol, AngTol);
683 else if (aType == SOLID_FACES) {
684 // result may be only a solid or a compound of solids
685 anExpectedType = TopAbs_SOLID;
686 allowCompound = true;
688 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
689 unsigned int ind, nbshapes = aShapes->Length();
692 BOPCol_ListOfShape aLS;
693 for (ind = 1; ind <= nbshapes; ind++) {
694 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
695 TopoDS_Shape aShape_i = aRefShape->GetValue();
696 if (aShape_i.IsNull()) {
697 Standard_NullObject::Raise("Shape for solid construction is null");
699 if (aShape_i.ShapeType() == TopAbs_COMPOUND) {
700 TopoDS_Iterator It (aShape_i, Standard_True, Standard_True);
701 for (; It.More(); It.Next()) {
702 TopoDS_Shape aSubShape = It.Value();
703 if (aSubShape.ShapeType() == TopAbs_FACE || aSubShape.ShapeType() == TopAbs_SHELL)
704 aLS.Append(aSubShape);
706 Standard_TypeMismatch::Raise
707 ("Shape for solid construction is neither a list of faces and/or shells "
708 "nor a compound of faces and/or shells");
711 aLS.Append(aShape_i);
714 BOPAlgo_MakerVolume aMV;
715 aMV.SetArguments(aLS);
716 aMV.SetIntersect(aCI.GetIsIntersect());
718 if (aMV.ErrorStatus()) return 0;
720 aShape = aMV.Shape();
722 else if (aType == EDGE_CURVE_LENGTH) {
723 // result may be only an edge
724 anExpectedType = TopAbs_EDGE;
726 GEOMImpl_IVector aVI (aFunction);
729 Handle(GEOM_Function) aRefCurve = aVI.GetPoint1();
730 if (aRefCurve.IsNull()) Standard_NullObject::Raise("Argument Curve is null");
731 TopoDS_Shape aRefShape1 = aRefCurve->GetValue();
732 if (aRefShape1.ShapeType() != TopAbs_EDGE) {
733 Standard_TypeMismatch::Raise
734 ("Edge On Curve creation aborted : curve shape is not an edge");
736 TopoDS_Edge aRefEdge = TopoDS::Edge(aRefShape1);
737 TopoDS_Vertex V1, V2;
738 TopExp::Vertices(aRefEdge, V1, V2, Standard_True);
741 TopoDS_Vertex aRefVertex;
742 Handle(GEOM_Function) aRefPoint = aVI.GetPoint2();
743 if (aRefPoint.IsNull()) {
747 TopoDS_Shape aRefShape2 = aRefPoint->GetValue();
748 if (aRefShape2.ShapeType() != TopAbs_VERTEX) {
749 Standard_TypeMismatch::Raise
750 ("Edge On Curve creation aborted : start point shape is not a vertex");
752 aRefVertex = TopoDS::Vertex(aRefShape2);
754 gp_Pnt aRefPnt = BRep_Tool::Pnt(aRefVertex);
757 Standard_Real aLength = aVI.GetParameter();
758 //Standard_Real aCurveLength = IntTools::Length(aRefEdge);
759 //if (aLength > aCurveLength) {
760 // Standard_ConstructionError::Raise
761 // ("Edge On Curve creation aborted : given length is greater than edges length");
763 if (fabs(aLength) < Precision::Confusion()) {
764 Standard_ConstructionError::Raise
765 ("Edge On Curve creation aborted : given length is smaller than Precision::Confusion()");
769 Standard_Real UFirst, ULast;
770 Handle(Geom_Curve) EdgeCurve = BRep_Tool::Curve(aRefEdge, UFirst, ULast);
771 Handle(Geom_Curve) ReOrientedCurve = EdgeCurve;
773 Standard_Real dU = ULast - UFirst;
774 Standard_Real par1 = UFirst + 0.1 * dU;
775 Standard_Real par2 = ULast - 0.1 * dU;
777 gp_Pnt P1 = EdgeCurve->Value(par1);
778 gp_Pnt P2 = EdgeCurve->Value(par2);
780 if (aRefPnt.SquareDistance(P2) < aRefPnt.SquareDistance(P1)) {
781 ReOrientedCurve = EdgeCurve->Reversed();
782 UFirst = EdgeCurve->ReversedParameter(ULast);
785 // Get the point by length
786 GeomAdaptor_Curve AdapCurve = GeomAdaptor_Curve(ReOrientedCurve);
787 GCPnts_AbscissaPoint anAbsPnt (AdapCurve, aLength, UFirst);
788 Standard_Real aParam = anAbsPnt.Parameter();
790 if (AdapCurve.IsClosed() && aLength < 0.0) {
791 Standard_Real aTmp = aParam;
796 BRepBuilderAPI_MakeEdge aME (ReOrientedCurve, UFirst, aParam);
798 aShape = aME.Shape();
800 else if (aType == SHAPE_ISOLINE) {
801 // result may be only an edge or compound of edges
802 anExpectedType = TopAbs_EDGE;
803 allowCompound = true;
805 GEOMImpl_IIsoline aII (aFunction);
806 Handle(GEOM_Function) aRefFace = aII.GetFace();
807 TopoDS_Shape aShapeFace = aRefFace->GetValue();
809 if (aShapeFace.ShapeType() == TopAbs_FACE) {
810 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
811 bool isUIso = aII.GetIsUIso();
812 Standard_Real aParam = aII.GetParameter();
813 Standard_Real U1,U2,V1,V2;
815 // Construct a real geometric parameter.
816 aFace.Orientation(TopAbs_FORWARD);
817 ShapeAnalysis::GetFaceUVBounds(aFace,U1,U2,V1,V2);
820 aParam = U1 + (U2 - U1)*aParam;
822 aParam = V1 + (V2 - V1)*aParam;
825 aShape = MakeIsoline(aFace, isUIso, aParam);
827 Standard_NullObject::Raise
828 ("Shape for isoline construction is not a face");
831 else if (aType == EDGE_UV) {
832 // result may be only an edge
833 anExpectedType = TopAbs_EDGE;
835 GEOMImpl_IShapeExtend aSE (aFunction);
836 Handle(GEOM_Function) aRefEdge = aSE.GetShape();
837 TopoDS_Shape aShapeEdge = aRefEdge->GetValue();
839 if (aShapeEdge.ShapeType() == TopAbs_EDGE) {
840 TopoDS_Edge anEdge = TopoDS::Edge(aShapeEdge);
842 aShape = ExtendEdge(anEdge, aSE.GetUMin(), aSE.GetUMax());
845 else if (aType == FACE_UV) {
846 // result may be only a face
847 anExpectedType = TopAbs_FACE;
849 GEOMImpl_IShapeExtend aSE (aFunction);
850 Handle(GEOM_Function) aRefFace = aSE.GetShape();
851 TopoDS_Shape aShapeFace = aRefFace->GetValue();
853 if (aShapeFace.ShapeType() == TopAbs_FACE) {
854 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
856 aFace.Orientation(TopAbs_FORWARD);
857 aShape = ExtendFace(aFace, aSE.GetUMin(), aSE.GetUMax(),
858 aSE.GetVMin(), aSE.GetVMax());
861 else if (aType == SURFACE_FROM_FACE) {
862 // result may be only a face
863 anExpectedType = TopAbs_FACE;
865 GEOMImpl_IShapeExtend aSE (aFunction);
866 Handle(GEOM_Function) aRefFace = aSE.GetShape();
867 TopoDS_Shape aShapeFace = aRefFace->GetValue();
869 if (aShapeFace.ShapeType() == TopAbs_FACE) {
870 TopoDS_Face aFace = TopoDS::Face(aShapeFace);
871 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
873 if (aSurface.IsNull() == Standard_False) {
874 Handle(Standard_Type) aType = aSurface->DynamicType();
880 // Get U, V bounds of the face.
881 aFace.Orientation(TopAbs_FORWARD);
882 ShapeAnalysis::GetFaceUVBounds(aFace, aU1, aU2, aV1, aV2);
884 // Get the surface of original type
885 while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
886 Handle(Geom_RectangularTrimmedSurface) aTrSurface =
887 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
889 aSurface = aTrSurface->BasisSurface();
890 aType = aSurface->DynamicType();
893 const Standard_Real aTol = BRep_Tool::Tolerance(aFace);
894 BRepBuilderAPI_MakeFace aMF(aSurface, aU1, aU2, aV1, aV2, aTol);
897 aShape = aMF.Shape();
905 if (aShape.IsNull()) return 0;
907 // Check shape validity
908 BRepCheck_Analyzer ana (aShape, true);
909 if (!ana.IsValid()) {
910 //Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
911 // For Mantis issue 0021772: EDF 2336 GEOM: Non valid face created from two circles
912 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape (aShape);
914 aShape = aSfs->Shape();
917 // Check if the result shape is of expected type.
918 const TopAbs_ShapeEnum aShType = aShape.ShapeType();
921 if ( aShType == TopAbs_COMPOUND || aShType == TopAbs_COMPSOLID ) {
922 ok = allowCompound && checkCompound( aShape, anExpectedType );
925 ok = ( anExpectedType == TopAbs_SHAPE ) || ( aShType == anExpectedType );
928 Standard_ConstructionError::Raise("Result type check failed");
930 aFunction->SetValue(aShape);
932 log.SetTouched(Label());
934 if (!aWarning.IsEmpty())
935 Standard_Failure::Raise(aWarning.ToCString());
940 TopoDS_Wire GEOMImpl_ShapeDriver::MakeWireFromEdges(const Handle(TColStd_HSequenceOfTransient)& theEdgesFuncs,
941 const Standard_Real theTolerance)
949 for (unsigned int ind = 1; ind <= theEdgesFuncs->Length(); ind++) {
950 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(theEdgesFuncs->Value(ind));
951 TopoDS_Shape aShape_i = aRefShape->GetValue();
952 if (aShape_i.IsNull()) {
953 Standard_NullObject::Raise("Shape for wire construction is null");
955 if (aShape_i.ShapeType() == TopAbs_EDGE || aShape_i.ShapeType() == TopAbs_WIRE) {
956 TopExp_Explorer exp (aShape_i, TopAbs_EDGE);
957 for (; exp.More(); exp.Next())
958 B.Add(aWire, TopoDS::Edge(exp.Current()));
960 Standard_TypeMismatch::Raise
961 ("Shape for wire construction is neither an edge nor a wire");
966 Handle(ShapeFix_Wire) aFW = new ShapeFix_Wire;
970 if (aFW->StatusReorder(ShapeExtend_FAIL1)) {
971 Standard_ConstructionError::Raise("Wire construction failed: several loops detected");
973 else if (aFW->StatusReorder(ShapeExtend_FAIL)) {
974 Standard_ConstructionError::Raise("Wire construction failed");
979 // IMP 0019766: Building a Wire from unconnected edges by introducing a tolerance
980 aFW->ClosedWireMode() = Standard_False;
981 aFW->FixConnected(theTolerance);
982 if (aFW->StatusConnected(ShapeExtend_FAIL)) {
983 Standard_ConstructionError::Raise("Wire construction failed: cannot build connected wire");
986 if (aFW->StatusConnected(ShapeExtend_DONE3)) {
987 // Confused with <prec> but not Analyzer.Precision(), set the same
988 aFW->FixGapsByRangesMode() = Standard_True;
989 if (aFW->FixGaps3d()) {
990 Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
991 Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
992 for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
993 TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
994 aFe->FixVertexTolerance(aEdge);
995 aFe->FixSameParameter(aEdge);
998 else if (aFW->StatusGaps3d(ShapeExtend_FAIL)) {
999 Standard_ConstructionError::Raise("Wire construction failed: cannot fix 3d gaps");
1002 aWire = aFW->WireAPIMake();
1007 TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
1008 const Standard_Real LinTol,
1009 const Standard_Real AngTol)
1011 TopoDS_Edge ResEdge;
1013 BRepLib::BuildCurves3d(aWire);
1014 Handle(ShapeFix_Shape) Fixer = new ShapeFix_Shape(aWire);
1015 Fixer->SetPrecision(LinTol);
1016 Fixer->SetMaxTolerance(LinTol);
1018 TopoDS_Wire theWire = TopoDS::Wire(Fixer->Shape());
1020 TColGeom_SequenceOfCurve CurveSeq;
1021 TopTools_SequenceOfShape LocSeq;
1022 TColStd_SequenceOfReal FparSeq;
1023 TColStd_SequenceOfReal LparSeq;
1024 TColStd_SequenceOfReal TolSeq;
1025 GeomAbs_CurveType CurType;
1026 TopoDS_Vertex FirstVertex, LastVertex;
1027 Standard_Real aPntShiftDist = 0.;
1029 BRepTools_WireExplorer wexp(theWire) ;
1030 for (; wexp.More(); wexp.Next())
1032 TopoDS_Edge anEdge = wexp.Current();
1033 Standard_Real fpar, lpar;
1034 TopLoc_Location aLoc;
1035 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aLoc, fpar, lpar);
1036 if (aCurve.IsNull())
1039 BRepAdaptor_Curve BAcurve(anEdge);
1040 GeomAbs_CurveType aType = BAcurve.GetType();
1042 Handle(Geom_Curve) aBasisCurve = BAcurve.Curve().Curve();
1044 if (aBasisCurve->IsPeriodic())
1045 ElCLib::AdjustPeriodic(aBasisCurve->FirstParameter(), aBasisCurve->LastParameter(),
1046 Precision::PConfusion(), fpar, lpar);
1048 if (CurveSeq.IsEmpty())
1050 CurveSeq.Append(aCurve);
1051 TopoDS_Shape aLocShape;
1052 aLocShape.Location(aLoc);
1053 aLocShape.Orientation(wexp.Orientation());
1054 LocSeq.Append(aLocShape);
1055 FparSeq.Append(fpar);
1056 LparSeq.Append(lpar);
1058 FirstVertex = wexp.CurrentVertex();
1062 Standard_Boolean Done = Standard_False;
1063 Standard_Real NewFpar, NewLpar;
1064 Handle(Geom_Geometry) aTrsfGeom = CurveSeq.Last()->Transformed
1065 (LocSeq.Last().Location().Transformation());
1066 GeomAdaptor_Curve GAprevcurve(Handle(Geom_Curve)::DownCast(aTrsfGeom));
1067 TopoDS_Vertex CurVertex = wexp.CurrentVertex();
1068 TopoDS_Vertex CurFirstVer = TopExp::FirstVertex(anEdge);
1069 TopAbs_Orientation ConnectByOrigin = (CurVertex.IsSame(CurFirstVer))? TopAbs_FORWARD : TopAbs_REVERSED;
1070 if (aCurve == CurveSeq.Last() && aLoc.IsEqual(LocSeq.Last().Location()))
1074 if (aBasisCurve->IsPeriodic())
1076 if (NewLpar < NewFpar)
1077 NewLpar += aBasisCurve->Period();
1078 if (ConnectByOrigin == TopAbs_FORWARD)
1079 ElCLib::AdjustPeriodic(FparSeq.Last(),
1080 FparSeq.Last() + aBasisCurve->Period(),
1081 Precision::PConfusion(), NewFpar, NewLpar);
1083 ElCLib::AdjustPeriodic(FparSeq.Last() - aBasisCurve->Period(),
1085 Precision::PConfusion(), NewFpar, NewLpar);
1087 Done = Standard_True;
1089 else if (aType == CurType &&
1090 aType != GeomAbs_BezierCurve &&
1091 aType != GeomAbs_BSplineCurve &&
1092 aType != GeomAbs_OtherCurve)
1098 gp_Lin aLine = BAcurve.Line();
1099 gp_Lin PrevLine = GAprevcurve.Line();
1100 if (aLine.Contains(PrevLine.Location(), LinTol) &&
1101 aLine.Direction().IsParallel(PrevLine.Direction(), AngTol))
1103 gp_Pnt P1 = ElCLib::Value(fpar, aLine);
1104 gp_Pnt P2 = ElCLib::Value(lpar, aLine);
1105 NewFpar = ElCLib::Parameter(PrevLine, P1);
1106 NewLpar = ElCLib::Parameter(PrevLine, P2);
1109 if (ConnectByOrigin == TopAbs_FORWARD) {
1110 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevLine);
1112 aPntShiftDist += P2.Distance(aNewP2);
1114 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevLine);
1116 aPntShiftDist += P1.Distance(aNewP1);
1119 if (NewLpar < NewFpar)
1121 Standard_Real MemNewFpar = NewFpar;
1123 NewLpar = MemNewFpar;
1124 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1126 Done = Standard_True;
1130 case GeomAbs_Circle:
1132 gp_Circ aCircle = BAcurve.Circle();
1133 gp_Circ PrevCircle = GAprevcurve.Circle();
1134 if (aCircle.Location().Distance(PrevCircle.Location()) <= LinTol &&
1135 Abs(aCircle.Radius() - PrevCircle.Radius()) <= LinTol &&
1136 aCircle.Axis().IsParallel(PrevCircle.Axis(), AngTol))
1138 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
1140 if (aCircle.Axis().Direction() * PrevCircle.Axis().Direction() < 0.)
1142 Standard_Real memfpar = fpar;
1145 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1147 gp_Pnt P1 = ElCLib::Value(fpar, aCircle);
1148 gp_Pnt P2 = ElCLib::Value(lpar, aCircle);
1149 NewFpar = ElCLib::Parameter(PrevCircle, P1);
1150 NewLpar = ElCLib::Parameter(PrevCircle, P2);
1154 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevCircle);
1156 aPntShiftDist += P2.Distance(aNewP2);
1158 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevCircle);
1160 aPntShiftDist += P1.Distance(aNewP1);
1163 if (NewLpar < NewFpar)
1165 //Standard_Real MemNewFpar = NewFpar, MemNewLpar = NewLpar;
1166 if (ConnectByOrigin == TopAbs_FORWARD)
1167 ElCLib::AdjustPeriodic(FparSeq.Last(),
1168 FparSeq.Last() + 2.*M_PI,
1169 Precision::PConfusion(), NewFpar, NewLpar);
1171 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
1173 Precision::PConfusion(), NewFpar, NewLpar);
1174 Done = Standard_True;
1178 case GeomAbs_Ellipse:
1180 gp_Elips anEllipse = BAcurve.Ellipse();
1181 gp_Elips PrevEllipse = GAprevcurve.Ellipse();
1182 if (anEllipse.Focus1().Distance(PrevEllipse.Focus1()) <= LinTol &&
1183 anEllipse.Focus2().Distance(PrevEllipse.Focus2()) <= LinTol &&
1184 Abs(anEllipse.MajorRadius() - PrevEllipse.MajorRadius()) <= LinTol &&
1185 Abs(anEllipse.MinorRadius() - PrevEllipse.MinorRadius()) <= LinTol &&
1186 anEllipse.Axis().IsParallel(PrevEllipse.Axis(), AngTol))
1188 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
1190 if (anEllipse.Axis().Direction() * PrevEllipse.Axis().Direction() < 0.)
1192 Standard_Real memfpar = fpar;
1195 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1197 gp_Pnt P1 = ElCLib::Value(fpar, anEllipse);
1198 gp_Pnt P2 = ElCLib::Value(lpar, anEllipse);
1199 NewFpar = ElCLib::Parameter(PrevEllipse, P1);
1200 NewLpar = ElCLib::Parameter(PrevEllipse, P2);
1204 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevEllipse);
1206 aPntShiftDist += P2.Distance(aNewP2);
1208 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevEllipse);
1210 aPntShiftDist += P1.Distance(aNewP1);
1213 if (NewLpar < NewFpar)
1215 if (ConnectByOrigin == TopAbs_FORWARD)
1216 ElCLib::AdjustPeriodic(FparSeq.Last(),
1217 FparSeq.Last() + 2.*M_PI,
1218 Precision::PConfusion(), NewFpar, NewLpar);
1220 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
1222 Precision::PConfusion(), NewFpar, NewLpar);
1223 Done = Standard_True;
1227 case GeomAbs_Hyperbola:
1229 gp_Hypr aHypr = BAcurve.Hyperbola();
1230 gp_Hypr PrevHypr = GAprevcurve.Hyperbola();
1231 if (aHypr.Focus1().Distance(PrevHypr.Focus1()) <= LinTol &&
1232 aHypr.Focus2().Distance(PrevHypr.Focus2()) <= LinTol &&
1233 Abs(aHypr.MajorRadius() - PrevHypr.MajorRadius()) <= LinTol &&
1234 Abs(aHypr.MinorRadius() - PrevHypr.MinorRadius()) <= LinTol &&
1235 aHypr.Axis().IsParallel(PrevHypr.Axis(), AngTol))
1237 gp_Pnt P1 = ElCLib::Value(fpar, aHypr);
1238 gp_Pnt P2 = ElCLib::Value(lpar, aHypr);
1239 NewFpar = ElCLib::Parameter(PrevHypr, P1);
1240 NewLpar = ElCLib::Parameter(PrevHypr, P2);
1243 if (ConnectByOrigin == TopAbs_FORWARD) {
1244 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevHypr);
1246 aPntShiftDist += P2.Distance(aNewP2);
1248 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevHypr);
1250 aPntShiftDist += P1.Distance(aNewP1);
1253 if (NewLpar < NewFpar)
1255 Standard_Real MemNewFpar = NewFpar;
1257 NewLpar = MemNewFpar;
1258 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1260 Done = Standard_True;
1264 case GeomAbs_Parabola:
1266 gp_Parab aParab = BAcurve.Parabola();
1267 gp_Parab PrevParab = GAprevcurve.Parabola();
1268 if (aParab.Location().Distance(PrevParab.Location()) <= LinTol &&
1269 aParab.Focus().Distance(PrevParab.Focus()) <= LinTol &&
1270 Abs(aParab.Focal() - PrevParab.Focal()) <= LinTol &&
1271 aParab.Axis().IsParallel(PrevParab.Axis(), AngTol))
1273 gp_Pnt P1 = ElCLib::Value(fpar, aParab);
1274 gp_Pnt P2 = ElCLib::Value(lpar, aParab);
1275 NewFpar = ElCLib::Parameter(PrevParab, P1);
1276 NewLpar = ElCLib::Parameter(PrevParab, P2);
1279 if (ConnectByOrigin == TopAbs_FORWARD) {
1280 gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevParab);
1282 aPntShiftDist += P2.Distance(aNewP2);
1284 gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevParab);
1286 aPntShiftDist += P1.Distance(aNewP1);
1289 if (NewLpar < NewFpar)
1291 Standard_Real MemNewFpar = NewFpar;
1293 NewLpar = MemNewFpar;
1294 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1296 Done = Standard_True;
1300 } //end of switch (aType)
1301 } // end of else if (aType == CurType && ...
1304 if (NewFpar < FparSeq.Last())
1305 FparSeq(FparSeq.Length()) = NewFpar;
1307 LparSeq(LparSeq.Length()) = NewLpar;
1311 CurveSeq.Append(aCurve);
1312 TopoDS_Shape aLocShape;
1313 aLocShape.Location(aLoc);
1314 aLocShape.Orientation(wexp.Orientation());
1315 LocSeq.Append(aLocShape);
1316 FparSeq.Append(fpar);
1317 LparSeq.Append(lpar);
1318 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(CurVertex));
1322 } // end of else (CurveSeq.IsEmpty()) -> not first time
1323 } // end for (; wexp.More(); wexp.Next())
1325 LastVertex = wexp.CurrentVertex();
1326 TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(LastVertex));
1328 FirstVertex.Orientation(TopAbs_FORWARD);
1329 LastVertex.Orientation(TopAbs_REVERSED);
1331 if (!CurveSeq.IsEmpty())
1333 Standard_Integer nb_curve = CurveSeq.Length(); //number of curves
1334 TColGeom_Array1OfBSplineCurve tab(0,nb_curve-1); //array of the curves
1335 TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2); //array of the tolerances
1341 for (i = 1; i <= nb_curve; i++)
1343 if (CurveSeq(i)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1344 CurveSeq(i) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(i))))->BasisCurve();
1346 Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(CurveSeq(i), FparSeq(i), LparSeq(i));
1347 tab(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve);
1348 tab(i-1)->Transform(LocSeq(i).Location().Transformation());
1349 GeomConvert::C0BSplineToC1BSplineCurve(tab(i-1), Precision::Confusion());
1350 if (LocSeq(i).Orientation() == TopAbs_REVERSED)
1351 tab(i-1)->Reverse();
1354 //char* name = new char[100];
1355 //sprintf(name, "c%d", i);
1356 //DrawTrSurf::Set(name, tab(i-1));
1359 tabtolvertex(i-2) = TolSeq(i-1);
1360 } // end for (i = 1; i <= nb_curve; i++)
1361 tabtolvertex(nb_curve-1) = TolSeq(TolSeq.Length());
1363 Standard_Boolean closed_flag = Standard_False;
1364 Standard_Real closed_tolerance = 0.;
1365 if (FirstVertex.IsSame(LastVertex) &&
1366 GeomLProp::Continuity(tab(0), tab(nb_curve-1),
1367 tab(0)->FirstParameter(),
1368 tab(nb_curve-1)->LastParameter(),
1369 Standard_False, Standard_False, LinTol, AngTol) >= GeomAbs_G1)
1371 closed_flag = Standard_True ;
1372 closed_tolerance = BRep_Tool::Tolerance(FirstVertex);
1375 Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves
1376 Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex
1377 GeomConvert::ConcatC1(tab,
1382 closed_tolerance); //C1 concatenation
1384 if (concatcurve->Length() > 1)
1386 GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower()));
1388 for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++)
1389 Concat.Add( concatcurve->Value(i), LinTol, Standard_True );
1391 concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve());
1393 // rnc : prevents the driver from building an edge without C1 continuity
1394 if (concatcurve->Value(concatcurve->Lower())->Continuity()==GeomAbs_C0){
1395 Standard_ConstructionError::Raise("Construction aborted : The given Wire has sharp bends between some Edges, no valid Edge can be built");
1398 Standard_Boolean isValidEndVtx = Standard_True;
1401 // Check if closed curve is reordered.
1402 Handle(Geom_Curve) aCurve = concatcurve->Value(concatcurve->Lower());
1403 Standard_Real aFPar = aCurve->FirstParameter();
1405 gp_Pnt aPntVtx = BRep_Tool::Pnt(FirstVertex);
1406 Standard_Real aTolVtx = BRep_Tool::Tolerance(FirstVertex);
1408 aCurve->D0(aFPar, aPFirst);
1410 if (!aPFirst.IsEqual(aPntVtx, aTolVtx)) {
1411 // The curve is reordered. Find the new first and last vertices.
1412 TopTools_IndexedMapOfShape aMapVtx;
1413 TopExp::MapShapes(theWire, TopAbs_VERTEX, aMapVtx);
1415 const Standard_Integer aNbVtx = aMapVtx.Extent();
1416 Standard_Integer iVtx;
1418 for (iVtx = 1; iVtx <= aNbVtx; iVtx++) {
1419 const TopoDS_Vertex aVtx = TopoDS::Vertex(aMapVtx.FindKey(iVtx));
1420 const gp_Pnt aPnt = BRep_Tool::Pnt(aVtx);
1421 const Standard_Real aTol = BRep_Tool::Tolerance(aVtx);
1423 if (aPFirst.IsEqual(aPnt, aTol)) {
1424 // The coinsident vertex is found.
1427 FirstVertex.Orientation(TopAbs_FORWARD);
1428 LastVertex.Orientation(TopAbs_REVERSED);
1433 if (iVtx > aNbVtx) {
1434 // It is necessary to create new vertices.
1435 isValidEndVtx = Standard_False;
1440 if (isValidEndVtx) {
1441 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1442 FirstVertex, LastVertex,
1443 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1444 concatcurve->Value(concatcurve->Lower())->LastParameter());
1446 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1447 concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1448 concatcurve->Value(concatcurve->Lower())->LastParameter());
1453 if (CurveSeq(1)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1454 CurveSeq(1) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(1))))->BasisCurve();
1456 Handle(Geom_Curve) aNewCurve =
1457 Handle(Geom_Curve)::DownCast(CurveSeq(1)->Copy());
1459 aNewCurve->Transform(LocSeq(1).Location().Transformation());
1461 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1462 const TopoDS_Vertex aVtxTmp = FirstVertex;
1464 FirstVertex = LastVertex;
1465 LastVertex = aVtxTmp;
1466 FirstVertex.Orientation(TopAbs_FORWARD);
1467 LastVertex.Orientation(TopAbs_REVERSED);
1470 ResEdge = BRepLib_MakeEdge(aNewCurve,
1471 FirstVertex, LastVertex,
1472 FparSeq(1), LparSeq(1));
1474 if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1483 //=============================================================================
1485 * \brief Returns an isoline for a face.
1487 //=============================================================================
1489 TopoDS_Shape GEOMImpl_ShapeDriver::MakeIsoline
1490 (const TopoDS_Face &theFace,
1492 const double theParameter) const
1494 TopoDS_Shape aResult;
1495 GEOMUtils::Hatcher aHatcher(theFace);
1496 const GeomAbs_IsoType aType = (IsUIso ? GeomAbs_IsoU : GeomAbs_IsoV);
1498 aHatcher.Init(aType, theParameter);
1501 if (!aHatcher.IsDone()) {
1502 Standard_ConstructionError::Raise("MakeIsoline : Hatcher failure");
1505 const Handle(TColStd_HArray1OfInteger) &anIndices =
1506 (IsUIso ? aHatcher.GetUIndices() : aHatcher.GetVIndices());
1508 if (anIndices.IsNull()) {
1509 Standard_ConstructionError::Raise("MakeIsoline : Null hatching indices");
1512 const Standard_Integer anIsoInd = anIndices->Lower();
1513 const Standard_Integer aHatchingIndex = anIndices->Value(anIsoInd);
1515 if (aHatchingIndex == 0) {
1516 Standard_ConstructionError::Raise("MakeIsoline : Invalid hatching index");
1519 const Standard_Integer aNbDomains =
1520 aHatcher.GetNbDomains(aHatchingIndex);
1522 if (aNbDomains < 0) {
1523 Standard_ConstructionError::Raise("MakeIsoline : Invalid number of domains");
1526 // The hatching is performed successfully. Create the 3d Curve.
1527 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1528 Handle(Geom_Curve) anIsoCurve = (IsUIso ?
1529 aSurface->UIso(theParameter) : aSurface->VIso(theParameter));
1530 Handle(Geom2d_Curve) aPIsoCurve =
1531 aHatcher.GetHatching(aHatchingIndex);
1532 const Standard_Real aTol = Precision::Confusion();
1533 Standard_Integer anIDom = 1;
1536 BRep_Builder aBuilder;
1537 Standard_Integer aNbEdges = 0;
1539 for (; anIDom <= aNbDomains; anIDom++) {
1540 if (aHatcher.GetDomain(aHatchingIndex, anIDom, aV1, aV2)) {
1541 // Check first and last parameters.
1542 if (!aHatcher.IsDomainInfinite(aHatchingIndex, anIDom)) {
1544 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(anIsoCurve, aV1, aV2);
1546 // Update it with a parametric curve on face.
1547 aBuilder.UpdateEdge(anEdge, aPIsoCurve, theFace, aTol);
1551 // Result is a compond.
1552 if (aNbEdges == 2) {
1553 // Create a new compound.
1554 TopoDS_Compound aCompound;
1556 aBuilder.MakeCompound(aCompound);
1557 aBuilder.Add(aCompound, aResult);
1558 aResult = aCompound;
1561 // Add an edge to the compound.
1562 aBuilder.Add(aResult, anEdge);
1564 // Result is the edge.
1571 if (aNbEdges == 0) {
1572 Standard_ConstructionError::Raise("MakeIsoline : Empty result");
1578 //=============================================================================
1580 * \brief Returns an extended edge.
1582 //=============================================================================
1584 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendEdge
1585 (const TopoDS_Edge &theEdge,
1586 const Standard_Real theMin,
1587 const Standard_Real theMax) const
1589 TopoDS_Shape aResult;
1592 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(theEdge, aF, aL);
1593 const Standard_Real aTol = BRep_Tool::Tolerance(theEdge);
1594 Standard_Real aRange2d = aL - aF;
1596 if (aCurve.IsNull() == Standard_False && aRange2d > aTol) {
1597 Standard_Real aMin = aF + aRange2d*theMin;
1598 Standard_Real aMax = aF + aRange2d*theMax;
1600 Handle(Standard_Type) aType = aCurve->DynamicType();
1602 // Get the curve of original type
1603 while (aType == STANDARD_TYPE(Geom_TrimmedCurve)) {
1604 Handle(Geom_TrimmedCurve) aTrCurve =
1605 Handle(Geom_TrimmedCurve)::DownCast(aCurve);
1607 aCurve = aTrCurve->BasisCurve();
1608 aType = aCurve->DynamicType();
1611 if (aCurve->IsPeriodic()) {
1612 // The curve is periodic. Check if a new range is less then a period.
1613 if (aMax - aMin > aCurve->Period()) {
1614 aMax = aMin + aCurve->Period();
1617 // The curve is not periodic. Check if aMin and aMax within bounds.
1618 aMin = Max(aMin, aCurve->FirstParameter());
1619 aMax = Min(aMax, aCurve->LastParameter());
1622 if (aMax - aMin > aTol) {
1623 // Create a new edge.
1624 BRepBuilderAPI_MakeEdge aME (aCurve, aMin, aMax);
1627 aResult = aME.Shape();
1635 //=============================================================================
1637 * \brief Returns an extended face.
1639 //=============================================================================
1641 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendFace
1642 (const TopoDS_Face &theFace,
1643 const Standard_Real theUMin,
1644 const Standard_Real theUMax,
1645 const Standard_Real theVMin,
1646 const Standard_Real theVMax) const
1648 TopoDS_Shape aResult;
1649 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1650 const Standard_Real aTol = BRep_Tool::Tolerance(theFace);
1656 // Get U, V bounds of the face.
1657 ShapeAnalysis::GetFaceUVBounds(theFace, aU1, aU2, aV1, aV2);
1659 const Standard_Real aURange = aU2 - aU1;
1660 const Standard_Real aVRange = aV2 - aV1;
1662 if (aSurface.IsNull() == Standard_False &&
1663 aURange > aTol && aURange > aTol) {
1664 Handle(Standard_Type) aType = aSurface->DynamicType();
1666 // Get the surface of original type
1667 while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1668 Handle(Geom_RectangularTrimmedSurface) aTrSurface =
1669 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
1671 aSurface = aTrSurface->BasisSurface();
1672 aType = aSurface->DynamicType();
1675 Standard_Real aUMin = aU1 + aURange*theUMin;
1676 Standard_Real aUMax = aU1 + aURange*theUMax;
1677 Standard_Real aVMin = aV1 + aVRange*theVMin;
1678 Standard_Real aVMax = aV1 + aVRange*theVMax;
1680 aSurface->Bounds(aU1, aU2, aV1, aV2);
1682 if (aSurface->IsUPeriodic()) {
1683 // The surface is U-periodic. Check if a new U range is less
1685 if (aUMax - aUMin > aSurface->UPeriod()) {
1686 aUMax = aUMin + aSurface->UPeriod();
1689 // The surface is not V-periodic. Check if aUMin and aUMax
1691 aUMin = Max(aUMin, aU1);
1692 aUMax = Min(aUMax, aU2);
1695 if (aSurface->IsVPeriodic()) {
1696 // The surface is V-periodic. Check if a new V range is less
1698 if (aVMax - aVMin > aSurface->VPeriod()) {
1699 aVMax = aVMin + aSurface->VPeriod();
1702 // The surface is not V-periodic. Check if aVMin and aVMax
1704 aVMin = Max(aVMin, aV1);
1705 aVMax = Min(aVMax, aV2);
1708 if (aUMax - aUMin > aTol && aVMax - aVMin > aTol) {
1709 // Create a new edge.
1710 BRepBuilderAPI_MakeFace aMF
1711 (aSurface, aUMin, aUMax, aVMin, aVMax, aTol);
1714 aResult = aMF.Shape();
1722 //================================================================================
1724 * \brief Returns a name of creation operation and names and values of creation parameters
1726 //================================================================================
1728 bool GEOMImpl_ShapeDriver::
1729 GetCreationInformation(std::string& theOperationName,
1730 std::vector<GEOM_Param>& theParams)
1732 if (Label().IsNull()) return 0;
1733 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
1735 GEOMImpl_IShapes aCI( function );
1736 Standard_Integer aType = function->GetType();
1740 theOperationName = "WIRE";
1741 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1742 AddParam( theParams, "Tolerance", aCI.GetTolerance() );
1745 theOperationName = "FACE";
1746 AddParam( theParams, "Wire/edge", aCI.GetBase() );
1747 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1750 theOperationName = "FACE";
1751 AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1752 AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1754 case FACE_FROM_SURFACE:
1756 theOperationName = "FACE";
1758 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1760 if (shapes.IsNull() == Standard_False) {
1761 Standard_Integer aNbShapes = shapes->Length();
1763 if (aNbShapes > 0) {
1764 AddParam(theParams, "Face", shapes->Value(1));
1766 if (aNbShapes > 1) {
1767 AddParam(theParams, "Wire", shapes->Value(2));
1774 theOperationName = "SHELL";
1775 AddParam( theParams, "Objects", aCI.GetShapes() );
1778 theOperationName = "SOLID";
1779 AddParam( theParams, "Objects", aCI.GetShapes() );
1782 theOperationName = "SOLID_FROM_FACES";
1783 AddParam( theParams, "Objects", aCI.GetShapes() );
1784 AddParam( theParams, "Is intersect", aCI.GetIsIntersect() );
1786 case COMPOUND_SHAPES:
1787 theOperationName = "COMPOUND";
1788 AddParam( theParams, "Objects", aCI.GetShapes() );
1791 theOperationName = "EDGE";
1792 AddParam( theParams, "Wire", aCI.GetBase() );
1793 AddParam( theParams, "Linear Tolerance", aCI.GetTolerance() );
1794 AddParam( theParams, "Angular Tolerance", aCI.GetAngularTolerance() );
1796 case EDGE_CURVE_LENGTH:
1797 theOperationName = "EDGE";
1799 GEOMImpl_IVector aCI( function );
1800 AddParam( theParams, "Edge", aCI.GetPoint1() );
1801 AddParam( theParams, "Start point", aCI.GetPoint2() );
1802 AddParam( theParams, "Length", aCI.GetParameter() );
1805 case SHAPES_ON_SHAPE:
1807 theOperationName = "GetShapesOnShapeAsCompound";
1808 Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1809 if ( !shapes.IsNull() && shapes->Length() > 0 )
1810 AddParam( theParams, "Check shape", shapes->Value(1) );
1811 if ( !shapes.IsNull() && shapes->Length() > 1 )
1812 AddParam( theParams, "Shape", shapes->Value(2) );
1813 AddParam( theParams, "Shape type", TopAbs_ShapeEnum( aCI.GetSubShapeType() ));
1814 AddParam( theParams, "State" );
1815 GEOMAlgo_State st = GEOMAlgo_State( (int) ( aCI.GetTolerance()+0.1 ) );
1816 const char* stName[] = { "UNKNOWN","IN","OUT","ON","ONIN","ONOUT","INOUT" };
1817 if ( 0 <= st && st <= GEOMAlgo_ST_INOUT )
1818 theParams.back() << stName[ st ];
1820 theParams.back() << (int) st;
1825 GEOMImpl_IIsoline aII (function);
1827 theOperationName = "ISOLINE";
1828 AddParam(theParams, "Face", aII.GetFace());
1829 AddParam(theParams, "Isoline type", (aII.GetIsUIso() ? "U" : "V"));
1830 AddParam(theParams, "Parameter", aII.GetParameter());
1835 GEOMImpl_IShapeExtend aSE (function);
1837 theOperationName = "EDGE_EXTEND";
1838 AddParam(theParams, "Edge", aSE.GetShape());
1839 AddParam(theParams, "Min", aSE.GetUMin());
1840 AddParam(theParams, "Max", aSE.GetUMax());
1845 GEOMImpl_IShapeExtend aSE (function);
1847 theOperationName = "FACE_EXTEND";
1848 AddParam(theParams, "Face", aSE.GetShape());
1849 AddParam(theParams, "UMin", aSE.GetUMin());
1850 AddParam(theParams, "UMax", aSE.GetUMax());
1851 AddParam(theParams, "VMin", aSE.GetVMin());
1852 AddParam(theParams, "VMax", aSE.GetVMax());
1855 case SURFACE_FROM_FACE:
1857 GEOMImpl_IShapeExtend aSE (function);
1859 theOperationName = "SURFACE_FROM_FACE";
1860 AddParam(theParams, "Face", aSE.GetShape());
1870 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1871 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1873 //modified by NIZNHY-PKV Wed Dec 28 13:48:31 2011f
1874 #include <TopoDS_Iterator.hxx>
1875 #include <TopTools_HSequenceOfShape.hxx>
1876 #include <ShapeAnalysis_FreeBounds.hxx>
1877 #include <TopTools_MapOfShape.hxx>
1878 #include <TopTools_MapOfOrientedShape.hxx>
1879 #include <BRep_Builder.hxx>
1880 #include <TopoDS_Wire.hxx>
1882 //=======================================================================
1883 //function : KeepEdgesOrder
1885 //=======================================================================
1887 void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
1888 const Handle(TopTools_HSequenceOfShape)& aWires)
1890 Standard_Integer aNbWires, aNbEdges;
1892 if (aEdges.IsNull()) {
1896 if (aWires.IsNull()) {
1900 aNbEdges=aEdges->Length();
1901 aNbWires=aWires->Length();
1902 if (!aNbEdges || !aNbWires) {
1906 Standard_Boolean bClosed;
1907 Standard_Integer i, j;
1909 TopoDS_Iterator aIt;
1911 TopTools_MapOfOrientedShape aMEx;
1913 for (i=1; i<=aNbWires; ++i) {
1914 const TopoDS_Shape& aWx=aWires->Value(i);
1917 aIt.Initialize (aWx);
1918 for (; aIt.More(); aIt.Next()) {
1919 const TopoDS_Shape& aEx=aIt.Value();
1924 for (j=1; j<=aNbEdges; ++j) {
1925 const TopoDS_Shape& aE=aEdges->Value(j);
1926 if (aMEx.Contains(aE)) {
1931 bClosed=aWx.Closed();
1932 aWy.Closed(bClosed);
1934 aWires->Append(aWy);
1935 }// for (i=1; i<=aNbWires; ++i) {
1937 aWires->Remove(1, aNbWires);
1940 //modified by NIZNHY-PKV Wed Dec 28 13:48:34 2011t