]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #585: polylines operations (split/merge)
authorasl <asl@opencascade.com>
Thu, 25 Jun 2015 12:36:07 +0000 (15:36 +0300)
committerasl <asl@opencascade.com>
Thu, 25 Jun 2015 12:36:07 +0000 (15:36 +0300)
src/HYDROData/HYDROData_PolylineOperator.cxx
src/HYDROData/HYDROData_PolylineOperator.h
src/HYDROData/HYDROData_PolylineXY.cxx
src/HYDROData/HYDROData_PolylineXY.h
src/HYDROGUI/HYDROGUI_MergePolylinesDlg.cxx
src/HYDROGUI/HYDROGUI_MergePolylinesDlg.h
src/HYDROGUI/HYDROGUI_MergePolylinesOp.cxx
src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.cxx
src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.h
src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index 61c835f6123d389986b42d23e185f3cc4ea43910..e8a7eec82937ebdb4ef51b491f27025a618bfbc6 100644 (file)
 //
 
 #include <HYDROData_PolylineOperator.h>
+#include <HYDROData_Document.h>
 #include <BRepBuilderAPI_MakeEdge2d.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
 #include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
 
 template<class T> void append( std::vector<T>& theList, const std::vector<T>& theList2 )
 {
@@ -34,7 +37,9 @@ template<class T> void append( std::vector<T>& theList, const std::vector<T>& th
 }
 
 
-bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& thePolyline,
+bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
+                                        const TCollection_AsciiString& theNamePrefix,
+                                        const Handle( HYDROData_PolylineXY )& thePolyline,
                                         const gp_Pnt2d& thePoint ) const
 {
   std::vector<gp_Pnt2d> aPointsList( 1 );
@@ -44,13 +49,15 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& th
   for( int i=0, n=aCurves.size(); i<n; i++ )
   {
     std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( aCurves[i], aPointsList );
-    bool isLocalOK = CreatePolylines( aCurvesList );
+    bool isLocalOK = CreatePolylines( theDoc, theNamePrefix, aCurvesList );
     isOK = isOK && isLocalOK;
   }
   return isOK;
 }
 
-bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& thePolyline,
+bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
+                                        const TCollection_AsciiString& theNamePrefix,
+                                        const Handle( HYDROData_PolylineXY )& thePolyline,
                                         const Handle( HYDROData_PolylineXY )& theTool ) const
 {
   std::vector<Handle( Geom2d_Curve )> aCurves = GetCurves( thePolyline );
@@ -61,13 +68,15 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& th
     {
       std::vector<gp_Pnt2d> aPointsList = Intersection( aCurves[i], aToolCurves[j] );
       std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( aCurves[i], aPointsList );
-      bool isLocalOK = CreatePolylines( aCurvesList );
+      bool isLocalOK = CreatePolylines( theDoc, theNamePrefix, aCurvesList );
       isOK = isOK && isLocalOK;
     }
   return isOK;
 }
 
-bool HYDROData_PolylineOperator::Split( const HYDROData_SequenceOfObjects& thePolylines )
+bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
+                                        const TCollection_AsciiString& theNamePrefix,
+                                        const HYDROData_SequenceOfObjects& thePolylines )
 {
   int f = thePolylines.Lower(), l = thePolylines.Upper();
   bool isOK = true;
@@ -90,13 +99,15 @@ bool HYDROData_PolylineOperator::Split( const HYDROData_SequenceOfObjects& thePo
       append( aCompletePointsList, aPointsList );
     }
     std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( anAllCurves[i], aCompletePointsList );
-    bool isLocalOK = CreatePolylines( aCurvesList );
+    bool isLocalOK = CreatePolylines( theDoc, theNamePrefix, aCurvesList );
     isOK = isOK && isLocalOK;
   }
   return isOK;
 }
 
-bool HYDROData_PolylineOperator::Merge( const HYDROData_SequenceOfObjects& thePolylines )
+bool HYDROData_PolylineOperator::Merge( const Handle( HYDROData_Document )& theDoc,
+                                        const TCollection_AsciiString& theName,
+                                        const HYDROData_SequenceOfObjects& thePolylines )
 {
   //TODO
   return true;
@@ -125,13 +136,27 @@ std::vector<Handle( Geom2d_Curve )> HYDROData_PolylineOperator::Split( const Han
   return aResult;
 }
 
-bool HYDROData_PolylineOperator::CreatePolylines( const std::vector<Handle( Geom2d_Curve )>& theCurves )
+bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Document )& theDoc,
+                                                  const TCollection_AsciiString& theNamePrefix,
+                                                  const std::vector<Handle( Geom2d_Curve )>& theCurves )
 {
+  if( theDoc.IsNull() )
+    return false;
+
   int n = theCurves.size();
   for( int i=0; i<n; i++ )
   {
     TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge2d( theCurves[i] ).Edge();
-    //TODO
+    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() );
+    //TODO: set name
   }
   return true;
 }
index d3e49e3526e0a1d4e7d7bcb5c94ce79ac844e90a..e11c41ba8772c9561805ac8d9598460837b540a3 100644 (file)
 #include <gp_Pnt2d.hxx>
 #include <vector>
 
-class HYDROData_PolylineOperator
+class Handle( HYDROData_Document );
+
+class HYDRODATA_EXPORT HYDROData_PolylineOperator
 {
 public:
-  HYDRODATA_EXPORT bool Split( const Handle( HYDROData_PolylineXY )& thePolyline,
-                               const gp_Pnt2d& thePoint ) const;
-  HYDRODATA_EXPORT bool Split( const Handle( HYDROData_PolylineXY )& thePolyline,
-                               const Handle( HYDROData_PolylineXY )& theTool ) const;
-  HYDRODATA_EXPORT bool Split( const HYDROData_SequenceOfObjects& thePolylines );
-  HYDRODATA_EXPORT bool Merge( const HYDROData_SequenceOfObjects& thePolylines );
-
-  static HYDRODATA_EXPORT std::vector<Handle( Geom2d_Curve )> GetCurves( const Handle( HYDROData_PolylineXY )& thePolyline );
-
-  static HYDRODATA_EXPORT std::vector<gp_Pnt2d> Intersection( const Handle( Geom2d_Curve )& theCurve,
-                                                              const Handle( Geom2d_Curve )& theTool );
-
-  static HYDRODATA_EXPORT std::vector<Handle( Geom2d_Curve )> Split( const Handle( Geom2d_Curve )& theCurve,
-                                                                     const std::vector<gp_Pnt2d>& thePoints );
-
-  static HYDRODATA_EXPORT bool CreatePolylines( const std::vector<Handle( Geom2d_Curve )>& theCurves );
+  bool Split( const Handle( HYDROData_Document )& theDoc,
+              const TCollection_AsciiString& theNamePrefix,
+              const Handle( HYDROData_PolylineXY )& thePolyline,
+              const gp_Pnt2d& thePoint ) const;
+  bool Split( const Handle( HYDROData_Document )& theDoc,
+              const TCollection_AsciiString& theNamePrefix,
+              const Handle( HYDROData_PolylineXY )& thePolyline,
+              const Handle( HYDROData_PolylineXY )& theTool ) const;
+  bool Split( const Handle( HYDROData_Document )& theDoc,
+              const TCollection_AsciiString& theNamePrefix,
+              const HYDROData_SequenceOfObjects& thePolylines );
+  bool Merge( const Handle( HYDROData_Document )& theDoc,
+              const TCollection_AsciiString& theName,
+              const HYDROData_SequenceOfObjects& thePolylines );
+
+protected:
+  static std::vector<Handle( Geom2d_Curve )> GetCurves( const Handle( HYDROData_PolylineXY )& thePolyline );
+
+  static std::vector<gp_Pnt2d> Intersection( const Handle( Geom2d_Curve )& theCurve,
+                                             const Handle( Geom2d_Curve )& theTool );
+
+  static std::vector<Handle( Geom2d_Curve )> Split( const Handle( Geom2d_Curve )& theCurve,
+                                                    const std::vector<gp_Pnt2d>& thePoints );
+
+  static bool CreatePolylines( const Handle( HYDROData_Document )& theDoc,
+                               const TCollection_AsciiString& theNamePrefix,
+                               const std::vector<Handle( Geom2d_Curve )>& theCurves );
 };
 
 #endif
index 1c824402a3276a9d19d48de047d4790d619d2061..608e5b9510bfa9f2fc2bac174e1e58249b5419f7 100755 (executable)
@@ -247,6 +247,12 @@ TopoDS_Shape HYDROData_PolylineXY::GetShape() const
   return getPolylineShape();
 }
 
+bool HYDROData_PolylineXY::SetShape( const TopoDS_Shape& theShape )
+{
+  setPolylineShape( theShape );
+  return true;
+}
+
 bool convertEdgeToSection( const TopoDS_Edge&                                       theEdge,
                            NCollection_Sequence<TCollection_AsciiString>&           theSectNames,
                            NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
index a0172fd743de4aed5bb98d2d698d1c3b83fbab62..3036097263f0ea5ff25c87eed0c64c0346253816 100644 (file)
@@ -126,13 +126,13 @@ public:
    * Returns the 2D presentation of all points.
    */
   HYDRODATA_EXPORT virtual TopoDS_Shape GetShape() const;
+  HYDRODATA_EXPORT bool SetShape( const TopoDS_Shape& theShape );
 
   /**
    * Returns the 3D presentation of all points.
    */
   HYDRODATA_EXPORT virtual bool ImportShape( const TopoDS_Shape& theShape );
 
-
   /**
    * Returns flag indicating that polyline can be edited or not.
    */
index 39bbcc1a0bd8595cd2764cbdf19d42936b3af7aa..5035aae9a265dc29f4da0942df82516beba49ef0 100644 (file)
@@ -19,7 +19,9 @@
 #include <HYDROGUI_MergePolylinesDlg.h>
 #include <HYDROGUI_ObjListBox.h>
 #include <QFrame>
+#include <QLabel>
 #include <QGridLayout>
+#include <QLineEdit>
 
 HYDROGUI_MergePolylinesDlg::HYDROGUI_MergePolylinesDlg( HYDROGUI_Module* theModule, const QString& theTitle )
 : HYDROGUI_InputPanel( theModule, theTitle )
@@ -31,8 +33,12 @@ HYDROGUI_MergePolylinesDlg::HYDROGUI_MergePolylinesDlg( HYDROGUI_Module* theModu
   aLayout->setMargin( 5 );
   aLayout->setSpacing( 5 );
 
+  myName = new QLineEdit( mainFrame() );
+  aLayout->addWidget( new QLabel( tr( "RESULT_NAME" ) ), 0, 0 );
+  aLayout->addWidget( myName, 0, 1 );
+
   myList = new HYDROGUI_ObjListBox( theModule, tr( "POLYLINES" ), KIND_POLYLINEXY, mainFrame() );
-  aLayout->addWidget( myList, 0, 0 );
+  aLayout->addWidget( myList, 1, 0, 1, 2 );
 }
 
 HYDROGUI_MergePolylinesDlg::~HYDROGUI_MergePolylinesDlg()
@@ -53,3 +59,8 @@ void HYDROGUI_MergePolylinesDlg::setPolylinesFromSelection()
 {
   return myList->setObjectsFromSelection();
 }
+
+QString HYDROGUI_MergePolylinesDlg::GetResultName() const
+{
+  return myName->text();
+}
index 874f0225330e2dfd9b4e401d1d212ac74a790004..9213deff5f26b7771105c14b6f74493d375d4859 100644 (file)
@@ -22,6 +22,7 @@
 #include <HYDROGUI_InputPanel.h>
 #include <HYDROData_Entity.h>
 
+class QLineEdit;
 class HYDROGUI_ObjListBox;
 
 class HYDROGUI_MergePolylinesDlg : public HYDROGUI_InputPanel
@@ -32,11 +33,13 @@ public:
   HYDROGUI_MergePolylinesDlg( HYDROGUI_Module* theModule, const QString& theTitle );
   virtual ~HYDROGUI_MergePolylinesDlg();
 
+  QString                     GetResultName() const;
   HYDROData_SequenceOfObjects selectedPolylines() const;
   void                        setSelectedPolylines( const HYDROData_SequenceOfObjects& );
   void                        setPolylinesFromSelection();
 
 private:
+  QLineEdit*           myName;
   HYDROGUI_ObjListBox* myList;
 };
 
index 8c6f21befca054c715b2a04505817333304f2555..9e0eaf0ccea3f59905530671f787a34d8c86f473 100644 (file)
@@ -19,6 +19,7 @@
 #include <HYDROGUI_MergePolylinesOp.h>
 #include <HYDROGUI_MergePolylinesDlg.h>
 #include <HYDROGUI_UpdateFlags.h>
+#include <HYDROData_Document.h>
 #include <HYDROData_PolylineOperator.h>
 
 HYDROGUI_MergePolylinesOp::HYDROGUI_MergePolylinesOp( HYDROGUI_Module* theModule )
@@ -56,9 +57,10 @@ bool HYDROGUI_MergePolylinesOp::processApply( int& theUpdateFlags,
   if ( !aPanel )
     return false;
 
+  QString aName = aPanel->GetResultName();
   HYDROData_SequenceOfObjects aPolylinesList = aPanel->selectedPolylines();
   HYDROData_PolylineOperator anOp;
-  anOp.Merge( aPolylinesList );
+  anOp.Merge( doc(), aName.toLatin1().data(), aPolylinesList );
 
   theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
   return true;
index ddc5d0b3ffed5fee408f4c1069376a4035a1fa16..aa70371aac72b4a49798d1c8e364e2146979724c 100644 (file)
@@ -31,6 +31,7 @@
 #include <QGridLayout>
 #include <QTabWidget>
 #include <QMouseEvent>
+#include <QLineEdit>
 #include <gp_Pnt2d.hxx>
 
 const double MIN_COORD = -1000000;
@@ -47,8 +48,12 @@ HYDROGUI_SplitPolylinesDlg::HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModu
   aLayout->setMargin( 5 );
   aLayout->setSpacing( 5 );
 
+  myName = new QLineEdit( mainFrame() );
+  aLayout->addWidget( new QLabel( tr( "RESULT_NAME" ) ), 0, 0 );
+  aLayout->addWidget( myName, 0, 1 );
+
   myTab = new QTabWidget( aFrame );
-  aLayout->addWidget( myTab, 0, 0 );
+  aLayout->addWidget( myTab, 1, 0, 1, 2 );
 
   QFrame* aPointPage = new QFrame();
   myMainPolyline1 = new HYDROGUI_ObjComboBox( theModule, tr( "POLYLINE" ), KIND_POLYLINEXY, aPointPage );
@@ -184,3 +189,8 @@ OCCViewer_ViewPort3d* HYDROGUI_SplitPolylinesDlg::getViewPort() const
     
   return aViewPort;
 }
+
+QString HYDROGUI_SplitPolylinesDlg::GetResultName() const
+{
+  return myName->text();
+}
index c550472a7d3a99482a2572930d56745bf45fb681..dedda92985f4eb284e996dbc8f719f07b2a4a4cf 100644 (file)
@@ -30,6 +30,7 @@ class gp_Pnt2d;
 class OCCViewer_Viewer;
 class SUIT_ViewWindow;
 class OCCViewer_ViewPort3d;
+class QLineEdit;
 
 class HYDROGUI_SplitPolylinesDlg : public HYDROGUI_InputPanel
 {
@@ -42,11 +43,12 @@ public:
   HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModule, const QString& theTitle );
   virtual ~HYDROGUI_SplitPolylinesDlg();
 
-  Mode GetMode() const; 
+  QString                        GetResultName() const;
+  Mode                           GetMode() const; 
   Handle( HYDROData_PolylineXY ) GetMainPolyline() const;
   Handle( HYDROData_PolylineXY ) GetToolPolyline() const;
-  gp_Pnt2d GetPoint() const;
-  HYDROData_SequenceOfObjects GetPolylines() const;
+  gp_Pnt2d                       GetPoint() const;
+  HYDROData_SequenceOfObjects    GetPolylines() const;
 
   void setPolylinesFromSelection();
   void setOCCViewer( OCCViewer_Viewer* theViewer );
@@ -63,9 +65,10 @@ private:
   OCCViewer_ViewPort3d* getViewPort() const;
 
 private:
-  QTabWidget* myTab;
-  QtxDoubleSpinBox* myX;
-  QtxDoubleSpinBox* myY;
+  QLineEdit*            myName;
+  QTabWidget*           myTab;
+  QtxDoubleSpinBox*     myX;
+  QtxDoubleSpinBox*     myY;
   HYDROGUI_ObjComboBox* myMainPolyline1;
   HYDROGUI_ObjComboBox* myMainPolyline2;
   HYDROGUI_ObjComboBox* myToolPolyline;
index 73f415a8957783ee7e0e6d81bb8eef3f32855fb4..d6556fbafd290457137764ebfd5f4d8ef492d42c 100644 (file)
@@ -22,6 +22,7 @@
 #include <HYDROGUI_UpdateFlags.h>
 #include <HYDROGUI_Shape.h>
 #include <HYDROData_PolylineOperator.h>
+#include <HYDROData_Document.h>
 #include <LightApp_Application.h>
 #include <OCCViewer_ViewModel.h>
 #include <OCCViewer_ViewManager.h>
@@ -78,6 +79,7 @@ bool HYDROGUI_SplitPolylinesOp::processApply( int& theUpdateFlags,
   if ( !aPanel )
     return false;
 
+  QString aName = aPanel->GetResultName();
   Handle( HYDROData_PolylineXY ) aMainPolyline = aPanel->GetMainPolyline();
   Handle( HYDROData_PolylineXY ) aToolPolyline = aPanel->GetToolPolyline();
   HYDROData_SequenceOfObjects aPolylinesList = aPanel->GetPolylines();
@@ -87,13 +89,13 @@ bool HYDROGUI_SplitPolylinesOp::processApply( int& theUpdateFlags,
   switch( aPanel->GetMode() )
   {
   case HYDROGUI_SplitPolylinesDlg::ByPoint:
-    anOp.Split( aMainPolyline, aPoint );
+    anOp.Split( doc(), aName.toLatin1().data(), aMainPolyline, aPoint );
     break;
   case HYDROGUI_SplitPolylinesDlg::ByTool:
-    anOp.Split( aMainPolyline, aToolPolyline );
+    anOp.Split( doc(), aName.toLatin1().data(), aMainPolyline, aToolPolyline );
     break;
   case HYDROGUI_SplitPolylinesDlg::Split:
-    anOp.Split( aPolylinesList );
+    anOp.Split( doc(), aName.toLatin1().data(), aPolylinesList );
     break;
   }
   
index 381bc4c857fd855deecf5506252ccd513903d501..67b675e63d600d83a3e6624bd66b684c1bd76dff 100644 (file)
@@ -3013,6 +3013,10 @@ Polyline should consist from one not closed curve.</translation>
       <source>COMPLETE_SPLIT</source>
       <translation>Complete split</translation>
     </message>
+    <message>
+      <source>RESULT_NAME</source>
+      <translation>Result name prefix:</translation>
+    </message>
   </context>
 
   <context>
@@ -3025,6 +3029,10 @@ Polyline should consist from one not closed curve.</translation>
       <source>MERGE_POLYLINES</source>
       <translation>Merge polylines</translation>
     </message>
+    <message>
+      <source>RESULT_NAME</source>
+      <translation>Result name:</translation>
+    </message>
   </context>
 
   <context>