EVENT_ADDNEW_FIELD,
EVENT_DELETE_FIELD,
EVENT_UPDATE_FIELD,
+ EVENT_CLEAN_WORKSPACE,
EVENT_UNKNOWN
};
icon = tr("ICO_DATASOURCE_INTERPOLATE_FIELD");
actionId = _salomeModule->createStandardAction(label,this,SLOT(OnInterpolateField()),icon);
_salomeModule->addActionInPopupMenu(actionId);
-
}
/**
_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 =
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?)
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");
}
}
}
}
else if ( actionId == _actionIds.remove ) {
STDLOG("WorkspaceController::processItemList: remove");
+ this->_removeItemList(itemNameIdList);
}
else {
STDLOG("WorkspaceController::processItemList: ERR : action unknown ");
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);
+ }
+ }
}
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
}
-
/*!
* This function sends a request to the SALOME data visualisation
* (module VISU or PARAVIS) for displaying a scalar map of the fields
#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);
}
// 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
void _exportItemList(QStringList itemNameIdList);
void _saveItemList(QStringList itemNameIdList);
+ void _removeItemList(QStringList itemNameIdList);
void _viewItemList(QStringList itemNameIdList);
MEDEventListener_i * _medEventListener;
// 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";
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() {
//}
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(' ', '_');
}
#
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-# Author : Guillaume Boulant (EDF)
+# Author : Guillaume Boulant (EDF)
#
# ===============================================================
global eventListener
if eventListener is not None:
return True
-
+
# Try to define the event listener
connectEventListener()
if eventListener is None:
# 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
#
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-# Author : Guillaume Boulant (EDF)
+# Author : Guillaume Boulant (EDF)
import xmed
import MEDOP
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
return None
return FieldProxy(rfieldHandler)
-
+
def __radd__(self, operande):
"""
The user typed 'operande+self', we replace by 'self+operande'
return None
return FieldProxy(rfieldHandler)
-
+
def __rsub__(self, operande):
"""
The user typed 'operande-self' where operande is not a field
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
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)
return None
return FieldProxy(rfieldHandler)
-
+
def __call__(self, restriction=None):
"""
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
# Print for visual control
print self.__repr__()
-
+
#
# ===================================================================
# Functions for events notification
# 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):
"""
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
-
-
-
-
-
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