From d8a62ff9961a88afa109c7269de197c682242c82 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Mon, 14 Sep 2015 14:43:37 +0200 Subject: [PATCH] Add MED engine --- idl/CMakeLists.txt | 1 + idl/MED_Gen.idl | 52 +++++ resources/MEDCatalog.xml.in | 9 + src/MEDCalc/cmp/CMakeLists.txt | 25 ++- src/MEDCalc/cmp/MED.cxx | 265 +++++++++++++++++++++++ src/MEDCalc/cmp/MED.hxx | 81 +++++++ src/MEDCalc/cmp/MEDFactoryClient.cxx | 2 +- src/MEDCalc/gui/DatasourceController.cxx | 103 ++++----- src/MEDCalc/gui/DatasourceController.hxx | 15 +- src/MEDCalc/gui/MEDModule.cxx | 202 +++++++++++++---- src/MEDCalc/gui/MEDModule.hxx | 45 +++- src/MEDCalc/gui/WorkspaceController.cxx | 16 +- src/MEDCalc/gui/WorkspaceController.hxx | 11 +- 13 files changed, 694 insertions(+), 133 deletions(-) create mode 100644 idl/MED_Gen.idl create mode 100644 src/MEDCalc/cmp/MED.cxx create mode 100644 src/MEDCalc/cmp/MED.hxx diff --git a/idl/CMakeLists.txt b/idl/CMakeLists.txt index 69c3b4a6c..09229bd42 100644 --- a/idl/CMakeLists.txt +++ b/idl/CMakeLists.txt @@ -26,6 +26,7 @@ INCLUDE_DIRECTORIES( ) SET(SalomeIDLMED_IDLSOURCES + MED_Gen.idl MEDCouplingCorbaServant.idl ParaMEDCouplingCorbaServant.idl MEDDataManager.idl diff --git a/idl/MED_Gen.idl b/idl/MED_Gen.idl new file mode 100644 index 000000000..3230a3547 --- /dev/null +++ b/idl/MED_Gen.idl @@ -0,0 +1,52 @@ +// Copyright (C) 2005-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MED_GEN_IDL_ +#define __MED_GEN_IDL_ + +#include "SALOME_Component.idl" +#include "SALOME_Exception.idl" +#include "MEDDataManager.idl" + +module MED_ORB +{ + /*! + \brief Operation result codes + */ + enum status { + OP_OK, //!< OK result + OP_ERROR //!< ERROR: other problems + }; + + interface + MED_Gen : Engines::EngineComponent + { + status addDatasourceToStudy(in SALOMEDS::Study study, + in MEDCALC::DatasourceHandler datasourceHandler) + raises (SALOME::SALOME_Exception); + + status registerPresentation(in SALOMEDS::Study study, + in long fieldId, + in string name, + in string label) + raises (SALOME::SALOME_Exception); + }; +}; + +#endif diff --git a/resources/MEDCatalog.xml.in b/resources/MEDCatalog.xml.in index 4f0429fcf..dc81f9b7b 100644 --- a/resources/MEDCatalog.xml.in +++ b/resources/MEDCatalog.xml.in @@ -82,5 +82,14 @@ 0 + + MED + Med + MED + @SALOMEMED_VERSION@ + MED component engine + 0 + + diff --git a/src/MEDCalc/cmp/CMakeLists.txt b/src/MEDCalc/cmp/CMakeLists.txt index 1c54b6c75..175ad0eda 100644 --- a/src/MEDCalc/cmp/CMakeLists.txt +++ b/src/MEDCalc/cmp/CMakeLists.txt @@ -33,15 +33,24 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/MEDLoader ) -SET(MEDFactoryEngine_SOURCES +SET(COMMON_SOURCES MEDFactoryClient.cxx MEDDataManager_i.cxx MEDCalculator_i.cxx MEDPresentationManager_i.cxx - MEDFactory_i.cxx MEDPresentation.cxx ) +SET(MEDFactoryEngine_SOURCES + ${COMMON_SOURCES} + MEDFactory_i.cxx +) + +SET(MEDEngine_SOURCES + ${COMMON_SOURCES} + MED.cxx +) + SET(COMMON_LIBS ${PLATFORM_LIBRARIES} SalomeIDLMED @@ -64,10 +73,16 @@ ADD_LIBRARY(MEDFactoryEngine SHARED ${MEDFactoryEngine_SOURCES}) SET_TARGET_PROPERTIES(MEDFactoryEngine PROPERTIES COMPILE_FLAGS "${COMMON_FLAGS}") TARGET_LINK_LIBRARIES(MEDFactoryEngine ${COMMON_LIBS}) -INSTALL(TARGETS MEDFactoryEngine DESTINATION ${SALOME_INSTALL_LIBS}) +ADD_LIBRARY(MEDEngine SHARED ${MEDEngine_SOURCES}) +SET_TARGET_PROPERTIES(MEDEngine PROPERTIES COMPILE_FLAGS "${COMMON_FLAGS}") +TARGET_LINK_LIBRARIES(MEDEngine ${COMMON_LIBS}) + +#INSTALL(TARGETS MEDFactoryEngine DESTINATION ${SALOME_INSTALL_LIBS}) +INSTALL(TARGETS MEDFactoryEngine EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) +INSTALL(TARGETS MEDEngine EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) -FILE(GLOB MEDFactoryEngine_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") -INSTALL(FILES ${MEDFactoryEngine_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS}) +FILE(GLOB MEDCALC_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") +INSTALL(FILES ${MEDCALC_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS}) IF(SALOME_ENABLE_PYTHON) INSTALL(FILES test_medcalc_components.py PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ DESTINATION ${SALOME_INSTALL_BINS}/xmed) diff --git a/src/MEDCalc/cmp/MED.cxx b/src/MEDCalc/cmp/MED.cxx new file mode 100644 index 000000000..ff3ab8651 --- /dev/null +++ b/src/MEDCalc/cmp/MED.cxx @@ -0,0 +1,265 @@ +// Copyright (C) 2015 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MED.hxx" + +#include "MEDFactoryClient.hxx" + +#include +#include CORBA_CLIENT_HEADER(SALOMEDS_Attributes) + +#include + +#include +#include + +#include + +/*! + \brief Constructor + + Creates an instance of the MED component engine + + \param orb reference to the ORB + \param poa reference to the POA + \param contId CORBA object ID, pointing to the owner SALOME container + \param instanceName SALOME component instance name + \param interfaceName SALOME component interface name +*/ +MED::MED(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId* contId, + const char* instanceName, + const char* interfaceName) + : Engines_Component_i(orb, poa, contId, instanceName, interfaceName), + _fieldSeriesEntries() +{ + _thisObj = this; + _id = _poa->activate_object(_thisObj); // register and activate this servant object +} + +MED::~MED() +{ + // nothing to do +} + +// Duplicate gui/XmedDataModel +static const int NB_TYPE_OF_FIELDS = 4; +static const char* mapTypeOfFieldLabel[NB_TYPE_OF_FIELDS] = + {"ON_CELLS", "ON_NODES", "ON_GAUSS_PT", "ON_GAUSS_NE" }; + +MED_ORB::status +MED::addDatasourceToStudy(SALOMEDS::Study_ptr study, + const MEDCALC::DatasourceHandler& datasourceHandler) +{ + // set exception handler to catch unexpected CORBA exceptions + Unexpect aCatch(SALOME_SalomeException); + + // set result status to error initially + MED_ORB::status result = MED_ORB::OP_ERROR; + + // check if reference to study is valid + if (!CORBA::is_nil(study)) { + // get full object path + std::string fullName = CORBA::string_dup(datasourceHandler.name); + // check if the object with the same name is already registered in the study + SALOMEDS::SObject_var sobj = study->FindObjectByPath(fullName.c_str()); + if (CORBA::is_nil(sobj)) { + // object is not registered yet -> register + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::AttributeParameter_var aParam; + SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder(); + SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder(); + + // find MED component; create it if not found + SALOMEDS::SComponent_var father = study->FindComponent("MED"); + if (CORBA::is_nil(father)) { + // create component + father = studyBuilder->NewComponent("MED"); + // set name attribute + father->SetAttrString("AttributeName", "MEDCalc"); + // set icon attribute + father->SetAttrString("AttributePixMap", "ICO_MED"); + // register component in the study + studyBuilder->DefineComponentInstance(father, MED_Gen::_this()); + // add component to the use case tree + // (to support tree representation customization and drag-n-drop) + useCaseBuilder->SetRootCurrent(); + useCaseBuilder->Append(father); // component object is added as the top level item + } + + // create new sub-object, as a child of the component object + SALOMEDS::SObject_var soDatasource = studyBuilder->NewObject(father); + soDatasource->SetAttrString("AttributeName", fullName.c_str()); + soDatasource->SetAttrString("AttributePixMap", "ICO_DATASOURCE"); + anAttr = studyBuilder->FindOrCreateAttribute(soDatasource, "AttributeParameter"); + aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); + aParam->SetInt("objectid", datasourceHandler.id); + useCaseBuilder->AppendTo(soDatasource->GetFather(), soDatasource); + + // We can add the meshes as children of the datasource + MEDCALC::MeshHandlerList* meshHandlerList = + MEDFactoryClient::getDataManager()->getMeshList(datasourceHandler.id); + + for(CORBA::ULong iMesh=0; iMeshlength(); iMesh++) { + MEDCALC::MeshHandler meshHandler = (*meshHandlerList)[iMesh]; + SALOMEDS::SObject_var soMesh = studyBuilder->NewObject(soDatasource); + soMesh->SetAttrString("AttributeName", meshHandler.name); + soMesh->SetAttrString("AttributePixMap", "ICO_DATASOURCE_MESH"); + anAttr = studyBuilder->FindOrCreateAttribute(soMesh, "AttributeParameter"); + aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); + aParam->SetInt("objectid", meshHandler.id); + anAttr = studyBuilder->FindOrCreateAttribute(soMesh, "AttributeParameter"); + aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); + aParam->SetBool("isInWorkspace", false); + useCaseBuilder->AppendTo(soMesh->GetFather(), soMesh); + + // We add the field timeseries defined on this mesh, as children of the mesh SObject + MEDCALC::FieldseriesHandlerList * fieldseriesHandlerList = + MEDFactoryClient::getDataManager()->getFieldseriesListOnMesh(meshHandler.id); + + for(CORBA::ULong iFieldseries=0; iFieldserieslength(); iFieldseries++) { + MEDCALC::FieldseriesHandler fieldseriesHandler = (*fieldseriesHandlerList)[iFieldseries]; + SALOMEDS::SObject_var soFieldseries = studyBuilder->NewObject(soMesh); + _fieldSeriesEntries[fieldseriesHandler.id] = soFieldseries->GetID(); + + std::string label(fieldseriesHandler.name); + label +=" ("+std::string(mapTypeOfFieldLabel[fieldseriesHandler.type])+")"; + soFieldseries->SetAttrString("AttributeName", label.c_str()); + soFieldseries->SetAttrString("AttributePixMap", "ICO_DATASOURCE_FIELD"); + anAttr = studyBuilder->FindOrCreateAttribute(soFieldseries, "AttributeParameter"); + aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); + aParam->SetInt("objectid", fieldseriesHandler.id); + anAttr = studyBuilder->FindOrCreateAttribute(soFieldseries, "AttributeParameter"); + aParam = SALOMEDS::AttributeParameter::_narrow(anAttr); + aParam->SetBool("isInWorkspace", false); + + useCaseBuilder->AppendTo(soFieldseries->GetFather(), soFieldseries); + soFieldseries->UnRegister(); + } + soMesh->UnRegister(); + } + + // cleanup + father->UnRegister(); + soDatasource->UnRegister(); + } + } + + result = MED_ORB::OP_OK; + return result; +} + +MED_ORB::status +MED::registerPresentation(SALOMEDS::Study_ptr study, + CORBA::Long fieldId, + const char* name, + const char* label) +{ + // set exception handler to catch unexpected CORBA exceptions + Unexpect aCatch(SALOME_SalomeException); + + // set result status to error initially + MED_ORB::status result = MED_ORB::OP_ERROR; + + if (_fieldSeriesEntries.find(fieldId) == _fieldSeriesEntries.end()) { + std::cerr << "Field not found\n"; + return MED_ORB::OP_ERROR ; + } + std::string entry = _fieldSeriesEntries[fieldId]; + //SALOMEDS::SObject_ptr soFieldseries = _studyEditor->findObject(entry.c_str()); + SALOMEDS::SObject_var sobject = study->FindObjectID(entry.c_str()); + SALOMEDS::SObject_ptr soFieldseries = sobject._retn(); + + if (soFieldseries->IsNull()) { + std::cerr << "Entry not found\n"; + return MED_ORB::OP_ERROR; + } + + //SALOMEDS::SObject_var soPresentation = _studyEditor->newObject(soFieldseries); + SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder(); + SALOMEDS::SObject_var soPresentation = studyBuilder->NewObject(soFieldseries); + + //_studyEditor->setName(soPresentation, tr(name.c_str()).toStdString().c_str()); + //_studyEditor->setIcon(soPresentation, tr("ICO_MED_PRESENTATION").toStdString().c_str()); + soPresentation->SetAttrString("AttributeName", name); + soPresentation->SetAttrString("AttributePixMap", label); + + + result = MED_ORB::OP_OK; + return result; +} + +Engines::TMPFile* +MED::DumpPython(CORBA::Object_ptr theStudy, + CORBA::Boolean isPublished, + CORBA::Boolean isMultiFile, + CORBA::Boolean& isValidScript) +{ + std::cout << "In MED::DumpPython\n"; + + SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy); + if(CORBA::is_nil(aStudy)) { + std::cerr << "Error: Cannot find the study\n"; + return new Engines::TMPFile(0); + } + + SALOMEDS::SObject_var aSO = aStudy->FindComponent("MED"); + if(CORBA::is_nil(aSO)) { + std::cerr << "Error: Cannot find component MED\n"; + return new Engines::TMPFile(0); + } + + TCollection_AsciiString aScript; + + aScript += "dumping MED"; + + int aLen = aScript.Length(); + unsigned char* aBuffer = new unsigned char[aLen+1]; + strcpy((char*)aBuffer, aScript.ToCString()); + + CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer; + Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1); + + isValidScript = true; + return aStreamFile._retn(); +} + +extern "C" +{ + /*! + \brief Exportable factory function: create an instance of the MED component engine + \param orb reference to the ORB + \param poa reference to the POA + \param contId CORBA object ID, pointing to the owner SALOME container + \param instanceName SALOME component instance name + \param interfaceName SALOME component interface name + \return CORBA object identifier of the registered servant + */ + //PortableServer::ObjectId* MEDEngine_factory( CORBA::ORB_ptr orb, + PortableServer::ObjectId* MEDEngine_factory(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId* contId, + const char* instanceName, + const char* interfaceName) + { + MED* component = new MED(orb, poa, contId, instanceName, interfaceName); + return component->getId(); + } +} diff --git a/src/MEDCalc/cmp/MED.hxx b/src/MEDCalc/cmp/MED.hxx new file mode 100644 index 000000000..196fbdaf2 --- /dev/null +++ b/src/MEDCalc/cmp/MED.hxx @@ -0,0 +1,81 @@ +// Copyright (C) 2015 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _MED_HXX_ +#define _MED_HXX_ + +#ifdef WIN32 +# if defined MEDENGINE_EXPORTS || defined MEDEngine_EXPORTS +# define MEDENGINE_EXPORT __declspec( dllexport ) +# else +# define MEDENGINE_EXPORT __declspec( dllimport ) +# endif +#else +# define MEDENGINE_EXPORT +#endif + +#include +#include CORBA_SERVER_HEADER(MED_Gen) +#include CORBA_SERVER_HEADER(MEDDataManager) +#include CORBA_CLIENT_HEADER(SALOMEDS) +#include +#include + +#include +#include + +class MEDENGINE_EXPORT MED : + public POA_MED_ORB::MED_Gen, + public Engines_Component_i +{ +public: + MED(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId* contId, + const char* instanceName, + const char* interfaceName); + virtual ~MED(); + + MED_ORB::status addDatasourceToStudy(SALOMEDS::Study_ptr study, + const MEDCALC::DatasourceHandler& datasourceHandler); + + MED_ORB::status registerPresentation(SALOMEDS::Study_ptr study, + CORBA::Long fieldId, + const char* name, + const char* label); + + /*! Dump the study as a Python file */ + virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy, + CORBA::Boolean isPublished, + CORBA::Boolean isMultiFile, + CORBA::Boolean& isValidScript); + + private: + std::map _fieldSeriesEntries; +}; + +extern "C" +MEDENGINE_EXPORT +PortableServer::ObjectId* MEDEngine_factory( CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId* contId, + const char* instanceName, + const char* interfaceName ); + +#endif diff --git a/src/MEDCalc/cmp/MEDFactoryClient.cxx b/src/MEDCalc/cmp/MEDFactoryClient.cxx index 2066cead9..747286ac5 100644 --- a/src/MEDCalc/cmp/MEDFactoryClient.cxx +++ b/src/MEDCalc/cmp/MEDFactoryClient.cxx @@ -31,7 +31,7 @@ namespace MEDFactoryClient { static MEDCALC::MEDFactory_ptr engine; if(CORBA::is_nil(engine)){ Engines::EngineComponent_var component = - KERNEL::getLifeCycleCORBA()->FindOrLoad_Component( "FactoryServer","MEDFactory" ); + KERNEL::getLifeCycleCORBA()->FindOrLoad_Component( "FactoryServer","MEDFactory" ); engine = MEDCALC::MEDFactory::_narrow(component); } return engine; diff --git a/src/MEDCalc/gui/DatasourceController.cxx b/src/MEDCalc/gui/DatasourceController.cxx index 386fa5e2d..6a9c77204 100644 --- a/src/MEDCalc/gui/DatasourceController.cxx +++ b/src/MEDCalc/gui/DatasourceController.cxx @@ -22,10 +22,23 @@ #include "DatasourceController.hxx" #include "DatasourceConstants.hxx" +#include +#include +#include + +#include +#include + +#include +#include +#include + #include "MEDFactoryClient.hxx" +#include "MEDModule.hxx" #include "QtHelper.hxx" #include CORBA_CLIENT_HEADER(SALOMEDS) +#include CORBA_CLIENT_HEADER(SALOMEDS_Attributes) #include #include @@ -40,8 +53,8 @@ // Datasource controller // ============================================================== // -DatasourceController::DatasourceController(StandardApp_Module * salomeModule) - : _fieldSeriesEntries() +//DatasourceController::DatasourceController(StandardApp_Module * salomeModule) +DatasourceController::DatasourceController(MEDModule * salomeModule) { STDLOG("Creating a DatasourceController"); _salomeModule = salomeModule; @@ -63,6 +76,10 @@ DatasourceController::~DatasourceController() { } void DatasourceController::createActions() { + //QWidget* dsk = _salomeModule->getApp()->desktop(); + //SUIT_ResourceMgr* resMgr = _salomeModule->getApp()->resourceMgr(); + int toolbarId = _salomeModule->createTool("Datasource", "DatasourceToolbar"); + // // Main actions (toolbar and menubar) // @@ -71,17 +88,21 @@ void DatasourceController::createActions() { QString icon = tr("ICO_DATASOURCE_ADD"); int actionId; actionId = _salomeModule->createStandardAction(label,this, SLOT(OnAddDatasource()),icon,tooltip); - _salomeModule->addActionInToolbar(actionId); + //_salomeModule->addActionInToolbar(actionId); + _salomeModule->createTool(actionId, toolbarId); // This action has to be placed in the general file menu with the label "Import MED file" int menuId = _salomeModule->createMenu( tr( "MEN_FILE" ), -1, 1 ); - _salomeModule->addActionInMenubar(actionId, menuId); + //_salomeModule->addActionInMenubar(actionId, menuId); + _salomeModule->action(actionId)->setIconVisibleInMenu(true); + _salomeModule->createMenu(actionId, menuId, 10); label = tr("LAB_ADD_IMAGE_SOURCE"); tooltip = tr("TIP_ADD_IMAGE_SOURCE"); icon = tr("ICO_IMAGE_ADD"); actionId = _salomeModule->createStandardAction(label,this, SLOT(OnAddImagesource()),icon,tooltip); - _salomeModule->addActionInToolbar(actionId); + // _salomeModule->addActionInToolbar(actionId); + _salomeModule->createTool(actionId, toolbarId); // // Actions for popup menu only @@ -142,47 +163,13 @@ DatasourceController::updateTreeViewWithNewDatasource(const MEDCALC::DatasourceH return; } - // We need a studyEditor updated on the active study - _studyEditor->updateActiveStudy(); + SalomeApp_Study* study = dynamic_cast(_salomeModule->application()->activeStudy()); + _PTR(Study) studyDS = study->studyDS(); - // Create a datasource SObject as a father of the module root - SALOMEDS::SComponent_var root = _studyEditor->findRoot(QCHARSTAR(_salomeModule->moduleName())); - SALOMEDS::SObject_var soDatasource = _studyEditor->newObject(root); - _studyEditor->setName(soDatasource,datasourceHandler->name); - _studyEditor->setIcon(soDatasource,tr("ICO_DATASOURCE").toStdString().c_str()); - _studyEditor->setParameterInt(soDatasource,OBJECT_ID,datasourceHandler->id); - - // We can add the meshes as children of the datasource - MEDCALC::MeshHandlerList * meshHandlerList = - MEDFactoryClient::getDataManager()->getMeshList(datasourceHandler->id); - - for(CORBA::ULong iMesh=0; iMeshlength(); iMesh++) { - MEDCALC::MeshHandler meshHandler = (*meshHandlerList)[iMesh]; - SALOMEDS::SObject_var soMesh = _studyEditor->newObject(soDatasource); - _studyEditor->setName(soMesh,meshHandler.name); - _studyEditor->setIcon(soMesh,tr("ICO_DATASOURCE_MESH").toStdString().c_str()); - _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 - MEDCALC::FieldseriesHandlerList * fieldseriesHandlerList = - MEDFactoryClient::getDataManager()->getFieldseriesListOnMesh(meshHandler.id); - - for(CORBA::ULong iFieldseries=0; iFieldserieslength(); iFieldseries++) { - MEDCALC::FieldseriesHandler fieldseriesHandler = (*fieldseriesHandlerList)[iFieldseries]; - SALOMEDS::SObject_var soFieldseries = _studyEditor->newObject(soMesh); - _fieldSeriesEntries[fieldseriesHandler.id] = soFieldseries->GetID(); - - std::string label(fieldseriesHandler.name); - label +=" ("+std::string(XmedDataObject::mapTypeOfFieldLabel[fieldseriesHandler.type])+")"; - _studyEditor->setName(soFieldseries,label.c_str()); - - _studyEditor->setIcon(soFieldseries,tr("ICO_DATASOURCE_FIELD").toStdString().c_str()); - _studyEditor->setParameterInt(soFieldseries,OBJECT_ID,fieldseriesHandler.id); - _studyEditor->setParameterBool(soFieldseries,OBJECT_IS_IN_WORKSPACE,false); - } - } + _salomeModule->engine()->addDatasourceToStudy(_CAST(Study, studyDS)->GetStudy(), *datasourceHandler); + + // update Object browser + _salomeModule->getApp()->updateObjectBrowser(true); } void @@ -193,21 +180,17 @@ DatasourceController::updateTreeViewWithNewPresentation(long fieldId, long prese return; } - if (_fieldSeriesEntries.find(fieldId) == _fieldSeriesEntries.end()) { - std::cerr << "Field not found\n"; - return; - } - std::string entry = _fieldSeriesEntries[fieldId]; - SALOMEDS::SObject_ptr soFieldseries = _studyEditor->findObject(entry.c_str()); - if (soFieldseries->IsNull()) { - std::cerr << "Entry not found\n"; - return; - } - std::string name = MEDFactoryClient::getPresentationManager()->getPresentationProperty(presentationId, "name"); - SALOMEDS::SObject_var soPresentation = _studyEditor->newObject(soFieldseries); - _studyEditor->setName(soPresentation, tr(name.c_str()).toStdString().c_str()); - _studyEditor->setIcon(soPresentation, tr("ICO_MED_PRESENTATION").toStdString().c_str()); + name = tr(name.c_str()).toStdString(); + std::string label = tr("ICO_MED_PRESENTATION").toStdString(); + + SalomeApp_Study* study = dynamic_cast(_salomeModule->application()->activeStudy()); + _PTR(Study) studyDS = study->studyDS(); + + _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId, name.c_str(), label.c_str()); + + // update Object browser + _salomeModule->getApp()->updateObjectBrowser(true); } void DatasourceController::OnAddDatasource() @@ -593,10 +576,8 @@ DatasourceController::processWorkspaceEvent(const MEDCALC::MedEvent* event) if ( event->type == MEDCALC::EVENT_ADD_DATASOURCE ) { MEDCALC::DatasourceHandler* datasourceHandler = MEDFactoryClient::getDataManager()->getDatasourceHandler(event->filename); this->updateTreeViewWithNewDatasource(datasourceHandler); - _salomeModule->updateObjBrowser(true); } else if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) { this->updateTreeViewWithNewPresentation(event->dataId, event->presentationId); - _salomeModule->updateObjBrowser(true); } } diff --git a/src/MEDCalc/gui/DatasourceController.hxx b/src/MEDCalc/gui/DatasourceController.hxx index 0ec0a1806..09cf69a7f 100644 --- a/src/MEDCalc/gui/DatasourceController.hxx +++ b/src/MEDCalc/gui/DatasourceController.hxx @@ -25,12 +25,11 @@ #include "MEDEventListener_i.hxx" #include #include CORBA_CLIENT_HEADER(MEDDataManager) -#include +//#include +#include #include #include -#include - #include "XmedDataModel.hxx" #include "DlgChangeUnderlyingMesh.hxx" #include "DlgInterpolateField.hxx" @@ -66,6 +65,8 @@ typedef struct { QString objectalias; } DatasourceEvent; +class MEDModule; + // // ============================================================== // Datasource controller @@ -75,7 +76,9 @@ class MEDCALCGUI_EXPORT DatasourceController: public QObject { Q_OBJECT public: - DatasourceController(StandardApp_Module * salomeModule); + //DatasourceController(StandardApp_Module * salomeModule); + //DatasourceController(SalomeApp_Module * salomeModule); + DatasourceController(MEDModule * salomeModule); ~DatasourceController(); void createActions(); @@ -105,9 +108,9 @@ private: void updateTreeViewWithNewPresentation(long fieldId, long presentationId); private: - StandardApp_Module * _salomeModule; + //StandardApp_Module * _salomeModule; + MEDModule* _salomeModule; SALOME_AppStudyEditor * _studyEditor; - std::map _fieldSeriesEntries; DlgChangeUnderlyingMesh * _dlgChangeUnderlyingMesh; DlgInterpolateField * _dlgInterpolateField; diff --git a/src/MEDCalc/gui/MEDModule.cxx b/src/MEDCalc/gui/MEDModule.cxx index 0f255328e..460f88ebd 100644 --- a/src/MEDCalc/gui/MEDModule.cxx +++ b/src/MEDCalc/gui/MEDModule.cxx @@ -22,46 +22,138 @@ #include "MEDModule.hxx" #include "QtHelper.hxx" -#include -#include CORBA_CLIENT_HEADER(SALOMEDS) +#include "SALOME_LifeCycleCORBA.hxx" +#include "QtxPopupMgr.h" + +#include +#include +#include +#include -#include "MEDFactoryClient.hxx" #ifndef DISABLE_PVVIEWER #include "PVViewer_ViewModel.h" #endif +//! The only instance of the reference to engine +MED_ORB::MED_Gen_var MEDModule::myEngine; + MEDModule::MEDModule() : - StandardApp_Module() + SalomeApp_Module("MED") { // Note also that we can't use the getApp() function here because // the initialize(...) function has not been called yet. - this->setModuleName("MED"); + init(); // internal initialization } -// -// ===================================================================== -// This part implements the mandatory interface -// ===================================================================== -// +MEDModule::~MEDModule() +{ + // nothing to do +} -/*! - * Returns the engine of the XMED module, i.e. the SALOME component - * associated to the study root of the module. - */ -Engines::EngineComponent_ptr MEDModule::getEngine() const { - return MEDFactoryClient::getFactory(); +MED_ORB::MED_Gen_var +MEDModule::engine() +{ + init(); // initialize engine, if necessary + return myEngine; } -/*! - * Returns the base file name of the image used for the icon's - * module. The file is supposed to be located in the resource - * directory of the module. - */ -QString MEDModule::studyIconName() { +void +MEDModule::init() +{ + // initialize MED module engine (load, if necessary) + if ( CORBA::is_nil( myEngine ) ) { + Engines::EngineComponent_var comp = + SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" ); + myEngine = MED_ORB::MED_Gen::_narrow( comp ); + } +} + +void +MEDModule::initialize( CAM_Application* app ) +{ + // call the parent implementation + SalomeApp_Module::initialize( app ); + + // The following initializes the GUI widget and associated actions + this->createModuleWidgets(); + this->createModuleActions(); +} + +QString +MEDModule::engineIOR() const +{ + init(); // initialize engine, if necessary + CORBA::String_var anIOR = getApp()->orb()->object_to_string( myEngine.in() ); + return QString( anIOR.in() ); +} + +QString +MEDModule::iconName() const +{ return tr("ICO_MED_SMALL"); } +void +MEDModule::windows( QMap& theMap ) const +{ + // want Object browser, in the left area + theMap.insert( SalomeApp_Application::WT_ObjectBrowser, + Qt::LeftDockWidgetArea ); +#ifndef DISABLE_PYCONSOLE + // want Python console, in the bottom area + theMap.insert( SalomeApp_Application::WT_PyConsole, + Qt::BottomDockWidgetArea ); +#endif +} + +void +MEDModule::viewManagers( QStringList& list ) const +{ +#ifndef DISABLE_PVVIEWER + list.append( PVViewer_Viewer::Type() ); +#endif +} + +bool +MEDModule::activateModule( SUIT_Study* theStudy ) +{ + if ( CORBA::is_nil( myEngine ) ) + return false; + + // call parent implementation + bool bOk = SalomeApp_Module::activateModule( theStudy ); + if (!bOk) + return false; + + // show own menus + setMenuShown( true ); + // show own toolbars + setToolShown( true ); + + //this->createStudyComponent(theStudy); + _workspaceController->showDockWidgets(true); + //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE); + + // return the activation status + return bOk; +} + +bool +MEDModule::deactivateModule( SUIT_Study* theStudy ) +{ + _workspaceController->showDockWidgets(false); + //this->unsetDockLayout(); + + // hide own menus + setMenuShown( false ); + // hide own toolbars + setToolShown( false ); + + // call parent implementation and return the activation status + return SalomeApp_Module::deactivateModule( theStudy ); +} + // // ===================================================================== // This part add custom widgets (a dockwidget containing a tree view @@ -75,7 +167,8 @@ QString MEDModule::studyIconName() { * creates the widgets specific for this module, in particular the * workspace widget and the dataspace widget. */ -void MEDModule::createModuleWidgets() { +void +MEDModule::createModuleWidgets() { _datasourceController = new DatasourceController(this); _workspaceController = new WorkspaceController(this); _xmedDataModel = new XmedDataModel(); @@ -88,30 +181,55 @@ void MEDModule::createModuleWidgets() { _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent *))); } -bool MEDModule::activateModule( SUIT_Study* theStudy ) -{ - bool bOk = StandardApp_Module::activateModule( theStudy ); - _workspaceController->showDockWidgets(true); - this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE); - return bOk; -} -bool MEDModule::deactivateModule( SUIT_Study* theStudy ) -{ - _workspaceController->showDockWidgets(false); - this->unsetDockLayout(); - return StandardApp_Module::deactivateModule( theStudy ); -} - -void MEDModule::createModuleActions() { +void +MEDModule::createModuleActions() { // Creating actions concerning the dataspace _datasourceController->createActions(); // Creating actions concerning the workspace _workspaceController->createActions(); } -void MEDModule::viewManagers( QStringList& list ) const +int +MEDModule::createStandardAction(const QString& label, + QObject * slotobject, + const char* slotmember, + const QString& iconName, + const QString& tooltip) { -#ifndef DISABLE_PVVIEWER - list.append( PVViewer_Viewer::Type() ); -#endif + SUIT_Desktop* dsk = getApp()->desktop(); + SUIT_ResourceMgr* resMgr = getApp()->resourceMgr(); + + // If the tooltip is not defined, we choose instead the label text. + QString effToolTip(tooltip); + if ( effToolTip.isEmpty() ) + effToolTip = label; + + QAction* action = createAction(-1, + label, + resMgr->loadPixmap("MED", iconName), + label, + effToolTip, + 0, + dsk, + false, + slotobject, + slotmember + ); + return actionId(action); +} + +void +MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule) +{ + // _GBO_ for a fine customization of the rule (for example with a + // test on the type of the selected object), see the LIGTH module: + // implement "LightApp_Selection* createSelection() const;" + int parentId = -1; + QtxPopupMgr* mgr = this->popupMgr(); + this->action( actionId )->setIconVisibleInMenu(true); + if (! menus.isEmpty()) + mgr->insert ( this->action( actionId ), menus, parentId, 0 ); + else + mgr->insert ( this->action( actionId ), parentId, 0 ); + mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule ); } diff --git a/src/MEDCalc/gui/MEDModule.hxx b/src/MEDCalc/gui/MEDModule.hxx index a34a508a1..6a64fea26 100644 --- a/src/MEDCalc/gui/MEDModule.hxx +++ b/src/MEDCalc/gui/MEDModule.hxx @@ -22,21 +22,23 @@ #ifndef _MED_MODULE_HXX_ #define _MED_MODULE_HXX_ -#include "StandardApp_Module.hxx" +#include "MEDCALCGUI.hxx" + +#include #include "WorkspaceController.hxx" #include "XmedDataModel.hxx" #include "DatasourceController.hxx" #include -#include CORBA_SERVER_HEADER(SALOME_Component) +#include CORBA_CLIENT_HEADER(MED_Gen) -#include "MEDCALCGUI.hxx" +class SalomeApp_Application; /*! * This class defines the gui of the MED module. */ -class MEDCALCGUI_EXPORT MEDModule: public StandardApp_Module +class MEDCALCGUI_EXPORT MEDModule: public SalomeApp_Module { Q_OBJECT @@ -46,20 +48,39 @@ class MEDCALCGUI_EXPORT MEDModule: public StandardApp_Module public: MEDModule(); - void viewManagers( QStringList& ) const; + ~MEDModule(); + + static MED_ORB::MED_Gen_var engine(); + + virtual void initialize( CAM_Application* app ); + virtual QString engineIOR() const; -protected: - virtual Engines::EngineComponent_ptr getEngine() const; - virtual QString studyIconName(); - virtual void createModuleWidgets(); - virtual void createModuleActions(); - virtual bool activateModule( SUIT_Study* theStudy ); - virtual bool deactivateModule( SUIT_Study* theStudy ); + virtual QString iconName() const; + + virtual void windows( QMap& theMap ) const; + virtual void viewManagers( QStringList& theList ) const; + + int createStandardAction(const QString& label, + QObject * slotobject, + const char* slotmember, + const QString& iconName, + const QString& tooltip=QString()); + void addActionInPopupMenu(int actionId,const QString& menus="",const QString& rule="client='ObjectBrowser'"); + +public slots: + virtual bool activateModule( SUIT_Study* theStudy ); + virtual bool deactivateModule( SUIT_Study* theStudy ); + +private: + void createModuleWidgets(); + void createModuleActions(); + static void init(); private: DatasourceController * _datasourceController; WorkspaceController * _workspaceController; XmedDataModel * _xmedDataModel; + static MED_ORB::MED_Gen_var myEngine; }; #endif diff --git a/src/MEDCalc/gui/WorkspaceController.cxx b/src/MEDCalc/gui/WorkspaceController.cxx index c7d281002..c873c26c5 100644 --- a/src/MEDCalc/gui/WorkspaceController.cxx +++ b/src/MEDCalc/gui/WorkspaceController.cxx @@ -22,6 +22,7 @@ #include "WorkspaceController.hxx" #include "QtHelper.hxx" #include "MEDFactoryClient.hxx" +#include "MEDModule.hxx" #include "XmedDataModel.hxx" #include "DlgAlias.hxx" @@ -32,13 +33,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(StandardApp_Module * salomeModule) +WorkspaceController::WorkspaceController(MEDModule * salomeModule) : TreeGuiManager(salomeModule->getApp(), "Workspace") { _salomeModule = salomeModule; @@ -97,6 +100,7 @@ WorkspaceController::WorkspaceController(StandardApp_Module * salomeModule) } WorkspaceController::~WorkspaceController() { + std::cout << "WorkspaceController::~WorkspaceController()\n"; MEDEventListener_i::release(); } @@ -106,18 +110,23 @@ WorkspaceController::~WorkspaceController() { * connected slots. */ void WorkspaceController::createActions() { + QWidget* dsk = _salomeModule->getApp()->desktop(); + SUIT_ResourceMgr* resMgr = _salomeModule->getApp()->resourceMgr(); + int toolbarId = _salomeModule->createTool("Workspace", "WorkspaceToolbar"); QString label = tr("LAB_SAVE_WORKSPACE"); 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->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->addActionInToolbar(actionId); + _salomeModule->createTool(actionId, toolbarId); } /*! @@ -474,6 +483,7 @@ void WorkspaceController::processDatasourceEvent(const DatasourceEvent * event) XmedDataObject * dataObject = event->objectdata; if ( event->eventtype == DatasourceEvent::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 diff --git a/src/MEDCalc/gui/WorkspaceController.hxx b/src/MEDCalc/gui/WorkspaceController.hxx index 45bc32927..28317ca8e 100644 --- a/src/MEDCalc/gui/WorkspaceController.hxx +++ b/src/MEDCalc/gui/WorkspaceController.hxx @@ -30,10 +30,13 @@ #include #include CORBA_CLIENT_HEADER(MEDDataManager) -#include +//#include +#include #include +class MEDModule; + /*! * This class defines a DockWidget plugged in the SALOME application, * and containing a tree view for rendering a hierarchical data @@ -44,7 +47,8 @@ class MEDCALCGUI_EXPORT WorkspaceController: public TreeGuiManager { Q_OBJECT public: - WorkspaceController(StandardApp_Module * salomeModule); + //WorkspaceController(StandardApp_Module * salomeModule); + WorkspaceController(MEDModule * salomeModule); ~WorkspaceController(); void createActions(); @@ -64,7 +68,8 @@ signals: private: XmedConsoleDriver * _consoleDriver; - StandardApp_Module * _salomeModule; + //StandardApp_Module * _salomeModule; + MEDModule * _salomeModule; void _importItem(QString itemNameId); void _importItemList(QStringList itemNameIdList); void _importFieldIntoConsole(MEDCALC::FieldHandler * fieldHandler, -- 2.39.2