X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCalc%2Fgui%2FWorkspaceController.cxx;h=dd59a244776e709b9d1a9052e1951f3ac087960f;hb=cd685749fe9381e48ab7a1a6316372a341bf0e00;hp=b4c6bd2db9f30861965d5f5c46da65e1beb09328;hpb=10e479e70a8c12d2ed92af46375266826616cf2c;p=modules%2Fmed.git diff --git a/src/MEDCalc/gui/WorkspaceController.cxx b/src/MEDCalc/gui/WorkspaceController.cxx index b4c6bd2db..dd59a2447 100644 --- a/src/MEDCalc/gui/WorkspaceController.cxx +++ b/src/MEDCalc/gui/WorkspaceController.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -35,13 +35,15 @@ #include #include +#include +#include + /*! * This class defines a DockWidget plugged in the SALOME application, * and containing a tree view for rendering a hierarchical data * model. This datamodel contains the objects used in the workspace. */ -//WorkspaceController::WorkspaceController(StandardApp_Module * salomeModule) -WorkspaceController::WorkspaceController(MEDModule * salomeModule) +WorkspaceController::WorkspaceController(MEDModule* salomeModule) : TreeGuiManager(salomeModule->getApp(), "Workspace") { _salomeModule = salomeModule; @@ -67,8 +69,8 @@ WorkspaceController::WorkspaceController(MEDModule * salomeModule) // with other parts of the application, in particular the python // console that could retrieve this IOR using the // getEventListenerIOR() function of the MEDDataManager. - SalomeApp_Application * salomeApp = salomeModule->getApp(); - const char * medEventListenerIOR = + SalomeApp_Application* salomeApp = salomeModule->getApp(); + const char* medEventListenerIOR = salomeApp->orb()->object_to_string(medEventListenerServant); MEDFactoryClient::getDataManager()->setEventListenerIOR(medEventListenerIOR); @@ -100,7 +102,7 @@ WorkspaceController::WorkspaceController(MEDModule * salomeModule) } WorkspaceController::~WorkspaceController() { - std::cout << "WorkspaceController::~WorkspaceController()\n"; + STDLOG("WorkspaceController::~WorkspaceController()"); MEDEventListener_i::release(); } @@ -118,14 +120,12 @@ void WorkspaceController::createActions() { QString tooltip = tr("TIP_SAVE_WORKSPACE"); QString icon = tr("ICO_WORKSPACE_SAVE"); int actionId = _salomeModule->createStandardAction(label,this,SLOT(OnSaveWorkspace()),icon,tooltip); - //_salomeModule->addActionInToolbar(actionId); _salomeModule->createTool(actionId, toolbarId); label = tr("LAB_CLEAN_WORKSPACE"); tooltip = tr("TIP_CLEAN_WORKSPACE"); icon = tr("ICO_WORKSPACE_CLEAN"); actionId = _salomeModule->createStandardAction(label,this,SLOT(OnCleanWorkspace()),icon,tooltip); -//_salomeModule->addActionInToolbar(actionId); _salomeModule->createTool(actionId, toolbarId); } @@ -178,7 +178,7 @@ void WorkspaceController::_importItemList(QStringList itemNameIdList) { * console (see _importItemList). */ void WorkspaceController::_importItem(QString itemNameId) { - XmedDataModel * dataModel = (XmedDataModel *)this->getDataModel(); + XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel(); if ( dataModel == NULL ) { LOG("No data model associated to this tree view"); return; @@ -186,8 +186,8 @@ void WorkspaceController::_importItem(QString itemNameId) { // 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)); + XmedDataObject* dataObject = + (XmedDataObject*)dataModel->getDataObject(QS2S(itemNameId)); if ( dataObject == NULL ) { LOG("WorkspaceController: WARN! No data object associated to the item "<getFieldHandler(); + MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler(); STDLOG("Field: mesh="<meshname<<" name="<fieldname); // Finally, we can import the field @@ -211,14 +211,14 @@ void WorkspaceController::_importItem(QString itemNameId) { * options or simply specify the alias (i.e. the name of the python * variable). */ -void WorkspaceController::_importFieldIntoConsole(MEDCALC::FieldHandler * fieldHandler, +void WorkspaceController::_importFieldIntoConsole(MEDCALC::FieldHandler* fieldHandler, bool askForOptions, - const char * alias) + const char* alias) { STDLOG("alias="<fieldname); } @@ -260,11 +260,11 @@ void WorkspaceController::_importFieldIntoConsole(MEDCALC::FieldHandler * fieldH * emitted from the MEDEventListener. It processes events coming from * the python console. */ -void WorkspaceController::processMedEvent(const MEDCALC::MedEvent * event) { +void WorkspaceController::processMedEvent(const MEDCALC::MedEvent* event) { STDLOG("WorkspaceController::processMedEvent"); STDLOG("dataId :"<dataId); - XmedDataModel * dataModel = (XmedDataModel *)this->getDataModel(); + XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel(); if ( dataModel == NULL ) { STDLOG("No data model associated to this tree view"); return; @@ -275,16 +275,16 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent * event) { } else if ( event->type == MEDCALC::EVENT_PUT_IN_WORKSPACE ) { STDLOG("add new field"); - MEDCALC::FieldHandler * fieldHandler = + MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(event->dataId); - XmedDataObject * dataObject = (XmedDataObject *)dataModel->newDataObject(); + XmedDataObject* dataObject = (XmedDataObject*)dataModel->newDataObject(); dataObject->setFieldHandler(*fieldHandler); this->getDataTreeModel()->addData(dataObject); } else if ( event->type == MEDCALC::EVENT_REMOVE_FROM_WORKSPACE ) { STDLOG("remove field"); - std::map::iterator itr = dataModel->begin(); + std::map::iterator itr = dataModel->begin(); for ( ; itr != dataModel->end(); ++itr) { XmedDataObject* obj = dynamic_cast(itr->second); if (obj->getFieldHandler()->id == event->dataId) { @@ -297,7 +297,7 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent * event) { } else if ( event->type == MEDCALC::EVENT_CLEAN_WORKSPACE ) { STDLOG("clean workspace"); - std::map::iterator itr = dataModel->begin(); + std::map::iterator itr = dataModel->begin(); for ( ; itr != dataModel->end(); ++itr) { XmedDataObject* obj = dynamic_cast(itr->second); std::string itemNameId = obj->getNameId(); @@ -309,9 +309,26 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent * event) { emit workspaceSignal(event); // forward to DatasourceController } else if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) { - emit workspaceSignal(event); // forward to DatasourceController + emit workspaceSignal(event); // forward to PresentationController } - + else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) { + emit workspaceSignal(event); // forward to PresentationController + } + else if ( event->type == MEDCALC::EVENT_MODIFY_PRESENTATION ) { + emit workspaceSignal(event); // forward to PresentationController + } + else if ( event->type == MEDCALC::EVENT_PLAY_TEST ) { + emit workspaceSignal(event); // forward to TestController + } + else if ( event->type == MEDCALC::EVENT_QUIT_SALOME ) { + emit workspaceSignal(event); // forward to TestController + } + else if ( event->type == MEDCALC::EVENT_ERROR ) { + std::string msg(event->msg); + QMessageBox::warning(_salomeModule->getApp()->desktop(), "Error", QString::fromStdString(msg)); + } + else + STDLOG("WorkspaceController::processMedEvent(): Unhandled event!!!"); } /*! @@ -319,7 +336,7 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent * event) { * name is requested to the user using a file chooser dialog box */ void WorkspaceController::_saveItemList(QStringList itemNameIdList) { - XmedDataProcessor * dataProcessor = new XmedDataProcessor(this->getDataModel()); + XmedDataProcessor* dataProcessor = new XmedDataProcessor(this->getDataModel()); dataProcessor->process(itemNameIdList); MEDCALC::FieldIdList_var fieldIdList = dataProcessor->getResultingFieldIdList(); delete dataProcessor; @@ -341,7 +358,7 @@ void WorkspaceController::_saveItemList(QStringList itemNameIdList) { * This function remove the selected item from workspace. */ void WorkspaceController::_removeItemList(QStringList itemNameIdList) { - XmedDataModel * dataModel = (XmedDataModel *)this->getDataModel(); + XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel(); if ( dataModel == NULL ) { LOG("No data model associated to this tree view"); return; @@ -352,8 +369,8 @@ void WorkspaceController::_removeItemList(QStringList itemNameIdList) { // 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)); + XmedDataObject* dataObject = + (XmedDataObject*)dataModel->getDataObject(QS2S(itemNameId)); if ( dataObject == NULL ) { LOG("WorkspaceController: WARN! No data object associated to the item "<getFieldHandler(); + MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler(); STDLOG("Field: mesh="<meshname<<" name="<fieldname); // Remove the field variable from console @@ -382,7 +399,7 @@ void WorkspaceController::_removeItemList(QStringList itemNameIdList) { * scalar map of the first item to start the job. */ void WorkspaceController::_exportItemList(QStringList itemNameIdList) { - XmedDataProcessor * dataProcessor = new XmedDataProcessor(this->getDataModel()); + XmedDataProcessor* dataProcessor = new XmedDataProcessor(this->getDataModel()); dataProcessor->process(itemNameIdList); MEDCALC::FieldIdList_var fieldIdList = dataProcessor->getResultingFieldIdList(); delete dataProcessor; @@ -390,24 +407,24 @@ void WorkspaceController::_exportItemList(QStringList itemNameIdList) { // _GBO_ We use a temporary file to proceed with this export to // paravis. I'm sure it could be better in a futur version or when I // will get a better understanding of paravis API. - const char * tmpfilename = "/tmp/medcalc_export2paravis.med"; + const char* tmpfilename = "/tmp/medcalc_export2paravis.med"; MEDFactoryClient::getDataManager()->saveFields(tmpfilename, fieldIdList); // We import the whole file but create a scalar map for the first // selected field only (it's just an export to continue the job in // paravis) - XmedDataModel * dataModel = (XmedDataModel *)this->getDataModel(); + XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel(); if ( dataModel == NULL ) { STDLOG("No data model associated to this tree view"); return; } QString itemNameId = itemNameIdList[0]; - XmedDataObject * dataObject = (XmedDataObject *)dataModel->getDataObject(QS2S(itemNameId)); + XmedDataObject* dataObject = (XmedDataObject*)dataModel->getDataObject(QS2S(itemNameId)); if ( dataObject == NULL ) { LOG("WorkspaceController: WARN! No data object associated to the item "<getFieldHandler(); + MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler(); QStringList commands; /* commands+=QString("from xmed.driver_pvis import pvis_scalarmap"); @@ -434,7 +451,7 @@ void WorkspaceController::_viewItemList(QStringList itemNameIdList) { // __GBO__: In this version, we consider only the first field in the selection QString itemNameId = itemNameIdList[0]; - XmedDataModel * dataModel = (XmedDataModel *)this->getDataModel(); + XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel(); if ( dataModel == NULL ) { LOG("No data model associated to this tree view"); return; @@ -442,8 +459,8 @@ void WorkspaceController::_viewItemList(QStringList itemNameIdList) { // 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)); + XmedDataObject* dataObject = + (XmedDataObject*)dataModel->getDataObject(QS2S(itemNameId)); if ( dataObject == NULL ) { LOG("WorkspaceController: WARN! No data object associated to the item "<getFieldHandler(); + MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler(); // And finally, we can create the set of medcalc instructions to // generate the scalar map on this field. @@ -466,8 +483,8 @@ void WorkspaceController::_viewItemList(QStringList itemNameIdList) { * DatasourceController. The connection between the datasource signal * and this slot is realized by the main class MEDModule. */ -void WorkspaceController::processDatasourceEvent(const DatasourceEvent * event) { - XmedDataModel * dataModel = (XmedDataModel *)this->getDataModel(); +void WorkspaceController::processDatasourceEvent(const DatasourceEvent* event) { + XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel(); if ( dataModel == NULL ) { STDLOG("No data model associated to this tree view"); return; @@ -480,7 +497,7 @@ void WorkspaceController::processDatasourceEvent(const DatasourceEvent * event) // options such that "change the underlying mesh". // <<< - XmedDataObject * dataObject = event->objectdata; + XmedDataObject* dataObject = event->objectdata; if ( event->eventtype == DatasourceEvent::EVENT_IMPORT_OBJECT ) { std::cout << "IMPORT object in workspace: " << dataObject->toString() << std::endl; @@ -505,31 +522,50 @@ void WorkspaceController::processDatasourceEvent(const DatasourceEvent * event) askForOptions, QCHARSTAR(event->objectalias)); } - else if ( event->eventtype == DatasourceEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) { - QStringList commands; - -#define stringify( name ) # name - QString viewMode = stringify(MEDCALC::VIEW_MODE_NEW_LAYOUT); // :TODO: change this (get value from dedicated dialog) - viewMode.replace("::", "."); - - MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler(); - commands += QString("medcalc.MakeScalarMap(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); - _consoleDriver->exec(commands); - } else if ( event->eventtype == DatasourceEvent::EVENT_ADD_DATASOURCE ) { QStringList commands; - commands += QString("medcalc.LoadDataSource('%1')").arg(event->objectalias); + commands += QString("source_id = medcalc.LoadDataSource('%1')").arg(event->objectalias); + commands += QString("source_id"); _consoleDriver->exec(commands); } else if ( event->eventtype == DatasourceEvent::EVENT_ADD_IMAGE_AS_DATASOURCE ) { QStringList commands; - commands += QString("medcalc.LoadImageAsDataSource('%1')").arg(event->objectalias); + commands += QString("source_id = medcalc.LoadImageAsDataSource('%1')").arg(event->objectalias); + commands += QString("source_id"); _consoleDriver->exec(commands); } else { STDLOG("The event "<eventtype<<" is not implemented yet"); } +} +void +WorkspaceController::processProcessingEvent(const ProcessingEvent* event) +{ + XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel(); + if ( dataModel == NULL ) { + STDLOG("No data model associated to this tree view"); + return; + } + + // >>> + // __GBO__ To know what to do we should test the type, because the + // object could be a mesh, a timeseries or a single field. We test + // here the case of a single field. Moreover, there could have + // options such that "change the underlying mesh". + // <<< + + XmedDataObject* dataObject = event->objectdata; + + if ( event->eventtype == ProcessingEvent::EVENT_IMPORT_OBJECT ) { + std::cout << "IMPORT object in workspace: " << dataObject->toString() << std::endl; + STDLOG("IMPORT object in workspace:\n"<toString()); + // _GBO_ QUESTION: tag automatically the object as a peristant object ?? + // We first add the data object to the internal data model + dataModel->addDataObject(dataObject); + // Then we request the tree view to consider this new object + this->getDataTreeModel()->addData(dataObject); + } } void WorkspaceController::OnSaveWorkspace() {