#define VARIABLE_SEPARATOR ':'
#define OPERATION_SEPARATOR '|'
+//to disable automatic genericobj management comment the following line
+#define WITHGENERICOBJ
+
+#ifdef WITHGENERICOBJ
+#include "SALOME_GenericObj_i.hh"
+static CORBA::ORB_var getORB()
+{
+ int argc=0;
+ return CORBA::ORB_init(argc,0);
+}
+#endif
//============================================================================
/*! Function : SALOMEDSImpl_Study
*/
//============================================================================
SALOMEDSImpl_Study::SALOMEDSImpl_Study(const DF_Document* doc,
- const string& study_name)
+ const string& study_name)
{
_name = study_name;
_doc = (DF_Document*)doc;
ID = SC.GetID();
if(aComponentID == ID)
{
- // ComponentID found
- _find = true;
+ // ComponentID found
+ _find = true;
compo = SC;
}
}
for (; it.More();it.Next()){
if(!_find)
{
- SALOMEDSImpl_SComponent SC = it.Value();
- if (SC.GetName() == anObjectName)
- {
- _find = true;
- RefSO = SC;
-
- }
- if (!_find) RefSO = _FindObject(SC, anObjectName, _find);
+ SALOMEDSImpl_SComponent SC = it.Value();
+ if (SC.GetName() == anObjectName)
+ {
+ _find = true;
+ RefSO = SC;
+
+ }
+ if (!_find) RefSO = _FindObject(SC, anObjectName, _find);
}
}
if(!RefSO) _errorCode = "No object was found";
*/
//============================================================================
vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindObjectByName(const string& anObjectName,
- const string& aComponentName)
+ const string& aComponentName)
{
_errorCode = "";
SALOMEDSImpl_SObject CSO = it.Value();
if ( CSO.GetName() == anObjectName ) {
- /* add to list */
- listSO.push_back(CSO) ;
+ /* add to list */
+ listSO.push_back(CSO) ;
}
/* looks also for eventual children */
for ( ; anIterator.More(); anIterator.Next() ) {
aLabel = anIterator.Value();
if((anAttr=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
- if(anAttr->Value() == aToken) {
- if(i == (len-1)) { //The searched label is found (no part of the path is left)
- return GetSObject(aLabel);
- }
-
- anIterator.Init(aLabel, false);
- break;
- }
+ if(anAttr->Value() == aToken) {
+ if(i == (len-1)) { //The searched label is found (no part of the path is left)
+ return GetSObject(aLabel);
+ }
+
+ anIterator.Init(aLabel, false);
+ break;
+ }
}
}
if(aFather) {
aName = aFather.GetName();
if(!aName.empty() && aName != "") {
- aValue = GetObjectPath(aFather);
- aPath = aValue + aPath;
+ aValue = GetObjectPath(aFather);
+ aPath = aValue + aPath;
}
}
}
SALOMEDSImpl_AttributeLocalID* anID;
if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
if (anID->Value() == DIRECTORYID) {
- SALOMEDSImpl_AttributeName* aName;
- if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
- aResultSeq.push_back(aName->Value());
- }
+ SALOMEDSImpl_AttributeName* aName;
+ if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
+ aResultSeq.push_back(aName->Value());
+ }
}
}
}
SALOMEDSImpl_AttributeLocalID* anID;
if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
if (anID->Value() == FILELOCALID) {
- SALOMEDSImpl_AttributePersistentRef* aName;
- if ((aName=(SALOMEDSImpl_AttributePersistentRef*)aLabel.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
- std::string aFileName = aName->Value();
- if (aFileName.size() > 0)
- aResultSeq.push_back(aFileName.substr(strlen(FILEID), aFileName.size()));
- }
+ SALOMEDSImpl_AttributePersistentRef* aName;
+ if ((aName=(SALOMEDSImpl_AttributePersistentRef*)aLabel.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
+ std::string aFileName = aName->Value();
+ if (aFileName.size() > 0)
+ aResultSeq.push_back(aFileName.substr(strlen(FILEID), aFileName.size()));
+ }
}
}
}
*/
//============================================================================
SALOMEDSImpl_SObject SALOMEDSImpl_Study::_FindObject(const SALOMEDSImpl_SObject& SO,
- const string& theObjectName,
- bool& _find)
+ const string& theObjectName,
+ bool& _find)
{
SALOMEDSImpl_SObject RefSO;
if(!SO) return RefSO;
for (; it.More(); it.Next()){
if(!_find)
{
- if ((anAttr=(SALOMEDSImpl_AttributeName*)it.Value().FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
- {
+ if ((anAttr=(SALOMEDSImpl_AttributeName*)it.Value().FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
+ {
string Val(anAttr->Value());
- if (Val == theObjectName)
- {
- RefSO = GetSObject(it.Value());
- _find = true;
- }
- }
- if (!_find) RefSO = _FindObject(GetSObject(it.Value()), theObjectName, _find);
+ if (Val == theObjectName)
+ {
+ RefSO = GetSObject(it.Value());
+ _find = true;
+ }
+ }
+ if (!_find) RefSO = _FindObject(GetSObject(it.Value()), theObjectName, _find);
}
}
return RefSO;
//============================================================================
SALOMEDSImpl_SObject
SALOMEDSImpl_Study::_FindObjectIOR(const SALOMEDSImpl_SObject& SO,
- const string& theObjectIOR,
- bool& _find)
+ const string& theObjectIOR,
+ bool& _find)
{
SALOMEDSImpl_SObject RefSO, aSO;
if(!SO) return RefSO;
for (; it.More();it.Next()){
if(!_find)
{
- if ((anAttr=(SALOMEDSImpl_AttributeIOR*)it.Value().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID())))
- {
+ if ((anAttr=(SALOMEDSImpl_AttributeIOR*)it.Value().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID())))
+ {
string Val(anAttr->Value());
- if (Val == theObjectIOR)
- {
- RefSO = GetSObject(it.Value());
- _find = true;
- }
- }
- aSO = GetSObject(it.Value());
- if (!_find) RefSO = _FindObjectIOR(aSO, theObjectIOR, _find);
+ if (Val == theObjectIOR)
+ {
+ RefSO = GetSObject(it.Value());
+ _find = true;
+ }
+ }
+ aSO = GetSObject(it.Value());
+ if (!_find) RefSO = _FindObjectIOR(aSO, theObjectIOR, _find);
}
}
return RefSO;
_errorCode = "";
DF_Label aLabel = DF_Label::Label(_doc->Main(), anEntry, true);
if (myIORLabels.find(anIOR) != myIORLabels.end()) myIORLabels.erase(anIOR);
+#ifdef WITHGENERICOBJ
+ else
+ {
+ // if the ior was not already registered, incref the genericobj (if it's one)
+ CORBA::Object_var obj;
+ SALOME::GenericObj_var gobj;
+ try
+ {
+ obj = getORB()->string_to_object(anIOR.c_str());
+ gobj = SALOME::GenericObj::_narrow(obj);
+ if(! CORBA::is_nil(gobj) )
+ {
+ gobj->Register();
+ }
+ }
+ catch(const CORBA::Exception& e)
+ {
+ }
+ }
+#endif
myIORLabels[anIOR] = aLabel;
}
{
if (myIORLabels.find(anIOR) != myIORLabels.end())
{
- //remove the ior entry
+ //remove the ior entry and decref the genericobj (if it's one)
myIORLabels.erase(anIOR);
+#ifdef WITHGENERICOBJ
+ CORBA::Object_var obj;
+ SALOME::GenericObj_var gobj;
+ try
+ {
+ obj = getORB()->string_to_object(anIOR.c_str());
+ gobj = SALOME::GenericObj::_narrow(obj);
+ if(! CORBA::is_nil(gobj) )
+ {
+ gobj->Destroy();
+ }
+ }
+ catch(const CORBA::Exception& e)
+ {
+ }
+#endif
}
}
char aDate[20];
sprintf(aDate, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d",
(int)(aDays[anIndex]), (int)(aMonths[anIndex]), (int)(aYears[anIndex]),
- (int)(aHours[anIndex]), (int)(aMinutes[anIndex]));
+ (int)(aHours[anIndex]), (int)(aMinutes[anIndex]));
aDates.push_back(aDate);
}
return aDates;
*/
//============================================================================
DF_Attribute* SALOMEDSImpl_Study::GetAttribute(const string& theEntry,
- const string& theType)
+ const string& theType)
{
SALOMEDSImpl_SObject aSO = GetSObject(theEntry);
DF_Attribute* anAttr;
*/
//============================================================================
bool SALOMEDSImpl_Study::DumpStudy(const string& thePath,
- const string& theBaseName,
- bool isPublished,
- SALOMEDSImpl_DriverFactory* theFactory)
+ const string& theBaseName,
+ bool isPublished,
+ SALOMEDSImpl_DriverFactory* theFactory)
{
_errorCode = "";
string IOREngine;
try {
if (!sco.ComponentIOR(IOREngine)) {
- if (!aCompType.empty()) {
-
- aDriver = theFactory->GetDriverByType(aCompType);
-
- if (aDriver != NULL) {
- SALOMEDSImpl_StudyBuilder* SB = NewBuilder();
- if(!SB->LoadWith(sco, aDriver)) {
- _errorCode = SB->GetErrorCode();
- return false;
- }
- }
- else continue;
- }
+ if (!aCompType.empty()) {
+
+ aDriver = theFactory->GetDriverByType(aCompType);
+
+ if (aDriver != NULL) {
+ SALOMEDSImpl_StudyBuilder* SB = NewBuilder();
+ if(!SB->LoadWith(sco, aDriver)) {
+ _errorCode = SB->GetErrorCode();
+ return false;
+ }
+ }
+ else continue;
+ }
}
else {
- aDriver = theFactory->GetDriverByIOR(IOREngine);
+ aDriver = theFactory->GetDriverByIOR(IOREngine);
}
} catch(...) {
_errorCode = "Can not restore information to dump it";
}
void dumpSO(const SALOMEDSImpl_SObject& theSO,
- fstream& fp,
- const string& Tab,
- SALOMEDSImpl_Study* theStudy);
+ fstream& fp,
+ const string& Tab,
+ SALOMEDSImpl_Study* theStudy);
//============================================================================
/*! Function : dump
void dumpSO(const SALOMEDSImpl_SObject& theSO,
- fstream& fp,
- const string& Tab,
- SALOMEDSImpl_Study* theStudy)
+ fstream& fp,
+ const string& Tab,
+ SALOMEDSImpl_Study* theStudy)
{
string aTab(Tab), anID(theSO.GetID());
fp << aTab << anID << endl;
*/
//============================================================================
SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const char* theID,
- const char* theModuleName,
- int theSavePoint)
+ const char* theModuleName,
+ int theSavePoint)
{
if(theSavePoint <= 0) return NULL;
SALOMEDSImpl_AttributeParameter* main_ap = GetCommonParameters(theID, theSavePoint);
*/
//============================================================================
bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
- SALOMEDSImpl_SObject theSObject,
- const std::string& theName)
+ SALOMEDSImpl_SObject theSObject,
+ const std::string& theName)
{
SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
for( ; anIter.More(); anIter.Next() )
vector< vector<string> > aSections = ParseVariables( aString );
for( int i = 0, n = aSections.size(); i < n; i++ )
{
- vector<string> aVector = aSections[i];
- for( int j = 0, m = aVector.size(); j < m; j++ )
- {
- string aStr = aVector[j];
- if( aStr.compare( theName ) == 0 )
- return true;
- }
+ vector<string> aVector = aSections[i];
+ for( int j = 0, m = aVector.size(); j < m; j++ )
+ {
+ string aStr = aVector[j];
+ if( aStr.compare( theName ) == 0 )
+ return true;
+ }
}
}
}
*/
//============================================================================
void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
- SALOMEDSImpl_SObject theSObject,
- const std::string& theSource,
- const std::string& theDest)
+ SALOMEDSImpl_SObject theSObject,
+ const std::string& theSource,
+ const std::string& theDest)
{
SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
for( ; anIter.More(); anIter.Next() )
vector< vector<string> > aSections = ParseVariables( aCurrentString );
for( int i = 0, n = aSections.size(); i < n; i++ )
{
- vector<string> aVector = aSections[i];
- for( int j = 0, m = aVector.size(); j < m; j++ )
- {
- string aStr = aVector[j];
- if( aStr.compare( theSource ) == 0 )
- {
- isChanged = true;
- aStr = theDest;
- }
-
- aNewString.append( aStr );
- if( j != m - 1 )
- aNewString.append( ":" );
- }
- if( i != n - 1 )
- aNewString.append( "|" );
+ vector<string> aVector = aSections[i];
+ for( int j = 0, m = aVector.size(); j < m; j++ )
+ {
+ string aStr = aVector[j];
+ if( aStr.compare( theSource ) == 0 )
+ {
+ isChanged = true;
+ aStr = theDest;
+ }
+
+ aNewString.append( aStr );
+ if( j != m - 1 )
+ aNewString.append( ":" );
+ }
+ if( i != n - 1 )
+ aNewString.append( "|" );
}
if( isChanged )
- aStringAttr->SetValue( aNewString );
+ aStringAttr->SetValue( aNewString );
}
}
}