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