Salome HOME
lot 10 - warnings for DTM - untested
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationOp.cxx
index b06fbb3b80eb9a134167b908e68ce5089de34b51..fce39e299a316265e3e7b638849c73618952abbe 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>
 #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()
@@ -98,6 +114,13 @@ void HYDROGUI_CalculationOp::startOperation()
   QStringList anEntryList;
   HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
   getNamesAndEntries( aSeq, aList, anEntryList );
+  
+  QStringList List1;
+  QStringList EList1;
+
+  //add intersection polylines
+  AddInterPolylinesToList(aList, anEntryList);
+  
   aPanel->setAllGeomObjects( aList, anEntryList );
 
   // Get all polylines
@@ -110,18 +133,18 @@ void HYDROGUI_CalculationOp::startOperation()
   {
     aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
 
-    if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
+    if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed(false) )
     { 
-      // Check the polyline shape
-      TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
-      if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
+//      // Check the polyline shape
+//      TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
+//      if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
         aPolylineName = aPolylineObj->GetName();
         if ( !aPolylineName.isEmpty() )
         {
           aList.append( aPolylineName );
           anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
         }
-      }
+//      }
     }
   }
   aPanel->setPolylineNames( aList, anEntryList );
@@ -129,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() ) );
@@ -147,9 +171,21 @@ void HYDROGUI_CalculationOp::startOperation()
         aPanel->setBoundary( aPolylineName );
       }
 
-      aSeq = myEditedObject->GetGeometryObjects();
+      aSeq = myEditedObject->GetGeometryObjects();      
+      HYDROData_SequenceOfObjects anInterPolyList = myEditedObject->GetInterPolyObjects();
+      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 );      
@@ -171,6 +207,26 @@ void HYDROGUI_CalculationOp::startOperation()
   createPreview( false );
 }
 
+void HYDROGUI_CalculationOp::AddInterPolylinesToList(QStringList& theList, QStringList& theEntryList)
+{
+  HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
+  Handle(HYDROData_PolylineXY) aPolylineObj;
+  QString aPolylineName;
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
+    if ( !aPolylineObj.IsNull())
+    { 
+      aPolylineName = aPolylineObj->GetName();
+      if ( !aPolylineName.isEmpty() && !theList.contains(aPolylineName) )
+      {
+        theList.append( aPolylineName );
+        theEntryList.append(HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ));
+      }
+    }
+  }
+}
+
 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq, 
                                                 QStringList& theNames, QStringList& theEntries ) const
 {
@@ -208,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 ) ) );  
@@ -217,6 +273,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& ) ) );
@@ -447,7 +506,7 @@ void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem,
         ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
       if ( aPanel )
         aPanel->refreshZonesBrowser();
-      createPreview( false );
+      createPreview( false, false, false );
     }
   }
 }
@@ -462,7 +521,7 @@ void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZ
     {
       aPanel->refreshZonesBrowser();
     }
-    createPreview( false );
+    createPreview( false, false, false  );
   }
 }
 
@@ -510,6 +569,17 @@ void HYDROGUI_CalculationOp::onAddObjects()
       anAddedList.append( anObject->GetName() );
   }
 
+  for (int i = 0; i < aSelectedList.length(); i++)
+  {
+    Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast( 
+      HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
+    if ( aPoly.IsNull() )
+      continue;
+
+    if ( myEditedObject->AddInterPoly( aPoly ) )
+      anAddedList.append( aPoly->GetName() );
+  }
+
   if ( !anAddedList.isEmpty() )
   {
     aPanel->includeGeomObjects( anAddedList );
@@ -526,6 +596,13 @@ void HYDROGUI_CalculationOp::onRemoveObjects()
     return;
 
   QStringList aSelectedList = aPanel->getSelectedGeomObjects();
+
+  if (myIsComplete)
+  {
+    QSet<QString> selMap = aSelectedList.toSet();
+  }
+
+
   if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
     return;
 
@@ -540,16 +617,38 @@ void HYDROGUI_CalculationOp::onRemoveObjects()
     myEditedObject->RemoveGeometryObject( anObject );
   }
 
+  for (int i = 0; i < aSelectedList.length(); i++)
+  {
+    Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast( 
+      HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
+    if ( aPoly.IsNull() )
+      continue;
+
+    setObjectVisibility( aPoly, false );
+    myEditedObject->RemoveInterPolyObject ( aPoly ); 
+  }
+
   module()->update( UF_OCCViewer );
   aPanel->excludeGeomObjects( aSelectedList );
 }
 
 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 )
@@ -756,14 +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 && !myIsComplete)
   {
     // Land cover map panel
      HYDROGUI_CalculationDlg* aPanel = 
@@ -868,7 +971,7 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex )
     closePreview( false );
     createPreview( true );
   }
-  else if( theIndex==)
+  else if( theIndex==4 || myIsComplete)
   {
     HYDROGUI_CalculationDlg* aPanel = 
       ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
@@ -898,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 ) );
@@ -909,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();
@@ -954,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==2 )
+  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==3 )
-  {
-    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 );
+    }
   }
 }
 
@@ -1035,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 );
@@ -1047,11 +1209,15 @@ void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
     {
       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
       if ( !aCtx.IsNull() )
-      {
-        int aCounter = 0;        
+      {     
         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();
@@ -1062,9 +1228,9 @@ void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
               Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
               if ( !aZone.IsNull() )
               {
-                QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
+                QColor aFillingColor = HYDROData_Tool::GenerateRandColor();
                 while (aFillingColor == Qt::red)
-                  aFillingColor = GenerateDefaultZonesColor(++aCounter);
+                  aFillingColor = HYDROData_Tool::GenerateRandColor();
                 
                 aZone->SetColor(aFillingColor);
               }
@@ -1076,20 +1242,6 @@ void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
   }
 }
 
-QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
-                                                          float theSaturation/* = 0.5*/,
-                                                          float theValue/* = 0.95*/ ) const
-{
-  float aHue = ( rand()%1000 ) * 0.001f;
-
-  QColor aColor;
-  aColor.setHsl( (int)(aHue*255.), 128, 128 );
-  int r = aColor.red();
-  int g = aColor.green();
-  int b = aColor.blue();
-  return ( aColor.isValid() ? aColor : Qt::darkBlue );
-}
-
 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
 {
   HYDROGUI_CalculationDlg* aPanel = 
@@ -1145,7 +1297,7 @@ bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZon
   return aRetValue;
 }
 
-void HYDROGUI_CalculationOp::createPreview( const bool theLandCoverMap )
+void HYDROGUI_CalculationOp::createPreview( const bool theLandCoverMap, bool fitAllFlag, bool onTopViewAndFit )
 {
   LightApp_Application* anApp = module()->getApp();
   HYDROData_SequenceOfObjects aSeq;
@@ -1156,7 +1308,9 @@ void HYDROGUI_CalculationOp::createPreview( const bool theLandCoverMap )
   else if ( !theLandCoverMap && myShowGeomObjects )
   {
     HYDROData_SequenceOfObjects aSeqGO = myEditedObject->GetGeometryObjects();
+    HYDROData_SequenceOfObjects aSeqP = myEditedObject->GetInterPolyObjects();
     aSeq.Append( aSeqGO );
+    aSeq.Append( aSeqP );
   }
 
   Handle(HYDROData_Entity) anEntity;
@@ -1184,7 +1338,8 @@ void HYDROGUI_CalculationOp::createPreview( const bool theLandCoverMap )
   }
 
   // Get a boundary polyline if any
-  aSeq.Append( myEditedObject->GetBoundaryPolyline() );
+  if (Handle(HYDROData_PolylineXY) aBPoly = myEditedObject->GetBoundaryPolyline())
+    aSeq.Append( aBPoly );
 
   module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
 
@@ -1221,16 +1376,23 @@ void HYDROGUI_CalculationOp::createPreview( const bool theLandCoverMap )
       HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
       for ( ; anIter.More(); anIter.Next() )
       {
-        setObjectVisibility( anIter.Value(), true );
+        const Handle(HYDROData_Entity)& ent = anIter.Value();
+        if (!ent.IsNull())
+          setObjectVisibility( ent, true );
       }
 
       //Process the draw events for viewer
       QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
-      if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
-        vw->onTopView();
     }
 
-    module()->update( UF_OCCViewer | UF_FitAll );
+    int UpdateFlags = UF_OCCViewer;
+    if (fitAllFlag)
+      UpdateFlags |= UF_FitAll;
+    module()->update( UpdateFlags );
+
+    OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView();
+    if ( onTopViewAndFit && vw )
+      vw->onTopView();
   }
 }
 
@@ -1313,11 +1475,11 @@ void HYDROGUI_CalculationOp::setAvailableGroups()
   HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
   for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
   {
-    Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
+    Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anObjs.Value( anIndex ) );
     HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
     for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
     {
-      Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
+      Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( aGIndex ) );
       aGroupsNames.append( aGroup->GetName() );
     }
   }
@@ -1392,6 +1554,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 =