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 OSD::SetSignal( true );
76 //============================================================================
77 // function : ~GEOM_Gen_i()
78 // purpose : destructor
79 //============================================================================
80 GEOM_Gen_i::~GEOM_Gen_i() {
86 //============================================================================
87 // function : IORToLocalPersistentID()
89 //============================================================================
90 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
91 const char* IORString,
92 CORBA::Boolean isMultiFile,
93 CORBA::Boolean isASCII)
95 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
96 if (!CORBA::is_nil(anObject)) {
97 return strdup(anObject->GetEntry());
103 //============================================================================
104 // function : LocalPersistentIDToIOR()
105 // purpose : Create/Load CORBA object from a persistent ref (an entry)
106 // : Used when a study is loaded
107 // : The IOR (IORName) of object created is returned
108 //============================================================================
109 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
110 const char* aLocalPersistentID,
111 CORBA::Boolean isMultiFile,
112 CORBA::Boolean isASCII)
114 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
116 Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
117 TCollection_AsciiString anEntry;
118 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
119 GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
121 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
122 return strdup(aPersRefString);
125 //============================================================================
126 // function : CanPublishInStudy
128 //============================================================================
129 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
131 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
132 return !(anObject->_is_nil());
136 //============================================================================
137 // function : PublishInStudy
139 //============================================================================
140 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
141 SALOMEDS::SObject_ptr theSObject,
142 CORBA::Object_ptr theObject,
143 const char* theName) throw (SALOME::SALOME_Exception)
145 Unexpect aCatch(SALOME_SalomeException);
146 SALOMEDS::SObject_var aResultSO;
147 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
149 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
150 if(aShape->_is_nil()) return aResultSO;
152 SALOMEDS::GenericAttribute_var anAttr;
153 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
155 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
156 if (aFather->_is_nil()) {
157 aFather = aStudyBuilder->NewComponent("GEOM");
158 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
159 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
160 aName->SetValue("Geometry");
161 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
162 SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
163 aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
165 if (aFather->_is_nil()) return aResultSO;
167 if (CORBA::is_nil(theSObject)) {
168 aResultSO = aStudyBuilder->NewObject(aFather);
170 if (!theSObject->ReferencedObject(aResultSO))
171 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
172 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
174 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
175 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
176 char *aGeomObjIOR = _orb->object_to_string(theObject);
177 anIOR->SetValue(strdup(aGeomObjIOR));
179 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
180 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
181 TCollection_AsciiString aShapeName("Shape_");
183 if ( aShape->GetType() == GEOM_GROUP ) {
184 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
185 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
187 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
188 aShapeName = "Group_Of_Vertices_";
191 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
192 aShapeName = "Group_Of_Edges_";
195 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
196 aShapeName = "Group_Of_Faces_";
199 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
200 aShapeName = "Group_Of_Solids_";
203 } else if ( aShape->GetType() == GEOM_MARKER ) {
204 aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
205 aShapeName = "LocalCS_";
206 } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
207 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
208 aShapeName = "Compound_";
209 } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
210 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
211 aShapeName = "Compsolid_";
212 } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
213 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
214 aShapeName = "Solid_";
215 } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
216 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
217 aShapeName = "Shell_";
218 } else if ( aShape->GetShapeType() == GEOM::FACE ) {
219 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
220 aShapeName = "Face_";
221 } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
222 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
223 aShapeName = "Wire_";
224 } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
225 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
226 aShapeName = "Edge_";
227 } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
228 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
229 aShapeName = "Vertex_";
231 //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
232 //else aShapeName = TCollection_AsciiString(strdup(theName));
234 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
235 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
236 // of objects in the study, but compute a number of objects with the same prefix
237 // and build a new name as Prefix_N+1
238 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
239 int i = 0; // (WITH EMPTY NEW NAME)
240 SALOMEDS::SObject_var obj;
241 TCollection_AsciiString aNewShapeName;
243 aNewShapeName = aShapeName + TCollection_AsciiString(++i);
244 obj = theStudy->FindObject( aNewShapeName.ToCString() );
246 while ( !obj->_is_nil() );
247 aShapeName = aNewShapeName;
249 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
250 aShapeName = TCollection_AsciiString(strdup(theName));
252 //Set the study entry as a name of the published GEOM_Object
253 aShape->SetStudyEntry(aResultSO->GetID());
255 //Set a name of the added shape
256 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
257 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
258 aNameAttrib->SetValue(aShapeName.ToCString());
260 return aResultSO._retn();
264 //============================================================================
266 // purpose : save OCAF/Geom document
267 //============================================================================
268 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
271 SALOMEDS::TMPFile_var aStreamFile;
272 // Get a temporary directory to store a file
273 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
274 // Create a list to store names of created files
275 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
277 // Prepare a file name to open
278 TCollection_AsciiString aNameWithExt("");
280 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
281 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
282 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
283 // Build a full file name of temporary file
284 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
285 // Save GEOM component in this file
286 _impl->Save(theComponent->GetStudy()->StudyId(), aFullName.ToCString());
287 // Conver a file to the byte stream
288 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
289 // Remove the created file and tmp directory
290 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
292 // Return the created byte stream
293 return aStreamFile._retn();
297 //============================================================================
298 // function : SaveASCII()
300 //============================================================================
301 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
304 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
305 return aStreamFile._retn();
309 //============================================================================
312 //============================================================================
313 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
314 const SALOMEDS::TMPFile& theStream,
318 if (theStream.length() <= 9) {
319 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
323 // Get a temporary directory for a file
324 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
325 // Conver the byte stream theStream to a file and place it in tmp directory
326 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
328 // Prepare a file name to open
329 TCollection_AsciiString aNameWithExt("");
331 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
332 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
333 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
336 if (!_impl->Load(theComponent->GetStudy()->StudyId(), aFullName.ToCString())) return false;
338 // Remove the created file and tmp directory
339 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
341 SALOMEDS::Study_var Study = theComponent->GetStudy();
342 TCollection_AsciiString name( strdup(Study->Name()) );
348 //============================================================================
349 // function : LoadASCII()
351 //============================================================================
352 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
353 const SALOMEDS::TMPFile& theStream,
356 return Load(theComponent, theStream, theURL, isMultiFile);
360 //============================================================================
361 // function : Close()
363 //============================================================================
364 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
366 _impl->Close(theComponent->GetStudy()->StudyId());
369 //============================================================================
370 // function : CanCopy()
372 //============================================================================
373 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
374 // Try to retrieve known by Geometry component GEOM_Object by given IOR
375 SALOMEDS::GenericAttribute_var anAttr;
376 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
378 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
380 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
381 // If the object is null one it can't be copied: return false
382 if (anObject->_is_nil()) return false;
386 //============================================================================
387 // function : CopyFrom()
389 //============================================================================
390 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
391 // Declare a sequence of the byte to store the copied object
392 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
394 // Try to get GEOM_Object object by given SObject
395 SALOMEDS::GenericAttribute_var anAttr;
396 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
397 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
398 if (anObject->_is_nil()) return aStreamFile._retn();
400 aStreamFile = anObject->GetShapeStream();
402 // Assign an ID the type of GEOM_Object
403 theObjectID = anObject->GetType();
405 // Return created TMPFile
406 return aStreamFile._retn();
409 //============================================================================
410 // function : CanPaste()
412 //============================================================================
413 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
414 // The Geometry component can paste only objects copied by Geometry component
415 // and with the object type = 1
416 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
420 //============================================================================
421 // function : PasteInto()
423 //============================================================================
424 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
425 CORBA::Long theObjectID,
426 SALOMEDS::SObject_ptr theObject) {
427 // Find the current Study and StudyBuilder
428 SALOMEDS::Study_var aStudy = theObject->GetStudy();
429 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
431 // Retrieve a TopoDS_Shape from byte stream
432 TopoDS_Shape aTopology;
433 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
434 BRep_Builder aBuilder;
436 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
437 } catch (Standard_Failure) {
441 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
442 SALOMEDS::SObject_var aNewSO;
443 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
444 aNewSO = aStudyBuilder->NewObject(theObject);
445 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
448 //Create a new GEOM_Object
449 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
450 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
451 aFunction->SetValue(aTopology);
453 TCollection_AsciiString anEntry;
454 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
455 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
457 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
458 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
459 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
460 anIOR->SetValue(_orb->object_to_string(obj));
462 // Return the created in the Study SObject
463 return aNewSO._retn();
466 //============================================================================
467 // function : ComponentDataType()
469 //============================================================================
470 char* GEOM_Gen_i::ComponentDataType()
472 return strdup("GEOM");
475 //============================================================================
476 // function : AddInStudy
478 //============================================================================
479 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM::GEOM_Object_ptr theObject, const char* theName, GEOM::GEOM_Object_ptr theFather)
481 SALOMEDS::SObject_var aResultSO;
482 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
484 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
487 if(!theFather->_is_nil()) {
488 IOR = _orb->object_to_string(theFather);
489 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR);
490 if(aFatherSO->_is_nil()) return aResultSO._retn();
491 aResultSO = aStudyBuilder->NewObject(aFatherSO);
492 //aStudyBuilder->Addreference(aResultSO, aResultSO);
495 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
496 if(aResultSO->_is_nil()) return aResultSO._retn();
498 GEOM::ListOfGO_var aList = theObject->GetDependency();
499 Standard_Integer aLength = aList->length();
500 if(aLength < 1) return aResultSO._retn();
502 //Publish the arguments
503 for(Standard_Integer i = 0; i< aLength; i++) {
504 GEOM::GEOM_Object_var anObject = aList[i];
505 if(anObject->_is_nil()) continue;
506 IOR = _orb->object_to_string(anObject);
507 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR);
508 if(aSO->_is_nil()) continue;
509 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
510 aStudyBuilder->Addreference(aSubSO, aSO);
513 return aResultSO._retn();
516 //============================================================================
517 // function : register()
518 // purpose : register 'name' in 'name_service'
519 //============================================================================
520 void GEOM_Gen_i::register_name(char * name)
522 GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(_this());
523 name_service->Register(g, strdup(name));
526 //============================================================================
529 //============================================================================
530 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
532 _impl->Undo(theStudyID);
535 //============================================================================
538 //============================================================================
539 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
541 _impl->Redo(theStudyID);
544 //============================================================================
545 // function : GetIBasicOperations
547 //============================================================================
548 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
549 throw ( SALOME::SALOME_Exception )
551 Unexpect aCatch(SALOME_SalomeException);
552 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
554 GEOM::GEOM_Gen_ptr engine = _this();
556 GEOM_IBasicOperations_i* aServant =
557 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
559 // activate the CORBA servant
560 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
561 return operations._retn();
564 //============================================================================
565 // function : GetITransformOperations
567 //============================================================================
568 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
569 throw ( SALOME::SALOME_Exception )
571 Unexpect aCatch(SALOME_SalomeException);
572 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
574 GEOM::GEOM_Gen_ptr engine = _this();
576 GEOM_ITransformOperations_i* aServant =
577 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
579 // activate the CORBA servant
580 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
581 return operations._retn();
584 //============================================================================
585 // function : GetI3DPrimOperations
587 //============================================================================
588 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
589 throw ( SALOME::SALOME_Exception )
591 Unexpect aCatch(SALOME_SalomeException);
592 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
594 GEOM::GEOM_Gen_ptr engine = _this();
596 GEOM_I3DPrimOperations_i* aServant =
597 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
599 // activate the CORBA servant
600 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
601 return operations._retn();
604 //============================================================================
605 // function : GetIShapesOperations
607 //============================================================================
608 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
609 throw ( SALOME::SALOME_Exception )
611 Unexpect aCatch(SALOME_SalomeException);
612 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
614 GEOM::GEOM_Gen_ptr engine = _this();
616 GEOM_IShapesOperations_i* aServant =
617 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
619 // activate the CORBA servant
620 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
621 return operations._retn();
624 //============================================================================
625 // function : GetIBlocksOperations
627 //============================================================================
628 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
629 throw ( SALOME::SALOME_Exception )
631 Unexpect aCatch(SALOME_SalomeException);
632 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
634 GEOM::GEOM_Gen_ptr engine = _this();
636 GEOM_IBlocksOperations_i* aServant =
637 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
639 // activate the CORBA servant
640 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
641 return operations._retn();
644 //============================================================================
645 // function : GetIBooleanOperations
647 //============================================================================
648 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
649 throw ( SALOME::SALOME_Exception )
651 Unexpect aCatch(SALOME_SalomeException);
652 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
654 GEOM::GEOM_Gen_ptr engine = _this();
656 GEOM_IBooleanOperations_i* aServant =
657 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
659 // activate the CORBA servant
660 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
661 return operations._retn();
664 //============================================================================
665 // function : GetICurvesOperations
667 //============================================================================
668 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
669 throw ( SALOME::SALOME_Exception )
671 Unexpect aCatch(SALOME_SalomeException);
672 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
674 GEOM::GEOM_Gen_ptr engine = _this();
676 GEOM_ICurvesOperations_i* aServant =
677 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
679 // activate the CORBA servant
680 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
681 return operations._retn();
684 //============================================================================
685 // function : GetILocalOperations
687 //============================================================================
688 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
689 throw ( SALOME::SALOME_Exception )
691 Unexpect aCatch(SALOME_SalomeException);
692 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
694 GEOM::GEOM_Gen_ptr engine = _this();
696 GEOM_ILocalOperations_i* aServant =
697 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
699 // activate the CORBA servant
700 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
701 return operations._retn();
704 //============================================================================
705 // function : GetIHealingOperations
707 //============================================================================
708 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
709 throw ( SALOME::SALOME_Exception )
711 Unexpect aCatch(SALOME_SalomeException);
712 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
714 GEOM::GEOM_Gen_ptr engine = _this();
716 GEOM_IHealingOperations_i* aServant =
717 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
719 // activate the CORBA servant
720 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
721 return operations._retn();
724 //============================================================================
725 // function : GetIInsertOperations
727 //============================================================================
728 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
729 throw ( SALOME::SALOME_Exception )
731 Unexpect aCatch(SALOME_SalomeException);
732 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
734 GEOM::GEOM_Gen_ptr engine = _this();
736 GEOM_IInsertOperations_i* aServant =
737 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
739 // activate the CORBA servant
740 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
741 return operations._retn();
744 //============================================================================
745 // function : GetIMeasureOperations
747 //============================================================================
748 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
749 throw ( SALOME::SALOME_Exception )
751 Unexpect aCatch(SALOME_SalomeException);
752 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
754 GEOM::GEOM_Gen_ptr engine = _this();
756 GEOM_IMeasureOperations_i* aServant =
757 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
759 // activate the CORBA servant
760 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
761 return operations._retn();
764 //============================================================================
765 // function : GetIGroupOperations
767 //============================================================================
768 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
769 throw ( SALOME::SALOME_Exception )
771 Unexpect aCatch(SALOME_SalomeException);
772 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
774 GEOM::GEOM_Gen_ptr engine = _this();
776 GEOM_IGroupOperations_i* aServant =
777 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
779 // activate the CORBA servant
780 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
781 return operations._retn();
784 //=============================================================================
788 //=============================================================================
789 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
790 const GEOM::ListOfLong& theIndices)
792 if(theMainShape == NULL || theIndices.length() < 1) return GEOM::GEOM_Object::_nil();
793 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
794 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
796 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
797 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
799 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
800 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
802 TCollection_AsciiString anEntry;
803 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
804 return GetObject(anObject->GetDocID(), anEntry.ToCString());
807 //=============================================================================
811 //=============================================================================
812 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
814 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
815 if (anObject.IsNull()) return;
816 _impl->RemoveObject(anObject);
821 //=================================================================================
822 // function : GetStringFromIOR()
823 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
824 //=================================================================================
825 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
826 return _orb->object_to_string(theObject);
830 //=================================================================================
831 // function : GetIORFromString()
832 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
833 //=================================================================================
834 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
835 GEOM::GEOM_Object_var aGeomObject;
836 if(strcmp(stringIOR,"") != 0){
837 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
838 if(!CORBA::is_nil(anObject))
839 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
841 return aGeomObject._retn();
844 //=================================================================================
845 // function : GetObject()
847 //=================================================================================
848 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
850 GEOM::GEOM_Object_var obj;
851 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
852 if (handle_object.IsNull()) return NULL;
854 TCollection_AsciiString stringIOR = handle_object->GetIOR();
855 if (stringIOR.Length() > 1) {
856 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
857 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
861 GEOM::GEOM_Gen_ptr engine = _this();
862 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
864 obj = servant->_this();
865 stringIOR = _orb->object_to_string(obj);
866 handle_object->SetIOR(stringIOR);
871 //=====================================================================================
873 //=====================================================================================
877 __declspec( dllexport )
879 PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
880 PortableServer::POA_ptr poa,
881 PortableServer::ObjectId * contId,
882 const char *instanceName,
883 const char * interfaceName)
885 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
886 myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
887 return myGEOM_Gen_i->getId();