#include "HYDROGUI_SplitZonesTool.h"
+#include <HYDROData_Polyline.h>
#include <HYDROData_Zone.h>
-void printPath( const QString& thePrefix, const QPainterPath& thePath )
+void printPath( const QString& thePathName,
+ const QPainterPath& thePath,
+ const QStringList& theZonesList = QStringList() )
{
- printf( "%s (n=%d) :", qPrintable( thePrefix ), thePath.elementCount() );
+ printf( "%s ", qPrintable( thePathName ) );
+ if( !theZonesList.isEmpty() )
+ {
+ printf( "[ " );
+ QStringListIterator anIter( theZonesList );
+ while( anIter.hasNext() )
+ printf( "%s ", qPrintable( anIter.next() ) );
+ printf( "] " );
+ }
+ printf( "(n=%d) :", thePath.elementCount() );
for( int i = 0, n = thePath.elementCount(); i < n; i++ )
{
const QPainterPath::Element anElement = thePath.elementAt( i );
HYDROGUI_SplitZonesTool::SplitDataList
HYDROGUI_SplitZonesTool::SplitZones( const HYDROData_SequenceOfObjects& theZoneList,
- const Handle(HYDROData_Polyline)& thePolylie )
+ const Handle(HYDROData_Polyline)& thePolyline )
{
SplitDataList anOutputSplitDataList;
+ // Preparation. Collect the zone paths to split.
SplitDataList anInputSplitDataList;
for( int anIndex = 1, aLength = theZoneList.Length(); anIndex <= aLength; anIndex++ )
{
}
}
+ // Step 1. Split the paths.
+ printf( "Step 1\n" );
SplitDataListIterator anInputIter( anInputSplitDataList );
while( anInputIter.hasNext() )
{
else
{
SplitDataList aSplitDataList;
- SplitDataListIterator anOutputIter( anOutputSplitDataList );
- while( anOutputIter.hasNext() )
+
+ SplitDataList aSrcSplitDataList;
+ aSrcSplitDataList.append( anInputSplitData );
+
+ SplitDataList aDestSplitDataList = anOutputSplitDataList;
+ anOutputSplitDataList.clear();
+
+ while( !aDestSplitDataList.isEmpty() )
{
- const SplitData& anOutputSplitData = anOutputIter.next();
+ SplitData aSrcSplitData = aSrcSplitDataList.last();
+
+ SplitData aDestSplitData = aDestSplitDataList.first();
+ aDestSplitDataList.pop_front();
- SplitDataList aList = SplitTwoData( anOutputSplitData, anInputSplitData );
- aSplitDataList.append( aList );
+ SplitData aData1Subtracted, aData2Subtracted, aDataIntersected;
+ if( SplitTwoData( aSrcSplitData, aDestSplitData,
+ aData1Subtracted, aData2Subtracted, aDataIntersected ) )
+ anOutputSplitDataList.append( aDataIntersected );
+ anOutputSplitDataList.append( aData2Subtracted );
+ aSrcSplitDataList.append( aData1Subtracted );
}
- anOutputSplitDataList = aSplitDataList;
+
+ if( !aSrcSplitDataList.isEmpty() )
+ anOutputSplitDataList.append( aSrcSplitDataList.last() );
}
}
- /*
- if( theZoneList.Length() != 2 )
- return aSplitDataList;
-
- Handle(HYDROData_Zone) aZone1 = Handle(HYDROData_Zone)::DownCast( theZoneList.Value( 1 ) );
- Handle(HYDROData_Zone) aZone2 = Handle(HYDROData_Zone)::DownCast( theZoneList.Value( 2 ) );
+ // Step 2. Take into account the boundary polyline.
+ printf( "Step 2\n" );
+ if( !thePolyline.IsNull() )
+ {
+ const QPainterPath& aBoundaryPath = thePolyline->painterPath();
+ SplitData aBoundarySplitData( aBoundaryPath, "" );
- SplitData aSplitData1( aZone1->GetPainterPath(), aZone1->GetName() );
- SplitData aSplitData2( aZone2->GetPainterPath(), aZone2->GetName() );
+ SplitDataList aCutSplitDataList;
+ SplitDataListIterator anOutputIter( anOutputSplitDataList );
+ while( anOutputIter.hasNext() )
+ {
+ const SplitData& anOutputSplitData = anOutputIter.next();
- aSplitDataList = SplitTwoData( aSplitData1, aSplitData2 );
- */
+ SplitData aData1Subtracted, aData2Subtracted, aDataIntersected;
+ if( SplitTwoData( anOutputSplitData, aBoundarySplitData,
+ aData1Subtracted, aData2Subtracted, aDataIntersected ) )
+ aCutSplitDataList.append( aDataIntersected );
+ }
+ anOutputSplitDataList = aCutSplitDataList;
+ }
- return anOutputSplitDataList;
+ // Step 3. Extract the separate regions.
+ printf( "Step 3\n" );
+ SplitDataList anExtractedSplitDataList;
+ SplitDataListIterator anOutputIter( anOutputSplitDataList );
+ while( anOutputIter.hasNext() )
+ {
+ const SplitData& anOutputSplitData = anOutputIter.next();
+ anExtractedSplitDataList.append( ExtractSeparateData( anOutputSplitData ) );
+ }
+ return anExtractedSplitDataList;
}
-HYDROGUI_SplitZonesTool::SplitDataList
-HYDROGUI_SplitZonesTool::SplitTwoData( const SplitData& theData1,
- const SplitData& theData2 )
+bool HYDROGUI_SplitZonesTool::SplitTwoData( const SplitData& theData1,
+ const SplitData& theData2,
+ SplitData& theData1Subtracted,
+ SplitData& theData2Subtracted,
+ SplitData& theDataIntersected )
{
- SplitDataList aSplitDataList;
-
const QPainterPath& aPath1 = theData1.Path;
const QPainterPath& aPath2 = theData2.Path;
- printPath( "aPath1", aPath1 );
- printPath( "aPath2", aPath2 );
const QStringList& aZoneNames1 = theData1.ZoneNames;
const QStringList& aZoneNames2 = theData2.ZoneNames;
- QPainterPath anIntersection = aPath1.intersected( aPath2 );
- printPath( "anIntersection", anIntersection );
- anIntersection.closeSubpath();
- printPath( "anIntersection after closing", anIntersection );
- if( anIntersection.isEmpty() )
+ //printPath( "aPath1", aPath1, aZoneNames1 );
+ //printPath( "aPath2", aPath2, aZoneNames2 );
+
+ QPainterPath aPathIntersected = aPath1.intersected( aPath2 );
+ aPathIntersected.closeSubpath();
+ //printPath( "aPathIntersected", aPathIntersected );
+ if( aPathIntersected.isEmpty() )
{
- aSplitDataList.append( theData1 );
- //aSplitDataList.append( theData2 );
+ theData1Subtracted = theData1;
+ theData2Subtracted = theData2;
+ return false;
}
- else
- {
- aSplitDataList.append( SplitData( anIntersection, aZoneNames1 + aZoneNames2 ) );
- QPainterPath aPath1Sub = aPath1.subtracted( aPath2 );
- printPath( "aPath1Sub", aPath1Sub );
- if( !aPath1Sub.isEmpty() )
- aSplitDataList.append( ExtractSeparateData( SplitData( aPath1Sub, aZoneNames1 ) ) );
+ QPainterPath aPath1Subtracted = aPath1.subtracted( aPath2 );
+ //printPath( "aPath1Subtracted", aPath1Subtracted );
+ theData1Subtracted = SplitData( aPath1Subtracted, aZoneNames1 );
- QPainterPath aPath2Sub = aPath2.subtracted( aPath1 );
- printPath( "aPath2Sub", aPath2Sub );
- if( !aPath2Sub.isEmpty() )
- aSplitDataList.append( ExtractSeparateData( SplitData( aPath2Sub, aZoneNames2 ) ) );
- }
- return aSplitDataList;
+ QPainterPath aPath2Subtracted = aPath2.subtracted( aPath1 );
+ //printPath( "aPath2Subtracted", aPath2Subtracted );
+ theData2Subtracted = SplitData( aPath2Subtracted, aZoneNames2 );
+
+ theDataIntersected = SplitData( aPathIntersected, aZoneNames1 + aZoneNames2 );
+
+ return true;
}
HYDROGUI_SplitZonesTool::SplitDataList
}
}
+ // check the hole case
if( aPathList.size() == 2 )
{
const QPainterPath& aPath1 = aPathList.first();
const QPainterPath& aPath2 = aPathList.last();
if( aPath1.contains( aPath2 ) || aPath2.contains( aPath1 ) )
{
- printf( "HOLE CASE!\n" );
aSplitDataList.append( theData );
return aSplitDataList;
}
QListIterator<QPainterPath> anIter( aPathList );
while( anIter.hasNext() )
{
- const QPainterPath& aPath = anIter.next();
- printPath( "aPath", aPath );
+ QPainterPath aPath = anIter.next();
+ aPath.closeSubpath();
+ //printPath( "aPath", aPath );
aSplitDataList.append( SplitData( aPath, aBaseZoneNames ) );
}
return aSplitDataList;