Salome HOME
lot 10 - warnings for DTM - untested
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationOp.cxx
index 739df20fcb81f4ce75dc5bf11039f2ffe6a6844a..fce39e299a316265e3e7b638849c73618952abbe 100644 (file)
 #include <QApplication>
 #include <QKeySequence>
 #include <QShortcut>
+#include <QPushButton>
+#include <BRep_Builder.hxx>
+#include <TopoDS.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopExp.hxx>
+#include <TopoDS.hxx>
 
-HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
+#include <HYDROData_CompleteCalcCase.h>
+
+
+HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit, bool IsComplete )
 : HYDROGUI_Operation( theModule ),
   myIsEdit( theIsEdit ),
   myActiveViewManager( NULL ),
   myPreviewViewManager( NULL ),
   myShowGeomObjects( true ),
   myShowLandCoverMap( false ),
-  myShowZones( false )
+  myShowZones( false ),
+  myIsComplete (IsComplete)
 {
-  setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
+  QString aDlgName;
+  if (myIsComplete)
+    aDlgName =  tr( "COMPLETE_CALCULATION" );
+  else
+    aDlgName = myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" );
+  setName( aDlgName );
 }
 
 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
@@ -137,6 +152,7 @@ void HYDROGUI_CalculationOp::startOperation()
   QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
 
   myEditedObject.Nullify();
+
   if ( myIsEdit )
   {
     myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
@@ -160,7 +176,16 @@ void HYDROGUI_CalculationOp::startOperation()
       aSeq.Append(anInterPolyList);
 
       getNamesAndEntries( aSeq, aList, anEntryList );
-      aPanel->includeGeomObjects( aList );
+      if (!myIsComplete)
+        aPanel->includeGeomObjects( aList );
+      else 
+      {
+        //aPanel->includeGeomObjects( aList );
+        aPanel->setAlreadyAddedGeomObjects( aList );
+        //myIncObjAtStart = aSeq;
+        aPanel->hideAvailableGeomObjects( aList );
+        aPanel->setGeomOrderingEnabled(true);
+      }
 
       // set rules
       setRules( HYDROData_CalculationCase::DataTag_CustomRules );      
@@ -239,7 +264,7 @@ void HYDROGUI_CalculationOp::commitOperation()
 
 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
 {
-  HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
+  HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName(), myIsComplete );
 
   // Connect signals and slots
   connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );  
@@ -571,6 +596,13 @@ void HYDROGUI_CalculationOp::onRemoveObjects()
     return;
 
   QStringList aSelectedList = aPanel->getSelectedGeomObjects();
+
+  if (myIsComplete)
+  {
+    QSet<QString> selMap = aSelectedList.toSet();
+  }
+
+
   if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
     return;
 
@@ -602,10 +634,21 @@ void HYDROGUI_CalculationOp::onRemoveObjects()
 
 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
 {
+
   // Check if the case is already modified or not
   bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
+
   if ( !isConfirmed )
   {
+  
+   if (myIsComplete)
+   {
+     //SUIT_MessageBox::information(module()->getApp()->desktop(),
+     //                         tr( "REGIONS_CHANGED" ),
+     //                         tr( "COMPLETE_OP_WILL_BE_PERFORMED" ));
+     return true;
+   }
+
     // If not modified check if the case has already defined regions with zones
     HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
     if ( aSeq.Length() > 0 )
@@ -812,18 +855,18 @@ void HYDROGUI_CalculationOp::onApply()
                                aMsg ); 
   }
 }
-
+#include <HYDROData_CompleteCalcCase.h>
 void HYDROGUI_CalculationOp::onNext( const int theIndex )
 {
-  if( theIndex==1 )
+  if( theIndex==1 && !myIsComplete)
   {
     setAvailableGroups();
   }
-  else if( theIndex==2 )
+  else if( theIndex==2 && !myIsComplete)
   {
     setAvailableBoundaryPolygons();
   }
-  else if( theIndex==3 )
+  else if( theIndex==3 && !myIsComplete)
   {
     // Land cover map panel
      HYDROGUI_CalculationDlg* aPanel = 
@@ -928,7 +971,7 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex )
     closePreview( false );
     createPreview( true );
   }
-  else if( theIndex==4 )
+  else if( theIndex==4 || myIsComplete)
   {
     HYDROGUI_CalculationDlg* aPanel = 
       ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
@@ -958,7 +1001,11 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex )
       if( myEditedObject->IsMustBeUpdated(  HYDROData_Entity::Geom_2d ) )
       {
         myEditedObject->RemoveGeometryObjects();
-        foreach ( const QString& aName, aPanel->getAllGeomObjects() )
+        QStringList aGeomObjNames;
+        if (myIsComplete) //erase objects ?
+          aGeomObjNames << aPanel->getAlreadyAddedGeomObjects();
+        aGeomObjNames << aPanel->getAllGeomObjects();
+        foreach ( const QString& aName, aGeomObjNames )
         {
           Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast( 
             HYDROGUI_Tool::FindObjectByName( module(), aName ) );
@@ -969,26 +1016,65 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex )
           myEditedObject->AddGeometryObject( anObject );
         }
 
-        // Clear priority rules
-        //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
+        if (!myIsComplete)
+        {
+          // Clear priority rules
+          //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
           myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
-        //@ASL }
-        // Set priority rules
-        foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
-          myEditedObject->AddRule( aRule.Object1, aRule.Priority,
-                                  aRule.Object2, aRule.MergeType,
-                                  HYDROData_CalculationCase::DataTag_CustomRules );
+          //@ASL }
+          // Set priority rules
+          foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
+            myEditedObject->AddRule( aRule.Object1, aRule.Priority,
+              aRule.Object2, aRule.MergeType,
+              HYDROData_CalculationCase::DataTag_CustomRules );
+          }
         }
       }
     }
     aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
 
+    if (myIsComplete)
+      aPanel->BackButton()->setEnabled(false); //force disable; to prevent moving to the first page
+
     if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
     {
       myShowZones = true;
-      myEditedObject->Update();
       
-      AssignDefaultZonesColors();
+      if (myIsComplete)
+      {
+        //abortDocOperation();
+        //module()->getApp()->updateObjectBrowser();
+        QList<Handle(HYDROData_Entity)> newGeomObj = aPanel->getGeometryObjects(false);
+        //QSet<Handle(HYDROData_Entity)> includedObjAtStartSet = myIncObjAtStart.toSet();
+        NCollection_Sequence<Handle(HYDROData_Entity)> theNewObjects;
+        foreach (Handle(HYDROData_Entity) obj, newGeomObj)
+          theNewObjects.Append(obj);
+
+
+        bool is_int = false;
+        bool UseOrigNamingOfNewRegions = true;
+        NCollection_Sequence<Handle(HYDROData_Region)> theNewRegions;
+        QSet<QString> newRegionEntries;
+        HYDROData_CompleteCalcCase::AddObjects(doc(), myEditedObject, theNewObjects, UseOrigNamingOfNewRegions, is_int, theNewRegions);
+        if (is_int)        
+          SUIT_MessageBox::information(module()->getApp()->desktop(),
+          tr( "COMPLETE_CASE" ),
+          tr( "There is an intersection(s) between new objects. result will be depend on order" ));
+
+        myEditedObject->ClearChanged();
+        for (int k=1;k<=theNewRegions.Size();k++)
+        {
+          QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theNewRegions(k) );
+          newRegionEntries.insert(anEntry);
+        }
+        AssignDefaultZonesColors(&newRegionEntries);
+      }
+      else
+      {
+        myEditedObject->Update();
+        AssignDefaultZonesColors(NULL);
+      }
+      
 
       //aPanel->setEditedObject( myEditedObject );
       aPanel->refreshZonesBrowser();
@@ -1014,32 +1100,48 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex )
 
 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
 {
-  if( theIndex==1 )
+  if (myIsComplete)
   {
-    setGeomObjectsVisible( true );
-
-    closePreview( false );
-    createPreview( false );
+    //theIndex == 0
+  //  setGeomObjectsVisible( true );
+  // // HYDROGUI_CalculationDlg* aPanel = ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+  // // QList<Handle(HYDROData_Entity)> geomObjList =  aPanel->getGeometryObjects(false);
+  // // foreach ( Handle(HYDROData_Entity) geomObj, geomObjList)
+  // //   setObjectVisibility( geomObj, true );
+  //
+  //  setZonesVisible( false );
+  //  closePreview( false );
+  //  createPreview( false );
   }
-  if( theIndex==3 )
+  else
   {
-    setLandCoverMapVisible( true );
+    if( theIndex==1 )
+    {
+      setGeomObjectsVisible( true );
 
-    closePreview( false );
-    createPreview( true );
+      closePreview( false );
+      createPreview( false );
+    }
+    if( theIndex==3 )
+    {
+      setLandCoverMapVisible( true );
 
-    // Hide zones
-    setZonesVisible( false );
-  }
-  else if( theIndex==4 )
-  {
-    AssignDefaultZonesColors();
+      closePreview( false );
+      createPreview( true );
 
-    closePreview( false );
-    createPreview( false );
+      // Hide zones
+      setZonesVisible( false );
+    }
+    else if( theIndex==4 )
+    {
+      AssignDefaultZonesColors();
+
+      closePreview( false );
+      createPreview( false );
 
-    // Show zones
-    setZonesVisible( true );
+      // Show zones
+      setZonesVisible( true );
+    }
   }
 }
 
@@ -1095,7 +1197,7 @@ void HYDROGUI_CalculationOp::setLandCoverMapVisible( bool theIsVisible )
   setObjectVisibility( myEditedObject->GetLandCoverMap(), theIsVisible );  
 }
 
-void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
+void HYDROGUI_CalculationOp::AssignDefaultZonesColors(const QSet<QString>* theRegionsEntriesToColored)
 {
   HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
   HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
@@ -1111,6 +1213,11 @@ void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
         for ( ; aRegionsIter.More(); aRegionsIter.Next() )
         {
           aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
+          QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aRegion );
+
+          if (theRegionsEntriesToColored && !theRegionsEntriesToColored->contains(anEntry))
+            continue;
+
           if ( !aRegion.IsNull() )
           {
             aZones = aRegion->GetZones();