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 //work around PAL12004, PAL12628
72 //OSD::SetSignal( true );
76 char* envDisableFPE = getenv("DISABLE_FPE");
77 if (envDisableFPE && atoi(envDisableFPE))
82 OSD::SetSignal( raiseFPE );
85 //============================================================================
86 // function : ~GEOM_Gen_i()
87 // purpose : destructor
88 //============================================================================
89 GEOM_Gen_i::~GEOM_Gen_i() {
95 //============================================================================
96 // function : IORToLocalPersistentID()
98 //============================================================================
99 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
100 const char* IORString,
101 CORBA::Boolean isMultiFile,
102 CORBA::Boolean isASCII)
104 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
105 if (!CORBA::is_nil(anObject)) {
106 return strdup(anObject->GetEntry());
112 //============================================================================
113 // function : LocalPersistentIDToIOR()
114 // purpose : Create/Load CORBA object from a persistent ref (an entry)
115 // : Used when a study is loaded
116 // : The IOR (IORName) of object created is returned
117 //============================================================================
118 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
119 const char* aLocalPersistentID,
120 CORBA::Boolean isMultiFile,
121 CORBA::Boolean isASCII)
123 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
125 Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
126 TCollection_AsciiString anEntry;
127 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
128 GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
130 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
131 return strdup(aPersRefString);
134 //============================================================================
135 // function : CanPublishInStudy
137 //============================================================================
138 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
140 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
141 return !(anObject->_is_nil());
145 //============================================================================
146 // function : PublishInStudy
148 //============================================================================
149 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
150 SALOMEDS::SObject_ptr theSObject,
151 CORBA::Object_ptr theObject,
152 const char* theName) throw (SALOME::SALOME_Exception)
154 Unexpect aCatch(SALOME_SalomeException);
155 SALOMEDS::SObject_var aResultSO;
156 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
158 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
159 if(aShape->_is_nil()) return aResultSO;
161 SALOMEDS::GenericAttribute_var anAttr;
162 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
164 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
165 if (aFather->_is_nil()) {
166 aFather = aStudyBuilder->NewComponent("GEOM");
167 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
168 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
169 aName->SetValue("Geometry");
170 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
171 SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
172 aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
174 if (aFather->_is_nil()) return aResultSO;
176 if (CORBA::is_nil(theSObject)) {
177 aResultSO = aStudyBuilder->NewObject(aFather);
179 if (!theSObject->ReferencedObject(aResultSO))
180 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
181 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
183 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
184 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
185 char *aGeomObjIOR = _orb->object_to_string(theObject);
186 anIOR->SetValue(strdup(aGeomObjIOR));
188 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
189 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
190 TCollection_AsciiString aShapeName("Shape_");
192 if ( aShape->GetType() == GEOM_GROUP ) {
193 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
194 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
196 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
197 aShapeName = "Group_Of_Vertices_";
200 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
201 aShapeName = "Group_Of_Edges_";
204 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
205 aShapeName = "Group_Of_Faces_";
208 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
209 aShapeName = "Group_Of_Solids_";
212 } else if ( aShape->GetType() == GEOM_MARKER ) {
213 aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
214 aShapeName = "LocalCS_";
215 } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
216 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
217 aShapeName = "Compound_";
218 } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
219 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
220 aShapeName = "Compsolid_";
221 } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
222 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
223 aShapeName = "Solid_";
224 } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
225 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
226 aShapeName = "Shell_";
227 } else if ( aShape->GetShapeType() == GEOM::FACE ) {
228 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
229 aShapeName = "Face_";
230 } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
231 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
232 aShapeName = "Wire_";
233 } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
234 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
235 aShapeName = "Edge_";
236 } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
237 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
238 aShapeName = "Vertex_";
240 //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
241 //else aShapeName = TCollection_AsciiString(strdup(theName));
243 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
244 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
245 // of objects in the study, but compute a number of objects with the same prefix
246 // and build a new name as Prefix_N+1
247 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
248 int i = 0; // (WITH EMPTY NEW NAME)
249 SALOMEDS::SObject_var obj;
250 TCollection_AsciiString aNewShapeName;
252 aNewShapeName = aShapeName + TCollection_AsciiString(++i);
253 obj = theStudy->FindObject( aNewShapeName.ToCString() );
255 while ( !obj->_is_nil() );
256 aShapeName = aNewShapeName;
258 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
259 aShapeName = TCollection_AsciiString(strdup(theName));
261 //Set the study entry as a name of the published GEOM_Object
262 aShape->SetStudyEntry(aResultSO->GetID());
264 //Set a name of the added shape
265 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
266 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
267 aNameAttrib->SetValue(aShapeName.ToCString());
269 return aResultSO._retn();
273 //============================================================================
275 // purpose : save OCAF/Geom document
276 //============================================================================
277 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
280 SALOMEDS::TMPFile_var aStreamFile;
281 // Get a temporary directory to store a file
282 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
283 // Create a list to store names of created files
284 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
286 // Prepare a file name to open
287 TCollection_AsciiString aNameWithExt("");
289 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
290 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
291 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
292 // Build a full file name of temporary file
293 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
294 // Save GEOM component in this file
295 _impl->Save(theComponent->GetStudy()->StudyId(), aFullName.ToCString());
296 // Conver a file to the byte stream
297 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
298 // Remove the created file and tmp directory
299 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
301 // Return the created byte stream
302 return aStreamFile._retn();
306 //============================================================================
307 // function : SaveASCII()
309 //============================================================================
310 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
313 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
314 return aStreamFile._retn();
318 //============================================================================
321 //============================================================================
322 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
323 const SALOMEDS::TMPFile& theStream,
327 if (theStream.length() <= 9) {
328 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
332 // Get a temporary directory for a file
333 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
334 // Conver the byte stream theStream to a file and place it in tmp directory
335 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
337 // Prepare a file name to open
338 TCollection_AsciiString aNameWithExt("");
340 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
341 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
342 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
345 if (!_impl->Load(theComponent->GetStudy()->StudyId(), aFullName.ToCString())) return false;
347 // Remove the created file and tmp directory
348 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
350 SALOMEDS::Study_var Study = theComponent->GetStudy();
351 TCollection_AsciiString name( strdup(Study->Name()) );
357 //============================================================================
358 // function : LoadASCII()
360 //============================================================================
361 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
362 const SALOMEDS::TMPFile& theStream,
365 return Load(theComponent, theStream, theURL, isMultiFile);
369 //============================================================================
370 // function : Close()
372 //============================================================================
373 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
375 _impl->Close(theComponent->GetStudy()->StudyId());
378 //============================================================================
379 // function : CanCopy()
381 //============================================================================
382 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
383 // Try to retrieve known by Geometry component GEOM_Object by given IOR
384 SALOMEDS::GenericAttribute_var anAttr;
385 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
387 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
389 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
390 // If the object is null one it can't be copied: return false
391 if (anObject->_is_nil()) return false;
395 //============================================================================
396 // function : CopyFrom()
398 //============================================================================
399 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
400 // Declare a sequence of the byte to store the copied object
401 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
403 // Try to get GEOM_Object object by given SObject
404 SALOMEDS::GenericAttribute_var anAttr;
405 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
406 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
407 if (anObject->_is_nil()) return aStreamFile._retn();
409 aStreamFile = anObject->GetShapeStream();
411 // Assign an ID the type of GEOM_Object
412 theObjectID = anObject->GetType();
414 // Return created TMPFile
415 return aStreamFile._retn();
418 //============================================================================
419 // function : CanPaste()
421 //============================================================================
422 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
423 // The Geometry component can paste only objects copied by Geometry component
424 // and with the object type = 1
425 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
429 //============================================================================
430 // function : PasteInto()
432 //============================================================================
433 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
434 CORBA::Long theObjectID,
435 SALOMEDS::SObject_ptr theObject) {
436 // Find the current Study and StudyBuilder
437 SALOMEDS::Study_var aStudy = theObject->GetStudy();
438 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
440 // Retrieve a TopoDS_Shape from byte stream
441 TopoDS_Shape aTopology;
442 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
443 BRep_Builder aBuilder;
445 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
446 } catch (Standard_Failure) {
450 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
451 SALOMEDS::SObject_var aNewSO;
452 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
453 aNewSO = aStudyBuilder->NewObject(theObject);
454 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
457 //Create a new GEOM_Object
458 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
459 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
460 aFunction->SetValue(aTopology);
462 TCollection_AsciiString anEntry;
463 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
464 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
466 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
467 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
468 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
469 anIOR->SetValue(_orb->object_to_string(obj));
471 // Return the created in the Study SObject
472 return aNewSO._retn();
475 //============================================================================
476 // function : ComponentDataType()
478 //============================================================================
479 char* GEOM_Gen_i::ComponentDataType()
481 return strdup("GEOM");
484 //============================================================================
485 // function : AddInStudy
487 //============================================================================
488 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM::GEOM_Object_ptr theObject, const char* theName, GEOM::GEOM_Object_ptr theFather)
490 SALOMEDS::SObject_var aResultSO;
491 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
493 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
496 if(!theFather->_is_nil()) {
497 IOR = _orb->object_to_string(theFather);
498 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR);
499 if(aFatherSO->_is_nil()) return aResultSO._retn();
500 aResultSO = aStudyBuilder->NewObject(aFatherSO);
501 //aStudyBuilder->Addreference(aResultSO, aResultSO);
504 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
505 if(aResultSO->_is_nil()) return aResultSO._retn();
507 GEOM::ListOfGO_var aList = theObject->GetDependency();
508 Standard_Integer aLength = aList->length();
509 if(aLength < 1) return aResultSO._retn();
511 //Publish the arguments
512 for(Standard_Integer i = 0; i< aLength; i++) {
513 GEOM::GEOM_Object_var anObject = aList[i];
514 if(anObject->_is_nil()) continue;
515 IOR = _orb->object_to_string(anObject);
516 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR);
517 if(aSO->_is_nil()) continue;
518 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
519 aStudyBuilder->Addreference(aSubSO, aSO);
522 return aResultSO._retn();
525 //============================================================================
526 // function : register()
527 // purpose : register 'name' in 'name_service'
528 //============================================================================
529 void GEOM_Gen_i::register_name(char * name)
531 GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(_this());
532 name_service->Register(g, strdup(name));
535 //============================================================================
538 //============================================================================
539 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
541 _impl->Undo(theStudyID);
544 //============================================================================
547 //============================================================================
548 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
550 _impl->Redo(theStudyID);
553 //============================================================================
554 // function : GetIBasicOperations
556 //============================================================================
557 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
558 throw ( SALOME::SALOME_Exception )
560 Unexpect aCatch(SALOME_SalomeException);
561 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
563 GEOM::GEOM_Gen_ptr engine = _this();
565 GEOM_IBasicOperations_i* aServant =
566 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
568 // activate the CORBA servant
569 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
570 return operations._retn();
573 //============================================================================
574 // function : GetITransformOperations
576 //============================================================================
577 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
578 throw ( SALOME::SALOME_Exception )
580 Unexpect aCatch(SALOME_SalomeException);
581 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
583 GEOM::GEOM_Gen_ptr engine = _this();
585 GEOM_ITransformOperations_i* aServant =
586 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
588 // activate the CORBA servant
589 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
590 return operations._retn();
593 //============================================================================
594 // function : GetI3DPrimOperations
596 //============================================================================
597 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
598 throw ( SALOME::SALOME_Exception )
600 Unexpect aCatch(SALOME_SalomeException);
601 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
603 GEOM::GEOM_Gen_ptr engine = _this();
605 GEOM_I3DPrimOperations_i* aServant =
606 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
608 // activate the CORBA servant
609 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
610 return operations._retn();
613 //============================================================================
614 // function : GetIShapesOperations
616 //============================================================================
617 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
618 throw ( SALOME::SALOME_Exception )
620 Unexpect aCatch(SALOME_SalomeException);
621 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
623 GEOM::GEOM_Gen_ptr engine = _this();
625 GEOM_IShapesOperations_i* aServant =
626 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
628 // activate the CORBA servant
629 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
630 return operations._retn();
633 //============================================================================
634 // function : GetIBlocksOperations
636 //============================================================================
637 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
638 throw ( SALOME::SALOME_Exception )
640 Unexpect aCatch(SALOME_SalomeException);
641 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
643 GEOM::GEOM_Gen_ptr engine = _this();
645 GEOM_IBlocksOperations_i* aServant =
646 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
648 // activate the CORBA servant
649 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
650 return operations._retn();
653 //============================================================================
654 // function : GetIBooleanOperations
656 //============================================================================
657 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
658 throw ( SALOME::SALOME_Exception )
660 Unexpect aCatch(SALOME_SalomeException);
661 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
663 GEOM::GEOM_Gen_ptr engine = _this();
665 GEOM_IBooleanOperations_i* aServant =
666 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
668 // activate the CORBA servant
669 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
670 return operations._retn();
673 //============================================================================
674 // function : GetICurvesOperations
676 //============================================================================
677 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
678 throw ( SALOME::SALOME_Exception )
680 Unexpect aCatch(SALOME_SalomeException);
681 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
683 GEOM::GEOM_Gen_ptr engine = _this();
685 GEOM_ICurvesOperations_i* aServant =
686 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
688 // activate the CORBA servant
689 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
690 return operations._retn();
693 //============================================================================
694 // function : GetILocalOperations
696 //============================================================================
697 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
698 throw ( SALOME::SALOME_Exception )
700 Unexpect aCatch(SALOME_SalomeException);
701 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
703 GEOM::GEOM_Gen_ptr engine = _this();
705 GEOM_ILocalOperations_i* aServant =
706 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
708 // activate the CORBA servant
709 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
710 return operations._retn();
713 //============================================================================
714 // function : GetIHealingOperations
716 //============================================================================
717 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
718 throw ( SALOME::SALOME_Exception )
720 Unexpect aCatch(SALOME_SalomeException);
721 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
723 GEOM::GEOM_Gen_ptr engine = _this();
725 GEOM_IHealingOperations_i* aServant =
726 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
728 // activate the CORBA servant
729 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
730 return operations._retn();
733 //============================================================================
734 // function : GetIInsertOperations
736 //============================================================================
737 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
738 throw ( SALOME::SALOME_Exception )
740 Unexpect aCatch(SALOME_SalomeException);
741 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
743 GEOM::GEOM_Gen_ptr engine = _this();
745 GEOM_IInsertOperations_i* aServant =
746 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
748 // activate the CORBA servant
749 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
750 return operations._retn();
753 //============================================================================
754 // function : GetIMeasureOperations
756 //============================================================================
757 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
758 throw ( SALOME::SALOME_Exception )
760 Unexpect aCatch(SALOME_SalomeException);
761 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
763 GEOM::GEOM_Gen_ptr engine = _this();
765 GEOM_IMeasureOperations_i* aServant =
766 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
768 // activate the CORBA servant
769 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
770 return operations._retn();
773 //============================================================================
774 // function : GetIGroupOperations
776 //============================================================================
777 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
778 throw ( SALOME::SALOME_Exception )
780 Unexpect aCatch(SALOME_SalomeException);
781 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
783 GEOM::GEOM_Gen_ptr engine = _this();
785 GEOM_IGroupOperations_i* aServant =
786 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
788 // activate the CORBA servant
789 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
790 return operations._retn();
793 //=============================================================================
797 //=============================================================================
798 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
799 const GEOM::ListOfLong& theIndices)
801 if(theMainShape == NULL || theIndices.length() < 1) return GEOM::GEOM_Object::_nil();
802 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
803 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
805 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
806 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
808 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
809 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
811 TCollection_AsciiString anEntry;
812 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
813 return GetObject(anObject->GetDocID(), anEntry.ToCString());
816 //=============================================================================
820 //=============================================================================
821 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
823 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
824 if (anObject.IsNull()) return;
825 _impl->RemoveObject(anObject);
830 //=================================================================================
831 // function : GetStringFromIOR()
832 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
833 //=================================================================================
834 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
835 return _orb->object_to_string(theObject);
839 //=================================================================================
840 // function : GetIORFromString()
841 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
842 //=================================================================================
843 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
844 GEOM::GEOM_Object_var aGeomObject;
845 if(strcmp(stringIOR,"") != 0){
846 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
847 if(!CORBA::is_nil(anObject))
848 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
850 return aGeomObject._retn();
853 //=================================================================================
854 // function : GetObject()
856 //=================================================================================
857 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
859 GEOM::GEOM_Object_var obj;
860 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
861 if (handle_object.IsNull()) return NULL;
863 TCollection_AsciiString stringIOR = handle_object->GetIOR();
864 if (stringIOR.Length() > 1) {
865 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
866 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
870 GEOM::GEOM_Gen_ptr engine = _this();
871 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
873 obj = servant->_this();
874 stringIOR = _orb->object_to_string(obj);
875 handle_object->SetIOR(stringIOR);
880 //=====================================================================================
882 //=====================================================================================
886 __declspec( dllexport )
888 PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
889 PortableServer::POA_ptr poa,
890 PortableServer::ObjectId * contId,
891 const char *instanceName,
892 const char * interfaceName)
894 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
895 myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
896 return myGEOM_Gen_i->getId();