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"
34 #include "Utils_CorbaException.hxx"
36 #include "Utils_ExceptHandlers.hxx"
37 #include "utilities.h"
39 #include "GEOM_Object_i.hh"
40 #include "GEOM_Object.hxx"
41 #include "GEOM_Function.hxx"
42 #include "GEOMImpl_Types.hxx"
43 #include "GEOMImpl_CopyDriver.hxx"
46 #include <BRep_Builder.hxx>
47 #include <BRepTools.hxx>
48 #include <TDF_Label.hxx>
49 #include <TDF_Tool.hxx>
50 #include <TCollection_AsciiString.hxx>
51 #include <TColStd_HArray1OfInteger.hxx>
52 #include <TopAbs_ShapeEnum.hxx>
55 #include "SALOMEDS_Tool.hxx"
57 //============================================================================
58 // function : GEOM_Gen_i()
59 // purpose : constructor to be called for servant creation.
60 //============================================================================
61 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
62 PortableServer::POA_ptr poa,
63 PortableServer::ObjectId * contId,
64 const char *instanceName,
65 const char *interfaceName) :
66 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
69 _id = _poa->activate_object(_thisObj);
70 name_service = new SALOME_NamingService(_orb);
72 _impl = new ::GEOMImpl_Gen;
74 //PAL10867: disable signals catching with "noexcepthandler" option
75 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
76 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
78 //work around PAL12004, PAL12628
79 //OSD::SetSignal( true );
83 char* envDisableFPE = getenv("DISABLE_FPE");
84 if (envDisableFPE && atoi(envDisableFPE))
89 OSD::SetSignal( raiseFPE );
93 //============================================================================
94 // function : ~GEOM_Gen_i()
95 // purpose : destructor
96 //============================================================================
97 GEOM_Gen_i::~GEOM_Gen_i() {
103 //============================================================================
104 // function : IORToLocalPersistentID()
106 //============================================================================
107 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
108 const char* IORString,
109 CORBA::Boolean isMultiFile,
110 CORBA::Boolean isASCII)
112 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
113 if (!CORBA::is_nil(anObject)) {
114 return CORBA::string_dup(anObject->GetEntry());
120 //============================================================================
121 // function : LocalPersistentIDToIOR()
122 // purpose : Create/Load CORBA object from a persistent ref (an entry)
123 // : Used when a study is loaded
124 // : The IOR (IORName) of object created is returned
125 //============================================================================
126 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
127 const char* aLocalPersistentID,
128 CORBA::Boolean isMultiFile,
129 CORBA::Boolean isASCII)
131 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
133 Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
134 TCollection_AsciiString anEntry;
135 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
136 GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
138 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
139 return CORBA::string_dup(aPersRefString);
142 //============================================================================
143 // function : CanPublishInStudy
145 //============================================================================
146 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
148 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
149 return !(anObject->_is_nil());
153 //============================================================================
154 // function : PublishInStudy
156 //============================================================================
157 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
158 SALOMEDS::SObject_ptr theSObject,
159 CORBA::Object_ptr theObject,
160 const char* theName) throw (SALOME::SALOME_Exception)
162 Unexpect aCatch(SALOME_SalomeException);
163 SALOMEDS::SObject_var aResultSO;
164 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
165 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
166 if(aShape->_is_nil()) return aResultSO;
168 SALOMEDS::GenericAttribute_var anAttr;
169 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
171 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
172 if (aFather->_is_nil()) {
173 aFather = aStudyBuilder->NewComponent("GEOM");
174 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
175 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
176 aName->SetValue("Geometry");
177 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
178 SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
179 aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
181 if (aFather->_is_nil()) return aResultSO;
183 if (CORBA::is_nil(theSObject)) {
184 aResultSO = aStudyBuilder->NewObject(aFather);
186 if (!theSObject->ReferencedObject(aResultSO))
187 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
188 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
190 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
191 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
192 //char *aGeomObjIOR = _orb->object_to_string(theObject);
193 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
194 //anIOR->SetValue(CORBA::string_dup(aGeomObjIOR));
195 anIOR->SetValue(aGeomObjIOR);
197 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
198 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
199 TCollection_AsciiString aShapeName("Shape_");
201 if ( aShape->GetType() == GEOM_GROUP ) {
202 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
203 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
205 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
206 aShapeName = "Group_Of_Vertices_";
209 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
210 aShapeName = "Group_Of_Edges_";
213 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
214 aShapeName = "Group_Of_Faces_";
217 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
218 aShapeName = "Group_Of_Solids_";
221 } else if ( aShape->GetType() == GEOM_MARKER ) {
222 aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
223 aShapeName = "LocalCS_";
224 } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
225 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
226 aShapeName = "Compound_";
227 } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
228 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
229 aShapeName = "Compsolid_";
230 } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
231 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
232 aShapeName = "Solid_";
233 } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
234 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
235 aShapeName = "Shell_";
236 } else if ( aShape->GetShapeType() == GEOM::FACE ) {
237 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
238 aShapeName = "Face_";
239 } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
240 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
241 aShapeName = "Wire_";
242 } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
243 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
244 aShapeName = "Edge_";
245 } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
246 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
247 aShapeName = "Vertex_";
249 //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
250 //else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName));
252 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
253 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
254 // of objects in the study, but compute a number of objects with the same prefix
255 // and build a new name as Prefix_N+1
256 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
257 int i = 0; // (WITH EMPTY NEW NAME)
258 SALOMEDS::SObject_var obj;
259 TCollection_AsciiString aNewShapeName;
261 aNewShapeName = aShapeName + TCollection_AsciiString(++i);
262 obj = theStudy->FindObject( aNewShapeName.ToCString() );
264 while ( !obj->_is_nil() );
265 aShapeName = aNewShapeName;
267 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
268 aShapeName = TCollection_AsciiString((char*)theName);
270 //Set the study entry as a name of the published GEOM_Object
271 aShape->SetStudyEntry(aResultSO->GetID());
273 //Set a name of the added shape
274 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
275 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
276 aNameAttrib->SetValue(aShapeName.ToCString());
278 //Set NoteBook variables used in the object creation
279 TCollection_AsciiString aVars;
280 SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aShape->GetParameters());
281 for(int i = 0, n = aSections->length(); i < n; i++) {
282 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
283 for(int j = 0, m = aListOfVars.length(); j < m; j++) {
284 if(theStudy->IsVariable(aListOfVars[j].in()))
285 aVars += TCollection_AsciiString(aListOfVars[j].in());
292 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeString");
293 SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
294 aStringAttrib->SetValue(aVars.ToCString());
296 //Set a name of the GEOM object
297 aShape->SetName(theName);
299 return aResultSO._retn();
303 //============================================================================
305 // purpose : save OCAF/Geom document
306 //============================================================================
307 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
310 SALOMEDS::TMPFile_var aStreamFile;
311 // Get a temporary directory to store a file
312 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
314 // OCCT BUG: cannot save a document (in current folder)
315 // if directory name is empty
316 if (aTmpDir.size() == 0) {
324 // Create a list to store names of created files
325 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
327 // Prepare a file name to open
328 TCollection_AsciiString aNameWithExt("");
330 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
331 (theComponent->GetStudy()->URL())).c_str());
332 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
333 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
334 // Build a full file name of temporary file
335 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
336 // Save GEOM component in this file
337 _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
338 // Conver a file to the byte stream
339 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
340 // Remove the created file and tmp directory
341 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
343 // Return the created byte stream
344 return aStreamFile._retn();
348 //============================================================================
349 // function : SaveASCII()
351 //============================================================================
352 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
355 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
356 return aStreamFile._retn();
360 //============================================================================
363 //============================================================================
364 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
365 const SALOMEDS::TMPFile& theStream,
369 if (theStream.length() <= 9) {
370 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
374 // Get a temporary directory for a file
375 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
377 // OCCT BUG: cannot load a document (from current folder)
378 // if directory name is empty
379 if (aTmpDir.size() == 0) {
387 // Conver the byte stream theStream to a file and place it in tmp directory
388 SALOMEDS::ListOfFileNames_var aSeq =
389 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
391 // Prepare a file name to open
392 TCollection_AsciiString aNameWithExt("");
394 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
395 (theComponent->GetStudy()->URL())).c_str());
396 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
397 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
400 if (!_impl->Load(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString())) return false;
402 // Remove the created file and tmp directory
403 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
405 SALOMEDS::Study_var Study = theComponent->GetStudy();
406 TCollection_AsciiString name (Study->Name());
412 //============================================================================
413 // function : LoadASCII()
415 //============================================================================
416 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
417 const SALOMEDS::TMPFile& theStream,
420 return Load(theComponent, theStream, theURL, isMultiFile);
424 //============================================================================
425 // function : Close()
427 //============================================================================
428 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
430 _impl->Close(theComponent->GetStudy()->StudyId());
433 //============================================================================
434 // function : CanCopy()
436 //============================================================================
437 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
438 // Try to retrieve known by Geometry component GEOM_Object by given IOR
439 SALOMEDS::GenericAttribute_var anAttr;
440 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
442 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
444 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
445 // If the object is null one it can't be copied: return false
446 if (anObject->_is_nil()) return false;
450 //============================================================================
451 // function : CopyFrom()
453 //============================================================================
454 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
456 // Declare a sequence of the byte to store the copied object
457 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
459 // Try to get GEOM_Object object by given SObject
460 SALOMEDS::GenericAttribute_var anAttr;
461 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
462 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
463 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
464 if (anObject->_is_nil()) return aStreamFile._retn();
466 aStreamFile = anObject->GetShapeStream();
468 // Assign an ID the type of GEOM_Object
469 theObjectID = anObject->GetType();
471 // Return created TMPFile
472 return aStreamFile._retn();
475 //============================================================================
476 // function : CanPaste()
478 //============================================================================
479 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
480 // The Geometry component can paste only objects copied by Geometry component
481 // and with the object type = 1
482 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
486 //============================================================================
487 // function : PasteInto()
489 //============================================================================
490 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
491 CORBA::Long theObjectID,
492 SALOMEDS::SObject_ptr theObject) {
493 // Find the current Study and StudyBuilder
494 SALOMEDS::Study_var aStudy = theObject->GetStudy();
495 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
497 // Retrieve a TopoDS_Shape from byte stream
498 TopoDS_Shape aTopology;
499 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
500 BRep_Builder aBuilder;
502 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
503 } catch (Standard_Failure) {
507 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
508 SALOMEDS::SObject_var aNewSO;
509 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
510 aNewSO = aStudyBuilder->NewObject(theObject);
511 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
514 //Create a new GEOM_Object
515 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
516 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
517 aFunction->SetValue(aTopology);
519 TCollection_AsciiString anEntry;
520 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
521 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
523 //Set the study entry of the published GEOM_Object
524 obj->SetStudyEntry(aNewSO->GetID());
526 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
527 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
528 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
529 CORBA::String_var objStr = _orb->object_to_string(obj);
530 anIOR->SetValue(objStr.in());
532 // Return the created in the Study SObject
533 return aNewSO._retn();
536 //============================================================================
537 // function : ComponentDataType()
539 //============================================================================
540 char* GEOM_Gen_i::ComponentDataType()
542 return CORBA::string_dup("GEOM");
545 //============================================================================
546 // function : AddInStudy
548 //============================================================================
549 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
550 GEOM::GEOM_Object_ptr theObject,
552 GEOM::GEOM_Object_ptr theFather)
554 SALOMEDS::SObject_var aResultSO;
555 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
557 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
558 CORBA::String_var IOR;
560 if(!theFather->_is_nil()) {
561 IOR = _orb->object_to_string(theFather);
562 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in());
563 if(aFatherSO->_is_nil()) return aResultSO._retn();
564 aResultSO = aStudyBuilder->NewObject(aFatherSO);
565 //aStudyBuilder->Addreference(aResultSO, aResultSO);
568 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
569 if(aResultSO->_is_nil()) return aResultSO._retn();
571 GEOM::ListOfGO_var aList = theObject->GetDependency();
572 Standard_Integer aLength = aList->length();
573 if(aLength < 1) return aResultSO._retn();
575 //Publish the arguments
576 for(Standard_Integer i = 0; i< aLength; i++) {
577 GEOM::GEOM_Object_var anObject = aList[i];
578 if(anObject->_is_nil()) continue;
579 IOR = _orb->object_to_string(anObject);
580 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR.in());
581 if(aSO->_is_nil()) continue;
582 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
583 aStudyBuilder->Addreference(aSubSO, aSO);
586 return aResultSO._retn();
589 //============================================================================
590 // function : RestoreSubShapesO
591 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
592 // To be used from python scripts out of geompy.addToStudy (non-default usage)
593 //============================================================================
594 CORBA::Boolean GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
595 GEOM::GEOM_Object_ptr theObject,
596 const GEOM::ListOfGO& theArgs,
597 GEOM::find_shape_method theFindMethod,
598 CORBA::Boolean theInheritFirstArg)
600 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
603 // find SObject in the study
604 CORBA::String_var anIORo = _orb->object_to_string(theObject);
605 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
606 if (CORBA::is_nil(aSO))
609 return RestoreSubShapes(theStudy, theObject, aSO, theArgs, theFindMethod, theInheritFirstArg);
612 //============================================================================
613 // function : RestoreSubShapesSO
614 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
615 // To be used from GUI and from geompy.addToStudy
616 //============================================================================
617 CORBA::Boolean GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
618 SALOMEDS::SObject_ptr theSObject,
619 const GEOM::ListOfGO& theArgs,
620 GEOM::find_shape_method theFindMethod,
621 CORBA::Boolean theInheritFirstArg)
623 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
626 SALOMEDS::GenericAttribute_var anAttr;
627 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
630 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
631 CORBA::String_var anIORso = anAttrIOR->Value();
633 // get Object from SObject
634 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
635 if (CORBA::is_nil(anO))
638 return RestoreSubShapes(theStudy, anO, theSObject, theArgs, theFindMethod, theInheritFirstArg);
641 //============================================================================
642 // function : RestoreSubShapes
643 // purpose : Private method. Works only if both theObject and theSObject
644 // are defined, and does not check, if they correspond to each other.
645 //============================================================================
646 CORBA::Boolean GEOM_Gen_i::RestoreSubShapes (SALOMEDS::Study_ptr theStudy,
647 GEOM::GEOM_Object_ptr theObject,
648 SALOMEDS::SObject_ptr theSObject,
649 const GEOM::ListOfGO& theArgs,
650 GEOM::find_shape_method theFindMethod,
651 CORBA::Boolean theInheritFirstArg)
653 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) || CORBA::is_nil(theSObject))
656 // Arguments to be published
657 GEOM::ListOfGO_var aList;
659 // If theArgs list is empty, we try to publish all arguments,
660 // otherwise publish only passed args
661 Standard_Integer nbArgsActual = -1; // -1 means unknown
662 Standard_Integer aLength = theArgs.length();
664 aList = new GEOM::ListOfGO;
665 aList->length(aLength);
666 for (int i = 0; i < aLength; i++) {
667 aList[i] = theArgs[i];
672 aList = theObject->GetDependency();
673 aLength = aList->length();
674 nbArgsActual = aLength;
680 if (theInheritFirstArg || (nbArgsActual == 1)) {
681 // Do not publish argument's reflection,
682 // but only reconstruct its published sub-shapes
684 GEOM::GEOM_Object_var anArgO = aList[0];
685 CORBA::String_var anIOR = _orb->object_to_string(anArgO);
686 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
688 GEOM::ListOfGO_var aParts =
689 RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, theFindMethod);
691 // set the color of the transformed shape to the color of initial shape
692 theObject->SetColor(aList[0]->GetColor());
694 return (aParts->length() > 0);
697 // Get interface, containing method, which we will use to reconstruct sub-shapes
698 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
699 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
701 // Reconstruct arguments and tree of sub-shapes of the arguments
702 CORBA::String_var anIOR;
703 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
704 for (Standard_Integer i = 0; i < aLength; i++)
706 GEOM::GEOM_Object_var anArgO = aList[i];
707 if (!CORBA::is_nil(anArgO)) {
708 anIOR = _orb->object_to_string(anArgO);
709 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
710 TCollection_AsciiString anArgName;
711 if (CORBA::is_nil(anArgSO)) {
713 anArgName += TCollection_AsciiString(i);
716 anArgName = anArgSO->GetName();
719 // Find a sub-shape of theObject in place of the argument
720 GEOM::GEOM_Object_var aSubO;
721 switch (theFindMethod) {
722 case GEOM::FSM_GetInPlace:
725 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
728 case GEOM::FSM_Transformed:
730 // transformation, cannot use GetInPlace, operate with indices
731 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
732 if (anIDs->length() > 1) {
734 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
735 if (!CORBA::is_nil(aSubO))
736 aGroupOp->UnionIDs(aSubO, anIDs);
740 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
744 case GEOM::FSM_GetSame:
747 aSubO = aShapesOp->GetSame(theObject, anArgO);
750 case GEOM::FSM_GetShapesOnShape:
752 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
753 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
754 (short)GEOM::SOLID, GEOM::ST_ONIN);
757 case GEOM::FSM_GetInPlaceByHistory:
759 // Use GetInPlaceByHistory
760 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
767 if (!CORBA::is_nil(aSubO)) {
768 // Publish the sub-shape
769 TCollection_AsciiString aSubName ("from_");
770 aSubName += anArgName;
771 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(theSObject);
772 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
774 aSubO->SetColor(anArgO->GetColor());
776 if (!CORBA::is_nil(anArgSO)) {
777 // Restore published sub-shapes of the argument
778 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
779 // pass theObject, because only it has the history
780 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
782 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, aSubO, theFindMethod);
785 else { // GetInPlace failed, try to build from published parts
786 if (!CORBA::is_nil(anArgSO)) {
787 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(theSObject);
789 // Restore published sub-shapes of the argument
790 GEOM::ListOfGO_var aParts =
791 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
793 if (aParts->length() > 0) {
794 // try to build an argument from a set of its sub-shapes,
795 // that published and will be reconstructed
796 if (aParts->length() > 1) {
797 aSubO = aShapesOp->MakeCompound(aParts);
802 if (!CORBA::is_nil(aSubO)) {
803 // Publish the sub-shape
804 TCollection_AsciiString aSubName ("from_parts_of_");
805 aSubName += anArgName;
806 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
808 aSubO->SetColor(anArgO->GetColor());
812 // remove created aSubSO, because no parts have been found
813 aStudyBuilder->RemoveObject(aSubSO);
816 } // try to build from published parts
818 } // process arguments
823 //============================================================================
824 // function : RestoreSubShapesOneLevel
825 // purpose : Private method
826 //============================================================================
827 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
828 SALOMEDS::SObject_ptr theOldSO,
829 SALOMEDS::SObject_ptr theNewSO,
830 GEOM::GEOM_Object_ptr theNewO,
831 GEOM::find_shape_method theFindMethod)
834 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
835 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
836 CORBA::is_nil(theNewO) || CORBA::is_nil(theNewSO))
837 return aParts._retn();
839 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
841 // Get interface, containing method, which we will use to reconstruct sub-shapes
842 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
843 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
845 // Reconstruct published sub-shapes
846 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
849 for (it->Init(); it->More(); it->Next()) {
852 aParts->length(aLen);
854 for (it->Init(); it->More(); it->Next()) {
855 SALOMEDS::SObject_var anOldSubSO = it->Value();
857 TCollection_AsciiString anArgName = anOldSubSO->GetName();
859 SALOMEDS::GenericAttribute_var anAttr;
860 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
861 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
862 GEOM::GEOM_Object_var anOldSubO =
863 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
864 if (!CORBA::is_nil(anOldSubO)) {
865 // Find a sub-shape of theNewO in place of anOldSubO
866 GEOM::GEOM_Object_var aNewSubO;
867 switch (theFindMethod) {
868 case GEOM::FSM_GetInPlace:
871 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
874 case GEOM::FSM_Transformed:
876 // transformation, cannot use GetInPlace, operate with indices
877 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
878 if (anIDs->length() > 1) {
880 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
881 if (!CORBA::is_nil(aNewSubO))
882 aGroupOp->UnionIDs(aNewSubO, anIDs);
886 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
890 case GEOM::FSM_GetSame:
893 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
896 case GEOM::FSM_GetShapesOnShape:
898 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
899 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
900 (short)GEOM::SOLID, GEOM::ST_ONIN);
903 case GEOM::FSM_GetInPlaceByHistory:
905 // Use GetInPlaceByHistory
906 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
913 if (!CORBA::is_nil(aNewSubO)) {
914 // add the part to the list
915 aParts[i] = aNewSubO;
918 // Publish the sub-shape
919 TCollection_AsciiString aSubName ("from_");
920 aSubName += anArgName;
921 SALOMEDS::SObject_var aNewSubSO = aStudyBuilder->NewObject(theNewSO);
922 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
924 aNewSubO->SetColor(anOldSubO->GetColor());
926 // Restore published sub-shapes of the argument
927 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
928 // pass the main shape as Object, because only it has the history
929 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
931 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, aNewSubO, theFindMethod);
933 else { // GetInPlace failed, try to build from published parts
934 SALOMEDS::SObject_var aNewSubSO = aStudyBuilder->NewObject(theNewSO);
936 // Restore published sub-shapes of the argument
937 GEOM::ListOfGO_var aParts =
938 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
940 if (aParts->length() > 0) {
941 // try to build an object from a set of its sub-shapes,
942 // that published and will be reconstructed
943 if (aParts->length() > 1) {
944 aNewSubO = aShapesOp->MakeCompound(aParts);
947 aNewSubO = aParts[0];
950 if (!CORBA::is_nil(aNewSubO)) {
951 // add the part to the list
952 aParts[i] = aNewSubO;
955 // Publish the sub-shape
956 TCollection_AsciiString aSubName = "from_parts_of_";
957 aSubName += anArgName;
958 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
960 aNewSubO->SetColor(anOldSubO->GetColor());
964 // remove created aSubSO, because no parts have been found
965 aStudyBuilder->RemoveObject(aNewSubSO);
967 } // try to build from published parts
970 } // iterate on published sub-shapes
973 return aParts._retn();
976 //============================================================================
977 // function : register()
978 // purpose : register 'name' in 'name_service'
979 //============================================================================
980 void GEOM_Gen_i::register_name(char * name)
982 GEOM::GEOM_Gen_var g = _this();
983 name_service->Register(g, name);
986 //============================================================================
989 //============================================================================
990 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
992 _impl->Undo(theStudyID);
995 //============================================================================
998 //============================================================================
999 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
1001 _impl->Redo(theStudyID);
1004 //============================================================================
1005 // function : GetIBasicOperations
1007 //============================================================================
1008 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
1009 throw ( SALOME::SALOME_Exception )
1011 Unexpect aCatch(SALOME_SalomeException);
1012 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
1014 GEOM::GEOM_Gen_ptr engine = _this();
1016 //transfer reference on engine
1017 GEOM_IBasicOperations_i* aServant =
1018 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
1020 // activate the CORBA servant
1021 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
1022 return operations._retn();
1025 //============================================================================
1026 // function : GetITransformOperations
1028 //============================================================================
1029 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
1030 throw ( SALOME::SALOME_Exception )
1032 Unexpect aCatch(SALOME_SalomeException);
1033 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
1035 GEOM::GEOM_Gen_ptr engine = _this();
1037 GEOM_ITransformOperations_i* aServant =
1038 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
1040 // activate the CORBA servant
1041 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
1042 return operations._retn();
1045 //============================================================================
1046 // function : GetI3DPrimOperations
1048 //============================================================================
1049 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
1050 throw ( SALOME::SALOME_Exception )
1052 Unexpect aCatch(SALOME_SalomeException);
1053 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
1055 GEOM::GEOM_Gen_ptr engine = _this();
1057 GEOM_I3DPrimOperations_i* aServant =
1058 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
1060 // activate the CORBA servant
1061 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
1062 return operations._retn();
1065 //============================================================================
1066 // function : GetIShapesOperations
1068 //============================================================================
1069 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
1070 throw ( SALOME::SALOME_Exception )
1072 Unexpect aCatch(SALOME_SalomeException);
1073 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
1075 GEOM::GEOM_Gen_ptr engine = _this();
1077 GEOM_IShapesOperations_i* aServant =
1078 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
1080 // activate the CORBA servant
1081 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
1082 return operations._retn();
1085 //============================================================================
1086 // function : GetIBlocksOperations
1088 //============================================================================
1089 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
1090 throw ( SALOME::SALOME_Exception )
1092 Unexpect aCatch(SALOME_SalomeException);
1093 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
1095 GEOM::GEOM_Gen_ptr engine = _this();
1097 GEOM_IBlocksOperations_i* aServant =
1098 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
1100 // activate the CORBA servant
1101 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
1102 return operations._retn();
1105 //============================================================================
1106 // function : GetIBooleanOperations
1108 //============================================================================
1109 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
1110 throw ( SALOME::SALOME_Exception )
1112 Unexpect aCatch(SALOME_SalomeException);
1113 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
1115 GEOM::GEOM_Gen_ptr engine = _this();
1117 GEOM_IBooleanOperations_i* aServant =
1118 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
1120 // activate the CORBA servant
1121 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
1122 return operations._retn();
1125 //============================================================================
1126 // function : GetICurvesOperations
1128 //============================================================================
1129 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
1130 throw ( SALOME::SALOME_Exception )
1132 Unexpect aCatch(SALOME_SalomeException);
1133 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
1135 GEOM::GEOM_Gen_ptr engine = _this();
1137 GEOM_ICurvesOperations_i* aServant =
1138 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
1140 // activate the CORBA servant
1141 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
1142 return operations._retn();
1145 //============================================================================
1146 // function : GetILocalOperations
1148 //============================================================================
1149 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
1150 throw ( SALOME::SALOME_Exception )
1152 Unexpect aCatch(SALOME_SalomeException);
1153 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
1155 GEOM::GEOM_Gen_ptr engine = _this();
1157 GEOM_ILocalOperations_i* aServant =
1158 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
1160 // activate the CORBA servant
1161 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
1162 return operations._retn();
1165 //============================================================================
1166 // function : GetIHealingOperations
1168 //============================================================================
1169 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
1170 throw ( SALOME::SALOME_Exception )
1172 Unexpect aCatch(SALOME_SalomeException);
1173 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
1175 GEOM::GEOM_Gen_ptr engine = _this();
1177 GEOM_IHealingOperations_i* aServant =
1178 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
1180 // activate the CORBA servant
1181 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
1182 return operations._retn();
1185 //============================================================================
1186 // function : GetIInsertOperations
1188 //============================================================================
1189 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
1190 throw ( SALOME::SALOME_Exception )
1192 Unexpect aCatch(SALOME_SalomeException);
1193 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
1195 GEOM::GEOM_Gen_ptr engine = _this();
1197 GEOM_IInsertOperations_i* aServant =
1198 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
1200 // activate the CORBA servant
1201 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
1202 return operations._retn();
1205 //============================================================================
1206 // function : GetIMeasureOperations
1208 //============================================================================
1209 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
1210 throw ( SALOME::SALOME_Exception )
1212 Unexpect aCatch(SALOME_SalomeException);
1213 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
1215 GEOM::GEOM_Gen_ptr engine = _this();
1217 GEOM_IMeasureOperations_i* aServant =
1218 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
1220 // activate the CORBA servant
1221 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
1222 return operations._retn();
1225 //============================================================================
1226 // function : GetIGroupOperations
1228 //============================================================================
1229 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
1230 throw ( SALOME::SALOME_Exception )
1232 Unexpect aCatch(SALOME_SalomeException);
1233 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
1235 GEOM::GEOM_Gen_ptr engine = _this();
1237 GEOM_IGroupOperations_i* aServant =
1238 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
1240 // activate the CORBA servant
1241 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
1242 return operations._retn();
1245 //=============================================================================
1249 //=============================================================================
1250 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
1251 const GEOM::ListOfLong& theIndices)
1253 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
1254 return GEOM::GEOM_Object::_nil();
1255 CORBA::String_var entry = theMainShape->GetEntry();
1256 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
1257 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
1259 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
1260 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
1262 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
1263 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
1265 TCollection_AsciiString anEntry;
1266 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
1267 return GetObject(anObject->GetDocID(), anEntry.ToCString());
1270 //=============================================================================
1274 //=============================================================================
1275 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
1277 CORBA::String_var anEntry = theObject->GetEntry();
1278 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry);
1279 if (anObject.IsNull()) return;
1280 _impl->RemoveObject(anObject);
1285 //=================================================================================
1286 // function : GetStringFromIOR()
1287 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
1288 //=================================================================================
1289 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
1290 return _orb->object_to_string(theObject);
1294 //=================================================================================
1295 // function : GetIORFromString()
1296 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
1297 //=================================================================================
1298 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
1299 GEOM::GEOM_Object_var aGeomObject;
1300 if(strcmp(stringIOR,"") != 0){
1301 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
1302 if(!CORBA::is_nil(anObject))
1303 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
1305 return aGeomObject._retn();
1308 //=================================================================================
1309 // function : GetObject()
1311 //=================================================================================
1312 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
1314 GEOM::GEOM_Object_var obj;
1315 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
1316 if (handle_object.IsNull()) return obj._retn();
1318 TCollection_AsciiString stringIOR = handle_object->GetIOR();
1319 if (stringIOR.Length() > 1) {
1320 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
1321 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
1325 GEOM::GEOM_Gen_ptr engine = _this();
1326 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
1328 obj = servant->_this();
1329 CORBA::String_var objStr = _orb->object_to_string(obj);
1330 TCollection_AsciiString anAscii( (char *)objStr.in() );
1331 handle_object->SetIOR( anAscii );
1335 //=================================================================================
1336 // function : hasObjectInfo()
1337 // purpose : shows if module provides information for its objects
1338 //=================================================================================
1339 bool GEOM_Gen_i::hasObjectInfo()
1344 //=================================================================================
1345 // function : getObjectInfo()
1346 // purpose : returns an information for a given object by its entry
1347 //=================================================================================
1348 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
1350 GEOM::GEOM_Object_var aGeomObject;
1352 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
1353 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
1354 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
1355 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
1356 SALOMEDS::SObject_var aResultSObj;
1357 if (aSObj->ReferencedObject(aResultSObj))
1358 aSObj = aResultSObj;
1360 SALOMEDS::GenericAttribute_var anAttr;
1361 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
1362 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1363 CORBA::String_var aVal = anIOR->Value();
1364 CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
1365 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
1368 const char* aTypeInfo = "Object";
1369 if ( !aGeomObject->_is_nil() ) {
1370 GEOM::GEOM_IKindOfShape::shape_kind aKind;
1371 GEOM::ListOfLong_var anInts;
1372 GEOM::ListOfDouble_var aDbls;
1374 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
1375 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
1377 if ( anOp->IsDone() ) {
1379 case GEOM::GEOM_IKindOfShape::COMPOUND:
1380 aTypeInfo = "Compound";
1382 case GEOM::GEOM_IKindOfShape::COMPSOLID:
1383 aTypeInfo = "CompSolid";
1385 case GEOM::GEOM_IKindOfShape::SHELL:
1386 aTypeInfo = "Shell";
1388 case GEOM::GEOM_IKindOfShape::WIRE:
1389 if ( anInts[0] == 1 )
1390 aTypeInfo = "Closed Wire";
1391 else if ( anInts[0] == 2 )
1392 aTypeInfo = "Opened Wire";
1397 case GEOM::GEOM_IKindOfShape::SPHERE:
1398 aTypeInfo = "Sphere";
1400 case GEOM::GEOM_IKindOfShape::CYLINDER:
1401 aTypeInfo = "Cylinder";
1403 case GEOM::GEOM_IKindOfShape::BOX:
1404 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
1407 case GEOM::GEOM_IKindOfShape::TORUS:
1408 aTypeInfo = "Torus";
1410 case GEOM::GEOM_IKindOfShape::CONE:
1413 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
1414 aTypeInfo = "Polyhedron";
1416 case GEOM::GEOM_IKindOfShape::SOLID:
1417 aTypeInfo = "Solid";
1420 case GEOM::GEOM_IKindOfShape::SPHERE2D:
1421 aTypeInfo = "Spherical Face";
1423 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
1424 aTypeInfo = "Cylindrical Face";
1426 case GEOM::GEOM_IKindOfShape::TORUS2D:
1427 aTypeInfo = "Toroidal Face";
1429 case GEOM::GEOM_IKindOfShape::CONE2D:
1430 aTypeInfo = "Conical Face";
1432 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
1435 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
1436 aTypeInfo = "Elliptical Face";
1438 case GEOM::GEOM_IKindOfShape::POLYGON:
1439 aTypeInfo = "Polygon";
1441 case GEOM::GEOM_IKindOfShape::PLANE:
1442 aTypeInfo = "Plane";
1444 case GEOM::GEOM_IKindOfShape::PLANAR:
1445 aTypeInfo = "Planar Face";
1447 case GEOM::GEOM_IKindOfShape::FACE:
1451 case GEOM::GEOM_IKindOfShape::CIRCLE:
1452 aTypeInfo = "Circle";
1454 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
1457 case GEOM::GEOM_IKindOfShape::ELLIPSE:
1458 aTypeInfo = "Ellipse";
1460 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
1461 aTypeInfo = "Arc Ellipse";
1463 case GEOM::GEOM_IKindOfShape::LINE:
1466 case GEOM::GEOM_IKindOfShape::SEGMENT:
1467 aTypeInfo = "Segment";
1469 case GEOM::GEOM_IKindOfShape::EDGE:
1472 case GEOM::GEOM_IKindOfShape::VERTEX:
1473 aTypeInfo = "Vertex";
1481 char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
1482 sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
1484 char* ret = CORBA::string_dup(anInfo);
1489 //=====================================================================================
1491 //=====================================================================================
1495 PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
1496 PortableServer::POA_ptr poa,
1497 PortableServer::ObjectId * contId,
1498 const char *instanceName,
1499 const char * interfaceName)
1501 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
1502 // Don't understand the reason of this register ????
1503 // myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
1504 return myGEOM_Gen_i->getId();