Salome HOME
refs #640: correct width for non-georeferenced profile
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationDlg.cxx
index c727437116b6f305cd9fafe62842a94a5fec6ce5..6a6e60f09f9c528f7577d344bce32d3d729da412 100644 (file)
@@ -245,6 +245,8 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
 
   connect( myGeomObjects, SIGNAL( orderChanged() ), SLOT( onOrderChanged() ) );
 
+  connect( myPriorityWidget, SIGNAL( ruleChanged() ), SLOT( onRuleChanged() ) );
+
   return aPage;
 }
 
@@ -443,7 +445,9 @@ QWizardPage* HYDROGUI_CalculationDlg::createLandCoversPage() {
   connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addLandCovers() ) );
   connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeLandCovers() ) );
 
-  connect( myLandCovers, SIGNAL( orderLandCoverChanged() ), SLOT( onOrderLandCoverChanged() ) );
+  connect( myLandCovers, SIGNAL( orderChanged() ), SLOT( onOrderLandCoverChanged() ) );
+
+  connect( myLandCoverPriorityWidget, SIGNAL( ruleChanged() ), SLOT( onLandCoverRuleChanged() ) );
 
   return aPage;
 }
@@ -453,13 +457,16 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
   QFrame* aFrame = new QFrame( aPage );
 
   QGridLayout* aLayout = new QGridLayout( aPage );
+
+  QLabel* aResultsOnGeomObjectsLabel = new QLabel( tr( "RESULTS_ON_GEOMETRY_OBJECTS" ), aFrame );
   
   myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
   myBrowser->setAutoOpenLevel( 3 );
   aLayout->setMargin( 5 );
   aLayout->setSpacing( 5 );
 
-  aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
+  aLayout->addWidget( aResultsOnGeomObjectsLabel, 0, 0 );
+  aLayout->addWidget( myBrowser, 1, 0, 1, 2 );
 
   myBathymetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
   myBathymetryChoice = new QComboBox( aFrame );
@@ -467,8 +474,11 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
   myBathymetryChoice->setVisible( false );
   myBathymetryLabel->setVisible( false );
 
-  aLayout->addWidget( myBathymetryLabel, 1, 0 );
-  aLayout->addWidget( myBathymetryChoice, 1, 1 );
+  aLayout->addWidget( myBathymetryLabel, 2, 0 );
+  aLayout->addWidget( myBathymetryChoice, 2, 1 );
+
+  QPushButton* aRegenerateBtn = new QPushButton( tr( "REGENERATE_COLORS" ), this );
+  aLayout->addWidget( aRegenerateBtn, 3, 0 );
 
   aPage->setLayout( aLayout );
 
@@ -480,7 +490,7 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
       SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
   connect( myBrowser, SIGNAL( newRegion() ), this, SLOT( OnNewRegion() ) );
-
+  connect( aRegenerateBtn, SIGNAL( clicked() ), this, SIGNAL( regenerateColors() ) );
   return aPage;
 }
 
@@ -490,12 +500,15 @@ QWizardPage* HYDROGUI_CalculationDlg::createLandCoverZonesPage() {
 
   QGridLayout* aLayout = new QGridLayout( aPage );
   
-  myLandCoverBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
+  QLabel* aResultsOnLandCoversLabel = new QLabel( tr( "RESULTS_ON_LAND_COVERS" ), aFrame );
+
+  myLandCoverBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage, true );
   myLandCoverBrowser->setAutoOpenLevel( 3 );
   aLayout->setMargin( 5 );
   aLayout->setSpacing( 5 );
 
-  aLayout->addWidget( myLandCoverBrowser, 0, 0, 1, 2 );
+  aLayout->addWidget( aResultsOnLandCoversLabel, 0, 0 );
+  aLayout->addWidget( myLandCoverBrowser, 1, 0, 1, 2 );
 
   myStricklerTypeLabel = new QLabel( tr( "STRICKLER_TYPE" ), aFrame );
   myStricklerTypeChoice = new QComboBox( aFrame );
@@ -503,8 +516,8 @@ QWizardPage* HYDROGUI_CalculationDlg::createLandCoverZonesPage() {
   myStricklerTypeLabel->setVisible( false );
   myStricklerTypeChoice->setVisible( false );  
 
-  aLayout->addWidget( myBathymetryLabel, 1, 0 );
-  aLayout->addWidget( myBathymetryChoice, 1, 1 );
+  aLayout->addWidget( myStricklerTypeLabel, 2, 0 );
+  aLayout->addWidget( myStricklerTypeChoice, 2, 1 );
 
   aPage->setLayout( aLayout );
 
@@ -585,7 +598,7 @@ void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& the
       HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
       if ( aRegion )
       {
-        emit moveZones( theTargetParent, aZonesList );
+        emit moveZones( theTargetParent, aZonesList, false );
       }
     }
   }
@@ -626,7 +639,7 @@ void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
     myBathymetryChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
     myBathymetryChoice->addItem( tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
     myBathymetryChoice->addItem( tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
-    QStringList aList = aZone->getAltitudes();
+    QStringList aList = aZone->getObjects();
     for ( int i = 0; i < aList.length(); i++ )
     {
       myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
@@ -658,18 +671,83 @@ void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
 
 void HYDROGUI_CalculationDlg::onLandCoverZoneSelected( SUIT_DataObject* theObject )
 {
-  // TODO: implement this function
+  bool doShow = false;
+  HYDROGUI_Zone* aZone = dynamic_cast<HYDROGUI_Zone*>( theObject );
+  if ( aZone )
+  {
+    doShow = aZone->isMergingNeed();
+  }
+
+  if ( doShow )
+  {
+    // Fill the merge type combo box
+    bool prevBlock = myStricklerTypeChoice->blockSignals( true );
+    myCurrentZone = aZone;
+    myStricklerTypeChoice->clear();
+    myStricklerTypeChoice->addItem( tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
+    QStringList aList = aZone->getObjects();
+    for ( int i = 0; i < aList.length(); i++ )
+    {
+      myStricklerTypeChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object );
+    }
+    // Select the current choice if any
+    int aCurIndex = 0;
+    switch ( aZone->getMergeType() )
+    {
+      case HYDROData_Zone::Merge_Object:
+        aCurIndex = 1 + aList.indexOf( aZone->text( HYDROGUI_DataObject::AltitudeObjId ) );
+        break;
+      default:
+        aCurIndex = 0; // Select unknown by default
+    }
+    myStricklerTypeChoice->setCurrentIndex( aCurIndex );
+    myStricklerTypeChoice->blockSignals( prevBlock );
+  }
+
+  myStricklerTypeChoice->setVisible( doShow );
+  myStricklerTypeChoice->setEnabled( getLandCoverMode() == HYDROData_CalculationCase::MANUAL );
+  myStricklerTypeLabel->setVisible( doShow );
 }
 
 void HYDROGUI_CalculationDlg::onMergeStricklerTypeSelected( int theIndex )
 {
-  // TODO: implement this function
+  int aType = myStricklerTypeChoice->itemData( theIndex ).toInt();
+  QString aText = myStricklerTypeChoice->itemText( theIndex );
+  emit setMergeStricklerType( aType, aText );
 }
 
 void HYDROGUI_CalculationDlg::onLandCoverZonesDropped( const QList<SUIT_DataObject*>& theList, 
     SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
 {
-  // TODO: implement this function
+  QList<SUIT_DataObject*> aZonesList;
+  HYDROGUI_Zone* aZone;
+  // Get a list of dropped land cover zones
+  for ( int i = 0; i < theList.length(); i++ )
+  {
+    aZone = dynamic_cast<HYDROGUI_Zone*>( theList.at( i ) );
+    if ( aZone )
+    {
+      aZonesList.append( aZone );
+    }
+  }
+  if ( aZonesList.length() > 0 )
+  {
+    // Get the target region
+    HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast<HYDROGUI_NamedObject*>(theTargetParent);
+    if ( aRegionsRoot )
+    {
+      // Create a new region
+      emit createLandCoverRegion( aZonesList );
+    }
+    else
+    {
+      HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
+      if ( aRegion )
+      {
+        emit moveZones( theTargetParent, aZonesList, true );
+      }
+    }
+  }
 }
 
 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
@@ -842,13 +920,22 @@ void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_Calculatio
   myValidator->setEditedObject( theCase );
 
   // Build the calculation case subtree
-  module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject );
+  module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject, false );
 
   myBrowser->updateTree();
   myBrowser->openLevels();
   myBrowser->adjustColumnsWidth();
   myBrowser->setAutoUpdate( true );
   myBrowser->setUpdateModified( true );
+
+  // Build the calculation case subtree for Land Cover regions
+  module()->getDataModel()->buildCaseTree( myLandCoverBrowser->root(), myEditedObject, true );
+
+  myLandCoverBrowser->updateTree();
+  myLandCoverBrowser->openLevels();
+  myLandCoverBrowser->adjustColumnsWidth();
+  myLandCoverBrowser->setAutoUpdate( true );
+  myLandCoverBrowser->setUpdateModified( true );
 }
 
 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
@@ -860,14 +947,14 @@ void HYDROGUI_CalculationDlg::refreshZonesBrowser()
 {
   SUIT_DataObject* aRoot = myBrowser->root();
   module()->getDataModel()->updateObjectTree( myEditedObject );
-  module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
+  module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, false );
   myBrowser->updateTree( aRoot );
 }
 
 void HYDROGUI_CalculationDlg::onDataChanged()
 {
   SUIT_DataObject* aRoot = myBrowser->root();
-  module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
+  module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, false );
   myBrowser->updateTree( aRoot );
 }
 
@@ -968,7 +1055,7 @@ void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
   Enable/disable land covers drag'n'drop and renaming.
   @param theIsEnabled if true - land covers drag'n'drop and renaming will be enabled
 */
-void HYDROGUI_CalculationDlg::setEditLandCoversEnabled( const bool theIsEnabled )
+void HYDROGUI_CalculationDlg::setEditLandCoverZonesEnabled( const bool theIsEnabled )
 {
   myLandCoverBrowser->setReadOnly( !theIsEnabled );
 }
@@ -1064,6 +1151,17 @@ void HYDROGUI_CalculationDlg::onOrderChanged()
     myGeomObjects->undoLastMove();
 }
 
+/**
+  Slot called when priority rule for geometry objects is changed.
+ */
+void HYDROGUI_CalculationDlg::onRuleChanged()
+{
+  bool isConfirmed = true;
+  emit ruleChanged( isConfirmed );
+  if( !isConfirmed )
+    myPriorityWidget->undoLastChange();
+}
+
 void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName, bool theBlockSignals )
 {
   bool isBlocked;
@@ -1124,7 +1222,7 @@ void HYDROGUI_CalculationDlg::refreshLandCoverZonesBrowser()
 {
   SUIT_DataObject* aRoot = myLandCoverBrowser->root();
   module()->getDataModel()->updateObjectTree( myEditedObject );
-  module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
+  module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, true );
   myLandCoverBrowser->updateTree( aRoot );
 }
 
@@ -1134,7 +1232,7 @@ void HYDROGUI_CalculationDlg::refreshLandCoverZonesBrowser()
 void HYDROGUI_CalculationDlg::onDataLandCoverChanged()
 {
   SUIT_DataObject* aRoot = myLandCoverBrowser->root();
-  module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
+  module()->getDataModel()->buildCaseTree( aRoot, myEditedObject, true );
   myLandCoverBrowser->updateTree( aRoot );
 }
 
@@ -1150,3 +1248,14 @@ void HYDROGUI_CalculationDlg::onOrderLandCoverChanged()
   else
     myLandCovers->undoLastMove();  
 }
+
+/**
+  Slot called when priority rule for land covers is changed.
+ */
+void HYDROGUI_CalculationDlg::onLandCoverRuleChanged()
+{
+  bool isConfirmed = true;
+  emit ruleLandCoverChanged( isConfirmed );
+  if( !isConfirmed )
+    myLandCoverPriorityWidget->undoLastChange();
+}