//
#include <HYDROData_PolylineOperator.h>
+#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>
-bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& thePolyline,
- const gp_Pnt2d& thePoint ) const
+template<class T> void append( std::vector<T>& theList, const std::vector<T>& theList2 )
{
- //TODO
+ int aSize = theList.size();
+ int aNewSize = aSize + theList2.size();
+
+ if( aSize==aNewSize )
+ return;
+
+ theList.resize( aNewSize );
+ for( int i=aSize, j=0; i<aNewSize; i++, j++ )
+ theList[i] = theList2[j];
+}
+
+bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
+ const Handle( HYDROData_PolylineXY )& thePolyline,
+ const gp_Pnt2d& thePoint,
+ double theTolerance ) const
+{
+ std::vector<gp_Pnt2d> aPointsList( 1 );
+ aPointsList[0] = thePoint;
+ std::vector<TopoDS_Wire> aCurves = GetWires( thePolyline );
+ bool isOK = true;
+ for( int i=0, n=aCurves.size(); i<n; i++ )
+ {
+ std::vector<TopoDS_Shape> aCurvesList = Split( aCurves[i], thePoint, theTolerance );
+ bool isLocalOK = CreatePolylines( theDoc, thePolyline->GetName(), aCurvesList, true );
+ isOK = isOK && isLocalOK;
+ }
+ return isOK;
+}
+
+bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
+ const Handle( HYDROData_PolylineXY )& thePolyline,
+ const Handle( HYDROData_PolylineXY )& theTool,
+ double theTolerance ) const
+{
+ HYDROData_SequenceOfObjects aSeq;
+ aSeq.Append( theTool );
+ return split( theDoc, thePolyline, aSeq, theTolerance, -1 );
+}
+
+bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
+ const HYDROData_SequenceOfObjects& thePolylines,
+ double theTolerance )
+{
+ int f = thePolylines.Lower(), l = thePolylines.Upper();
+ for( int i=f; i<=l; i++ )
+ {
+ Handle( HYDROData_PolylineXY ) aPolyline = Handle( HYDROData_PolylineXY )::DownCast( thePolylines.Value( i ) );
+ if( !split( theDoc, aPolyline, thePolylines, theTolerance, i ) )
+ return false;
+ }
return true;
}
-bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& thePolyline,
- const Handle( HYDROData_PolylineXY )& theTool ) const
+bool HYDROData_PolylineOperator::Merge( const Handle( HYDROData_Document )& theDoc,
+ const QString& theName,
+ const HYDROData_SequenceOfObjects& thePolylines,
+ bool isConnectByNewSegment,
+ double theTolerance )
{
- //TODO
+ TopoDS_Shape aMergedPolyline;
+
+ int f = thePolylines.Lower(), l = thePolylines.Upper();
+ for( int i=f; i<=l; i++ )
+ {
+ Handle( HYDROData_PolylineXY ) aPolyline = Handle( HYDROData_PolylineXY )::DownCast( thePolylines.Value( i ) );
+ std::vector<TopoDS_Wire> aCurves = GetWires( aPolyline );
+ for( int j=0, m=aCurves.size(); j<m; j++ )
+ if( !Merge( aMergedPolyline, aCurves[j], isConnectByNewSegment, theTolerance ) )
+ return false;
+ }
+
+ std::vector<TopoDS_Shape> aShapes( 1 );
+ aShapes[0] = aMergedPolyline;
+ CreatePolylines( theDoc, theName, aShapes, false );
+
return true;
}
-bool HYDROData_PolylineOperator::Split( const HYDROData_SequenceOfObjects& thePolylines )
+bool HYDROData_PolylineOperator::Merge( TopoDS_Shape& theShape, const TopoDS_Wire& theWire,
+ bool isConnectByNewSegment, double theTolerance )
{
//TODO
return true;
}
-bool HYDROData_PolylineOperator::Merge( const HYDROData_SequenceOfObjects& thePolylines )
+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<TopoDS_Shape> aNewResults;
+ for( int k=0, q=aResults.size(); k<q; k++ )
+ {
+ std::vector<TopoDS_Shape> aCurvesList = Split( TopoDS::Wire( aResults[k] ), aToolCurves[j], theTolerance );
+ append( aNewResults, aCurvesList );
+ }
+ aResults = aNewResults;
+ }
+
+ CreatePolylines( theDoc, thePolyline->GetName(), aResults, true );
+
+ return isOK;
+}
+
+std::vector<TopoDS_Wire> HYDROData_PolylineOperator::GetWires( const Handle( HYDROData_PolylineXY )& thePolyline )
{
+ std::vector<TopoDS_Wire> aResult;
+
+ TopoDS_Shape aShape = thePolyline->GetShape();
+
+ 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<TopoDS_Shape> HYDROData_PolylineOperator::Split( const TopoDS_Wire& theWire,
+ const gp_Pnt2d& thePoint,
+ double theTolerance )
+{
+ std::vector<TopoDS_Shape> aResult;
//TODO
+ return aResult;
+}
+
+std::vector<TopoDS_Shape> HYDROData_PolylineOperator::Split( const TopoDS_Wire& theWire,
+ const TopoDS_Wire& theTool,
+ double theTolerance )
+{
+ std::vector<TopoDS_Shape> aResult;
+ //TODO
+ return aResult;
+}
+
+std::vector<TopoDS_Shape> HYDROData_PolylineOperator::Split( const std::vector<TopoDS_Wire>& theWires,
+ double theTolerance )
+{
+ std::vector<TopoDS_Shape> aResult;
+ //TODO
+ return aResult;
+}
+
+bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Document )& theDoc,
+ const QString& theNamePrefix,
+ const std::vector<TopoDS_Shape>& theShapes,
+ bool isUseIndices )
+{
+ if( theDoc.IsNull() )
+ return false;
+
+ int n = theShapes.size();
+ for( int i=0; i<n; i++ )
+ {
+ Handle( HYDROData_PolylineXY ) aPolyline =
+ Handle( HYDROData_PolylineXY )::DownCast( theDoc->CreateObject( KIND_POLYLINEXY ) );
+ if( aPolyline.IsNull() )
+ return false;
+
+ aPolyline->SetShape( theShapes[i] );
+ //TODO: set name
+ }
return true;
}