X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FTOOLSDS%2FSALOMEDS_Tool.cxx;h=e250257af13543478515d606348f082965e72b12;hb=refs%2Ftags%2FV2_2_3;hp=210c4273940dd87f805f6bcb09f2db8f3f3ec543;hpb=102608ce8b69dd1ea798169e30223b67742ec26d;p=modules%2Fkernel.git diff --git a/src/TOOLSDS/SALOMEDS_Tool.cxx b/src/TOOLSDS/SALOMEDS_Tool.cxx index 210c42739..e250257af 100644 --- a/src/TOOLSDS/SALOMEDS_Tool.cxx +++ b/src/TOOLSDS/SALOMEDS_Tool.cxx @@ -1,4 +1,3 @@ -using namespace std; // File : SALOMEDS_Tool.cxx // Created : Mon Oct 21 16:24:34 2002 // Author : Sergey RUIN @@ -27,11 +26,15 @@ using namespace std; #include #include +#include CORBA_SERVER_HEADER(SALOMEDS_Attributes) + +using namespace std; + //============================================================================ // function : GetTempDir // purpose : Return a temp directory to store created files like "/tmp/sub_dir/" //============================================================================ -char* SALOMEDS_Tool::GetTmpDir() +std::string SALOMEDS_Tool::GetTmpDir() { //Find a temporary directory to store a file @@ -83,18 +86,18 @@ char* SALOMEDS_Tool::GetTmpDir() OSD_Protection aProtection(OSD_RW, OSD_RWX, OSD_RX, OSD_RX); aDir.Build(aProtection); - return CORBA::string_dup(aTmpDir.ToCString()); + return aTmpDir.ToCString(); } //============================================================================ // function : RemoveTemporaryFiles // purpose : Removes files listed in theFileList //============================================================================ -void SALOMEDS_Tool::RemoveTemporaryFiles(const char* theDirectory, +void SALOMEDS_Tool::RemoveTemporaryFiles(const std::string& theDirectory, const SALOMEDS::ListOfFileNames& theFiles, const bool IsDirDeleted) { - TCollection_AsciiString aDirName(const_cast(theDirectory)); + TCollection_AsciiString aDirName(const_cast(theDirectory.c_str())); int i, aLength = theFiles.length(); for(i=0; i(theFromDirectory)); //Get a temporary directory for saved a file + //Get a temporary directory for saved a file + TCollection_AsciiString aTmpDir(const_cast(theFromDirectory.c_str())); long aBufferSize = 0; long aCurrentPos; @@ -146,7 +156,7 @@ SALOMEDS_Tool::PutFilesToStream(const char* theFromDirectory, //Check if the file exists if (!theNamesOnly) { // mpv 15.01.2003: if only file names must be stroed, then size of files is zero - TCollection_AsciiString aFullPath = aTmpDir + strdup(theFiles[i]); + TCollection_AsciiString aFullPath = aTmpDir + CORBA::string_dup(theFiles[i]); OSD_Path anOSDPath(aFullPath); OSD_File anOSDFile(anOSDPath); if(!anOSDFile.Exists()) continue; @@ -168,7 +178,9 @@ SALOMEDS_Tool::PutFilesToStream(const char* theFromDirectory, aBufferSize += 4; //4 bytes for a number of the files that will be written to the stream; unsigned char* aBuffer = new unsigned char[aBufferSize]; - if(aBuffer == NULL) return NULL; + if(aBuffer == NULL) +// return NULL; + return (new SALOMEDS::TMPFile); //Initialize 4 bytes of the buffer by 0 memset(aBuffer, 0, 4); @@ -181,7 +193,7 @@ SALOMEDS_Tool::PutFilesToStream(const char* theFromDirectory, for(i=0; i(theToDirectory)); //Get a temporary directory for saving a file + if(theStream.length() == 0) + return NULL; + + //Get a temporary directory for saving a file + TCollection_AsciiString aTmpDir(const_cast(theToDirectory.c_str())); unsigned char *aBuffer = (unsigned char*)theStream.NP_data(); if(aBuffer == NULL) return NULL; - long aBufferSize = theStream.length(); long aFileSize, aCurrentPos = 4; int i, aFileNameSize, aNbFiles = 0; @@ -277,28 +291,129 @@ SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream, delete[] aFileName; } - return aFiles._retn(); + return aFiles; } //============================================================================ // function : GetNameFromPath // purpose : Returns the name by the path //============================================================================ -char* SALOMEDS_Tool::GetNameFromPath(const char* thePath) { - if (thePath == NULL) return strdup(""); - OSD_Path aPath = OSD_Path(TCollection_AsciiString(strdup(thePath))); +std::string SALOMEDS_Tool::GetNameFromPath(const std::string& thePath) { + if(thePath == "") + return ""; + OSD_Path aPath = OSD_Path(TCollection_AsciiString(const_cast(thePath.c_str()))); TCollection_AsciiString aNameString(aPath.Name()); - return CORBA::string_dup(aNameString.ToCString()); + return aNameString.ToCString(); } //============================================================================ // function : GetDirFromPath // purpose : Returns the dir by the path //============================================================================ -char* SALOMEDS_Tool::GetDirFromPath(const char* thePath) { - if (thePath == NULL) return strdup(""); - OSD_Path aPath = OSD_Path(TCollection_AsciiString(strdup(thePath))); +std::string SALOMEDS_Tool::GetDirFromPath(const std::string& thePath) { + if(thePath == "") + return ""; + OSD_Path aPath = OSD_Path(TCollection_AsciiString(const_cast(thePath.c_str()))); TCollection_AsciiString aDirString(aPath.Trek()); aDirString.ChangeAll('|','/'); - return CORBA::string_dup(aDirString.ToCString()); + return aDirString.ToCString(); +} + +//======================================================================= +// name : GetFlag +// Purpose : Retrieve specified flaf from "AttributeFlags" attribute +//======================================================================= +bool SALOMEDS_Tool::GetFlag( const int theFlag, + SALOMEDS::Study_var theStudy, + SALOMEDS::SObject_var theObj ) +{ + SALOMEDS::GenericAttribute_var anAttr; + if ( !theObj->_is_nil() && theObj->FindAttribute( anAttr, "AttributeFlags" ) ) + { + SALOMEDS::AttributeFlags_var aFlags = SALOMEDS::AttributeFlags::_narrow( anAttr ); + return aFlags->Get( theFlag ); + } + + return false; +} + +//======================================================================= +// name : SetFlag +// Purpose : Set/Unset specified flaf from "AttributeFlags" attribute +//======================================================================= +bool SALOMEDS_Tool::SetFlag( const int theFlag, + SALOMEDS::Study_var theStudy, + const std::string& theEntry, + const bool theValue ) +{ + SALOMEDS::SObject_var anObj = theStudy->FindObjectID(theEntry.c_str()); + + if ( !anObj->_is_nil() ) + { + SALOMEDS::GenericAttribute_var aGAttr; + if ( anObj->FindAttribute( aGAttr, "AttributeFlags" ) ) + { + SALOMEDS::AttributeFlags_var anAttr = SALOMEDS::AttributeFlags::_narrow( aGAttr ); + anAttr->Set( theFlag, theValue ); + } + else if ( theValue ) + { + SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder(); + SALOMEDS::AttributeFlags_var anAttr = SALOMEDS::AttributeFlags::_narrow( + aBuilder->FindOrCreateAttribute( anObj, "AttributeFlags" ) ); + anAttr->Set( theFlag, theValue ); + } + return true; + } + + return false; } + +//======================================================================= +// name : getAllChildren +// Purpose : Get all children of object. +// If theObj is null all objects of study are returned +//======================================================================= +void SALOMEDS_Tool::GetAllChildren( SALOMEDS::Study_var theStudy, + SALOMEDS::SObject_var theObj, + std::list& theList ) +{ + if ( theObj->_is_nil() ) + { + SALOMEDS::SComponentIterator_var anIter = theStudy->NewComponentIterator(); + for ( ; anIter->More(); anIter->Next() ) + { + SALOMEDS::SObject_var anObj = SALOMEDS::SObject::_narrow( anIter->Value() ); + if ( !anObj->_is_nil() ) + { + theList.push_back( anObj ); + GetAllChildren( theStudy, anObj, theList ); + } + } + } + else + { + SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theObj ); + for ( ; anIter->More(); anIter->Next() ) + { + SALOMEDS::SObject_var anObj = anIter->Value(); + SALOMEDS::SObject_var aRef; + if ( !anObj->ReferencedObject( aRef ) ) + { + theList.push_back( anObj ); + GetAllChildren( theStudy, anObj, theList ); + } + } + } +} + + + + + + + + + + +