* GetDocument
*/
//=============================================================================
-Handle(TDocStd_Document) GEOM_Engine::GetDocument(int theDocID)
+Handle(TDocStd_Document) GEOM_Engine::GetDocument(int theDocID, bool force)
{
Handle(TDocStd_Document) aDoc;
- if(!_mapIDDocument.IsBound(theDocID)) {
+ if(_mapIDDocument.IsBound(theDocID)) {
+ aDoc = Handle(TDocStd_Document)::DownCast(_mapIDDocument(theDocID));
+ }
+ else if (force) {
_OCAFApp->NewDocument("SALOME_GEOM", aDoc);
aDoc->SetUndoLimit(_UndoLimit);
_mapIDDocument.Bind(theDocID, aDoc);
TDataStd_Integer::Set(aDoc->Main(), theDocID);
}
-
- return Handle(TDocStd_Document)::DownCast(_mapIDDocument(theDocID));
+ return aDoc;
}
//=============================================================================
* GetObject
*/
//=============================================================================
-Handle(GEOM_Object) GEOM_Engine::GetObject(int theDocID, char* theEntry)
+Handle(GEOM_Object) GEOM_Engine::GetObject(int theDocID, char* theEntry, bool force)
{
- TCollection_AsciiString anID = BuildID(theDocID, theEntry);
- if(_objects.IsBound(anID)) return Handle(GEOM_Object)::DownCast(_objects(anID));
+ Handle(GEOM_Object) anObject;
- TDF_Label aLabel;
- Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
- TDF_Tool::Label(aDoc->Main().Data(), theEntry, aLabel, Standard_True);
- Handle(GEOM_Object) anObject = new GEOM_Object(aLabel);
+ TCollection_AsciiString anID = BuildID(theDocID, theEntry);
- _objects.Bind(anID, anObject);
+ if (_objects.IsBound(anID)) {
+ anObject = Handle(GEOM_Object)::DownCast(_objects(anID));
+ }
+ else if (force) {
+ Handle(TDocStd_Document) aDoc = GetDocument(theDocID, force);
+ if ( !aDoc.IsNull()) {
+ TDF_Label aLabel;
+ TDF_Tool::Label(aDoc->Main().Data(), theEntry, aLabel, Standard_True);
+ anObject = new GEOM_Object(aLabel);
+ _objects.Bind(anID, anObject);
+ }
+ }
return anObject;
}
if (theObject.IsNull()) return false;
int aDocID = theObject->GetDocID();
-
+ if(!_mapIDDocument.IsBound(aDocID))
+ return false; // document is closed...
+
//Remove an object from the map of available objects
TCollection_AsciiString anID = BuildIDFromObject(theObject);
if (_objects.IsBound(anID)) _objects.UnBind(anID);
Standard_EXPORT static GEOM_Engine* GetEngine();
//Returns the OCAF document by its ID, if document doesn't exists it will be created
- Standard_EXPORT Handle(TDocStd_Document) GetDocument(int theDocID);
+ Standard_EXPORT Handle(TDocStd_Document) GetDocument(int theDocID, bool force=true);
//Returns the ID of the given OCAF document
Standard_EXPORT int GetDocID(Handle(TDocStd_Document) theDocument);
Standard_EXPORT Handle(TDocStd_Application) GetApplication() { return _OCAFApp; }
//Returns a pointer to GEOM_Object defined by a document and the entry
- Standard_EXPORT Handle(GEOM_Object) GetObject(int theDocID, char* theEntry);
+ Standard_EXPORT Handle(GEOM_Object) GetObject(int theDocID, char* theEntry, bool force=true);
//Adds a new object of the type theType in the OCAF document
Standard_EXPORT Handle(GEOM_Object) AddObject(int theDocID, int theType);
*/
//=============================================================================
GEOM_Object::GEOM_Object(TDF_Label& theEntry)
-: _label(theEntry), _ior("")
+ : _label(theEntry), _ior(""), _docID(-1)
{
+ Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(_label.Data());
+ if(!aDoc.IsNull()) {
+ Handle(TDataStd_Integer) anID;
+ if(aDoc->Main().FindAttribute(TDataStd_Integer::GetID(), anID)) _docID = anID->Get();
+ }
+
if(!theEntry.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), _root))
_root = TDataStd_TreeNode::Set(theEntry);
}
*/
//=============================================================================
GEOM_Object::GEOM_Object(TDF_Label& theEntry, int theType)
-: _label(theEntry), _ior("")
+: _label(theEntry), _ior(""), _docID(-1)
{
+ Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(_label.Data());
+ if(!aDoc.IsNull()) {
+ Handle(TDataStd_Integer) anID;
+ if(aDoc->Main().FindAttribute(TDataStd_Integer::GetID(), anID)) _docID = anID->Get();
+ }
+
theEntry.ForgetAllAttributes(Standard_True);
if(!theEntry.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), _root))
//=============================================================================
int GEOM_Object::GetDocID()
{
- Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(_label.Data());
- if(aDoc.IsNull()) return -1;
-
- Handle(TDataStd_Integer) anID;
- if(!aDoc->Main().FindAttribute(TDataStd_Integer::GetID(), anID)) return -1;
-
- return anID->Get();
+ return _docID;
}
TDF_Label _label;
TCollection_AsciiString _ior;
TCollection_AsciiString _parameters;
+ int _docID;
};
#endif
// function : GEOM_Gen_i()
// purpose : constructor to be called for servant creation.
//============================================================================
-GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
- PortableServer::POA_ptr poa,
- PortableServer::ObjectId * contId,
- const char *instanceName,
- const char *interfaceName) :
+GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
+ PortableServer::POA_ptr poa,
+ PortableServer::ObjectId* contId,
+ const char* instanceName,
+ const char* interfaceName) :
Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
{
_thisObj = this;
void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
{
CORBA::String_var anEntry = theObject->GetEntry();
- Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry);
+ Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false);
if (anObject.IsNull()) return;
_impl->RemoveObject(anObject);
return;
//=====================================================================================
extern "C"
{
-GEOM_I_EXPORT
-PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
-
-GEOM_I_EXPORT
- PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
- PortableServer::POA_ptr poa,
- PortableServer::ObjectId * contId,
- const char *instanceName,
- const char * interfaceName)
+ /*
+ GEOM_I_EXPORT
+ PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
+ */
+
+ GEOM_I_EXPORT
+ PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb,
+ PortableServer::POA_ptr poa,
+ PortableServer::ObjectId* contId,
+ const char* instanceName,
+ const char* interfaceName)
{
- GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
- // Don't understand the reason of this register ????
-// myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
- return myGEOM_Gen_i->getId();
+ GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
+ return myGEOM_Gen_i->getId();
}
}