]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #585: split/merge implementation
authorasl <asl@opencascade.com>
Fri, 26 Jun 2015 12:23:51 +0000 (15:23 +0300)
committerasl <asl@opencascade.com>
Fri, 26 Jun 2015 12:23:51 +0000 (15:23 +0300)
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_PolylineOperator.cxx
src/HYDROData/HYDROData_PolylineOperator.h
src/HYDROData/HYDROData_PolylineXY.cxx
src/HYDROData/HYDROData_SplitToZonesTool.h
src/HYDROGUI/HYDROGUI_MergePolylinesOp.cxx
src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx

index b0241aa91ba15b556d27f14eb7c47e5e85870665..be8f1a8bc754b1ae72501518a4222e840f5c55e3 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#include "HYDROData_CalculationCase.h"
+#ifdef WIN32
+  #pragma warning ( disable: 4251 )
+#endif
 
+#include "HYDROData_CalculationCase.h"
 #include "HYDROData_ArtificialObject.h"
 #include "HYDROData_IAltitudeObject.h"
 #include "HYDROData_Document.h"
 #include <BRepBuilderAPI_MakeVertex.hxx>
 #endif
 
+#ifdef WIN32
+  #pragma warning ( default: 4251 )
+#endif
+
 #define EXPORT_NAME "HYDRO_" + GetName()
 
 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
index dff7ce3eaadc044141048e6117066b4d3b0d6a6b..43eda5fffb3deba980892dca8e7510ca41d04cb5 100644 (file)
 #include <HYDROData_Document.h>
 #include <BRepBuilderAPI_MakeEdge2d.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
+#include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Wire.hxx>
+#include <TopExp_Explorer.hxx>
+#include <QString>
 
 template<class T> void append( std::vector<T>& theList, const std::vector<T>& theList2 )
 {
@@ -36,138 +39,167 @@ template<class T> void append( std::vector<T>& theList, const std::vector<T>& th
     theList[i] = theList2[j];
 }
 
-
 bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
-                                        const TCollection_AsciiString& theNamePrefix,
                                         const Handle( HYDROData_PolylineXY )& thePolyline,
-                                        const gp_Pnt2d& thePoint ) const
+                                        const gp_Pnt2d& thePoint,
+                                        double theTolerance ) const
 {
   std::vector<gp_Pnt2d> aPointsList( 1 );
   aPointsList[0] = thePoint;
-  std::vector<Handle( Geom2d_Curve )> aCurves = GetCurves( thePolyline );
+  std::vector<TopoDS_Wire> aCurves = GetWires( thePolyline );
   bool isOK = true;
   for( int i=0, n=aCurves.size(); i<n; i++ )
   {
-    std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( aCurves[i], aPointsList );
-    bool isLocalOK = CreatePolylines( theDoc, theNamePrefix, aCurvesList );
+    std::vector<TopoDS_Shape> aCurvesList = Split( aCurves[i], thePoint, theTolerance );
+    bool isLocalOK = CreatePolylines( theDoc, thePolyline->GetName(), aCurvesList );
     isOK = isOK && isLocalOK;
   }
   return isOK;
 }
 
 bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
-                                        const TCollection_AsciiString& theNamePrefix,
-                                        const Handle( HYDROData_PolylineXY )& thePolyline,
-                                        const Handle( HYDROData_PolylineXY )& theTool ) const
+              const Handle( HYDROData_PolylineXY )& thePolyline,
+              const Handle( HYDROData_PolylineXY )& theTool,
+              double theTolerance ) const
 {
-  std::vector<Handle( Geom2d_Curve )> aCurves = GetCurves( thePolyline );
-  std::vector<Handle( Geom2d_Curve )> aToolCurves = GetCurves( theTool );
-  bool isOK = true;
-  for( int i=0, n=aCurves.size(); i<n; i++ )
-    for( int j=0, m=aToolCurves.size(); j<m; j++ )
-    {
-      std::vector<gp_Pnt2d> aPointsList = Intersection( aCurves[i], aToolCurves[j] );
-      std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( aCurves[i], aPointsList );
-      bool isLocalOK = CreatePolylines( theDoc, theNamePrefix, aCurvesList );
-      isOK = isOK && isLocalOK;
-    }
-  return isOK;
+  HYDROData_SequenceOfObjects aSeq;
+  aSeq.Append( theTool );
+  return split( theDoc, thePolyline, aSeq, theTolerance, -1 );
 }
 
 bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
-                                        const TCollection_AsciiString& theNamePrefix,
-                                        const HYDROData_SequenceOfObjects& thePolylines )
+                                        const HYDROData_SequenceOfObjects& thePolylines,
+                                        double theTolerance )
 {
   int f = thePolylines.Lower(), l = thePolylines.Upper();
-  bool isOK = true;
-  std::vector<Handle( Geom2d_Curve )> anAllCurves;
   for( int i=f; i<=l; i++ )
   {
-    Handle( HYDROData_PolylineXY ) aPolyline = Handle( HYDROData_PolylineXY )::DownCast( thePolylines.Value( i ) );
-    std::vector<Handle( Geom2d_Curve )> aCurves = GetCurves( aPolyline );
-    append( anAllCurves, aCurves );
+    Handle( HYDROData_PolylineXY ) aPolylineI = Handle( HYDROData_PolylineXY )::DownCast( thePolylines.Value( i ) );
+    if( !split( theDoc, aPolylineI, thePolylines, theTolerance, i ) )
+      return false;
   }
+  return true;
+}
+
+bool HYDROData_PolylineOperator::Merge( const Handle( HYDROData_Document )& theDoc,
+                                        const QString& theName,
+                                        const HYDROData_SequenceOfObjects& thePolylines,
+                                        bool isConnectByNewSegment,
+                                        double theTolerance )
+{
+  TopoDS_Shape aMergedPolyline;
+
+  //TODO
+
+  std::vector<TopoDS_Shape> aShapes( 1 );
+  aShapes[0] = aMergedPolyline;
+  CreatePolylines( theDoc, theName, aShapes );
 
-  for( int i=0, n=anAllCurves.size(); i<n; i++ )
+  return true;
+}
+
+bool HYDROData_PolylineOperator::split( const Handle( HYDROData_Document )& theDoc,
+                                        const Handle( HYDROData_PolylineXY )& thePolyline,
+                                        const HYDROData_SequenceOfObjects& theTools,
+                                        double theTolerance,
+                                        int theIgnoreIndex ) const
+{
+  std::vector<TopoDS_Wire> aCurves = GetWires( thePolyline );
+  std::vector<TopoDS_Wire> aToolCurves;
+  for( int i=theTools.Lower(), n=theTools.Upper(); i<=n; i++ )
+    if( i!=theIgnoreIndex )
+    {
+      Handle( HYDROData_PolylineXY ) aToolPolyline = 
+        Handle( HYDROData_PolylineXY )::DownCast( theTools.Value( i ) );
+      append( aToolCurves, GetWires( aToolPolyline ) );
+    }
+
+  bool isOK = true;
+
+  int n = aCurves.size();
+  std::vector<TopoDS_Shape> aResults( n );
+  for( int i=0; i<n; i++ )
+    aResults[i] = aCurves[i];
+
+  for( int j=0, m=aToolCurves.size(); j<m; j++ )
   {
-    std::vector<gp_Pnt2d> aCompletePointsList;
-    for( int j=0; j<n; j++ )
+    std::vector<TopoDS_Shape> aNewResults;
+    for( int k=0, q=aResults.size(); k<q; k++ )
     {
-      if( i==j )
-        continue;
-      std::vector<gp_Pnt2d> aPointsList = Intersection( anAllCurves[i], anAllCurves[j] );
-      append( aCompletePointsList, aPointsList );
+      std::vector<TopoDS_Shape> aCurvesList = Split( TopoDS::Wire( aResults[k] ), aToolCurves[j], theTolerance );
+      append( aNewResults, aCurvesList );
     }
-    std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( anAllCurves[i], aCompletePointsList );
-    bool isLocalOK = CreatePolylines( theDoc, theNamePrefix, aCurvesList );
-    isOK = isOK && isLocalOK;
+    aResults = aNewResults;
   }
+
+  CreatePolylines( theDoc, thePolyline->GetName(), aResults );
+
   return isOK;
 }
 
-bool HYDROData_PolylineOperator::Merge( const Handle( HYDROData_Document )& theDoc,
-                                        const TCollection_AsciiString& theName,
-                                        const HYDROData_SequenceOfObjects& thePolylines,
-                                        bool isConnectByNewSegment )
+std::vector<TopoDS_Wire> HYDROData_PolylineOperator::GetWires( const Handle( HYDROData_PolylineXY )& thePolyline )
 {
-  //TODO
+  std::vector<TopoDS_Wire> aResult;
 
-  TopoDS_Shape aMergedPolyline;
+  TopoDS_Shape aShape = thePolyline->GetShape();
 
-  Handle( HYDROData_PolylineXY ) aPolyline = 
-    Handle( HYDROData_PolylineXY )::DownCast( theDoc->CreateObject( KIND_POLYLINEXY ) );
-  if( aPolyline.IsNull() )
-    return false;
-
-  aPolyline->SetShape( aMergedPolyline );
-  //TODO: set name
-
-  return true;
+  if( aShape.ShapeType()==TopAbs_WIRE )
+  {
+    aResult.push_back( TopoDS::Wire( aShape ) );
+  }
+  else
+  {
+    TopExp_Explorer anExp( aShape, TopAbs_WIRE );
+    for( ; anExp.More(); anExp.Next() )
+    {
+      aResult.push_back( TopoDS::Wire( anExp.Current() ) );
+    }
+  }
+  return aResult;
 }
 
-std::vector<Handle( Geom2d_Curve )> HYDROData_PolylineOperator::GetCurves( const Handle( HYDROData_PolylineXY )& thePolyline )
+std::vector<TopoDS_Shape> HYDROData_PolylineOperator::Split( const TopoDS_Wire& theWire,
+                                                             const gp_Pnt2d& thePoint,
+                                                             double theTolerance )
 {
-  std::vector<Handle( Geom2d_Curve )> aResult;
+  std::vector<TopoDS_Shape> aResult;
   //TODO
   return aResult;
 }
 
-std::vector<gp_Pnt2d> HYDROData_PolylineOperator::Intersection( const Handle( Geom2d_Curve )& theCurve,
-                                                                const Handle( Geom2d_Curve )& theTool )
+std::vector<TopoDS_Shape> HYDROData_PolylineOperator::Split( const TopoDS_Wire& theWire,
+                                                             const TopoDS_Wire& theTool,
+                                                             double theTolerance )
 {
-  std::vector<gp_Pnt2d> aResult;
+  std::vector<TopoDS_Shape> aResult;
   //TODO
   return aResult;
 }
 
-std::vector<Handle( Geom2d_Curve )> HYDROData_PolylineOperator::Split( const Handle( Geom2d_Curve )& theCurve,
-                                                                       const std::vector<gp_Pnt2d>& thePoints )
+std::vector<TopoDS_Shape> HYDROData_PolylineOperator::Split( const std::vector<TopoDS_Wire>& theWires,
+                                                             double theTolerance )
 {
-  std::vector<Handle( Geom2d_Curve )> aResult;
+  std::vector<TopoDS_Shape> aResult;
   //TODO
   return aResult;
 }
 
 bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Document )& theDoc,
-                                                  const TCollection_AsciiString& theNamePrefix,
-                                                  const std::vector<Handle( Geom2d_Curve )>& theCurves )
+                                                  const QString& theNamePrefix,
+                                                  const std::vector<TopoDS_Shape>& theShapes )
 {
   if( theDoc.IsNull() )
     return false;
 
-  int n = theCurves.size();
+  int n = theShapes.size();
   for( int i=0; i<n; i++ )
   {
-    TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge2d( theCurves[i] ).Edge();
-    BRepBuilderAPI_MakeWire aMakeWire;
-    aMakeWire.Add( anEdge );
-
     Handle( HYDROData_PolylineXY ) aPolyline = 
       Handle( HYDROData_PolylineXY )::DownCast( theDoc->CreateObject( KIND_POLYLINEXY ) );
     if( aPolyline.IsNull() )
       return false;
 
-    aPolyline->SetShape( aMakeWire.Wire() );
+    aPolyline->SetShape( theShapes[i] );
     //TODO: set name
   }
   return true;
index a76a6af9eed6de3f57900d52a904e514cf41395c..0613c23923a5e47b623fab7914c4a6e752d0fed2 100644 (file)
@@ -30,33 +30,43 @@ class HYDRODATA_EXPORT HYDROData_PolylineOperator
 {
 public:
   bool Split( const Handle( HYDROData_Document )& theDoc,
-              const TCollection_AsciiString& theNamePrefix,
               const Handle( HYDROData_PolylineXY )& thePolyline,
-              const gp_Pnt2d& thePoint ) const;
+              const gp_Pnt2d& thePoint,
+              double theTolerance ) const;
   bool Split( const Handle( HYDROData_Document )& theDoc,
-              const TCollection_AsciiString& theNamePrefix,
               const Handle( HYDROData_PolylineXY )& thePolyline,
-              const Handle( HYDROData_PolylineXY )& theTool ) const;
+              const Handle( HYDROData_PolylineXY )& theTool,
+              double theTolerance ) const;
   bool Split( const Handle( HYDROData_Document )& theDoc,
-              const TCollection_AsciiString& theNamePrefix,
-              const HYDROData_SequenceOfObjects& thePolylines );
+              const HYDROData_SequenceOfObjects& thePolylines,
+              double theTolerance );
   bool Merge( const Handle( HYDROData_Document )& theDoc,
-              const TCollection_AsciiString& theName,
+              const QString& theName,
               const HYDROData_SequenceOfObjects& thePolylines,
-              bool isConnectByNewSegment );
+              bool isConnectByNewSegment,
+              double theTolerance );
 
 protected:
-  static std::vector<Handle( Geom2d_Curve )> GetCurves( const Handle( HYDROData_PolylineXY )& thePolyline );
+  bool split( const Handle( HYDROData_Document )& theDoc,
+              const Handle( HYDROData_PolylineXY )& thePolyline,
+              const HYDROData_SequenceOfObjects& theTools,
+              double theTolerance,
+              int theIgnoreIndex ) const;
 
-  static std::vector<gp_Pnt2d> Intersection( const Handle( Geom2d_Curve )& theCurve,
-                                             const Handle( Geom2d_Curve )& theTool );
+  static std::vector<TopoDS_Wire> GetWires( const Handle( HYDROData_PolylineXY )& thePolyline );
 
-  static std::vector<Handle( Geom2d_Curve )> Split( const Handle( Geom2d_Curve )& theCurve,
-                                                    const std::vector<gp_Pnt2d>& thePoints );
+  static std::vector<TopoDS_Shape> Split( const TopoDS_Wire& theWire,
+                                          const gp_Pnt2d& thePoint,
+                                          double theTolerance );
+  static std::vector<TopoDS_Shape> Split( const TopoDS_Wire& theWire,
+                                          const TopoDS_Wire& theTool,
+                                          double theTolerance );
+  static std::vector<TopoDS_Shape> Split( const std::vector<TopoDS_Wire>& theWires,
+                                          double theTolerance );
 
   static bool CreatePolylines( const Handle( HYDROData_Document )& theDoc,
-                               const TCollection_AsciiString& theNamePrefix,
-                               const std::vector<Handle( Geom2d_Curve )>& theCurves );
+                               const QString& theNamePrefix,
+                               const std::vector<TopoDS_Shape>& theShape );
 };
 
 #endif
index 608e5b9510bfa9f2fc2bac174e1e58249b5419f7..ab34af79f43deed24ab133afe4d9a5b132fd7bec 100755 (executable)
@@ -495,7 +495,7 @@ void HYDROData_PolylineXY::Update()
   NCollection_Sequence<bool>                              aSectClosures;
   GetSections( aSectNames, aSectTypes, aSectClosures );
 
-  BRepBuilderAPI_MakeWire aMakeWire;
+  //BRepBuilderAPI_MakeWire aMakeWire;
 
   TopTools_ListOfShape aSectionWiresList;
 
@@ -521,7 +521,7 @@ void HYDROData_PolylineXY::Update()
     TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
     if ( !aSectionWire.IsNull() ) {
       aSectionWiresList.Append( aSectionWire );
-      aMakeWire.Add( aSectionWire );
+      //aMakeWire.Add( aSectionWire );
     }
   }
 // all input wires in the <aSectionWiresList>
index 160fba0d64279d857b71550f9c4ddd1f9da81997..eaa58208496cd17581c277b36cf2792c8fcd9427 100644 (file)
 #ifndef HYDROData_SplitToZonesTool_H
 #define HYDROData_SplitToZonesTool_H
 
+#ifdef WIN32
+  #pragma warning ( disable: 4251 )
+#endif
+
 #include <HYDROData_Object.h>
 #include <HYDROData_Transform.h>
 #include <TopoDS_Shape.hxx>
@@ -97,4 +101,9 @@ private:
   static Standard_Integer SplitFaces(const TopoDS_Compound& theComp, HYDROData_Transform& theTool);
 };
 
+#ifdef WIN32
+  #pragma warning ( default: 4251 )
+#endif
+
+
 #endif
index c5067c84643cff49d6b1474bf8273980365dcf80..b97ca96cea23a3c695990ff80992e5b6dd3f03e6 100644 (file)
@@ -61,7 +61,8 @@ bool HYDROGUI_MergePolylinesOp::processApply( int& theUpdateFlags,
   bool isConnectByNewSegment = aPanel->IsConnectByNewSegment();
   HYDROData_SequenceOfObjects aPolylinesList = aPanel->selectedPolylines();
   HYDROData_PolylineOperator anOp;
-  anOp.Merge( doc(), aName.toLatin1().data(), aPolylinesList, isConnectByNewSegment );
+  double aTolerance = 1E-7; //TODO
+  anOp.Merge( doc(), aName.toLatin1().data(), aPolylinesList, isConnectByNewSegment, aTolerance );
 
   theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
   return true;
index d6556fbafd290457137764ebfd5f4d8ef492d42c..bab464a82a4bd0a52192f7620a5fbbcf6daa91e4 100644 (file)
@@ -79,23 +79,24 @@ bool HYDROGUI_SplitPolylinesOp::processApply( int& theUpdateFlags,
   if ( !aPanel )
     return false;
 
-  QString aName = aPanel->GetResultName();
+  //TODO: QString aName = aPanel->GetResultName();
   Handle( HYDROData_PolylineXY ) aMainPolyline = aPanel->GetMainPolyline();
   Handle( HYDROData_PolylineXY ) aToolPolyline = aPanel->GetToolPolyline();
   HYDROData_SequenceOfObjects aPolylinesList = aPanel->GetPolylines();
   gp_Pnt2d aPoint = aPanel->GetPoint();
+  double aTolerance = 1E-7; //TODO
 
   HYDROData_PolylineOperator anOp;
   switch( aPanel->GetMode() )
   {
   case HYDROGUI_SplitPolylinesDlg::ByPoint:
-    anOp.Split( doc(), aName.toLatin1().data(), aMainPolyline, aPoint );
+    anOp.Split( doc(), aMainPolyline, aPoint, aTolerance );
     break;
   case HYDROGUI_SplitPolylinesDlg::ByTool:
-    anOp.Split( doc(), aName.toLatin1().data(), aMainPolyline, aToolPolyline );
+    anOp.Split( doc(), aMainPolyline, aToolPolyline, aTolerance );
     break;
   case HYDROGUI_SplitPolylinesDlg::Split:
-    anOp.Split( doc(), aName.toLatin1().data(), aPolylinesList );
+    anOp.Split( doc(), aPolylinesList, aTolerance );
     break;
   }