Salome HOME
[MEDOP] Clean workspace V7_5_0b1
authorCédric Aguerre <cedric.aguerre@edf.fr>
Thu, 30 Oct 2014 08:47:28 +0000 (09:47 +0100)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Thu, 30 Oct 2014 08:47:28 +0000 (09:47 +0100)
idl/MEDEventListener.idl
src/MEDOP/gui/DatasourceController.cxx
src/MEDOP/gui/WorkspaceController.cxx
src/MEDOP/gui/WorkspaceController.hxx
src/MEDOP/gui/XmedConsoleDriver.cxx
src/MEDOP/gui/dialogs/DlgAlias.cxx
src/MEDOP/tui/xmedpy/__init__.py
src/MEDOP/tui/xmedpy/fieldproxy.py
src/MEDOP/tui/xmedpy/fieldtools.py

index 3a33441bc9cd4e0423b2435f89ba9c5997e0596b..5f0a8a8f1efd38a7ee1beb0051853ef2c028fedf 100644 (file)
@@ -31,6 +31,7 @@ module MEDOP
     EVENT_ADDNEW_FIELD,
     EVENT_DELETE_FIELD,
     EVENT_UPDATE_FIELD,
+    EVENT_CLEAN_WORKSPACE,
     EVENT_UNKNOWN
   };
 
index ca0d90b6da46dc9c394882b0b2f8215065d289f6..aaeda916779b84cfbd5f98816cbd530f6467d038 100644 (file)
@@ -114,7 +114,6 @@ void DatasourceController::createActions() {
   icon  = tr("ICO_DATASOURCE_INTERPOLATE_FIELD");
   actionId = _salomeModule->createStandardAction(label,this,SLOT(OnInterpolateField()),icon);
   _salomeModule->addActionInPopupMenu(actionId);
-
 }
 
 /**
@@ -152,7 +151,6 @@ MEDOP::DatasourceHandler * DatasourceController::addDatasource(const char * file
     _studyEditor->setParameterInt(soMesh,OBJECT_ID,meshHandler.id);
     _studyEditor->setParameterBool(soMesh,OBJECT_IS_IN_WORKSPACE,false);
 
-
     // We add the field timeseries defined on this mesh, as children
     // of the mesh SObject
     MEDOP::FieldseriesHandlerList * fieldseriesHandlerList =
@@ -382,7 +380,7 @@ void DatasourceController::OnUseInWorkspace() {
     event->objectalias = alias;
     emit datasourceSignal(event);
     // Tag the item to prevent double import
-    _studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
+    //    _studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
     // Tag the field as persistent on the server. It means that a
     // saving of the workspace will save at least this field (maybe it
     // should be an option?)
@@ -396,27 +394,27 @@ void DatasourceController::OnUseInWorkspace() {
 
       bool isInWorkspace = _studyEditor->getParameterBool(soField,OBJECT_IS_IN_WORKSPACE);
       if ( !isInWorkspace ) {
-  int fieldId = _studyEditor->getParameterInt(soField,OBJECT_ID);
-  MEDOP::FieldHandler * fieldHandler =
-    MEDOPFactoryClient::getDataManager()->getFieldHandler(fieldId);
-  DatasourceEvent * event = new DatasourceEvent();
-  event->eventtype = DatasourceEvent::EVENT_IMPORT_OBJECT;
-  XmedDataObject * dataObject = new XmedDataObject();
-  dataObject->setFieldHandler(*fieldHandler);
-  event->objectdata  = dataObject;
-  emit datasourceSignal(event);
-  // Note that this signal is processed by the WorkspaceController
-
-  // Tag the item to prevent double import
-  _studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
-  // Tag the field as persistent on the server. It means that a
-  // saving of the workspace will save at least this field (maybe it
-  // should be an option?)
-  MEDOPFactoryClient::getDataManager()->markAsPersistent(fieldId, true);
+        int fieldId = _studyEditor->getParameterInt(soField,OBJECT_ID);
+        MEDOP::FieldHandler * fieldHandler =
+          MEDOPFactoryClient::getDataManager()->getFieldHandler(fieldId);
+        DatasourceEvent * event = new DatasourceEvent();
+        event->eventtype = DatasourceEvent::EVENT_IMPORT_OBJECT;
+        XmedDataObject * dataObject = new XmedDataObject();
+        dataObject->setFieldHandler(*fieldHandler);
+        event->objectdata  = dataObject;
+        emit datasourceSignal(event);
+        // Note that this signal is processed by the WorkspaceController
+
+        // Tag the item to prevent double import
+        //        _studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
+        // Tag the field as persistent on the server. It means that a
+        // saving of the workspace will save at least this field (maybe it
+        // should be an option?)
+        MEDOPFactoryClient::getDataManager()->markAsPersistent(fieldId, true);
       }
       else {
-  STDLOG("The field "<<_studyEditor->getName(soField)<<
-         " is already defined in the workspace");
+        STDLOG("The field "<<_studyEditor->getName(soField)<<
+               " is already defined in the workspace");
       }
     }
   }
index 312fad9f5c321129bb5bf6502d76ceb9c1afd9d3..ddda183458eb16e8a31af5da52c52f94e0139af0 100644 (file)
@@ -142,6 +142,7 @@ void WorkspaceController::processItemList(QStringList itemNameIdList, int action
   }
   else if ( actionId == _actionIds.remove ) {
     STDLOG("WorkspaceController::processItemList: remove");
+    this->_removeItemList(itemNameIdList);
   }
   else {
     STDLOG("WorkspaceController::processItemList: ERR : action unknown ");
@@ -269,6 +270,29 @@ void WorkspaceController::processMedEvent(const MEDOP::MedEvent * event) {
     dataObject->setFieldHandler(*fieldHandler);
     this->getDataTreeModel()->addData(dataObject);
   }
+  else if ( event->type == MEDOP::EVENT_DELETE_FIELD ) {
+    STDLOG("remove field");
+    std::map<string, DataObject *>::iterator itr = dataModel->begin();
+    for ( ; itr != dataModel->end(); ++itr) {
+      XmedDataObject* obj = dynamic_cast<XmedDataObject*>(itr->second);
+      if (obj->getFieldHandler()->id == event->fieldid) {
+        std::string itemNameId = obj->getNameId();
+        this->getDataTreeModel()->removeData(obj);
+        dataModel->removeDataObject(itemNameId);
+        return;
+      }
+    }
+  }
+  else if ( event->type == MEDOP::EVENT_CLEAN_WORKSPACE ) {
+    STDLOG("clean workspace");
+    std::map<string, DataObject *>::iterator itr = dataModel->begin();
+    for ( ; itr != dataModel->end(); ++itr) {
+      XmedDataObject* obj = dynamic_cast<XmedDataObject*>(itr->second);
+      std::string itemNameId = obj->getNameId();
+      this->getDataTreeModel()->removeData(obj);
+      dataModel->removeDataObject(itemNameId);
+    }
+  }
 
 }
 
@@ -295,6 +319,44 @@ void WorkspaceController::_saveItemList(QStringList itemNameIdList) {
   MEDOPFactoryClient::getDataManager()->saveFields(QCHARSTAR(filename), fieldIdList);
 }
 
+/*!
+ * This function remove the selected item from workspace.
+ */
+void WorkspaceController::_removeItemList(QStringList itemNameIdList) {
+  XmedDataModel * dataModel = (XmedDataModel *)this->getDataModel();
+  if ( dataModel == NULL ) {
+    LOG("No data model associated to this tree view");
+    return;
+  }
+
+  // __GBO__: In this version, we consider only the first field in the selection
+  QString itemNameId = itemNameIdList[0];
+
+  // We can request the dataModel to obtain the dataObject associated
+  // to this item (iteNameId is a TreeView id, Qt stuff only).
+  XmedDataObject * dataObject =
+    (XmedDataObject *)dataModel->getDataObject(QS2S(itemNameId));
+
+  if ( dataObject == NULL ) {
+    LOG("WorkspaceController: WARN! No data object associated to the item "<<itemNameId);
+    return;
+  }
+
+  // Then, we can request this data object to obtain the associated
+  // FieldHandler.
+  MEDOP::FieldHandler * fieldHandler = dataObject->getFieldHandler();
+  STDLOG("Field: mesh="<<fieldHandler->meshname<<" name="<<fieldHandler->fieldname);
+
+  // Remove the field variable from console
+  QStringList commands;
+  commands+=QString("remove(get(%1))").arg(fieldHandler->id);
+  _consoleDriver->exec(commands);
+
+  // Finally, we can remove the field from tree data model and tree view
+  this->getDataTreeModel()->removeData(dataObject);
+  dataModel->removeDataObject(QS2S(itemNameId));
+}
+
 /**
  * This function export the list of specified field item to PARAVIS
  * module. This consists in create a med file gathering the selected
@@ -340,7 +402,6 @@ void WorkspaceController::_exportItemList(QStringList itemNameIdList) {
 
 }
 
-
 /*!
  * This function sends a request to the SALOME data visualisation
  * (module VISU or PARAVIS) for displaying a scalar map of the fields
@@ -454,7 +515,8 @@ void WorkspaceController::OnSaveWorkspace() {
 
 #include <QMessageBox>
 void WorkspaceController::OnCleanWorkspace() {
-  QMessageBox::warning(_salomeModule->getApp()->desktop(),
-           tr("NOT_IMPLEMENTED_YET"),
-           tr("FUNCTION_NOT_IMPLEMENTED"));
+  // Remove field from console
+  QStringList commands;
+  commands += QString("clean()");
+  _consoleDriver->exec(commands);
 }
index fac1755b6af1fd2989531418618c5180951ed8d4..88e7bef72d7f29d97597d9ba8838daeb97a1ce30 100644 (file)
@@ -17,7 +17,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-// Author : Guillaume Boulant (EDF) 
+// Author : Guillaume Boulant (EDF)
 
 #ifndef _WORKSPACE_CONTROLLER_HXX
 #define _WORKSPACE_CONTROLLER_HXX
@@ -70,6 +70,7 @@ private:
 
   void _exportItemList(QStringList itemNameIdList);
   void _saveItemList(QStringList itemNameIdList);
+  void _removeItemList(QStringList itemNameIdList);
   void _viewItemList(QStringList itemNameIdList);
 
   MEDEventListener_i * _medEventListener;
index ab3217b3ffb7a205b93692f80fbbb38fcf82c108..c80628fade3f1605da4810e31a6e31500d0ccb23 100644 (file)
@@ -48,7 +48,7 @@ void XmedConsoleDriver::setup() {
     // Set the globals dictionnary so that the fields tools work properly.
     commands+="xmed.setConsoleGlobals(globals())";
     // Import the tools required for field operations
-    commands+="from xmed import load, get, put, dup, ls, la, save, view, doc, wipe";
+    commands+="from xmed import load, get, put, dup, ls, la, save, view, doc, wipe, remove, clean";
     // A last one to clear the console screen
     //commands+="wipe";
 
index 6551164b5924fd2d7276add4e96387e95b589c1b..7210714bc48d9980e398743a73a19a20b0d4a8ba 100644 (file)
@@ -9,14 +9,14 @@ using std::endl;
 DlgAlias::DlgAlias(QDialog *parent) : QDialog(parent)
 {
   ui.setupUi(this); // A faire en premier
-  
+
   /*
     Personnalisez vos widgets ici si nécessaire
     Réalisez des connexions supplémentaires entre signaux et slots
   */
-  
+
   // The slots accept() and reject() are already connected to the
-  // buttonbox (inherited features) 
+  // buttonbox (inherited features)
 }
 
 void DlgAlias::accept() {
@@ -33,9 +33,9 @@ void DlgAlias::accept() {
 //}
 
 void DlgAlias::setAlias(QString alias) {
-  ui.txtAlias->setText(alias);
+  ui.txtAlias->setText(alias.trimmed().replace(' ', '_'));
 }
 
 QString DlgAlias::getAlias() {
-  return ui.txtAlias->text().trimmed();
+  return ui.txtAlias->text().trimmed().replace(' ', '_');
 }
index 0754411f22c2f37fdf4ee92368e35fb4390717f8..665c066c29e5dc00ce6559cce5df50905897f2c3 100644 (file)
@@ -17,7 +17,7 @@
 #
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
-# Author : Guillaume Boulant (EDF) 
+# Author : Guillaume Boulant (EDF)
 
 #
 # ===============================================================
@@ -112,7 +112,7 @@ def eventListenerIsRunning():
     global eventListener
     if eventListener is not None:
         return True
-    
+
     # Try to define the event listener
     connectEventListener()
     if eventListener is None:
@@ -133,7 +133,7 @@ connectEventListener()
 # Automatic import of some elements of the package
 # ===============================================================
 #
-from fieldtools import load, get, put, dup, ls, la, save, view
+from fieldtools import load, get, put, dup, ls, la, save, view, remove, clean
 from fieldguide import doc
 from cmdtools import cls, wipe
 
index 7f3a94354e8e0790df1723844534df3c15ca97ac..0efb442bff686e62d8bf25d7b0500d6246335fb4 100644 (file)
@@ -17,7 +17,7 @@
 #
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
-# Author : Guillaume Boulant (EDF) 
+# Author : Guillaume Boulant (EDF)
 
 import xmed
 import MEDOP
@@ -85,7 +85,7 @@ class FieldProxy:
                 xmed.err("The modification of the attribute %s is not possible"%name)
         else:
             self.__dict__[name] = value
-        
+
     def __repr__(self):
         """
         Return a string containing a printable representation of this
@@ -146,7 +146,7 @@ class FieldProxy:
             return None
 
         return FieldProxy(rfieldHandler)
-    
+
     def __radd__(self, operande):
         """
         The user typed 'operande+self', we replace by 'self+operande'
@@ -183,7 +183,7 @@ class FieldProxy:
             return None
 
         return FieldProxy(rfieldHandler)
-        
+
     def __rsub__(self, operande):
         """
         The user typed 'operande-self' where operande is not a field
@@ -207,9 +207,9 @@ class FieldProxy:
         except SALOME.SALOME_Exception, ex:
             xmed.err(ex.details.text)
             return None
-        
+
         return FieldProxy(rfieldHandler)
-        
+
     def __mul__(self, operande):
         """
         This makes the multiplication of two fields or the
@@ -290,7 +290,7 @@ class FieldProxy:
 
     def __abs__(self):
         """
-        This compute the absolute value of the field. We use here 
+        This compute the absolute value of the field. We use here
         """
         return self.ope(function="abs(u)",duplicate=True)
 
@@ -332,7 +332,7 @@ class FieldProxy:
             return None
 
         return FieldProxy(rfieldHandler)
-        
+
 
     def __call__(self, restriction=None):
         """
@@ -359,7 +359,7 @@ class FieldProxy:
             order = self.order
         if source is None:
             source = self.source
-            
+
         xmed.dataManager.updateFieldMetadata(self.id,name,iteration,order,source)
         self.__fieldHandler.fieldname = name
         self.__fieldHandler.iteration = iteration
@@ -375,7 +375,7 @@ class FieldProxy:
 
         # Print for visual control
         print self.__repr__()
-            
+
 #
 # ===================================================================
 # Functions for events notification
@@ -385,14 +385,14 @@ class FieldProxy:
 # that they could be used in another context than the FieldProxy instances
 import MEDOP
 
-def __notifyGui(type, fieldId):
+def __notifyGui(type, fieldId=-1):
     medEvent = MEDOP.MedEvent(type, fieldId)
-    
+
     if not xmed.eventListenerIsRunning(): return
-    
+
     # Notify the GUI of the update event
     xmed.eventListener.processMedEvent(medEvent)
-    
+
 
 def notifyGui_update(fieldId):
     """
@@ -404,19 +404,20 @@ def notifyGui_update(fieldId):
 
 def notifyGui_add(fieldId):
     __notifyGui(MEDOP.EVENT_ADDNEW_FIELD,fieldId)
-  
+
+def notifyGui_remove(fieldId):
+    __notifyGui(MEDOP.EVENT_DELETE_FIELD,fieldId)
+
+def notifyGui_clean():
+    __notifyGui(MEDOP.EVENT_CLEAN_WORKSPACE)
+
 #
 # ===================================================================
 # use case functions
 # ===================================================================
 #
-    
+
 # ===================================================================
 if __name__ == "__main__":
     # See test_medoperation.py
     pass
-
-
-
-
-
index 6fa6c32d82cc84169fac45f6a71e39bac3e65cd7..c5509364b0b9d9506d5518e1f5cedd71edc5582f 100644 (file)
@@ -112,6 +112,34 @@ class ListFields(object):
 ls=ListFields(all=False)
 la=ListFields(all=True)
 
+# ===================================================================
+# Remove variable from console
+from xmed.fieldproxy import notifyGui_remove
+def remove(aFieldProxy):
+    dvars = pyConsoleGlobals
+    if dvars is None:
+        return
+    for varkey, var in dvars.items():
+        if isinstance(var, FieldProxy) and var.id == aFieldProxy.id:
+            exec("del %s"%varkey) in pyConsoleGlobals
+    notifyGui_remove(aFieldProxy.id)
+#
+
+# Clean workspace
+from xmed.fieldproxy import notifyGui_clean
+def clean():
+    dvars = pyConsoleGlobals
+    if dvars is None:
+        return
+    all_keys = []
+    for varkey, var in dvars.items():
+        if isinstance(var, FieldProxy):
+            all_keys.append("%s"%varkey)
+    if len(all_keys) > 0:
+        exec "del "+",".join(all_keys) in pyConsoleGlobals
+    notifyGui_clean()
+#
+
 # ===================================================================
 # Field Data Management
 from xmed import properties