2 #pragma warning( disable:4786 )
5 #include <Standard_Stream.hxx>
7 #include "GEOM_Gen_i.hh"
8 #include "GEOM_Object_i.hh"
12 #include "Utils_CorbaException.hxx"
14 #include "Utils_ExceptHandlers.hxx"
15 #include "utilities.h"
17 #include "GEOM_Object_i.hh"
18 #include "GEOM_Object.hxx"
19 #include "GEOM_Function.hxx"
20 #include "GEOMImpl_Types.hxx"
21 #include "GEOMImpl_CopyDriver.hxx"
24 #include <BRep_Builder.hxx>
25 #include <BRepTools.hxx>
26 #include <TDF_Label.hxx>
27 #include <TDF_Tool.hxx>
28 #include <TCollection_AsciiString.hxx>
29 #include <TColStd_HArray1OfInteger.hxx>
30 #include <TopAbs_ShapeEnum.hxx>
32 #include "SALOMEDS_Tool.hxx"
34 //============================================================================
35 // function : GEOM_Gen_i()
36 // purpose : constructor to be called for servant creation.
37 //============================================================================
38 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
39 PortableServer::POA_ptr poa,
40 PortableServer::ObjectId * contId,
41 const char *instanceName,
42 const char *interfaceName) :
43 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
46 _id = _poa->activate_object(_thisObj);
47 name_service = new SALOME_NamingService(_orb);
49 _impl = new ::GEOMImpl_Gen;
55 //============================================================================
56 // function : ~GEOM_Gen_i()
57 // purpose : destructor
58 //============================================================================
59 GEOM_Gen_i::~GEOM_Gen_i() {
65 //============================================================================
66 // function : IORToLocalPersistentID()
68 //============================================================================
69 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
70 const char* IORString,
71 CORBA::Boolean isMultiFile,
72 CORBA::Boolean isASCII)
74 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
75 if (!CORBA::is_nil(anObject)) {
76 return strdup(anObject->GetEntry());
82 //============================================================================
83 // function : LocalPersistentIDToIOR()
84 // purpose : Create/Load CORBA object from a persistent ref (an entry)
85 // : Used when a study is loaded
86 // : The IOR (IORName) of object created is returned
87 //============================================================================
88 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
89 const char* aLocalPersistentID,
90 CORBA::Boolean isMultiFile,
91 CORBA::Boolean isASCII)
93 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
95 Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
96 TCollection_AsciiString anEntry;
97 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
98 GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
100 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
101 return strdup(aPersRefString);
104 //============================================================================
105 // function : CanPublishInStudy
107 //============================================================================
108 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
110 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
111 return !(anObject->_is_nil());
115 //============================================================================
116 // function : PublishInStudy
118 //============================================================================
119 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
120 SALOMEDS::SObject_ptr theSObject,
121 CORBA::Object_ptr theObject,
122 const char* theName) throw (SALOME::SALOME_Exception)
124 Unexpect aCatch(SALOME_SalomeException);
125 SALOMEDS::SObject_var aResultSO;
126 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
128 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
129 if(aShape->_is_nil()) return aResultSO;
131 SALOMEDS::GenericAttribute_var anAttr;
132 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
134 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
135 if (aFather->_is_nil()) {
136 aFather = aStudyBuilder->NewComponent("GEOM");
137 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
138 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
139 aName->SetValue("Geometry");
140 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
141 SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
142 aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
144 if (aFather->_is_nil()) return aResultSO;
146 if (CORBA::is_nil(theSObject)) {
147 aResultSO = aStudyBuilder->NewObject(aFather);
149 if (!theSObject->ReferencedObject(aResultSO))
150 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
151 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
153 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
154 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
155 char *aGeomObjIOR = _orb->object_to_string(theObject);
156 anIOR->SetValue(strdup(aGeomObjIOR));
158 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
159 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
160 TCollection_AsciiString aShapeName("Shape_");
162 if ( aShape->GetType() == GEOM_GROUP ) {
163 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
164 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
166 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
167 aShapeName = "Group_Of_Vertices_";
170 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
171 aShapeName = "Group_Of_Edges_";
174 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
175 aShapeName = "Group_Of_Faces_";
178 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
179 aShapeName = "Group_Of_Solids_";
182 } else if ( aShape->GetType() == GEOM_MARKER ) {
183 aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
184 aShapeName = "LocalCS_";
185 } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
186 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
187 aShapeName = "Compound_";
188 } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
189 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
190 aShapeName = "Compsolid_";
191 } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
192 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
193 aShapeName = "Solid_";
194 } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
195 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
196 aShapeName = "Shell_";
197 } else if ( aShape->GetShapeType() == GEOM::FACE ) {
198 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
199 aShapeName = "Face_";
200 } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
201 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
202 aShapeName = "Wire_";
203 } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
204 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
205 aShapeName = "Edge_";
206 } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
207 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
208 aShapeName = "Vertex_";
210 //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
211 //else aShapeName = TCollection_AsciiString(strdup(theName));
213 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
214 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
215 // of objects in the study, but compute a number of objects with the same prefix
216 // and build a new name as Prefix_N+1
217 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
218 int i = 0; // (WITH EMPTY NEW NAME)
219 SALOMEDS::SObject_var obj;
220 TCollection_AsciiString aNewShapeName;
222 aNewShapeName = aShapeName + TCollection_AsciiString(++i);
223 obj = theStudy->FindObject( aNewShapeName.ToCString() );
225 while ( !obj->_is_nil() );
226 aShapeName = aNewShapeName;
228 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
229 aShapeName = TCollection_AsciiString(strdup(theName));
231 //Set the study entry as a name of the published GEOM_Object
232 aShape->SetStudyEntry(aResultSO->GetID());
234 //Set a name of the added shape
235 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
236 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
237 aNameAttrib->SetValue(aShapeName.ToCString());
239 return aResultSO._retn();
243 //============================================================================
245 // purpose : save OCAF/Geom document
246 //============================================================================
247 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
250 SALOMEDS::TMPFile_var aStreamFile;
251 // Get a temporary directory to store a file
252 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
253 // Create a list to store names of created files
254 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
256 // Prepare a file name to open
257 TCollection_AsciiString aNameWithExt("");
259 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
260 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
261 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
262 // Build a full file name of temporary file
263 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
264 // Save GEOM component in this file
265 _impl->Save(theComponent->GetStudy()->StudyId(), aFullName.ToCString());
266 // Conver a file to the byte stream
267 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
268 // Remove the created file and tmp directory
269 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
271 // Return the created byte stream
272 return aStreamFile._retn();
276 //============================================================================
277 // function : SaveASCII()
279 //============================================================================
280 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
283 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
284 return aStreamFile._retn();
288 //============================================================================
291 //============================================================================
292 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
293 const SALOMEDS::TMPFile& theStream,
297 if (theStream.length() <= 9) {
298 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
302 // Get a temporary directory for a file
303 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
304 // Conver the byte stream theStream to a file and place it in tmp directory
305 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
307 // Prepare a file name to open
308 TCollection_AsciiString aNameWithExt("");
310 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
311 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
312 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
315 if (!_impl->Load(theComponent->GetStudy()->StudyId(), aFullName.ToCString())) return false;
317 // Remove the created file and tmp directory
318 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
320 SALOMEDS::Study_var Study = theComponent->GetStudy();
321 TCollection_AsciiString name( strdup(Study->Name()) );
327 //============================================================================
328 // function : LoadASCII()
330 //============================================================================
331 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
332 const SALOMEDS::TMPFile& theStream,
335 return Load(theComponent, theStream, theURL, isMultiFile);
339 //============================================================================
340 // function : Close()
342 //============================================================================
343 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
345 _impl->Close(theComponent->GetStudy()->StudyId());
348 //============================================================================
349 // function : CanCopy()
351 //============================================================================
352 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
353 // Try to retrieve known by Geometry component GEOM_Object by given IOR
354 SALOMEDS::GenericAttribute_var anAttr;
355 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
357 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
359 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
360 // If the object is null one it can't be copied: return false
361 if (anObject->_is_nil()) return false;
365 //============================================================================
366 // function : CopyFrom()
368 //============================================================================
369 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
370 // Declare a sequence of the byte to store the copied object
371 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
373 // Try to get GEOM_Object object by given SObject
374 SALOMEDS::GenericAttribute_var anAttr;
375 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
376 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
377 if (anObject->_is_nil()) return aStreamFile._retn();
379 aStreamFile = anObject->GetShapeStream();
381 // Assign an ID the type of GEOM_Object
382 theObjectID = anObject->GetType();
384 // Return created TMPFile
385 return aStreamFile._retn();
388 //============================================================================
389 // function : CanPaste()
391 //============================================================================
392 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
393 // The Geometry component can paste only objects copied by Geometry component
394 // and with the object type = 1
395 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
399 //============================================================================
400 // function : PasteInto()
402 //============================================================================
403 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
404 CORBA::Long theObjectID,
405 SALOMEDS::SObject_ptr theObject) {
406 // Find the current Study and StudyBuilder
407 SALOMEDS::Study_var aStudy = theObject->GetStudy();
408 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
410 // Retrieve a TopoDS_Shape from byte stream
411 TopoDS_Shape aTopology;
412 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
413 BRep_Builder aBuilder;
415 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
416 } catch (Standard_Failure) {
420 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
421 SALOMEDS::SObject_var aNewSO;
422 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
423 aNewSO = aStudyBuilder->NewObject(theObject);
424 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
427 //Create a new GEOM_Object
428 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
429 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
430 aFunction->SetValue(aTopology);
432 TCollection_AsciiString anEntry;
433 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
434 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
436 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
437 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
438 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
439 anIOR->SetValue(_orb->object_to_string(obj));
441 // Return the created in the Study SObject
442 return aNewSO._retn();
445 //============================================================================
446 // function : ComponentDataType()
448 //============================================================================
449 char* GEOM_Gen_i::ComponentDataType()
451 return strdup("GEOM");
454 //============================================================================
455 // function : AddInStudy
457 //============================================================================
458 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM::GEOM_Object_ptr theObject, const char* theName, GEOM::GEOM_Object_ptr theFather)
460 SALOMEDS::SObject_var aResultSO;
461 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
463 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
466 if(!theFather->_is_nil()) {
467 IOR = _orb->object_to_string(theFather);
468 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR);
469 if(aFatherSO->_is_nil()) return aResultSO._retn();
470 aResultSO = aStudyBuilder->NewObject(aFatherSO);
471 //aStudyBuilder->Addreference(aResultSO, aResultSO);
474 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
475 if(aResultSO->_is_nil()) return aResultSO._retn();
477 GEOM::ListOfGO_var aList = theObject->GetDependency();
478 Standard_Integer aLength = aList->length();
479 if(aLength < 1) return aResultSO._retn();
481 //Publish the arguments
482 for(Standard_Integer i = 0; i< aLength; i++) {
483 GEOM::GEOM_Object_var anObject = aList[i];
484 if(anObject->_is_nil()) continue;
485 IOR = _orb->object_to_string(anObject);
486 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR);
487 if(aSO->_is_nil()) continue;
488 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
489 aStudyBuilder->Addreference(aSubSO, aSO);
492 return aResultSO._retn();
495 //============================================================================
496 // function : register()
497 // purpose : register 'name' in 'name_service'
498 //============================================================================
499 void GEOM_Gen_i::register_name(char * name)
501 GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(_this());
502 name_service->Register(g, strdup(name));
505 //============================================================================
508 //============================================================================
509 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
511 _impl->Undo(theStudyID);
514 //============================================================================
517 //============================================================================
518 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
520 _impl->Redo(theStudyID);
523 //============================================================================
524 // function : GetIBasicOperations
526 //============================================================================
527 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
528 throw ( SALOME::SALOME_Exception )
530 Unexpect aCatch(SALOME_SalomeException);
531 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
533 GEOM::GEOM_Gen_ptr engine = _this();
535 GEOM_IBasicOperations_i* aServant =
536 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
538 // activate the CORBA servant
539 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
540 return operations._retn();
543 //============================================================================
544 // function : GetITransformOperations
546 //============================================================================
547 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
548 throw ( SALOME::SALOME_Exception )
550 Unexpect aCatch(SALOME_SalomeException);
551 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
553 GEOM::GEOM_Gen_ptr engine = _this();
555 GEOM_ITransformOperations_i* aServant =
556 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
558 // activate the CORBA servant
559 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
560 return operations._retn();
563 //============================================================================
564 // function : GetI3DPrimOperations
566 //============================================================================
567 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
568 throw ( SALOME::SALOME_Exception )
570 Unexpect aCatch(SALOME_SalomeException);
571 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
573 GEOM::GEOM_Gen_ptr engine = _this();
575 GEOM_I3DPrimOperations_i* aServant =
576 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
578 // activate the CORBA servant
579 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
580 return operations._retn();
583 //============================================================================
584 // function : GetIShapesOperations
586 //============================================================================
587 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
588 throw ( SALOME::SALOME_Exception )
590 Unexpect aCatch(SALOME_SalomeException);
591 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
593 GEOM::GEOM_Gen_ptr engine = _this();
595 GEOM_IShapesOperations_i* aServant =
596 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
598 // activate the CORBA servant
599 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
600 return operations._retn();
603 //============================================================================
604 // function : GetIBlocksOperations
606 //============================================================================
607 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
608 throw ( SALOME::SALOME_Exception )
610 Unexpect aCatch(SALOME_SalomeException);
611 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
613 GEOM::GEOM_Gen_ptr engine = _this();
615 GEOM_IBlocksOperations_i* aServant =
616 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
618 // activate the CORBA servant
619 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
620 return operations._retn();
623 //============================================================================
624 // function : GetIBooleanOperations
626 //============================================================================
627 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
628 throw ( SALOME::SALOME_Exception )
630 Unexpect aCatch(SALOME_SalomeException);
631 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
633 GEOM::GEOM_Gen_ptr engine = _this();
635 GEOM_IBooleanOperations_i* aServant =
636 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
638 // activate the CORBA servant
639 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
640 return operations._retn();
643 //============================================================================
644 // function : GetICurvesOperations
646 //============================================================================
647 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
648 throw ( SALOME::SALOME_Exception )
650 Unexpect aCatch(SALOME_SalomeException);
651 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
653 GEOM::GEOM_Gen_ptr engine = _this();
655 GEOM_ICurvesOperations_i* aServant =
656 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
658 // activate the CORBA servant
659 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
660 return operations._retn();
663 //============================================================================
664 // function : GetILocalOperations
666 //============================================================================
667 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
668 throw ( SALOME::SALOME_Exception )
670 Unexpect aCatch(SALOME_SalomeException);
671 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
673 GEOM::GEOM_Gen_ptr engine = _this();
675 GEOM_ILocalOperations_i* aServant =
676 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
678 // activate the CORBA servant
679 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
680 return operations._retn();
683 //============================================================================
684 // function : GetIHealingOperations
686 //============================================================================
687 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
688 throw ( SALOME::SALOME_Exception )
690 Unexpect aCatch(SALOME_SalomeException);
691 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
693 GEOM::GEOM_Gen_ptr engine = _this();
695 GEOM_IHealingOperations_i* aServant =
696 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
698 // activate the CORBA servant
699 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
700 return operations._retn();
703 //============================================================================
704 // function : GetIInsertOperations
706 //============================================================================
707 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
708 throw ( SALOME::SALOME_Exception )
710 Unexpect aCatch(SALOME_SalomeException);
711 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
713 GEOM::GEOM_Gen_ptr engine = _this();
715 GEOM_IInsertOperations_i* aServant =
716 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
718 // activate the CORBA servant
719 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
720 return operations._retn();
723 //============================================================================
724 // function : GetIMeasureOperations
726 //============================================================================
727 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
728 throw ( SALOME::SALOME_Exception )
730 Unexpect aCatch(SALOME_SalomeException);
731 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
733 GEOM::GEOM_Gen_ptr engine = _this();
735 GEOM_IMeasureOperations_i* aServant =
736 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
738 // activate the CORBA servant
739 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
740 return operations._retn();
743 //============================================================================
744 // function : GetIGroupOperations
746 //============================================================================
747 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
748 throw ( SALOME::SALOME_Exception )
750 Unexpect aCatch(SALOME_SalomeException);
751 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
753 GEOM::GEOM_Gen_ptr engine = _this();
755 GEOM_IGroupOperations_i* aServant =
756 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
758 // activate the CORBA servant
759 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
760 return operations._retn();
763 //=============================================================================
767 //=============================================================================
768 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
769 const GEOM::ListOfLong& theIndices)
771 if(theMainShape == NULL || theIndices.length() < 1) return GEOM::GEOM_Object::_nil();
772 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
773 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
775 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
776 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
778 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
779 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
781 TCollection_AsciiString anEntry;
782 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
783 return GetObject(anObject->GetDocID(), anEntry.ToCString());
786 //=============================================================================
790 //=============================================================================
791 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
793 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
794 if (anObject.IsNull()) return;
795 _impl->RemoveObject(anObject);
800 //=================================================================================
801 // function : GetStringFromIOR()
802 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
803 //=================================================================================
804 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
805 return _orb->object_to_string(theObject);
809 //=================================================================================
810 // function : GetIORFromString()
811 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
812 //=================================================================================
813 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
814 GEOM::GEOM_Object_var aGeomObject;
815 if(strcmp(stringIOR,"") != 0){
816 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
817 if(!CORBA::is_nil(anObject))
818 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
820 return aGeomObject._retn();
823 //=================================================================================
824 // function : GetObject()
826 //=================================================================================
827 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
829 GEOM::GEOM_Object_var obj;
830 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
831 if (handle_object.IsNull()) return NULL;
833 TCollection_AsciiString stringIOR = handle_object->GetIOR();
834 if (stringIOR.Length() > 1) {
835 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
836 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
840 GEOM::GEOM_Gen_ptr engine = _this();
841 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
843 obj = servant->_this();
844 stringIOR = _orb->object_to_string(obj);
845 handle_object->SetIOR(stringIOR);
850 //=====================================================================================
852 //=====================================================================================
855 PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
856 PortableServer::POA_ptr poa,
857 PortableServer::ObjectId * contId,
858 const char *instanceName,
859 const char * interfaceName)
861 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
862 myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
863 return myGEOM_Gen_i->getId();