Salome HOME
Mantis issue 0021465: EDF 2067 GEOM: Extrusion along a path leads to a self-intersect...
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ShapeDriver.cxx
index f254c2a0c6ef8e5940923bd97e27fc262cc64b96..f538cd337d500e7cfe5e8786f733bd7a1f5c28a1 100644 (file)
@@ -18,7 +18,6 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 #include <GEOMImpl_ShapeDriver.hxx>
 
 #include <Standard_TypeMismatch.hxx>
 #include <Standard_ConstructionError.hxx>
 
+//modified by NIZNHY-PKV Wed Dec 28 13:48:20 2011f
+//static
+//  void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
+//                   const Handle(TopTools_HSequenceOfShape)& aWires);
+//modified by NIZNHY-PKV Wed Dec 28 13:48:23 2011t
+
 //=======================================================================
 //function : GetID
 //purpose  :
@@ -122,6 +127,8 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
   Standard_Integer aType = aFunction->GetType();
 
   TopoDS_Shape aShape;
+  TCollection_AsciiString aWarning;
+
   BRep_Builder B;
 
   if (aType == WIRE_EDGES) {
@@ -215,7 +222,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
       Standard_NullObject::Raise
         ("Shape for face construction is neither a wire nor a closed edge");
     }
-    GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), aShape);
+    aWarning = GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), aShape);
     if (aShape.IsNull()) {
       Standard_ConstructionError::Raise("Face construction failed");
     }
@@ -250,6 +257,9 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     Handle(TopTools_HSequenceOfShape) aSeqWiresOut;
     ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdgesIn, Precision::Confusion(),
                                                   /*shared*/Standard_False, aSeqWiresOut);
+    //modified by NIZNHY-PKV Wed Dec 28 13:46:55 2011f
+    //KeepEdgesOrder(aSeqEdgesIn, aSeqWiresOut);
+    //modified by NIZNHY-PKV Wed Dec 28 13:46:59 2011t
 
     // 3. Separate closed wires
     Handle(TopTools_HSequenceOfShape) aSeqClosedWires = new TopTools_HSequenceOfShape;
@@ -271,7 +281,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     // 4.a. Basic face
     TopoDS_Shape aFFace;
     TopoDS_Wire aW1 = TopoDS::Wire(aSeqClosedWires->Value(1));
-    GEOMImpl_Block6Explorer::MakeFace(aW1, aCI.GetIsPlanar(), aFFace);
+    aWarning = GEOMImpl_Block6Explorer::MakeFace(aW1, aCI.GetIsPlanar(), aFFace);
     if (aFFace.IsNull()) {
       Standard_ConstructionError::Raise("Face construction failed");
     }
@@ -449,6 +459,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     aShape = C;
 
   }
+  /*
   else if (aType == REVERSE_ORIENTATION) {
     Handle(GEOM_Function) aRefShape = aCI.GetBase();
     TopoDS_Shape aShape_i = aRefShape->GetValue();
@@ -471,6 +482,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
       aShape = tds;
     }
   }
+  */
   else if (aType == EDGE_WIRE) {
     Handle(GEOM_Function) aRefBase = aCI.GetBase();
     TopoDS_Shape aWire = aRefBase->GetValue();
@@ -494,6 +506,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     TColStd_SequenceOfReal TolSeq;
     GeomAbs_CurveType CurType;
     TopoDS_Vertex FirstVertex, LastVertex;
+    Standard_Boolean FinalReverse = Standard_False;
 
     BRepTools_WireExplorer wexp(theWire) ;
     for (; wexp.More(); wexp.Next())
@@ -525,6 +538,8 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
         LparSeq.Append(lpar);
         CurType = aType;
         FirstVertex = wexp.CurrentVertex();
+        if (anEdge.Orientation() == TopAbs_REVERSED)
+          FinalReverse = Standard_True;
       }
       else
       {
@@ -602,14 +617,14 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
                 NewFpar = ElCLib::Parameter(PrevCircle, P1);
                 NewLpar = ElCLib::Parameter(PrevCircle, P2);
                 if (NewLpar < NewFpar)
-                  NewLpar += 2.*PI;
+                  NewLpar += 2.*M_PI;
                 //Standard_Real MemNewFpar = NewFpar, MemNewLpar =  NewLpar;
                 if (ConnectByOrigin == TopAbs_FORWARD)
                   ElCLib::AdjustPeriodic(FparSeq.Last(),
-                                         FparSeq.Last() + 2.*PI,
+                                         FparSeq.Last() + 2.*M_PI,
                                          Precision::PConfusion(), NewFpar, NewLpar);
                 else
-                  ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*PI,
+                  ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
                                          FparSeq.Last(),
                                          Precision::PConfusion(), NewFpar, NewLpar);
                 Done = Standard_True;
@@ -638,13 +653,13 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
                 NewFpar = ElCLib::Parameter(PrevEllipse, P1);
                 NewLpar = ElCLib::Parameter(PrevEllipse, P2);
                 if (NewLpar < NewFpar)
-                  NewLpar += 2.*PI;
+                  NewLpar += 2.*M_PI;
                 if (ConnectByOrigin == TopAbs_FORWARD)
                   ElCLib::AdjustPeriodic(FparSeq.Last(),
-                                         FparSeq.Last() + 2.*PI,
+                                         FparSeq.Last() + 2.*M_PI,
                                          Precision::PConfusion(), NewFpar, NewLpar);
                 else
-                  ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*PI,
+                  ElCLib::AdjustPeriodic(FparSeq.Last() - 2.*M_PI,
                                          FparSeq.Last(),
                                          Precision::PConfusion(), NewFpar, NewLpar);
                 Done = Standard_True;
@@ -727,6 +742,11 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     LastVertex = wexp.CurrentVertex();
     TolSeq.Append(BRep_Tool::Tolerance(LastVertex));
 
+    TopoDS_Vertex FirstVtx_final = (FinalReverse)? LastVertex : FirstVertex;
+    FirstVtx_final.Orientation(TopAbs_FORWARD);
+    TopoDS_Vertex LastVtx_final = (FinalReverse)? FirstVertex : LastVertex;
+    LastVtx_final.Orientation(TopAbs_REVERSED);
+
     if (!CurveSeq.IsEmpty())
     {
       Standard_Integer nb_curve = CurveSeq.Length();   //number of curves
@@ -794,20 +814,25 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
           Standard_ConstructionError::Raise("Construction aborted : The given Wire has sharp bends between some Edges, no valid Edge can be built");
         }
         ResEdge = BRepLib_MakeEdge(concatcurve->Value(concatcurve->Lower()),
-                                   FirstVertex, LastVertex);
+                                   FirstVtx_final, LastVtx_final,
+                                   concatcurve->Value(concatcurve->Lower())->FirstParameter(),
+                                   concatcurve->Value(concatcurve->Lower())->LastParameter());
       }
       else
       {
         if (CurveSeq(1)->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
-          CurveSeq(1) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(i))))->BasisCurve();
+          CurveSeq(1) = (*((Handle(Geom_TrimmedCurve)*)&(CurveSeq(1))))->BasisCurve();
 
         CurveSeq(1)->Transform(LocSeq(1).Location().Transformation());
         ResEdge = BRepLib_MakeEdge(CurveSeq(1),
-                                   FirstVertex, LastVertex,
+                                   FirstVtx_final, LastVtx_final,
                                    FparSeq(1), LparSeq(1));
       }
     }
 
+    if (FinalReverse)
+      ResEdge.Reverse();
+
     aShape = ResEdge;
   }
   else if (aType == EDGE_CURVE_LENGTH) {
@@ -872,7 +897,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
 
     // Get the point by length
     GeomAdaptor_Curve AdapCurve = GeomAdaptor_Curve(ReOrientedCurve);
-    GCPnts_AbscissaPoint anAbsPnt (AdapCurve, aLength, UFirst); 
+    GCPnts_AbscissaPoint anAbsPnt (AdapCurve, aLength, UFirst);
     Standard_Real aParam = anAbsPnt.Parameter();
 
     if (AdapCurve.IsClosed() && aLength < 0.0) {
@@ -900,6 +925,9 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
 
   log.SetTouched(Label());
 
+  if (!aWarning.IsEmpty())
+    Standard_Failure::Raise(aWarning.ToCString());
+
   return 1;
 }
 
@@ -945,3 +973,72 @@ const Handle(GEOMImpl_ShapeDriver) Handle(GEOMImpl_ShapeDriver)::DownCast(const
 
   return _anOtherObject;
 }
+
+//modified by NIZNHY-PKV Wed Dec 28 13:48:31 2011f
+#include <TopoDS_Iterator.hxx>
+#include <TopTools_HSequenceOfShape.hxx>
+#include <ShapeAnalysis_FreeBounds.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopTools_MapOfOrientedShape.hxx>
+#include <BRep_Builder.hxx>
+#include <TopoDS_Wire.hxx>
+
+//=======================================================================
+//function : KeepEdgesOrder
+//purpose  : 
+//=======================================================================
+/*
+void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
+                   const Handle(TopTools_HSequenceOfShape)& aWires)
+{
+  Standard_Integer aNbWires, aNbEdges;
+  // 
+  if (aEdges.IsNull()) {
+    return;
+  }
+  //
+  if (aWires.IsNull()) {
+    return;
+  }
+  //
+  aNbEdges=aEdges->Length();
+  aNbWires=aWires->Length();
+  if (!aNbEdges || !aNbWires) {
+    return;
+  }
+  //-----
+  Standard_Boolean bClosed;
+  Standard_Integer i, j;
+  TopoDS_Wire aWy;
+  TopoDS_Iterator aIt;
+  BRep_Builder aBB;
+  TopTools_MapOfOrientedShape aMEx;
+  //
+  for (i=1; i<=aNbWires; ++i) {
+    const TopoDS_Shape& aWx=aWires->Value(i);
+    //
+    aMEx.Clear();
+    aIt.Initialize (aWx);
+    for (; aIt.More(); aIt.Next()) {
+      const TopoDS_Shape& aEx=aIt.Value();
+      aMEx.Add(aEx);
+    }
+    // aWy
+    aBB.MakeWire (aWy);
+    for (j=1; j<=aNbEdges; ++j) {
+      const TopoDS_Shape& aE=aEdges->Value(j);
+      if (aMEx.Contains(aE)) {
+       aBB.Add(aWy, aE);
+      }
+    }
+    //
+    bClosed=aWx.Closed();
+    aWy.Closed(bClosed);
+    //
+    aWires->Append(aWy);
+  }// for (i=1; i<=aNbWires; ++i) {
+  //
+  aWires->Remove(1, aNbWires);
+}
+*/
+//modified by NIZNHY-PKV Wed Dec 28 13:48:34 2011t