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 //Set the study entry as a name of the published GEOM_Object
207 aShape->SetStudyEntry(aResultSO->GetID());
209 //Set a name of the added shape
210 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
211 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
212 aNameAttrib->SetValue(aShapeName.ToCString());
214 return aResultSO._retn();
218 //============================================================================
220 // purpose : save OCAF/Geom document
221 //============================================================================
222 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
225 SALOMEDS::TMPFile_var aStreamFile;
226 // Get a temporary directory to store a file
227 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
228 // Create a list to store names of created files
229 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
231 // Prepare a file name to open
232 TCollection_AsciiString aNameWithExt("");
234 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
235 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
236 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
237 // Build a full file name of temporary file
238 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
239 // Save GEOM component in this file
240 _impl->Save(theComponent->GetStudy()->StudyId(), aFullName.ToCString());
241 // Conver a file to the byte stream
242 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
243 // Remove the created file and tmp directory
244 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
246 // Return the created byte stream
247 return aStreamFile._retn();
251 //============================================================================
252 // function : SaveASCII()
254 //============================================================================
255 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
258 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
259 return aStreamFile._retn();
263 //============================================================================
266 //============================================================================
267 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
268 const SALOMEDS::TMPFile& theStream,
272 if (theStream.length() <= 9) {
273 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
277 // Get a temporary directory for a file
278 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
279 // Conver the byte stream theStream to a file and place it in tmp directory
280 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
282 // Prepare a file name to open
283 TCollection_AsciiString aNameWithExt("");
285 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
286 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
287 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
290 if (!_impl->Load(theComponent->GetStudy()->StudyId(), aFullName.ToCString())) return false;
292 // Remove the created file and tmp directory
293 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
295 SALOMEDS::Study_var Study = theComponent->GetStudy();
296 TCollection_AsciiString name( strdup(Study->Name()) );
302 //============================================================================
303 // function : LoadASCII()
305 //============================================================================
306 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
307 const SALOMEDS::TMPFile& theStream,
310 return Load(theComponent, theStream, theURL, isMultiFile);
314 //============================================================================
315 // function : Close()
317 //============================================================================
318 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
320 _impl->Close(theComponent->GetStudy()->StudyId());
323 //============================================================================
324 // function : CanCopy()
326 //============================================================================
327 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
328 // Try to retrieve known by Geometry component GEOM_Object by given IOR
329 SALOMEDS::GenericAttribute_var anAttr;
330 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
332 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
334 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
335 // If the object is null one it can't be copied: return false
336 if (anObject->_is_nil()) return false;
340 //============================================================================
341 // function : CopyFrom()
343 //============================================================================
344 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
345 // Declare a sequence of the byte to store the copied object
346 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
348 // Try to get GEOM_Object object by given SObject
349 SALOMEDS::GenericAttribute_var anAttr;
350 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
351 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
352 if (anObject->_is_nil()) return aStreamFile._retn();
354 aStreamFile = anObject->GetShapeStream();
356 // Assign an ID the type of GEOM_Object
357 theObjectID = anObject->GetType();
359 // Return created TMPFile
360 return aStreamFile._retn();
363 //============================================================================
364 // function : CanPaste()
366 //============================================================================
367 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
368 // The Geometry component can paste only objects copied by Geometry component
369 // and with the object type = 1
370 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
374 //============================================================================
375 // function : PasteInto()
377 //============================================================================
378 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
379 CORBA::Long theObjectID,
380 SALOMEDS::SObject_ptr theObject) {
381 // Find the current Study and StudyBuilder
382 SALOMEDS::Study_var aStudy = theObject->GetStudy();
383 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
385 // Retrieve a TopoDS_Shape from byte stream
386 TopoDS_Shape aTopology;
387 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
388 BRep_Builder aBuilder;
390 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
391 } catch (Standard_Failure) {
395 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
396 SALOMEDS::SObject_var aNewSO;
397 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
398 aNewSO = aStudyBuilder->NewObject(theObject);
399 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
402 //Create a new GEOM_Object
403 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
404 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
405 aFunction->SetValue(aTopology);
407 TCollection_AsciiString anEntry;
408 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
409 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
411 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
412 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
413 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
414 anIOR->SetValue(_orb->object_to_string(obj));
416 // Return the created in the Study SObject
417 return aNewSO._retn();
420 //============================================================================
421 // function : ComponentDataType()
423 //============================================================================
424 char* GEOM_Gen_i::ComponentDataType()
426 return strdup("GEOM");
429 //============================================================================
430 // function : AddInStudy
432 //============================================================================
433 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM::GEOM_Object_ptr theObject, const char* theName, GEOM::GEOM_Object_ptr theFather)
435 SALOMEDS::SObject_var aResultSO;
436 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
438 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
441 if(!theFather->_is_nil()) {
442 IOR = _orb->object_to_string(theFather);
443 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR);
444 if(aFatherSO->_is_nil()) return aResultSO._retn();
445 aResultSO = aStudyBuilder->NewObject(aFatherSO);
446 //aStudyBuilder->Addreference(aResultSO, aResultSO);
449 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
450 if(aResultSO->_is_nil()) return aResultSO._retn();
452 GEOM::ListOfGO_var aList = theObject->GetDependency();
453 Standard_Integer aLength = aList->length();
454 if(aLength < 1) return aResultSO._retn();
456 //Publish the arguments
457 for(Standard_Integer i = 0; i< aLength; i++) {
458 GEOM::GEOM_Object_var anObject = aList[i];
459 if(anObject->_is_nil()) continue;
460 IOR = _orb->object_to_string(anObject);
461 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR);
462 if(aSO->_is_nil()) continue;
463 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
464 aStudyBuilder->Addreference(aSubSO, aSO);
467 return aResultSO._retn();
470 //============================================================================
471 // function : register()
472 // purpose : register 'name' in 'name_service'
473 //============================================================================
474 void GEOM_Gen_i::register_name(char * name)
476 GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(POA_GEOM::GEOM_Gen::_this());
477 name_service->Register(g, strdup(name));
480 //============================================================================
483 //============================================================================
484 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
486 _impl->Undo(theStudyID);
489 //============================================================================
492 //============================================================================
493 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
495 _impl->Redo(theStudyID);
498 //============================================================================
499 // function : GetIBasicOperations
501 //============================================================================
502 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
503 throw ( SALOME::SALOME_Exception )
505 Unexpect aCatch(SALOME_SalomeException);
506 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
508 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
510 GEOM_IBasicOperations_i* aServant =
511 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
513 // activate the CORBA servant
514 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
515 return operations._retn();
518 //============================================================================
519 // function : GetITransformOperations
521 //============================================================================
522 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
523 throw ( SALOME::SALOME_Exception )
525 Unexpect aCatch(SALOME_SalomeException);
526 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
528 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
530 GEOM_ITransformOperations_i* aServant =
531 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
533 // activate the CORBA servant
534 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
535 return operations._retn();
538 //============================================================================
539 // function : GetI3DPrimOperations
541 //============================================================================
542 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
543 throw ( SALOME::SALOME_Exception )
545 Unexpect aCatch(SALOME_SalomeException);
546 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
548 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
550 GEOM_I3DPrimOperations_i* aServant =
551 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
553 // activate the CORBA servant
554 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
555 return operations._retn();
558 //============================================================================
559 // function : GetIShapesOperations
561 //============================================================================
562 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
563 throw ( SALOME::SALOME_Exception )
565 Unexpect aCatch(SALOME_SalomeException);
566 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
568 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
570 GEOM_IShapesOperations_i* aServant =
571 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
573 // activate the CORBA servant
574 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
575 return operations._retn();
578 //============================================================================
579 // function : GetIBlocksOperations
581 //============================================================================
582 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
583 throw ( SALOME::SALOME_Exception )
585 Unexpect aCatch(SALOME_SalomeException);
586 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
588 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
590 GEOM_IBlocksOperations_i* aServant =
591 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
593 // activate the CORBA servant
594 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
595 return operations._retn();
598 //============================================================================
599 // function : GetIBooleanOperations
601 //============================================================================
602 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
603 throw ( SALOME::SALOME_Exception )
605 Unexpect aCatch(SALOME_SalomeException);
606 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
608 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
610 GEOM_IBooleanOperations_i* aServant =
611 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
613 // activate the CORBA servant
614 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
615 return operations._retn();
618 //============================================================================
619 // function : GetICurvesOperations
621 //============================================================================
622 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
623 throw ( SALOME::SALOME_Exception )
625 Unexpect aCatch(SALOME_SalomeException);
626 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
628 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
630 GEOM_ICurvesOperations_i* aServant =
631 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
633 // activate the CORBA servant
634 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
635 return operations._retn();
638 //============================================================================
639 // function : GetILocalOperations
641 //============================================================================
642 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
643 throw ( SALOME::SALOME_Exception )
645 Unexpect aCatch(SALOME_SalomeException);
646 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
648 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
650 GEOM_ILocalOperations_i* aServant =
651 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
653 // activate the CORBA servant
654 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
655 return operations._retn();
658 //============================================================================
659 // function : GetIHealingOperations
661 //============================================================================
662 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
663 throw ( SALOME::SALOME_Exception )
665 Unexpect aCatch(SALOME_SalomeException);
666 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
668 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
670 GEOM_IHealingOperations_i* aServant =
671 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
673 // activate the CORBA servant
674 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
675 return operations._retn();
678 //============================================================================
679 // function : GetIInsertOperations
681 //============================================================================
682 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
683 throw ( SALOME::SALOME_Exception )
685 Unexpect aCatch(SALOME_SalomeException);
686 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
688 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
690 GEOM_IInsertOperations_i* aServant =
691 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
693 // activate the CORBA servant
694 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
695 return operations._retn();
698 //============================================================================
699 // function : GetIMeasureOperations
701 //============================================================================
702 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
703 throw ( SALOME::SALOME_Exception )
705 Unexpect aCatch(SALOME_SalomeException);
706 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
708 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
710 GEOM_IMeasureOperations_i* aServant =
711 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
713 // activate the CORBA servant
714 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
715 return operations._retn();
718 //============================================================================
719 // function : GetIGroupOperations
721 //============================================================================
722 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
723 throw ( SALOME::SALOME_Exception )
725 Unexpect aCatch(SALOME_SalomeException);
726 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
728 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
730 GEOM_IGroupOperations_i* aServant =
731 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
733 // activate the CORBA servant
734 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
735 return operations._retn();
738 //=============================================================================
742 //=============================================================================
743 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape(GEOM::GEOM_Object_ptr theMainShape, const GEOM::ListOfLong& theIndices)
745 if(theMainShape == NULL || theIndices.length() < 1) return GEOM::GEOM_Object::_nil();
746 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
747 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
749 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
750 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
752 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray);
753 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
755 TCollection_AsciiString anEntry;
756 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
757 return GetObject(anObject->GetDocID(), anEntry.ToCString());
760 //=============================================================================
764 //=============================================================================
765 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
767 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
768 if (anObject.IsNull()) return;
769 _impl->RemoveObject(anObject);
774 //=================================================================================
775 // function : GetStringFromIOR()
776 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
777 //=================================================================================
778 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
779 return _orb->object_to_string(theObject);
783 //=================================================================================
784 // function : GetIORFromString()
785 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
786 //=================================================================================
787 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
788 GEOM::GEOM_Object_var aGeomObject;
789 if(strcmp(stringIOR,"") != 0){
790 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
791 if(!CORBA::is_nil(anObject))
792 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in()) ;
794 return aGeomObject._retn() ;
797 //=================================================================================
798 // function : GetObject()
800 //=================================================================================
801 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject(CORBA::Long theStudyID, const char* theEntry)
803 GEOM::GEOM_Object_var obj;
804 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
805 if(handle_object.IsNull()) return NULL;
806 TCollection_AsciiString stringIOR = handle_object->GetIOR();
807 if(stringIOR.Length() > 1) {
808 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
809 if(!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
813 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
814 GEOM_Object_i* servant = new GEOM_Object_i(_poa, engine, handle_object);
816 obj = servant->_this();
817 stringIOR = _orb->object_to_string(obj);
818 handle_object->SetIOR(stringIOR);
823 //=====================================================================================
825 //=====================================================================================
828 PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
829 PortableServer::POA_ptr poa,
830 PortableServer::ObjectId * contId,
831 const char *instanceName,
832 const char * interfaceName)
834 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
835 myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
836 return myGEOM_Gen_i->getId() ;