]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Feature #103: Names of Regions:
authorrkv <rkv@opencascade.com>
Fri, 13 Dec 2013 09:02:17 +0000 (09:02 +0000)
committerrkv <rkv@opencascade.com>
Fri, 13 Dec 2013 09:02:17 +0000 (09:02 +0000)
- It is now possible to rename objects by F2 in Calculation dialog;
- Main module's object browser is synchronyzed with calculation dialog browser.

15 files changed:
src/HYDROGUI/HYDROGUI_CalculationDlg.cxx
src/HYDROGUI/HYDROGUI_CalculationDlg.h
src/HYDROGUI/HYDROGUI_CalculationOp.cxx
src/HYDROGUI/HYDROGUI_CalculationOp.h
src/HYDROGUI/HYDROGUI_DataBrowser.cxx
src/HYDROGUI/HYDROGUI_DataBrowser.h
src/HYDROGUI/HYDROGUI_DataModel.cxx
src/HYDROGUI/HYDROGUI_DataModel.h
src/HYDROGUI/HYDROGUI_DataObject.cxx
src/HYDROGUI/HYDROGUI_DataObject.h
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_Region.cxx
src/HYDROGUI/HYDROGUI_Region.h
src/HYDROGUI/HYDROGUI_Zone.cxx
src/HYDROGUI/HYDROGUI_Zone.h

index 5d39423bb634636b4b64654d6e34e9ffeaeb51fa..322fc12392efe8c04cd0d9f34b662aad65d01670 100644 (file)
@@ -168,7 +168,7 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
 
   QGridLayout* aLayout = new QGridLayout( aPage );
   
-  myBrowser = new HYDROGUI_DataBrowser( module(), 0, aPage );
+  myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage );
   myBrowser->setAutoOpenLevel( 3 );
   aLayout->setMargin( 5 );
   aLayout->setSpacing( 5 );
@@ -186,6 +186,7 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
 
   aPage->setLayout( aLayout );
 
+  connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) );
   connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
   connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) );
@@ -430,13 +431,15 @@ void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_Calculatio
   myEditedObject = theCase;
   myValidator->setEditedObject( theCase );
 
-  HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" );
-  myBrowser->setRoot(anobj);
+  // Build the calculation case subtree
+  module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject );
 
-  module()->getDataModel()->buildCaseTree( anobj, myEditedObject );
   myBrowser->updateTree();
   myBrowser->openLevels();
   myBrowser->adjustColumnsWidth();
+  myBrowser->setAutoUpdate( true );
+  myBrowser->setUpdateModified( true );
+
 }
 
 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
@@ -446,5 +449,15 @@ HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
 
 void HYDROGUI_CalculationDlg::refreshZonesBrowser()
 {
-  myBrowser->updateTree();
+  SUIT_DataObject* aRoot = myBrowser->root();
+  module()->getDataModel()->updateObjectTree( myEditedObject );
+  module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
+  myBrowser->updateTree( aRoot );
+}
+
+void HYDROGUI_CalculationDlg::onDataChanged()
+{
+  SUIT_DataObject* aRoot = myBrowser->root();
+  module()->getDataModel()->buildCaseTree( aRoot, myEditedObject );
+  myBrowser->updateTree( aRoot );
 }
\ No newline at end of file
index 7178207fc7d19c3c64c00b29cec4fc672c404b04..43770dc28722b39a09f254d4d925e361dc19e66d 100644 (file)
@@ -66,6 +66,7 @@ public slots:
   void                       onEmptyName();
   void                       onAlreadyExists( QString theName );
   void                       refreshZonesBrowser();
+  void                       onDataChanged();
   /**
    * Process items selection: hide/show bathymetry merge type selector.
    */
index ad69b40c86fe7ae1690bb09178491878e8bc245a..2dabc9fa9714a77fdf10a696578d8754300225c3 100644 (file)
 
 #include <SUIT_MessageBox.h>
 #include <SUIT_Desktop.h>
+#include <SUIT_DataBrowser.h>
 
 #include <QApplication>
+#include <QKeySequence>
+#include <QShortcut>
 
 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
 : HYDROGUI_Operation( theModule ),
@@ -75,6 +78,20 @@ void HYDROGUI_CalculationOp::startOperation()
   if ( !aPanel )
     return;
 
+  SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
+  QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
+  QShortcut* aShortcut;
+  foreach( aShortcut, aShortcuts )
+  {
+    if ( aShortcut->key() == 
+      QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey( 
+      SUIT_DataBrowser::RenameShortcut ) ) )
+    {
+      aShortcut->setEnabled( false );
+    }
+  }
+
+
   aPanel->reset();
   QStringList aList;
   QStringList anEntryList;
@@ -169,6 +186,7 @@ void HYDROGUI_CalculationOp::abortOperation()
   // Abort transaction
   abortDocOperation();
   HYDROGUI_Operation::abortOperation();
+  module()->getApp()->updateObjectBrowser();
 }
 
 void HYDROGUI_CalculationOp::commitOperation()
@@ -188,7 +206,7 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
   connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
   connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onSplitZones() ) );
   connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) );
-  connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
+  //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
   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*>& ) ) );
@@ -344,7 +362,7 @@ void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const
         ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
       if ( aPanel )
       {
-        aPanel->setEditedObject(myEditedObject);
+        aPanel->refreshZonesBrowser();
       }
       createPreview();
     }
@@ -371,7 +389,7 @@ void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZ
       ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
     if ( aPanel )
     {
-      aPanel->setEditedObject(myEditedObject);
+      aPanel->refreshZonesBrowser();
     }
     createPreview();
   }
@@ -558,7 +576,8 @@ void HYDROGUI_CalculationOp::onSplitZones()
     myShowZones = true;
     myEditedObject->Update();
 
-    aPanel->setEditedObject( myEditedObject );
+    //aPanel->setEditedObject( myEditedObject );
+    aPanel->refreshZonesBrowser();
 
     createPreview();
   }
@@ -719,6 +738,20 @@ void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager
 
 void HYDROGUI_CalculationOp::closePreview()
 {
+  SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
+  QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
+  QShortcut* aShortcut;
+  foreach( aShortcut, aShortcuts )
+  {
+    if ( aShortcut->key() == 
+      QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey( 
+      SUIT_DataBrowser::RenameShortcut ) ) )
+    {
+      aShortcut->setEnabled( true );
+    }
+  }
+
+
   if( myPreviewViewManager )
   {
     disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
index bf449bde2826ab0514c550fa7f69fe3ccdd41ba2..1ede7ff639838b5b6a25b44ea29e029526590e15 100644 (file)
@@ -105,6 +105,7 @@ private:
   void                            setZonesVisible( bool theIsVisible );
   void                            getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq, 
                                                 QStringList& theNames, QStringList& theEntries ) const;
+
   /**
    * Ask user to confirm splitting zones recalculation.
    * \return true if confirmed
index f4cc73c2b0ad64f157d411c65e972e741280dd89..714d2a16ae949234dda03e9322270d4436901149 100644 (file)
@@ -42,8 +42,15 @@ HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_Dat
 {
   SUIT_ResourceMgr* resMgr = theModule->getApp()->resourceMgr();
 
+  if ( ( !theRoot ) && theModule )
+  {
+    // Initialize the root with the module data model
+    setRoot( new CAM_ModuleObject( theModule->dataModel(), NULL ) );
+  }
+
   setSortMenuEnabled( true );
   setAutoUpdate( true );
+  setUpdateModified( true );
 
   if ( resMgr->hasValue( "ObjectBrowser", "auto_hide_search_tool" ) )
     searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) );
@@ -54,6 +61,7 @@ HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_Dat
   QString EntryCol = QObject::tr( "ENTRY_COLUMN" );
   QString RefObjCol = tr( "REF_OBJECT_COLUMN" );
   QString BathymetryCol = tr( "BATHYMETRY_COLUMN" );
+
   SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( model() );
   //RKV: treeModel->setSearcher( theModule->getApp() );
   treeModel->setSearcher( this ); //RKV
@@ -70,6 +78,33 @@ HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_Dat
     connect( proxyModel, 
       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
       SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
+
+    //// Connect signal emitted after editing for updating after objects renaming
+    SUIT_TreeModel* aMiniModel = dynamic_cast<SUIT_TreeModel*>( proxyModel->sourceModel() );
+    if ( aMiniModel )
+    {
+      connect( aMiniModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ), 
+        SIGNAL( dataChanged() ) );
+    }
+
+    // Do updating also in the module's main object browser.
+    if ( theModule )
+    {
+      SUIT_DataBrowser* aModulBrowser = theModule->getApp()->objectBrowser();
+      if ( aModulBrowser )
+      {
+        SUIT_ProxyModel* aPModel = dynamic_cast<SUIT_ProxyModel*>(aModulBrowser->model());
+        if ( aPModel )
+        {
+          SUIT_TreeModel* aModel = dynamic_cast<SUIT_TreeModel*>(aPModel->sourceModel());
+          //connect( proxyModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ), 
+          //  aPModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ) );
+          //connect( proxyModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ), 
+          //  aModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ) );
+          connect( proxyModel, SIGNAL( modelUpdated() ), aModel, SIGNAL( modelUpdated() ) );
+        }
+      }
+    }
   }
 
   // temporary commented
index 50a7753446faef4bb1cf8593b0ee0e4ea5b3d470..11856cf6352a48de4a750a44e30f66f3761e6773 100644 (file)
@@ -51,6 +51,7 @@ public:
 signals:
   void             dropped( const QList<SUIT_DataObject*>& theList, 
     SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction );
+  void             dataChanged();
 
 private:
   HYDROGUI_Module* myModule;
index a436ec17b755f946242195c239438158956f5e79..ca645914050cc0e2e43b44d96d0d82c044243928 100644 (file)
@@ -663,11 +663,12 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject*
 LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject*     theParent,
                                                       HYDROGUI_DataObject* theObject,
                                                       const QString&       theParentEntry,
-                                                      const bool           theIsBuildTree )
+                                                      const bool           theIsBuildTree,
+                                                      const bool           theIsInOperation )
 {
   if ( theIsBuildTree )
   {
-    buildObjectTree( theParent, theObject, theParentEntry );
+    buildObjectTree( theParent, theObject, theParentEntry, theIsInOperation );
   }
   return theObject;
 }
@@ -675,17 +676,21 @@ LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject*     thePa
 LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject*       theParent,
                                                      Handle(HYDROData_Zone) theModelObject,
                                                      const QString&         theParentEntry,
-                                                     const bool             theIsBuildTree )
+                                                     const bool             theIsBuildTree,
+                                                     const bool             theIsInOperation )
 {
-  return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
+  return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation ), 
+    theParentEntry, theIsBuildTree, theIsInOperation );
 }
 
 LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject*         theParent,
                                                        Handle(HYDROData_Region) theModelObject,
                                                        const QString&           theParentEntry,
-                                                       const bool               theIsBuildTree )
+                                                       const bool               theIsBuildTree,
+                                                       const bool               theIsInOperation )
 {
-  return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree );
+  return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry, theIsInOperation ), 
+    theParentEntry, theIsBuildTree, theIsInOperation );
 }
 
 LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
@@ -697,7 +702,8 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParen
 
 void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
                                           SUIT_DataObject* theObject,
-                                          const QString&   theParentEntry )
+                                          const QString&   theParentEntry,
+                                          const bool       theIsInOperation )
 {
   HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>( theObject );
   if ( !aGuiObj )
@@ -764,7 +770,7 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
       Handle(HYDROData_Region) aCaseRegion =
         Handle(HYDROData_Region)::DownCast( anIter.Value() );
       if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
-        createRegion( aCaseRegionsSect, aCaseRegion, "", true );
+        createRegion( aCaseRegionsSect, aCaseRegion, "", true, theIsInOperation );
     }
   }
   else if ( anObjectKind == KIND_REGION )
@@ -779,7 +785,7 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
       Handle(HYDROData_Zone) aRegionZone =
         Handle(HYDROData_Zone)::DownCast( anIter.Value() );
       if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() )
-        createZone( aGuiObj, aRegionZone, "", true );
+        createZone( aGuiObj, aRegionZone, "", true, theIsInOperation );
     }
   }
   else if ( anObjectKind == KIND_PROFILE )
@@ -795,7 +801,17 @@ void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDRO
 {
   if ( !theCase.IsNull() )
   {
-    new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "" );
+    if ( theParent )
+    {
+      // Remove previous objects tree
+        DataObjectList aList;
+        theParent->children( aList );
+        QListIterator<SUIT_DataObject*> anIter( aList );
+        while( anIter.hasNext() )
+          removeChild( theParent, anIter.next() );
+    }
+
+    new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "", true );
 
     HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions();
     HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions );
@@ -804,7 +820,43 @@ void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDRO
       Handle(HYDROData_Region) aCaseRegion =
         Handle(HYDROData_Region)::DownCast( anIter.Value() );
       if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() )
-        createRegion( theParent, aCaseRegion, "", true );
+        createRegion( theParent, aCaseRegion, "", true, true );
+    }
+  }
+}
+
+void HYDROGUI_DataModel::updateObjectTree( Handle(HYDROData_Entity)& theObj )
+{
+  if ( !theObj.IsNull() )
+  {
+    HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>(
+      findObject( HYDROGUI_DataObject::dataObjectEntry( theObj ) ) );
+    if ( aGuiObj )
+    {
+      // Remove previous objects tree
+      DataObjectList aList;
+      aGuiObj->children( aList );
+      QListIterator<SUIT_DataObject*> anIter( aList );
+      while( anIter.hasNext() )
+        removeChild( aGuiObj, anIter.next() );
+
+      // Rebuild the subtree
+      QString aParentEntry;
+      HYDROGUI_DataObject* aParent = dynamic_cast<HYDROGUI_DataObject*>( aGuiObj->parent() );
+      if ( aParent )
+      {
+        aParentEntry = aParent->entry();
+      }
+      buildObjectTree( aParent, aGuiObj, aParentEntry, aGuiObj->isInOperation() );
+    } 
+    else
+    {
+      // workaround for the bug in SalomeApp_Study::findObjectByEntry - it can't find LightApp_DataObjects
+      HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
+      if( aModule )
+      {
+        aModule->getApp()->updateObjectBrowser();
+      }
     }
   }
 }
index e4d2bcb741332fb518c670838618dbe457f4981d..077905a5ff96fdb811f9bf422d5b2cd27ad57a29 100644 (file)
@@ -226,14 +226,19 @@ public:
   bool rename( Handle(HYDROData_Entity) theEntity, const QString& theName );
 
   /**
-   * 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
+   * Creates the Calculation Case subtree for usage within an operation dialog.
+   * \param theParent a created object will be appended as a child of this GUI object
+   * \param theCase the calculation case model object
    */
   void buildCaseTree( SUIT_DataObject*                  theParent,
                       Handle(HYDROData_CalculationCase) theCase );
 
+  /**
+   * Updates the object subtree.
+   * \param theObj the data model entity
+   */
+  void updateObjectTree( Handle(HYDROData_Entity)& theObj );
+
   /**
    * Update the sequence of the objects to be copied
    */
@@ -280,30 +285,52 @@ protected:
    * \param theObject the GUI object
    * \param theParentEntry the entry of parent object
    * \param theIsBuildTree if true then build the subtree of the GUI object
+   * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
    */
   LightApp_DataObject* buildObject( SUIT_DataObject*     theParent,
                                     HYDROGUI_DataObject* theObject,
                                     const QString&       theParentEntry,
-                                    const bool           theIsBuildTree );
+                                    const bool           theIsBuildTree,
+                                    const bool           theIsInOperation = false );
 
+  /**
+   * Build object tree if the flag theIsBuildTree is true. 
+   * \param theParent a created object will be appended as a child of this GUI object
+   * \param theModelObject the data model zone object
+   * \param theParentEntry the entry of parent object
+   * \param theIsBuildTree if true then build the subtree of the GUI object
+   * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
+   */
   LightApp_DataObject* createZone( SUIT_DataObject*       theParent,
                                    Handle(HYDROData_Zone) theModelObject,
                                    const QString&         theParentEntry,
-                                   const bool             theIsBuildTree );
+                                   const bool             theIsBuildTree ,
+                                   const bool             theIsInOperation = false  );
 
+  /**
+   * Build object tree if the flag theIsBuildTree is true. 
+   * \param theParent a created object will be appended as a child of this GUI object
+   * \param theModelObject the data model region object
+   * \param theParentEntry the entry of parent object
+   * \param theIsBuildTree if true then build the subtree of the GUI object
+   * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
+   */
   LightApp_DataObject* createRegion( SUIT_DataObject*         theParent,
                                      Handle(HYDROData_Region) theModelObject,
                                      const QString&           theParentEntry,
-                                     const bool               theIsBuildTree );
+                                     const bool               theIsBuildTree ,
+                                     const bool               theIsInOperation = false );
   /**
-   * Build tree of model object.
+   * Build tree of model object.
    * \param theParent a created object will be appended as a child of this object
    * \param theObject gui object for which the tree will be build
    * \param theParentEntry entry of parent object
+   * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
    */
   void                 buildObjectTree( SUIT_DataObject* theParent,
                                         SUIT_DataObject* theObject,
-                                        const QString&   theParentEntry = QString() );
+                                        const QString&   theParentEntry = QString(),
+                                        const bool       theIsInOperation = false );
 
   /**
    * Removes data object from the tree.
index a3227a7d63c61c37264e45ff992f7155fdb1215d..cc62a54a38a1aa759bca0bbc2c597613f23e6ebf 100644 (file)
 #include <SUIT_DataObject.h>
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_Session.h>
+#include <SUIT_Operation.h>
+#include <CAM_Module.h>
+#include <CAM_Application.h>
+#include <SUIT_Study.h>
 
 #include <QPixmap>
 
 HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent, 
                                           Handle(HYDROData_Entity) theData,
-                                          const QString& theParentEntry )
+                                          const QString& theParentEntry,
+                                          const bool theIsInOperation )
 : CAM_DataObject( theParent ),
   LightApp_DataObject( theParent ),
   myData( theData ),
   myParentEntry( theParentEntry ),
-  myIsValid( true )
+  myIsValid( true ),
+  myIsInOperation( theIsInOperation )
 {
 }
 
@@ -192,13 +198,39 @@ bool HYDROGUI_DataObject::isValid() const
   return myIsValid;
 }
 
+bool HYDROGUI_DataObject::renameAllowed( const int theColumnId ) const
+{
+  bool aRes = false;
+  if ( theColumnId == NameId && module())
+  {
+    SUIT_Operation* anOp = module()->application()->activeStudy()->activeOperation();
+    if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
+    {
+      aRes = isInOperation();
+    }
+    else
+    {
+      aRes = !anOp;
+    }
+  }
+  else
+  {
+    aRes = LightApp_DataObject::renameAllowed( theColumnId );
+  }
+  return aRes;
+}
+
+
+
 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
                                             const QString&   theName,
-                                            const QString&   theParentEntry  )
+                                            const QString&   theParentEntry,
+                                            const bool       theIsInOperation  )
 : CAM_DataObject( theParent ),
   LightApp_DataObject( theParent ),
   myName( theName ),
-  myParentEntry( theParentEntry )
+  myParentEntry( theParentEntry ),
+  myIsInOperation( theIsInOperation )
 {
 }
 
@@ -227,7 +259,9 @@ QPixmap HYDROGUI_NamedObject::icon( const int theId ) const
 
 HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
                                             const QString&   theName,
-                                            const QString&   theParentEntry  )
-: HYDROGUI_NamedObject( theParent, theName, theParentEntry ), CAM_DataObject( theParent )
+                                            const QString&   theParentEntry,
+                                            const bool       theIsInOperation  )
+: HYDROGUI_NamedObject( theParent, theName, theParentEntry, theIsInOperation ), 
+  CAM_DataObject( theParent )
 {
 }
index ea9fb38c00edada61d75d32e37f9c25f085d0888..d8b78a8c04e784cb7ae7e7665c411a25ca98a7cd 100644 (file)
@@ -50,15 +50,22 @@ public:
     BathymetryId                     //!< Bathymetry column
   };
 
+  //! Role
+  enum {
+    IsInOperationRole = Qtx::AppropriateRole + 100 //!< Filter value role
+  };
+
   /**
    * Constructor.
    * \param theParent parent data object
    * \param theData reference to the corresponding object from data structure
    * \param theParentEntry entry of the parent data object (for reference objects)
+   * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
    */
-  HYDROGUI_DataObject( SUIT_DataObject* theParent,
+  HYDROGUI_DataObject( SUIT_DataObject*         theParent,
                        Handle(HYDROData_Entity) theData,
-                       const QString& theParentEntry );
+                       const QString&           theParentEntry,
+                       const bool               theIsInOperation = false );
     
   /**
    * Returns the unique object identifier string.
@@ -90,6 +97,11 @@ public:
    */
   virtual QPixmap icon( const int = NameId ) const;
 
+  /**
+   * Returns true if renaming is allowed for the object.
+   */
+  virtual bool    renameAllowed( const int = NameId ) const;
+
   /**
    * Returns the model data object.
    */
@@ -118,14 +130,22 @@ public:
 
   /**
    * Returns the validity flag: is object valid or not
-   * \returns false if object is not valid
+   * \return false if object is not valid
    */
   bool isValid() const;
 
+  /**
+   * Returns the usage within active operation flag: 
+   * is the object is used in the local tree of an active operation dialog or not.
+   * \return false if the object is used in the main object browser tree
+   */
+  bool isInOperation() const { return myIsInOperation; }
+
 protected:
   Handle(HYDROData_Entity) myData; ///< object from data model
   QString myParentEntry;
   bool myIsValid; ///< indicates if the object is valid
+  bool myIsInOperation; ///< indicates if the object is used within an active operation
   QPixmap myIcon;
 };
 
@@ -145,10 +165,12 @@ public:
    * Constructor.
    * \param theParent parent data object
    * \param theName displayed name
+   * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
    */
   HYDROGUI_NamedObject( SUIT_DataObject* theParent,
-                        const QString& theName,
-                        const QString& theParentEntry  );
+                        const QString&   theName,
+                        const QString&   theParentEntry,
+                        const bool       theIsInOperation = false );
     
   /**
    * Returns the unique object identifier string.
@@ -165,10 +187,18 @@ public:
    */
   virtual QPixmap icon( const int = NameId ) const;
 
+  /**
+   * Returns the usage within active operation flag: 
+   * is the object is used in the local tree of an active operation dialog or not.
+   * \return false if the object is used in the main object browser tree
+   */
+  bool isInOperation() const { return myIsInOperation; }
+
 private:
   QString myName; ///< name in the OB
   QString myParentEntry;
   QPixmap myIcon;
+  bool myIsInOperation; ///< indicates if the object is used within an active operation
 };
 
 /**
@@ -183,10 +213,12 @@ public:
    * Constructor.
    * \param theParent parent data object
    * \param theName displayed name
+   * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
    */
   HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
-                             const QString& theName,
-                             const QString& theParentEntry  );
+                             const QString&   theName,
+                             const QString&   theParentEntry,
+                             const bool       theIsInOperation = false );
     
   bool isDropAccepted() const { return true; }
 };
index c9fca653e8d192a0afdbc41b1b52cd5b54ef2d62..7d8dba61d98a7e0d1969a6f99ff68b8967b64813 100644 (file)
@@ -544,8 +544,8 @@ bool HYDROGUI_Module::renameAllowed( const QString& theEntry ) const
 bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theName )
 {
   Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
-  bool aRes = !anEntity.IsNull();
-  if ( aRes )
+  bool aRes = false;
+  if ( !anEntity.IsNull() )
   {
     HYDROGUI_DataModel* aModel = getDataModel();
     if( aModel )
@@ -554,10 +554,18 @@ bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theN
       {
         // check that there are no other objects with the same name in the document
         Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( this, theName );
-        aRes = anObject.IsNull();
-        if ( aRes )
+        if ( anObject.IsNull() )
         {
-          aRes = aModel->rename( anEntity, theName );
+          SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
+          if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
+          {
+            anEntity->SetName( theName );
+            aRes = true;
+          }
+          else
+          {
+            aRes = aModel->rename( anEntity, theName );
+          }
         }
         else
         {
index f9e1547b472474d08dad14cd30afdc173ae92df1..a53ddc78507d851add33c532b38790a02c26628a 100644 (file)
@@ -32,8 +32,9 @@
 
 HYDROGUI_Region::HYDROGUI_Region( SUIT_DataObject* theParent, 
                                   Handle(HYDROData_Region) theData,
-                                  const QString& theParentEntry )
-: HYDROGUI_DataObject( theParent, theData, theParentEntry ), CAM_DataObject( theParent )
+                                  const QString& theParentEntry,
+                                  const bool theIsInOperation )
+: HYDROGUI_DataObject( theParent, theData, theParentEntry, theIsInOperation ), CAM_DataObject( theParent )
 {
 }
 
index b9e705d2006b5691546278793d90705552549dfe..b6db313f3bef027a6b711e68a60225ca843bd4b1 100644 (file)
@@ -47,10 +47,12 @@ public:
    * \param theParent parent data object
    * \param theData reference to the corresponding object from data structure
    * \param theParentEntry entry of the parent data object (for reference objects)
+   * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
    */
-  HYDROGUI_Region( SUIT_DataObject* theParent,
+  HYDROGUI_Region( SUIT_DataObject*         theParent,
                    Handle(HYDROData_Region) theData,
-                   const QString& theParentEntry );
+                   const QString&           theParentEntry,
+                   const bool               theIsInOperation = false );
 
   bool isDropAccepted() const { return true; }
 
index 189394cf0c9afb124951837f9322ffc0e9bd625f..4485ec4f32d06c669953b2d563101340247ec42d 100644 (file)
@@ -31,8 +31,9 @@
 
 HYDROGUI_Zone::HYDROGUI_Zone( SUIT_DataObject* theParent, 
                                           Handle(HYDROData_Zone) theData,
-                                          const QString& theParentEntry )
-: HYDROGUI_DataObject( theParent, theData, theParentEntry ), CAM_DataObject( theParent )
+                                          const QString& theParentEntry,
+                                          const bool theIsInOperation )
+: HYDROGUI_DataObject( theParent, theData, theParentEntry, theIsInOperation ), CAM_DataObject( theParent )
 {
 }
 
@@ -277,3 +278,58 @@ void HYDROGUI_Zone::setMergeType( int theMergeType, QString theBathymetryName )
     }
   }
 }
+
+/*!
+  \brief Check if this object is can't be renamed in place
+
+  \param id column id
+  \return \c true if the item can be renamed by the user in place (e.g. in the Object browser)
+*/
+bool HYDROGUI_Zone::renameAllowed( const int id ) const
+{
+  if ( id == NameId && isInOperation() )
+  {
+    return true;
+  }
+  return HYDROGUI_DataObject::renameAllowed( id );
+}
+
+///*!
+//  \brief Set name of this object.
+//
+//  \return \c true if rename operation finished successfully, \c false otherwise.
+//*/
+//bool HYDROGUI_Zone::setName(const QString& theName)
+//{
+//  if ( isInOperation() )
+//  {
+//    bool aRes = false;
+//    if ( !theName.isEmpty() )
+//    {
+//      Handle(HYDROData_Entity) anEntity = modelObject();
+//      CAM_Module* aModule = module();
+//      if( anEntity->GetName() != theName && aModule )
+//      {
+//        // check that there are no other objects with the same name in the document
+//        Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( aModule, theName );
+//        if ( anObject.IsNull() )
+//        {
+//          anEntity->SetName( theName );
+//          aRes = true;
+//        }
+//        else
+//        {
+//          // Inform the user that the name is already used
+//          QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
+//          QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
+//          SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage );
+//        }
+//      }
+//    }
+//  }
+//  else
+//  {
+//    aRes = HYDROGUI_DataObject::setName( theName );
+//  }
+//  return aRes;
+//}
index ee25b8023e3f2c262c0d9052381a0565bdd9c435..e960de24508215749b4743f4ec5e2038690951e2 100644 (file)
@@ -45,10 +45,12 @@ public:
    * \param theParent parent data object
    * \param theData reference to the corresponding object from data structure
    * \param theParentEntry entry of the parent data object (for reference objects)
+   * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
    */
-  HYDROGUI_Zone( SUIT_DataObject* theParent,
-                       Handle(HYDROData_Zone) theData,
-                       const QString& theParentEntry );
+  HYDROGUI_Zone( SUIT_DataObject*       theParent,
+                 Handle(HYDROData_Zone) theData,
+                 const QString&         theParentEntry,
+                 const bool             theIsInOperation = false );
     
   /**
    * Returns the text for the specified column.
@@ -65,6 +67,9 @@ public:
    */
   bool        isDraggable() const { return true; }
 
+  bool        renameAllowed( const int = NameId ) const;
+  //bool        setName( const QString& );
+
   /**
    * Returns true if it is a zone which needs merge of bathymetries.
    */