// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
//
// File : VISUConfig.cc
#include "SUIT_ResourceMgr.h"
#include "SUIT_Session.h"
-#include <SALOMEDSClient_GenericAttribute.hxx>
-#include <SALOMEDSClient_AttributeIOR.hxx>
+#include "SALOMEDSClient_GenericAttribute.hxx"
+#include "SALOMEDSClient_AttributeIOR.hxx"
-#include <SalomeApp_Application.h>
+#include "SalomeApp_Application.h"
+#include "SalomeApp_Study.h"
-using namespace std;
+#include "SALOME_Event.hxx"
+
+#include <qregexp.h>
+
+#include <fstream>
#ifdef _DEBUG_
static int MYDEBUG = 0;
static int MYDEBUG = 0;
#endif
-namespace VISU{
+
+namespace VISU
+{
SUIT_Session*
GetSession()
return GetSession()->resourceMgr();
}
- //===========================================================================
+ //---------------------------------------------------------------------------
QMutex* Base_i::myMutex = NULL; //apo - &VISUMutex;
CORBA::ORB_var Base_i::myOrb;
return CORBA::string_dup(myID.c_str());
}
- //===========================================================================
+ //---------------------------------------------------------------------------
static int mySCnt = 0;
static QMutex aMutex(TRUE);
- Mutex::Mutex(QMutex* theMutex): myMutex(&aMutex){
+ Mutex::Mutex(QMutex* theMutex): myMutex(&aMutex)
+ {
if(MYDEBUG) MESSAGE("Mutex::Mutex : "<<!mySCnt);
if(!mySCnt++)
myMutex->lock();
}
- Mutex::~Mutex(){
+ Mutex::~Mutex()
+ {
if(!(--mySCnt))
myMutex->unlock();
if(MYDEBUG) MESSAGE("Mutex::~Mutex : "<<!mySCnt);
}
- //===========================================================================
- static Storable::TCallbackMap VisuStoreMap;
- string Storable::ToString(){
- ostringstream strOut;
- Storable::DataToStream( strOut, "myComment", GetComment() );
- ToStream(strOut);
- strOut<<ends;
- if(MYDEBUG) MESSAGE("Storable::ToString - "<<strOut.str());
- return strOut.str();
+ //---------------------------------------------------------------------------
+ Storable::TStorableEngineMap Storable::myStorableEngineMap;
+
+ std::string
+ Storable
+ ::ToString()
+ {
+ ostringstream anOutputStream;
+ Storable::DataToStream( anOutputStream, "myComment", GetComment() );
+ ToStream(anOutputStream);
+ anOutputStream<<ends;
+ if(MYDEBUG) MESSAGE("Storable::ToString - "<<anOutputStream.str());
+ return anOutputStream.str();
+ }
+
+
+ //---------------------------------------------------------------
+ CORBA::Boolean
+ Storable
+ ::CanCopy(SALOMEDS::SObject_ptr theObject)
+ {
+ return false;
+ }
+
+
+ //---------------------------------------------------------------
+ bool
+ Storable
+ ::CopyFrom(SALOMEDS::SObject_ptr theObject,
+ CORBA::Long& theObjectID,
+ const std::string& theTmpDir,
+ TFileNames& theFileNames)
+ {
+ TFileName aFileName("copy_persistent");
+ std::string aCopyPersist = theTmpDir + aFileName;
+ std::ofstream anOutputFileStream(aCopyPersist.c_str(), ios::out);
+ anOutputFileStream<<ToString()<<endl;
+
+ theFileNames.push_back(aFileName);
+ theObjectID = 1;
+
+ return true;
}
- void Storable::Registry(const char* theComment, TStorableEngine theEngine)
+
+ //---------------------------------------------------------------
+ void
+ Storable
+ ::RegistryStorableEngine(const std::string& theComment,
+ TStorableEngine theEngine)
{
- if(!VisuStoreMap.insert(TCallbackMap::value_type(theComment,theEngine)).second){
- if(MYDEBUG) MESSAGE("Storable::Registry >> dupliacte registring !!!");
+ if(!myStorableEngineMap.insert(TStorableEngineMap::value_type(theComment, theEngine)).second)
throw std::logic_error("Storable::Registry >> dupliacte registring !!!");
+ }
+
+
+ //---------------------------------------------------------------
+ Storable*
+ Storable
+ ::Create(SALOMEDS::SObject_ptr theSObject,
+ const std::string& theLocalPersistentID,
+ const std::string& thePrefix,
+ CORBA::Boolean theIsMultiFile)
+ {
+ try{
+ QString aString( CorrectPersistentString( theLocalPersistentID ) );
+ TRestoringMap aRestoringMap;
+ StringToMap(aString, aRestoringMap);
+ bool anIsExists;
+ QString aComment = VISU::Storable::FindValue(aRestoringMap, "myComment", &anIsExists);
+ if ( anIsExists ) {
+ TStorableEngineMap::const_iterator anIter = myStorableEngineMap.find(aComment.latin1());
+ if(MYDEBUG) MESSAGE("Storable::Create - "<<aComment.latin1()<<" "<<(anIter != myStorableEngineMap.end()));
+ if(anIter == myStorableEngineMap.end())
+ return NULL;
+ TStorableEngine aStorableEngine = anIter->second;
+ return aStorableEngine(theSObject, aRestoringMap, thePrefix, theIsMultiFile);
+ }
+ }catch(std::exception& exc){
+ INFOS("Follow exception was occured :\n"<<exc.what());
+ }catch(...){
+ INFOS("Unknown exception was occured!");
+ }
+ return NULL;
+ }
+
+
+ //---------------------------------------------------------------
+ VISU::VISUType
+ Storable
+ ::Comment2Type(const std::string& theComment)
+ {
+ if ( theComment == "CURVE" )
+ return VISU::TCURVE;
+ if ( theComment == "TABLE" )
+ return VISU::TTABLE;
+ if ( theComment == "CONTAINER" )
+ return VISU::TCONTAINER;
+ if ( theComment == "MESH" )
+ return VISU::TMESH;
+ if ( theComment == "SCALARMAP" )
+ return VISU::TSCALARMAP;
+ if ( theComment == "PRSMERGER" )
+ return VISU::TSCALARMAP;
+ if ( theComment == "ISOSURFACE" )
+ return VISU::TISOSURFACES;
+ if ( theComment == "DEFORMEDSHAPE" )
+ return VISU::TDEFORMEDSHAPE;
+ if ( theComment == "SCALARMAPONDEFORMEDSHAPE" )
+ return VISU::TSCALARMAPONDEFORMEDSHAPE;
+ if ( theComment == "GAUSSPOINTS" )
+ return VISU::TGAUSSPOINTS;
+ if ( theComment == "PLOT3D" )
+ return VISU::TPLOT3D;
+ if ( theComment == "CUTPLANES" )
+ return VISU::TCUTPLANES;
+ if ( theComment == "CUTLINES" )
+ return VISU::TCUTLINES;
+ if ( theComment == "VECTORS" )
+ return VISU::TVECTORS;
+ if ( theComment == "STREAMLINES" )
+ return VISU::TSTREAMLINES;
+ if ( theComment == "VISUGEN" )
+ return VISU::TVISUGEN;
+ if ( theComment == "VIEWMANAGER" )
+ return VISU::TVIEWMANAGER;
+ if ( theComment == "RESULT" )
+ return VISU::TRESULT;
+ if ( theComment == "XYPLOT" )
+ return VISU::TXYPLOT;
+ if ( theComment == "TABLEVIEW" )
+ return VISU::TTABLEVIEW;
+ if ( theComment == "VIEW3D" )
+ return VISU::TVIEW3D;
+ if ( theComment == "GAUSSVIEW" )
+ return VISU::TGAUSSVIEW;
+ if ( theComment == "ENTITY" )
+ return VISU::TENTITY;
+ if ( theComment == "FAMILY" )
+ return VISU::TFAMILY;
+ if ( theComment == "PART" )
+ return VISU::TPART; // MULTIPR
+ if ( theComment == "GROUP" )
+ return VISU::TGROUP;
+ if ( theComment == "FIELD" )
+ return VISU::TFIELD;
+ if ( theComment == "TIMESTAMP" )
+ return VISU::TTIMESTAMP;
+ if ( theComment == "ANIMATION" )
+ return VISU::TANIMATION;
+ if ( theComment == "ALL" )
+ return VISU::TALL;
+
+ return VISU::TNONE;
+ }
+
+
+ //---------------------------------------------------------------
+ VISU::VISUType
+ Storable
+ ::RestoringMap2Type(const TRestoringMap& theRestoringMap)
+ {
+ QString aComment = Storable::FindValue( theRestoringMap, "myComment", "" );
+ return Comment2Type(aComment.latin1());
+ }
+
+
+ //---------------------------------------------------------------
+ VISU::VISUType
+ Storable
+ ::Stream2Type(const std::string& thePersistentString)
+ {
+ QString aString(thePersistentString.c_str());
+ if(aString.isEmpty())
+ return VISU::TNONE;
+
+ VISU::Storable::TRestoringMap aRestoringMap;
+ Storable::StringToMap( aString, aRestoringMap );
+ return RestoringMap2Type( aRestoringMap );
+ }
+
+
+ //---------------------------------------------------------------
+ VISU::VISUType
+ Storable
+ ::SObject2Type(const _PTR(SObject)& theSObject)
+ {
+ _PTR(GenericAttribute) anAttr;
+ if (theSObject->FindAttribute(anAttr, "AttributeString")) {
+ _PTR(AttributeString) aDataAttr(anAttr);
+ std::string aData = aDataAttr->Value();
+ return Stream2Type(aData);
+ }
+
+ return VISU::TNONE;
+ }
+
+
+ //---------------------------------------------------------------
+ std::string
+ Storable
+ ::CorrectPersistentString(const std::string& thePersistentString)
+ {
+ QString aString(thePersistentString.c_str());
+ if(aString.isEmpty())
+ return aString.latin1();
+
+ VISU::Storable::TRestoringMap aRestoringMap;
+ Storable::StringToMap( aString, aRestoringMap );
+
+ bool anIsFound = false;
+ QString aComment = Storable::FindValue( aRestoringMap, "myComment", &anIsFound );
+ if ( anIsFound ) {
+ if ( aComment == "PRSMERGER" )
+ aString.replace( "myComment=PRSMERGER", "myComment=SCALARMAP" );
}
+
+ return aString.latin1();
}
- void Storable::StrToMap(const QString& theStr, VISU::Storable::TRestoringMap& theMap){
- if(0 && MYDEBUG) MESSAGE("Storable::StrToMap : string="<<theStr);
- QStringList strList = QStringList::split( ";", theStr, false );
+
+ //---------------------------------------------------------------
+ std::string
+ Storable
+ ::FindEntry(SALOMEDS::Study_ptr theStudyDocument,
+ const std::string& theStartEntry,
+ const TRestoringMap& theRestoringMap,
+ int IsAllLevels)
+ {
+ SALOMEDS::SObject_var aSObject = theStudyDocument->FindObjectID(theStartEntry.c_str());
+ SALOMEDS::ChildIterator_var anIter = theStudyDocument->NewChildIterator(aSObject);
+ anIter->InitEx(IsAllLevels);
+ for(; anIter->More(); anIter->Next()) {
+ aSObject = anIter->Value();
+ SALOMEDS::GenericAttribute_var anAttr;
+ if (aSObject->FindAttribute(anAttr,"AttributeString")) {
+ SALOMEDS::AttributeString_var aDataAttr = SALOMEDS::AttributeString::_narrow(anAttr);
+ CORBA::String_var aString = aDataAttr->Value();
+ VISU::Storable::TRestoringMap aRestoringMap;
+ Storable::StringToMap( aString.in(), aRestoringMap );
+ bool anIsSame = true;
+ TRestoringMap::const_iterator anIter = theRestoringMap.begin();
+ for(; anIter != theRestoringMap.end(); anIter++){
+ const TRestoringMap::key_type& aKey = anIter->first;
+ TRestoringMap::const_iterator anIter2 = aRestoringMap.find(aKey);
+ if(anIter2 != aRestoringMap.end()){
+ if (anIter->second == anIter2->second)
+ continue;
+ }
+ anIsSame = false;
+ break;
+ }
+ if(anIsSame){
+ CORBA::String_var anEntry = aSObject->GetID();
+ return anEntry.in();
+ }
+ }
+ }
+ return "";
+ }
+
+
+ //----------------------------------------------------------------------------
+ void
+ Storable
+ ::StringToMap(const QString& theString,
+ TRestoringMap& theMap)
+ {
+ if(0 && MYDEBUG) MESSAGE("Storable::StringToMap : string="<<theString);
+ QStringList strList = QStringList::split( ";", theString, false );
for ( int i = 0; i < strList.count(); i++ ) {
QString next = strList[ i ];
int pos = next.find("=");
}
}
- void Storable::DataToStream(ostringstream& theStr, const QString& theName, const QString& theVal) {
+
+ //----------------------------------------------------------------------------
+ Storable::TRestoringMap
+ Storable
+ ::GetStorableMap(_PTR(SObject) theSObject)
+ {
+ Storable::TRestoringMap aRestoringMap;
+ if(theSObject){
+ _PTR(GenericAttribute) anAttr;
+ if(theSObject->FindAttribute(anAttr,"AttributeString")){
+ _PTR(AttributeString) aComment (anAttr);
+ std::string aValue = aComment->Value();
+ VISU::Storable::StringToMap(aValue.c_str(), aRestoringMap);
+ }
+ }
+ return aRestoringMap;
+ }
+
+
+ //----------------------------------------------------------------------------
+ void
+ Storable
+ ::DataToStream(std::ostringstream& theStr,
+ const QString& theName,
+ const QString& theVal)
+ {
QString output = ( !theName.isNull() ? theName : QString("") )
+ QString( "=" )
+ ( !theVal.isNull() ? theVal : QString("") );
theStr<<output.latin1()<<";";
}
- void Storable::DataToStream(ostringstream& theStr, const QString& theName, const int theVal) {
+
+ //---------------------------------------------------------------
+ void
+ Storable
+ ::DataToStream(std::ostringstream& theStr,
+ const QString& theName,
+ int theVal)
+ {
QString output = ( !theName.isNull() ? theName : QString("") )
+ QString( "=" )
+ QString::number( theVal );
theStr<<output.latin1()<<";";
}
- void Storable::DataToStream(ostringstream& theStr, const QString& theName, const double theVal) {
+
+ //---------------------------------------------------------------
+ void
+ Storable
+ ::DataToStream(std::ostringstream& theStr,
+ const QString& theName,
+ long theVal)
+ {
QString output = ( !theName.isNull() ? theName : QString("") )
+ QString( "=" )
+ QString::number( theVal );
theStr<<output.latin1()<<";";
}
- Storable* Storable::Create(SALOMEDS::SObject_ptr theSObject,
- const string& thePrefix, const string& theLocalPersistentID)
+
+
+ //---------------------------------------------------------------
+ void
+ Storable
+ ::DataToStream(std::ostringstream& theStr,
+ const QString& theName,
+ double theVal)
{
- try{
- QString strIn( theLocalPersistentID.c_str() );
- TRestoringMap aMap;
- StrToMap(strIn,aMap);
- bool isExist;
- QString aComment = VISU::Storable::FindValue(aMap,"myComment",&isExist);
- if ( isExist ) {
- TCallbackMap::const_iterator i = VisuStoreMap.find(aComment.latin1());
- if(MYDEBUG) MESSAGE("Storable::Create - "<<aComment.latin1()<<" "<<(i != VisuStoreMap.end()));
- if(i == VisuStoreMap.end()) return NULL;
- return (i->second)(theSObject,thePrefix,aMap);
- }
- }catch(std::logic_error& exc){
- INFOS("Follow exception was occured :\n"<<exc.what());
- }catch(...){
- INFOS("Unknown exception was occured!");
- }
- return NULL;
+ QString output = ( !theName.isNull() ? theName : QString("") )
+ + QString( "=" )
+ + QString::number( theVal );
+ theStr<<output.latin1()<<";";
}
- QString Storable::FindValue(const TRestoringMap& theMap, const string& theArg, bool* isFind)
+
+ //---------------------------------------------------------------
+ QString
+ Storable
+ ::FindValue(const TRestoringMap& theMap,
+ const std::string& theArg,
+ bool* theIsFind)
{
- TRestoringMap::const_iterator i = theMap.find(theArg);
- if(i == theMap.end()) {
+ TRestoringMap::const_iterator anIter = theMap.find(theArg);
+ if(anIter == theMap.end()) {
if(MYDEBUG) MESSAGE("Storable::Init >> there is no value for "<<theArg);
- if(isFind != NULL) *isFind = false;
+ if(theIsFind != NULL)
+ *theIsFind = false;
//throw std::logic_error(string("Storable::Init >> there is no value for ") + theArg);
static QString BAD_VALUE("NULL");
return BAD_VALUE;
}
- if(isFind != NULL) *isFind = true;
- return i->second;
+ if(theIsFind != NULL)
+ *theIsFind = true;
+ return anIter->second;
}
- //===========================================================================
- PortableServer::ServantBase_var GetServant(CORBA::Object_ptr theObject){
- if(CORBA::is_nil(theObject)) return NULL;
+ //---------------------------------------------------------------
+ QString
+ Storable
+ ::FindValue(const TRestoringMap& theMap,
+ const std::string& theArg,
+ const QString& theDefaultValue)
+ {
+ bool anIsFound = false;
+ QString aValue = FindValue(theMap,theArg,&anIsFound);
+ if(anIsFound)
+ return aValue;
+ return theDefaultValue;
+ }
+
+
+ //---------------------------------------------------------------------------
+ PortableServer::ServantBase_var
+ GetServant(CORBA::Object_ptr theObject)
+ {
+ if(CORBA::is_nil(theObject))
+ return NULL;
try{
PortableServer::POA_ptr aPOA = Base_i::GetPOA();
PortableServer::Servant aServant = aPOA->reference_to_servant(theObject);
}
- //===========================================================================
- CORBA::Object_var SObjectToObject(SALOMEDS::SObject_ptr theSObject){
+ //---------------------------------------------------------------------------
+ CORBA::Object_var
+ SObjectToObject(SALOMEDS::SObject_ptr theSObject)
+ {
SALOMEDS::GenericAttribute_var anAttr;
- CORBA::Object_var anObj;
+ CORBA::Object_var anObject;
+ if(CORBA::is_nil(theSObject))
+ return anObject;
try{
if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
CORBA::String_var aValue = anIOR->Value();
CORBA::ORB_ptr anORB = Base_i::GetORB();
if(strcmp(aValue,"") != 0)
- anObj = anORB->string_to_object(aValue);
+ anObject = anORB->string_to_object(aValue);
}
}catch(...){
INFOS("SObjectToObject - Unknown exception was occured!!!");
}
- return anObj;
+ return anObject;
}
- //===========================================================================
- CORBA::Object_var ClientSObjectToObject(_PTR(SObject) theSObject){
+ //---------------------------------------------------------------------------
+ CORBA::Object_var
+ ClientSObjectToObject(_PTR(SObject) theSObject)
+ {
_PTR(GenericAttribute) anAttr;
- CORBA::Object_var anObj;
+ CORBA::Object_var anObject;
+ if(!theSObject)
+ return anObject;
try{
if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
_PTR(AttributeIOR) anIOR = anAttr;
CORBA::String_var aValue = anIOR->Value().c_str();
CORBA::ORB_ptr anORB = Base_i::GetORB();
if(strcmp(aValue,"") != 0)
- anObj = anORB->string_to_object(aValue);
+ anObject = anORB->string_to_object(aValue);
}
}catch(...){
INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
}
- return anObj;
+ return anObject;
}
- //===========================================================================
- string FindEntryWithComment(SALOMEDS::Study_ptr theStudyDocument, const char* theStartEntry,
- const char* theComment, int IsAllLevels)
- {
- SALOMEDS::ChildIterator_var anIter =
- theStudyDocument->NewChildIterator(theStudyDocument->FindObjectID(theStartEntry));
- anIter->InitEx(IsAllLevels);
- SALOMEDS::SObject_var aFieldSO;
- for(;anIter->More();anIter->Next()) {
- SALOMEDS::GenericAttribute_var anAttr;
- if (anIter->Value()->FindAttribute(anAttr,"AttributeComment")) {
- SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
- CORBA::String_var aString = aCmnt->Value();
- string aValue(aString);
- if (aValue == theComment) {
- aFieldSO = anIter->Value();
- aString = aFieldSO->GetID();
- aValue = aString;
- return aValue;
- }
- }
- }
- return "";
- }
- //===========================================================================
- string CreateAttributes(SALOMEDS::Study_ptr theStudyDocument,
- const char* theFatherEntry, const char* theRefFatherEntry,
- const char* theIOR, const char* theName,
- const char* thePersistentRef, const char* theComment,
- CORBA::Boolean theCreateNew)
+ //---------------------------------------------------------------------------
+ std::string
+ CreateAttributes(SALOMEDS::Study_ptr theStudyDocument,
+ const std::string& theFatherEntry,
+ const std::string& theIconName,
+ const std::string& theIOR,
+ const std::string& theName,
+ const std::string& thePersistentRef,
+ const std::string& theComment,
+ CORBA::Boolean theCreateNew)
{
SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
- SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry);
- SALOMEDS::SObject_var newObj;
- if (theCreateNew) newObj = aStudyBuilder->NewObject(aFather);
- else newObj = aFather;
+ SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str());
+ SALOMEDS::SObject_var aNewSObject;
+ if (theCreateNew)
+ aNewSObject = aStudyBuilder->NewObject(aFather);
+ else
+ aNewSObject = aFather;
SALOMEDS::GenericAttribute_var anAttr;
- if(strcmp(theIOR,"") != 0){
- anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
- SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
- anIOR->SetValue(theIOR);
+ if(theIOR != NO_IOR){
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeIOR");
+ SALOMEDS::AttributeIOR_var aCustomAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
+ aCustomAttr->SetValue(theIOR.c_str());
}
- if(strcmp(theName,"") != 0){
- anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
- SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
- aName->SetValue(theName);
+ if(theName != NO_NAME){
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeName");
+ SALOMEDS::AttributeName_var aCustomAttr = SALOMEDS::AttributeName::_narrow(anAttr);
+ aCustomAttr->SetValue(theName.c_str());
}
- if(strcmp(thePersistentRef,"") != 0){
- anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePersistentRef");
- SALOMEDS::AttributePersistentRef_var aPRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
- aPRef->SetValue(thePersistentRef);
+ if(thePersistentRef != NO_PERFSITENT_REF){
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributePersistentRef");
+ SALOMEDS::AttributePersistentRef_var aCustomAttr = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
+ aCustomAttr->SetValue(thePersistentRef.c_str());
}
- if(strcmp(theComment,"") != 0){
- anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
- SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
- aCmnt->SetValue(theComment);
- if(MYDEBUG) INFOS("CreateAttributes - Comment = "<<theComment);
+ if(theComment != NO_COMMENT){
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeString");
+ SALOMEDS::AttributeString_var aCustomAttr = SALOMEDS::AttributeString::_narrow(anAttr);
+ aCustomAttr->SetValue(theComment.c_str());
}
- if(strcmp(theRefFatherEntry,"") != 0){
- SALOMEDS::SObject_var aRefFather = theStudyDocument->FindObjectID(theRefFatherEntry);
- SALOMEDS::SObject_var anObj = aStudyBuilder->NewObject(aRefFather);
- aStudyBuilder->Addreference(anObj,newObj);
+ if(theIconName != NO_ICON){
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributePixMap");
+ SALOMEDS::AttributePixMap_var aCustomAttr = SALOMEDS::AttributePixMap::_narrow(anAttr);
+ aCustomAttr->SetPixMap(theIconName.c_str());
}
- CORBA::String_var anEntry = newObj->GetID();
- string aRet(anEntry);
+ CORBA::String_var anEntry = aNewSObject->GetID();
+ std::string aRet(anEntry);
if(MYDEBUG)
INFOS("CreateAttributes - StudyId = "<<theStudyDocument->StudyId()<<"; anEntry = "<<aRet<<"; IOR = '"<<theIOR<<"'");
return aRet;
}
- string CreateAttributes(_PTR(Study) theStudyDocument,
- const char* theFatherEntry, const char* theRefFatherEntry,
- const char* theIOR, const char* theName,
- const char* thePersistentRef, const char* theComment,
- CORBA::Boolean theCreateNew)
+
+ std::string
+ CreateAttributes(_PTR(Study) theStudyDocument,
+ const std::string& theFatherEntry,
+ const std::string& theIconName,
+ const std::string& theIOR,
+ const std::string& theName,
+ const std::string& thePersistentRef,
+ const std::string& theComment,
+ CORBA::Boolean theCreateNew)
{
_PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
_PTR(SObject) aFather = theStudyDocument->FindObjectID(theFatherEntry);
- _PTR(SObject) newObj;
+ _PTR(SObject) aNewSObject;
if (theCreateNew)
- newObj = aStudyBuilder->NewObject(aFather);
+ {
+ aNewSObject = aStudyBuilder->NewObject(aFather);
+ }
else
- newObj = aFather;
+ aNewSObject = aFather;
_PTR(GenericAttribute) anAttr;
- if (strcmp(theIOR, "") != 0) {
- anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
- _PTR(AttributeIOR) anIOR (anAttr);
- anIOR->SetValue(theIOR);
+ if (theIOR != NO_IOR) {
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeIOR");
+ _PTR(AttributeIOR) aCustomAttr (anAttr);
+ aCustomAttr->SetValue(theIOR);
}
- if (strcmp(theName, "") != 0) {
- anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
- _PTR(AttributeName) aName (anAttr);
- aName->SetValue(theName);
+ if (theName != NO_NAME) {
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeName");
+ _PTR(AttributeName) aCustomAttr (anAttr);
+ aCustomAttr->SetValue(theName);
}
- if (strcmp(thePersistentRef, "") != 0) {
- anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePersistentRef");
- _PTR(AttributePersistentRef) aPRef (anAttr);
- aPRef->SetValue(thePersistentRef);
+ if (thePersistentRef != NO_PERFSITENT_REF) {
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributePersistentRef");
+ _PTR(AttributePersistentRef) aCustomAttr (anAttr);
+ aCustomAttr->SetValue(thePersistentRef);
}
- if (strcmp(theComment, "") != 0) {
- anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
- _PTR(AttributeComment) aCmnt (anAttr);
- aCmnt->SetValue(theComment);
- if (MYDEBUG) INFOS("CreateAttributes - Comment = " << theComment);
+ if (theComment != NO_COMMENT) {
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeString");
+ _PTR(AttributeString) aCustomAttr (anAttr);
+ aCustomAttr->SetValue(theComment);
}
- if (strcmp(theRefFatherEntry, "") != 0) {
- _PTR(SObject) aRefFather = theStudyDocument->FindObjectID(theRefFatherEntry);
- _PTR(SObject) anObj = aStudyBuilder->NewObject(aRefFather);
- aStudyBuilder->Addreference(anObj, newObj);
+ if (theIconName != NO_ICON) {
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributePixMap");
+ _PTR(AttributePixMap) aCustomAttr (anAttr);
+ aCustomAttr->SetPixMap(theIconName);
}
- string aRet = newObj->GetID();
+ std::string aRet = aNewSObject->GetID();
if (MYDEBUG)
INFOS("CreateAttributes - StudyId = " << theStudyDocument->StudyId()
<< "; anEntry = " << aRet << "; IOR = '" << theIOR << "'");
return aRet;
}
- QString GenerateName(const string& theFmt, int theId){
- static QString aName;
+
+ //---------------------------------------------------------------
+ QString
+ GenerateName(const std::string& theFmt, int theId)
+ {
+ QString aName;
if(theId > 0)
- aName.sprintf("%s:%d",theFmt.c_str(),theId);
+ aName.sprintf("%s:%d", theFmt.c_str(), theId);
else
- aName.sprintf("%s",theFmt.c_str());
+ aName.sprintf("%s", theFmt.c_str());
return aName;
}
- SALOMEDS::StudyManager_var GetStudyManager()
+ //---------------------------------------------------------------
+ SALOMEDS::StudyManager_var
+ GetStudyManager()
{
static SALOMEDS::StudyManager_var aStudyManager;
if(CORBA::is_nil(aStudyManager)){
}
- SALOMEDS::Study_var GetDSStudy(_PTR(Study) theStudy)
+ //---------------------------------------------------------------
+ SALOMEDS::Study_var
+ GetDSStudy(_PTR(Study) theStudy)
{
- //std::string aStudyName = theStudy->Name();
- //return GetStudyManager()->GetStudyByName(aStudyName.c_str());
int aStudyID = theStudy->StudyId();
return GetStudyManager()->GetStudyByID(aStudyID);
}
- SALOMEDS::SObject_var GetSObject( _PTR(SObject) obj )
+
+ //---------------------------------------------------------------
+ struct TGetStudyEvent: public SALOME_Event
+ {
+ SALOMEDS::Study_var myStudy;
+
+ typedef SalomeApp_Study* TResult;
+ TResult myResult;
+
+ TGetStudyEvent(SALOMEDS::Study_ptr theStudy):
+ myStudy(SALOMEDS::Study::_duplicate(theStudy)),
+ myResult(NULL)
+ {}
+
+ virtual
+ void
+ Execute()
+ {
+ if(CORBA::is_nil(myStudy))
+ return;
+
+ int aStudyId = myStudy->StudyId();
+ SUIT_Session* aSession = SUIT_Session::session();
+ QPtrList<SUIT_Application> anApplications = aSession->applications();
+ QPtrListIterator<SUIT_Application> anIter (anApplications);
+ while (SUIT_Application* anApp = anIter.current()) {
+ ++anIter;
+ if (SUIT_Study* aSStudy = anApp->activeStudy()) {
+ if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
+ if (_PTR(Study) aCStudy = aStudy->studyDS()) {
+ if (aStudyId == aCStudy->StudyId()) {
+ myResult = aStudy;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ };
+
+
+ //---------------------------------------------------------------
+ SalomeApp_Study*
+ GetGUIStudy(SALOMEDS::Study_ptr theStudy)
+ {
+ return ProcessEvent(new TGetStudyEvent(theStudy));
+ }
+
+
+ //---------------------------------------------------------------
+ _PTR(Study)
+ GetStudy(SALOMEDS::Study_ptr theStudy)
+ {
+ if(SalomeApp_Study* aStudy = ProcessEvent(new TGetStudyEvent(theStudy)))
+ return aStudy->studyDS();
+
+ return _PTR(Study)();
+ }
+
+
+ //---------------------------------------------------------------
+ SALOMEDS::SObject_var
+ GetSObject( _PTR(SObject) obj )
{
_PTR(Study) aStudy = obj->GetStudy();
SALOMEDS::Study_var aSalomeDSStudy = GetDSStudy( aStudy );
return aSalomeDSStudy->FindObjectID( id.c_str() );
}
- _PTR(SObject) GetClientSObject( SALOMEDS::SObject_var obj,
- _PTR(Study) study )
+ //---------------------------------------------------------------
+ _PTR(SObject)
+ GetClientSObject(SALOMEDS::SObject_ptr theSObject,
+ _PTR(Study) theStudy)
{
- return study->FindObjectID( obj->GetID() );
-
+ CORBA::String_var anEntry = theSObject->GetID();
+ return theStudy->FindObjectID( anEntry.in() );
}
- void RemoveFromStudy (SALOMEDS::SObject_ptr theSObject,
- bool theIsAttrOnly,
- bool theDestroySubObjects)
+ //---------------------------------------------------------------
+ void
+ RemoveFromStudy (SALOMEDS::SObject_ptr theSObject,
+ bool theIsAttrOnly,
+ bool theDestroySubObjects)
{
if (theSObject->_is_nil()) return;
if (CORBA::is_nil(aRemovableObject)) continue;
aRemovableObject->RemoveFromStudy();
-
- // Destroy
- if (theDestroySubObjects) {
- VISU::Prs3d_var aPrs3d = VISU::Prs3d::_narrow(aRemovableObject);
- if (CORBA::is_nil(aPrs3d)) continue;
- aPrs3d->Destroy();
- }
}
// asl, fix for PAL10455: Remove references to SObject
- SALOMEDS::Study::ListOfSObject* aRefs = aStudyDocument->FindDependances( theSObject );
+ SALOMEDS::Study::ListOfSObject_var aRefs = aStudyDocument->FindDependances( theSObject );
for( int i=0, n=aRefs->length(); i<n; i++ )
{
- SALOMEDS::SObject_var o = (*aRefs)[i];
+ SALOMEDS::SObject_var o = aRefs[i];
if( o->GetFatherComponent()->ComponentDataType()==theSObject->GetFatherComponent()->ComponentDataType() )
{
aStudyBuilder->RemoveReference( o );
aStudyBuilder->RemoveObjectWithChildren(theSObject);
}
- void RemoveFromStudy (_PTR(SObject) theSObject,
- bool theIsAttrOnly,
- bool theDestroySubObjects)
+
+ //---------------------------------------------------------------
+ void
+ RemoveFromStudy (_PTR(SObject) theSObject,
+ bool theIsAttrOnly,
+ bool theDestroySubObjects)
{
if (!theSObject) return;
for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
_PTR(SObject) aChildSObject = aChildIter->Value();
CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
- if (CORBA::is_nil(aChildObj)) continue;
+ if (CORBA::is_nil(aChildObj))
+ continue;
VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(aChildObj);
- if (CORBA::is_nil(aRemovableObject)) continue;
+ if (CORBA::is_nil(aRemovableObject))
+ continue;
aRemovableObject->RemoveFromStudy();
-
- // Destroy
- if (theDestroySubObjects) {
- VISU::Prs3d_var aPrs3d = VISU::Prs3d::_narrow(aRemovableObject);
- if (CORBA::is_nil(aPrs3d)) continue;
- aPrs3d->Destroy();
- }
}
// Remove the SObject itself