Salome HOME
933ad9eea273c2c693c4ee3250f12c6d401d06be
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ShapeDriver.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <GEOMImpl_ShapeDriver.hxx>
24
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>
31
32 #include <GEOM_Function.hxx>
33 #include <GEOMUtils_Hatcher.hxx>
34 #include <GEOMAlgo_State.hxx>
35
36 // OCCT Includes
37 #include <ShapeFix_Wire.hxx>
38 #include <ShapeFix_Edge.hxx>
39 #include <ShapeFix_Shape.hxx>
40
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>
58
59 #include <ShapeAnalysis.hxx>
60 #include <ShapeAnalysis_FreeBounds.hxx>
61
62 #include <TNaming_CopyShape.hxx>
63
64 #include <TopAbs.hxx>
65 #include <TopExp.hxx>
66 #include <TopExp_Explorer.hxx>
67 #include <TopoDS.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>
75
76 #include <TopTools_MapOfShape.hxx>
77 #include <TopTools_HSequenceOfShape.hxx>
78
79 #include <ElCLib.hxx>
80
81 #include <GCPnts_AbscissaPoint.hxx>
82
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>
90
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>
98
99 #include <Precision.hxx>
100
101 #include <Standard_NullObject.hxx>
102 #include <Standard_TypeMismatch.hxx>
103 #include <Standard_ConstructionError.hxx>
104
105 #include <BOPAlgo_PaveFiller.hxx>
106 #include <BOPAlgo_MakerVolume.hxx>
107
108 #include <list>
109
110 //modified by NIZNHY-PKV Wed Dec 28 13:48:20 2011f
111 //static
112 //  void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
113 //                    const Handle(TopTools_HSequenceOfShape)& aWires);
114 //modified by NIZNHY-PKV Wed Dec 28 13:48:23 2011t
115
116 //=======================================================================
117 //function : GetID
118 //purpose  :
119 //=======================================================================
120 const Standard_GUID& GEOMImpl_ShapeDriver::GetID()
121 {
122   static Standard_GUID aShapeDriver("FF1BBB54-5D14-4df2-980B-3A668264EA16");
123   return aShapeDriver;
124 }
125
126
127 //=======================================================================
128 //function : GEOMImpl_ShapeDriver
129 //purpose  :
130 //=======================================================================
131 GEOMImpl_ShapeDriver::GEOMImpl_ShapeDriver()
132 {
133 }
134
135 //=======================================================================
136 //function : Execute
137 //purpose  :
138 //=======================================================================
139 Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
140 {
141   if (Label().IsNull()) return 0;
142   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
143
144   GEOMImpl_IShapes aCI (aFunction);
145   Standard_Integer aType = aFunction->GetType();
146
147   TopoDS_Shape aShape;
148   TCollection_AsciiString aWarning;
149   std::list<TopAbs_ShapeEnum> anExpectedType;
150
151   BRep_Builder B;
152
153   if (aType == WIRE_EDGES) {
154     anExpectedType.push_back(TopAbs_WIRE);
155
156     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
157
158     Standard_Real aTolerance = aCI.GetTolerance();
159     if (aTolerance < Precision::Confusion())
160       aTolerance = Precision::Confusion();
161
162     aShape = MakeWireFromEdges(aShapes, aTolerance);
163   }
164   else if (aType == FACE_WIRE) {
165     anExpectedType.push_back(TopAbs_FACE);
166
167     Handle(GEOM_Function) aRefBase = aCI.GetBase();
168     TopoDS_Shape aShapeBase = aRefBase->GetValue();
169     if (aShapeBase.IsNull()) Standard_NullObject::Raise("Argument Shape is null");
170     TopoDS_Wire W;
171     if (aShapeBase.ShapeType() == TopAbs_WIRE) {
172       W = TopoDS::Wire(aShapeBase);
173       // check the wire is closed
174       TopoDS_Vertex aV1, aV2;
175       TopExp::Vertices(W, aV1, aV2);
176       if ( !aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2) )
177         aShapeBase.Closed(true);
178       else
179         Standard_NullObject::Raise
180           ("Shape for face construction is not closed");
181     }
182     else if (aShapeBase.ShapeType() == TopAbs_EDGE && BRep_Tool::IsClosed(aShapeBase)) {
183       BRepBuilderAPI_MakeWire MW;
184       MW.Add(TopoDS::Edge(aShapeBase));
185       if (!MW.IsDone()) {
186         Standard_ConstructionError::Raise("Wire construction failed");
187       }
188       W = MW;
189     }
190     else {
191       Standard_NullObject::Raise
192         ("Shape for face construction is neither a wire nor a closed edge");
193     }
194     aWarning = GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), aShape);
195     if (aShape.IsNull()) {
196       Standard_ConstructionError::Raise("Face construction failed");
197     }
198   }
199   else if (aType == FACE_WIRES) {
200     anExpectedType.push_back(TopAbs_FACE);
201
202     // Try to build a face from a set of wires and edges
203     int ind;
204
205     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
206     int nbshapes = aShapes->Length();
207     if (nbshapes < 1) {
208       Standard_ConstructionError::Raise("No wires or edges given");
209     }
210
211     // 1. Extract all edges from the given arguments
212     TopTools_MapOfShape aMapEdges;
213     Handle(TopTools_HSequenceOfShape) aSeqEdgesIn = new TopTools_HSequenceOfShape;
214     TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
215
216     for (ind = 1; ind <= nbshapes; ind++) {
217       Handle(GEOM_Function) aRefSh_i = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
218       TopoDS_Shape aSh_i = aRefSh_i->GetValue();
219
220       TopExp_Explorer anExpE_i (aSh_i, TopAbs_EDGE);
221       for (; anExpE_i.More(); anExpE_i.Next()) {
222         if (aMapEdges.Add(anExpE_i.Current())) {
223           // Copy the original shape.
224           TopoDS_Shape aShapeCopy;
225
226           TNaming_CopyShape::CopyTool
227             (anExpE_i.Current(), aMapTShapes, aShapeCopy);
228           aSeqEdgesIn->Append(aShapeCopy);
229         }
230       }
231     }
232
233     if (aSeqEdgesIn->IsEmpty()) {
234       Standard_ConstructionError::Raise("No edges given");
235     }
236
237     // 2. Connect edges to wires of maximum length
238     Handle(TopTools_HSequenceOfShape) aSeqWiresOut;
239     ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdgesIn, Precision::Confusion(),
240                                                   /*shared*/Standard_False, aSeqWiresOut);
241     //modified by NIZNHY-PKV Wed Dec 28 13:46:55 2011f
242     //KeepEdgesOrder(aSeqEdgesIn, aSeqWiresOut);
243     //modified by NIZNHY-PKV Wed Dec 28 13:46:59 2011t
244
245     // 3. Separate closed wires
246     Handle(TopTools_HSequenceOfShape) aSeqClosedWires = new TopTools_HSequenceOfShape;
247     Handle(TopTools_HSequenceOfShape) aSeqOpenWires = new TopTools_HSequenceOfShape;
248     for (ind = 1; ind <= aSeqWiresOut->Length(); ind++) {
249       if (aSeqWiresOut->Value(ind).Closed())
250         aSeqClosedWires->Append(aSeqWiresOut->Value(ind));
251       else
252         aSeqOpenWires->Append(aSeqWiresOut->Value(ind));
253     }
254
255     if (aSeqClosedWires->Length() < 1) {
256       Standard_ConstructionError::Raise
257         ("There is no closed contour can be built from the given arguments");
258     }
259
260     // 4. Build a face / list of faces from all the obtained closed wires
261
262     // 4.a. Basic face
263     TopoDS_Shape aFFace;
264     TopoDS_Wire aW1 = TopoDS::Wire(aSeqClosedWires->Value(1));
265     aWarning = GEOMImpl_Block6Explorer::MakeFace(aW1, aCI.GetIsPlanar(), aFFace);
266     if (aFFace.IsNull()) {
267       Standard_ConstructionError::Raise("Face construction failed");
268     }
269
270     // 4.b. Add other wires
271     if (aSeqClosedWires->Length() == 1) {
272       aShape = aFFace;
273     }
274     else {
275       TopoDS_Compound C;
276       BRep_Builder aBuilder;
277       aBuilder.MakeCompound(C);
278       BRepAlgo_FaceRestrictor FR;
279
280       TopAbs_Orientation OriF = aFFace.Orientation();
281       TopoDS_Shape aLocalS = aFFace.Oriented(TopAbs_FORWARD);
282       FR.Init(TopoDS::Face(aLocalS), Standard_False, Standard_True);
283
284       for (ind = 1; ind <= aSeqClosedWires->Length(); ind++) {
285         TopoDS_Wire aW = TopoDS::Wire(aSeqClosedWires->Value(ind));
286         FR.Add(aW);
287       }
288
289       FR.Perform();
290
291       if (FR.IsDone()) {
292         int k = 0;
293         TopoDS_Shape aFace;
294         for (; FR.More(); FR.Next()) {
295           aFace = FR.Current().Oriented(OriF);
296           aBuilder.Add(C, aFace);
297           k++;
298         }
299         if (k == 1) {
300           aShape = aFace;
301         } else {
302           aShape = C;
303         }
304       }
305     }
306
307     // 5. Add all open wires to the result
308     if (aSeqOpenWires->Length() > 0) {
309       //Standard_ConstructionError::Raise("There are some open wires");
310       TopoDS_Compound C;
311       BRep_Builder aBuilder;
312       if (aSeqClosedWires->Length() == 1) {
313         aBuilder.MakeCompound(C);
314         aBuilder.Add(C, aShape);
315       }
316       else {
317         C = TopoDS::Compound(aShape);
318       }
319
320       for (ind = 1; ind <= aSeqOpenWires->Length(); ind++) {
321         aBuilder.Add(C, aSeqOpenWires->Value(ind));
322       }
323
324       aShape = C;
325     }
326   }
327   else if (aType == FACE_FROM_SURFACE) {
328     anExpectedType.push_back(TopAbs_FACE);
329
330     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
331
332     if (aShapes.IsNull() == Standard_False) {
333       Standard_Integer aNbShapes = aShapes->Length();
334
335       if (aNbShapes == 2) {
336         Handle(GEOM_Function) aRefFace =
337           Handle(GEOM_Function)::DownCast(aShapes->Value(1));
338         Handle(GEOM_Function) aRefWire =
339           Handle(GEOM_Function)::DownCast(aShapes->Value(2));
340
341         if (aRefFace.IsNull() == Standard_False &&
342             aRefWire.IsNull() == Standard_False) {
343           TopoDS_Shape aShFace = aRefFace->GetValue();
344           TopoDS_Shape aShWire = aRefWire->GetValue();
345
346           if (aShFace.IsNull()    == Standard_False &&
347               aShFace.ShapeType() == TopAbs_FACE    &&
348               aShWire.IsNull()    == Standard_False &&
349               aShWire.ShapeType() == TopAbs_WIRE) {
350             TopoDS_Face             aFace = TopoDS::Face(aShFace);
351             TopoDS_Wire             aWire = TopoDS::Wire(aShWire);
352             Handle(Geom_Surface)    aSurf = BRep_Tool::Surface(aFace);
353             BRepBuilderAPI_MakeFace aMkFace(aSurf, aWire);
354
355             if (aMkFace.IsDone()) {
356               aShape = aMkFace.Shape();
357             }
358           }
359         }
360       }
361     }
362   }
363   else if (aType == SHELL_FACES) {
364     anExpectedType.push_back(TopAbs_SHELL);
365
366     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
367     unsigned int ind, nbshapes = aShapes->Length();
368
369     // add faces
370     BRepBuilderAPI_Sewing aSewing (Precision::Confusion()*10.0);
371     for (ind = 1; ind <= nbshapes; ind++) {
372       Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
373       TopoDS_Shape aShape_i = aRefShape->GetValue();
374       if (aShape_i.IsNull()) {
375         Standard_NullObject::Raise("Face for shell construction is null");
376       }
377       aSewing.Add(aShape_i);
378     }
379
380     aSewing.Perform();
381
382     TopoDS_Shape sh = aSewing.SewedShape();
383
384     if (sh.ShapeType()==TopAbs_FACE && nbshapes==1) {
385       // case for creation of shell from one face - PAL12722 (skl 26.06.2006)
386       TopoDS_Shell ss;
387       B.MakeShell(ss);
388       B.Add(ss,sh);
389       aShape = ss;
390     }
391     else {
392       //TopExp_Explorer exp (aSewing.SewedShape(), TopAbs_SHELL);
393       TopExp_Explorer exp (sh, TopAbs_SHELL);
394       Standard_Integer ish = 0;
395       for (; exp.More(); exp.Next()) {
396         aShape = exp.Current();
397         ish++;
398       }
399
400       if (ish != 1) {
401         // try the case of one face (Mantis issue 0021809)
402         TopExp_Explorer expF (sh, TopAbs_FACE);
403         Standard_Integer ifa = 0;
404         for (; expF.More(); expF.Next()) {
405           aShape = expF.Current();
406           ifa++;
407         }
408
409         if (ifa == 1) {
410           TopoDS_Shell ss;
411           B.MakeShell(ss);
412           B.Add(ss,aShape);
413           aShape = ss;
414         }
415         else {
416           aShape = aSewing.SewedShape();
417         }
418       }
419     }
420
421   }
422   else if (aType == SOLID_SHELLS) {
423     anExpectedType.push_back(TopAbs_SOLID);
424
425     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
426     unsigned int ind, nbshapes = aShapes->Length();
427     Standard_Integer ish = 0;
428     BRepBuilderAPI_MakeSolid aMkSolid;
429
430     // add shapes
431     for (ind = 1; ind <= nbshapes; ind++) {
432       Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
433       TopoDS_Shape aShapeShell = aRefShape->GetValue();
434       if (aShapeShell.IsNull()) {
435         Standard_NullObject::Raise("Shell for solid construction is null");
436       }
437       if (aShapeShell.ShapeType() == TopAbs_COMPOUND) {
438         TopoDS_Iterator It (aShapeShell, Standard_True, Standard_True);
439         for (; It.More(); It.Next()) {
440           TopoDS_Shape aSubShape = It.Value();
441           if (aSubShape.ShapeType() == TopAbs_SHELL) {
442             aMkSolid.Add(TopoDS::Shell(aSubShape));
443             ish++;
444           }
445           else
446             Standard_TypeMismatch::Raise
447               ("Shape for solid construction is neither a shell nor a compound of shells");
448         }
449       }
450       else if (aShapeShell.ShapeType() == TopAbs_SHELL) {
451         aMkSolid.Add(TopoDS::Shell(aShapeShell));
452         ish++;
453       }
454     }
455     if (ish == 0 || !aMkSolid.IsDone()) return 0;
456
457     TopoDS_Solid Sol = aMkSolid.Solid();
458     BRepClass3d_SolidClassifier SC (Sol);
459     SC.PerformInfinitePoint(Precision::Confusion());
460     if (SC.State() == TopAbs_IN)
461       aShape = Sol.Reversed();
462     else
463       aShape = Sol;
464   }
465   else if (aType == COMPOUND_SHAPES) {
466     anExpectedType.push_back(TopAbs_COMPOUND);
467
468     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
469     unsigned int ind, nbshapes = aShapes->Length();
470
471     // add shapes
472     TopoDS_Compound C;
473     B.MakeCompound(C);
474     for (ind = 1; ind <= nbshapes; ind++) {
475       Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
476       TopoDS_Shape aShape_i = aRefShape->GetValue();
477       if (aShape_i.IsNull()) {
478         Standard_NullObject::Raise("Shape for compound construction is null");
479       }
480       B.Add(C, aShape_i);
481     }
482
483     aShape = C;
484
485   }
486   else if (aType == EDGE_WIRE) {
487     anExpectedType.push_back(TopAbs_EDGE);
488
489     Handle(GEOM_Function) aRefBase = aCI.GetBase();
490     TopoDS_Shape aWire = aRefBase->GetValue();
491     Standard_Real LinTol = aCI.GetTolerance();
492     Standard_Real AngTol = aCI.GetAngularTolerance();
493     if (aWire.IsNull()) Standard_NullObject::Raise("Argument Wire is null");
494
495     aShape = MakeEdgeFromWire(aWire, LinTol, AngTol);
496   }
497   else if (aType == SOLID_FACES) {
498     anExpectedType.push_back(TopAbs_SOLID);
499     anExpectedType.push_back(TopAbs_COMPOUND);
500     anExpectedType.push_back(TopAbs_COMPSOLID);
501     
502     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
503     unsigned int ind, nbshapes = aShapes->Length();
504     
505     // add faces
506     BOPCol_ListOfShape aLS;
507     for (ind = 1; ind <= nbshapes; ind++) {
508       Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
509       TopoDS_Shape aShape_i = aRefShape->GetValue();
510       if (aShape_i.IsNull()) {
511         Standard_NullObject::Raise("Shape for solid construction is null");
512       }
513       if (aShape_i.ShapeType() == TopAbs_COMPOUND) {
514         TopoDS_Iterator It (aShape_i, Standard_True, Standard_True);
515         for (; It.More(); It.Next()) {
516           TopoDS_Shape aSubShape = It.Value();
517           if (aSubShape.ShapeType() == TopAbs_FACE || aSubShape.ShapeType() == TopAbs_SHELL)
518             aLS.Append(aSubShape);
519           else
520             Standard_TypeMismatch::Raise
521               ("Shape for solid construction is neither a list of faces and/or shells "
522                "nor a compound of faces and/or shells");
523         }
524       }
525       aLS.Append(aShape_i);
526     }
527
528     BOPAlgo_MakerVolume aMV;
529     aMV.SetArguments(aLS);
530     aMV.SetIntersect(aCI.GetIsIntersect());
531     aMV.Perform();
532     if (aMV.ErrorStatus()) return 0;
533
534     aShape = aMV.Shape();
535   }
536   else if (aType == EDGE_CURVE_LENGTH) {
537     anExpectedType.push_back(TopAbs_EDGE);
538
539     GEOMImpl_IVector aVI (aFunction);
540
541     // RefCurve
542     Handle(GEOM_Function) aRefCurve = aVI.GetPoint1();
543     if (aRefCurve.IsNull()) Standard_NullObject::Raise("Argument Curve is null");
544     TopoDS_Shape aRefShape1 = aRefCurve->GetValue();
545     if (aRefShape1.ShapeType() != TopAbs_EDGE) {
546       Standard_TypeMismatch::Raise
547         ("Edge On Curve creation aborted : curve shape is not an edge");
548     }
549     TopoDS_Edge aRefEdge = TopoDS::Edge(aRefShape1);
550     TopoDS_Vertex V1, V2;
551     TopExp::Vertices(aRefEdge, V1, V2, Standard_True);
552
553     // RefPoint
554     TopoDS_Vertex aRefVertex;
555     Handle(GEOM_Function) aRefPoint = aVI.GetPoint2();
556     if (aRefPoint.IsNull()) {
557       aRefVertex = V1;
558     }
559     else {
560       TopoDS_Shape aRefShape2 = aRefPoint->GetValue();
561       if (aRefShape2.ShapeType() != TopAbs_VERTEX) {
562         Standard_TypeMismatch::Raise
563           ("Edge On Curve creation aborted : start point shape is not a vertex");
564       }
565       aRefVertex = TopoDS::Vertex(aRefShape2);
566     }
567     gp_Pnt aRefPnt = BRep_Tool::Pnt(aRefVertex);
568
569     // Length
570     Standard_Real aLength = aVI.GetParameter();
571     //Standard_Real aCurveLength = IntTools::Length(aRefEdge);
572     //if (aLength > aCurveLength) {
573     //  Standard_ConstructionError::Raise
574     //    ("Edge On Curve creation aborted : given length is greater than edges length");
575     //}
576     if (fabs(aLength) < Precision::Confusion()) {
577       Standard_ConstructionError::Raise
578         ("Edge On Curve creation aborted : given length is smaller than Precision::Confusion()");
579     }
580
581     // Check orientation
582     Standard_Real UFirst, ULast;
583     Handle(Geom_Curve) EdgeCurve = BRep_Tool::Curve(aRefEdge, UFirst, ULast);
584     Handle(Geom_Curve) ReOrientedCurve = EdgeCurve;
585
586     Standard_Real dU = ULast - UFirst;
587     Standard_Real par1 = UFirst + 0.1 * dU;
588     Standard_Real par2 = ULast  - 0.1 * dU;
589
590     gp_Pnt P1 = EdgeCurve->Value(par1);
591     gp_Pnt P2 = EdgeCurve->Value(par2);
592
593     if (aRefPnt.SquareDistance(P2) < aRefPnt.SquareDistance(P1)) {
594       ReOrientedCurve = EdgeCurve->Reversed();
595       UFirst = EdgeCurve->ReversedParameter(ULast);
596     }
597
598     // Get the point by length
599     GeomAdaptor_Curve AdapCurve = GeomAdaptor_Curve(ReOrientedCurve);
600     GCPnts_AbscissaPoint anAbsPnt (AdapCurve, aLength, UFirst);
601     Standard_Real aParam = anAbsPnt.Parameter();
602
603     if (AdapCurve.IsClosed() && aLength < 0.0) {
604       Standard_Real aTmp = aParam;
605       aParam = UFirst;
606       UFirst = aTmp;
607     }
608
609     BRepBuilderAPI_MakeEdge aME (ReOrientedCurve, UFirst, aParam);
610     if (aME.IsDone())
611       aShape = aME.Shape();
612   } else if (aType == SHAPE_ISOLINE) {
613     GEOMImpl_IIsoline     aII (aFunction);
614     Handle(GEOM_Function) aRefFace = aII.GetFace();
615     TopoDS_Shape          aShapeFace = aRefFace->GetValue();
616
617     if (aShapeFace.ShapeType() == TopAbs_FACE) {
618       TopoDS_Face   aFace  = TopoDS::Face(aShapeFace);
619       bool          isUIso = aII.GetIsUIso();
620       Standard_Real aParam = aII.GetParameter();
621       Standard_Real U1,U2,V1,V2;
622
623       // Construct a real geometric parameter.
624       aFace.Orientation(TopAbs_FORWARD);
625       ShapeAnalysis::GetFaceUVBounds(aFace,U1,U2,V1,V2);
626
627       if (isUIso) {
628         aParam = U1 + (U2 - U1)*aParam;
629       } else {
630         aParam = V1 + (V2 - V1)*aParam;
631       }
632
633       aShape = MakeIsoline(aFace, isUIso, aParam);
634     } else {
635       Standard_NullObject::Raise
636         ("Shape for isoline construction is not a face");
637     }
638   } else if (aType == EDGE_UV) {
639     anExpectedType.push_back(TopAbs_EDGE);
640     GEOMImpl_IShapeExtend aSE (aFunction);
641     Handle(GEOM_Function) aRefEdge   = aSE.GetShape();
642     TopoDS_Shape          aShapeEdge = aRefEdge->GetValue();
643
644     if (aShapeEdge.ShapeType() == TopAbs_EDGE) {
645       TopoDS_Edge anEdge = TopoDS::Edge(aShapeEdge);
646
647       aShape = ExtendEdge(anEdge, aSE.GetUMin(), aSE.GetUMax());
648     }
649   } else if (aType == FACE_UV) {
650     anExpectedType.push_back(TopAbs_FACE);
651
652     GEOMImpl_IShapeExtend aSE (aFunction);
653     Handle(GEOM_Function) aRefFace   = aSE.GetShape();
654     TopoDS_Shape          aShapeFace = aRefFace->GetValue();
655
656     if (aShapeFace.ShapeType() == TopAbs_FACE) {
657       TopoDS_Face aFace = TopoDS::Face(aShapeFace);
658
659       aFace.Orientation(TopAbs_FORWARD);
660       aShape = ExtendFace(aFace, aSE.GetUMin(), aSE.GetUMax(),
661                           aSE.GetVMin(), aSE.GetVMax()); 
662     }
663   } else if (aType == SURFACE_FROM_FACE) {
664     anExpectedType.push_back(TopAbs_FACE);
665
666     GEOMImpl_IShapeExtend aSE (aFunction);
667     Handle(GEOM_Function) aRefFace   = aSE.GetShape();
668     TopoDS_Shape          aShapeFace = aRefFace->GetValue();
669
670     if (aShapeFace.ShapeType() == TopAbs_FACE) {
671       TopoDS_Face          aFace    = TopoDS::Face(aShapeFace);
672       Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
673
674       if (aSurface.IsNull() == Standard_False) {
675         Handle(Standard_Type) aType = aSurface->DynamicType();
676         Standard_Real         aU1;
677         Standard_Real         aU2;
678         Standard_Real         aV1;
679         Standard_Real         aV2;
680
681          // Get U, V bounds of the face.
682         aFace.Orientation(TopAbs_FORWARD);
683         ShapeAnalysis::GetFaceUVBounds(aFace, aU1, aU2, aV1, aV2);
684
685         // Get the surface of original type
686         while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
687           Handle(Geom_RectangularTrimmedSurface) aTrSurface =
688             Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
689
690           aSurface = aTrSurface->BasisSurface();
691           aType    = aSurface->DynamicType();
692         }
693
694         const Standard_Real     aTol = BRep_Tool::Tolerance(aFace);
695         BRepBuilderAPI_MakeFace aMF(aSurface, aU1, aU2, aV1, aV2, aTol);
696
697         if (aMF.IsDone()) {
698           aShape = aMF.Shape();
699         }
700       }
701     }
702   }
703   else {
704   }
705
706   if (aShape.IsNull()) return 0;
707
708   // Check shape validity
709   BRepCheck_Analyzer ana (aShape, false);
710   if (!ana.IsValid()) {
711     //Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
712     // For Mantis issue 0021772: EDF 2336 GEOM: Non valid face created from two circles
713     Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape (aShape);
714     aSfs->Perform();
715     aShape = aSfs->Shape();
716   }
717
718   // Check if the result shape type is compatible with the expected.
719   const TopAbs_ShapeEnum aShType = aShape.ShapeType();
720
721   if (!anExpectedType.empty()) {
722     bool ok = false;
723     std::list<TopAbs_ShapeEnum>::const_iterator it;
724     for (it = anExpectedType.begin(); it != anExpectedType.end() && !ok; ++it)
725       ok = (*it == TopAbs_SHAPE || *it == aShType);
726     if (!ok)
727       Standard_ConstructionError::Raise("Result type check failed");
728   }
729
730   aFunction->SetValue(aShape);
731
732   log.SetTouched(Label());
733
734   if (!aWarning.IsEmpty())
735     Standard_Failure::Raise(aWarning.ToCString());
736
737   return 1;
738 }
739
740 TopoDS_Wire GEOMImpl_ShapeDriver::MakeWireFromEdges(const Handle(TColStd_HSequenceOfTransient)& theEdgesFuncs,
741                                                     const Standard_Real theTolerance)
742 {
743   BRep_Builder B;
744
745   TopoDS_Wire aWire;
746   B.MakeWire(aWire);
747
748   // add edges
749   for (unsigned int ind = 1; ind <= theEdgesFuncs->Length(); ind++) {
750     Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(theEdgesFuncs->Value(ind));
751     TopoDS_Shape aShape_i = aRefShape->GetValue();
752     if (aShape_i.IsNull()) {
753       Standard_NullObject::Raise("Shape for wire construction is null");
754     }
755     if (aShape_i.ShapeType() == TopAbs_EDGE || aShape_i.ShapeType() == TopAbs_WIRE) {
756       TopExp_Explorer exp (aShape_i, TopAbs_EDGE);
757       for (; exp.More(); exp.Next())
758         B.Add(aWire, TopoDS::Edge(exp.Current()));
759     } else {
760       Standard_TypeMismatch::Raise
761         ("Shape for wire construction is neither an edge nor a wire");
762     }
763   }
764
765   // fix edges order
766   Handle(ShapeFix_Wire) aFW = new ShapeFix_Wire;
767   aFW->Load(aWire);
768   aFW->FixReorder();
769
770   if (aFW->StatusReorder(ShapeExtend_FAIL1)) {
771     Standard_ConstructionError::Raise("Wire construction failed: several loops detected");
772   }
773   else if (aFW->StatusReorder(ShapeExtend_FAIL)) {
774     Standard_ConstructionError::Raise("Wire construction failed");
775   }
776   else {
777   }
778
779   // IMP 0019766: Building a Wire from unconnected edges by introducing a tolerance
780   aFW->ClosedWireMode() = Standard_False;
781   aFW->FixConnected(theTolerance);
782   if (aFW->StatusConnected(ShapeExtend_FAIL)) {
783     Standard_ConstructionError::Raise("Wire construction failed: cannot build connected wire");
784   }
785   // IMP 0019766
786   if (aFW->StatusConnected(ShapeExtend_DONE3)) {
787     // Confused with <prec> but not Analyzer.Precision(), set the same
788     aFW->FixGapsByRangesMode() = Standard_True;
789     if (aFW->FixGaps3d()) {
790       Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
791       Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
792       for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
793         TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
794         aFe->FixVertexTolerance(aEdge);
795         aFe->FixSameParameter(aEdge);
796       }
797     }
798     else if (aFW->StatusGaps3d(ShapeExtend_FAIL)) {
799       Standard_ConstructionError::Raise("Wire construction failed: cannot fix 3d gaps");
800     }
801   }
802   aWire = aFW->WireAPIMake();
803
804   return aWire;
805 }
806
807 TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
808                                                    const Standard_Real LinTol,
809                                                    const Standard_Real AngTol)
810 {
811     TopoDS_Edge ResEdge;
812
813     BRepLib::BuildCurves3d(aWire);
814     Handle(ShapeFix_Shape) Fixer = new ShapeFix_Shape(aWire);
815     Fixer->SetPrecision(LinTol);
816     Fixer->SetMaxTolerance(LinTol);
817     Fixer->Perform();
818     TopoDS_Wire theWire = TopoDS::Wire(Fixer->Shape());
819
820     TColGeom_SequenceOfCurve CurveSeq;
821     TopTools_SequenceOfShape LocSeq;
822     TColStd_SequenceOfReal FparSeq;
823     TColStd_SequenceOfReal LparSeq;
824     TColStd_SequenceOfReal TolSeq;
825     GeomAbs_CurveType CurType;
826     TopoDS_Vertex FirstVertex, LastVertex;
827     Standard_Real aPntShiftDist = 0.;
828
829     BRepTools_WireExplorer wexp(theWire) ;
830     for (; wexp.More(); wexp.Next())
831     {
832       TopoDS_Edge anEdge = wexp.Current();
833       Standard_Real fpar, lpar;
834       TopLoc_Location aLoc;
835       Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aLoc, fpar, lpar);
836       if (aCurve.IsNull())
837         continue;
838
839       BRepAdaptor_Curve BAcurve(anEdge);
840       GeomAbs_CurveType aType = BAcurve.GetType();
841
842       Handle(Geom_Curve) aBasisCurve = BAcurve.Curve().Curve();
843
844       if (aBasisCurve->IsPeriodic())
845         ElCLib::AdjustPeriodic(aBasisCurve->FirstParameter(), aBasisCurve->LastParameter(),
846                                Precision::PConfusion(), fpar, lpar);
847
848       if (CurveSeq.IsEmpty())
849       {
850         CurveSeq.Append(aCurve);
851         TopoDS_Shape aLocShape;
852         aLocShape.Location(aLoc);
853         aLocShape.Orientation(wexp.Orientation());
854         LocSeq.Append(aLocShape);
855         FparSeq.Append(fpar);
856         LparSeq.Append(lpar);
857         CurType = aType;
858         FirstVertex = wexp.CurrentVertex();
859       }
860       else
861       {
862         Standard_Boolean Done = Standard_False;
863         Standard_Real NewFpar, NewLpar;
864         GeomAdaptor_Curve GAprevcurve(CurveSeq.Last());
865         TopoDS_Vertex CurVertex = wexp.CurrentVertex();
866         TopoDS_Vertex CurFirstVer = TopExp::FirstVertex(anEdge);
867         TopAbs_Orientation ConnectByOrigin = (CurVertex.IsSame(CurFirstVer))? TopAbs_FORWARD : TopAbs_REVERSED;
868         if (aCurve == CurveSeq.Last())
869         {
870           NewFpar = fpar;
871           NewLpar = lpar;
872           if (aBasisCurve->IsPeriodic())
873           {
874             if (NewLpar < NewFpar)
875               NewLpar += aBasisCurve->Period();
876             if (ConnectByOrigin == TopAbs_FORWARD)
877               ElCLib::AdjustPeriodic(FparSeq.Last(),
878                                      FparSeq.Last() + aBasisCurve->Period(),
879                                      Precision::PConfusion(), NewFpar, NewLpar);
880             else
881               ElCLib::AdjustPeriodic(FparSeq.Last() - aBasisCurve->Period(),
882                                      FparSeq.Last(),
883                                      Precision::PConfusion(), NewFpar, NewLpar);
884           }
885           Done = Standard_True;
886         }
887         else if (aType == CurType &&
888                  aType != GeomAbs_BezierCurve &&
889                  aType != GeomAbs_BSplineCurve &&
890                  aType != GeomAbs_OtherCurve)
891         {
892           switch (aType)
893           {
894           case GeomAbs_Line:
895             {
896               gp_Lin aLine    = BAcurve.Line();
897               gp_Lin PrevLine = GAprevcurve.Line();
898               if (aLine.Contains(PrevLine.Location(), LinTol) &&
899                   aLine.Direction().IsParallel(PrevLine.Direction(), AngTol))
900               {
901                 gp_Pnt P1 = ElCLib::Value(fpar, aLine);
902                 gp_Pnt P2 = ElCLib::Value(lpar, aLine);
903                 NewFpar = ElCLib::Parameter(PrevLine, P1);
904                 NewLpar = ElCLib::Parameter(PrevLine, P2);
905
906                 // Compute shift
907                 if (ConnectByOrigin == TopAbs_FORWARD) {
908                   gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevLine);
909
910                   aPntShiftDist += P2.Distance(aNewP2);
911                 } else {
912                   gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevLine);
913
914                   aPntShiftDist += P1.Distance(aNewP1);
915                 }
916
917                 if (NewLpar < NewFpar)
918                 {
919                   Standard_Real MemNewFpar = NewFpar;
920                   NewFpar = NewLpar;
921                   NewLpar = MemNewFpar;
922                   ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
923                 }
924                 Done = Standard_True;
925               }
926               break;
927             }
928           case GeomAbs_Circle:
929             {
930               gp_Circ aCircle    = BAcurve.Circle();
931               gp_Circ PrevCircle = GAprevcurve.Circle();
932               if (aCircle.Location().Distance(PrevCircle.Location()) <= LinTol &&
933                   Abs(aCircle.Radius() - PrevCircle.Radius()) <= LinTol &&
934                   aCircle.Axis().IsParallel(PrevCircle.Axis(), AngTol))
935               {
936                 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
937
938                 if (aCircle.Axis().Direction() * PrevCircle.Axis().Direction() < 0.)
939                 {
940                   Standard_Real memfpar = fpar;
941                   fpar = lpar;
942                   lpar = memfpar;
943                   ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
944                 }
945                 gp_Pnt P1 = ElCLib::Value(fpar, aCircle);
946                 gp_Pnt P2 = ElCLib::Value(lpar, aCircle);
947                 NewFpar = ElCLib::Parameter(PrevCircle, P1);
948                 NewLpar = ElCLib::Parameter(PrevCircle, P2);
949
950                 // Compute shift
951                 if (isFwd) {
952                   gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevCircle);
953
954                   aPntShiftDist += P2.Distance(aNewP2);
955                 } else {
956                   gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevCircle);
957
958                   aPntShiftDist += P1.Distance(aNewP1);
959                 }
960
961                 if (NewLpar < NewFpar)
962                   NewLpar += 2.*M_PI;
963                 //Standard_Real MemNewFpar = NewFpar, MemNewLpar =  NewLpar;
964                 if (ConnectByOrigin == TopAbs_FORWARD)
965                   ElCLib::AdjustPeriodic(FparSeq.Last(),
966                                          FparSeq.Last() + 2.*M_PI,
967                                          Precision::PConfusion(), NewFpar, NewLpar);
968                 else
969                   ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
970                                          FparSeq.Last(),
971                                          Precision::PConfusion(), NewFpar, NewLpar);
972                 Done = Standard_True;
973               }
974               break;
975             }
976           case GeomAbs_Ellipse:
977             {
978               gp_Elips anEllipse   = BAcurve.Ellipse();
979               gp_Elips PrevEllipse = GAprevcurve.Ellipse();
980               if (anEllipse.Focus1().Distance(PrevEllipse.Focus1()) <= LinTol &&
981                   anEllipse.Focus2().Distance(PrevEllipse.Focus2()) <= LinTol &&
982                   Abs(anEllipse.MajorRadius() - PrevEllipse.MajorRadius()) <= LinTol &&
983                   Abs(anEllipse.MinorRadius() - PrevEllipse.MinorRadius()) <= LinTol &&
984                   anEllipse.Axis().IsParallel(PrevEllipse.Axis(), AngTol))
985               {
986                 const Standard_Boolean isFwd = ConnectByOrigin == TopAbs_FORWARD;
987
988                 if (anEllipse.Axis().Direction() * PrevEllipse.Axis().Direction() < 0.)
989                 {
990                   Standard_Real memfpar = fpar;
991                   fpar = lpar;
992                   lpar = memfpar;
993                   ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
994                 }
995                 gp_Pnt P1 = ElCLib::Value(fpar, anEllipse);
996                 gp_Pnt P2 = ElCLib::Value(lpar, anEllipse);
997                 NewFpar = ElCLib::Parameter(PrevEllipse, P1);
998                 NewLpar = ElCLib::Parameter(PrevEllipse, P2);
999
1000                 // Compute shift
1001                 if (isFwd) {
1002                   gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevEllipse);
1003
1004                   aPntShiftDist += P2.Distance(aNewP2);
1005                 } else {
1006                   gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevEllipse);
1007
1008                   aPntShiftDist += P1.Distance(aNewP1);
1009                 }
1010
1011                 if (NewLpar < NewFpar)
1012                   NewLpar += 2.*M_PI;
1013                 if (ConnectByOrigin == TopAbs_FORWARD)
1014                   ElCLib::AdjustPeriodic(FparSeq.Last(),
1015                                          FparSeq.Last() + 2.*M_PI,
1016                                          Precision::PConfusion(), NewFpar, NewLpar);
1017                 else
1018                   ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
1019                                          FparSeq.Last(),
1020                                          Precision::PConfusion(), NewFpar, NewLpar);
1021                 Done = Standard_True;
1022               }
1023               break;
1024             }
1025           case GeomAbs_Hyperbola:
1026             {
1027               gp_Hypr aHypr    = BAcurve.Hyperbola();
1028               gp_Hypr PrevHypr = GAprevcurve.Hyperbola();
1029               if (aHypr.Focus1().Distance(PrevHypr.Focus1()) <= LinTol &&
1030                   aHypr.Focus2().Distance(PrevHypr.Focus2()) <= LinTol &&
1031                   Abs(aHypr.MajorRadius() - PrevHypr.MajorRadius()) <= LinTol &&
1032                   Abs(aHypr.MinorRadius() - PrevHypr.MinorRadius()) <= LinTol &&
1033                   aHypr.Axis().IsParallel(PrevHypr.Axis(), AngTol))
1034               {
1035                 gp_Pnt P1 = ElCLib::Value(fpar, aHypr);
1036                 gp_Pnt P2 = ElCLib::Value(lpar, aHypr);
1037                 NewFpar = ElCLib::Parameter(PrevHypr, P1);
1038                 NewLpar = ElCLib::Parameter(PrevHypr, P2);
1039
1040                 // Compute shift
1041                 if (ConnectByOrigin == TopAbs_FORWARD) {
1042                   gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevHypr);
1043
1044                   aPntShiftDist += P2.Distance(aNewP2);
1045                 } else {
1046                   gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevHypr);
1047
1048                   aPntShiftDist += P1.Distance(aNewP1);
1049                 }
1050
1051                 if (NewLpar < NewFpar)
1052                 {
1053                   Standard_Real MemNewFpar = NewFpar;
1054                   NewFpar = NewLpar;
1055                   NewLpar = MemNewFpar;
1056                   ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1057                 }
1058                 Done = Standard_True;
1059               }
1060               break;
1061             }
1062           case GeomAbs_Parabola:
1063             {
1064               gp_Parab aParab    = BAcurve.Parabola();
1065               gp_Parab PrevParab = GAprevcurve.Parabola();
1066               if (aParab.Location().Distance(PrevParab.Location()) <= LinTol &&
1067                   aParab.Focus().Distance(PrevParab.Focus()) <= LinTol &&
1068                   Abs(aParab.Focal() - PrevParab.Focal()) <= LinTol &&
1069                   aParab.Axis().IsParallel(PrevParab.Axis(), AngTol))
1070               {
1071                 gp_Pnt P1 = ElCLib::Value(fpar, aParab);
1072                 gp_Pnt P2 = ElCLib::Value(lpar, aParab);
1073                 NewFpar = ElCLib::Parameter(PrevParab, P1);
1074                 NewLpar = ElCLib::Parameter(PrevParab, P2);
1075
1076                 // Compute shift
1077                 if (ConnectByOrigin == TopAbs_FORWARD) {
1078                   gp_Pnt aNewP2 = ElCLib::Value(NewLpar, PrevParab);
1079
1080                   aPntShiftDist += P2.Distance(aNewP2);
1081                 } else {
1082                   gp_Pnt aNewP1 = ElCLib::Value(NewFpar, PrevParab);
1083
1084                   aPntShiftDist += P1.Distance(aNewP1);
1085                 }
1086
1087                 if (NewLpar < NewFpar)
1088                 {
1089                   Standard_Real MemNewFpar = NewFpar;
1090                   NewFpar = NewLpar;
1091                   NewLpar = MemNewFpar;
1092                   ConnectByOrigin = TopAbs::Reverse(ConnectByOrigin);
1093                 }
1094                 Done = Standard_True;
1095               }
1096               break;
1097             }
1098           } //end of switch (aType)
1099         } // end of else if (aType == CurType && ...
1100         if (Done)
1101         {
1102           if (NewFpar < FparSeq.Last())
1103             FparSeq(FparSeq.Length()) = NewFpar;
1104           else
1105             LparSeq(LparSeq.Length()) = NewLpar;
1106         }
1107         else
1108         {
1109           CurveSeq.Append(aCurve);
1110           TopoDS_Shape aLocShape;
1111           aLocShape.Location(aLoc);
1112           aLocShape.Orientation(wexp.Orientation());
1113           LocSeq.Append(aLocShape);
1114           FparSeq.Append(fpar);
1115           LparSeq.Append(lpar);
1116           TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(CurVertex));
1117           aPntShiftDist = 0.;
1118           CurType = aType;
1119         }
1120       } // end of else (CurveSeq.IsEmpty()) -> not first time
1121     } // end for (; wexp.More(); wexp.Next())
1122
1123     LastVertex = wexp.CurrentVertex();
1124     TolSeq.Append(aPntShiftDist + BRep_Tool::Tolerance(LastVertex));
1125
1126     FirstVertex.Orientation(TopAbs_FORWARD);
1127     LastVertex.Orientation(TopAbs_REVERSED);
1128
1129     if (!CurveSeq.IsEmpty())
1130     {
1131       Standard_Integer nb_curve = CurveSeq.Length();   //number of curves
1132       TColGeom_Array1OfBSplineCurve tab(0,nb_curve-1);                    //array of the curves
1133       TColStd_Array1OfReal tabtolvertex(0,nb_curve-1); //(0,nb_curve-2);  //array of the tolerances
1134
1135       Standard_Integer i;
1136
1137       if (nb_curve > 1)
1138       {
1139         for (i = 1; i <= nb_curve; i++)
1140         {
1141           if (CurveSeq(i)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1142             CurveSeq(i) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(i))))->BasisCurve();
1143
1144           Handle(Geom_TrimmedCurve) aTrCurve = new Geom_TrimmedCurve(CurveSeq(i), FparSeq(i), LparSeq(i));
1145           tab(i-1) = GeomConvert::CurveToBSplineCurve(aTrCurve);
1146           tab(i-1)->Transform(LocSeq(i).Location().Transformation());
1147           GeomConvert::C0BSplineToC1BSplineCurve(tab(i-1), Precision::Confusion());
1148           if (LocSeq(i).Orientation() == TopAbs_REVERSED)
1149             tab(i-1)->Reverse();
1150
1151           //Temporary
1152           //char* name = new char[100];
1153           //sprintf(name, "c%d", i);
1154           //DrawTrSurf::Set(name, tab(i-1));
1155
1156           if (i > 1)
1157             tabtolvertex(i-2) = TolSeq(i-1);
1158         } // end for (i = 1; i <= nb_curve; i++)
1159         tabtolvertex(nb_curve-1) = TolSeq(TolSeq.Length());
1160
1161         Standard_Boolean closed_flag = Standard_False;
1162         Standard_Real closed_tolerance = 0.;
1163         if (FirstVertex.IsSame(LastVertex) &&
1164             GeomLProp::Continuity(tab(0), tab(nb_curve-1),
1165                                   tab(0)->FirstParameter(),
1166                                   tab(nb_curve-1)->LastParameter(),
1167                                   Standard_False, Standard_False, LinTol, AngTol) >= GeomAbs_G1)
1168         {
1169           closed_flag = Standard_True ;
1170           closed_tolerance = BRep_Tool::Tolerance(FirstVertex);
1171         }
1172
1173         Handle(TColGeom_HArray1OfBSplineCurve)  concatcurve;     //array of the concatenated curves
1174         Handle(TColStd_HArray1OfInteger)        ArrayOfIndices;  //array of the remining Vertex
1175         GeomConvert::ConcatC1(tab,
1176                               tabtolvertex,
1177                               ArrayOfIndices,
1178                               concatcurve,
1179                               closed_flag,
1180                               closed_tolerance);   //C1 concatenation
1181
1182         if (concatcurve->Length() > 1)
1183         {
1184           GeomConvert_CompCurveToBSplineCurve Concat(concatcurve->Value(concatcurve->Lower()));
1185
1186           for (i = concatcurve->Lower()+1; i <= concatcurve->Upper(); i++)
1187             Concat.Add( concatcurve->Value(i), LinTol, Standard_True );
1188
1189           concatcurve->SetValue(concatcurve->Lower(), Concat.BSplineCurve());
1190         }
1191         // rnc : prevents the driver from building an edge without C1 continuity
1192         if (concatcurve->Value(concatcurve->Lower())->Continuity()==GeomAbs_C0){
1193           Standard_ConstructionError::Raise("Construction aborted : The given Wire has sharp bends between some Edges, no valid Edge can be built");
1194         }
1195
1196         Standard_Boolean isValidEndVtx = Standard_True;
1197
1198         if (closed_flag) {
1199           // Check if closed curve is reordered.
1200           Handle(Geom_Curve) aCurve  = concatcurve->Value(concatcurve->Lower());
1201           Standard_Real      aFPar   = aCurve->FirstParameter();
1202           gp_Pnt             aPFirst;
1203           gp_Pnt             aPntVtx = BRep_Tool::Pnt(FirstVertex);
1204           Standard_Real      aTolVtx = BRep_Tool::Tolerance(FirstVertex);
1205
1206           aCurve->D0(aFPar, aPFirst);
1207
1208           if (!aPFirst.IsEqual(aPntVtx, aTolVtx)) {
1209             // The curve is reordered. Find the new first and last vertices.
1210             TopTools_IndexedMapOfShape aMapVtx;
1211             TopExp::MapShapes(theWire, TopAbs_VERTEX, aMapVtx);
1212
1213             const Standard_Integer aNbVtx = aMapVtx.Extent();
1214             Standard_Integer       iVtx;
1215
1216             for (iVtx = 1; iVtx <= aNbVtx; iVtx++) {
1217               const TopoDS_Vertex aVtx = TopoDS::Vertex(aMapVtx.FindKey(iVtx));
1218               const gp_Pnt        aPnt = BRep_Tool::Pnt(aVtx);
1219               const Standard_Real aTol = BRep_Tool::Tolerance(aVtx);
1220
1221               if (aPFirst.IsEqual(aPnt, aTol)) {
1222                 // The coinsident vertex is found.
1223                 FirstVertex = aVtx;
1224                 LastVertex  = aVtx;
1225                 FirstVertex.Orientation(TopAbs_FORWARD);
1226                 LastVertex.Orientation(TopAbs_REVERSED);
1227                 break;
1228               }
1229             }
1230
1231             if (iVtx > aNbVtx) {
1232               // It is necessary to create new vertices.
1233               isValidEndVtx = Standard_False;
1234             }
1235           }
1236         }
1237
1238         if (isValidEndVtx) {
1239           ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1240                                      FirstVertex, LastVertex,
1241                                      concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1242                                      concatcurve->Value(concatcurve->Lower())->LastParameter());
1243         } else {
1244           ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
1245                                      concatcurve->Value(concatcurve->Lower())->FirstParameter(),
1246                                      concatcurve->Value(concatcurve->Lower())->LastParameter());
1247         }
1248       }
1249       else
1250       {
1251         if (CurveSeq(1)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1252           CurveSeq(1) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(1))))->BasisCurve();
1253
1254         Handle(Geom_Curve) aNewCurve =
1255           Handle(Geom_Curve)::DownCast(CurveSeq(1)->Copy());
1256
1257         aNewCurve->Transform(LocSeq(1).Location().Transformation());
1258
1259         if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1260           const TopoDS_Vertex aVtxTmp = FirstVertex;
1261
1262           FirstVertex = LastVertex;
1263           LastVertex  = aVtxTmp;
1264           FirstVertex.Orientation(TopAbs_FORWARD);
1265           LastVertex.Orientation(TopAbs_REVERSED);
1266         }
1267
1268         ResEdge = BRepLib_MakeEdge(aNewCurve,
1269                                    FirstVertex, LastVertex,
1270                                    FparSeq(1), LparSeq(1));
1271
1272         if (LocSeq(1).Orientation() == TopAbs_REVERSED) {
1273           ResEdge.Reverse();
1274         }
1275       }
1276     }
1277
1278     return ResEdge;
1279 }
1280
1281 //=============================================================================
1282 /*!
1283  * \brief Returns an isoline for a face.
1284  */
1285 //=============================================================================
1286
1287 TopoDS_Shape GEOMImpl_ShapeDriver::MakeIsoline
1288                             (const TopoDS_Face &theFace,
1289                              const bool         IsUIso,
1290                              const double       theParameter) const
1291 {
1292   TopoDS_Shape          aResult;
1293   GEOMUtils::Hatcher    aHatcher(theFace);
1294   const GeomAbs_IsoType aType = (IsUIso ? GeomAbs_IsoU : GeomAbs_IsoV);
1295
1296   aHatcher.Init(aType, theParameter);
1297   aHatcher.Perform();
1298
1299   if (!aHatcher.IsDone()) {
1300     Standard_ConstructionError::Raise("MakeIsoline : Hatcher failure");
1301   }
1302
1303   const Handle(TColStd_HArray1OfInteger) &anIndices =
1304     (IsUIso ? aHatcher.GetUIndices() : aHatcher.GetVIndices());
1305
1306   if (anIndices.IsNull()) {
1307     Standard_ConstructionError::Raise("MakeIsoline : Null hatching indices");
1308   }
1309
1310   const Standard_Integer anIsoInd = anIndices->Lower();
1311   const Standard_Integer aHatchingIndex = anIndices->Value(anIsoInd);
1312
1313   if (aHatchingIndex == 0) {
1314     Standard_ConstructionError::Raise("MakeIsoline : Invalid hatching index");
1315   }
1316
1317   const Standard_Integer aNbDomains =
1318     aHatcher.GetNbDomains(aHatchingIndex);
1319
1320   if (aNbDomains < 0) {
1321     Standard_ConstructionError::Raise("MakeIsoline : Invalid number of domains");
1322   }
1323
1324   // The hatching is performed successfully. Create the 3d Curve.
1325   Handle(Geom_Surface) aSurface   = BRep_Tool::Surface(theFace);
1326   Handle(Geom_Curve)   anIsoCurve = (IsUIso ?
1327     aSurface->UIso(theParameter) : aSurface->VIso(theParameter));
1328   Handle(Geom2d_Curve) aPIsoCurve =
1329     aHatcher.GetHatching(aHatchingIndex);
1330   const Standard_Real  aTol = Precision::Confusion();
1331   Standard_Integer     anIDom = 1;
1332   Standard_Real        aV1;
1333   Standard_Real        aV2;
1334   BRep_Builder         aBuilder;
1335   Standard_Integer     aNbEdges = 0;
1336
1337   for (; anIDom <= aNbDomains; anIDom++) {
1338     if (aHatcher.GetDomain(aHatchingIndex, anIDom, aV1, aV2)) {
1339       // Check first and last parameters.
1340       if (!aHatcher.IsDomainInfinite(aHatchingIndex, anIDom)) {
1341         // Create an edge.
1342         TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(anIsoCurve, aV1, aV2);
1343
1344         // Update it with a parametric curve on face.
1345         aBuilder.UpdateEdge(anEdge, aPIsoCurve, theFace, aTol);
1346         aNbEdges++;
1347
1348         if (aNbEdges > 1) {
1349           // Result is a compond.
1350           if (aNbEdges == 2) {
1351             // Create a new compound.
1352             TopoDS_Compound aCompound;
1353
1354             aBuilder.MakeCompound(aCompound);
1355             aBuilder.Add(aCompound, aResult);
1356             aResult = aCompound;
1357           }
1358
1359           // Add an edge to the compound.
1360           aBuilder.Add(aResult, anEdge);
1361         } else {
1362           // Result is the edge.
1363           aResult = anEdge;
1364         }
1365       }
1366     }
1367   }
1368
1369   if (aNbEdges == 0) {
1370     Standard_ConstructionError::Raise("MakeIsoline : Empty result");
1371   }
1372
1373   return aResult;
1374 }
1375
1376 //=============================================================================
1377 /*!
1378  * \brief Returns an extended edge.
1379  */
1380 //=============================================================================
1381
1382 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendEdge
1383                          (const TopoDS_Edge   &theEdge,
1384                           const Standard_Real  theMin,
1385                           const Standard_Real  theMax) const
1386 {
1387   TopoDS_Shape        aResult;
1388   Standard_Real       aF;
1389   Standard_Real       aL;
1390   Handle(Geom_Curve)  aCurve   = BRep_Tool::Curve(theEdge, aF, aL);
1391   const Standard_Real aTol     = BRep_Tool::Tolerance(theEdge);
1392   Standard_Real       aRange2d = aL - aF;
1393
1394   if (aCurve.IsNull() == Standard_False && aRange2d > aTol) {
1395     Standard_Real aMin = aF + aRange2d*theMin;
1396     Standard_Real aMax = aF + aRange2d*theMax;
1397
1398     Handle(Standard_Type) aType = aCurve->DynamicType();
1399
1400     // Get the curve of original type
1401     while (aType == STANDARD_TYPE(Geom_TrimmedCurve)) {
1402       Handle(Geom_TrimmedCurve) aTrCurve =
1403         Handle(Geom_TrimmedCurve)::DownCast(aCurve);
1404
1405       aCurve = aTrCurve->BasisCurve();
1406       aType  = aCurve->DynamicType();
1407     }
1408
1409     if (aCurve->IsPeriodic()) {
1410       // The curve is periodic. Check if a new range is less then a period.
1411       if (aMax - aMin > aCurve->Period()) {
1412         aMax = aMin + aCurve->Period();
1413       }
1414     } else {
1415       // The curve is not periodic. Check if aMin and aMax within bounds.
1416       aMin = Max(aMin, aCurve->FirstParameter());
1417       aMax = Min(aMax, aCurve->LastParameter());
1418     }
1419
1420     if (aMax - aMin > aTol) {
1421       // Create a new edge.
1422       BRepBuilderAPI_MakeEdge aME (aCurve, aMin, aMax);
1423
1424       if (aME.IsDone()) {
1425         aResult = aME.Shape();
1426       }
1427     }
1428   }
1429
1430   return aResult;
1431 }
1432
1433 //=============================================================================
1434 /*!
1435  * \brief Returns an extended face.
1436  */
1437 //=============================================================================
1438
1439 TopoDS_Shape GEOMImpl_ShapeDriver::ExtendFace
1440                          (const TopoDS_Face   &theFace,
1441                           const Standard_Real  theUMin,
1442                           const Standard_Real  theUMax,
1443                           const Standard_Real  theVMin,
1444                           const Standard_Real  theVMax) const
1445 {
1446   TopoDS_Shape         aResult;
1447   Handle(Geom_Surface) aSurface = BRep_Tool::Surface(theFace);
1448   const Standard_Real  aTol     = BRep_Tool::Tolerance(theFace);
1449   Standard_Real        aU1;
1450   Standard_Real        aU2;
1451   Standard_Real        aV1;
1452   Standard_Real        aV2;
1453
1454   // Get U, V bounds of the face.
1455   ShapeAnalysis::GetFaceUVBounds(theFace, aU1, aU2, aV1, aV2);
1456
1457   const Standard_Real aURange = aU2 - aU1;
1458   const Standard_Real aVRange = aV2 - aV1;
1459
1460   if (aSurface.IsNull() == Standard_False &&
1461       aURange > aTol && aURange > aTol) {
1462     Handle(Standard_Type) aType = aSurface->DynamicType();
1463
1464     // Get the surface of original type
1465     while (aType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1466       Handle(Geom_RectangularTrimmedSurface) aTrSurface =
1467         Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
1468
1469       aSurface = aTrSurface->BasisSurface();
1470       aType    = aSurface->DynamicType();
1471     }
1472
1473     Standard_Real aUMin = aU1 + aURange*theUMin;
1474     Standard_Real aUMax = aU1 + aURange*theUMax;
1475     Standard_Real aVMin = aV1 + aVRange*theVMin;
1476     Standard_Real aVMax = aV1 + aVRange*theVMax;
1477
1478     aSurface->Bounds(aU1, aU2, aV1, aV2);
1479
1480     if (aSurface->IsUPeriodic()) {
1481       // The surface is U-periodic. Check if a new U range is less
1482       // then a period.
1483       if (aUMax - aUMin > aSurface->UPeriod()) {
1484         aUMax = aUMin + aSurface->UPeriod();
1485       }
1486     } else {
1487       // The surface is not V-periodic. Check if aUMin and aUMax
1488       // within bounds.
1489       aUMin = Max(aUMin, aU1);
1490       aUMax = Min(aUMax, aU2);
1491     }
1492
1493     if (aSurface->IsVPeriodic()) {
1494       // The surface is V-periodic. Check if a new V range is less
1495       // then a period.
1496       if (aVMax - aVMin > aSurface->VPeriod()) {
1497         aVMax = aVMin + aSurface->VPeriod();
1498       }
1499     } else {
1500       // The surface is not V-periodic. Check if aVMin and aVMax
1501       // within bounds.
1502       aVMin = Max(aVMin, aV1);
1503       aVMax = Min(aVMax, aV2);
1504     }
1505
1506     if (aUMax - aUMin > aTol && aVMax - aVMin > aTol) {
1507       // Create a new edge.
1508       BRepBuilderAPI_MakeFace aMF
1509         (aSurface, aUMin, aUMax, aVMin, aVMax, aTol);
1510     
1511       if (aMF.IsDone()) {
1512         aResult = aMF.Shape();
1513       }
1514     }
1515   }
1516
1517   return aResult;
1518 }
1519
1520 //================================================================================
1521 /*!
1522  * \brief Returns a name of creation operation and names and values of creation parameters
1523  */
1524 //================================================================================
1525
1526 bool GEOMImpl_ShapeDriver::
1527 GetCreationInformation(std::string&             theOperationName,
1528                        std::vector<GEOM_Param>& theParams)
1529 {
1530   if (Label().IsNull()) return 0;
1531   Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
1532
1533   GEOMImpl_IShapes aCI( function );
1534   Standard_Integer aType = function->GetType();
1535
1536   switch ( aType ) {
1537   case WIRE_EDGES:
1538     theOperationName = "WIRE";
1539     AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1540     AddParam( theParams, "Tolerance", aCI.GetTolerance() );
1541     break;
1542   case FACE_WIRE:
1543     theOperationName = "FACE";
1544     AddParam( theParams, "Wire/edge", aCI.GetBase() );
1545     AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1546     break;
1547   case FACE_WIRES:
1548     theOperationName = "FACE";
1549     AddParam( theParams, "Wires/edges", aCI.GetShapes() );
1550     AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
1551     break;
1552   case FACE_FROM_SURFACE:
1553   {
1554     theOperationName = "FACE";
1555
1556     Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1557
1558     if (shapes.IsNull() == Standard_False) {
1559       Standard_Integer aNbShapes = shapes->Length();
1560
1561       if (aNbShapes > 0) {
1562         AddParam(theParams, "Face", shapes->Value(1));
1563
1564         if (aNbShapes > 1) {
1565           AddParam(theParams, "Wire", shapes->Value(2));
1566         }
1567       }
1568     }
1569     break;
1570   }
1571   case SHELL_FACES:
1572     theOperationName = "SHELL";
1573     AddParam( theParams, "Objects", aCI.GetShapes() );
1574     break;
1575   case SOLID_SHELLS:
1576     theOperationName = "SOLID";
1577     AddParam( theParams, "Objects", aCI.GetShapes() );
1578     break;
1579   case SOLID_FACES:
1580     theOperationName = "SOLID_FROM_FACES";
1581     AddParam( theParams, "Objects", aCI.GetShapes() );
1582     AddParam( theParams, "Is intersect", aCI.GetIsIntersect() );
1583     break;
1584   case COMPOUND_SHAPES:
1585     theOperationName = "COMPOUND";
1586     AddParam( theParams, "Objects", aCI.GetShapes() );
1587     break;
1588   case EDGE_WIRE:
1589     theOperationName = "EDGE";
1590     AddParam( theParams, "Wire", aCI.GetBase() );
1591     AddParam( theParams, "Linear Tolerance", aCI.GetTolerance() );
1592     AddParam( theParams, "Angular Tolerance", aCI.GetAngularTolerance() );
1593     break;
1594   case EDGE_CURVE_LENGTH:
1595     theOperationName = "EDGE";
1596     {
1597       GEOMImpl_IVector aCI( function );
1598       AddParam( theParams, "Edge", aCI.GetPoint1() );
1599       AddParam( theParams, "Start point", aCI.GetPoint2() );
1600       AddParam( theParams, "Length", aCI.GetParameter() );
1601     }
1602     break;
1603   case SHAPES_ON_SHAPE:
1604   {
1605     theOperationName = "GetShapesOnShapeAsCompound";
1606     Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
1607     if ( !shapes.IsNull() && shapes->Length() > 0 )
1608       AddParam( theParams, "Check shape", shapes->Value(1) );
1609     if ( !shapes.IsNull() && shapes->Length() > 1 )
1610       AddParam( theParams, "Shape", shapes->Value(2) );
1611     AddParam( theParams, "Shape type", TopAbs_ShapeEnum( aCI.GetSubShapeType() ));
1612     AddParam( theParams, "State" );
1613     GEOMAlgo_State st = GEOMAlgo_State( (int) ( aCI.GetTolerance()+0.1 ) );
1614     const char* stName[] = { "UNKNOWN","IN","OUT","ON","ONIN","ONOUT","INOUT" };
1615     if ( 0 <= st && st <= GEOMAlgo_ST_INOUT )
1616       theParams.back() << stName[ st ];
1617     else
1618       theParams.back() << (int) st;
1619     break;
1620   }
1621   case SHAPE_ISOLINE:
1622   {
1623     GEOMImpl_IIsoline aII (function);
1624
1625     theOperationName = "ISOLINE";
1626     AddParam(theParams, "Face", aII.GetFace());
1627     AddParam(theParams, "Isoline type", (aII.GetIsUIso() ? "U" : "V"));
1628     AddParam(theParams, "Parameter", aII.GetParameter());
1629     break;
1630   }
1631   case EDGE_UV:
1632   {
1633     GEOMImpl_IShapeExtend aSE (function);
1634
1635     theOperationName = "EDGE_EXTEND";
1636     AddParam(theParams, "Edge", aSE.GetShape());
1637     AddParam(theParams, "Min", aSE.GetUMin());
1638     AddParam(theParams, "Max", aSE.GetUMax());
1639     break;
1640   }
1641   case FACE_UV:
1642   {
1643     GEOMImpl_IShapeExtend aSE (function);
1644
1645     theOperationName = "FACE_EXTEND";
1646     AddParam(theParams, "Face", aSE.GetShape());
1647     AddParam(theParams, "UMin", aSE.GetUMin());
1648     AddParam(theParams, "UMax", aSE.GetUMax());
1649     AddParam(theParams, "VMin", aSE.GetVMin());
1650     AddParam(theParams, "VMax", aSE.GetVMax());
1651     break;
1652   }
1653   case SURFACE_FROM_FACE:
1654   {
1655     GEOMImpl_IShapeExtend aSE (function);
1656
1657     theOperationName = "SURFACE_FROM_FACE";
1658     AddParam(theParams, "Face", aSE.GetShape());
1659     break;
1660   }
1661   default:
1662     return false;
1663   }
1664
1665   return true;
1666 }
1667
1668 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1669 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
1670
1671 //modified by NIZNHY-PKV Wed Dec 28 13:48:31 2011f
1672 #include <TopoDS_Iterator.hxx>
1673 #include <TopTools_HSequenceOfShape.hxx>
1674 #include <ShapeAnalysis_FreeBounds.hxx>
1675 #include <TopTools_MapOfShape.hxx>
1676 #include <TopTools_MapOfOrientedShape.hxx>
1677 #include <BRep_Builder.hxx>
1678 #include <TopoDS_Wire.hxx>
1679
1680 //=======================================================================
1681 //function : KeepEdgesOrder
1682 //purpose  : 
1683 //=======================================================================
1684 /*
1685 void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
1686                     const Handle(TopTools_HSequenceOfShape)& aWires)
1687 {
1688   Standard_Integer aNbWires, aNbEdges;
1689   // 
1690   if (aEdges.IsNull()) {
1691     return;
1692   }
1693   //
1694   if (aWires.IsNull()) {
1695     return;
1696   }
1697   //
1698   aNbEdges=aEdges->Length();
1699   aNbWires=aWires->Length();
1700   if (!aNbEdges || !aNbWires) {
1701     return;
1702   }
1703   //-----
1704   Standard_Boolean bClosed;
1705   Standard_Integer i, j;
1706   TopoDS_Wire aWy;
1707   TopoDS_Iterator aIt;
1708   BRep_Builder aBB;
1709   TopTools_MapOfOrientedShape aMEx;
1710   //
1711   for (i=1; i<=aNbWires; ++i) {
1712     const TopoDS_Shape& aWx=aWires->Value(i);
1713     //
1714     aMEx.Clear();
1715     aIt.Initialize (aWx);
1716     for (; aIt.More(); aIt.Next()) {
1717       const TopoDS_Shape& aEx=aIt.Value();
1718       aMEx.Add(aEx);
1719     }
1720     // aWy
1721     aBB.MakeWire (aWy);
1722     for (j=1; j<=aNbEdges; ++j) {
1723       const TopoDS_Shape& aE=aEdges->Value(j);
1724       if (aMEx.Contains(aE)) {
1725         aBB.Add(aWy, aE);
1726       }
1727     }
1728     //
1729     bClosed=aWx.Closed();
1730     aWy.Closed(bClosed);
1731     //
1732     aWires->Append(aWy);
1733   }// for (i=1; i<=aNbWires; ++i) {
1734   //
1735   aWires->Remove(1, aNbWires);
1736 }
1737 */
1738 //modified by NIZNHY-PKV Wed Dec 28 13:48:34 2011t