]> SALOME platform Git repositories - modules/hydro.git/blobdiff - src/HYDROGUI/HYDROGUI_CalculationOp.cxx
Salome HOME
Name validator is added to the Calculation Case dialog.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationOp.cxx
index 5d4a465b695d194b9e13b965bfebd34e515d6ae5..621d9d755a6badbc11402614253e9f0ca8b6e174 100644 (file)
 
 #include <HYDROData_Polyline.h>
 #include <HYDROData_Iterator.h>
-#include <HYDROData_Zone.h>
+#include <HYDROData_ImmersibleZone.h>
 
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
+#include <OCCViewer_ViewWindow.h>
 
 #include <LightApp_Application.h>
 #include <LightApp_UpdateFlags.h>
 
+#include <SUIT_MessageBox.h>
+#include <SUIT_Desktop.h>
+
 #include <QApplication>
 
 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
@@ -57,104 +61,74 @@ HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
 void HYDROGUI_CalculationOp::startOperation()
 {
   HYDROGUI_Operation::startOperation();
+  
+  // Begin transaction
+  startDocOperation();
 
   HYDROGUI_CalculationDlg* aPanel = 
     ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
   if ( !aPanel )
     return;
 
-  mySplittedZones.clear();
+  myRegionsList.clear();
   aPanel->reset();
 
   QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Case" );
 
-  QStringList aSelectedZones, aSplittedZones;
+  QStringList aSelectedObjects;
 
   myEditedObject.Nullify();
   if ( myIsEdit )
   {
-    myEditedObject = Handle(HYDROData_Calculation)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+    myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
     if ( !myEditedObject.IsNull() )
     {
       anObjectName = myEditedObject->GetName();
 
-      Handle(HYDROData_Polyline) aBoundaryPolyline = myEditedObject->GetBoundaryPolyline();
-      if ( !aBoundaryPolyline.IsNull() )
-      {
-        QString aPolylineName = aBoundaryPolyline->GetName();
-        aPanel->setPolylineName( aPolylineName );
-      }
-
-      HYDROData_SequenceOfObjects aRefZones = myEditedObject->GetZones();
-      HYDROData_SequenceOfObjects::Iterator anIter( aRefZones );
-      for ( ; anIter.More(); anIter.Next() )
-      {
-        Handle(HYDROData_Zone) aRefZone = 
-          Handle(HYDROData_Zone)::DownCast( anIter.Value() );
-        if ( aRefZone.IsNull() )
-          continue;
-
-        QString aRefZoneName = aRefZone->GetName();
-        if ( aRefZoneName.isEmpty() )
-          continue;
-
-        aSelectedZones.append( aRefZoneName );
-      }
-
-      HYDROData_SequenceOfObjects aSplitZones = myEditedObject->GetSplittedZones();
-      anIter.Init( aSplitZones );
+      HYDROData_SequenceOfObjects aRefObjects = myEditedObject->GetGeometryObjects();
+      HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
       for ( ; anIter.More(); anIter.Next() )
       {
-        Handle(HYDROData_Zone) aSplitZone = 
-          Handle(HYDROData_Zone)::DownCast( anIter.Value() );
-        if ( aSplitZone.IsNull() )
+        Handle(HYDROData_Object) aRefbject = 
+          Handle(HYDROData_Object)::DownCast( anIter.Value() );
+        if ( aRefbject.IsNull() )
           continue;
 
-        QString aSplitZoneName = aSplitZone->GetName();
-        if ( aSplitZoneName.isEmpty() )
+        QString aRefObjectName = aRefbject->GetName();
+        if ( aRefObjectName.isEmpty() )
           continue;
 
-        aSplittedZones.append( aSplitZoneName );
+        aSelectedObjects.append( aRefObjectName );
       }
     }
   }
-
-  // collect information about existing zones
-  QStringList aZones;
-
-  HYDROData_Iterator anIter( doc(), KIND_ZONE );
-  for ( ; anIter.More(); anIter.Next() )
+  else
   {
-    Handle(HYDROData_Zone) aZoneObj = 
-      Handle(HYDROData_Zone)::DownCast( anIter.Current() );
-    if ( aZoneObj.IsNull() )
-      continue;
-
-    QString aZoneName = aZoneObj->GetName();
-    if ( aZoneName.isEmpty() )
-      continue;
-
-    aZones.append( aZoneName );
+    myEditedObject =
+      Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
+    myEditedObject->SetName(anObjectName);
   }
 
   aPanel->setObjectName( anObjectName );
+  aPanel->setEditedObject( myEditedObject );
+  aPanel->setSelectedGeomObjects( aSelectedObjects );
 
-  aPanel->setZones( aZones );
-  aPanel->setSelectedZones( aSelectedZones );
-  aPanel->setSplittedZones( aSplittedZones );
+  createPreview();
 }
 
 void HYDROGUI_CalculationOp::abortOperation()
 {
   closePreview();
-
+  // Abort transaction
+  abortDocOperation();
   HYDROGUI_Operation::abortOperation();
 }
 
 void HYDROGUI_CalculationOp::commitOperation()
 {
   closePreview();
-
+  // Commit transaction
+  commitDocOperation();
   HYDROGUI_Operation::commitOperation();
 }
 
@@ -163,7 +137,6 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
   HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
 
   // Connect signals and slots
-  connect( aPanel, SIGNAL( SplitZones() ), this, SLOT( onSplitZones() ) );
 
   return aPanel;
 }
@@ -176,107 +149,88 @@ bool HYDROGUI_CalculationOp::processApply( int&     theUpdateFlags,
   if ( !aPanel )
     return false;
 
-  QString anObjectName = aPanel->getObjectName().simplified();
-  if ( anObjectName.isEmpty() )
-  {
-    theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
-    return false;
-  }
+  //QString anObjectName = aPanel->getObjectName().simplified();
+  //if ( anObjectName.isEmpty() )
+  //{
+  //  theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
+  //  return false;
+  //}
+
+  //// check that there are no other objects with the same name in the document
+  //if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
+  //{
+  //  Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
+  //  if ( !anObject.IsNull() )
+  //  {
+  //    theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
+  //    return false;
+  //  }
+  //}
+
+  //Handle(HYDROData_Document) aDocument = doc();
+
+  //Handle(HYDROData_CalculationCase) aCalculObj = myIsEdit ? myEditedObject :
+  //  Handle(HYDROData_CalculationCase)::DownCast( aDocument->CreateObject( KIND_CALCULATION ) );
+  //if ( aCalculObj.IsNull() )
+  //  return false;
+
+  //aCalculObj->SetName( anObjectName );
+
+  //QStringList aRefObjectNames = aPanel->getSelectedGeomObjects();
+  //HYDROData_SequenceOfObjects aGeomObjects = 
+  //  HYDROGUI_Tool::FindObjectsByNames( module(), aRefObjectNames );
 
-  // check that there are no other objects with the same name in the document
-  if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
-  {
-    Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
-    if ( !anObject.IsNull() )
-    {
-      theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
-      return false;
-    }
-  }
-
-  Handle(HYDROData_Document) aDocument = doc();
-
-  Handle(HYDROData_Calculation) aCalculObj = myIsEdit ? myEditedObject :
-    Handle(HYDROData_Calculation)::DownCast( aDocument->CreateObject( KIND_CALCULATION ) );
-  if ( aCalculObj.IsNull() )
-    return false;
-
-  aCalculObj->SetName( anObjectName );
-
-  QString aPolylineName = aPanel->getPolylineName();
-  Handle(HYDROData_Polyline) aBndPolyline = Handle(HYDROData_Polyline)::DownCast(
-      HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINE ) );
-
-  aCalculObj->SetBoundaryPolyline( aBndPolyline );
+  theUpdateFlags = UF_Model;
 
-  QStringList aRefZoneNames = aPanel->getSelectedZones();
-  HYDROData_SequenceOfObjects aRefZones = 
-    HYDROGUI_Tool::FindObjectsByNames( module(), aRefZoneNames, KIND_ZONE );
+  return true;
+}
 
-  aCalculObj->SetZones( aRefZones );
+void HYDROGUI_CalculationOp::onApply()
+{
+  QApplication::setOverrideCursor( Qt::WaitCursor );
 
-  HYDROData_SequenceOfObjects aSplittedZones;
+  int anUpdateFlags = 0;
+  QString anErrorMsg;
 
-  SplittedZonesList::iterator anIter = mySplittedZones.begin();
-  for ( ; anIter != mySplittedZones.end(); ++anIter )
+  bool aResult = false;
+  
+  try
   {
-    const SplittedZone& aSplittedZone = *anIter;
-
-    Handle(HYDROData_Polyline) aPolyline =
-      Handle(HYDROData_Polyline)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
-    Handle(HYDROData_Zone) aDtaZone =
-      Handle(HYDROData_Zone)::DownCast( aDocument->CreateObject( KIND_ZONE ) );
-
-    if( aPolyline.IsNull() || aDtaZone.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
-    aDtaZone->SetName( aSplittedZone.ZoneName );
-    aDtaZone->SetPolyline( aPolyline );
-    aDtaZone->SetBorderColor( aSplittedZone.BorderColor );
-    aDtaZone->SetFillingColor( aSplittedZone.FillingColor );
-
-    aSplittedZones.Append( aDtaZone );
+    aResult = processApply( anUpdateFlags, anErrorMsg );
   }
+  catch ( Standard_Failure )
+  {
+    Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
+    anErrorMsg = aFailure->GetMessageString();
+    aResult = false;
+  }
+  catch ( ... )
+  {
+    aResult = false;
+  }
+  
+  QApplication::restoreOverrideCursor();
 
-  aCalculObj->SetSplittedZones( aSplittedZones );
-
-  theUpdateFlags = UF_Model;
-
-  return true;
+  if ( aResult )
+  {
+    module()->update( anUpdateFlags );
+    commit();
+  }
+  else
+  {
+    abort();
+    QString aMsg = tr( "INPUT_VALID_DATA" );
+    if( !anErrorMsg.isEmpty() )
+      aMsg.prepend( anErrorMsg + "\n" );
+    SUIT_MessageBox::critical( module()->getApp()->desktop(),
+                               tr( "INSUFFICIENT_INPUT_DATA" ),
+                               aMsg ); 
+  }
 }
 
 void HYDROGUI_CalculationOp::onSplitZones()
 {
-  mySplittedZones.clear();
+  myRegionsList.clear();
 
   HYDROGUI_CalculationDlg* aPanel = 
     ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
@@ -285,43 +239,34 @@ void HYDROGUI_CalculationOp::onSplitZones()
 
   QApplication::setOverrideCursor( Qt::WaitCursor );
 
-  QString aPolylineName = aPanel->getPolylineName();
-  Handle(HYDROData_Polyline) aBndPolyline = Handle(HYDROData_Polyline)::DownCast(
-      HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINE ) );
-
-  QStringList aZoneNames = aPanel->getSelectedZones();
-  HYDROData_SequenceOfObjects aZones = 
-    HYDROGUI_Tool::FindObjectsByNames( module(), aZoneNames, KIND_ZONE );
+  QStringList aGeomObjectNames = aPanel->getSelectedGeomObjects();
+  HYDROData_SequenceOfObjects aGeomObjects = 
+    HYDROGUI_Tool::FindObjectsByNames( module(), aGeomObjectNames );
 
   QStringList aResSplittedZones;
 
-  HYDROGUI_SplitZonesTool::SplitDataList aSplittedZones =
-    HYDROGUI_SplitZonesTool::SplitZones( aZones, aBndPolyline );
+  HYDROData_SplitToZonesTool::SplitDataList aSplittedZones =
+    HYDROData_SplitToZonesTool::SplitToZones( aGeomObjects );
 
-  QString aSplitZonesPrefix = aPanel->getSplitZonesPrefix();
   QStringList aUsedNames;
 
-  HYDROGUI_SplitZonesTool::SplitDataListIterator anIter( aSplittedZones );
+  HYDROData_SplitToZonesTool::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.ObjectNames );
+    aRegion.BorderColor  = QColor( HYDROData_ImmersibleZone::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(), "Region", 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 );
   
   createPreview();
 
@@ -334,6 +279,9 @@ void HYDROGUI_CalculationOp::createPreview()
 
   if ( !myActiveViewManager )
   {
+    if ( myRegionsList.isEmpty() )
+      return;
+
     myActiveViewManager = anApp->activeViewManager();
   }
 
@@ -359,19 +307,27 @@ 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
+      QApplication::processEvents();
+      if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
+        vw->onTopView();
     }
   }
 }
@@ -383,14 +339,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;
     }
   }