Salome HOME
Add MED engine
authorCédric Aguerre <cedric.aguerre@edf.fr>
Mon, 14 Sep 2015 12:43:37 +0000 (14:43 +0200)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Mon, 14 Sep 2015 13:02:47 +0000 (15:02 +0200)
13 files changed:
idl/CMakeLists.txt
idl/MED_Gen.idl [new file with mode: 0644]
resources/MEDCatalog.xml.in
src/MEDCalc/cmp/CMakeLists.txt
src/MEDCalc/cmp/MED.cxx [new file with mode: 0644]
src/MEDCalc/cmp/MED.hxx [new file with mode: 0644]
src/MEDCalc/cmp/MEDFactoryClient.cxx
src/MEDCalc/gui/DatasourceController.cxx
src/MEDCalc/gui/DatasourceController.hxx
src/MEDCalc/gui/MEDModule.cxx
src/MEDCalc/gui/MEDModule.hxx
src/MEDCalc/gui/WorkspaceController.cxx
src/MEDCalc/gui/WorkspaceController.hxx

index 69c3b4a6cf16d7ef589bd22257b4db5a9c20f474..09229bd42ccb7001875b06ef5b4b59143f422058 100644 (file)
@@ -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 (file)
index 0000000..3230a35
--- /dev/null
@@ -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
index 4f0429fcf7d3358f6325dbdb5ec4905a2caae36c..dc81f9b7bce835a14e7601703f00903387e9c82f 100644 (file)
                 <component-multistudy>0</component-multistudy>
         </component>
 
+        <component>
+            <component-name>MED</component-name>
+            <component-username>Med</component-username>
+            <component-type>MED</component-type>
+            <component-version>@SALOMEMED_VERSION@</component-version>
+            <component-comment>MED component engine</component-comment>
+            <component-multistudy>0</component-multistudy>
+        </component>
+
 </component-list>
 </begin-catalog>
index 1c54b6c75902a4b5c25ad768e75c6f3309370863..175ad0eda196676d3eac15cecdb53d2e289225ca 100644 (file)
@@ -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 (file)
index 0000000..ff3ab86
--- /dev/null
@@ -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 <SALOMEconfig.h>
+#include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
+
+#include <SALOMEDS_SObject.hxx>
+
+#include <Utils_ExceptHandlers.hxx>
+#include <TCollection_AsciiString.hxx>
+
+#include <string>
+
+/*!
+  \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; iMesh<meshHandlerList->length(); 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; iFieldseries<fieldseriesHandlerList->length(); 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 (file)
index 0000000..196fbda
--- /dev/null
@@ -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 <SALOMEconfig.h>
+#include CORBA_SERVER_HEADER(MED_Gen)
+#include CORBA_SERVER_HEADER(MEDDataManager)
+#include CORBA_CLIENT_HEADER(SALOMEDS)
+#include <SALOME_Component_i.hxx>
+#include <SALOMEDS_Study.hxx>
+
+#include <map>
+#include <string>
+
+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<long, std::string> _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
index 2066cead98af4c2eccca94901495dbb24b233f9b..747286ac5a950d7ee7f0780ef96da31bad10e6d0 100644 (file)
@@ -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;
index 386fa5e2d1bea47fc9164f873d8149d9bbc8b559..6a9c77204954a103a905c6335439d5207b04439f 100644 (file)
 #include "DatasourceController.hxx"
 #include "DatasourceConstants.hxx"
 
+#include <SalomeApp_Application.h>
+#include <SalomeApp_Study.h>
+#include <SalomeApp_DataObject.h>
+
+#include <SALOME_ListIO.hxx>
+#include <LightApp_SelectionMgr.h>
+
+#include <SALOME_LifeCycleCORBA.hxx>
+#include <SALOMEDS_SObject.hxx>
+#include <SALOMEDS_Study.hxx>
+
 #include "MEDFactoryClient.hxx"
+#include "MEDModule.hxx"
 #include "QtHelper.hxx"
 
 #include CORBA_CLIENT_HEADER(SALOMEDS)
+#include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
 #include <SUIT_FileDlg.h>
 #include <SUIT_Desktop.h>
 
@@ -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<SalomeApp_Study*>(_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; iMesh<meshHandlerList->length(); 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; iFieldseries<fieldseriesHandlerList->length(); 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<SalomeApp_Study*>(_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);
   }
 }
index 0ec0a180669c4ee54be8c18e0d843f29fc27934c..09cf69a7ff27fc69544f06841fe8127b99d77044 100644 (file)
 #include "MEDEventListener_i.hxx"
 #include <SALOMEconfig.h>
 #include CORBA_CLIENT_HEADER(MEDDataManager)
-#include <StandardApp_Module.hxx>
+//#include <StandardApp_Module.hxx>
+#include <SalomeApp_Module.h>
 #include <SALOME_AppStudyEditor.hxx>
 #include <MEDPresentation.hxx>
 
-#include <map>
-
 #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<long, std::string> _fieldSeriesEntries;
 
   DlgChangeUnderlyingMesh * _dlgChangeUnderlyingMesh;
   DlgInterpolateField * _dlgInterpolateField;
index 0f255328eabf4f259b18cc772af325502f70c923..460f88ebd4c3e5ad85331f4a3239da7d8dbf5e89 100644 (file)
 #include "MEDModule.hxx"
 #include "QtHelper.hxx"
 
-#include <SALOMEconfig.h>
-#include CORBA_CLIENT_HEADER(SALOMEDS)
+#include "SALOME_LifeCycleCORBA.hxx"
+#include "QtxPopupMgr.h"
+
+#include <SUIT_Desktop.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+#include <SalomeApp_Study.h>
 
-#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<int, int>& 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 );
 }
index a34a508a15588bb07371f5dbe0b68c0dcfdbe54d..6a64fea267659ced7077f9a1502cc8d693222514 100644 (file)
 #ifndef _MED_MODULE_HXX_
 #define _MED_MODULE_HXX_
 
-#include "StandardApp_Module.hxx"
+#include "MEDCALCGUI.hxx"
+
+#include <SalomeApp_Module.h>
 
 #include "WorkspaceController.hxx"
 #include "XmedDataModel.hxx"
 #include "DatasourceController.hxx"
 
 #include <SALOMEconfig.h>
-#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<int, int>& 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
index c7d281002520951dd0e440aec893bb3d2dd6784f..c873c26c5fa388b24d5f7bcb36160b6d070b0e65 100644 (file)
@@ -22,6 +22,7 @@
 #include "WorkspaceController.hxx"
 #include "QtHelper.hxx"
 #include "MEDFactoryClient.hxx"
+#include "MEDModule.hxx"
 #include "XmedDataModel.hxx"
 #include "DlgAlias.hxx"
 
 #include <SALOME_LifeCycleCORBA.hxx>
 #include <SUIT_FileDlg.h>
 #include <SUIT_Desktop.h>
+#include <SUIT_ResourceMgr.h>
 
 /*!
  * 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"<<dataObject->toString());
     // _GBO_ QUESTION: tag automatically the object as a peristant object ??
     // We first add the data object to the internal data model
index 45bc32927c91ec253f7e16faf5cc9fd271100d1b..28317ca8e5f7a70aeb9941523e2bbadd1a10df78 100644 (file)
 
 #include <SALOMEconfig.h>
 #include CORBA_CLIENT_HEADER(MEDDataManager)
-#include <StandardApp_Module.hxx>
+//#include <StandardApp_Module.hxx>
+#include <SalomeApp_Module.h>
 
 #include <vector>
 
+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,