1 // Copyright (C) 2007-2010 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.
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_IShapes.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOMImpl_Block6Explorer.hxx>
29 #include <GEOM_Function.hxx>
32 #include <ShapeFix_Wire.hxx>
33 #include <ShapeFix_Edge.hxx>
34 #include <ShapeFix_Shape.hxx>
36 #include <BRep_Tool.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRepAlgo_FaceRestrictor.hxx>
39 #include <BRepBuilderAPI_Sewing.hxx>
40 #include <BRepBuilderAPI_Copy.hxx>
41 #include <BRepCheck.hxx>
42 #include <BRepCheck_Analyzer.hxx>
43 #include <BRepCheck_Shell.hxx>
44 #include <BRepClass3d_SolidClassifier.hxx>
45 #include <BRepBuilderAPI_MakeWire.hxx>
46 #include <BRepBuilderAPI_Sewing.hxx>
47 #include <BRepLib.hxx>
48 #include <BRepLib_MakeEdge.hxx>
49 #include <BRepTools_WireExplorer.hxx>
50 #include <BRepAdaptor_Curve.hxx>
52 #include <ShapeAnalysis_FreeBounds.hxx>
57 #include <TopoDS_Shape.hxx>
58 #include <TopoDS_Edge.hxx>
59 #include <TopoDS_Wire.hxx>
60 #include <TopoDS_Shell.hxx>
61 #include <TopoDS_Solid.hxx>
62 #include <TopoDS_Compound.hxx>
63 #include <TopoDS_Iterator.hxx>
65 #include <TopExp_Explorer.hxx>
67 #include <TopTools_MapOfShape.hxx>
68 #include <TopTools_HSequenceOfShape.hxx>
70 #include <TColStd_SequenceOfReal.hxx>
71 #include <TColStd_HSequenceOfTransient.hxx>
72 #include <TColStd_Array1OfReal.hxx>
73 #include <TColGeom_SequenceOfCurve.hxx>
74 #include <TColGeom_Array1OfBSplineCurve.hxx>
75 #include <TColGeom_HArray1OfBSplineCurve.hxx>
77 #include <GeomAbs_CurveType.hxx>
78 #include <Geom_TrimmedCurve.hxx>
79 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
80 #include <GeomConvert.hxx>
81 #include <GeomLProp.hxx>
83 #include <Precision.hxx>
84 #include <Standard_NullObject.hxx>
85 #include <Standard_TypeMismatch.hxx>
86 #include <Standard_ConstructionError.hxx>
88 //=======================================================================
91 //=======================================================================
92 const Standard_GUID& GEOMImpl_ShapeDriver::GetID()
94 static Standard_GUID aShapeDriver("FF1BBB54-5D14-4df2-980B-3A668264EA16");
99 //=======================================================================
100 //function : GEOMImpl_ShapeDriver
102 //=======================================================================
103 GEOMImpl_ShapeDriver::GEOMImpl_ShapeDriver()
107 //=======================================================================
110 //=======================================================================
111 Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
113 if (Label().IsNull()) return 0;
114 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
116 GEOMImpl_IShapes aCI (aFunction);
117 Standard_Integer aType = aFunction->GetType();
122 if (aType == WIRE_EDGES) {
123 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
128 for (unsigned int ind = 1; ind <= aShapes->Length(); ind++) {
129 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
130 TopoDS_Shape aShape_i = aRefShape->GetValue();
131 if (aShape_i.IsNull()) {
132 Standard_NullObject::Raise("Shape for wire construction is null");
134 if (aShape_i.ShapeType() == TopAbs_EDGE || aShape_i.ShapeType() == TopAbs_WIRE) {
135 TopExp_Explorer exp (aShape_i, TopAbs_EDGE);
136 for (; exp.More(); exp.Next())
137 B.Add(aWire, TopoDS::Edge(exp.Current()));
139 Standard_TypeMismatch::Raise
140 ("Shape for wire construction is neither an edge nor a wire");
145 Handle(ShapeFix_Wire) aFW = new ShapeFix_Wire;
149 if (aFW->StatusReorder(ShapeExtend_FAIL1)) {
150 Standard_ConstructionError::Raise("Wire construction failed: several loops detected");
151 } else if (aFW->StatusReorder(ShapeExtend_FAIL)) {
152 Standard_ConstructionError::Raise("Wire construction failed");
156 // IMP 0019766: Building a Wire from unconnected edges by introducing a tolerance
157 Standard_Real aTolerance = aCI.GetTolerance();
158 if (aTolerance < Precision::Confusion())
159 aTolerance = Precision::Confusion();
161 aFW->ClosedWireMode() = Standard_False;
162 aFW->FixConnected(aTolerance);
163 if (aFW->StatusConnected(ShapeExtend_FAIL)) {
164 Standard_ConstructionError::Raise("Wire construction failed: cannot build connected wire");
167 if (aFW->StatusConnected(ShapeExtend_DONE3)) {
168 // Confused with <prec> but not Analyzer.Precision(), set the same
169 aFW->FixGapsByRangesMode() = Standard_True;
170 if (aFW->FixGaps3d()) {
171 Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
172 Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
173 for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
174 TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
175 aFe->FixVertexTolerance(aEdge);
176 aFe->FixSameParameter(aEdge);
179 else if (aFW->StatusGaps3d(ShapeExtend_FAIL)) {
180 Standard_ConstructionError::Raise("Wire construction failed: cannot fix 3d gaps");
183 aShape = aFW->WireAPIMake();
185 else if (aType == FACE_WIRE) {
186 Handle(GEOM_Function) aRefBase = aCI.GetBase();
187 TopoDS_Shape aShapeBase = aRefBase->GetValue();
188 if (aShapeBase.IsNull()) Standard_NullObject::Raise("Argument Shape is null");
190 if (aShapeBase.ShapeType() == TopAbs_WIRE) {
191 W = TopoDS::Wire(aShapeBase);
192 // check the wire is closed
193 TopoDS_Vertex aV1, aV2;
194 TopExp::Vertices(W, aV1, aV2);
195 if ( !aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2) )
196 aShapeBase.Closed(true);
198 Standard_NullObject::Raise
199 ("Shape for face construction is not closed");
201 else if (aShapeBase.ShapeType() == TopAbs_EDGE && aShapeBase.Closed()) {
202 BRepBuilderAPI_MakeWire MW;
203 MW.Add(TopoDS::Edge(aShapeBase));
205 Standard_ConstructionError::Raise("Wire construction failed");
210 Standard_NullObject::Raise
211 ("Shape for face construction is neither a wire nor a closed edge");
213 GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), aShape);
214 if (aShape.IsNull()) {
215 Standard_ConstructionError::Raise("Face construction failed");
218 else if (aType == FACE_WIRES) {
219 // Try to build a face from a set of wires and edges
222 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
223 int nbshapes = aShapes->Length();
225 Standard_ConstructionError::Raise("No wires or edges given");
228 // 1. Extract all edges from the given arguments
229 TopTools_MapOfShape aMapEdges;
230 Handle(TopTools_HSequenceOfShape) aSeqEdgesIn = new TopTools_HSequenceOfShape;
232 for (ind = 1; ind <= nbshapes; ind++) {
233 Handle(GEOM_Function) aRefSh_i = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
234 TopoDS_Shape aSh_i = aRefSh_i->GetValue();
236 TopExp_Explorer anExpE_i (aSh_i, TopAbs_EDGE);
237 for (; anExpE_i.More(); anExpE_i.Next()) {
238 if (aMapEdges.Add(anExpE_i.Current())) {
239 aSeqEdgesIn->Append(anExpE_i.Current());
244 // 2. Connect edges to wires of maximum length
245 Handle(TopTools_HSequenceOfShape) aSeqWiresOut;
246 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdgesIn, Precision::Confusion(),
247 /*shared*/Standard_False, aSeqWiresOut);
249 // 3. Separate closed wires
250 Handle(TopTools_HSequenceOfShape) aSeqClosedWires = new TopTools_HSequenceOfShape;
251 Handle(TopTools_HSequenceOfShape) aSeqOpenWires = new TopTools_HSequenceOfShape;
252 for (ind = 1; ind <= aSeqWiresOut->Length(); ind++) {
253 if (aSeqWiresOut->Value(ind).Closed())
254 aSeqClosedWires->Append(aSeqWiresOut->Value(ind));
256 aSeqOpenWires->Append(aSeqWiresOut->Value(ind));
259 if (aSeqClosedWires->Length() < 1) {
260 Standard_ConstructionError::Raise
261 ("There is no closed contour can be built from the given arguments");
264 // 4. Build a face / list of faces from all the obtained closed wires
268 TopoDS_Wire aW1 = TopoDS::Wire(aSeqClosedWires->Value(1));
269 GEOMImpl_Block6Explorer::MakeFace(aW1, aCI.GetIsPlanar(), aFFace);
270 if (aFFace.IsNull()) {
271 Standard_ConstructionError::Raise("Face construction failed");
274 // 4.b. Add other wires
275 if (aSeqClosedWires->Length() == 1) {
280 BRep_Builder aBuilder;
281 aBuilder.MakeCompound(C);
282 BRepAlgo_FaceRestrictor FR;
284 TopAbs_Orientation OriF = aFFace.Orientation();
285 TopoDS_Shape aLocalS = aFFace.Oriented(TopAbs_FORWARD);
286 FR.Init(TopoDS::Face(aLocalS), Standard_False, Standard_True);
288 for (ind = 1; ind <= aSeqClosedWires->Length(); ind++) {
289 TopoDS_Wire aW = TopoDS::Wire(aSeqClosedWires->Value(ind));
298 for (; FR.More(); FR.Next()) {
299 aFace = FR.Current().Oriented(OriF);
300 aBuilder.Add(C, aFace);
311 // 5. Add all open wires to the result
312 if (aSeqOpenWires->Length() > 0) {
313 //Standard_ConstructionError::Raise("There are some open wires");
315 BRep_Builder aBuilder;
316 if (aSeqClosedWires->Length() == 1) {
317 aBuilder.MakeCompound(C);
318 aBuilder.Add(C, aShape);
321 C = TopoDS::Compound(aShape);
324 for (ind = 1; ind <= aSeqOpenWires->Length(); ind++) {
325 aBuilder.Add(C, aSeqOpenWires->Value(ind));
331 else if (aType == SHELL_FACES) {
332 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
333 unsigned int ind, nbshapes = aShapes->Length();
336 BRepBuilderAPI_Sewing aSewing(Precision::Confusion()*10.0);
337 for (ind = 1; ind <= nbshapes; ind++) {
338 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
339 TopoDS_Shape aShape_i = aRefShape->GetValue();
340 if (aShape_i.IsNull()) {
341 Standard_NullObject::Raise("Face for shell construction is null");
343 aSewing.Add(aShape_i);
348 TopoDS_Shape sh = aSewing.SewedShape();
349 if( sh.ShapeType()==TopAbs_FACE && nbshapes==1 ) {
350 // case for creation of shell from one face - PAL12722 (skl 26.06.2006)
357 //TopExp_Explorer exp (aSewing.SewedShape(), TopAbs_SHELL);
358 TopExp_Explorer exp (sh, TopAbs_SHELL);
359 Standard_Integer ish = 0;
360 for (; exp.More(); exp.Next()) {
361 aShape = exp.Current();
366 aShape = aSewing.SewedShape();
370 else if (aType == SOLID_SHELL) {
371 Handle(GEOM_Function) aRefShell = aCI.GetBase();
372 TopoDS_Shape aShapeShell = aRefShell->GetValue();
373 if (aShapeShell.IsNull() || aShapeShell.ShapeType() != TopAbs_SHELL) {
374 Standard_NullObject::Raise("Shape for solid construction is null or not a shell");
377 BRepCheck_Shell chkShell(TopoDS::Shell(aShapeShell));
378 if(chkShell.Closed() == BRepCheck_NotClosed) return 0;
382 B.Add(Sol, aShapeShell);
383 BRepClass3d_SolidClassifier SC (Sol);
384 SC.PerformInfinitePoint(Precision::Confusion());
385 if (SC.State() == TopAbs_IN) {
387 B.Add(Sol, aShapeShell.Reversed());
393 else if (aType == SOLID_SHELLS) {
394 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
395 unsigned int ind, nbshapes = aShapes->Length();
396 Standard_Integer ish = 0;
401 for (ind = 1; ind <= nbshapes; ind++) {
402 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
403 TopoDS_Shape aShapeShell = aRefShape->GetValue();
404 if (aShapeShell.IsNull()) {
405 Standard_NullObject::Raise("Shell for solid construction is null");
407 if (aShapeShell.ShapeType() == TopAbs_SHELL) {
408 B.Add(Sol, aShapeShell);
412 if ( ish == 0 ) return 0;
413 BRepClass3d_SolidClassifier SC (Sol);
414 SC.PerformInfinitePoint(Precision::Confusion());
415 if (SC.State() == TopAbs_IN)
416 aShape = Sol.Reversed();
420 else if (aType == COMPOUND_SHAPES) {
421 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
422 unsigned int ind, nbshapes = aShapes->Length();
427 for (ind = 1; ind <= nbshapes; ind++) {
428 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
429 TopoDS_Shape aShape_i = aRefShape->GetValue();
430 if (aShape_i.IsNull()) {
431 Standard_NullObject::Raise("Shape for compound construction is null");
439 else if (aType == REVERSE_ORIENTATION) {
440 Handle(GEOM_Function) aRefShape = aCI.GetBase();
441 TopoDS_Shape aShape_i = aRefShape->GetValue();
442 if (aShape_i.IsNull()) {
443 Standard_NullObject::Raise("Shape for reverse is null");
446 BRepBuilderAPI_Copy Copy(aShape_i);
447 if( Copy.IsDone() ) {
448 TopoDS_Shape tds = Copy.Shape();
450 Standard_ConstructionError::Raise("Orientation aborted : Can not reverse the shape");
453 if( tds.Orientation() == TopAbs_FORWARD)
454 tds.Orientation(TopAbs_REVERSED);
456 tds.Orientation(TopAbs_FORWARD);
461 else if (aType == EDGE_WIRE) {
462 Handle(GEOM_Function) aRefBase = aCI.GetBase();
463 TopoDS_Shape aWire = aRefBase->GetValue();
464 Standard_Real LinTol = aCI.GetTolerance();
465 Standard_Real AngTol = aCI.GetAngularTolerance();
466 if (aWire.IsNull()) Standard_NullObject::Raise("Argument Wire is null");
470 BRepLib::BuildCurves3d(aWire);
471 Handle(ShapeFix_Shape) Fixer = new ShapeFix_Shape(aWire);
472 Fixer->SetPrecision(LinTol);
473 Fixer->SetMaxTolerance(LinTol);
475 TopoDS_Wire theWire = TopoDS::Wire(Fixer->Shape());
477 TColGeom_SequenceOfCurve CurveSeq;
478 TopTools_SequenceOfShape LocSeq;
479 TColStd_SequenceOfReal FparSeq;
480 TColStd_SequenceOfReal LparSeq;
481 TColStd_SequenceOfReal TolSeq;
482 GeomAbs_CurveType CurType;
483 TopoDS_Vertex FirstVertex, LastVertex;
485 BRepTools_WireExplorer wexp(theWire) ;
486 for (; wexp.More(); wexp.Next())
488 TopoDS_Edge anEdge = wexp.Current();
489 Standard_Real fpar, lpar;
490 TopLoc_Location aLoc;
491 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aLoc, fpar, lpar);
495 BRepAdaptor_Curve BAcurve(anEdge);
496 GeomAbs_CurveType aType = BAcurve.GetType();
498 Handle(Geom_Curve) aBasisCurve = BAcurve.Curve().Curve();
500 if (aBasisCurve->IsPeriodic())
501 ElCLib::AdjustPeriodic(aBasisCurve->FirstParameter(), aBasisCurve->LastParameter(),
502 Precision::PConfusion(), fpar, lpar);
504 if (CurveSeq.IsEmpty())
506 CurveSeq.Append(aCurve);
507 TopoDS_Shape aLocShape;
508 aLocShape.Location(aLoc);
509 aLocShape.Orientation(wexp.Orientation());
510 LocSeq.Append(aLocShape);
511 FparSeq.Append(fpar);
512 LparSeq.Append(lpar);
514 FirstVertex = wexp.CurrentVertex();
518 Standard_Boolean Done = Standard_False;
519 Standard_Real NewFpar, NewLpar;
520 GeomAdaptor_Curve GAprevcurve(CurveSeq.Last());
521 TopoDS_Vertex CurVertex = wexp.CurrentVertex();
522 TopoDS_Vertex CurFirstVer = TopExp::FirstVertex(anEdge);
523 TopAbs_Orientation ConnectByOrigin = (CurVertex.IsSame(CurFirstVer))? TopAbs_FORWARD : TopAbs_REVERSED;
524 if (aCurve == CurveSeq.Last())
528 if (aBasisCurve->IsPeriodic())
530 if (NewLpar < NewFpar)
531 NewLpar += aBasisCurve->Period();
532 if (ConnectByOrigin == TopAbs_FORWARD)
533 ElCLib::AdjustPeriodic(FparSeq.Last(),
534 FparSeq.Last() + aBasisCurve->Period(),
535 Precision::PConfusion(), NewFpar, NewLpar);
537 ElCLib::AdjustPeriodic(FparSeq.Last() - aBasisCurve->Period(),
539 Precision::PConfusion(), NewFpar, NewLpar);
541 Done = Standard_True;
543 else if (aType == CurType &&
544 aType != GeomAbs_BezierCurve &&
545 aType != GeomAbs_BSplineCurve &&
546 aType != GeomAbs_OtherCurve)
552 gp_Lin aLine = BAcurve.Line();
553 gp_Lin PrevLine = GAprevcurve.Line();
554 if (aLine.Contains(PrevLine.Location(), LinTol) &&
555 aLine.Direction().IsParallel(PrevLine.Direction(), AngTol))
557 gp_Pnt P1 = ElCLib::Value(fpar, aLine);
558 gp_Pnt P2 = ElCLib::Value(lpar, aLine);
559 NewFpar = ElCLib::Parameter(PrevLine, P1);
560 NewLpar = ElCLib::Parameter(PrevLine, P2);
561 if (NewLpar < NewFpar)
563 Standard_Real MemNewFpar = NewFpar;
565 NewLpar = MemNewFpar;
566 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
568 Done = Standard_True;
574 gp_Circ aCircle = BAcurve.Circle();
575 gp_Circ PrevCircle = GAprevcurve.Circle();
576 if (aCircle.Location().Distance(PrevCircle.Location()) <= LinTol &&
577 Abs(aCircle.Radius() - PrevCircle.Radius()) <= LinTol &&
578 aCircle.Axis().IsParallel(PrevCircle.Axis(), AngTol))
580 if (aCircle.Axis().Direction() * PrevCircle.Axis().Direction() < 0.)
582 Standard_Real memfpar = fpar;
585 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
587 gp_Pnt P1 = ElCLib::Value(fpar, aCircle);
588 gp_Pnt P2 = ElCLib::Value(lpar, aCircle);
589 NewFpar = ElCLib::Parameter(PrevCircle, P1);
590 NewLpar = ElCLib::Parameter(PrevCircle, P2);
591 if (NewLpar < NewFpar)
593 //Standard_Real MemNewFpar = NewFpar, MemNewLpar = NewLpar;
594 if (ConnectByOrigin == TopAbs_FORWARD)
595 ElCLib::AdjustPeriodic(FparSeq.Last(),
596 FparSeq.Last() + 2.*PI,
597 Precision::PConfusion(), NewFpar, NewLpar);
599 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*PI,
601 Precision::PConfusion(), NewFpar, NewLpar);
602 Done = Standard_True;
606 case GeomAbs_Ellipse:
608 gp_Elips anEllipse = BAcurve.Ellipse();
609 gp_Elips PrevEllipse = GAprevcurve.Ellipse();
610 if (anEllipse.Focus1().Distance(PrevEllipse.Focus1()) <= LinTol &&
611 anEllipse.Focus2().Distance(PrevEllipse.Focus2()) <= LinTol &&
612 Abs(anEllipse.MajorRadius() - PrevEllipse.MajorRadius()) <= LinTol &&
613 Abs(anEllipse.MinorRadius() - PrevEllipse.MinorRadius()) <= LinTol &&
614 anEllipse.Axis().IsParallel(PrevEllipse.Axis(), AngTol))
616 if (anEllipse.Axis().Direction() * PrevEllipse.Axis().Direction() < 0.)
618 Standard_Real memfpar = fpar;
621 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
623 gp_Pnt P1 = ElCLib::Value(fpar, anEllipse);
624 gp_Pnt P2 = ElCLib::Value(lpar, anEllipse);
625 NewFpar = ElCLib::Parameter(PrevEllipse, P1);
626 NewLpar = ElCLib::Parameter(PrevEllipse, P2);
627 if (NewLpar < NewFpar)
629 if (ConnectByOrigin == TopAbs_FORWARD)
630 ElCLib::AdjustPeriodic(FparSeq.Last(),
631 FparSeq.Last() + 2.*PI,
632 Precision::PConfusion(), NewFpar, NewLpar);
634 ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*PI,
636 Precision::PConfusion(), NewFpar, NewLpar);
637 Done = Standard_True;
641 case GeomAbs_Hyperbola:
643 gp_Hypr aHypr = BAcurve.Hyperbola();
644 gp_Hypr PrevHypr = GAprevcurve.Hyperbola();
645 if (aHypr.Focus1().Distance(PrevHypr.Focus1()) <= LinTol &&
646 aHypr.Focus2().Distance(PrevHypr.Focus2()) <= LinTol &&
647 Abs(aHypr.MajorRadius() - PrevHypr.MajorRadius()) <= LinTol &&
648 Abs(aHypr.MinorRadius() - PrevHypr.MinorRadius()) <= LinTol &&
649 aHypr.Axis().IsParallel(PrevHypr.Axis(), AngTol))
651 gp_Pnt P1 = ElCLib::Value(fpar, aHypr);
652 gp_Pnt P2 = ElCLib::Value(lpar, aHypr);
653 NewFpar = ElCLib::Parameter(PrevHypr, P1);
654 NewLpar = ElCLib::Parameter(PrevHypr, P2);
655 if (NewLpar < NewFpar)
657 Standard_Real MemNewFpar = NewFpar;
659 NewLpar = MemNewFpar;
660 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
662 Done = Standard_True;
666 case GeomAbs_Parabola:
668 gp_Parab aParab = BAcurve.Parabola();
669 gp_Parab PrevParab = GAprevcurve.Parabola();
670 if (aParab.Location().Distance(PrevParab.Location()) <= LinTol &&
671 aParab.Focus().Distance(PrevParab.Focus()) <= LinTol &&
672 Abs(aParab.Focal() - PrevParab.Focal()) <= LinTol &&
673 aParab.Axis().IsParallel(PrevParab.Axis(), AngTol))
675 gp_Pnt P1 = ElCLib::Value(fpar, aParab);
676 gp_Pnt P2 = ElCLib::Value(lpar, aParab);
677 NewFpar = ElCLib::Parameter(PrevParab, P1);
678 NewLpar = ElCLib::Parameter(PrevParab, P2);
679 if (NewLpar < NewFpar)
681 Standard_Real MemNewFpar = NewFpar;
683 NewLpar = MemNewFpar;
684 ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
686 Done = Standard_True;
690 } //end of switch (aType)
691 } // end of else if (aType == CurType && ...
694 if (NewFpar < FparSeq.Last())
695 FparSeq(FparSeq.Length()) = NewFpar;
697 LparSeq(LparSeq.Length()) = NewLpar;
701 CurveSeq.Append(aCurve);
702 TopoDS_Shape aLocShape;
703 aLocShape.Location(aLoc);
704 aLocShape.Orientation(wexp.Orientation());
705 LocSeq.Append(aLocShape);
706 FparSeq.Append(fpar);
707 LparSeq.Append(lpar);
708 TolSeq.Append(BRep_Tool::Tolerance(CurVertex));
711 } // end of else (CurveSeq.IsEmpty()) -> not first time
712 } // end for (; wexp.More(); wexp.Next())
714 LastVertex = wexp.CurrentVertex();
715 TolSeq.Append(BRep_Tool::Tolerance(LastVertex));
717 if (!CurveSeq.IsEmpty())
719 Standard_Integer nb_curve = CurveSeq.Length(); //number of curves
720 TColGeom_Array1OfBSplineCurve tab(0,nb_curve-1); //array of the curves
721 TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2); //array of the tolerances
727 for (i = 1; i <= nb_curve; i++)
729 if (CurveSeq(i)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
730 CurveSeq(i) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(i))))->BasisCurve();
732 Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(CurveSeq(i), FparSeq(i), LparSeq(i));
733 tab(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve);
734 tab(i-1)->Transform(LocSeq(i).Location().Transformation());
735 GeomConvert::C0BSplineToC1BSplineCurve(tab(i-1), Precision::Confusion());
736 if (LocSeq(i).Orientation() == TopAbs_REVERSED)
740 //char* name = new char[100];
741 //sprintf(name, "c%d", i);
742 //DrawTrSurf::Set(name, tab(i-1));
745 tabtolvertex(i-2) = TolSeq(i-1);
746 } // end for (i = 1; i <= nb_curve; i++)
747 tabtolvertex(nb_curve-1) = TolSeq(TolSeq.Length());
749 Standard_Boolean closed_flag = Standard_False;
750 Standard_Real closed_tolerance = 0.;
751 if (FirstVertex.IsSame(LastVertex) &&
752 GeomLProp::Continuity(tab(0), tab(nb_curve-1),
753 tab(0)->FirstParameter(),
754 tab(nb_curve-1)->LastParameter(),
755 Standard_False, Standard_False, LinTol, AngTol) >= GeomAbs_G1)
757 closed_flag = Standard_True ;
758 closed_tolerance = BRep_Tool::Tolerance(FirstVertex);
761 Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves
762 Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex
763 GeomConvert::ConcatC1(tab,
768 closed_tolerance); //C1 concatenation
770 if (concatcurve->Length() > 1)
772 GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower()));
774 for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++)
775 Concat.Add( concatcurve->Value(i), LinTol, Standard_True );
777 concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve());
780 ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
781 FirstVertex, LastVertex);
785 if (CurveSeq(1)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
786 CurveSeq(1) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(i))))->BasisCurve();
788 CurveSeq(1)->Transform(LocSeq(1).Location().Transformation());
789 ResEdge = BRepLib_MakeEdge(CurveSeq(1),
790 FirstVertex, LastVertex,
791 FparSeq(1), LparSeq(1));
798 if (aShape.IsNull()) return 0;
800 // Check shape validity
801 BRepCheck_Analyzer ana (aShape, false);
802 if (!ana.IsValid()) {
803 //Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
806 aFunction->SetValue(aShape);
808 log.SetTouched(Label());
814 //=======================================================================
815 //function : GEOMImpl_ShapeDriver_Type_
817 //=======================================================================
818 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ShapeDriver_Type_()
821 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
822 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
823 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
824 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
825 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
826 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
829 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
830 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ShapeDriver",
831 sizeof(GEOMImpl_ShapeDriver),
833 (Standard_Address)_Ancestors,
834 (Standard_Address)NULL);
839 //=======================================================================
840 //function : DownCast
842 //=======================================================================
843 const Handle(GEOMImpl_ShapeDriver) Handle(GEOMImpl_ShapeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
845 Handle(GEOMImpl_ShapeDriver) _anOtherObject;
847 if (!AnObject.IsNull()) {
848 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ShapeDriver))) {
849 _anOtherObject = Handle(GEOMImpl_ShapeDriver)((Handle(GEOMImpl_ShapeDriver)&)AnObject);
853 return _anOtherObject;