From cd0d26a7d307914cd7f6f519b3f30317be6783f0 Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 26 Jun 2015 15:23:51 +0300 Subject: [PATCH] refs #585: split/merge implementation --- src/HYDROData/HYDROData_CalculationCase.cxx | 9 +- src/HYDROData/HYDROData_PolylineOperator.cxx | 170 +++++++++++-------- src/HYDROData/HYDROData_PolylineOperator.h | 40 +++-- src/HYDROData/HYDROData_PolylineXY.cxx | 4 +- src/HYDROData/HYDROData_SplitToZonesTool.h | 9 + src/HYDROGUI/HYDROGUI_MergePolylinesOp.cxx | 3 +- src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx | 9 +- 7 files changed, 152 insertions(+), 92 deletions(-) diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index b0241aa9..be8f1a8b 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -16,8 +16,11 @@ // 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" @@ -67,6 +70,10 @@ #include #endif +#ifdef WIN32 + #pragma warning ( default: 4251 ) +#endif + #define EXPORT_NAME "HYDRO_" + GetName() IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity) diff --git a/src/HYDROData/HYDROData_PolylineOperator.cxx b/src/HYDROData/HYDROData_PolylineOperator.cxx index dff7ce3e..43eda5ff 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.cxx +++ b/src/HYDROData/HYDROData_PolylineOperator.cxx @@ -20,8 +20,11 @@ #include #include #include +#include #include #include +#include +#include template void append( std::vector& theList, const std::vector& theList2 ) { @@ -36,138 +39,167 @@ template void append( std::vector& theList, const std::vector& 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 aPointsList( 1 ); aPointsList[0] = thePoint; - std::vector aCurves = GetCurves( thePolyline ); + std::vector aCurves = GetWires( thePolyline ); bool isOK = true; for( int i=0, n=aCurves.size(); i aCurvesList = Split( aCurves[i], aPointsList ); - bool isLocalOK = CreatePolylines( theDoc, theNamePrefix, aCurvesList ); + std::vector 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 aCurves = GetCurves( thePolyline ); - std::vector aToolCurves = GetCurves( theTool ); - bool isOK = true; - for( int i=0, n=aCurves.size(); i aPointsList = Intersection( aCurves[i], aToolCurves[j] ); - std::vector 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 anAllCurves; for( int i=f; i<=l; i++ ) { - Handle( HYDROData_PolylineXY ) aPolyline = Handle( HYDROData_PolylineXY )::DownCast( thePolylines.Value( i ) ); - std::vector 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 aShapes( 1 ); + aShapes[0] = aMergedPolyline; + CreatePolylines( theDoc, theName, aShapes ); - for( int i=0, n=anAllCurves.size(); i aCurves = GetWires( thePolyline ); + std::vector 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 aResults( n ); + for( int i=0; i aCompletePointsList; - for( int j=0; j aNewResults; + for( int k=0, q=aResults.size(); k aPointsList = Intersection( anAllCurves[i], anAllCurves[j] ); - append( aCompletePointsList, aPointsList ); + std::vector aCurvesList = Split( TopoDS::Wire( aResults[k] ), aToolCurves[j], theTolerance ); + append( aNewResults, aCurvesList ); } - std::vector 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 HYDROData_PolylineOperator::GetWires( const Handle( HYDROData_PolylineXY )& thePolyline ) { - //TODO + std::vector 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 HYDROData_PolylineOperator::GetCurves( const Handle( HYDROData_PolylineXY )& thePolyline ) +std::vector HYDROData_PolylineOperator::Split( const TopoDS_Wire& theWire, + const gp_Pnt2d& thePoint, + double theTolerance ) { - std::vector aResult; + std::vector aResult; //TODO return aResult; } -std::vector HYDROData_PolylineOperator::Intersection( const Handle( Geom2d_Curve )& theCurve, - const Handle( Geom2d_Curve )& theTool ) +std::vector HYDROData_PolylineOperator::Split( const TopoDS_Wire& theWire, + const TopoDS_Wire& theTool, + double theTolerance ) { - std::vector aResult; + std::vector aResult; //TODO return aResult; } -std::vector HYDROData_PolylineOperator::Split( const Handle( Geom2d_Curve )& theCurve, - const std::vector& thePoints ) +std::vector HYDROData_PolylineOperator::Split( const std::vector& theWires, + double theTolerance ) { - std::vector aResult; + std::vector aResult; //TODO return aResult; } bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Document )& theDoc, - const TCollection_AsciiString& theNamePrefix, - const std::vector& theCurves ) + const QString& theNamePrefix, + const std::vector& theShapes ) { if( theDoc.IsNull() ) return false; - int n = theCurves.size(); + int n = theShapes.size(); for( int i=0; iCreateObject( KIND_POLYLINEXY ) ); if( aPolyline.IsNull() ) return false; - aPolyline->SetShape( aMakeWire.Wire() ); + aPolyline->SetShape( theShapes[i] ); //TODO: set name } return true; diff --git a/src/HYDROData/HYDROData_PolylineOperator.h b/src/HYDROData/HYDROData_PolylineOperator.h index a76a6af9..0613c239 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.h +++ b/src/HYDROData/HYDROData_PolylineOperator.h @@ -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 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 Intersection( const Handle( Geom2d_Curve )& theCurve, - const Handle( Geom2d_Curve )& theTool ); + static std::vector GetWires( const Handle( HYDROData_PolylineXY )& thePolyline ); - static std::vector Split( const Handle( Geom2d_Curve )& theCurve, - const std::vector& thePoints ); + static std::vector Split( const TopoDS_Wire& theWire, + const gp_Pnt2d& thePoint, + double theTolerance ); + static std::vector Split( const TopoDS_Wire& theWire, + const TopoDS_Wire& theTool, + double theTolerance ); + static std::vector Split( const std::vector& theWires, + double theTolerance ); static bool CreatePolylines( const Handle( HYDROData_Document )& theDoc, - const TCollection_AsciiString& theNamePrefix, - const std::vector& theCurves ); + const QString& theNamePrefix, + const std::vector& theShape ); }; #endif diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index 608e5b95..ab34af79 100755 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -495,7 +495,7 @@ void HYDROData_PolylineXY::Update() NCollection_Sequence 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 diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.h b/src/HYDROData/HYDROData_SplitToZonesTool.h index 160fba0d..eaa58208 100644 --- a/src/HYDROData/HYDROData_SplitToZonesTool.h +++ b/src/HYDROData/HYDROData_SplitToZonesTool.h @@ -19,6 +19,10 @@ #ifndef HYDROData_SplitToZonesTool_H #define HYDROData_SplitToZonesTool_H +#ifdef WIN32 + #pragma warning ( disable: 4251 ) +#endif + #include #include #include @@ -97,4 +101,9 @@ private: static Standard_Integer SplitFaces(const TopoDS_Compound& theComp, HYDROData_Transform& theTool); }; +#ifdef WIN32 + #pragma warning ( default: 4251 ) +#endif + + #endif diff --git a/src/HYDROGUI/HYDROGUI_MergePolylinesOp.cxx b/src/HYDROGUI/HYDROGUI_MergePolylinesOp.cxx index c5067c84..b97ca96c 100644 --- a/src/HYDROGUI/HYDROGUI_MergePolylinesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_MergePolylinesOp.cxx @@ -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; diff --git a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx index d6556fba..bab464a8 100644 --- a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx @@ -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; } -- 2.39.2