]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Split Zones functionality + some minor changes.
authorouv <ouv@opencascade.com>
Fri, 20 Sep 2013 12:54:23 +0000 (12:54 +0000)
committerouv <ouv@opencascade.com>
Fri, 20 Sep 2013 12:54:23 +0000 (12:54 +0000)
src/HYDROGUI/HYDROGUI_Shape.cxx
src/HYDROGUI/HYDROGUI_SplitZonesTool.cxx
src/HYDROGUI/HYDROGUI_SplitZonesTool.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index 3fee62afb9282293e4902859d6e7de30e1d05375..be595d23a983300fce1a56781c8fcdb0560f93d6 100644 (file)
@@ -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 )
index d570f46c50288b83dff9e5d4449d241d90e98c17..2411bacc0efe008cf34575b382056bc60d256415 100644 (file)
 
 #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 );
@@ -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<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;
index 7a1b3c21458b6b3f544a676a1a8d4ee8e65fad90..0f68d15f455b96620bbd824e210f449cc50cce64 100644 (file)
@@ -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 );
 };
index e006fe795775f6a50aef433265385db9a5456145..13f36555762a16ec254f1c4379a2a04174aaccde 100644 (file)
@@ -98,7 +98,7 @@ does not exist or you have not enough permissions to open it.</translation>
     </message>
     <message>
       <source>DEFAULT_PREFIX_SPLITTED_ZONES</source>
-      <translation>Splitt</translation>
+      <translation>Split</translation>
     </message>
     <message>
       <source>NAME</source>