1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #pragma warning( disable:4786 )
26 #include <Standard_Stream.hxx>
28 #include "GEOM_Gen_i.hh"
29 #include "GEOM_Object_i.hh"
33 #include "Utils_CorbaException.hxx"
35 #include "Utils_ExceptHandlers.hxx"
36 #include "utilities.h"
38 #include "GEOM_Object_i.hh"
39 #include "GEOM_Object.hxx"
40 #include "GEOM_Function.hxx"
41 #include "GEOMImpl_Types.hxx"
42 #include "GEOMImpl_CopyDriver.hxx"
45 #include <BRep_Builder.hxx>
46 #include <BRepTools.hxx>
47 #include <TDF_Label.hxx>
48 #include <TDF_Tool.hxx>
49 #include <TCollection_AsciiString.hxx>
50 #include <TColStd_HArray1OfInteger.hxx>
51 #include <TopAbs_ShapeEnum.hxx>
54 #include "SALOMEDS_Tool.hxx"
56 //============================================================================
57 // function : GEOM_Gen_i()
58 // purpose : constructor to be called for servant creation.
59 //============================================================================
60 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
61 PortableServer::POA_ptr poa,
62 PortableServer::ObjectId * contId,
63 const char *instanceName,
64 const char *interfaceName) :
65 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
68 _id = _poa->activate_object(_thisObj);
69 name_service = new SALOME_NamingService(_orb);
71 _impl = new ::GEOMImpl_Gen;
73 //PAL10867: disable signals catching with "noexcepthandler" option
74 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
75 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
77 //work around PAL12004, PAL12628
78 //OSD::SetSignal( true );
82 char* envDisableFPE = getenv("DISABLE_FPE");
83 if (envDisableFPE && atoi(envDisableFPE))
88 OSD::SetSignal( raiseFPE );
92 //============================================================================
93 // function : ~GEOM_Gen_i()
94 // purpose : destructor
95 //============================================================================
96 GEOM_Gen_i::~GEOM_Gen_i() {
102 //============================================================================
103 // function : IORToLocalPersistentID()
105 //============================================================================
106 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
107 const char* IORString,
108 CORBA::Boolean isMultiFile,
109 CORBA::Boolean isASCII)
111 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
112 if (!CORBA::is_nil(anObject)) {
113 return CORBA::string_dup(anObject->GetEntry());
119 //============================================================================
120 // function : LocalPersistentIDToIOR()
121 // purpose : Create/Load CORBA object from a persistent ref (an entry)
122 // : Used when a study is loaded
123 // : The IOR (IORName) of object created is returned
124 //============================================================================
125 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
126 const char* aLocalPersistentID,
127 CORBA::Boolean isMultiFile,
128 CORBA::Boolean isASCII)
130 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
132 Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
133 TCollection_AsciiString anEntry;
134 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
135 GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
137 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
138 return CORBA::string_dup(aPersRefString);
141 //============================================================================
142 // function : CanPublishInStudy
144 //============================================================================
145 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
147 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
148 return !(anObject->_is_nil());
152 //============================================================================
153 // function : PublishInStudy
155 //============================================================================
156 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
157 SALOMEDS::SObject_ptr theSObject,
158 CORBA::Object_ptr theObject,
159 const char* theName) throw (SALOME::SALOME_Exception)
161 Unexpect aCatch(SALOME_SalomeException);
162 SALOMEDS::SObject_var aResultSO;
163 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
164 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
165 if(aShape->_is_nil()) return aResultSO;
167 SALOMEDS::GenericAttribute_var anAttr;
168 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
170 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
171 if (aFather->_is_nil()) {
172 aFather = aStudyBuilder->NewComponent("GEOM");
173 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
174 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
175 aName->SetValue("Geometry");
176 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
177 SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
178 aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
180 if (aFather->_is_nil()) return aResultSO;
182 if (CORBA::is_nil(theSObject)) {
183 aResultSO = aStudyBuilder->NewObject(aFather);
185 if (!theSObject->ReferencedObject(aResultSO))
186 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
187 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
189 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
190 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
191 //char *aGeomObjIOR = _orb->object_to_string(theObject);
192 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
193 //anIOR->SetValue(CORBA::string_dup(aGeomObjIOR));
194 anIOR->SetValue(aGeomObjIOR);
196 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
197 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
198 TCollection_AsciiString aShapeName("Shape_");
200 if ( aShape->GetType() == GEOM_GROUP ) {
201 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
202 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
204 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
205 aShapeName = "Group_Of_Vertices_";
208 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
209 aShapeName = "Group_Of_Edges_";
212 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
213 aShapeName = "Group_Of_Faces_";
216 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
217 aShapeName = "Group_Of_Solids_";
220 } else if ( aShape->GetType() == GEOM_MARKER ) {
221 aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
222 aShapeName = "LocalCS_";
223 } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
224 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
225 aShapeName = "Compound_";
226 } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
227 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
228 aShapeName = "Compsolid_";
229 } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
230 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
231 aShapeName = "Solid_";
232 } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
233 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
234 aShapeName = "Shell_";
235 } else if ( aShape->GetShapeType() == GEOM::FACE ) {
236 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
237 aShapeName = "Face_";
238 } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
239 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
240 aShapeName = "Wire_";
241 } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
242 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
243 aShapeName = "Edge_";
244 } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
245 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
246 aShapeName = "Vertex_";
248 //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
249 //else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName));
251 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
252 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
253 // of objects in the study, but compute a number of objects with the same prefix
254 // and build a new name as Prefix_N+1
255 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
256 int i = 0; // (WITH EMPTY NEW NAME)
257 SALOMEDS::SObject_var obj;
258 TCollection_AsciiString aNewShapeName;
260 aNewShapeName = aShapeName + TCollection_AsciiString(++i);
261 obj = theStudy->FindObject( aNewShapeName.ToCString() );
263 while ( !obj->_is_nil() );
264 aShapeName = aNewShapeName;
266 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
267 aShapeName = TCollection_AsciiString((char*)theName);
269 //Set the study entry as a name of the published GEOM_Object
270 aShape->SetStudyEntry(aResultSO->GetID());
272 //Set a name of the added shape
273 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
274 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
275 aNameAttrib->SetValue(aShapeName.ToCString());
277 //Set NoteBook variables used in the object creation
278 TCollection_AsciiString aVars;
279 SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aShape->GetParameters());
280 for(int i = 0, n = aSections->length(); i < n; i++) {
281 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
282 for(int j = 0, m = aListOfVars.length(); j < m; j++) {
283 if(theStudy->IsVariable(aListOfVars[j].in()))
284 aVars += TCollection_AsciiString(aListOfVars[j].in());
291 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeString");
292 SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
293 aStringAttrib->SetValue(aVars.ToCString());
295 //Set a name of the GEOM object
296 aShape->SetName(theName);
298 return aResultSO._retn();
302 //============================================================================
304 // purpose : save OCAF/Geom document
305 //============================================================================
306 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
309 SALOMEDS::TMPFile_var aStreamFile;
310 // Get a temporary directory to store a file
311 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
313 // OCCT BUG: cannot save a document (in current folder)
314 // if directory name is empty
315 if (aTmpDir.size() == 0) {
323 // Create a list to store names of created files
324 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
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 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
332 // Build a full file name of temporary file
333 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
334 // Save GEOM component in this file
335 _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
336 // Conver a file to the byte stream
337 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
338 // Remove the created file and tmp directory
339 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
341 // Return the created byte stream
342 return aStreamFile._retn();
346 //============================================================================
347 // function : SaveASCII()
349 //============================================================================
350 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
353 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
354 return aStreamFile._retn();
358 //============================================================================
361 //============================================================================
362 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
363 const SALOMEDS::TMPFile& theStream,
367 if (theStream.length() <= 9) {
368 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
372 // Get a temporary directory for a file
373 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
375 // OCCT BUG: cannot load a document (from current folder)
376 // if directory name is empty
377 if (aTmpDir.size() == 0) {
385 // Conver the byte stream theStream to a file and place it in tmp directory
386 SALOMEDS::ListOfFileNames_var aSeq =
387 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
389 // Prepare a file name to open
390 TCollection_AsciiString aNameWithExt("");
392 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
393 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
394 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
397 if (!_impl->Load(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString())) return false;
399 // Remove the created file and tmp directory
400 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
402 SALOMEDS::Study_var Study = theComponent->GetStudy();
403 TCollection_AsciiString name (Study->Name());
409 //============================================================================
410 // function : LoadASCII()
412 //============================================================================
413 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
414 const SALOMEDS::TMPFile& theStream,
417 return Load(theComponent, theStream, theURL, isMultiFile);
421 //============================================================================
422 // function : Close()
424 //============================================================================
425 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
427 _impl->Close(theComponent->GetStudy()->StudyId());
430 //============================================================================
431 // function : CanCopy()
433 //============================================================================
434 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
435 // Try to retrieve known by Geometry component GEOM_Object by given IOR
436 SALOMEDS::GenericAttribute_var anAttr;
437 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
439 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
441 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
442 // If the object is null one it can't be copied: return false
443 if (anObject->_is_nil()) return false;
447 //============================================================================
448 // function : CopyFrom()
450 //============================================================================
451 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
452 // Declare a sequence of the byte to store the copied object
453 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
455 // Try to get GEOM_Object object by given SObject
456 SALOMEDS::GenericAttribute_var anAttr;
457 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
458 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
459 if (anObject->_is_nil()) return aStreamFile._retn();
461 aStreamFile = anObject->GetShapeStream();
463 // Assign an ID the type of GEOM_Object
464 theObjectID = anObject->GetType();
466 // Return created TMPFile
467 return aStreamFile._retn();
470 //============================================================================
471 // function : CanPaste()
473 //============================================================================
474 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
475 // The Geometry component can paste only objects copied by Geometry component
476 // and with the object type = 1
477 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
481 //============================================================================
482 // function : PasteInto()
484 //============================================================================
485 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
486 CORBA::Long theObjectID,
487 SALOMEDS::SObject_ptr theObject) {
488 // Find the current Study and StudyBuilder
489 SALOMEDS::Study_var aStudy = theObject->GetStudy();
490 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
492 // Retrieve a TopoDS_Shape from byte stream
493 TopoDS_Shape aTopology;
494 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
495 BRep_Builder aBuilder;
497 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
498 } catch (Standard_Failure) {
502 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
503 SALOMEDS::SObject_var aNewSO;
504 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
505 aNewSO = aStudyBuilder->NewObject(theObject);
506 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
509 //Create a new GEOM_Object
510 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
511 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
512 aFunction->SetValue(aTopology);
514 TCollection_AsciiString anEntry;
515 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
516 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
518 //Set the study entry of the published GEOM_Object
519 obj->SetStudyEntry(aNewSO->GetID());
521 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
522 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
523 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
524 CORBA::String_var objStr = _orb->object_to_string(obj);
525 anIOR->SetValue(objStr.in());
527 // Return the created in the Study SObject
528 return aNewSO._retn();
531 //============================================================================
532 // function : ComponentDataType()
534 //============================================================================
535 char* GEOM_Gen_i::ComponentDataType()
537 return CORBA::string_dup("GEOM");
540 //============================================================================
541 // function : AddInStudy
543 //============================================================================
544 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
545 GEOM::GEOM_Object_ptr theObject,
547 GEOM::GEOM_Object_ptr theFather)
549 SALOMEDS::SObject_var aResultSO;
550 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
552 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
553 CORBA::String_var IOR;
555 if(!theFather->_is_nil()) {
556 IOR = _orb->object_to_string(theFather);
557 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in());
558 if(aFatherSO->_is_nil()) return aResultSO._retn();
559 aResultSO = aStudyBuilder->NewObject(aFatherSO);
560 //aStudyBuilder->Addreference(aResultSO, aResultSO);
563 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
564 if(aResultSO->_is_nil()) return aResultSO._retn();
566 GEOM::ListOfGO_var aList = theObject->GetDependency();
567 Standard_Integer aLength = aList->length();
568 if(aLength < 1) return aResultSO._retn();
570 //Publish the arguments
571 for(Standard_Integer i = 0; i< aLength; i++) {
572 GEOM::GEOM_Object_var anObject = aList[i];
573 if(anObject->_is_nil()) continue;
574 IOR = _orb->object_to_string(anObject);
575 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR.in());
576 if(aSO->_is_nil()) continue;
577 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
578 aStudyBuilder->Addreference(aSubSO, aSO);
581 return aResultSO._retn();
584 //============================================================================
585 // function : RestoreSubShapesO
586 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
587 // To be used from python scripts out of geompy.addToStudy (non-default usage)
588 //============================================================================
589 CORBA::Boolean GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
590 GEOM::GEOM_Object_ptr theObject,
591 const GEOM::ListOfGO& theArgs,
592 GEOM::find_shape_method theFindMethod,
593 CORBA::Boolean theInheritFirstArg)
595 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
598 // find SObject in the study
599 CORBA::String_var anIORo = _orb->object_to_string(theObject);
600 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
601 if (CORBA::is_nil(aSO))
604 return RestoreSubShapes(theStudy, theObject, aSO, theArgs, theFindMethod, theInheritFirstArg);
607 //============================================================================
608 // function : RestoreSubShapesSO
609 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
610 // To be used from GUI and from geompy.addToStudy
611 //============================================================================
612 CORBA::Boolean GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
613 SALOMEDS::SObject_ptr theSObject,
614 const GEOM::ListOfGO& theArgs,
615 GEOM::find_shape_method theFindMethod,
616 CORBA::Boolean theInheritFirstArg)
618 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
621 SALOMEDS::GenericAttribute_var anAttr;
622 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
625 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
626 CORBA::String_var anIORso = anAttrIOR->Value();
628 // get Object from SObject
629 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
630 if (CORBA::is_nil(anO))
633 return RestoreSubShapes(theStudy, anO, theSObject, theArgs, theFindMethod, theInheritFirstArg);
636 //============================================================================
637 // function : RestoreSubShapes
638 // purpose : Private method. Works only if both theObject and theSObject
639 // are defined, and does not check, if they correspond to each other.
640 //============================================================================
641 CORBA::Boolean GEOM_Gen_i::RestoreSubShapes (SALOMEDS::Study_ptr theStudy,
642 GEOM::GEOM_Object_ptr theObject,
643 SALOMEDS::SObject_ptr theSObject,
644 const GEOM::ListOfGO& theArgs,
645 GEOM::find_shape_method theFindMethod,
646 CORBA::Boolean theInheritFirstArg)
648 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) || CORBA::is_nil(theSObject))
651 // Arguments to be published
652 GEOM::ListOfGO_var aList;
654 // If theArgs list is empty, we try to publish all arguments,
655 // otherwise publish only passed args
656 Standard_Integer nbArgsActual = -1; // -1 means unknown
657 Standard_Integer aLength = theArgs.length();
659 aList = new GEOM::ListOfGO;
660 aList->length(aLength);
661 for (int i = 0; i < aLength; i++) {
662 aList[i] = theArgs[i];
667 aList = theObject->GetDependency();
668 aLength = aList->length();
669 nbArgsActual = aLength;
675 if (theInheritFirstArg || (nbArgsActual == 1)) {
676 // Do not publish argument's reflection,
677 // but only reconstruct its published sub-shapes
679 GEOM::GEOM_Object_var anArgO = aList[0];
680 CORBA::String_var anIOR = _orb->object_to_string(anArgO);
681 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
683 GEOM::ListOfGO_var aParts =
684 RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, theFindMethod);
686 // set the color of the transformed shape to the color of initial shape
687 theObject->SetColor(aList[0]->GetColor());
689 return (aParts->length() > 0);
692 // Get interface, containing method, which we will use to reconstruct sub-shapes
693 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
694 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
696 // Reconstruct arguments and tree of sub-shapes of the arguments
697 CORBA::String_var anIOR;
698 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
699 for (Standard_Integer i = 0; i < aLength; i++)
701 GEOM::GEOM_Object_var anArgO = aList[i];
702 if (!CORBA::is_nil(anArgO)) {
703 anIOR = _orb->object_to_string(anArgO);
704 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
705 TCollection_AsciiString anArgName;
706 if (CORBA::is_nil(anArgSO)) {
708 anArgName += TCollection_AsciiString(i);
711 anArgName = anArgSO->GetName();
714 // Find a sub-shape of theObject in place of the argument
715 GEOM::GEOM_Object_var aSubO;
716 switch (theFindMethod) {
717 case GEOM::FSM_GetInPlace:
720 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
723 case GEOM::FSM_Transformed:
725 // transformation, cannot use GetInPlace, operate with indices
726 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
727 if (anIDs->length() > 1) {
729 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
730 if (!CORBA::is_nil(aSubO))
731 aGroupOp->UnionIDs(aSubO, anIDs);
735 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
739 case GEOM::FSM_GetSame:
742 aSubO = aShapesOp->GetSame(theObject, anArgO);
745 case GEOM::FSM_GetShapesOnShape:
747 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
748 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
749 (short)GEOM::SOLID, GEOM::ST_ONIN);
752 case GEOM::FSM_GetInPlaceByHistory:
754 // Use GetInPlaceByHistory
755 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
762 if (!CORBA::is_nil(aSubO)) {
763 // Publish the sub-shape
764 TCollection_AsciiString aSubName ("from_");
765 aSubName += anArgName;
766 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(theSObject);
767 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
769 aSubO->SetColor(anArgO->GetColor());
771 if (!CORBA::is_nil(anArgSO)) {
772 // Restore published sub-shapes of the argument
773 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
774 // pass theObject, because only it has the history
775 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
777 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, aSubO, theFindMethod);
780 else { // GetInPlace failed, try to build from published parts
781 if (!CORBA::is_nil(anArgSO)) {
782 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(theSObject);
784 // Restore published sub-shapes of the argument
785 GEOM::ListOfGO_var aParts =
786 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
788 if (aParts->length() > 0) {
789 // try to build an argument from a set of its sub-shapes,
790 // that published and will be reconstructed
791 if (aParts->length() > 1) {
792 aSubO = aShapesOp->MakeCompound(aParts);
797 if (!CORBA::is_nil(aSubO)) {
798 // Publish the sub-shape
799 TCollection_AsciiString aSubName ("from_parts_of_");
800 aSubName += anArgName;
801 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
803 aSubO->SetColor(anArgO->GetColor());
807 // remove created aSubSO, because no parts have been found
808 aStudyBuilder->RemoveObject(aSubSO);
811 } // try to build from published parts
813 } // process arguments
818 //============================================================================
819 // function : RestoreSubShapesOneLevel
820 // purpose : Private method
821 //============================================================================
822 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
823 SALOMEDS::SObject_ptr theOldSO,
824 SALOMEDS::SObject_ptr theNewSO,
825 GEOM::GEOM_Object_ptr theNewO,
826 GEOM::find_shape_method theFindMethod)
829 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
830 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
831 CORBA::is_nil(theNewO) || CORBA::is_nil(theNewSO))
832 return aParts._retn();
834 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
836 // Get interface, containing method, which we will use to reconstruct sub-shapes
837 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
838 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
840 // Reconstruct published sub-shapes
841 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
844 for (it->Init(); it->More(); it->Next()) {
847 aParts->length(aLen);
849 for (it->Init(); it->More(); it->Next()) {
850 SALOMEDS::SObject_var anOldSubSO = it->Value();
852 TCollection_AsciiString anArgName = anOldSubSO->GetName();
854 SALOMEDS::GenericAttribute_var anAttr;
855 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
856 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
857 GEOM::GEOM_Object_var anOldSubO =
858 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
859 if (!CORBA::is_nil(anOldSubO)) {
860 // Find a sub-shape of theNewO in place of anOldSubO
861 GEOM::GEOM_Object_var aNewSubO;
862 switch (theFindMethod) {
863 case GEOM::FSM_GetInPlace:
866 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
869 case GEOM::FSM_Transformed:
871 // transformation, cannot use GetInPlace, operate with indices
872 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
873 if (anIDs->length() > 1) {
875 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
876 if (!CORBA::is_nil(aNewSubO))
877 aGroupOp->UnionIDs(aNewSubO, anIDs);
881 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
885 case GEOM::FSM_GetSame:
888 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
891 case GEOM::FSM_GetShapesOnShape:
893 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
894 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
895 (short)GEOM::SOLID, GEOM::ST_ONIN);
898 case GEOM::FSM_GetInPlaceByHistory:
900 // Use GetInPlaceByHistory
901 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
908 if (!CORBA::is_nil(aNewSubO)) {
909 // add the part to the list
910 aParts[i] = aNewSubO;
913 // Publish the sub-shape
914 TCollection_AsciiString aSubName ("from_");
915 aSubName += anArgName;
916 SALOMEDS::SObject_var aNewSubSO = aStudyBuilder->NewObject(theNewSO);
917 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
919 aNewSubO->SetColor(anOldSubO->GetColor());
921 // Restore published sub-shapes of the argument
922 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
923 // pass the main shape as Object, because only it has the history
924 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
926 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, aNewSubO, theFindMethod);
928 else { // GetInPlace failed, try to build from published parts
929 SALOMEDS::SObject_var aNewSubSO = aStudyBuilder->NewObject(theNewSO);
931 // Restore published sub-shapes of the argument
932 GEOM::ListOfGO_var aParts =
933 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
935 if (aParts->length() > 0) {
936 // try to build an object from a set of its sub-shapes,
937 // that published and will be reconstructed
938 if (aParts->length() > 1) {
939 aNewSubO = aShapesOp->MakeCompound(aParts);
942 aNewSubO = aParts[0];
945 if (!CORBA::is_nil(aNewSubO)) {
946 // add the part to the list
947 aParts[i] = aNewSubO;
950 // Publish the sub-shape
951 TCollection_AsciiString aSubName = "from_parts_of_";
952 aSubName += anArgName;
953 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
955 aNewSubO->SetColor(anOldSubO->GetColor());
959 // remove created aSubSO, because no parts have been found
960 aStudyBuilder->RemoveObject(aNewSubSO);
962 } // try to build from published parts
965 } // iterate on published sub-shapes
968 return aParts._retn();
971 //============================================================================
972 // function : register()
973 // purpose : register 'name' in 'name_service'
974 //============================================================================
975 void GEOM_Gen_i::register_name(char * name)
977 GEOM::GEOM_Gen_var g = _this();
978 name_service->Register(g, name);
981 //============================================================================
984 //============================================================================
985 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
987 _impl->Undo(theStudyID);
990 //============================================================================
993 //============================================================================
994 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
996 _impl->Redo(theStudyID);
999 //============================================================================
1000 // function : GetIBasicOperations
1002 //============================================================================
1003 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
1004 throw ( SALOME::SALOME_Exception )
1006 Unexpect aCatch(SALOME_SalomeException);
1007 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
1009 GEOM::GEOM_Gen_ptr engine = _this();
1011 //transfer reference on engine
1012 GEOM_IBasicOperations_i* aServant =
1013 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
1015 // activate the CORBA servant
1016 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
1017 return operations._retn();
1020 //============================================================================
1021 // function : GetITransformOperations
1023 //============================================================================
1024 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
1025 throw ( SALOME::SALOME_Exception )
1027 Unexpect aCatch(SALOME_SalomeException);
1028 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
1030 GEOM::GEOM_Gen_ptr engine = _this();
1032 GEOM_ITransformOperations_i* aServant =
1033 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
1035 // activate the CORBA servant
1036 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
1037 return operations._retn();
1040 //============================================================================
1041 // function : GetI3DPrimOperations
1043 //============================================================================
1044 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
1045 throw ( SALOME::SALOME_Exception )
1047 Unexpect aCatch(SALOME_SalomeException);
1048 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
1050 GEOM::GEOM_Gen_ptr engine = _this();
1052 GEOM_I3DPrimOperations_i* aServant =
1053 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
1055 // activate the CORBA servant
1056 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
1057 return operations._retn();
1060 //============================================================================
1061 // function : GetIShapesOperations
1063 //============================================================================
1064 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
1065 throw ( SALOME::SALOME_Exception )
1067 Unexpect aCatch(SALOME_SalomeException);
1068 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
1070 GEOM::GEOM_Gen_ptr engine = _this();
1072 GEOM_IShapesOperations_i* aServant =
1073 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
1075 // activate the CORBA servant
1076 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
1077 return operations._retn();
1080 //============================================================================
1081 // function : GetIBlocksOperations
1083 //============================================================================
1084 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
1085 throw ( SALOME::SALOME_Exception )
1087 Unexpect aCatch(SALOME_SalomeException);
1088 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
1090 GEOM::GEOM_Gen_ptr engine = _this();
1092 GEOM_IBlocksOperations_i* aServant =
1093 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
1095 // activate the CORBA servant
1096 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
1097 return operations._retn();
1100 //============================================================================
1101 // function : GetIBooleanOperations
1103 //============================================================================
1104 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
1105 throw ( SALOME::SALOME_Exception )
1107 Unexpect aCatch(SALOME_SalomeException);
1108 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
1110 GEOM::GEOM_Gen_ptr engine = _this();
1112 GEOM_IBooleanOperations_i* aServant =
1113 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
1115 // activate the CORBA servant
1116 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
1117 return operations._retn();
1120 //============================================================================
1121 // function : GetICurvesOperations
1123 //============================================================================
1124 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
1125 throw ( SALOME::SALOME_Exception )
1127 Unexpect aCatch(SALOME_SalomeException);
1128 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
1130 GEOM::GEOM_Gen_ptr engine = _this();
1132 GEOM_ICurvesOperations_i* aServant =
1133 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
1135 // activate the CORBA servant
1136 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
1137 return operations._retn();
1140 //============================================================================
1141 // function : GetILocalOperations
1143 //============================================================================
1144 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
1145 throw ( SALOME::SALOME_Exception )
1147 Unexpect aCatch(SALOME_SalomeException);
1148 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
1150 GEOM::GEOM_Gen_ptr engine = _this();
1152 GEOM_ILocalOperations_i* aServant =
1153 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
1155 // activate the CORBA servant
1156 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
1157 return operations._retn();
1160 //============================================================================
1161 // function : GetIHealingOperations
1163 //============================================================================
1164 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
1165 throw ( SALOME::SALOME_Exception )
1167 Unexpect aCatch(SALOME_SalomeException);
1168 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
1170 GEOM::GEOM_Gen_ptr engine = _this();
1172 GEOM_IHealingOperations_i* aServant =
1173 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
1175 // activate the CORBA servant
1176 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
1177 return operations._retn();
1180 //============================================================================
1181 // function : GetIInsertOperations
1183 //============================================================================
1184 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
1185 throw ( SALOME::SALOME_Exception )
1187 Unexpect aCatch(SALOME_SalomeException);
1188 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
1190 GEOM::GEOM_Gen_ptr engine = _this();
1192 GEOM_IInsertOperations_i* aServant =
1193 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
1195 // activate the CORBA servant
1196 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
1197 return operations._retn();
1200 //============================================================================
1201 // function : GetIMeasureOperations
1203 //============================================================================
1204 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
1205 throw ( SALOME::SALOME_Exception )
1207 Unexpect aCatch(SALOME_SalomeException);
1208 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
1210 GEOM::GEOM_Gen_ptr engine = _this();
1212 GEOM_IMeasureOperations_i* aServant =
1213 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
1215 // activate the CORBA servant
1216 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
1217 return operations._retn();
1220 //============================================================================
1221 // function : GetIGroupOperations
1223 //============================================================================
1224 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
1225 throw ( SALOME::SALOME_Exception )
1227 Unexpect aCatch(SALOME_SalomeException);
1228 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
1230 GEOM::GEOM_Gen_ptr engine = _this();
1232 GEOM_IGroupOperations_i* aServant =
1233 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
1235 // activate the CORBA servant
1236 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
1237 return operations._retn();
1240 //=============================================================================
1244 //=============================================================================
1245 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
1246 const GEOM::ListOfLong& theIndices)
1248 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
1249 return GEOM::GEOM_Object::_nil();
1250 CORBA::String_var entry = theMainShape->GetEntry();
1251 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
1252 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
1254 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
1255 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
1257 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
1258 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
1260 TCollection_AsciiString anEntry;
1261 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
1262 return GetObject(anObject->GetDocID(), anEntry.ToCString());
1265 //=============================================================================
1269 //=============================================================================
1270 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
1272 CORBA::String_var anEntry = theObject->GetEntry();
1273 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry);
1274 if (anObject.IsNull()) return;
1275 _impl->RemoveObject(anObject);
1280 //=================================================================================
1281 // function : GetStringFromIOR()
1282 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
1283 //=================================================================================
1284 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
1285 return _orb->object_to_string(theObject);
1289 //=================================================================================
1290 // function : GetIORFromString()
1291 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
1292 //=================================================================================
1293 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
1294 GEOM::GEOM_Object_var aGeomObject;
1295 if(strcmp(stringIOR,"") != 0){
1296 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
1297 if(!CORBA::is_nil(anObject))
1298 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
1300 return aGeomObject._retn();
1303 //=================================================================================
1304 // function : GetObject()
1306 //=================================================================================
1307 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
1309 GEOM::GEOM_Object_var obj;
1310 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
1311 if (handle_object.IsNull()) return obj._retn();
1313 TCollection_AsciiString stringIOR = handle_object->GetIOR();
1314 if (stringIOR.Length() > 1) {
1315 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
1316 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
1320 GEOM::GEOM_Gen_ptr engine = _this();
1321 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
1323 obj = servant->_this();
1324 CORBA::String_var objStr = _orb->object_to_string(obj);
1325 TCollection_AsciiString anAscii( (char *)objStr.in() );
1326 handle_object->SetIOR( anAscii );
1330 //=================================================================================
1331 // function : hasObjectInfo()
1332 // purpose : shows if module provides information for its objects
1333 //=================================================================================
1334 bool GEOM_Gen_i::hasObjectInfo()
1339 //=================================================================================
1340 // function : getObjectInfo()
1341 // purpose : returns an information for a given object by its entry
1342 //=================================================================================
1343 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
1345 GEOM::GEOM_Object_var aGeomObject;
1347 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
1348 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
1349 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
1350 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
1351 SALOMEDS::SObject_var aResultSObj;
1352 if (aSObj->ReferencedObject(aResultSObj))
1353 aSObj = aResultSObj;
1355 SALOMEDS::GenericAttribute_var anAttr;
1356 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
1357 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1358 CORBA::String_var aVal = anIOR->Value();
1359 CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
1360 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
1363 char* aTypeInfo = "Object";
1364 if ( !aGeomObject->_is_nil() ) {
1365 GEOM::GEOM_IKindOfShape::shape_kind aKind;
1366 GEOM::ListOfLong_var anInts;
1367 GEOM::ListOfDouble_var aDbls;
1369 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
1370 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
1372 if ( anOp->IsDone() ) {
1374 case GEOM::GEOM_IKindOfShape::COMPOUND:
1375 aTypeInfo = "Compound";
1377 case GEOM::GEOM_IKindOfShape::COMPSOLID:
1378 aTypeInfo = "CompSolid";
1380 case GEOM::GEOM_IKindOfShape::SHELL:
1381 aTypeInfo = "Shell";
1383 case GEOM::GEOM_IKindOfShape::WIRE:
1384 if ( anInts[0] == 1 )
1385 aTypeInfo = "Closed Wire";
1386 else if ( anInts[0] == 2 )
1387 aTypeInfo = "Opened Wire";
1392 case GEOM::GEOM_IKindOfShape::SPHERE:
1393 aTypeInfo = "Sphere";
1395 case GEOM::GEOM_IKindOfShape::CYLINDER:
1396 aTypeInfo = "Cylinder";
1398 case GEOM::GEOM_IKindOfShape::BOX:
1399 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
1402 case GEOM::GEOM_IKindOfShape::TORUS:
1403 aTypeInfo = "Torus";
1405 case GEOM::GEOM_IKindOfShape::CONE:
1408 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
1409 aTypeInfo = "Polyhedron";
1411 case GEOM::GEOM_IKindOfShape::SOLID:
1412 aTypeInfo = "Solid";
1415 case GEOM::GEOM_IKindOfShape::SPHERE2D:
1416 aTypeInfo = "Spherical Face";
1418 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
1419 aTypeInfo = "Cylindrical Face";
1421 case GEOM::GEOM_IKindOfShape::TORUS2D:
1422 aTypeInfo = "Toroidal Face";
1424 case GEOM::GEOM_IKindOfShape::CONE2D:
1425 aTypeInfo = "Conical Face";
1427 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
1430 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
1431 aTypeInfo = "Elliptical Face";
1433 case GEOM::GEOM_IKindOfShape::POLYGON:
1434 aTypeInfo = "Polygon";
1436 case GEOM::GEOM_IKindOfShape::PLANE:
1437 aTypeInfo = "Plane";
1439 case GEOM::GEOM_IKindOfShape::PLANAR:
1440 aTypeInfo = "Planar Face";
1442 case GEOM::GEOM_IKindOfShape::FACE:
1446 case GEOM::GEOM_IKindOfShape::CIRCLE:
1447 aTypeInfo = "Circle";
1449 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
1452 case GEOM::GEOM_IKindOfShape::ELLIPSE:
1453 aTypeInfo = "Ellipse";
1455 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
1456 aTypeInfo = "Arc Ellipse";
1458 case GEOM::GEOM_IKindOfShape::LINE:
1461 case GEOM::GEOM_IKindOfShape::SEGMENT:
1462 aTypeInfo = "Segment";
1464 case GEOM::GEOM_IKindOfShape::EDGE:
1467 case GEOM::GEOM_IKindOfShape::VERTEX:
1468 aTypeInfo = "Vertex";
1476 char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
1477 sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
1479 char* ret = CORBA::string_dup(anInfo);
1484 //=====================================================================================
1486 //=====================================================================================
1490 PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
1491 PortableServer::POA_ptr poa,
1492 PortableServer::ObjectId * contId,
1493 const char *instanceName,
1494 const char * interfaceName)
1496 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
1497 // Don't understand the reason of this register ????
1498 // myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
1499 return myGEOM_Gen_i->getId();