5 #include "GEOM_Gen_i.hh"
6 #include "GEOM_Object_i.hh"
7 #include "SALOMEDS_Tool.hxx"
9 #include "Utils_CorbaException.hxx"
11 #include "Utils_ExceptHandlers.hxx"
12 #include "utilities.h"
14 #include "GEOM_Object_i.hh"
15 #include "GEOM_Object.hxx"
16 #include "GEOM_Function.hxx"
17 #include "GEOMImpl_Types.hxx"
18 #include "GEOMImpl_CopyDriver.hxx"
21 #include <BRep_Builder.hxx>
22 #include <BRepTools.hxx>
23 #include <TDF_Label.hxx>
24 #include <TDF_Tool.hxx>
25 #include <TCollection_AsciiString.hxx>
26 #include <TColStd_HArray1OfInteger.hxx>
27 #include <TopAbs_ShapeEnum.hxx>
29 //============================================================================
30 // function : GEOM_Gen_i()
31 // purpose : constructor to be called for servant creation.
32 //============================================================================
33 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
34 PortableServer::POA_ptr poa,
35 PortableServer::ObjectId * contId,
36 const char *instanceName,
37 const char *interfaceName) :
38 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
41 _id = _poa->activate_object(_thisObj);
42 name_service = new SALOME_NamingService(_orb);
44 _impl = new ::GEOMImpl_Gen;
50 //============================================================================
51 // function : ~GEOM_Gen_i()
52 // purpose : destructor
53 //============================================================================
54 GEOM_Gen_i::~GEOM_Gen_i() {
60 //============================================================================
61 // function : IORToLocalPersistentID()
63 //============================================================================
64 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
65 const char* IORString,
66 CORBA::Boolean isMultiFile,
67 CORBA::Boolean isASCII)
69 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
70 if (!CORBA::is_nil(anObject)) {
71 return strdup(anObject->GetEntry());
77 //============================================================================
78 // function : LocalPersistentIDToIOR()
79 // purpose : Create/Load CORBA object from a persistent ref (an entry)
80 // : Used when a study is loaded
81 // : The IOR (IORName) of object created is returned
82 //============================================================================
83 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
84 const char* aLocalPersistentID,
85 CORBA::Boolean isMultiFile,
86 CORBA::Boolean isASCII)
88 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
90 Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
91 TCollection_AsciiString anEntry;
92 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
93 GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
95 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
96 return strdup(aPersRefString);
99 //============================================================================
100 // function : CanPublishInStudy
102 //============================================================================
103 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
105 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
106 return !(anObject->_is_nil());
110 //============================================================================
111 // function : PublishInStudy
113 //============================================================================
114 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
115 SALOMEDS::SObject_ptr theSObject,
116 CORBA::Object_ptr theObject,
117 const char* theName) throw (SALOME::SALOME_Exception)
119 Unexpect aCatch(SALOME_SalomeException);
120 SALOMEDS::SObject_var aResultSO;
121 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
123 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
124 if(aShape->_is_nil()) return aResultSO;
126 SALOMEDS::GenericAttribute_var anAttr;
127 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
129 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
130 if (aFather->_is_nil()) {
131 aFather = aStudyBuilder->NewComponent("GEOM");
132 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
133 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
134 aName->SetValue("Geometry");
135 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
136 SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
137 aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
139 if (aFather->_is_nil()) return aResultSO;
141 if (CORBA::is_nil(theSObject)) {
142 aResultSO = aStudyBuilder->NewObject(aFather);
144 if (!theSObject->ReferencedObject(aResultSO))
145 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
146 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
148 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
149 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
150 char *aGeomObjIOR = _orb->object_to_string(theObject);
151 anIOR->SetValue(strdup(aGeomObjIOR));
153 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
154 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
155 TCollection_AsciiString aShapeName("Shape_");
157 if ( aShape->GetType() == GEOM_GROUP ) {
158 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
159 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
161 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
162 aShapeName = "Group_Of_Vertices_";
165 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
166 aShapeName = "Group_Of_Edges_";
169 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
170 aShapeName = "Group_Of_Faces_";
173 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
174 aShapeName = "Group_Of_Solids_";
177 } else if ( aShape->GetType() == GEOM_MARKER ) {
178 aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
179 aShapeName = "LocalCS_";
180 } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
181 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
182 aShapeName = "Compound_";
183 } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
184 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
185 aShapeName = "Compsolid_";
186 } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
187 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
188 aShapeName = "Solid_";
189 } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
190 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
191 aShapeName = "Shell_";
192 } else if ( aShape->GetShapeType() == GEOM::FACE ) {
193 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
194 aShapeName = "Face_";
195 } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
196 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
197 aShapeName = "Wire_";
198 } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
199 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
200 aShapeName = "Edge_";
201 } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
202 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
203 aShapeName = "Vertex_";
205 //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
206 //else aShapeName = TCollection_AsciiString(strdup(theName));
208 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
209 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
210 // of objects in the study, but compute a number of objects with the same prefix
211 // and build a new name as Prefix_N+1
212 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
213 int i = 0; // (WITH EMPTY NEW NAME)
214 SALOMEDS::SObject_var obj;
215 TCollection_AsciiString aNewShapeName;
217 aNewShapeName = aShapeName + TCollection_AsciiString(++i);
218 obj = theStudy->FindObject( aNewShapeName.ToCString() );
220 while ( !obj->_is_nil() );
221 aShapeName = aNewShapeName;
223 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
224 aShapeName = TCollection_AsciiString(strdup(theName));
226 //Set the study entry as a name of the published GEOM_Object
227 aShape->SetStudyEntry(aResultSO->GetID());
229 //Set a name of the added shape
230 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
231 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
232 aNameAttrib->SetValue(aShapeName.ToCString());
234 return aResultSO._retn();
238 //============================================================================
240 // purpose : save OCAF/Geom document
241 //============================================================================
242 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
245 SALOMEDS::TMPFile_var aStreamFile;
246 // Get a temporary directory to store a file
247 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
248 // Create a list to store names of created files
249 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
251 // Prepare a file name to open
252 TCollection_AsciiString aNameWithExt("");
254 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
255 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
256 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
257 // Build a full file name of temporary file
258 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
259 // Save GEOM component in this file
260 _impl->Save(theComponent->GetStudy()->StudyId(), aFullName.ToCString());
261 // Conver a file to the byte stream
262 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
263 // Remove the created file and tmp directory
264 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
266 // Return the created byte stream
267 return aStreamFile._retn();
271 //============================================================================
272 // function : SaveASCII()
274 //============================================================================
275 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
278 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
279 return aStreamFile._retn();
283 //============================================================================
286 //============================================================================
287 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
288 const SALOMEDS::TMPFile& theStream,
292 if (theStream.length() <= 9) {
293 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
297 // Get a temporary directory for a file
298 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
299 // Conver the byte stream theStream to a file and place it in tmp directory
300 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
302 // Prepare a file name to open
303 TCollection_AsciiString aNameWithExt("");
305 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
306 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
307 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
310 if (!_impl->Load(theComponent->GetStudy()->StudyId(), aFullName.ToCString())) return false;
312 // Remove the created file and tmp directory
313 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
315 SALOMEDS::Study_var Study = theComponent->GetStudy();
316 TCollection_AsciiString name( strdup(Study->Name()) );
322 //============================================================================
323 // function : LoadASCII()
325 //============================================================================
326 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
327 const SALOMEDS::TMPFile& theStream,
330 return Load(theComponent, theStream, theURL, isMultiFile);
334 //============================================================================
335 // function : Close()
337 //============================================================================
338 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
340 _impl->Close(theComponent->GetStudy()->StudyId());
343 //============================================================================
344 // function : CanCopy()
346 //============================================================================
347 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
348 // Try to retrieve known by Geometry component GEOM_Object by given IOR
349 SALOMEDS::GenericAttribute_var anAttr;
350 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
352 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
354 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
355 // If the object is null one it can't be copied: return false
356 if (anObject->_is_nil()) return false;
360 //============================================================================
361 // function : CopyFrom()
363 //============================================================================
364 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
365 // Declare a sequence of the byte to store the copied object
366 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
368 // Try to get GEOM_Object object by given SObject
369 SALOMEDS::GenericAttribute_var anAttr;
370 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
371 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
372 if (anObject->_is_nil()) return aStreamFile._retn();
374 aStreamFile = anObject->GetShapeStream();
376 // Assign an ID the type of GEOM_Object
377 theObjectID = anObject->GetType();
379 // Return created TMPFile
380 return aStreamFile._retn();
383 //============================================================================
384 // function : CanPaste()
386 //============================================================================
387 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
388 // The Geometry component can paste only objects copied by Geometry component
389 // and with the object type = 1
390 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
394 //============================================================================
395 // function : PasteInto()
397 //============================================================================
398 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
399 CORBA::Long theObjectID,
400 SALOMEDS::SObject_ptr theObject) {
401 // Find the current Study and StudyBuilder
402 SALOMEDS::Study_var aStudy = theObject->GetStudy();
403 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
405 // Retrieve a TopoDS_Shape from byte stream
406 TopoDS_Shape aTopology;
407 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
408 BRep_Builder aBuilder;
410 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
411 } catch (Standard_Failure) {
415 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
416 SALOMEDS::SObject_var aNewSO;
417 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
418 aNewSO = aStudyBuilder->NewObject(theObject);
419 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
422 //Create a new GEOM_Object
423 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
424 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
425 aFunction->SetValue(aTopology);
427 TCollection_AsciiString anEntry;
428 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
429 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
431 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
432 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
433 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
434 anIOR->SetValue(_orb->object_to_string(obj));
436 // Return the created in the Study SObject
437 return aNewSO._retn();
440 //============================================================================
441 // function : ComponentDataType()
443 //============================================================================
444 char* GEOM_Gen_i::ComponentDataType()
446 return strdup("GEOM");
449 //============================================================================
450 // function : AddInStudy
452 //============================================================================
453 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM::GEOM_Object_ptr theObject, const char* theName, GEOM::GEOM_Object_ptr theFather)
455 SALOMEDS::SObject_var aResultSO;
456 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
458 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
461 if(!theFather->_is_nil()) {
462 IOR = _orb->object_to_string(theFather);
463 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR);
464 if(aFatherSO->_is_nil()) return aResultSO._retn();
465 aResultSO = aStudyBuilder->NewObject(aFatherSO);
466 //aStudyBuilder->Addreference(aResultSO, aResultSO);
469 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
470 if(aResultSO->_is_nil()) return aResultSO._retn();
472 GEOM::ListOfGO_var aList = theObject->GetDependency();
473 Standard_Integer aLength = aList->length();
474 if(aLength < 1) return aResultSO._retn();
476 //Publish the arguments
477 for(Standard_Integer i = 0; i< aLength; i++) {
478 GEOM::GEOM_Object_var anObject = aList[i];
479 if(anObject->_is_nil()) continue;
480 IOR = _orb->object_to_string(anObject);
481 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR);
482 if(aSO->_is_nil()) continue;
483 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
484 aStudyBuilder->Addreference(aSubSO, aSO);
487 return aResultSO._retn();
490 //============================================================================
491 // function : register()
492 // purpose : register 'name' in 'name_service'
493 //============================================================================
494 void GEOM_Gen_i::register_name(char * name)
496 GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(POA_GEOM::GEOM_Gen::_this());
497 name_service->Register(g, strdup(name));
500 //============================================================================
503 //============================================================================
504 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
506 _impl->Undo(theStudyID);
509 //============================================================================
512 //============================================================================
513 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
515 _impl->Redo(theStudyID);
518 //============================================================================
519 // function : GetIBasicOperations
521 //============================================================================
522 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
523 throw ( SALOME::SALOME_Exception )
525 Unexpect aCatch(SALOME_SalomeException);
526 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
528 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
530 GEOM_IBasicOperations_i* aServant =
531 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
533 // activate the CORBA servant
534 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
535 return operations._retn();
538 //============================================================================
539 // function : GetITransformOperations
541 //============================================================================
542 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
543 throw ( SALOME::SALOME_Exception )
545 Unexpect aCatch(SALOME_SalomeException);
546 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
548 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
550 GEOM_ITransformOperations_i* aServant =
551 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
553 // activate the CORBA servant
554 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
555 return operations._retn();
558 //============================================================================
559 // function : GetI3DPrimOperations
561 //============================================================================
562 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
563 throw ( SALOME::SALOME_Exception )
565 Unexpect aCatch(SALOME_SalomeException);
566 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
568 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
570 GEOM_I3DPrimOperations_i* aServant =
571 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
573 // activate the CORBA servant
574 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
575 return operations._retn();
578 //============================================================================
579 // function : GetIShapesOperations
581 //============================================================================
582 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
583 throw ( SALOME::SALOME_Exception )
585 Unexpect aCatch(SALOME_SalomeException);
586 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
588 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
590 GEOM_IShapesOperations_i* aServant =
591 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
593 // activate the CORBA servant
594 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
595 return operations._retn();
598 //============================================================================
599 // function : GetIBlocksOperations
601 //============================================================================
602 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
603 throw ( SALOME::SALOME_Exception )
605 Unexpect aCatch(SALOME_SalomeException);
606 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
608 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
610 GEOM_IBlocksOperations_i* aServant =
611 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
613 // activate the CORBA servant
614 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
615 return operations._retn();
618 //============================================================================
619 // function : GetIBooleanOperations
621 //============================================================================
622 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
623 throw ( SALOME::SALOME_Exception )
625 Unexpect aCatch(SALOME_SalomeException);
626 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
628 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
630 GEOM_IBooleanOperations_i* aServant =
631 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
633 // activate the CORBA servant
634 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
635 return operations._retn();
638 //============================================================================
639 // function : GetICurvesOperations
641 //============================================================================
642 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
643 throw ( SALOME::SALOME_Exception )
645 Unexpect aCatch(SALOME_SalomeException);
646 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
648 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
650 GEOM_ICurvesOperations_i* aServant =
651 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
653 // activate the CORBA servant
654 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
655 return operations._retn();
658 //============================================================================
659 // function : GetILocalOperations
661 //============================================================================
662 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
663 throw ( SALOME::SALOME_Exception )
665 Unexpect aCatch(SALOME_SalomeException);
666 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
668 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
670 GEOM_ILocalOperations_i* aServant =
671 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
673 // activate the CORBA servant
674 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
675 return operations._retn();
678 //============================================================================
679 // function : GetIHealingOperations
681 //============================================================================
682 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
683 throw ( SALOME::SALOME_Exception )
685 Unexpect aCatch(SALOME_SalomeException);
686 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
688 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
690 GEOM_IHealingOperations_i* aServant =
691 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
693 // activate the CORBA servant
694 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
695 return operations._retn();
698 //============================================================================
699 // function : GetIInsertOperations
701 //============================================================================
702 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
703 throw ( SALOME::SALOME_Exception )
705 Unexpect aCatch(SALOME_SalomeException);
706 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
708 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
710 GEOM_IInsertOperations_i* aServant =
711 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
713 // activate the CORBA servant
714 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
715 return operations._retn();
718 //============================================================================
719 // function : GetIMeasureOperations
721 //============================================================================
722 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
723 throw ( SALOME::SALOME_Exception )
725 Unexpect aCatch(SALOME_SalomeException);
726 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
728 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
730 GEOM_IMeasureOperations_i* aServant =
731 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
733 // activate the CORBA servant
734 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
735 return operations._retn();
738 //============================================================================
739 // function : GetIGroupOperations
741 //============================================================================
742 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
743 throw ( SALOME::SALOME_Exception )
745 Unexpect aCatch(SALOME_SalomeException);
746 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
748 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
750 GEOM_IGroupOperations_i* aServant =
751 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
753 // activate the CORBA servant
754 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
755 return operations._retn();
758 //=============================================================================
762 //=============================================================================
763 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape(GEOM::GEOM_Object_ptr theMainShape, const GEOM::ListOfLong& theIndices)
765 if(theMainShape == NULL || theIndices.length() < 1) return GEOM::GEOM_Object::_nil();
766 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
767 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
769 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
770 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
772 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray);
773 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
775 TCollection_AsciiString anEntry;
776 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
777 return GetObject(anObject->GetDocID(), anEntry.ToCString());
780 //=============================================================================
784 //=============================================================================
785 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
787 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
788 if (anObject.IsNull()) return;
789 _impl->RemoveObject(anObject);
794 //=================================================================================
795 // function : GetStringFromIOR()
796 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
797 //=================================================================================
798 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
799 return _orb->object_to_string(theObject);
803 //=================================================================================
804 // function : GetIORFromString()
805 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
806 //=================================================================================
807 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
808 GEOM::GEOM_Object_var aGeomObject;
809 if(strcmp(stringIOR,"") != 0){
810 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
811 if(!CORBA::is_nil(anObject))
812 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in()) ;
814 return aGeomObject._retn() ;
817 //=================================================================================
818 // function : GetObject()
820 //=================================================================================
821 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject(CORBA::Long theStudyID, const char* theEntry)
823 GEOM::GEOM_Object_var obj;
824 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
825 if(handle_object.IsNull()) return NULL;
826 TCollection_AsciiString stringIOR = handle_object->GetIOR();
827 if(stringIOR.Length() > 1) {
828 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
829 if(!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
833 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
834 GEOM_Object_i* servant = new GEOM_Object_i(_poa, engine, handle_object);
836 obj = servant->_this();
837 stringIOR = _orb->object_to_string(obj);
838 handle_object->SetIOR(stringIOR);
843 //=====================================================================================
845 //=====================================================================================
848 PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
849 PortableServer::POA_ptr poa,
850 PortableServer::ObjectId * contId,
851 const char *instanceName,
852 const char * interfaceName)
854 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
855 myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
856 return myGEOM_Gen_i->getId() ;