1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #pragma warning( disable:4786 )
24 #include <Standard_Stream.hxx>
26 #include "GEOM_Gen_i.hh"
27 #include "GEOM_Object_i.hh"
31 #include "Utils_CorbaException.hxx"
33 #include "Utils_ExceptHandlers.hxx"
34 #include "utilities.h"
36 #include "GEOM_Object_i.hh"
37 #include "GEOM_Object.hxx"
38 #include "GEOM_Function.hxx"
39 #include "GEOMImpl_Types.hxx"
40 #include "GEOMImpl_CopyDriver.hxx"
43 #include <BRep_Builder.hxx>
44 #include <BRepTools.hxx>
45 #include <TDF_Label.hxx>
46 #include <TDF_Tool.hxx>
47 #include <TCollection_AsciiString.hxx>
48 #include <TColStd_HArray1OfInteger.hxx>
49 #include <TopAbs_ShapeEnum.hxx>
52 #include "SALOMEDS_Tool.hxx"
54 //============================================================================
55 // function : GEOM_Gen_i()
56 // purpose : constructor to be called for servant creation.
57 //============================================================================
58 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
59 PortableServer::POA_ptr poa,
60 PortableServer::ObjectId * contId,
61 const char *instanceName,
62 const char *interfaceName) :
63 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
66 _id = _poa->activate_object(_thisObj);
67 name_service = new SALOME_NamingService(_orb);
69 _impl = new ::GEOMImpl_Gen;
71 //PAL10867: disable signals catching with "noexcepthandler" option
72 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
73 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
75 //work around PAL12004, PAL12628
76 //OSD::SetSignal( true );
80 char* envDisableFPE = getenv("DISABLE_FPE");
81 if (envDisableFPE && atoi(envDisableFPE))
86 OSD::SetSignal( raiseFPE );
90 //============================================================================
91 // function : ~GEOM_Gen_i()
92 // purpose : destructor
93 //============================================================================
94 GEOM_Gen_i::~GEOM_Gen_i() {
100 //============================================================================
101 // function : IORToLocalPersistentID()
103 //============================================================================
104 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
105 const char* IORString,
106 CORBA::Boolean isMultiFile,
107 CORBA::Boolean isASCII)
109 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
110 if (!CORBA::is_nil(anObject)) {
111 return CORBA::string_dup(anObject->GetEntry());
117 //============================================================================
118 // function : LocalPersistentIDToIOR()
119 // purpose : Create/Load CORBA object from a persistent ref (an entry)
120 // : Used when a study is loaded
121 // : The IOR (IORName) of object created is returned
122 //============================================================================
123 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
124 const char* aLocalPersistentID,
125 CORBA::Boolean isMultiFile,
126 CORBA::Boolean isASCII)
128 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
130 Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
131 TCollection_AsciiString anEntry;
132 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
133 GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
135 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
136 return CORBA::string_dup(aPersRefString);
139 //============================================================================
140 // function : CanPublishInStudy
142 //============================================================================
143 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
145 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
146 return !(anObject->_is_nil());
150 //============================================================================
151 // function : PublishInStudy
153 //============================================================================
154 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
155 SALOMEDS::SObject_ptr theSObject,
156 CORBA::Object_ptr theObject,
157 const char* theName) throw (SALOME::SALOME_Exception)
159 Unexpect aCatch(SALOME_SalomeException);
160 SALOMEDS::SObject_var aResultSO;
161 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
163 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
164 if(aShape->_is_nil()) return aResultSO;
166 SALOMEDS::GenericAttribute_var anAttr;
167 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
169 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
170 if (aFather->_is_nil()) {
171 aFather = aStudyBuilder->NewComponent("GEOM");
172 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
173 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
174 aName->SetValue("Geometry");
175 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
176 SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
177 aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
179 if (aFather->_is_nil()) return aResultSO;
181 if (CORBA::is_nil(theSObject)) {
182 aResultSO = aStudyBuilder->NewObject(aFather);
184 if (!theSObject->ReferencedObject(aResultSO))
185 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
186 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
188 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
189 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
190 //char *aGeomObjIOR = _orb->object_to_string(theObject);
191 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
192 //anIOR->SetValue(CORBA::string_dup(aGeomObjIOR));
193 anIOR->SetValue(aGeomObjIOR);
195 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
196 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
197 TCollection_AsciiString aShapeName("Shape_");
199 if ( aShape->GetType() == GEOM_GROUP ) {
200 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
201 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
203 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
204 aShapeName = "Group_Of_Vertices_";
207 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
208 aShapeName = "Group_Of_Edges_";
211 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
212 aShapeName = "Group_Of_Faces_";
215 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
216 aShapeName = "Group_Of_Solids_";
219 } else if ( aShape->GetType() == GEOM_MARKER ) {
220 aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
221 aShapeName = "LocalCS_";
222 } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
223 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
224 aShapeName = "Compound_";
225 } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
226 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
227 aShapeName = "Compsolid_";
228 } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
229 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
230 aShapeName = "Solid_";
231 } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
232 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
233 aShapeName = "Shell_";
234 } else if ( aShape->GetShapeType() == GEOM::FACE ) {
235 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
236 aShapeName = "Face_";
237 } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
238 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
239 aShapeName = "Wire_";
240 } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
241 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
242 aShapeName = "Edge_";
243 } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
244 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
245 aShapeName = "Vertex_";
247 //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
248 //else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName));
250 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
251 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
252 // of objects in the study, but compute a number of objects with the same prefix
253 // and build a new name as Prefix_N+1
254 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
255 int i = 0; // (WITH EMPTY NEW NAME)
256 SALOMEDS::SObject_var obj;
257 TCollection_AsciiString aNewShapeName;
259 aNewShapeName = aShapeName + TCollection_AsciiString(++i);
260 obj = theStudy->FindObject( aNewShapeName.ToCString() );
262 while ( !obj->_is_nil() );
263 aShapeName = aNewShapeName;
265 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
266 aShapeName = TCollection_AsciiString((char*)theName);
268 //Set the study entry as a name of the published GEOM_Object
269 aShape->SetStudyEntry(aResultSO->GetID());
271 //Set a name of the added shape
272 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
273 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
274 aNameAttrib->SetValue(aShapeName.ToCString());
276 return aResultSO._retn();
280 //============================================================================
282 // purpose : save OCAF/Geom document
283 //============================================================================
284 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
287 SALOMEDS::TMPFile_var aStreamFile;
288 // Get a temporary directory to store a file
289 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
291 // OCCT BUG: cannot save a document (in current folder)
292 // if directory name is empty
293 if (aTmpDir.size() == 0) {
301 // Create a list to store names of created files
302 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
304 // Prepare a file name to open
305 TCollection_AsciiString aNameWithExt("");
307 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
308 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
309 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
310 // Build a full file name of temporary file
311 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
312 // Save GEOM component in this file
313 _impl->Save(theComponent->GetStudy()->StudyId(), aFullName.ToCString());
314 // Conver a file to the byte stream
315 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
316 // Remove the created file and tmp directory
317 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
319 // Return the created byte stream
320 return aStreamFile._retn();
324 //============================================================================
325 // function : SaveASCII()
327 //============================================================================
328 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
331 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
332 return aStreamFile._retn();
336 //============================================================================
339 //============================================================================
340 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
341 const SALOMEDS::TMPFile& theStream,
345 if (theStream.length() <= 9) {
346 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
350 // Get a temporary directory for a file
351 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
353 // OCCT BUG: cannot load a document (from current folder)
354 // if directory name is empty
355 if (aTmpDir.size() == 0) {
363 // Conver the byte stream theStream to a file and place it in tmp directory
364 SALOMEDS::ListOfFileNames_var aSeq =
365 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
367 // Prepare a file name to open
368 TCollection_AsciiString aNameWithExt("");
370 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
371 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
372 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
375 if (!_impl->Load(theComponent->GetStudy()->StudyId(), aFullName.ToCString())) return false;
377 // Remove the created file and tmp directory
378 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
380 SALOMEDS::Study_var Study = theComponent->GetStudy();
381 TCollection_AsciiString name (Study->Name());
387 //============================================================================
388 // function : LoadASCII()
390 //============================================================================
391 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
392 const SALOMEDS::TMPFile& theStream,
395 return Load(theComponent, theStream, theURL, isMultiFile);
399 //============================================================================
400 // function : Close()
402 //============================================================================
403 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
405 _impl->Close(theComponent->GetStudy()->StudyId());
408 //============================================================================
409 // function : CanCopy()
411 //============================================================================
412 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
413 // Try to retrieve known by Geometry component GEOM_Object by given IOR
414 SALOMEDS::GenericAttribute_var anAttr;
415 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
417 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
419 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
420 // If the object is null one it can't be copied: return false
421 if (anObject->_is_nil()) return false;
425 //============================================================================
426 // function : CopyFrom()
428 //============================================================================
429 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
430 // Declare a sequence of the byte to store the copied object
431 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
433 // Try to get GEOM_Object object by given SObject
434 SALOMEDS::GenericAttribute_var anAttr;
435 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
436 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
437 if (anObject->_is_nil()) return aStreamFile._retn();
439 aStreamFile = anObject->GetShapeStream();
441 // Assign an ID the type of GEOM_Object
442 theObjectID = anObject->GetType();
444 // Return created TMPFile
445 return aStreamFile._retn();
448 //============================================================================
449 // function : CanPaste()
451 //============================================================================
452 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
453 // The Geometry component can paste only objects copied by Geometry component
454 // and with the object type = 1
455 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
459 //============================================================================
460 // function : PasteInto()
462 //============================================================================
463 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
464 CORBA::Long theObjectID,
465 SALOMEDS::SObject_ptr theObject) {
466 // Find the current Study and StudyBuilder
467 SALOMEDS::Study_var aStudy = theObject->GetStudy();
468 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
470 // Retrieve a TopoDS_Shape from byte stream
471 TopoDS_Shape aTopology;
472 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
473 BRep_Builder aBuilder;
475 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
476 } catch (Standard_Failure) {
480 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
481 SALOMEDS::SObject_var aNewSO;
482 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
483 aNewSO = aStudyBuilder->NewObject(theObject);
484 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
487 //Create a new GEOM_Object
488 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
489 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
490 aFunction->SetValue(aTopology);
492 TCollection_AsciiString anEntry;
493 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
494 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
496 //Set the study entry of the published GEOM_Object
497 obj->SetStudyEntry(aNewSO->GetID());
499 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
500 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
501 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
502 anIOR->SetValue(_orb->object_to_string(obj));
504 // Return the created in the Study SObject
505 return aNewSO._retn();
508 //============================================================================
509 // function : ComponentDataType()
511 //============================================================================
512 char* GEOM_Gen_i::ComponentDataType()
514 return CORBA::string_dup("GEOM");
517 //============================================================================
518 // function : AddInStudy
520 //============================================================================
521 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM::GEOM_Object_ptr theObject, const char* theName, GEOM::GEOM_Object_ptr theFather)
523 SALOMEDS::SObject_var aResultSO;
524 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
526 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
529 if(!theFather->_is_nil()) {
530 IOR = _orb->object_to_string(theFather);
531 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR);
532 if(aFatherSO->_is_nil()) return aResultSO._retn();
533 aResultSO = aStudyBuilder->NewObject(aFatherSO);
534 //aStudyBuilder->Addreference(aResultSO, aResultSO);
537 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
538 if(aResultSO->_is_nil()) return aResultSO._retn();
540 GEOM::ListOfGO_var aList = theObject->GetDependency();
541 Standard_Integer aLength = aList->length();
542 if(aLength < 1) return aResultSO._retn();
544 //Publish the arguments
545 for(Standard_Integer i = 0; i< aLength; i++) {
546 GEOM::GEOM_Object_var anObject = aList[i];
547 if(anObject->_is_nil()) continue;
548 IOR = _orb->object_to_string(anObject);
549 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR);
550 if(aSO->_is_nil()) continue;
551 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
552 aStudyBuilder->Addreference(aSubSO, aSO);
555 return aResultSO._retn();
558 //============================================================================
559 // function : register()
560 // purpose : register 'name' in 'name_service'
561 //============================================================================
562 void GEOM_Gen_i::register_name(char * name)
564 GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(_this());
565 name_service->Register(g, CORBA::string_dup(name));
568 //============================================================================
571 //============================================================================
572 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
574 _impl->Undo(theStudyID);
577 //============================================================================
580 //============================================================================
581 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
583 _impl->Redo(theStudyID);
586 //============================================================================
587 // function : GetIBasicOperations
589 //============================================================================
590 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
591 throw ( SALOME::SALOME_Exception )
593 Unexpect aCatch(SALOME_SalomeException);
594 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
596 GEOM::GEOM_Gen_ptr engine = _this();
598 GEOM_IBasicOperations_i* aServant =
599 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
601 // activate the CORBA servant
602 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
603 return operations._retn();
606 //============================================================================
607 // function : GetITransformOperations
609 //============================================================================
610 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
611 throw ( SALOME::SALOME_Exception )
613 Unexpect aCatch(SALOME_SalomeException);
614 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
616 GEOM::GEOM_Gen_ptr engine = _this();
618 GEOM_ITransformOperations_i* aServant =
619 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
621 // activate the CORBA servant
622 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
623 return operations._retn();
626 //============================================================================
627 // function : GetI3DPrimOperations
629 //============================================================================
630 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
631 throw ( SALOME::SALOME_Exception )
633 Unexpect aCatch(SALOME_SalomeException);
634 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
636 GEOM::GEOM_Gen_ptr engine = _this();
638 GEOM_I3DPrimOperations_i* aServant =
639 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
641 // activate the CORBA servant
642 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
643 return operations._retn();
646 //============================================================================
647 // function : GetIShapesOperations
649 //============================================================================
650 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
651 throw ( SALOME::SALOME_Exception )
653 Unexpect aCatch(SALOME_SalomeException);
654 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
656 GEOM::GEOM_Gen_ptr engine = _this();
658 GEOM_IShapesOperations_i* aServant =
659 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
661 // activate the CORBA servant
662 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
663 return operations._retn();
666 //============================================================================
667 // function : GetIBlocksOperations
669 //============================================================================
670 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
671 throw ( SALOME::SALOME_Exception )
673 Unexpect aCatch(SALOME_SalomeException);
674 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
676 GEOM::GEOM_Gen_ptr engine = _this();
678 GEOM_IBlocksOperations_i* aServant =
679 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
681 // activate the CORBA servant
682 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
683 return operations._retn();
686 //============================================================================
687 // function : GetIBooleanOperations
689 //============================================================================
690 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
691 throw ( SALOME::SALOME_Exception )
693 Unexpect aCatch(SALOME_SalomeException);
694 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
696 GEOM::GEOM_Gen_ptr engine = _this();
698 GEOM_IBooleanOperations_i* aServant =
699 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
701 // activate the CORBA servant
702 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
703 return operations._retn();
706 //============================================================================
707 // function : GetICurvesOperations
709 //============================================================================
710 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
711 throw ( SALOME::SALOME_Exception )
713 Unexpect aCatch(SALOME_SalomeException);
714 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
716 GEOM::GEOM_Gen_ptr engine = _this();
718 GEOM_ICurvesOperations_i* aServant =
719 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
721 // activate the CORBA servant
722 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
723 return operations._retn();
726 //============================================================================
727 // function : GetILocalOperations
729 //============================================================================
730 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
731 throw ( SALOME::SALOME_Exception )
733 Unexpect aCatch(SALOME_SalomeException);
734 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
736 GEOM::GEOM_Gen_ptr engine = _this();
738 GEOM_ILocalOperations_i* aServant =
739 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
741 // activate the CORBA servant
742 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
743 return operations._retn();
746 //============================================================================
747 // function : GetIHealingOperations
749 //============================================================================
750 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
751 throw ( SALOME::SALOME_Exception )
753 Unexpect aCatch(SALOME_SalomeException);
754 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
756 GEOM::GEOM_Gen_ptr engine = _this();
758 GEOM_IHealingOperations_i* aServant =
759 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
761 // activate the CORBA servant
762 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
763 return operations._retn();
766 //============================================================================
767 // function : GetIInsertOperations
769 //============================================================================
770 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
771 throw ( SALOME::SALOME_Exception )
773 Unexpect aCatch(SALOME_SalomeException);
774 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
776 GEOM::GEOM_Gen_ptr engine = _this();
778 GEOM_IInsertOperations_i* aServant =
779 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
781 // activate the CORBA servant
782 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
783 return operations._retn();
786 //============================================================================
787 // function : GetIMeasureOperations
789 //============================================================================
790 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
791 throw ( SALOME::SALOME_Exception )
793 Unexpect aCatch(SALOME_SalomeException);
794 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
796 GEOM::GEOM_Gen_ptr engine = _this();
798 GEOM_IMeasureOperations_i* aServant =
799 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
801 // activate the CORBA servant
802 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
803 return operations._retn();
806 //============================================================================
807 // function : GetIGroupOperations
809 //============================================================================
810 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
811 throw ( SALOME::SALOME_Exception )
813 Unexpect aCatch(SALOME_SalomeException);
814 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
816 GEOM::GEOM_Gen_ptr engine = _this();
818 GEOM_IGroupOperations_i* aServant =
819 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
821 // activate the CORBA servant
822 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
823 return operations._retn();
826 //=============================================================================
830 //=============================================================================
831 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
832 const GEOM::ListOfLong& theIndices)
834 if(theMainShape == NULL || theIndices.length() < 1) return GEOM::GEOM_Object::_nil();
835 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
836 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
838 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
839 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
841 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
842 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
844 TCollection_AsciiString anEntry;
845 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
846 return GetObject(anObject->GetDocID(), anEntry.ToCString());
849 //=============================================================================
853 //=============================================================================
854 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
856 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
857 if (anObject.IsNull()) return;
858 _impl->RemoveObject(anObject);
863 //=================================================================================
864 // function : GetStringFromIOR()
865 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
866 //=================================================================================
867 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
868 return _orb->object_to_string(theObject);
872 //=================================================================================
873 // function : GetIORFromString()
874 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
875 //=================================================================================
876 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
877 GEOM::GEOM_Object_var aGeomObject;
878 if(strcmp(stringIOR,"") != 0){
879 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
880 if(!CORBA::is_nil(anObject))
881 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
883 return aGeomObject._retn();
886 //=================================================================================
887 // function : GetObject()
889 //=================================================================================
890 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
892 GEOM::GEOM_Object_var obj;
893 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
894 if (handle_object.IsNull()) return NULL;
896 TCollection_AsciiString stringIOR = handle_object->GetIOR();
897 if (stringIOR.Length() > 1) {
898 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
899 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
903 GEOM::GEOM_Gen_ptr engine = _this();
904 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
906 obj = servant->_this();
907 stringIOR = _orb->object_to_string(obj);
908 handle_object->SetIOR(stringIOR);
913 //=====================================================================================
915 //=====================================================================================
919 __declspec( dllexport )
921 PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
922 PortableServer::POA_ptr poa,
923 PortableServer::ObjectId * contId,
924 const char *instanceName,
925 const char * interfaceName)
927 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
928 myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
929 return myGEOM_Gen_i->getId();