From 1a52e03c8344a46f0db70927bf8c445815fc7b2d Mon Sep 17 00:00:00 2001 From: ouv Date: Fri, 20 Sep 2013 12:54:23 +0000 Subject: [PATCH] Split Zones functionality + some minor changes. --- src/HYDROGUI/HYDROGUI_Shape.cxx | 2 +- src/HYDROGUI/HYDROGUI_SplitZonesTool.cxx | 146 ++++++++++++++-------- src/HYDROGUI/HYDROGUI_SplitZonesTool.h | 9 +- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 2 +- 4 files changed, 104 insertions(+), 55 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index 3fee62af..be595d23 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -331,7 +331,7 @@ QColor HYDROGUI_Shape::getActiveColor() const double HYDROGUI_Shape::getQuantityColorVal( const int theColorVal ) { - return theColorVal == 0 ? 0 : (double)( theColorVal / 255 ); + return theColorVal == 0 ? 0 : ( (double)theColorVal / 255 ); } void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor ) diff --git a/src/HYDROGUI/HYDROGUI_SplitZonesTool.cxx b/src/HYDROGUI/HYDROGUI_SplitZonesTool.cxx index d570f46c..2411bacc 100644 --- a/src/HYDROGUI/HYDROGUI_SplitZonesTool.cxx +++ b/src/HYDROGUI/HYDROGUI_SplitZonesTool.cxx @@ -22,11 +22,23 @@ #include "HYDROGUI_SplitZonesTool.h" +#include #include -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 ); @@ -47,10 +59,11 @@ void printPath( const QString& thePrefix, const QPainterPath& thePath ) 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++ ) { @@ -62,6 +75,8 @@ HYDROGUI_SplitZonesTool::SplitZones( const HYDROData_SequenceOfObjects& theZoneL } } + // Step 1. Split the paths. + printf( "Step 1\n" ); SplitDataListIterator anInputIter( anInputSplitDataList ); while( anInputIter.hasNext() ) { @@ -71,72 +86,102 @@ HYDROGUI_SplitZonesTool::SplitZones( const HYDROData_SequenceOfObjects& theZoneL 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 @@ -169,13 +214,13 @@ HYDROGUI_SplitZonesTool::ExtractSeparateData( const SplitData& theData ) } } + // 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; } @@ -184,8 +229,9 @@ HYDROGUI_SplitZonesTool::ExtractSeparateData( const SplitData& theData ) QListIterator 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; diff --git a/src/HYDROGUI/HYDROGUI_SplitZonesTool.h b/src/HYDROGUI/HYDROGUI_SplitZonesTool.h index 7a1b3c21..0f68d15f 100644 --- a/src/HYDROGUI/HYDROGUI_SplitZonesTool.h +++ b/src/HYDROGUI/HYDROGUI_SplitZonesTool.h @@ -59,11 +59,14 @@ public: public: static SplitDataList SplitZones( const HYDROData_SequenceOfObjects& theZoneList, - const Handle(HYDROData_Polyline)& thePolylie ); + const Handle(HYDROData_Polyline)& thePolyline ); private: - static SplitDataList SplitTwoData( const SplitData& theData1, - const SplitData& theData2 ); + static bool SplitTwoData( const SplitData& theData1, + const SplitData& theData2, + SplitData& theData1Subtracted, + SplitData& theData2Subtracted, + SplitData& theDataIntersected ); static SplitDataList ExtractSeparateData( const SplitData& theData ); }; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index e006fe79..13f36555 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -98,7 +98,7 @@ does not exist or you have not enough permissions to open it. DEFAULT_PREFIX_SPLITTED_ZONES - Splitt + Split NAME -- 2.39.2