Salome HOME
Selector implementation for OCC viewer.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationOp.cxx
index 71082b7e14b1287b3e4ab4e2c1d25f95b57df7eb..fd48bc169f2a73f5f80a6feb9beaa1e4c6394b30 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <HYDROData_Polyline.h>
 #include <HYDROData_Iterator.h>
+#include <HYDROData_Zone.h>
 
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
@@ -63,12 +64,12 @@ void HYDROGUI_CalculationOp::startOperation()
   if ( !aPanel )
     return;
 
-  mySplittedZones.clear();
+  myRegionsList.clear();
   aPanel->reset();
 
   QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Case" );
 
-  QStringList aSelectedZones, aSplittedZones;
+  QStringList aSelectedZones, aRegions;
 
   myEditedObject.Nullify();
   if ( myIsEdit )
@@ -101,37 +102,32 @@ void HYDROGUI_CalculationOp::startOperation()
         aSelectedZones.append( aRefZoneName );
       }
 
-      HYDROData_SequenceOfObjects aSplitZones = myEditedObject->GetSplittedZones();
-      anIter.Init( aSplitZones );
+      HYDROData_SequenceOfObjects aDataRegions = myEditedObject->GetRegions();
+      anIter.Init( aDataRegions );
       for ( ; anIter.More(); anIter.Next() )
       {
-        Handle(HYDROData_Zone) aSplitZone = 
-          Handle(HYDROData_Zone)::DownCast( anIter.Value() );
-        if ( aSplitZone.IsNull() )
+        Handle(HYDROData_Region) aDataRegion = 
+          Handle(HYDROData_Region)::DownCast( anIter.Value() );
+        if ( aDataRegion.IsNull() )
           continue;
 
-        QString aSplitZoneName = aSplitZone->GetName();
-        if ( aSplitZoneName.isEmpty() )
+        QString aRegionName = aDataRegion->GetName();
+        if ( aRegionName.isEmpty() )
           continue;
 
-        SplittedZone aSplittedZone;
-        aSplittedZone.SplitData.Path = aSplitZone->GetPainterPath();
-        // aSplittedZone.SplitData.ZoneNames ???
-
-        aSplittedZone.FillingColor = aSplitZone->GetFillingColor();
-        aSplittedZone.BorderColor  = aSplitZone->GetBorderColor();
+        Region aRegion;
+        aRegion.SplitData.Shape = aDataRegion->Face();
 
-        aSplittedZone.ZoneName = aSplitZoneName;
+        aRegion.FillingColor = aDataRegion->GetFillingColor();
+        aRegion.BorderColor  = aDataRegion->GetBorderColor();
 
-        Handle(HYDROData_Polyline) aZonePolyline = aSplitZone->GetPolyline();
-        if ( !aZonePolyline.IsNull() )
-          aSplittedZone.PolylineName = aZonePolyline->GetName();
+        aRegion.RegionName = aRegionName;
 
-        aSplittedZone.DataZone = aSplitZone;
+        aRegion.DataRegion = aDataRegion;
 
-        mySplittedZones.append( aSplittedZone );
+        myRegionsList.append( aRegion );
 
-        aSplittedZones.append( aSplitZoneName );
+        aRegions.append( aRegionName );
       }
     }
   }
@@ -158,7 +154,7 @@ void HYDROGUI_CalculationOp::startOperation()
 
   aPanel->setZones( aZones );
   aPanel->setSelectedZones( aSelectedZones );
-  aPanel->setSplittedZones( aSplittedZones );
+  aPanel->setRegions( aRegions );
 
   createPreview();
 }
@@ -234,66 +230,36 @@ bool HYDROGUI_CalculationOp::processApply( int&     theUpdateFlags,
 
   aCalculObj->SetZones( aRefZones );
 
-  HYDROData_SequenceOfObjects aSplittedZones;
+  HYDROData_SequenceOfObjects aRegions;
 
-  SplittedZonesList::iterator anIter = mySplittedZones.begin();
-  for ( ; anIter != mySplittedZones.end(); ++anIter )
+  RegionsList::iterator anIter = myRegionsList.begin();
+  for ( ; anIter != myRegionsList.end(); ++anIter )
   {
-    const SplittedZone& aSplittedZone = *anIter;
+    const Region& aRegion = *anIter;
 
-    if ( !aSplittedZone.DataZone.IsNull() )
+    if ( !aRegion.DataRegion.IsNull() )
     {
       //No need to create new but use old zone
-      aSplittedZones.Append( aSplittedZone.DataZone );
+      aRegions.Append( aRegion.DataRegion );
       continue;
     }
 
-    Handle(HYDROData_Polyline) aPolyline =
-      Handle(HYDROData_Polyline)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
-    Handle(HYDROData_Zone) aDataZone =
-      Handle(HYDROData_Zone)::DownCast( aDocument->CreateObject( KIND_ZONE ) );
-
-    if( aPolyline.IsNull() || aDataZone.IsNull() )
+    Handle(HYDROData_Region) aDataRegion =
+      Handle(HYDROData_Region)::DownCast( aDocument->CreateObject( KIND_REGION ) );
+    if( aDataRegion.IsNull() )
       continue;
 
-    // Fill the polyline data
-    aPolyline->SetName( aSplittedZone.PolylineName );
-    aPolyline->setDimension( 2 );
-
-    QList<PolylineSection> aPolylineData;
-    for( int i = 0, n = aSplittedZone.SplitData.Path.elementCount(); i < n; i++ )
-    {
-      const QPainterPath::Element anElement = aSplittedZone.SplitData.Path.elementAt( i );
-      switch( anElement.type )
-      {
-        case QPainterPath::MoveToElement:
-          aPolylineData.append( PolylineSection() );
-          break;
-        case QPainterPath::LineToElement:
-          if( !aPolylineData.isEmpty() )
-          {
-            PolylineSection& aSection = aPolylineData.last();
-            aSection.myCoords << anElement.x;
-            aSection.myCoords << anElement.y;
-          }
-          break;
-        case QPainterPath::CurveToElement: // currently not supported
-        default:
-          break;
-      }
-    }
-    aPolyline->setPolylineData( aPolylineData );
-
     // Fill the zone data
-    aDataZone->SetName( aSplittedZone.ZoneName );
-    aDataZone->SetPolyline( aPolyline );
-    aDataZone->SetBorderColor( aSplittedZone.BorderColor );
-    aDataZone->SetFillingColor( aSplittedZone.FillingColor );
+    aDataRegion->SetFace( aRegion.SplitData.Face() );
 
-    aSplittedZones.Append( aDataZone );
+    aDataRegion->SetName( aRegion.RegionName );
+    aDataRegion->SetBorderColor( aRegion.BorderColor );
+    aDataRegion->SetFillingColor( aRegion.FillingColor );
+
+    aRegions.Append( aDataRegion );
   }
 
-  aCalculObj->SetSplittedZones( aSplittedZones );
+  aCalculObj->SetRegions( aRegions );
 
   theUpdateFlags = UF_Model;
 
@@ -302,7 +268,7 @@ bool HYDROGUI_CalculationOp::processApply( int&     theUpdateFlags,
 
 void HYDROGUI_CalculationOp::onSplitZones()
 {
-  mySplittedZones.clear();
+  myRegionsList.clear();
 
   HYDROGUI_CalculationDlg* aPanel = 
     ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
@@ -330,24 +296,22 @@ void HYDROGUI_CalculationOp::onSplitZones()
   HYDROGUI_SplitZonesTool::SplitDataListIterator anIter( aSplittedZones );
   while( anIter.hasNext() )
   {
-    SplittedZone aSplittedZone;
-    aSplittedZone.SplitData = anIter.next();
+    Region aRegion;
+    aRegion.SplitData = anIter.next();
 
-    aSplittedZone.FillingColor = HYDROGUI_Tool::GenerateFillingColor( module(), aSplittedZone.SplitData.ZoneNames );
-    aSplittedZone.BorderColor  = QColor( HYDROData_Zone::DefaultBorderColor() );
+    aRegion.FillingColor = HYDROGUI_Tool::GenerateFillingColor( module(), aRegion.SplitData.ZoneNames );
+    aRegion.BorderColor  = QColor( HYDROData_Zone::DefaultBorderColor() );
 
-    aSplittedZone.ZoneName = HYDROGUI_Tool::GenerateObjectName( module(), aSplitZonesPrefix + "Zone", aUsedNames );
-    aSplittedZone.PolylineName = HYDROGUI_Tool::GenerateObjectName( module(), aSplitZonesPrefix + "Poly", aUsedNames );
+    aRegion.RegionName = HYDROGUI_Tool::GenerateObjectName( module(), aSplitZonesPrefix, aUsedNames );
 
-    aUsedNames.append( aSplittedZone.ZoneName );
-    aUsedNames.append( aSplittedZone.PolylineName );
+    aUsedNames.append( aRegion.RegionName );
 
-    aResSplittedZones.append( aSplittedZone.ZoneName );
+    aResSplittedZones.append( aRegion.RegionName );
 
-    mySplittedZones.append( aSplittedZone );
+    myRegionsList.append( aRegion );
   }
 
-  aPanel->setSplittedZones( aResSplittedZones );
+  aPanel->setRegions( aResSplittedZones );
   
   createPreview();
 
@@ -360,7 +324,7 @@ void HYDROGUI_CalculationOp::createPreview()
 
   if ( !myActiveViewManager )
   {
-    if ( mySplittedZones.isEmpty() )
+    if ( myRegionsList.isEmpty() )
       return;
 
     myActiveViewManager = anApp->activeViewManager();
@@ -388,18 +352,21 @@ void HYDROGUI_CalculationOp::createPreview()
     Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
     if ( !aCtx.IsNull() )
     {
-      SplittedZonesList::iterator anIter = mySplittedZones.begin();
-      for ( ; anIter != mySplittedZones.end(); ++anIter )
+      RegionsList::iterator anIter = myRegionsList.begin();
+      for ( ; anIter != myRegionsList.end(); ++anIter )
       {
-        SplittedZone& aSplittedZone = *anIter;
-        if ( aSplittedZone.Shape )
-          delete aSplittedZone.Shape;
-
-        aSplittedZone.Shape = new HYDROGUI_Shape( aCtx );
-
-        aSplittedZone.Shape->setFillingColor( aSplittedZone.FillingColor, false );
-        aSplittedZone.Shape->setBorderColor( aSplittedZone.BorderColor, false );
-        aSplittedZone.Shape->setPath( aSplittedZone.SplitData.Path, true );
+        Region& aRegion = *anIter;
+        if ( aRegion.Shape )
+        {
+          aRegion.Shape->erase( false );
+          delete aRegion.Shape;
+        }
+
+        aRegion.Shape = new HYDROGUI_Shape( aCtx, NULL );
+
+        aRegion.Shape->setFillingColor( aRegion.FillingColor, false, false );
+        aRegion.Shape->setBorderColor( aRegion.BorderColor, false, false );
+        aRegion.Shape->setFace( aRegion.SplitData.Face(), true, false );
       }
 
       //Process the draw events for viewer
@@ -417,14 +384,15 @@ void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager
 
 void HYDROGUI_CalculationOp::closePreview()
 {
-  SplittedZonesList::iterator anIter= mySplittedZones.begin();
-  for ( ; anIter != mySplittedZones.end(); ++anIter )
+  RegionsList::iterator anIter= myRegionsList.begin();
+  for ( ; anIter != myRegionsList.end(); ++anIter )
   {
-    SplittedZone& aSplittedZone = *anIter;
-    if ( aSplittedZone.Shape )
+    Region& aRegion = *anIter;
+    if ( aRegion.Shape )
     {
-      delete aSplittedZone.Shape;
-      aSplittedZone.Shape = NULL;
+      aRegion.Shape->erase( false );
+      delete aRegion.Shape;
+      aRegion.Shape = NULL;
     }
   }