Salome HOME
refs #1813 ... lot 14 combined commit : parts : 1 - 16
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationOp.cxx
index 092c97bf3020a24ad6a666be08e2a891e18542d2..739df20fcb81f4ce75dc5bf11039f2ffe6a6844a 100644 (file)
@@ -33,6 +33,7 @@
 #include <HYDROData_Object.h>
 #include <HYDROData_Tool.h>
 #include <HYDROData_StricklerTable.h>
+#include <HYDROData_BCPolygon.h>
 
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
@@ -247,6 +248,9 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
   connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
   connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
 
+  connect( aPanel, SIGNAL( addBoundaryPolygons() ), SLOT( onAddBoundaryPolygons() ) );
+  connect( aPanel, SIGNAL( removeBoundaryPolygons() ), SLOT( onRemoveBoundaryPolygons() ) );
+
   connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
 
   connect( aPanel, SIGNAL( ruleChanged( bool& ) ), SLOT( onRuleChanged( bool& ) ) );
@@ -816,6 +820,10 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex )
     setAvailableGroups();
   }
   else if( theIndex==2 )
+  {
+    setAvailableBoundaryPolygons();
+  }
+  else if( theIndex==3 )
   {
     // Land cover map panel
      HYDROGUI_CalculationDlg* aPanel = 
@@ -920,7 +928,7 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex )
     closePreview( false );
     createPreview( true );
   }
-  else if( theIndex==3 )
+  else if( theIndex==4 )
   {
     HYDROGUI_CalculationDlg* aPanel = 
       ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
@@ -1013,7 +1021,7 @@ void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
     closePreview( false );
     createPreview( false );
   }
-  if( theIndex==2 )
+  if( theIndex==3 )
   {
     setLandCoverMapVisible( true );
 
@@ -1023,7 +1031,7 @@ void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
     // Hide zones
     setZonesVisible( false );
   }
-  else if( theIndex==3 )
+  else if( theIndex==4 )
   {
     AssignDefaultZonesColors();
 
@@ -1439,6 +1447,110 @@ void HYDROGUI_CalculationOp::onRemoveGroups()
   aPanel->excludeGroups( aSelectedList );
 }
 
+
+void HYDROGUI_CalculationOp::setAvailableBoundaryPolygons()
+{
+  HYDROGUI_CalculationDlg* aPanel = ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+
+  HYDROData_Iterator anIter( doc(), KIND_BC_POLYGON );
+  Handle(HYDROData_BCPolygon) aBCP;
+  QStringList aNames;
+  QVector<int> aTypes; 
+  for (;anIter.More(); anIter.Next())
+  {
+    aBCP = Handle(HYDROData_BCPolygon)::DownCast( anIter.Current() );
+    aNames.append(aBCP->GetName());
+    aTypes.append(aBCP->GetBoundaryType());
+  }
+  HYDROData_SequenceOfObjects aBCPSeq = myEditedObject->GetBoundaryPolygons();
+
+  QStringList aListCut, aListIS;
+  for (int i=1; i<=aBCPSeq.Size();i++)
+  {
+    int type = Handle(HYDROData_BCPolygon)::DownCast(aBCPSeq(i))->GetBoundaryType();
+    if (type == 1)
+      aListCut << aBCPSeq(i)->GetName();
+    else if (type == 2 || type == 3)
+      aListIS << aBCPSeq(i)->GetName();
+  }
+
+  aPanel->setAvailableBoundaryPolygons( aNames, aTypes );
+  aPanel->includeBoundaryPolygons( aListCut );
+  aPanel->includeISBoundaryPolygons( aListIS );
+}
+
+void HYDROGUI_CalculationOp::onRemoveBoundaryPolygons()
+{
+  HYDROGUI_CalculationDlg* aPanel = 
+    ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+  if ( !aPanel )
+    return;
+
+  QStringList aSelectedListCut = aPanel->getSelectedBoundaryPolygons();
+  QStringList aSelectedListIS = aPanel->getSelectedISBoundaryPolygons();
+
+  if ( aSelectedListCut.isEmpty() && aSelectedListIS.isEmpty() )
+    return;
+
+  for (int i = 0; i < aSelectedListCut.length(); i++)
+  {
+    Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( 
+      HYDROGUI_Tool::FindObjectByName( module(), aSelectedListCut.at(i) ) );
+    if ( aBCPoly.IsNull() )
+      continue;
+    myEditedObject->RemoveBoundaryPolygon( aBCPoly );
+  }
+
+  for (int i = 0; i < aSelectedListIS.length(); i++)
+  {
+    Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( 
+      HYDROGUI_Tool::FindObjectByName( module(), aSelectedListIS.at(i) ) );
+    if ( aBCPoly.IsNull() )
+      continue;
+    myEditedObject->RemoveBoundaryPolygon( aBCPoly );
+  }
+
+  aPanel->excludeBoundaryPolygons( aSelectedListCut );
+  aPanel->excludeISBoundaryPolygons( aSelectedListIS );
+}
+
+void HYDROGUI_CalculationOp::onAddBoundaryPolygons()
+{
+  HYDROGUI_CalculationDlg* aPanel = ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+  if ( !aPanel )
+    return;
+
+  QStringList aSelectedList = aPanel->getSelectedAvailableBoundaryPolygons();
+  if ( aSelectedList.isEmpty())
+    return;
+
+  QStringList anAddedListCut, anAddedListIS;
+  for (int i = 0; i < aSelectedList.length(); i++)
+  {
+    Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( 
+      HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
+    if ( aBCPoly.IsNull() )
+      continue;
+   
+   if ( myEditedObject->AddBoundaryPolygon( aBCPoly ) )
+   {
+     QString aName = aBCPoly->GetName();
+     int type = aBCPoly->GetBoundaryType(); 
+     if (type == 1)
+       anAddedListCut.append(aName);
+     else if (type == 2 || type == 3)
+       anAddedListIS.append(aName);
+   }
+
+  }
+
+  if ( !anAddedListCut.isEmpty() )
+    aPanel->includeBoundaryPolygons(anAddedListCut);
+  if ( !anAddedListIS.isEmpty() )
+    aPanel->includeISBoundaryPolygons(anAddedListIS);
+}
+
 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
 {
   HYDROGUI_CalculationDlg* aPanel =