#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 )
{
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;
{
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