From 8db2a634f4e26d4c58a13c3c09e319eab144e067 Mon Sep 17 00:00:00 2001 From: asl Date: Thu, 25 Jun 2015 15:36:07 +0300 Subject: [PATCH] refs #585: polylines operations (split/merge) --- src/HYDROData/HYDROData_PolylineOperator.cxx | 43 ++++++++++++++---- src/HYDROData/HYDROData_PolylineOperator.h | 47 +++++++++++++------- src/HYDROData/HYDROData_PolylineXY.cxx | 6 +++ src/HYDROData/HYDROData_PolylineXY.h | 2 +- src/HYDROGUI/HYDROGUI_MergePolylinesDlg.cxx | 13 +++++- src/HYDROGUI/HYDROGUI_MergePolylinesDlg.h | 3 ++ src/HYDROGUI/HYDROGUI_MergePolylinesOp.cxx | 4 +- src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.cxx | 12 ++++- src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.h | 15 ++++--- src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx | 8 ++-- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 8 ++++ 11 files changed, 122 insertions(+), 39 deletions(-) diff --git a/src/HYDROData/HYDROData_PolylineOperator.cxx b/src/HYDROData/HYDROData_PolylineOperator.cxx index 61c835f6..e8a7eec8 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.cxx +++ b/src/HYDROData/HYDROData_PolylineOperator.cxx @@ -17,8 +17,11 @@ // #include +#include #include +#include #include +#include template void append( std::vector& theList, const std::vector& theList2 ) { @@ -34,7 +37,9 @@ template void append( std::vector& theList, const std::vector& 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 aPointsList( 1 ); @@ -44,13 +49,15 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& th for( int i=0, n=aCurves.size(); i 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 aCurves = GetCurves( thePolyline ); @@ -61,13 +68,15 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& th { std::vector aPointsList = Intersection( aCurves[i], aToolCurves[j] ); std::vector 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 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 HYDROData_PolylineOperator::Split( const Han return aResult; } -bool HYDROData_PolylineOperator::CreatePolylines( const std::vector& theCurves ) +bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Document )& theDoc, + const TCollection_AsciiString& theNamePrefix, + const std::vector& theCurves ) { + if( theDoc.IsNull() ) + return false; + int n = theCurves.size(); for( int i=0; iCreateObject( KIND_POLYLINEXY ) ); + if( aPolyline.IsNull() ) + return false; + + aPolyline->SetShape( aMakeWire.Wire() ); + //TODO: set name } return true; } diff --git a/src/HYDROData/HYDROData_PolylineOperator.h b/src/HYDROData/HYDROData_PolylineOperator.h index d3e49e35..e11c41ba 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.h +++ b/src/HYDROData/HYDROData_PolylineOperator.h @@ -24,25 +24,38 @@ #include #include -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 GetCurves( const Handle( HYDROData_PolylineXY )& thePolyline ); - - static HYDRODATA_EXPORT std::vector Intersection( const Handle( Geom2d_Curve )& theCurve, - const Handle( Geom2d_Curve )& theTool ); - - static HYDRODATA_EXPORT std::vector Split( const Handle( Geom2d_Curve )& theCurve, - const std::vector& thePoints ); - - static HYDRODATA_EXPORT bool CreatePolylines( const std::vector& 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 GetCurves( const Handle( HYDROData_PolylineXY )& thePolyline ); + + static std::vector Intersection( const Handle( Geom2d_Curve )& theCurve, + const Handle( Geom2d_Curve )& theTool ); + + static std::vector Split( const Handle( Geom2d_Curve )& theCurve, + const std::vector& thePoints ); + + static bool CreatePolylines( const Handle( HYDROData_Document )& theDoc, + const TCollection_AsciiString& theNamePrefix, + const std::vector& theCurves ); }; #endif diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index 1c824402..608e5b95 100755 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -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& theSectNames, NCollection_Sequence& theSectTypes, diff --git a/src/HYDROData/HYDROData_PolylineXY.h b/src/HYDROData/HYDROData_PolylineXY.h index a0172fd7..30360972 100644 --- a/src/HYDROData/HYDROData_PolylineXY.h +++ b/src/HYDROData/HYDROData_PolylineXY.h @@ -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. */ diff --git a/src/HYDROGUI/HYDROGUI_MergePolylinesDlg.cxx b/src/HYDROGUI/HYDROGUI_MergePolylinesDlg.cxx index 39bbcc1a..5035aae9 100644 --- a/src/HYDROGUI/HYDROGUI_MergePolylinesDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_MergePolylinesDlg.cxx @@ -19,7 +19,9 @@ #include #include #include +#include #include +#include 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(); +} diff --git a/src/HYDROGUI/HYDROGUI_MergePolylinesDlg.h b/src/HYDROGUI/HYDROGUI_MergePolylinesDlg.h index 874f0225..9213deff 100644 --- a/src/HYDROGUI/HYDROGUI_MergePolylinesDlg.h +++ b/src/HYDROGUI/HYDROGUI_MergePolylinesDlg.h @@ -22,6 +22,7 @@ #include #include +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; }; diff --git a/src/HYDROGUI/HYDROGUI_MergePolylinesOp.cxx b/src/HYDROGUI/HYDROGUI_MergePolylinesOp.cxx index 8c6f21be..9e0eaf0c 100644 --- a/src/HYDROGUI/HYDROGUI_MergePolylinesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_MergePolylinesOp.cxx @@ -19,6 +19,7 @@ #include #include #include +#include #include 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; diff --git a/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.cxx b/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.cxx index ddc5d0b3..aa70371a 100644 --- a/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include 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(); +} diff --git a/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.h b/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.h index c550472a..dedda929 100644 --- a/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.h +++ b/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.h @@ -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; diff --git a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx index 73f415a8..d6556fba 100644 --- a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -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; } diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 381bc4c8..67b675e6 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -3013,6 +3013,10 @@ Polyline should consist from one not closed curve. COMPLETE_SPLIT Complete split + + RESULT_NAME + Result name prefix: + @@ -3025,6 +3029,10 @@ Polyline should consist from one not closed curve. MERGE_POLYLINES Merge polylines + + RESULT_NAME + Result name: + -- 2.39.2