3 #include "GEOM_Gen_i.hh"
4 #include "GEOM_Object_i.hh"
5 #include "SALOMEDS_Tool.hxx"
7 #include "Utils_CorbaException.hxx"
9 #include "Utils_ExceptHandlers.hxx"
10 #include "utilities.h"
12 #include "GEOM_Object_i.hh"
13 #include "GEOM_Object.hxx"
14 #include "GEOM_Function.hxx"
15 #include "GEOMImpl_Types.hxx"
16 #include "GEOMImpl_CopyDriver.hxx"
19 #include <BRep_Builder.hxx>
20 #include <BRepTools.hxx>
21 #include <TDF_Label.hxx>
22 #include <TDF_Tool.hxx>
23 #include <TCollection_AsciiString.hxx>
24 #include <TColStd_HArray1OfInteger.hxx>
25 #include <TopAbs_ShapeEnum.hxx>
27 //============================================================================
28 // function : GEOM_Gen_i()
29 // purpose : constructor to be called for servant creation.
30 //============================================================================
31 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
32 PortableServer::POA_ptr poa,
33 PortableServer::ObjectId * contId,
34 const char *instanceName,
35 const char *interfaceName) :
36 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
39 _id = _poa->activate_object(_thisObj);
40 name_service = new SALOME_NamingService(_orb);
42 _impl = new ::GEOMImpl_Gen;
48 //============================================================================
49 // function : ~GEOM_Gen_i()
50 // purpose : destructor
51 //============================================================================
52 GEOM_Gen_i::~GEOM_Gen_i() {
58 //============================================================================
59 // function : IORToLocalPersistentID()
61 //============================================================================
62 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
63 const char* IORString,
64 CORBA::Boolean isMultiFile,
65 CORBA::Boolean isASCII)
67 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
68 if (!CORBA::is_nil(anObject)) {
69 return strdup(anObject->GetEntry());
75 //============================================================================
76 // function : LocalPersistentIDToIOR()
77 // purpose : Create/Load CORBA object from a persistent ref (an entry)
78 // : Used when a study is loaded
79 // : The IOR (IORName) of object created is returned
80 //============================================================================
81 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
82 const char* aLocalPersistentID,
83 CORBA::Boolean isMultiFile,
84 CORBA::Boolean isASCII)
86 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
88 Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
89 TCollection_AsciiString anEntry;
90 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
91 GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
93 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
94 return strdup(aPersRefString);
97 //============================================================================
98 // function : CanPublishInStudy
100 //============================================================================
101 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
103 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
104 return !(anObject->_is_nil());
108 //============================================================================
109 // function : PublishInStudy
111 //============================================================================
112 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
113 SALOMEDS::SObject_ptr theSObject,
114 CORBA::Object_ptr theObject,
115 const char* theName) throw (SALOME::SALOME_Exception)
117 Unexpect aCatch(SALOME_SalomeException);
118 SALOMEDS::SObject_var aResultSO;
119 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
121 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
122 if(aShape->_is_nil()) return aResultSO;
124 SALOMEDS::GenericAttribute_var anAttr;
125 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
127 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
128 if (aFather->_is_nil()) {
129 aFather = aStudyBuilder->NewComponent("GEOM");
130 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
131 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
132 aName->SetValue("Geometry");
133 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
134 SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
135 aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
137 if (aFather->_is_nil()) return aResultSO;
139 if (CORBA::is_nil(theSObject)) {
140 aResultSO = aStudyBuilder->NewObject(aFather);
142 if (!theSObject->ReferencedObject(aResultSO))
143 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
144 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
146 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
147 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
148 char *aGeomObjIOR = _orb->object_to_string(theObject);
149 anIOR->SetValue(strdup(aGeomObjIOR));
151 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
152 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
153 TCollection_AsciiString aShapeName("Shape_");
155 if ( aShape->GetType() == GEOM_GROUP ) {
156 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
157 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
159 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
160 aShapeName = "Group_Of_Vertices_";
163 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
164 aShapeName = "Group_Of_Edges_";
167 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
168 aShapeName = "Group_Of_Faces_";
171 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
172 aShapeName = "Group_Of_Solids_";
175 } else if ( aShape->GetType() == GEOM_MARKER ) {
176 aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
177 aShapeName = "LocalCS_";
178 } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
179 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
180 aShapeName = "Compound_";
181 } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
182 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
183 aShapeName = "Compsolid_";
184 } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
185 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
186 aShapeName = "Solid_";
187 } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
188 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
189 aShapeName = "Shell_";
190 } else if ( aShape->GetShapeType() == GEOM::FACE ) {
191 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
192 aShapeName = "Face_";
193 } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
194 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
195 aShapeName = "Wire_";
196 } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
197 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
198 aShapeName = "Edge_";
199 } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
200 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
201 aShapeName = "Vertex_";
203 //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
204 //else aShapeName = TCollection_AsciiString(strdup(theName));
206 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
207 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
208 // of objects in the study, but compute a number of objects with the same prefix
209 // and build a new name as Prefix_N+1
210 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
211 int i = 0; // (WITH EMPTY NEW NAME)
212 SALOMEDS::SObject_var obj;
213 TCollection_AsciiString aNewShapeName;
215 aNewShapeName = aShapeName + TCollection_AsciiString(++i);
216 obj = theStudy->FindObject( aNewShapeName.ToCString() );
218 while ( !obj->_is_nil() );
219 aShapeName = aNewShapeName;
221 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
222 aShapeName = TCollection_AsciiString(strdup(theName));
224 //Set the study entry as a name of the published GEOM_Object
225 aShape->SetStudyEntry(aResultSO->GetID());
227 //Set a name of the added shape
228 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
229 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
230 aNameAttrib->SetValue(aShapeName.ToCString());
232 return aResultSO._retn();
236 //============================================================================
238 // purpose : save OCAF/Geom document
239 //============================================================================
240 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
243 SALOMEDS::TMPFile_var aStreamFile;
244 // Get a temporary directory to store a file
245 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
246 // Create a list to store names of created files
247 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
249 // Prepare a file name to open
250 TCollection_AsciiString aNameWithExt("");
252 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
253 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
254 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
255 // Build a full file name of temporary file
256 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
257 // Save GEOM component in this file
258 _impl->Save(theComponent->GetStudy()->StudyId(), aFullName.ToCString());
259 // Conver a file to the byte stream
260 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
261 // Remove the created file and tmp directory
262 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
264 // Return the created byte stream
265 return aStreamFile._retn();
269 //============================================================================
270 // function : SaveASCII()
272 //============================================================================
273 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
276 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
277 return aStreamFile._retn();
281 //============================================================================
284 //============================================================================
285 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
286 const SALOMEDS::TMPFile& theStream,
290 if (theStream.length() <= 9) {
291 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
295 // Get a temporary directory for a file
296 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
297 // Conver the byte stream theStream to a file and place it in tmp directory
298 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
300 // Prepare a file name to open
301 TCollection_AsciiString aNameWithExt("");
303 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
304 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
305 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
308 if (!_impl->Load(theComponent->GetStudy()->StudyId(), aFullName.ToCString())) return false;
310 // Remove the created file and tmp directory
311 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
313 SALOMEDS::Study_var Study = theComponent->GetStudy();
314 TCollection_AsciiString name( strdup(Study->Name()) );
320 //============================================================================
321 // function : LoadASCII()
323 //============================================================================
324 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
325 const SALOMEDS::TMPFile& theStream,
328 return Load(theComponent, theStream, theURL, isMultiFile);
332 //============================================================================
333 // function : Close()
335 //============================================================================
336 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
338 _impl->Close(theComponent->GetStudy()->StudyId());
341 //============================================================================
342 // function : CanCopy()
344 //============================================================================
345 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
346 // Try to retrieve known by Geometry component GEOM_Object by given IOR
347 SALOMEDS::GenericAttribute_var anAttr;
348 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
350 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
352 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
353 // If the object is null one it can't be copied: return false
354 if (anObject->_is_nil()) return false;
358 //============================================================================
359 // function : CopyFrom()
361 //============================================================================
362 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
363 // Declare a sequence of the byte to store the copied object
364 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
366 // Try to get GEOM_Object object by given SObject
367 SALOMEDS::GenericAttribute_var anAttr;
368 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
369 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
370 if (anObject->_is_nil()) return aStreamFile._retn();
372 aStreamFile = anObject->GetShapeStream();
374 // Assign an ID the type of GEOM_Object
375 theObjectID = anObject->GetType();
377 // Return created TMPFile
378 return aStreamFile._retn();
381 //============================================================================
382 // function : CanPaste()
384 //============================================================================
385 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
386 // The Geometry component can paste only objects copied by Geometry component
387 // and with the object type = 1
388 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
392 //============================================================================
393 // function : PasteInto()
395 //============================================================================
396 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
397 CORBA::Long theObjectID,
398 SALOMEDS::SObject_ptr theObject) {
399 // Find the current Study and StudyBuilder
400 SALOMEDS::Study_var aStudy = theObject->GetStudy();
401 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
403 // Retrieve a TopoDS_Shape from byte stream
404 TopoDS_Shape aTopology;
405 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
406 BRep_Builder aBuilder;
408 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
409 } catch (Standard_Failure) {
413 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
414 SALOMEDS::SObject_var aNewSO;
415 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
416 aNewSO = aStudyBuilder->NewObject(theObject);
417 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
420 //Create a new GEOM_Object
421 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
422 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
423 aFunction->SetValue(aTopology);
425 TCollection_AsciiString anEntry;
426 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
427 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
429 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
430 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
431 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
432 anIOR->SetValue(_orb->object_to_string(obj));
434 // Return the created in the Study SObject
435 return aNewSO._retn();
438 //============================================================================
439 // function : ComponentDataType()
441 //============================================================================
442 char* GEOM_Gen_i::ComponentDataType()
444 return strdup("GEOM");
447 //============================================================================
448 // function : AddInStudy
450 //============================================================================
451 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM::GEOM_Object_ptr theObject, const char* theName, GEOM::GEOM_Object_ptr theFather)
453 SALOMEDS::SObject_var aResultSO;
454 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
456 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
459 if(!theFather->_is_nil()) {
460 IOR = _orb->object_to_string(theFather);
461 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR);
462 if(aFatherSO->_is_nil()) return aResultSO._retn();
463 aResultSO = aStudyBuilder->NewObject(aFatherSO);
464 //aStudyBuilder->Addreference(aResultSO, aResultSO);
467 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
468 if(aResultSO->_is_nil()) return aResultSO._retn();
470 GEOM::ListOfGO_var aList = theObject->GetDependency();
471 Standard_Integer aLength = aList->length();
472 if(aLength < 1) return aResultSO._retn();
474 //Publish the arguments
475 for(Standard_Integer i = 0; i< aLength; i++) {
476 GEOM::GEOM_Object_var anObject = aList[i];
477 if(anObject->_is_nil()) continue;
478 IOR = _orb->object_to_string(anObject);
479 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR);
480 if(aSO->_is_nil()) continue;
481 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
482 aStudyBuilder->Addreference(aSubSO, aSO);
485 return aResultSO._retn();
488 //============================================================================
489 // function : register()
490 // purpose : register 'name' in 'name_service'
491 //============================================================================
492 void GEOM_Gen_i::register_name(char * name)
494 GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(POA_GEOM::GEOM_Gen::_this());
495 name_service->Register(g, strdup(name));
498 //============================================================================
501 //============================================================================
502 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
504 _impl->Undo(theStudyID);
507 //============================================================================
510 //============================================================================
511 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
513 _impl->Redo(theStudyID);
516 //============================================================================
517 // function : GetIBasicOperations
519 //============================================================================
520 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
521 throw ( SALOME::SALOME_Exception )
523 Unexpect aCatch(SALOME_SalomeException);
524 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
526 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
528 GEOM_IBasicOperations_i* aServant =
529 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
531 // activate the CORBA servant
532 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
533 return operations._retn();
536 //============================================================================
537 // function : GetITransformOperations
539 //============================================================================
540 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
541 throw ( SALOME::SALOME_Exception )
543 Unexpect aCatch(SALOME_SalomeException);
544 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
546 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
548 GEOM_ITransformOperations_i* aServant =
549 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
551 // activate the CORBA servant
552 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
553 return operations._retn();
556 //============================================================================
557 // function : GetI3DPrimOperations
559 //============================================================================
560 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
561 throw ( SALOME::SALOME_Exception )
563 Unexpect aCatch(SALOME_SalomeException);
564 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
566 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
568 GEOM_I3DPrimOperations_i* aServant =
569 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
571 // activate the CORBA servant
572 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
573 return operations._retn();
576 //============================================================================
577 // function : GetIShapesOperations
579 //============================================================================
580 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
581 throw ( SALOME::SALOME_Exception )
583 Unexpect aCatch(SALOME_SalomeException);
584 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
586 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
588 GEOM_IShapesOperations_i* aServant =
589 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
591 // activate the CORBA servant
592 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
593 return operations._retn();
596 //============================================================================
597 // function : GetIBlocksOperations
599 //============================================================================
600 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
601 throw ( SALOME::SALOME_Exception )
603 Unexpect aCatch(SALOME_SalomeException);
604 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
606 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
608 GEOM_IBlocksOperations_i* aServant =
609 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
611 // activate the CORBA servant
612 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
613 return operations._retn();
616 //============================================================================
617 // function : GetIBooleanOperations
619 //============================================================================
620 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
621 throw ( SALOME::SALOME_Exception )
623 Unexpect aCatch(SALOME_SalomeException);
624 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
626 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
628 GEOM_IBooleanOperations_i* aServant =
629 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
631 // activate the CORBA servant
632 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
633 return operations._retn();
636 //============================================================================
637 // function : GetICurvesOperations
639 //============================================================================
640 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
641 throw ( SALOME::SALOME_Exception )
643 Unexpect aCatch(SALOME_SalomeException);
644 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
646 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
648 GEOM_ICurvesOperations_i* aServant =
649 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
651 // activate the CORBA servant
652 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
653 return operations._retn();
656 //============================================================================
657 // function : GetILocalOperations
659 //============================================================================
660 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
661 throw ( SALOME::SALOME_Exception )
663 Unexpect aCatch(SALOME_SalomeException);
664 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
666 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
668 GEOM_ILocalOperations_i* aServant =
669 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
671 // activate the CORBA servant
672 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
673 return operations._retn();
676 //============================================================================
677 // function : GetIHealingOperations
679 //============================================================================
680 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
681 throw ( SALOME::SALOME_Exception )
683 Unexpect aCatch(SALOME_SalomeException);
684 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
686 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
688 GEOM_IHealingOperations_i* aServant =
689 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
691 // activate the CORBA servant
692 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
693 return operations._retn();
696 //============================================================================
697 // function : GetIInsertOperations
699 //============================================================================
700 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
701 throw ( SALOME::SALOME_Exception )
703 Unexpect aCatch(SALOME_SalomeException);
704 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
706 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
708 GEOM_IInsertOperations_i* aServant =
709 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
711 // activate the CORBA servant
712 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
713 return operations._retn();
716 //============================================================================
717 // function : GetIMeasureOperations
719 //============================================================================
720 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
721 throw ( SALOME::SALOME_Exception )
723 Unexpect aCatch(SALOME_SalomeException);
724 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
726 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
728 GEOM_IMeasureOperations_i* aServant =
729 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
731 // activate the CORBA servant
732 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
733 return operations._retn();
736 //============================================================================
737 // function : GetIGroupOperations
739 //============================================================================
740 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
741 throw ( SALOME::SALOME_Exception )
743 Unexpect aCatch(SALOME_SalomeException);
744 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
746 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
748 GEOM_IGroupOperations_i* aServant =
749 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
751 // activate the CORBA servant
752 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
753 return operations._retn();
756 //=============================================================================
760 //=============================================================================
761 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape(GEOM::GEOM_Object_ptr theMainShape, const GEOM::ListOfLong& theIndices)
763 if(theMainShape == NULL || theIndices.length() < 1) return GEOM::GEOM_Object::_nil();
764 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
765 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
767 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
768 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
770 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray);
771 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
773 TCollection_AsciiString anEntry;
774 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
775 return GetObject(anObject->GetDocID(), anEntry.ToCString());
778 //=============================================================================
782 //=============================================================================
783 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
785 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
786 if (anObject.IsNull()) return;
787 _impl->RemoveObject(anObject);
792 //=================================================================================
793 // function : GetStringFromIOR()
794 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
795 //=================================================================================
796 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
797 return _orb->object_to_string(theObject);
801 //=================================================================================
802 // function : GetIORFromString()
803 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
804 //=================================================================================
805 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
806 GEOM::GEOM_Object_var aGeomObject;
807 if(strcmp(stringIOR,"") != 0){
808 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
809 if(!CORBA::is_nil(anObject))
810 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in()) ;
812 return aGeomObject._retn() ;
815 //=================================================================================
816 // function : GetObject()
818 //=================================================================================
819 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject(CORBA::Long theStudyID, const char* theEntry)
821 GEOM::GEOM_Object_var obj;
822 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
823 if(handle_object.IsNull()) return NULL;
824 TCollection_AsciiString stringIOR = handle_object->GetIOR();
825 if(stringIOR.Length() > 1) {
826 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
827 if(!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
831 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
832 GEOM_Object_i* servant = new GEOM_Object_i(_poa, engine, handle_object);
834 obj = servant->_this();
835 stringIOR = _orb->object_to_string(obj);
836 handle_object->SetIOR(stringIOR);
841 //=====================================================================================
843 //=====================================================================================
846 PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
847 PortableServer::POA_ptr poa,
848 PortableServer::ObjectId * contId,
849 const char *instanceName,
850 const char * interfaceName)
852 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
853 myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
854 return myGEOM_Gen_i->getId() ;