Salome HOME
Minor change.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationDlg.cxx
index 4cf7eb3720f21998f060e2f604d31f3bc4ff8aa5..0de08e8a9f7be76fd084926ab93c7d75ae0a5721 100644 (file)
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_DataObject.h"
 #include "HYDROGUI_NameValidator.h"
+#include "HYDROGUI_Region.h"
+#include "HYDROGUI_Zone.h"
 
 #include <HYDROData_Document.h>
 #include <HYDROData_Entity.h>
-#include <HYDROGUI_Zone.h>
 
 #include <CAM_Application.h>
 #include <LightApp_DataObject.h>
@@ -168,10 +169,47 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
 
   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
   connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
+  connect( myBrowser, 
+      SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
+      SLOT( onZonesDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
 
   return aPage;
 }
 
+void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& theList, 
+    SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction )
+{
+  QList<SUIT_DataObject*> aZonesList;
+  HYDROGUI_Zone* aZone;
+  // Get a list of dropped 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 createRegion( aZonesList );
+    }
+    else
+    {
+      HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
+      if ( aRegion )
+      {
+        emit moveZones( theTargetParent, aZonesList );
+      }
+    }
+  }
+}
+
 void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex )
 {
   int aType = myBathymetryChoice->itemData( theIndex ).toInt();
@@ -194,9 +232,9 @@ void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
     bool prevBlock = myBathymetryChoice->blockSignals( true );
     myCurrentZone = aZone;
     myBathymetryChoice->clear();
-    myBathymetryChoice->addItem( QObject::tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN );
-    myBathymetryChoice->addItem( QObject::tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN );
-    myBathymetryChoice->addItem( QObject::tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX );
+    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->getBathymetries();
     for ( int i = 0; i < aList.length(); i++ )
     {
@@ -213,7 +251,7 @@ void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
         aCurIndex = 2;
         break;
       case HYDROData_Zone::Merge_Object:
-        aCurIndex = aList.indexOf( aZone->text( HYDROGUI_DataObject::BathymetryId ) );
+        aCurIndex = 3 + aList.indexOf( aZone->text( HYDROGUI_DataObject::BathymetryId ) );
         break;
       default:
         aCurIndex = 0; // Select unknown by default
@@ -272,13 +310,18 @@ void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_Calculatio
   HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" );
   myBrowser->setRoot(anobj);
 
-  LightApp_DataObject* aCaseItem = module()->getDataModel()->createObject( anobj,
-                                     myEditedObject, "", true );
+  module()->getDataModel()->buildCaseTree( anobj, myEditedObject );
   myBrowser->updateTree();
   myBrowser->openLevels();
+  myBrowser->adjustColumnsWidth();
 }
 
 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
 {
   return myCurrentZone;
+}
+
+void HYDROGUI_CalculationDlg::refreshZonesBrowser()
+{
+  myBrowser->updateTree();
 }
\ No newline at end of file