]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
- Zones drag and drop in the Calculation Case wizard is implemented.
authorrkv <rkv@opencascade.com>
Tue, 5 Nov 2013 08:20:15 +0000 (08:20 +0000)
committerrkv <rkv@opencascade.com>
Tue, 5 Nov 2013 08:20:15 +0000 (08:20 +0000)
- "New region" item is added in the regions tree in Calculation Case wizard.

src/HYDROGUI/HYDROGUI_CalculationDlg.cxx
src/HYDROGUI/HYDROGUI_CalculationDlg.h
src/HYDROGUI/HYDROGUI_CalculationOp.cxx
src/HYDROGUI/HYDROGUI_CalculationOp.h
src/HYDROGUI/HYDROGUI_DataModel.cxx
src/HYDROGUI/HYDROGUI_DataModel.h
src/HYDROGUI/HYDROGUI_DataObject.cxx
src/HYDROGUI/HYDROGUI_DataObject.h
src/HYDROGUI/HYDROGUI_Region.cxx
src/HYDROGUI/HYDROGUI_Region.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index c06ab638b0f0e2d3ff6480d2c4a556c44be64ae7..0de08e8a9f7be76fd084926ab93c7d75ae0a5721 100644 (file)
@@ -197,13 +197,14 @@ void HYDROGUI_CalculationDlg::onZonesDropped( const QList<SUIT_DataObject*>& the
     if ( aRegionsRoot )
     {
       // Create a new region
+      emit createRegion( aZonesList );
     }
     else
     {
       HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theTargetParent);
       if ( aRegion )
       {
-        aRegion->addZones( );
+        emit moveZones( theTargetParent, aZonesList );
       }
     }
   }
@@ -309,8 +310,7 @@ 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();
index e2791f2140a016fff88809ed9c9138cd7f81add0..627c9fe7d95cdff89d24033b60e3910481031f5f 100644 (file)
@@ -80,7 +80,9 @@ signals:
   void                       addObjects();
   void                       removeObjects();
   void                       splitZones();
-  void                       setMergeType( int theMergeType, QString theBathymetryName );
+  void                       setMergeType( int theMergeType, QString& theBathymetryName );
+  void                       createRegion( const QList<SUIT_DataObject*>& theZonesList );
+  void                       moveZones( SUIT_DataObject* theRegion, const QList<SUIT_DataObject*>& theZonesList );
 
 private:
 
index 3dab9422c0eb0fecebb2a2df68669719be3c1248..2e8744cb2b300e9d06ee424873a03c25e25d2179 100644 (file)
@@ -28,6 +28,7 @@
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_UpdateFlags.h"
 #include "HYDROGUI_Zone.h"
+#include "HYDROGUI_Region.h"
 
 #include <HYDROData_Polyline.h>
 #include <HYDROData_Iterator.h>
@@ -151,12 +152,70 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
   connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
   connect( aPanel, SIGNAL( splitZones() ), SLOT( onSplitZones() ) );
   connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
-  connect( aPanel, SIGNAL( setMergeType( int, QString ) ), SLOT( onSetMergeType( int, QString ) ) );
+  connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
+  connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
+    SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
+  connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
+    SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
 
   return aPanel;
 }
 
-void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString theBathymetryName )
+void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
+{
+  HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
+  if ( aRegion )
+  {
+    QList<HYDROGUI_Zone*> aZonesList;
+    HYDROGUI_Zone* aZone;
+    // Get a list of dropped zones
+    for ( int i = 0; i < theZonesList.length(); i++ )
+    {
+      aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
+      if ( aZone )
+      {
+        aZonesList.append( aZone );
+      }
+    }
+    if ( aZonesList.length() > 0 )
+    {
+      aRegion->addZones( aZonesList );
+      HYDROGUI_CalculationDlg* aPanel = 
+        ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+      if ( aPanel )
+      {
+        aPanel->setEditedObject(myEditedObject);
+      }
+    }
+  }
+}
+
+void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
+{
+  QList<HYDROGUI_Zone*> aZonesList;
+  HYDROGUI_Zone* aZone;
+  // Get a list of dropped zones
+  for ( int i = 0; i < theZonesList.length(); i++ )
+  {
+    aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
+    if ( aZone )
+    {
+      aZonesList.append( aZone );
+    }
+  }
+  if ( aZonesList.length() > 0 )
+  {
+    module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
+    HYDROGUI_CalculationDlg* aPanel = 
+      ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+    if ( aPanel )
+    {
+      aPanel->setEditedObject(myEditedObject);
+    }
+  }
+}
+
+void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theBathymetryName )
 {
   HYDROGUI_CalculationDlg* aPanel = 
     ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
index 729db62eb18ef1f585fe153a3fa8e3a68ac63ea2..3cf13988affa816f1adf4c57d1fd81a4d6c08db8 100644 (file)
@@ -34,6 +34,7 @@
 class SUIT_ViewManager;
 class OCCViewer_ViewManager;
 class HYDROGUI_CalculationDlg;
+class SUIT_DataObject;
 
 class HYDROGUI_CalculationOp : public HYDROGUI_Operation
 {
@@ -92,7 +93,10 @@ protected slots:
   /**
    * Set the given bathymetry merge type to the current zone.
    */
-  void                            onSetMergeType( int theMergeType, QString theBathymetryName );
+  void                            onSetMergeType( int theMergeType, QString& theBathymetryName );
+  void                            onMoveZones( SUIT_DataObject* theRegionItem, 
+                                               const QList<SUIT_DataObject*>& theZonesList );
+  void                            onCreateRegion( const QList<SUIT_DataObject*>& theZonesList );
   void                            onSplitZones();
   void                            onLastViewClosed( SUIT_ViewManager* );
 
index dbe6cead511cd96d7b0dbd2f36861e88313a27c6..b15b99ac9ff38c58b0fd8000e250f02773064fa6 100644 (file)
@@ -653,6 +653,24 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
   }
 }
 
+void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
+{
+  if ( !theCase.IsNull() )
+  {
+    new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "" );
+
+    HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions();
+    HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
+    for ( ; anIter.More(); anIter.Next() )
+    {
+      Handle(HYDROData_Region) aCaseRegion =
+        Handle(HYDROData_Region)::DownCast( anIter.Value() );
+      if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
+        createRegion( theParent, aCaseRegion, "", true );
+    }
+  }
+}
+
 void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent,
                                       SUIT_DataObject* theChild )
 {
@@ -674,3 +692,34 @@ SUIT_DataObject* HYDROGUI_DataModel::findChildByName( const SUIT_DataObject* the
   }
   return NULL; // not found
 }
+
+bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theCase, 
+                                         const QList<HYDROGUI_Zone*>& theZonesList )
+{
+  bool isOk = !theCase.IsNull();
+  if ( isOk )
+  {
+    Handle(HYDROData_Region) aRegion;
+    Handle(HYDROData_Zone) aZone;
+    for (int i = 0; i < theZonesList.length(); i++ )
+    {
+      aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() );
+      if ( !aZone.IsNull() )
+      {
+        if ( aRegion.IsNull() )
+        {
+          aRegion = theCase->AddNewRegion( aZone );
+          isOk = !aRegion.IsNull();
+        }
+        else
+        {
+          if ( !( aRegion->AddZone( aZone ) ) )
+          {
+            isOk = false;
+          }
+        }
+      }
+    }
+  }
+  return isOk;
+}
index bfc590e71b4a2d43df8b0b6ed87028ef311dbb51..060a3db56936e155a39dc47c94da2856ac9c7488 100644 (file)
 #include <HYDROData_Entity.h>
 #include <HYDROData_Zone.h>
 #include <HYDROData_Region.h>
+#include <HYDROData_CalculationCase.h>
 
 #include <QMap>
+#include <QList>
 #include <LightApp_DataModel.h>
 
 #include <SUIT_TreeModel.h>
@@ -36,6 +38,7 @@
 class CAM_DataObject;
 class SUIT_DataObject;
 class HYDROGUI_DataObject;
+class HYDROGUI_Zone;
 
 /**
  * \class HYDROGUI_DataModel
@@ -141,6 +144,11 @@ public:
    */
   CAM_DataObject* createRootModuleObject( SUIT_DataObject* theParent );
 
+  /**
+   * Create a new region in the given calculation case containing given zones. 
+   */
+  bool createNewRegion( Handle(HYDROData_CalculationCase) theCase, const QList<HYDROGUI_Zone*>& theZonesList );
+
   /**
    * Correct an internal model object according to the current document mode
    */
@@ -212,6 +220,15 @@ public:
    */
   bool paste();
 
+  /**
+   * Creates the GUI data object according to the model object.
+   * \param theParent a created object will be appended as a child of this object
+   * \param theModelObject model object
+   * \param theParentEntry entry of parent object
+   */
+  void buildCaseTree( SUIT_DataObject*                  theParent,
+                      Handle(HYDROData_CalculationCase) theCase );
+
   /**
    * Update the sequence of the objects to be copied
    */
@@ -224,6 +241,7 @@ public:
    */
   static QString partitionName( const ObjectKind theObjectKind );
 
+protected:
   /**
    * Returns the document for the current study
    */
@@ -240,7 +258,6 @@ public:
                                      const QString&           theParentEntry = QString(),
                                      const bool               theIsBuildTree = true );
 
-protected:
   /**
    * Creates the GUI data object without corresponding model object: just by name
    * \param theParent a created object will be appended as a child of this object
index b54120e1db8c83b479857063a5d3cf6496647594..532ae5f282a2c4cc69c93d2643bafe8e9a5f6526 100644 (file)
@@ -107,3 +107,11 @@ QString HYDROGUI_NamedObject::name() const
 {
   return myName;
 }
+
+HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
+                                            const QString&   theName,
+                                            const QString&   theParentEntry  )
+: HYDROGUI_NamedObject( theParent, theName, theParentEntry ), CAM_DataObject( theParent )
+{
+}
+
index c48daaa04fd8ec0647b98aa8806d65c9276d828f..a93963bd348db8ce8c59f1dc5f0493cd822f4377 100644 (file)
@@ -142,4 +142,24 @@ private:
   QString myParentEntry;
 };
 
+/**
+ * \brief Module data object, used for dropping items in the object browser.
+ *
+ * It inherits NamedObject with only difference - it accepts dropping.
+ */
+class HYDROGUI_DropTargetObject : public HYDROGUI_NamedObject
+{
+public:
+  /**
+   * Constructor.
+   * \param theParent parent data object
+   * \param theName displayed name
+   */
+  HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
+                             const QString& theName,
+                             const QString& theParentEntry  );
+    
+  bool isDropAccepted() const override { return true; }
+};
+
 #endif
index 15722904a6c296dcf89ed5e41984500eb228bd83..f9e1547b472474d08dad14cd30afdc173ae92df1 100644 (file)
@@ -37,12 +37,24 @@ HYDROGUI_Region::HYDROGUI_Region( SUIT_DataObject* theParent,
 {
 }
 
-void HYDROGUI_Region::addZones( )
+bool HYDROGUI_Region::addZones( const QList<HYDROGUI_Zone*>& theZonesList )
 {
   Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast( modelObject() );
-  if ( !aRegion.IsNull() )
+  bool isOk = !aRegion.IsNull();
+  if ( isOk )
   {
-    // TODO: Add zones
-    ;
+    Handle(HYDROData_Zone) aZone;
+    for (int i = 0; i < theZonesList.length(); i++ )
+    {
+      aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() );
+      if ( !aZone.IsNull() )
+      {
+        if ( !( aRegion->AddZone( aZone ) ) )
+        {
+          isOk = false;
+        }
+      }
+    }
   }
+  return isOk;
 }
index c5b3ac7079600e75ec78a358f4802bdcb6066441..e7fdf16df342eaaa8770277726b09d7032e5a441 100644 (file)
@@ -30,6 +30,8 @@
 #include <QString>
 #include <QColor>
 
+class HYDROGUI_Zone;
+
 /**
  * \class HYDROGUI_Region
  * \brief Browser item presenting a zone, used for object browser tree creation.
@@ -55,6 +57,6 @@ public:
   /**
    * Add zones to the region. 
    */
-  void addZones();
+  bool addZones( const QList<HYDROGUI_Zone*>& theZonesList );
 };
 #endif
index 356f537c745b159d5ec3ca51ccccaa75c749007b..85ec0921480edf7255710eaa50caff7eefae6a82 100644 (file)
@@ -72,6 +72,10 @@ does not exist or you have not enough permissions to open it.</translation>
       <source>MERGE_ZMAX</source>
       <translation>ZMAX</translation>
     </message>
+    <message>
+      <source>NEW_REGION</source>
+      <translation>&lt;New region&gt;</translation>
+    </message>
   </context>
 
   <context>