From 4175df2323fb2acb51119252d60e7e08cf331c13 Mon Sep 17 00:00:00 2001 From: rraphael Date: Mon, 8 Feb 2021 19:32:54 +0100 Subject: [PATCH] Add shaper standalone executable without CORBA --- .../SALOMEDSImpl_ChildIterator.hxx | 2 +- .../SALOMEDSImpl_SComponentIterator.hxx | 2 +- .../SALOMEDSImpl_UseCaseBuilder.cxx | 9 + .../SALOMEDSImpl_UseCaseBuilder.hxx | 2 + .../SALOMEDSImpl_UseCaseIterator.cxx | 11 + .../SALOMEDSImpl_UseCaseIterator.hxx | 4 +- src/TOOLSDS/CMakeLists.txt | 4 +- src/TOOLSDS/SALOMEDS_Tool.cxx | 262 ++++++++++++------ src/TOOLSDS/SALOMEDS_Tool.hxx | 77 ++++- 9 files changed, 264 insertions(+), 109 deletions(-) diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_ChildIterator.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_ChildIterator.hxx index 804d2f053..476f20c55 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_ChildIterator.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_ChildIterator.hxx @@ -34,7 +34,7 @@ class SALOMEDSIMPL_EXPORT SALOMEDSImpl_ChildIterator { -private: +protected: DF_ChildIterator _it; SALOMEDSImpl_SObject _so; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_SComponentIterator.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_SComponentIterator.hxx index 9d85ce653..cfe568d28 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_SComponentIterator.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_SComponentIterator.hxx @@ -39,7 +39,7 @@ class SALOMEDSIMPL_EXPORT SALOMEDSImpl_SComponentIterator { -private: +protected: DF_ChildIterator _it; DF_Label _lab; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx index f46495393..397d5526b 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx @@ -94,6 +94,15 @@ SALOMEDSImpl_UseCaseBuilder::SALOMEDSImpl_UseCaseBuilder(DF_Document* theDocumen } } +//============================================================================ +/*! Function : copy constructor + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_UseCaseBuilder::SALOMEDSImpl_UseCaseBuilder(SALOMEDSImpl_UseCaseBuilder* aCopy): + _root(aCopy->_root), _doc(aCopy->_doc), _lastChild(aCopy->_lastChild), _childIndex(aCopy->_childIndex) +{} + //============================================================================ /*! Function : destructor * Purpose : diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.hxx index 72e2216ff..4fea9f8a4 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.hxx @@ -52,6 +52,8 @@ public: //! standard constructor SALOMEDSImpl_UseCaseBuilder(DF_Document* theDocument); + SALOMEDSImpl_UseCaseBuilder(SALOMEDSImpl_UseCaseBuilder* aCopy); + //! standard destructor virtual ~SALOMEDSImpl_UseCaseBuilder(); diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.cxx index 608aadcb9..854724493 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.cxx @@ -54,6 +54,17 @@ SALOMEDSImpl_UseCaseIterator::SALOMEDSImpl_UseCaseIterator(const DF_Label& theLa } } +SALOMEDSImpl_UseCaseIterator::SALOMEDSImpl_UseCaseIterator(const SALOMEDSImpl_UseCaseIterator *itr) + :SALOMEDSImpl_UseCaseIterator() +{ + if(!itr) + return; + _it = itr->_it; + _node = itr->_node; + _guid = itr->_guid; + _levels = itr->_levels; +} + //============================================================================ /*! Function : destructor * Purpose : diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.hxx index cade5ce71..a6266aed0 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.hxx @@ -38,7 +38,7 @@ class SALOMEDSIMPL_EXPORT SALOMEDSImpl_UseCaseIterator { -private: +protected: std::string _guid; bool _levels; SALOMEDSImpl_AttributeTreeNode* _node; @@ -48,6 +48,8 @@ public: SALOMEDSImpl_UseCaseIterator(); + SALOMEDSImpl_UseCaseIterator(const SALOMEDSImpl_UseCaseIterator *itr); + //! standard constructor SALOMEDSImpl_UseCaseIterator(const DF_Label& theLabel, const std::string& theGUID, diff --git a/src/TOOLSDS/CMakeLists.txt b/src/TOOLSDS/CMakeLists.txt index 81520c256..06bb3fb8b 100644 --- a/src/TOOLSDS/CMakeLists.txt +++ b/src/TOOLSDS/CMakeLists.txt @@ -26,12 +26,14 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMELocalTrace ${CMAKE_CURRENT_SOURCE_DIR}/../Basics ${CMAKE_CURRENT_SOURCE_DIR}/../Utils + ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMEDSImpl + ${CMAKE_CURRENT_SOURCE_DIR}/../DF ${PROJECT_BINARY_DIR}/idl ) ADD_LIBRARY(TOOLSDS SALOMEDS_Tool.cxx) ADD_DEFINITIONS(${OMNIORB_DEFINITIONS} ${HDF5_DEFINITIONS} ${BOOST_DEFINITIONS}) -TARGET_LINK_LIBRARIES(TOOLSDS OpUtil SalomeIDLKernel ${OMNIORB_LIBRARIES}) +TARGET_LINK_LIBRARIES(TOOLSDS OpUtil SalomeIDLKernel ${OMNIORB_LIBRARIES} SalomeDSImpl) INSTALL(TARGETS TOOLSDS EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") diff --git a/src/TOOLSDS/SALOMEDS_Tool.cxx b/src/TOOLSDS/SALOMEDS_Tool.cxx index b9f4f5e63..ddae415c4 100644 --- a/src/TOOLSDS/SALOMEDS_Tool.cxx +++ b/src/TOOLSDS/SALOMEDS_Tool.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE, CSGROUP // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -45,10 +45,12 @@ #include #include +#include +#ifndef DISABLE_ORB #include #include CORBA_SERVER_HEADER(SALOMEDS_Attributes) - +#endif bool Exists(const std::string thePath) { return Kernel_Utils::IsExists(thePath); @@ -168,38 +170,37 @@ void SALOMEDS_Tool::RemoveTemporaryFiles(const std::string& theDirectory, //============================================================================ namespace { - SALOMEDS::TMPFile* - PutFilesToStream(const std::string& theFromDirectory, - const std::vector& theFiles, - const std::vector& theFileNames, - const int theNamesOnly) + long filesToStream(const std::string& theFromDirectory, + const std::vector& theFiles, + const std::vector& theFileNames, + const int theNamesOnly, unsigned char*& aBuffer) { int i, aLength = (int)theFiles.size(); //!< TODO: conversion from size_t to int if(aLength == 0) - return (new SALOMEDS::TMPFile); - + return 0; + //Get a temporary directory for saved a file std::string aTmpDir = theFromDirectory; - + long aBufferSize = 0; long aCurrentPos; - + int aNbFiles = 0; int* aFileNameSize= new int[aLength]; long* aFileSize= new long[aLength]; - + //Determine the required size of the buffer - + for(i=0; i 4) ? 4 : sizeof(int))); - - + memcpy(aBuffer, &aNbFiles, ((sizeof(int) > 4) ? 4 : sizeof(int))); + + aCurrentPos = 4; - + for(i=0; i 4) ? 4 : sizeof(int))); + memcpy((aBuffer + aCurrentPos), (aFileNameSize + i), ((sizeof(int) > 4) ? 4 : sizeof(int))); aCurrentPos += 4; - + //Copy the file name to the buffer memcpy((aBuffer + aCurrentPos), theFileNames[i].c_str(), aFileNameSize[i]); aCurrentPos += aFileNameSize[i]; - + if (!theNamesOnly) { // mpv 15.01.2003: we don't copy file content to the buffer if !theNamesOnly //Initialize 8 bytes of the buffer by 0 - memset((aBuffer + aCurrentPos), 0, 8); + memset((aBuffer + aCurrentPos), 0, 8); //Copy the length of the file to the buffer memcpy((aBuffer + aCurrentPos), (aFileSize + i), ((sizeof(long) > 8) ? 8 : sizeof(long))); aCurrentPos += 8; - + aFile->seekg(0, std::ios::beg); - aFile->read((char *)(aBuffer + aCurrentPos), aFileSize[i]); + aFile->read((char *)(aBuffer + aCurrentPos), aFileSize[i]); aFile->close(); delete(aFile); aCurrentPos += aFileSize[i]; } } - + delete[] aFileNameSize; delete[] aFileSize; - + return aBufferSize; + } +#ifndef DISABLE_ORB + SALOMEDS::TMPFile* + PutFilesToStream(const std::string& theFromDirectory, + const std::vector& theFiles, + const std::vector& theFileNames, + const int theNamesOnly) + { + + + unsigned char* aBuffer; + long aBufferSize = filesToStream(theFromDirectory, theFiles, theFileNames, theNamesOnly, aBuffer); + + if(!aBufferSize) + return (new SALOMEDS::TMPFile); CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer; return (new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1)); } - -} +#else + +SALOMEDSImpl_Tool::TMPFile* +PutFilesToStreamImp(const std::string& theFromDirectory, + const std::vector& theFiles, + const std::vector& theFileNames, + const int theNamesOnly) +{ + + unsigned char* aBuffer; + long aBufferSize = filesToStream(theFromDirectory, theFiles, theFileNames, theNamesOnly, aBuffer); + if(!aBufferSize) + return nullptr; + return (new SALOMEDSImpl_Tool::TMPFile(aBufferSize, aBuffer, 1)); +} +#endif +} + +#ifndef DISABLE_ORB SALOMEDS::TMPFile* SALOMEDS_Tool::PutFilesToStream(const std::string& theFromDirectory, const ListOfFiles& theFiles, @@ -300,79 +333,127 @@ SALOMEDS_Tool::PutFilesToStream(const ListOfFiles& theFiles, { return ::PutFilesToStream("",theFiles,theFileNames,0); } +#else -//============================================================================ -// function : PutStreamToFile -// purpose : converts the stream "theStream" to the files -//============================================================================ -SALOMEDS_Tool::ListOfFiles -SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream, - const std::string& theToDirectory, +SALOMEDSImpl_Tool::TMPFile* +SALOMEDS_Tool::PutFilesToStreamImpl(const std::string& theFromDirectory, + const ListOfFiles& theFiles, const int theNamesOnly) { - ListOfFiles aFiles; + ListOfFiles aFileNames(theFiles); + return ::PutFilesToStreamImp(theFromDirectory,theFiles,aFileNames,theNamesOnly); +} - if(theStream.length() == 0) - return aFiles; +SALOMEDSImpl_Tool::TMPFile* +SALOMEDS_Tool::PutFilesToStreamImpl(const ListOfFiles& theFiles, + const ListOfFiles& theFileNames) +{ + return ::PutFilesToStreamImp("",theFiles,theFileNames,0); +} +#endif - //Get a temporary directory for saving a file - std::string aTmpDir = theToDirectory; - unsigned char *aBuffer = (unsigned char*)theStream.NP_data(); +namespace { + template - if(aBuffer == NULL) - return aFiles; + SALOMEDS_Tool::ListOfFiles PutStreamToFiles(const TMPFile& theStream, + const std::string& theToDirectory, + const int theNamesOnly) + { + SALOMEDS_Tool::ListOfFiles aFiles; + + if(theStream.length() == 0) + return aFiles; + + //Get a temporary directory for saving a file + std::string aTmpDir = theToDirectory; + unsigned char *aBuffer = (unsigned char*)theStream.NP_data(); + + if(aBuffer == NULL) + return aFiles; - long aFileSize, aCurrentPos = 4; - int i, aFileNameSize, aNbFiles = 0; + long aFileSize, aCurrentPos = 4; + int i, aFileNameSize, aNbFiles = 0; - //Copy the number of files in the stream - memcpy(&aNbFiles, aBuffer, sizeof(int)); + //Copy the number of files in the stream + memcpy(&aNbFiles, aBuffer, sizeof(int)); - aFiles.reserve(aNbFiles); + aFiles.reserve(aNbFiles); - for(i=0; i 4) ? 4 : sizeof(int))); - aCurrentPos += 4; + //Put a length of the file name to aFileNameSize + memcpy(&aFileNameSize, (aBuffer + aCurrentPos), ((sizeof(int) > 4) ? 4 : sizeof(int))); + aCurrentPos += 4; - char *aFileName = new char[aFileNameSize]; - //Put a file name to aFileName - memcpy(aFileName, (aBuffer + aCurrentPos), aFileNameSize); + char *aFileName = new char[aFileNameSize]; + //Put a file name to aFileName + memcpy(aFileName, (aBuffer + aCurrentPos), aFileNameSize); #ifdef WIN32 - for (int j = 0; j < strlen(aFileName); j++) - { - if (aFileName[j] == ':') - aFileName[j] = '_'; - } + for (int j = 0; j < strlen(aFileName); j++) + { + if (aFileName[j] == ':') + aFileName[j] = '_'; + } #endif - aCurrentPos += aFileNameSize; - - //Put a length of the file to aFileSize - if (!theNamesOnly) { - memcpy(&aFileSize, (aBuffer + aCurrentPos), ((sizeof(long) > 8) ? 8 : sizeof(long))); - aCurrentPos += 8; - - std::string aFullPath = aTmpDir + aFileName; + aCurrentPos += aFileNameSize; + + //Put a length of the file to aFileSize + if (!theNamesOnly) { + memcpy(&aFileSize, (aBuffer + aCurrentPos), ((sizeof(long) > 8) ? 8 : sizeof(long))); + aCurrentPos += 8; + + std::string aFullPath = aTmpDir + aFileName; #ifdef WIN32 #ifdef UNICODE - std::ofstream aFile(Kernel_Utils::utf8_decode_s(aFullPath).c_str(), std::ios::binary); + std::ofstream aFile(Kernel_Utils::utf8_decode_s(aFullPath).c_str(), std::ios::binary); #else - std::ofstream aFile(aFullPath.c_str(), std::ios::binary); + std::ofstream aFile(aFullPath.c_str(), std::ios::binary); #endif #else - std::ofstream aFile(aFullPath.c_str()); + std::ofstream aFile(aFullPath.c_str()); #endif - aFile.write((char *)(aBuffer + aCurrentPos), aFileSize); - aFile.close(); - aCurrentPos += aFileSize; + aFile.write((char *)(aBuffer + aCurrentPos), aFileSize); + aFile.close(); + aCurrentPos += aFileSize; + } + aFiles.push_back(aFileName); + delete[] aFileName; } - aFiles.push_back(CORBA::string_dup(aFileName)); - delete[] aFileName; + + return aFiles; + } +} + +#ifndef DISABLE_ORB +//============================================================================ +// function : PutStreamToFile +// purpose : converts the stream "theStream" to the files +//============================================================================ +SALOMEDS_Tool::ListOfFiles +SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream, + const std::string& theToDirectory, + const int theNamesOnly) +{ + ListOfFiles aFiles0 = ::PutStreamToFiles(theStream, theToDirectory, theNamesOnly); + + ListOfFiles aFiles; + + for(unsigned i=0; i< aFiles0.size(); i++) { + aFiles.push_back(CORBA::string_dup(aFiles0[i].c_str())); } return aFiles; } +#else + +SALOMEDS_Tool::ListOfFiles +SALOMEDS_Tool::PutStreamToFilesImpl(const SALOMEDSImpl_Tool::TMPFile& theStream, + const std::string& theToDirectory, + const int theNamesOnly) +{ + return ::PutStreamToFiles(theStream, theToDirectory, theNamesOnly); +} +#endif //============================================================================ // function : GetNameFromPath @@ -438,6 +519,7 @@ std::string SALOMEDS_Tool::GetDirFromPath(const std::string& thePath) { return path; } +#ifndef DISABLE_ORB //======================================================================= // name : GetFlag // Purpose : Retrieve specified flaf from "AttributeFlags" attribute @@ -525,5 +607,5 @@ void SALOMEDS_Tool::GetAllChildren( SALOMEDS::Study_var theStudy, } } } - +#endif diff --git a/src/TOOLSDS/SALOMEDS_Tool.hxx b/src/TOOLSDS/SALOMEDS_Tool.hxx index 62807ce8c..cc841cb99 100644 --- a/src/TOOLSDS/SALOMEDS_Tool.hxx +++ b/src/TOOLSDS/SALOMEDS_Tool.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE, CSGROUP // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -30,14 +30,17 @@ #define __SALOMEDS_Tool_H__ #include -#include +#include #include #include // IDL headers +#include "SALOMEDSImpl_TMPFile.hxx" +#ifndef DISABLE_ORB #include "SALOMEconfig.h" #include CORBA_SERVER_HEADER(SALOMEDS) +#endif #ifdef WIN32 # if defined TOOLSDS_EXPORTS @@ -49,45 +52,78 @@ # define TOOLSDS_EXPORT #endif -class TOOLSDS_EXPORT SALOMEDS_Tool +#ifdef DISABLE_ORB +namespace SALOMEDSImpl_Tool { + + TOOLSDS_EXPORT class TMPFile: public SALOMEDSImpl_TMPFile + { + public: + explicit TMPFile(long buffSize, unsigned char* streamBuff, bool isRelative): + _myStreamBuff(streamBuff), _myBuffSize(buffSize), _myIsRelative(isRelative) + {} + inline long length() const + {return _myBuffSize;} + + inline unsigned char* NP_data() const + {return _myStreamBuff;} + + inline bool IsRelative() const + {return _myIsRelative;} + TMPFile() = default; + ~TMPFile() = default; + + private: + unsigned char* _myStreamBuff; + unsigned _myBuffSize; + bool _myIsRelative; + + virtual size_t Size() override + {return 0;} + virtual TOctet& Get(size_t) override + {return _myStreamBuff[0];} + }; +} +#endif + +class TOOLSDS_EXPORT SALOMEDS_Tool { public: typedef std::vector ListOfFiles; - + // Returns the unique temporary directory, that is defined in SALOME_TMP_DIR if this variable is set // otherwise return /tmp/something/ for Unix or c:\something\ for WIN32 static std::string GetTmpDir(); - + // Removes files which are in , the files for deletion are listed in // if is true is also deleted if it is empty static void RemoveTemporaryFiles(const std::string& theDirectory, const ListOfFiles& theFiles, const bool IsDirDeleted); + // Returns the name by the path + // for an example: if thePath = "/tmp/aaa/doc1.hdf" the function returns "doc1" + static std::string GetNameFromPath(const std::string& thePath); + + // Returns the directory by the path + // for an example: if thePath = "/tmp/aaa/doc1.hdf" the function returns "/tmp/aaa" + static std::string GetDirFromPath(const std::string& thePath); + + #ifndef DISABLE_ORB // Converts files listed in which are in into a byte sequence TMPFile - static SALOMEDS::TMPFile* PutFilesToStream(const std::string& theFromDirectory, + static SALOMEDS::TMPFile* PutFilesToStream(const std::string& theFromDirectory, const ListOfFiles& theFiles, const int theNamesOnly = 0); // Converts files listed in which will be named as pointed in the into a byte sequence TMPFile static SALOMEDS::TMPFile* PutFilesToStream(const ListOfFiles& theFiles, const ListOfFiles& theFileNames); - // Converts a byte sequence to files and places them in static ListOfFiles PutStreamToFiles(const SALOMEDS::TMPFile& theStream, const std::string& theToDirectory, const int theNamesOnly = 0); - // Returns the name by the path - // for an example: if thePath = "/tmp/aaa/doc1.hdf" the function returns "doc1" - static std::string GetNameFromPath(const std::string& thePath); - - // Returns the directory by the path - // for an example: if thePath = "/tmp/aaa/doc1.hdf" the function returns "/tmp/aaa" - static std::string GetDirFromPath(const std::string& thePath); - // Retrieves specified flaf from "AttributeFlags" attribute static bool GetFlag( const int theFlag, SALOMEDS::Study_var theStudy, @@ -103,7 +139,18 @@ public: static void GetAllChildren( SALOMEDS::Study_var theStudy, SALOMEDS::SObject_var theObj, std::list& theList ); +#else + static SALOMEDSImpl_Tool::TMPFile* PutFilesToStreamImpl(const std::string& theFromDirectory, + const ListOfFiles& theFiles, + const int theNamesOnly = 0); + + static SALOMEDSImpl_Tool::TMPFile* PutFilesToStreamImpl(const ListOfFiles& theFiles, + const ListOfFiles& theFileNames); + static ListOfFiles PutStreamToFilesImpl(const SALOMEDSImpl_Tool::TMPFile& theStream, + const std::string& theToDirectory, + const int theNamesOnly = 0); +#endif }; #endif -- 2.39.2