-using namespace std;
// File : SALOMEDS_Tool.cxx
// Created : Mon Oct 21 16:24:34 2002
// Author : Sergey RUIN
#include <sys/time.h>
#include <stdlib.h>
+#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
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<char*>(theDirectory));
+ TCollection_AsciiString aDirName(const_cast<char*>(theDirectory.c_str()));
int i, aLength = theFiles.length();
for(i=0; i<aLength; i++) {
OSD_File anOSDFile(anOSDPath);
if(!anOSDFile.Exists()) continue;
+ OSD_Protection aProtection = anOSDFile.Protection();
+ aProtection.SetUser(OSD_RW);
+ anOSDFile.SetProtection(aProtection);
+
anOSDFile.Remove();
}
// purpose : converts the files from a list 'theFiles' to the stream
//============================================================================
SALOMEDS::TMPFile*
-SALOMEDS_Tool::PutFilesToStream(const char* theFromDirectory,
+SALOMEDS_Tool::PutFilesToStream(const std::string& theFromDirectory,
const SALOMEDS::ListOfFileNames& theFiles,
const int theNamesOnly)
{
int i, aLength = theFiles.length();
- if(aLength == 0) return NULL;
+ if(aLength == 0)
+// return NULL;
+ return (new SALOMEDS::TMPFile);
- TCollection_AsciiString aTmpDir(const_cast<char*>(theFromDirectory)); //Get a temporary directory for saved a file
+ //Get a temporary directory for saved a file
+ TCollection_AsciiString aTmpDir(const_cast<char*>(theFromDirectory.c_str()));
long aBufferSize = 0;
long aCurrentPos;
//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;
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);
for(i=0; i<aLength; i++) {
ifstream *aFile;
if (!theNamesOnly) { // mpv 15.01.2003: we don't open any file if theNamesOnly = true
- 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;
// function : PutStreamToFile
// purpose : converts the stream "theStream" to the files
//============================================================================
-SALOMEDS::ListOfFileNames*
+SALOMEDS::ListOfFileNames_var
SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream,
- const char* theToDirectory,
+ const std::string& theToDirectory,
const int theNamesOnly)
{
- if(theStream.length() == 0) return NULL;
- TCollection_AsciiString aTmpDir(const_cast<char*>(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<char*>(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;
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<char*>(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<char*>(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<SALOMEDS::SObject_var>& 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 );
+ }
+ }
+ }
+}
+
+
+
+
+
+
+
+
+
+
+