From 5cc0671adea16d34d75f5fb35ed2c16e7f68b956 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Thu, 30 Oct 2014 09:47:28 +0100 Subject: [PATCH] [MEDOP] Clean workspace --- idl/MEDEventListener.idl | 1 + src/MEDOP/gui/DatasourceController.cxx | 42 ++++++++-------- src/MEDOP/gui/WorkspaceController.cxx | 70 ++++++++++++++++++++++++-- src/MEDOP/gui/WorkspaceController.hxx | 3 +- src/MEDOP/gui/XmedConsoleDriver.cxx | 2 +- src/MEDOP/gui/dialogs/DlgAlias.cxx | 10 ++-- src/MEDOP/tui/xmedpy/__init__.py | 6 +-- src/MEDOP/tui/xmedpy/fieldproxy.py | 43 ++++++++-------- src/MEDOP/tui/xmedpy/fieldtools.py | 28 +++++++++++ 9 files changed, 148 insertions(+), 57 deletions(-) diff --git a/idl/MEDEventListener.idl b/idl/MEDEventListener.idl index 3a33441bc..5f0a8a8f1 100644 --- a/idl/MEDEventListener.idl +++ b/idl/MEDEventListener.idl @@ -31,6 +31,7 @@ module MEDOP EVENT_ADDNEW_FIELD, EVENT_DELETE_FIELD, EVENT_UPDATE_FIELD, + EVENT_CLEAN_WORKSPACE, EVENT_UNKNOWN }; diff --git a/src/MEDOP/gui/DatasourceController.cxx b/src/MEDOP/gui/DatasourceController.cxx index ca0d90b6d..aaeda9167 100644 --- a/src/MEDOP/gui/DatasourceController.cxx +++ b/src/MEDOP/gui/DatasourceController.cxx @@ -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"); } } } diff --git a/src/MEDOP/gui/WorkspaceController.cxx b/src/MEDOP/gui/WorkspaceController.cxx index 312fad9f5..ddda18345 100644 --- a/src/MEDOP/gui/WorkspaceController.cxx +++ b/src/MEDOP/gui/WorkspaceController.cxx @@ -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::iterator itr = dataModel->begin(); + for ( ; itr != dataModel->end(); ++itr) { + XmedDataObject* obj = dynamic_cast(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::iterator itr = dataModel->begin(); + for ( ; itr != dataModel->end(); ++itr) { + XmedDataObject* obj = dynamic_cast(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 "<getFieldHandler(); + STDLOG("Field: mesh="<meshname<<" name="<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 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); } diff --git a/src/MEDOP/gui/WorkspaceController.hxx b/src/MEDOP/gui/WorkspaceController.hxx index fac1755b6..88e7bef72 100644 --- a/src/MEDOP/gui/WorkspaceController.hxx +++ b/src/MEDOP/gui/WorkspaceController.hxx @@ -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; diff --git a/src/MEDOP/gui/XmedConsoleDriver.cxx b/src/MEDOP/gui/XmedConsoleDriver.cxx index ab3217b3f..c80628fad 100644 --- a/src/MEDOP/gui/XmedConsoleDriver.cxx +++ b/src/MEDOP/gui/XmedConsoleDriver.cxx @@ -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"; diff --git a/src/MEDOP/gui/dialogs/DlgAlias.cxx b/src/MEDOP/gui/dialogs/DlgAlias.cxx index 6551164b5..7210714bc 100644 --- a/src/MEDOP/gui/dialogs/DlgAlias.cxx +++ b/src/MEDOP/gui/dialogs/DlgAlias.cxx @@ -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(' ', '_'); } diff --git a/src/MEDOP/tui/xmedpy/__init__.py b/src/MEDOP/tui/xmedpy/__init__.py index 0754411f2..665c066c2 100644 --- a/src/MEDOP/tui/xmedpy/__init__.py +++ b/src/MEDOP/tui/xmedpy/__init__.py @@ -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 diff --git a/src/MEDOP/tui/xmedpy/fieldproxy.py b/src/MEDOP/tui/xmedpy/fieldproxy.py index 7f3a94354..0efb442bf 100644 --- a/src/MEDOP/tui/xmedpy/fieldproxy.py +++ b/src/MEDOP/tui/xmedpy/fieldproxy.py @@ -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 - - - - - diff --git a/src/MEDOP/tui/xmedpy/fieldtools.py b/src/MEDOP/tui/xmedpy/fieldtools.py index 6fa6c32d8..c5509364b 100644 --- a/src/MEDOP/tui/xmedpy/fieldtools.py +++ b/src/MEDOP/tui/xmedpy/fieldtools.py @@ -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 -- 2.39.2