From ac44b8b991e8926b95d61b62d6382a61c0dc6cfe Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 18 Oct 2012 06:29:03 +0000 Subject: [PATCH] Initial integration of SimanIO support and SIMAN study interfaces --- src/Container/Component_i.cxx | 32 +++++++ src/Container/Makefile.am | 5 +- src/Container/SALOME_ComponentPy.py | 6 ++ src/Container/SALOME_Component_i.hxx | 3 + src/Container/SALOME_DataContainerPy.py | 86 +++++++++++++++++++ src/Container/SALOME_DataContainer_i.cxx | 103 +++++++++++++++++++++++ src/Container/SALOME_DataContainer_i.hxx | 65 ++++++++++++++ 7 files changed, 299 insertions(+), 1 deletion(-) create mode 100755 src/Container/SALOME_DataContainerPy.py create mode 100644 src/Container/SALOME_DataContainer_i.cxx create mode 100644 src/Container/SALOME_DataContainer_i.hxx diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index 3e77256aa..e7ef49a3a 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -1077,6 +1077,38 @@ Engines_Component_i::configureSalome_file(std::string service_name, // By default this method does nothing } +//============================================================================= +/*! + * C++ method: allows to import data file into the Component internal data + structure (like import operation of BRep file in GEOM module). + * \param studyId identifier of the working study + * \param data container of the file content + * \param options additional options for import (if needed) + */ +//============================================================================= +Engines::ListOfIdentifiers* Engines_Component_i::importData(CORBA::Long studyId, + Engines::DataContainer_ptr data, + const Engines::ListOfOptions& options) +{ + // By default this method does nothing + Engines::ListOfIdentifiers_var aList = new Engines::ListOfIdentifiers; + return aList._retn(); +} + +//============================================================================= +/*! + * C++ method: allows to export data files from the Component internal data + structure (like Export operation of Step file in GEOM module). + * \param studyId identifier of the working study + */ +//============================================================================= +Engines::ListOfData* Engines_Component_i::getModifiedData(CORBA::Long studyId) +{ + // By default this method does nothing + Engines::ListOfData_var aList = new Engines::ListOfData; + return aList._retn(); +} + //============================================================================= /*! * C++ method: return the name of the container associated with this component diff --git a/src/Container/Makefile.am b/src/Container/Makefile.am index 7243153df..2d7a75c8c 100644 --- a/src/Container/Makefile.am +++ b/src/Container/Makefile.am @@ -37,6 +37,7 @@ include $(top_srcdir)/salome_adm/unix/make_common_starter.am salomeinclude_HEADERS = \ SALOME_Component_i.hxx \ SALOME_Container_i.hxx \ + SALOME_DataContainer_i.hxx \ SALOME_FileTransfer_i.hxx \ SALOME_FileRef_i.hxx \ SALOME_ContainerManager.hxx \ @@ -48,7 +49,8 @@ salomeinclude_HEADERS = \ dist_salomescript_PYTHON =\ SALOME_ComponentPy.py \ SALOME_PyNode.py \ - SALOME_Container.py + SALOME_Container.py \ + SALOME_DataContainerPy.py # These files are executable scripts dist_salomescript_SCRIPTS=\ @@ -106,6 +108,7 @@ lib_LTLIBRARIES = libSalomeContainer.la libSalomeContainer_la_SOURCES=\ Component_i.cxx \ Container_i.cxx \ + SALOME_DataContainer_i.cxx \ SALOME_FileTransfer_i.cxx \ SALOME_FileRef_i.cxx \ Container_init_python.cxx \ diff --git a/src/Container/SALOME_ComponentPy.py b/src/Container/SALOME_ComponentPy.py index 55ec0ff55..8659025fc 100755 --- a/src/Container/SALOME_ComponentPy.py +++ b/src/Container/SALOME_ComponentPy.py @@ -314,3 +314,9 @@ class SALOME_ComponentPy_i (Engines__POA.EngineComponent): def getObjectInfo(self, studyId, entry): return "" + + def importData(self, studyId, dataContainer, options): + return [] # no implmenetation by default + + def getModifiedData(self, studyId): + return [] # no implmenetation by default diff --git a/src/Container/SALOME_Component_i.hxx b/src/Container/SALOME_Component_i.hxx index 94fd62ce8..0cbbdd8b2 100644 --- a/src/Container/SALOME_Component_i.hxx +++ b/src/Container/SALOME_Component_i.hxx @@ -146,6 +146,9 @@ public: std::string file_port_name, Salome_file_i * file); + virtual Engines::ListOfIdentifiers* importData( + CORBA::Long studyId, Engines::DataContainer_ptr data, const Engines::ListOfOptions& options); + virtual Engines::ListOfData* getModifiedData(CORBA::Long studyId); protected: int _studyId; // -1: not initialised; 0: multiStudy; >0: study diff --git a/src/Container/SALOME_DataContainerPy.py b/src/Container/SALOME_DataContainerPy.py new file mode 100755 index 000000000..ea2808c26 --- /dev/null +++ b/src/Container/SALOME_DataContainerPy.py @@ -0,0 +1,86 @@ +#! /usr/bin/env python +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +# +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# 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. +# +# 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 +# + +# SALOME DataContainer : implementation of data container +# File : SALOME_DataContainerPy.py +# Author : Mikhail PONIKARIOV +# Module : SALOME +# $Header$ +# +import os +import sys +import string + +from omniORB import CORBA, PortableServer +import Engines, Engines__POA +from SALOME_ComponentPy import * + +#============================================================================= + +#define an implementation of the data container interface for the data transfer implemented in Python + +class SALOME_DataContainerPy_i (Engines__POA.DataContainer): + _url = "" + _name = "" + _identifier = "" + _ext = -1 + _removeAfterGet = True; + + #------------------------------------------------------------------------- + + def __init__(self, url, name, identifier, removeAfterGet): + self._url = url + self._name = name + self._identifier = identifier + self._removeAfterGet = removeAfterGet + self._ext = url[url.rfind(".") + 1 : ] + + #------------------------------------------------------------------------- + + def get(self): + f = open(self._url, 'r') + stream = f.read() + f.close() + if self._removeAfterGet: + os.remove(self._url) + try: # try to remove directory if it is empty + index = max(self._url.rfind("\\"), self._url.rfind("/")) + if index > 0: + os.rmdir(self._url[:index]) + except: + pass + return stream + + #------------------------------------------------------------------------- + + def name(self): + return self._name + + #------------------------------------------------------------------------- + + def identifier(self): + return self._identifier + + def extension(self): + return self._ext diff --git a/src/Container/SALOME_DataContainer_i.cxx b/src/Container/SALOME_DataContainer_i.cxx new file mode 100644 index 000000000..2085bd2c1 --- /dev/null +++ b/src/Container/SALOME_DataContainer_i.cxx @@ -0,0 +1,103 @@ +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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. +// +// 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 +// + +// SALOME DataContainer : implementation of data container +// File : SALOME_DataContainer_i.cxx +// Author : Mikhail PONIKAROV +// Module : SALOME +// $Header$ +// + +#include + +#include +#include + +using namespace std; + +Engines_DataContainer_i::Engines_DataContainer_i() +{ +} + +Engines_DataContainer_i::Engines_DataContainer_i(const char* url, + const char* name, const char* identifier, const bool removeAfterGet) + : myName(name), myIdentifier(identifier), myURL(url), myRemoveAfterGet(removeAfterGet) +{ + std::string anExtension(url); + if (anExtension.rfind(".") != std::string::npos) { // keep only extension + myExt = anExtension.substr(anExtension.rfind(".") + 1); + } else myExt = ""; +} + +Engines_DataContainer_i::~Engines_DataContainer_i() +{ +} + +Engines::TMPFile* Engines_DataContainer_i::get() +{ + // open file to make stream from its content +#ifdef WIN32 + ifstream aFile(myURL.c_str(), std::ios::binary); +#else + ifstream aFile(myURL.c_str()); +#endif + if (!aFile.good()) { + std::cerr<<"File "< +#include CORBA_SERVER_HEADER(SALOME_Component) + +#include + +class CONTAINER_EXPORT Engines_DataContainer_i: + public POA_Engines::DataContainer +{ +public: + Engines_DataContainer_i(); + Engines_DataContainer_i(const char* url, + const char* name, + const char* identifier, + const bool removeAfterGet); + virtual ~Engines_DataContainer_i(); + + // --- CORBA methods + virtual Engines::TMPFile* get(); + virtual char* name(); + virtual char* identifier(); + virtual char* extension(); + +protected: + + std::string myExt; ///< extension (type) of the file + std::string myName; ///< name of the document corresponding to this data + std::string myIdentifier; ///< module identifier of the document corresponding to this data + std::string myURL; ///< path to the locally located file + bool myRemoveAfterGet; ///< if this flag is true, file must be removed after the first "get" method call +}; + +#endif -- 2.39.2