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/
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>
51 #include "SALOMEDS_Tool.hxx"
53 //============================================================================
54 // function : GEOM_Gen_i()
55 // purpose : constructor to be called for servant creation.
56 //============================================================================
57 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
58 PortableServer::POA_ptr poa,
59 PortableServer::ObjectId * contId,
60 const char *instanceName,
61 const char *interfaceName) :
62 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
65 _id = _poa->activate_object(_thisObj);
66 name_service = new SALOME_NamingService(_orb);
68 _impl = new ::GEOMImpl_Gen;
74 //============================================================================
75 // function : ~GEOM_Gen_i()
76 // purpose : destructor
77 //============================================================================
78 GEOM_Gen_i::~GEOM_Gen_i() {
84 //============================================================================
85 // function : IORToLocalPersistentID()
87 //============================================================================
88 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
89 const char* IORString,
90 CORBA::Boolean isMultiFile,
91 CORBA::Boolean isASCII)
93 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
94 if (!CORBA::is_nil(anObject)) {
95 return strdup(anObject->GetEntry());
101 //============================================================================
102 // function : LocalPersistentIDToIOR()
103 // purpose : Create/Load CORBA object from a persistent ref (an entry)
104 // : Used when a study is loaded
105 // : The IOR (IORName) of object created is returned
106 //============================================================================
107 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
108 const char* aLocalPersistentID,
109 CORBA::Boolean isMultiFile,
110 CORBA::Boolean isASCII)
112 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
114 Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
115 TCollection_AsciiString anEntry;
116 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
117 GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
119 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
120 return strdup(aPersRefString);
123 //============================================================================
124 // function : CanPublishInStudy
126 //============================================================================
127 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
129 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
130 return !(anObject->_is_nil());
134 //============================================================================
135 // function : PublishInStudy
137 //============================================================================
138 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
139 SALOMEDS::SObject_ptr theSObject,
140 CORBA::Object_ptr theObject,
141 const char* theName) throw (SALOME::SALOME_Exception)
143 Unexpect aCatch(SALOME_SalomeException);
144 SALOMEDS::SObject_var aResultSO;
145 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
147 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
148 if(aShape->_is_nil()) return aResultSO;
150 SALOMEDS::GenericAttribute_var anAttr;
151 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
153 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
154 if (aFather->_is_nil()) {
155 aFather = aStudyBuilder->NewComponent("GEOM");
156 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
157 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
158 aName->SetValue("Geometry");
159 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
160 SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
161 aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
163 if (aFather->_is_nil()) return aResultSO;
165 if (CORBA::is_nil(theSObject)) {
166 aResultSO = aStudyBuilder->NewObject(aFather);
168 if (!theSObject->ReferencedObject(aResultSO))
169 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
170 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
172 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
173 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
174 char *aGeomObjIOR = _orb->object_to_string(theObject);
175 anIOR->SetValue(strdup(aGeomObjIOR));
177 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
178 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
179 TCollection_AsciiString aShapeName("Shape_");
181 if ( aShape->GetType() == GEOM_GROUP ) {
182 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
183 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
185 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
186 aShapeName = "Group_Of_Vertices_";
189 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
190 aShapeName = "Group_Of_Edges_";
193 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
194 aShapeName = "Group_Of_Faces_";
197 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
198 aShapeName = "Group_Of_Solids_";
201 } else if ( aShape->GetType() == GEOM_MARKER ) {
202 aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
203 aShapeName = "LocalCS_";
204 } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
205 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
206 aShapeName = "Compound_";
207 } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
208 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
209 aShapeName = "Compsolid_";
210 } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
211 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
212 aShapeName = "Solid_";
213 } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
214 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
215 aShapeName = "Shell_";
216 } else if ( aShape->GetShapeType() == GEOM::FACE ) {
217 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
218 aShapeName = "Face_";
219 } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
220 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
221 aShapeName = "Wire_";
222 } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
223 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
224 aShapeName = "Edge_";
225 } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
226 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
227 aShapeName = "Vertex_";
229 //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
230 //else aShapeName = TCollection_AsciiString(strdup(theName));
232 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
233 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
234 // of objects in the study, but compute a number of objects with the same prefix
235 // and build a new name as Prefix_N+1
236 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
237 int i = 0; // (WITH EMPTY NEW NAME)
238 SALOMEDS::SObject_var obj;
239 TCollection_AsciiString aNewShapeName;
241 aNewShapeName = aShapeName + TCollection_AsciiString(++i);
242 obj = theStudy->FindObject( aNewShapeName.ToCString() );
244 while ( !obj->_is_nil() );
245 aShapeName = aNewShapeName;
247 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
248 aShapeName = TCollection_AsciiString(strdup(theName));
250 //Set the study entry as a name of the published GEOM_Object
251 aShape->SetStudyEntry(aResultSO->GetID());
253 //Set a name of the added shape
254 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
255 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
256 aNameAttrib->SetValue(aShapeName.ToCString());
258 return aResultSO._retn();
262 //============================================================================
264 // purpose : save OCAF/Geom document
265 //============================================================================
266 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
269 SALOMEDS::TMPFile_var aStreamFile;
270 // Get a temporary directory to store a file
271 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
272 // Create a list to store names of created files
273 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
275 // Prepare a file name to open
276 TCollection_AsciiString aNameWithExt("");
278 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
279 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
280 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
281 // Build a full file name of temporary file
282 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
283 // Save GEOM component in this file
284 _impl->Save(theComponent->GetStudy()->StudyId(), aFullName.ToCString());
285 // Conver a file to the byte stream
286 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
287 // Remove the created file and tmp directory
288 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
290 // Return the created byte stream
291 return aStreamFile._retn();
295 //============================================================================
296 // function : SaveASCII()
298 //============================================================================
299 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
302 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
303 return aStreamFile._retn();
307 //============================================================================
310 //============================================================================
311 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
312 const SALOMEDS::TMPFile& theStream,
316 if (theStream.length() <= 9) {
317 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
321 // Get a temporary directory for a file
322 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
323 // Conver the byte stream theStream to a file and place it in tmp directory
324 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
326 // Prepare a file name to open
327 TCollection_AsciiString aNameWithExt("");
329 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
330 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
331 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
334 if (!_impl->Load(theComponent->GetStudy()->StudyId(), aFullName.ToCString())) return false;
336 // Remove the created file and tmp directory
337 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
339 SALOMEDS::Study_var Study = theComponent->GetStudy();
340 TCollection_AsciiString name( strdup(Study->Name()) );
346 //============================================================================
347 // function : LoadASCII()
349 //============================================================================
350 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
351 const SALOMEDS::TMPFile& theStream,
354 return Load(theComponent, theStream, theURL, isMultiFile);
358 //============================================================================
359 // function : Close()
361 //============================================================================
362 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
364 _impl->Close(theComponent->GetStudy()->StudyId());
367 //============================================================================
368 // function : CanCopy()
370 //============================================================================
371 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
372 // Try to retrieve known by Geometry component GEOM_Object by given IOR
373 SALOMEDS::GenericAttribute_var anAttr;
374 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
376 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
378 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
379 // If the object is null one it can't be copied: return false
380 if (anObject->_is_nil()) return false;
384 //============================================================================
385 // function : CopyFrom()
387 //============================================================================
388 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
389 // Declare a sequence of the byte to store the copied object
390 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
392 // Try to get GEOM_Object object by given SObject
393 SALOMEDS::GenericAttribute_var anAttr;
394 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
395 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
396 if (anObject->_is_nil()) return aStreamFile._retn();
398 aStreamFile = anObject->GetShapeStream();
400 // Assign an ID the type of GEOM_Object
401 theObjectID = anObject->GetType();
403 // Return created TMPFile
404 return aStreamFile._retn();
407 //============================================================================
408 // function : CanPaste()
410 //============================================================================
411 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
412 // The Geometry component can paste only objects copied by Geometry component
413 // and with the object type = 1
414 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
418 //============================================================================
419 // function : PasteInto()
421 //============================================================================
422 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
423 CORBA::Long theObjectID,
424 SALOMEDS::SObject_ptr theObject) {
425 // Find the current Study and StudyBuilder
426 SALOMEDS::Study_var aStudy = theObject->GetStudy();
427 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
429 // Retrieve a TopoDS_Shape from byte stream
430 TopoDS_Shape aTopology;
431 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
432 BRep_Builder aBuilder;
434 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
435 } catch (Standard_Failure) {
439 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
440 SALOMEDS::SObject_var aNewSO;
441 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
442 aNewSO = aStudyBuilder->NewObject(theObject);
443 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
446 //Create a new GEOM_Object
447 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
448 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
449 aFunction->SetValue(aTopology);
451 TCollection_AsciiString anEntry;
452 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
453 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
455 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
456 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
457 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
458 anIOR->SetValue(_orb->object_to_string(obj));
460 // Return the created in the Study SObject
461 return aNewSO._retn();
464 //============================================================================
465 // function : ComponentDataType()
467 //============================================================================
468 char* GEOM_Gen_i::ComponentDataType()
470 return strdup("GEOM");
473 //============================================================================
474 // function : AddInStudy
476 //============================================================================
477 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM::GEOM_Object_ptr theObject, const char* theName, GEOM::GEOM_Object_ptr theFather)
479 SALOMEDS::SObject_var aResultSO;
480 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
482 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
485 if(!theFather->_is_nil()) {
486 IOR = _orb->object_to_string(theFather);
487 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR);
488 if(aFatherSO->_is_nil()) return aResultSO._retn();
489 aResultSO = aStudyBuilder->NewObject(aFatherSO);
490 //aStudyBuilder->Addreference(aResultSO, aResultSO);
493 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
494 if(aResultSO->_is_nil()) return aResultSO._retn();
496 GEOM::ListOfGO_var aList = theObject->GetDependency();
497 Standard_Integer aLength = aList->length();
498 if(aLength < 1) return aResultSO._retn();
500 //Publish the arguments
501 for(Standard_Integer i = 0; i< aLength; i++) {
502 GEOM::GEOM_Object_var anObject = aList[i];
503 if(anObject->_is_nil()) continue;
504 IOR = _orb->object_to_string(anObject);
505 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR);
506 if(aSO->_is_nil()) continue;
507 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
508 aStudyBuilder->Addreference(aSubSO, aSO);
511 return aResultSO._retn();
514 //============================================================================
515 // function : register()
516 // purpose : register 'name' in 'name_service'
517 //============================================================================
518 void GEOM_Gen_i::register_name(char * name)
520 GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(_this());
521 name_service->Register(g, strdup(name));
524 //============================================================================
527 //============================================================================
528 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
530 _impl->Undo(theStudyID);
533 //============================================================================
536 //============================================================================
537 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
539 _impl->Redo(theStudyID);
542 //============================================================================
543 // function : GetIBasicOperations
545 //============================================================================
546 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
547 throw ( SALOME::SALOME_Exception )
549 Unexpect aCatch(SALOME_SalomeException);
550 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
552 GEOM::GEOM_Gen_ptr engine = _this();
554 GEOM_IBasicOperations_i* aServant =
555 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
557 // activate the CORBA servant
558 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
559 return operations._retn();
562 //============================================================================
563 // function : GetITransformOperations
565 //============================================================================
566 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
567 throw ( SALOME::SALOME_Exception )
569 Unexpect aCatch(SALOME_SalomeException);
570 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
572 GEOM::GEOM_Gen_ptr engine = _this();
574 GEOM_ITransformOperations_i* aServant =
575 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
577 // activate the CORBA servant
578 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
579 return operations._retn();
582 //============================================================================
583 // function : GetI3DPrimOperations
585 //============================================================================
586 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
587 throw ( SALOME::SALOME_Exception )
589 Unexpect aCatch(SALOME_SalomeException);
590 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
592 GEOM::GEOM_Gen_ptr engine = _this();
594 GEOM_I3DPrimOperations_i* aServant =
595 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
597 // activate the CORBA servant
598 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
599 return operations._retn();
602 //============================================================================
603 // function : GetIShapesOperations
605 //============================================================================
606 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
607 throw ( SALOME::SALOME_Exception )
609 Unexpect aCatch(SALOME_SalomeException);
610 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
612 GEOM::GEOM_Gen_ptr engine = _this();
614 GEOM_IShapesOperations_i* aServant =
615 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
617 // activate the CORBA servant
618 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
619 return operations._retn();
622 //============================================================================
623 // function : GetIBlocksOperations
625 //============================================================================
626 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
627 throw ( SALOME::SALOME_Exception )
629 Unexpect aCatch(SALOME_SalomeException);
630 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
632 GEOM::GEOM_Gen_ptr engine = _this();
634 GEOM_IBlocksOperations_i* aServant =
635 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
637 // activate the CORBA servant
638 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
639 return operations._retn();
642 //============================================================================
643 // function : GetIBooleanOperations
645 //============================================================================
646 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
647 throw ( SALOME::SALOME_Exception )
649 Unexpect aCatch(SALOME_SalomeException);
650 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
652 GEOM::GEOM_Gen_ptr engine = _this();
654 GEOM_IBooleanOperations_i* aServant =
655 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
657 // activate the CORBA servant
658 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
659 return operations._retn();
662 //============================================================================
663 // function : GetICurvesOperations
665 //============================================================================
666 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
667 throw ( SALOME::SALOME_Exception )
669 Unexpect aCatch(SALOME_SalomeException);
670 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
672 GEOM::GEOM_Gen_ptr engine = _this();
674 GEOM_ICurvesOperations_i* aServant =
675 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
677 // activate the CORBA servant
678 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
679 return operations._retn();
682 //============================================================================
683 // function : GetILocalOperations
685 //============================================================================
686 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
687 throw ( SALOME::SALOME_Exception )
689 Unexpect aCatch(SALOME_SalomeException);
690 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
692 GEOM::GEOM_Gen_ptr engine = _this();
694 GEOM_ILocalOperations_i* aServant =
695 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
697 // activate the CORBA servant
698 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
699 return operations._retn();
702 //============================================================================
703 // function : GetIHealingOperations
705 //============================================================================
706 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
707 throw ( SALOME::SALOME_Exception )
709 Unexpect aCatch(SALOME_SalomeException);
710 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
712 GEOM::GEOM_Gen_ptr engine = _this();
714 GEOM_IHealingOperations_i* aServant =
715 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
717 // activate the CORBA servant
718 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
719 return operations._retn();
722 //============================================================================
723 // function : GetIInsertOperations
725 //============================================================================
726 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
727 throw ( SALOME::SALOME_Exception )
729 Unexpect aCatch(SALOME_SalomeException);
730 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
732 GEOM::GEOM_Gen_ptr engine = _this();
734 GEOM_IInsertOperations_i* aServant =
735 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
737 // activate the CORBA servant
738 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
739 return operations._retn();
742 //============================================================================
743 // function : GetIMeasureOperations
745 //============================================================================
746 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
747 throw ( SALOME::SALOME_Exception )
749 Unexpect aCatch(SALOME_SalomeException);
750 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
752 GEOM::GEOM_Gen_ptr engine = _this();
754 GEOM_IMeasureOperations_i* aServant =
755 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
757 // activate the CORBA servant
758 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
759 return operations._retn();
762 //============================================================================
763 // function : GetIGroupOperations
765 //============================================================================
766 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
767 throw ( SALOME::SALOME_Exception )
769 Unexpect aCatch(SALOME_SalomeException);
770 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
772 GEOM::GEOM_Gen_ptr engine = _this();
774 GEOM_IGroupOperations_i* aServant =
775 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
777 // activate the CORBA servant
778 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
779 return operations._retn();
782 //=============================================================================
786 //=============================================================================
787 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
788 const GEOM::ListOfLong& theIndices)
790 if(theMainShape == NULL || theIndices.length() < 1) return GEOM::GEOM_Object::_nil();
791 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
792 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
794 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
795 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
797 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
798 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
800 TCollection_AsciiString anEntry;
801 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
802 return GetObject(anObject->GetDocID(), anEntry.ToCString());
805 //=============================================================================
809 //=============================================================================
810 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
812 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
813 if (anObject.IsNull()) return;
814 _impl->RemoveObject(anObject);
819 //=================================================================================
820 // function : GetStringFromIOR()
821 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
822 //=================================================================================
823 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
824 return _orb->object_to_string(theObject);
828 //=================================================================================
829 // function : GetIORFromString()
830 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
831 //=================================================================================
832 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
833 GEOM::GEOM_Object_var aGeomObject;
834 if(strcmp(stringIOR,"") != 0){
835 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
836 if(!CORBA::is_nil(anObject))
837 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
839 return aGeomObject._retn();
842 //=================================================================================
843 // function : GetObject()
845 //=================================================================================
846 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
848 GEOM::GEOM_Object_var obj;
849 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
850 if (handle_object.IsNull()) return NULL;
852 TCollection_AsciiString stringIOR = handle_object->GetIOR();
853 if (stringIOR.Length() > 1) {
854 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
855 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
859 GEOM::GEOM_Gen_ptr engine = _this();
860 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
862 obj = servant->_this();
863 stringIOR = _orb->object_to_string(obj);
864 handle_object->SetIOR(stringIOR);
869 //=====================================================================================
871 //=====================================================================================
875 __declspec( dllexport )
877 PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
878 PortableServer::POA_ptr poa,
879 PortableServer::ObjectId * contId,
880 const char *instanceName,
881 const char * interfaceName)
883 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
884 myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
885 return myGEOM_Gen_i->getId();