1 // Copyright (C) 2007-2010 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 "GEOM_ISubShape.hxx"
43 #include <GEOM_PythonDump.hxx>
44 #include "GEOMImpl_Types.hxx"
45 #include "GEOMImpl_CopyDriver.hxx"
48 #include <BRep_Builder.hxx>
49 #include <BRepTools.hxx>
50 #include <TDF_Label.hxx>
51 #include <TDF_Tool.hxx>
52 #include <TDF_ChildIDIterator.hxx>
53 #include <TNaming_NamedShape.hxx>
54 #include <TDataStd_Name.hxx>
55 #include <TCollection_AsciiString.hxx>
56 #include <TColStd_HArray1OfInteger.hxx>
57 #include <TopAbs_ShapeEnum.hxx>
58 //#include <TopTools_IndexedMapOfShape.hxx>
62 #include "SALOMEDS_Tool.hxx"
64 //============================================================================
65 // function : GEOM_Gen_i()
66 // purpose : constructor to be called for servant creation.
67 //============================================================================
68 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
69 PortableServer::POA_ptr poa,
70 PortableServer::ObjectId* contId,
71 const char* instanceName,
72 const char* interfaceName) :
73 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
76 _id = _poa->activate_object(_thisObj);
77 name_service = new SALOME_NamingService(_orb);
79 _impl = new ::GEOMImpl_Gen;
81 //PAL10867: disable signals catching with "noexcepthandler" option
82 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
83 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
85 //work around PAL12004, PAL12628
86 //OSD::SetSignal( true );
90 char* envDisableFPE = getenv("DISABLE_FPE");
91 if (envDisableFPE && atoi(envDisableFPE))
96 OSD::SetSignal( raiseFPE );
100 //============================================================================
101 // function : ~GEOM_Gen_i()
102 // purpose : destructor
103 //============================================================================
104 GEOM_Gen_i::~GEOM_Gen_i() {
110 //============================================================================
111 // function : IORToLocalPersistentID()
113 //============================================================================
114 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
115 const char* IORString,
116 CORBA::Boolean isMultiFile,
117 CORBA::Boolean isASCII)
119 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
120 if (!CORBA::is_nil(anObject)) {
121 return CORBA::string_dup(anObject->GetEntry());
127 //============================================================================
128 // function : LocalPersistentIDToIOR()
129 // purpose : Create/Load CORBA object from a persistent ref (an entry)
130 // : Used when a study is loaded
131 // : The IOR (IORName) of object created is returned
132 //============================================================================
133 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
134 const char* aLocalPersistentID,
135 CORBA::Boolean isMultiFile,
136 CORBA::Boolean isASCII)
138 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
140 Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
141 TCollection_AsciiString anEntry;
142 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
143 GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
145 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
146 return CORBA::string_dup(aPersRefString);
149 //============================================================================
150 // function : CanPublishInStudy
152 //============================================================================
153 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
155 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
156 return !(anObject->_is_nil());
160 //============================================================================
161 // function : PublishInStudy
163 //============================================================================
164 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
165 SALOMEDS::SObject_ptr theSObject,
166 CORBA::Object_ptr theObject,
167 const char* theName) throw (SALOME::SALOME_Exception)
169 Unexpect aCatch(SALOME_SalomeException);
170 SALOMEDS::SObject_var aResultSO;
171 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
172 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
173 if(aShape->_is_nil()) return aResultSO;
175 SALOMEDS::GenericAttribute_var anAttr;
176 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
178 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
179 if (aFather->_is_nil()) {
180 aFather = aStudyBuilder->NewComponent("GEOM");
181 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
182 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
183 aName->SetValue("Geometry");
185 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
186 SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr);
187 aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry");
189 aStudyBuilder->DefineComponentInstance(aFather, (GEOM::GEOM_Gen_var)GEOM_Gen::_this());
191 if (aFather->_is_nil()) return aResultSO;
193 if (CORBA::is_nil(theSObject)) {
194 aResultSO = aStudyBuilder->NewObject(aFather);
196 if (!theSObject->ReferencedObject(aResultSO))
197 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
198 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
200 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
201 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
202 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
203 anIOR->SetValue(aGeomObjIOR);
206 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
207 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
208 TCollection_AsciiString aShapeName("Shape_");
210 if ( aShape->GetType() == GEOM_GROUP ) {
211 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
212 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
214 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
215 aShapeName = "Group_Of_Vertices_";
218 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
219 aShapeName = "Group_Of_Edges_";
222 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
223 aShapeName = "Group_Of_Faces_";
226 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
227 aShapeName = "Group_Of_Solids_";
230 } else if ( aShape->GetType() == GEOM_MARKER ) {
231 aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
232 aShapeName = "LocalCS_";
233 } else if ( aShape->GetType() > ADVANCED_BASE ) {
235 sprintf( buf, "%d", aShape->GetType() );
236 std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf;
237 aPixmap->SetPixMap( advId.c_str() );
238 aShapeName = "Advanced_";
239 } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
240 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
241 aShapeName = "Compound_";
242 } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
243 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
244 aShapeName = "Compsolid_";
245 } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
246 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
247 aShapeName = "Solid_";
248 } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
249 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
250 aShapeName = "Shell_";
251 } else if ( aShape->GetShapeType() == GEOM::FACE ) {
252 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
253 aShapeName = "Face_";
254 } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
255 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
256 aShapeName = "Wire_";
257 } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
258 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
259 aShapeName = "Edge_";
260 } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
261 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
262 aShapeName = "Vertex_";
265 //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
266 //else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName));
268 // BEGIN: try to find existed name for current shape
269 bool HasName = false;
270 // recieve current TopoDS shape
271 CORBA::String_var entry = aShape->GetEntry();
272 Handle(GEOM_Object) aGShape = _impl->GetObject(aShape->GetStudyID(), entry);
273 TopoDS_Shape TopoSh = aGShape->GetValue();
274 // find label of main shape
275 GEOM::GEOM_Object_var aMainSh = aShape;
276 while( !aMainSh->IsMainShape() ) {
277 aMainSh = aMainSh->GetMainShape();
279 entry = aMainSh->GetEntry();
280 Handle(GEOM_Object) anObj = _impl->GetObject(aMainSh->GetStudyID(), entry);
281 TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry();
283 // check all named shapes using iterator
284 TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
286 for (; anIt.More() && !HasName; anIt.Next()) {
287 Handle(TNaming_NamedShape) anAttr =
288 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
289 if (anAttr.IsNull()) continue;
290 TopoDS_Shape S = anAttr->Get();
291 if (S.IsEqual(TopoSh)) {
292 TDF_Label L = anAttr->Label();
293 Handle(TDataStd_Name) aName;
294 if (L.FindAttribute(TDataStd_Name::GetID(), aName)) {
295 aShapeName = aName->Get();
300 // END: try to find existed name for current shape
303 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
304 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
305 // of objects in the study, but compute a number of objects with the same prefix
306 // and build a new name as Prefix_N+1
307 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
308 int i = 0; // (WITH EMPTY NEW NAME)
309 SALOMEDS::SObject_var obj;
310 TCollection_AsciiString aNewShapeName;
312 aNewShapeName = aShapeName + TCollection_AsciiString(++i);
313 obj = theStudy->FindObject( aNewShapeName.ToCString() );
315 while ( !obj->_is_nil() );
316 aShapeName = aNewShapeName;
318 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
319 aShapeName = TCollection_AsciiString((char*)theName);
322 //Set the study entry as a name of the published GEOM_Object
323 CORBA::String_var anID =aResultSO->GetID();
324 aShape->SetStudyEntry(anID.in());
326 //Set a name of the added shape
327 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
328 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
329 aNameAttrib->SetValue(aShapeName.ToCString());
330 aNameAttrib->Destroy();
332 //Set NoteBook variables used in the object creation
333 TCollection_AsciiString aVars;
334 CORBA::String_var aString=aShape->GetParameters();
335 SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aString);
336 for(int i = 0, n = aSections->length(); i < n; i++) {
337 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
338 for(int j = 0, m = aListOfVars.length(); j < m; j++) {
339 if(theStudy->IsVariable(aListOfVars[j].in()))
340 aVars += TCollection_AsciiString(aListOfVars[j].in());
347 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeString");
348 SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
349 aStringAttrib->SetValue(aVars.ToCString());
350 aStringAttrib->Destroy();
354 //Set a name of the GEOM object
355 aShape->SetName(theName);
357 return aResultSO._retn();
361 //============================================================================
362 // function : CreateAndPublishGroup
363 // purpose : auxilary for PublishNamedShapesInStudy
364 //============================================================================
365 void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
366 GEOM::GEOM_Object_var theMainShape,
367 const TopTools_IndexedMapOfShape& anIndices,
368 const TopTools_SequenceOfShape& SeqS,
369 const TColStd_SequenceOfAsciiString& SeqN,
370 const Standard_CString& GrName,
371 GEOM::ListOfGO_var aResList)
373 CORBA::String_var entry = theMainShape->GetEntry();
374 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
375 Handle(TColStd_HArray1OfInteger) anArray;
376 if(SeqS.Length()>0) {
378 GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId());
379 GEOM::GEOM_Object_ptr GrObj =
380 GOp->CreateGroup( theMainShape, SeqS.Value(1).ShapeType() );
381 AddInStudy(theStudy, GrObj, GrName, theMainShape._retn());
382 CORBA::String_var GrEntry = GrObj->GetEntry();
383 Handle(GEOM_Object) HGrObj = _impl->GetObject(GrObj->GetStudyID(), GrEntry);
385 //Handle(GEOM_Object) anObj;
386 for(int i=1; i<=SeqS.Length(); i++) {
387 TopoDS_Shape aValue = SeqS.Value(i);
388 //anArray = new TColStd_HArray1OfInteger(1,1);
389 Standard_Integer anIndex = anIndices.FindIndex(aValue);
390 //anArray->SetValue(1, anIndex);
391 GOp->AddObject(GrObj,anIndex);
392 //anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE);
393 //if (anObj.IsNull()) continue;
394 //Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
395 //if (aFunction.IsNull()) continue;
396 //GEOM_ISubShape aSSI(aFunction);
397 //aSSI.SetMainShape(aMainShape->GetLastFunction());
398 //aSSI.SetIndices(anArray);
399 //aFunction->SetValue(aValue);
400 //GOp->UnionIDs(GrObj, anIndex);
401 //SALOMEDS::SObject_var aResultSO;
402 //TCollection_AsciiString anEntry;
403 //TDF_Tool::Entry(anObj->GetEntry(),anEntry);
404 //GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString());
405 //AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
411 //============================================================================
412 // function : PublishNamedShapesInStudy
414 //============================================================================
415 GEOM::ListOfGO* GEOM_Gen_i::
416 PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
417 //SALOMEDS::SObject_ptr theSObject,
418 CORBA::Object_ptr theObject)
420 //Unexpect aCatch(SALOME_SalomeException);
421 GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
423 //CORBA::Object_var theObject = theSObject->GetObject();
424 GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
425 if(theMainShape->_is_nil()) return aResList._retn();
427 CORBA::String_var entry = theMainShape->GetEntry();
428 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
429 if (aMainShape.IsNull()) return aResList._retn();
430 TopoDS_Shape MainSh = aMainShape->GetValue();
432 TDF_Label aMainLbl = aMainShape->GetEntry();
433 TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
434 TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
435 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
436 for(; anIt.More(); anIt.Next()) {
437 Handle(TNaming_NamedShape) anAttr =
438 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
439 if(anAttr.IsNull()) continue;
440 TopoDS_Shape S = anAttr->Get();
441 TDF_Label L = anAttr->Label();
442 //if(S.IsEqual(MainSh)) continue;
443 Handle(TDataStd_Name) aName;
444 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
445 TCollection_ExtendedString EName = aName->Get();
446 if(S.ShapeType()==TopAbs_SOLID) {
448 SolidSeqN.Append(aName->Get());
450 else if(S.ShapeType()==TopAbs_FACE) {
452 FaceSeqN.Append(aName->Get());
454 else if(S.ShapeType()==TopAbs_EDGE) {
456 EdgeSeqN.Append(aName->Get());
458 else if(S.ShapeType()==TopAbs_VERTEX) {
460 VertSeqN.Append(aName->Get());
465 TopTools_IndexedMapOfShape anIndices;
466 TopExp::MapShapes(MainSh, anIndices);
468 CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN,
469 "Group_Of_Named_Solids", aResList);
471 CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN,
472 "Group_Of_Named_Faces", aResList);
474 CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
475 "Group_Of_Named_Edges", aResList);
477 CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN,
478 "Group_Of_Named_Vertices", aResList);
480 return aResList._retn();
484 //============================================================================
486 // purpose : save OCAF/Geom document
487 //============================================================================
488 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
491 SALOMEDS::TMPFile_var aStreamFile;
492 // Get a temporary directory to store a file
493 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
495 // OCCT BUG: cannot save a document (in current folder)
496 // if directory name is empty
497 if (aTmpDir.size() == 0) {
505 // Create a list to store names of created files
506 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
508 // Prepare a file name to open
509 TCollection_AsciiString aNameWithExt("");
511 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
512 (theComponent->GetStudy()->URL())).c_str());
513 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
514 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
515 // Build a full file name of temporary file
516 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
517 // Save GEOM component in this file
518 _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
519 // Conver a file to the byte stream
520 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
521 // Remove the created file and tmp directory
522 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
524 // Return the created byte stream
525 return aStreamFile._retn();
529 //============================================================================
530 // function : SaveASCII()
532 //============================================================================
533 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
536 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
537 return aStreamFile._retn();
541 //============================================================================
544 //============================================================================
545 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
546 const SALOMEDS::TMPFile& theStream,
550 if (theStream.length() <= 9) {
551 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
555 // Get a temporary directory for a file
556 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
558 // OCCT BUG: cannot load a document (from current folder)
559 // if directory name is empty
560 if (aTmpDir.size() == 0) {
568 // Conver the byte stream theStream to a file and place it in tmp directory
569 SALOMEDS::ListOfFileNames_var aSeq =
570 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
572 // Prepare a file name to open
573 TCollection_AsciiString aNameWithExt("");
575 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
576 (theComponent->GetStudy()->URL())).c_str());
577 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
578 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
581 if (!_impl->Load(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString())) return false;
583 // Remove the created file and tmp directory
584 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
586 SALOMEDS::Study_var Study = theComponent->GetStudy();
587 TCollection_AsciiString name (Study->Name());
593 //============================================================================
594 // function : LoadASCII()
596 //============================================================================
597 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
598 const SALOMEDS::TMPFile& theStream,
601 return Load(theComponent, theStream, theURL, isMultiFile);
605 //============================================================================
606 // function : Close()
608 //============================================================================
609 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
611 SALOMEDS::Study_var aStudy= theComponent->GetStudy();
612 _impl->Close(aStudy->StudyId());
615 //============================================================================
616 // function : CanCopy()
618 //============================================================================
619 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
620 // Try to retrieve known by Geometry component GEOM_Object by given IOR
621 SALOMEDS::GenericAttribute_var anAttr;
622 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
624 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
626 CORBA::String_var aString=anIOR->Value();
628 CORBA::Object_var anObj = _orb->string_to_object(aString);
629 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(anObj);
630 // If the object is null one it can't be copied: return false
631 if (anObject->_is_nil()) return false;
635 //============================================================================
636 // function : CopyFrom()
638 //============================================================================
639 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
641 // Declare a sequence of the byte to store the copied object
642 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
644 // Try to get GEOM_Object object by given SObject
645 SALOMEDS::GenericAttribute_var anAttr;
646 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
647 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
648 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
649 if (anObject->_is_nil()) return aStreamFile._retn();
651 aStreamFile = anObject->GetShapeStream();
653 // Assign an ID the type of GEOM_Object
654 theObjectID = anObject->GetType();
656 // Return created TMPFile
657 return aStreamFile._retn();
660 //============================================================================
661 // function : CanPaste()
663 //============================================================================
664 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
665 // The Geometry component can paste only objects copied by Geometry component
666 // and with the object type = 1
667 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
671 //============================================================================
672 // function : PasteInto()
674 //============================================================================
675 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
676 CORBA::Long theObjectID,
677 SALOMEDS::SObject_ptr theObject) {
678 // Find the current Study and StudyBuilder
679 SALOMEDS::Study_var aStudy = theObject->GetStudy();
680 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
682 // Retrieve a TopoDS_Shape from byte stream
683 TopoDS_Shape aTopology;
684 std::istringstream aStreamedBrep((char*) &theStream[0]);
685 BRep_Builder aBuilder;
687 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
688 } catch (Standard_Failure) {
692 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
693 SALOMEDS::SObject_var aNewSO;
694 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
695 aNewSO = aStudyBuilder->NewObject(theObject);
696 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
699 //Create a new GEOM_Object
700 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
701 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
702 aFunction->SetValue(aTopology);
704 TCollection_AsciiString anEntry;
705 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
706 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
708 //Set the study entry of the published GEOM_Object
709 obj->SetStudyEntry(aNewSO->GetID());
711 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
712 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
713 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
714 CORBA::String_var objStr = _orb->object_to_string(obj);
715 anIOR->SetValue(objStr.in());
718 // Return the created in the Study SObject
719 return aNewSO._retn();
722 //============================================================================
723 // function : ComponentDataType()
725 //============================================================================
726 char* GEOM_Gen_i::ComponentDataType()
728 return CORBA::string_dup("GEOM");
731 //============================================================================
732 // function : AddInStudy
734 //============================================================================
735 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
736 GEOM::GEOM_Object_ptr theObject,
738 GEOM::GEOM_Object_ptr theFather)
740 SALOMEDS::SObject_var aResultSO;
741 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
743 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
744 CORBA::String_var IOR;
746 if(!theFather->_is_nil()) {
747 IOR = _orb->object_to_string(theFather);
748 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in());
749 if(aFatherSO->_is_nil()) return aResultSO._retn();
750 aResultSO = aStudyBuilder->NewObject(aFatherSO);
751 aFatherSO->Destroy();
752 //aStudyBuilder->Addreference(aResultSO, aResultSO);
755 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
756 if(aResultSO->_is_nil()) return aResultSO._retn();
758 GEOM::ListOfGO_var aList = theObject->GetDependency();
759 Standard_Integer aLength = aList->length();
760 if(aLength < 1) return aResultSO._retn();
762 //Publish the arguments
763 for(Standard_Integer i = 0; i< aLength; i++) {
764 GEOM::GEOM_Object_var anObject = aList[i];
765 if(anObject->_is_nil()) continue;
766 IOR = _orb->object_to_string(anObject);
767 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR.in());
768 if(aSO->_is_nil()) continue;
769 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
770 aStudyBuilder->Addreference(aSubSO, aSO);
775 return aResultSO._retn();
778 //============================================================================
779 // function : RestoreSubShapesO
780 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
781 // To be used from python scripts out of geompy.addToStudy (non-default usage)
782 //============================================================================
783 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
784 GEOM::GEOM_Object_ptr theObject,
785 const GEOM::ListOfGO& theArgs,
786 GEOM::find_shape_method theFindMethod,
787 CORBA::Boolean theInheritFirstArg,
788 CORBA::Boolean theAddPrefix)
790 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
791 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
792 return aParts._retn();
794 // find SObject in the study if it is already published
795 CORBA::String_var anIORo = _orb->object_to_string(theObject);
796 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
797 //PTv, IMP 0020001, The salome object <aSO>
798 // is not obligatory in case of invokation from script
799 // if (CORBA::is_nil(aSO))
800 // return aParts._retn();
802 aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs,
803 theFindMethod, theInheritFirstArg, theAddPrefix);
804 if (!CORBA::is_nil(aSO)) aSO->Destroy();
805 return aParts._retn();
808 //============================================================================
809 // function : RestoreGivenSubShapesO
810 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
811 // To be used from python scripts, generated by Dump Python.
812 //============================================================================
813 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (SALOMEDS::Study_ptr theStudy,
814 GEOM::GEOM_Object_ptr theObject,
815 const GEOM::ListOfGO& theArgs,
816 GEOM::find_shape_method theFindMethod,
817 CORBA::Boolean theInheritFirstArg,
818 CORBA::Boolean theAddPrefix)
820 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
821 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
822 return aParts._retn();
824 // find SObject in the study if it is already published
825 CORBA::String_var anIORo = _orb->object_to_string(theObject);
826 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
827 //PTv, IMP 0020001, The salome object <aSO>
828 // is not obligatory in case of invokation from script
829 // if (CORBA::is_nil(aSO))
830 // return aParts._retn();
832 aParts = RestoreGivenSubShapes(theStudy, theObject, aSO, theArgs,
833 theFindMethod, theInheritFirstArg, theAddPrefix);
834 if (!CORBA::is_nil(aSO)) aSO->Destroy();
835 return aParts._retn();
838 //============================================================================
839 // function : RestoreSubShapesSO
840 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
841 // To be used from GUI and from geompy.addToStudy
842 //============================================================================
843 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
844 SALOMEDS::SObject_ptr theSObject,
845 const GEOM::ListOfGO& theArgs,
846 GEOM::find_shape_method theFindMethod,
847 CORBA::Boolean theInheritFirstArg,
848 CORBA::Boolean theAddPrefix)
850 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
851 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
852 return aParts._retn();
854 SALOMEDS::GenericAttribute_var anAttr;
855 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
856 return aParts._retn();
858 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
859 CORBA::String_var anIORso = anAttrIOR->Value();
861 // get Object from SObject
862 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
863 if (CORBA::is_nil(anO))
864 return aParts._retn();
866 aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs,
867 theFindMethod, theInheritFirstArg, theAddPrefix);
868 return aParts._retn();
871 //============================================================================
872 // function : addToListOfGO
873 // purpose : static local function
874 //============================================================================
875 static void addToListOfGO( GEOM::GEOM_Object_ptr theObject,
876 GEOM::ListOfGO& theList )
878 const int oldLen = theList.length();
879 theList.length(oldLen + 1);
880 theList[ oldLen ] = GEOM::GEOM_Object::_duplicate( theObject );
883 //============================================================================
884 // function : addToListOfGO
885 // purpose : static local function
886 //============================================================================
887 static void addToListOfGO( const GEOM::ListOfGO& theSrcList,
888 GEOM::ListOfGO& theTrgList )
890 const int oldLen = theTrgList.length();
891 const int srcLen = theSrcList.length();
892 theTrgList.length(oldLen + srcLen);
893 for( int i = 0; i < srcLen; i++ )
894 theTrgList[ oldLen + i ] = GEOM::GEOM_Object::_duplicate( theSrcList[ i ] );
897 //============================================================================
898 // function : RestoreSubShapes
899 // purpose : Private method. Works only if both theObject and theSObject
900 // are defined, and does not check, if they correspond to each other.
901 //============================================================================
902 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy,
903 GEOM::GEOM_Object_ptr theObject,
904 SALOMEDS::SObject_ptr theSObject,
905 const GEOM::ListOfGO& theArgs,
906 GEOM::find_shape_method theFindMethod,
907 CORBA::Boolean theInheritFirstArg,
908 CORBA::Boolean theAddPrefix)
910 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
911 //PTv, IMP 0020001, The salome object <theSObject>
912 // is not obligatory in case of invokation from script
913 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
914 return aParts._retn();
916 // For Dump Python (mantis issue 0020768)
917 GEOM::ListOfGO_var anOutArgs = new GEOM::ListOfGO;
919 // Arguments to be published
920 GEOM::ListOfGO_var aList;
922 // If theArgs list is empty, we try to publish all arguments,
923 // otherwise publish only passed args
924 Standard_Integer nbArgsActual = -1; // -1 means unknown
925 Standard_Integer aLength = theArgs.length();
927 aList = new GEOM::ListOfGO;
928 aList->length(aLength);
929 for (int i = 0; i < aLength; i++) {
930 aList[i] = GEOM::GEOM_Object::_duplicate( theArgs[i] );
935 aList = theObject->GetDependency();
936 aLength = aList->length();
937 nbArgsActual = aLength;
941 return aParts._retn();
943 if (theInheritFirstArg || (nbArgsActual == 1)) {
944 // Do not publish argument's reflection,
945 // but only reconstruct its published sub-shapes
947 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
948 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
950 // remember restored objects for Python Dump
951 addToListOfGO(aList[0], anOutArgs);
953 aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
954 anOutArgs, theFindMethod, theAddPrefix);
956 // set the color of the transformed shape to the color of initial shape
957 theObject->SetColor(aList[0]->GetColor());
959 if (theObject->GetShapeType() == GEOM::VERTEX) {
960 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
961 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
962 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
968 // Get interface, containing method, which we will use to reconstruct sub-shapes
969 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
970 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
971 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
973 // Reconstruct arguments and tree of sub-shapes of the arguments
974 CORBA::String_var anIOR;
975 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
976 for (Standard_Integer i = 0; i < aLength; i++)
978 GEOM::GEOM_Object_var anArgO = aList[i];
979 if (!CORBA::is_nil(anArgO)) {
980 anIOR = _orb->object_to_string(anArgO);
981 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
982 TCollection_AsciiString anArgName;
983 if (CORBA::is_nil(anArgSO)) {
985 anArgName += TCollection_AsciiString(i);
988 anArgName = anArgSO->GetName();
991 // Find a sub-shape of theObject in place of the argument
992 GEOM::GEOM_Object_var aSubO;
993 switch (theFindMethod) {
994 case GEOM::FSM_GetInPlace:
997 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1000 case GEOM::FSM_MultiTransformed:
1002 // Only for Multi-transformations
1003 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anArgO, theObject);
1004 if (!CORBA::is_nil(anArgOTrsf)) {
1005 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1006 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1007 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1008 anArgOTrsfFun->SetDescription("");
1009 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1012 Handle(GEOM_Function) anOFun = theObject->GetLastFunction();
1013 if (!anOFun.IsNull()) {
1014 CORBA::String_var entryArg = anArgO->GetEntry();
1015 Handle(GEOM_Object) anArgOImpl = _impl->GetObject(anArgO->GetStudyID(), entryArg);
1016 if (!anArgOImpl.IsNull()) {
1017 TopoDS_Shape anArgOShape = anArgOImpl->GetValue();
1018 TopoDS_Shape aMultiArgShape;
1019 //GEOM::GEOM_Object_var anArgOMulti; // ???
1020 switch (anOFun->GetType()) {
1023 GEOMImpl_ITranslate aTI (anOFun);
1024 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape1D(anArgOShape, &aTI);
1025 //anArgOMulti = aTrsfOp->Translate1D(anArgO, , , );
1030 GEOMImpl_ITranslate aTI (anOFun);
1031 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1036 GEOMImpl_IRotate aTI (anOFun);
1037 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1042 GEOMImpl_IRotate aTI (anOFun);
1043 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1049 GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO
1050 Handle(GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction();
1051 anArgOMultiFun->SetDescription("");
1052 aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti);
1058 case GEOM::FSM_Transformed:
1060 // transformation, cannot use GetInPlace, operate with indices
1061 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1062 if (anIDs->length() > 1) {
1064 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1065 if (!CORBA::is_nil(aSubO))
1066 aGroupOp->UnionIDs(aSubO, anIDs);
1068 else if (anIDs->length() > 0) {
1070 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1074 case GEOM::FSM_GetSame:
1077 aSubO = aShapesOp->GetSame(theObject, anArgO);
1080 case GEOM::FSM_GetShapesOnShape:
1082 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1083 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1084 (short)GEOM::SOLID, GEOM::ST_ONIN);
1087 case GEOM::FSM_GetInPlaceByHistory:
1089 // Use GetInPlaceByHistory
1090 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1097 if (!CORBA::is_nil(aSubO)) {
1098 // remember restored objects for Python Dump
1099 addToListOfGO(anArgO, anOutArgs);
1101 // add to parts list
1102 addToListOfGO( aSubO, aParts );
1104 // Publish the sub-shape
1105 SALOMEDS::SObject_var aSubSO;
1106 if (!CORBA::is_nil(theSObject)) {
1107 TCollection_AsciiString aSubName;
1111 aSubName += anArgName;
1112 aSubSO = aStudyBuilder->NewObject(theSObject);
1113 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1115 aSubO->SetColor(anArgO->GetColor());
1117 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1118 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1119 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1120 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1124 if (!CORBA::is_nil(anArgSO)) {
1125 // Restore published sub-shapes of the argument
1126 GEOM::ListOfGO_var aSubParts;
1127 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1128 // pass theObject, because only it has the history
1129 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1130 theObject, anOutArgs, theFindMethod, theAddPrefix);
1132 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1133 aSubO, anOutArgs, theFindMethod, theAddPrefix);
1134 // add to parts list
1135 addToListOfGO( aSubParts, aParts );
1138 else { // GetInPlace failed, try to build from published parts
1139 if (!CORBA::is_nil(anArgSO)) {
1140 SALOMEDS::SObject_var aSubSO;
1141 if (!CORBA::is_nil(theSObject))
1142 aSubSO = aStudyBuilder->NewObject(theSObject);
1144 // Restore published sub-shapes of the argument
1145 GEOM::ListOfGO_var aSubParts =
1146 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1147 theObject, anOutArgs, theFindMethod, theAddPrefix);
1149 // add to parts list
1150 addToListOfGO( aSubParts, aParts );
1152 if (aSubParts->length() > 0) {
1153 // remember restored objects for Python Dump
1154 addToListOfGO(anArgO, anOutArgs);
1156 // try to build an argument from a set of its sub-shapes,
1157 // that published and will be reconstructed
1158 if (aSubParts->length() > 1) {
1159 aSubO = aShapesOp->MakeCompound(aSubParts);
1160 // add to parts list
1161 addToListOfGO( aSubO, aParts );
1164 aSubO = aSubParts[0];
1166 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1167 // Publish the sub-shape
1168 TCollection_AsciiString aSubName;
1170 aSubName = "from_parts_of_";
1172 aSubName += anArgName;
1173 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1175 aSubO->SetColor(anArgO->GetColor());
1177 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1178 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1179 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1180 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1184 else if (!CORBA::is_nil(aSubSO)) {
1185 // remove created aSubSO, because no parts have been found
1186 aStudyBuilder->RemoveObject(aSubSO);
1189 } // try to build from published parts
1192 } // process arguments
1194 std::set<std::string> anObjEntryMap;
1195 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1197 int nb = aParts->length();
1198 aResParts->length(nb);
1201 Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1202 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1203 GEOM::TPythonDump pd (aFunction, true);
1206 for ( ; i < nb; i++ )
1208 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1209 if (CORBA::is_nil(anObj))
1211 char* anEntry = anObj->GetEntry();
1212 if (anObjEntryMap.count(anEntry))
1213 continue; // already treated
1214 anObjEntryMap.insert(anEntry);
1215 aResParts[nbRes++] = anObj;
1216 // clear python dump of object
1217 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1218 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1219 if ( !anObjFun.IsNull() )
1220 anObjFun->SetDescription( "" );
1226 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1227 //i = 0; nb = theArgs.length(); j = 0;
1228 i = 0; nb = anOutArgs->length(); j = 0;
1229 for ( ; i < nb; i++ )
1231 //GEOM::GEOM_Object_var anObj = theArgs[ i ];
1232 GEOM::GEOM_Object_var anObj = anOutArgs[ i ];
1233 if (CORBA::is_nil(anObj))
1235 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1241 pd <<"]" << ", " <<"geompy.GEOM.";
1242 switch (theFindMethod) {
1243 case GEOM::FSM_GetInPlace:
1244 pd << "FSM_GetInPlace"; break;
1245 case GEOM::FSM_MultiTransformed:
1246 pd << "FSM_MultiTransformed"; break;
1247 case GEOM::FSM_Transformed:
1248 pd << "FSM_Transformed"; break;
1249 case GEOM::FSM_GetSame:
1250 pd << "FSM_GetSame"; break;
1251 case GEOM::FSM_GetShapesOnShape:
1252 pd << "FSM_GetShapesOnShape"; break;
1253 case GEOM::FSM_GetInPlaceByHistory:
1255 pd << "FSM_GetInPlaceByHistory"; break;
1257 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1259 aResParts->length(nbRes);
1260 return aResParts._retn();
1263 //============================================================================
1264 // function : RestoreSubShapesOneLevel
1265 // purpose : Private method
1266 //============================================================================
1267 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1268 SALOMEDS::SObject_ptr theOldSO,
1269 SALOMEDS::SObject_ptr theNewSO,
1270 GEOM::GEOM_Object_ptr theNewO,
1271 GEOM::ListOfGO& theOutArgs,
1272 GEOM::find_shape_method theFindMethod,
1273 CORBA::Boolean theAddPrefix)
1276 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1277 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1278 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1279 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1280 return aParts._retn();
1282 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1284 // Get interface, containing method, which we will use to reconstruct sub-shapes
1285 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1286 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1287 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1289 // Reconstruct published sub-shapes
1290 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1293 for (it->Init(); it->More(); it->Next()) {
1296 aParts->length(aLen);
1298 for (it->Init(); it->More(); it->Next()) {
1299 SALOMEDS::SObject_var anOldSubSO = it->Value();
1301 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1303 SALOMEDS::GenericAttribute_var anAttr;
1304 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1305 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1306 GEOM::GEOM_Object_var anOldSubO =
1307 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1308 if (!CORBA::is_nil(anOldSubO)) {
1309 // Find a sub-shape of theNewO in place of anOldSubO
1310 GEOM::GEOM_Object_var aNewSubO;
1311 switch (theFindMethod) {
1312 case GEOM::FSM_GetInPlace:
1315 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1318 case GEOM::FSM_MultiTransformed:
1320 // Only for Multi-transformations
1321 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anOldSubO, theNewO);
1322 if (!CORBA::is_nil(anArgOTrsf)) {
1323 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1324 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1325 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1326 anArgOTrsfFun->SetDescription("");
1327 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1331 case GEOM::FSM_Transformed:
1333 // transformation, cannot use GetInPlace, operate with indices
1334 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1335 if (anIDs->length() > 1) {
1337 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1338 if (!CORBA::is_nil(aNewSubO))
1339 aGroupOp->UnionIDs(aNewSubO, anIDs);
1343 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1347 case GEOM::FSM_GetSame:
1350 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1353 case GEOM::FSM_GetShapesOnShape:
1355 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1356 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1357 (short)GEOM::SOLID, GEOM::ST_ONIN);
1360 case GEOM::FSM_GetInPlaceByHistory:
1362 // Use GetInPlaceByHistory
1363 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1370 if (!CORBA::is_nil(aNewSubO)) {
1371 // remember restored objects for Python Dump
1372 addToListOfGO(anOldSubO, theOutArgs);
1374 // add the part to the list
1375 aParts[i] = aNewSubO;
1377 // add to parts list
1378 addToListOfGO( aNewSubO, aNewParts );
1380 SALOMEDS::SObject_var aNewSubSO;
1381 if (!CORBA::is_nil(theNewSO)) {
1382 // Publish the sub-shape
1383 TCollection_AsciiString aSubName;
1387 aSubName += anArgName;
1388 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1389 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1391 aNewSubO->SetColor(anOldSubO->GetColor());
1393 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1394 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1395 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1396 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1399 // Restore published sub-shapes of the argument
1400 GEOM::ListOfGO_var aSubParts;
1401 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1402 // pass the main shape as Object, because only it has the history
1403 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1404 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1406 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1407 aNewSubO, theOutArgs, theFindMethod, theAddPrefix);
1408 // add to parts list
1409 addToListOfGO( aSubParts, aNewParts );
1411 else { // GetInPlace failed, try to build from published parts
1412 SALOMEDS::SObject_var aNewSubSO;
1413 if (!CORBA::is_nil(theNewSO))
1414 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1416 // Restore published sub-shapes of the argument
1417 GEOM::ListOfGO_var aSubParts =
1418 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1419 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1420 // add to parts list
1421 addToListOfGO( aSubParts, aNewParts );
1423 if (aSubParts->length() > 0) {
1424 // remember restored objects for Python Dump
1425 addToListOfGO(anOldSubO, theOutArgs);
1427 // try to build an object from a set of its sub-shapes,
1428 // that published and will be reconstructed
1429 if (aSubParts->length() > 1) {
1430 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1431 // add to parts list
1432 addToListOfGO( aNewSubO, aNewParts );
1435 aNewSubO = aSubParts[0];
1438 if (!CORBA::is_nil(aNewSubO)) {
1439 // add the part to the list
1440 aSubParts[i] = aNewSubO;
1443 // Publish the sub-shape
1444 if (!CORBA::is_nil(aNewSubSO)) {
1445 TCollection_AsciiString aSubName;
1447 aSubName = "from_parts_of_";
1449 aSubName += anArgName;
1450 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1452 aNewSubO->SetColor(anOldSubO->GetColor());
1454 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1455 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1456 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1457 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1462 else if (!CORBA::is_nil(aNewSubSO)) {
1463 // remove created aSubSO, because no parts have been found
1464 aStudyBuilder->RemoveObject(aNewSubSO);
1466 } // try to build from published parts
1469 } // iterate on published sub-shapes
1472 // add to parts list
1473 addToListOfGO( aNewParts, aParts );
1474 return aParts._retn();
1477 //============================================================================
1478 // function : RestoreGivenSubShapes
1479 // purpose : Private method. Works only if both theObject and theSObject
1480 // are defined, and does not check, if they correspond to each other.
1481 // List theArgs in this case contains not only operation arguments,
1482 // but also all subshapes, which must be published.
1483 //============================================================================
1484 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStudy,
1485 GEOM::GEOM_Object_ptr theObject,
1486 SALOMEDS::SObject_ptr theSObject,
1487 const GEOM::ListOfGO& theArgs,
1488 GEOM::find_shape_method theFindMethod,
1489 CORBA::Boolean theInheritFirstArg,
1490 CORBA::Boolean theAddPrefix)
1492 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1493 //PTv, IMP 0020001, The salome object <theSObject>
1494 // is not obligatory in case of invokation from script
1495 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
1496 return aParts._retn();
1498 // If theArgs list is empty, nothing to do
1499 Standard_Integer aLength = theArgs.length();
1501 return aParts._retn();
1503 // Get all arguments
1504 GEOM::ListOfGO_var anOpArgsList = theObject->GetDependency();
1505 Standard_Integer nbArgsActual = anOpArgsList->length();
1507 // If anOpArgsList list is empty, nothing to do
1508 if (nbArgsActual == 0)
1509 return aParts._retn();
1511 // Entries of arguments and subshapes
1512 std::set<std::string> anArgs;
1513 for (int i = 0; i < aLength; i++) {
1514 CORBA::String_var anEntry = theArgs[i]->GetEntry();
1515 anArgs.insert(anEntry.in());
1518 // Arguments to be published
1519 // We try to publish all arguments, that are in theArgs list
1520 GEOM::ListOfGO_var aList = new GEOM::ListOfGO;
1521 aList->length(nbArgsActual);
1524 for (int j = 0; j < nbArgsActual; j++) {
1525 CORBA::String_var anEntry = anOpArgsList[j]->GetEntry();
1526 if (anArgs.count(anEntry.in())) {
1527 aList[k] = GEOM::GEOM_Object::_duplicate(anOpArgsList[j]);
1532 //aList->length(nbArgsActual);
1534 if (nbArgsActual < 1)
1535 return aParts._retn();
1537 if (theInheritFirstArg || (nbArgsActual == 1)) {
1538 // Do not publish argument's reflection,
1539 // but only reconstruct its published sub-shapes
1541 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1542 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1544 aParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
1545 anArgs, theFindMethod, theAddPrefix);
1547 // set the color of the transformed shape to the color of initial shape
1548 theObject->SetColor(aList[0]->GetColor());
1550 if (theObject->GetShapeType() == GEOM::VERTEX) {
1551 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1552 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1553 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1559 // Get interface, containing method, which we will use to reconstruct sub-shapes
1560 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1561 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1562 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1564 // Reconstruct arguments and tree of sub-shapes of the arguments
1565 CORBA::String_var anIOR;
1566 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1567 for (Standard_Integer i = 0; i < nbArgsActual; i++)
1569 GEOM::GEOM_Object_var anArgO = aList[i];
1570 if (!CORBA::is_nil(anArgO)) {
1571 anIOR = _orb->object_to_string(anArgO);
1572 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1573 TCollection_AsciiString anArgName;
1574 if (CORBA::is_nil(anArgSO)) {
1576 anArgName += TCollection_AsciiString(i);
1579 anArgName = anArgSO->GetName();
1582 // Find a sub-shape of theObject in place of the argument
1583 GEOM::GEOM_Object_var aSubO;
1584 switch (theFindMethod) {
1585 case GEOM::FSM_GetInPlace:
1588 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1591 case GEOM::FSM_MultiTransformed:
1593 // Only for Multi-transformations
1594 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anArgO, theObject);
1595 if (!CORBA::is_nil(anArgOTrsf)) {
1596 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1597 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1598 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1599 anArgOTrsfFun->SetDescription("");
1600 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1604 case GEOM::FSM_Transformed:
1606 // transformation, cannot use GetInPlace, operate with indices
1607 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1608 if (anIDs->length() > 1) {
1610 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1611 if (!CORBA::is_nil(aSubO))
1612 aGroupOp->UnionIDs(aSubO, anIDs);
1614 else if (anIDs->length() > 0) {
1616 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1620 case GEOM::FSM_GetSame:
1623 aSubO = aShapesOp->GetSame(theObject, anArgO);
1626 case GEOM::FSM_GetShapesOnShape:
1628 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1629 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1630 (short)GEOM::SOLID, GEOM::ST_ONIN);
1633 case GEOM::FSM_GetInPlaceByHistory:
1635 // Use GetInPlaceByHistory
1636 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1643 if (!CORBA::is_nil(aSubO)) {
1644 // add to parts list
1645 addToListOfGO( aSubO, aParts );
1647 // Publish the sub-shape
1648 SALOMEDS::SObject_var aSubSO;
1649 if (!CORBA::is_nil(theSObject)) {
1650 TCollection_AsciiString aSubName;
1654 aSubName += anArgName;
1655 aSubSO = aStudyBuilder->NewObject(theSObject);
1656 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1658 aSubO->SetColor(anArgO->GetColor());
1660 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1661 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1662 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1663 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1667 if (!CORBA::is_nil(anArgSO)) {
1668 // Restore published sub-shapes of the argument
1669 GEOM::ListOfGO_var aSubParts;
1670 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1671 // pass theObject, because only it has the history
1672 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1673 theObject, anArgs, theFindMethod, theAddPrefix);
1675 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1676 aSubO, anArgs, theFindMethod, theAddPrefix);
1677 // add to parts list
1678 addToListOfGO( aSubParts, aParts );
1681 else { // GetInPlace failed, try to build from published parts
1682 if (!CORBA::is_nil(anArgSO)) {
1683 SALOMEDS::SObject_var aSubSO;
1684 if (!CORBA::is_nil(theSObject))
1685 aSubSO = aStudyBuilder->NewObject(theSObject);
1687 // Restore published sub-shapes of the argument
1688 GEOM::ListOfGO_var aSubParts =
1689 RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1690 theObject, anArgs, theFindMethod, theAddPrefix);
1692 // add to parts list
1693 addToListOfGO( aSubParts, aParts );
1695 if (aSubParts->length() > 0) {
1696 // try to build an argument from a set of its sub-shapes,
1697 // that published and will be reconstructed
1698 if (aSubParts->length() > 1) {
1699 aSubO = aShapesOp->MakeCompound(aSubParts);
1700 // add to parts list
1701 addToListOfGO( aSubO, aParts );
1704 aSubO = aSubParts[0];
1706 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1707 // Publish the sub-shape
1708 TCollection_AsciiString aSubName;
1710 aSubName = "from_parts_of_";
1712 aSubName += anArgName;
1713 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1715 aSubO->SetColor(anArgO->GetColor());
1717 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1718 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1719 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1720 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1724 else if (!CORBA::is_nil(aSubSO)) {
1725 // remove created aSubSO, because no parts have been found
1726 aStudyBuilder->RemoveObject(aSubSO);
1729 } // try to build from published parts
1732 } // process arguments
1734 std::set<std::string> anObjEntryMap;
1735 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1737 int nb = aParts->length();
1738 aResParts->length(nb);
1741 Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1742 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1743 GEOM::TPythonDump pd (aFunction, true);
1746 for ( ; i < nb; i++ )
1748 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1749 if (CORBA::is_nil(anObj))
1751 char* anEntry = anObj->GetEntry();
1752 if (anObjEntryMap.count(anEntry))
1753 continue; // already treated
1754 anObjEntryMap.insert(anEntry);
1755 aResParts[nbRes++] = anObj;
1756 // clear python dump of object
1757 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1758 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1759 if ( !anObjFun.IsNull() )
1760 anObjFun->SetDescription( "" );
1766 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1767 i = 0; nb = theArgs.length(); j = 0;
1768 for ( ; i < nb; i++ )
1770 GEOM::GEOM_Object_var anObj = theArgs[ i ];
1771 if (CORBA::is_nil(anObj))
1773 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1779 pd <<"]" << ", " <<"geompy.GEOM.";
1780 switch (theFindMethod) {
1781 case GEOM::FSM_GetInPlace:
1782 pd << "FSM_GetInPlace"; break;
1783 case GEOM::FSM_MultiTransformed:
1784 pd << "FSM_MultiTransformed"; break;
1785 case GEOM::FSM_Transformed:
1786 pd << "FSM_Transformed"; break;
1787 case GEOM::FSM_GetSame:
1788 pd << "FSM_GetSame"; break;
1789 case GEOM::FSM_GetShapesOnShape:
1790 pd << "FSM_GetShapesOnShape"; break;
1791 case GEOM::FSM_GetInPlaceByHistory:
1793 pd << "FSM_GetInPlaceByHistory"; break;
1795 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1797 aResParts->length(nbRes);
1798 return aResParts._retn();
1801 //============================================================================
1802 // function : RestoreGivenSubShapesOneLevel
1803 // purpose : Private method
1804 //============================================================================
1805 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1806 SALOMEDS::SObject_ptr theOldSO,
1807 SALOMEDS::SObject_ptr theNewSO,
1808 GEOM::GEOM_Object_ptr theNewO,
1809 std::set<std::string> theArgs,
1810 GEOM::find_shape_method theFindMethod,
1811 CORBA::Boolean theAddPrefix)
1814 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1815 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1816 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1817 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1818 return aParts._retn();
1820 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1822 // Get interface, containing method, which we will use to reconstruct sub-shapes
1823 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1824 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1825 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1827 // Reconstruct published sub-shapes
1828 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1831 for (it->Init(); it->More(); it->Next()) {
1834 aParts->length(aLen);
1836 for (it->Init(); it->More(); it->Next()) {
1837 SALOMEDS::SObject_var anOldSubSO = it->Value();
1839 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1841 SALOMEDS::GenericAttribute_var anAttr;
1842 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1843 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1844 GEOM::GEOM_Object_var anOldSubO =
1845 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1847 bool okToContinue = false;
1849 if (!CORBA::is_nil(anOldSubO)) {
1850 CORBA::String_var anEntry = anOldSubO->GetEntry();
1851 okToContinue = theArgs.count(anEntry.in());
1855 // Find a sub-shape of theNewO in place of anOldSubO
1856 GEOM::GEOM_Object_var aNewSubO;
1857 switch (theFindMethod) {
1858 case GEOM::FSM_GetInPlace:
1861 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1864 case GEOM::FSM_MultiTransformed:
1866 // Only for Multi-transformations
1867 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anOldSubO, theNewO);
1868 if (!CORBA::is_nil(anArgOTrsf)) {
1869 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1870 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1871 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1872 anArgOTrsfFun->SetDescription("");
1873 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1877 case GEOM::FSM_Transformed:
1879 // transformation, cannot use GetInPlace, operate with indices
1880 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1881 if (anIDs->length() > 1) {
1883 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1884 if (!CORBA::is_nil(aNewSubO))
1885 aGroupOp->UnionIDs(aNewSubO, anIDs);
1889 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1893 case GEOM::FSM_GetSame:
1896 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1899 case GEOM::FSM_GetShapesOnShape:
1901 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1902 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1903 (short)GEOM::SOLID, GEOM::ST_ONIN);
1906 case GEOM::FSM_GetInPlaceByHistory:
1908 // Use GetInPlaceByHistory
1909 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1916 if (!CORBA::is_nil(aNewSubO)) {
1917 // add the part to the list
1918 aParts[i] = aNewSubO;
1920 // add to parts list
1921 addToListOfGO( aNewSubO, aNewParts );
1923 SALOMEDS::SObject_var aNewSubSO;
1924 if (!CORBA::is_nil(theNewSO)) {
1925 // Publish the sub-shape
1926 TCollection_AsciiString aSubName;
1930 aSubName += anArgName;
1931 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1932 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1934 aNewSubO->SetColor(anOldSubO->GetColor());
1936 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1937 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1938 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1939 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1942 // Restore published sub-shapes of the argument
1943 GEOM::ListOfGO_var aSubParts;
1944 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1945 // pass the main shape as Object, because only it has the history
1946 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1947 theNewO, theArgs, theFindMethod, theAddPrefix);
1949 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1950 aNewSubO, theArgs, theFindMethod, theAddPrefix);
1951 // add to parts list
1952 addToListOfGO( aSubParts, aNewParts );
1954 else { // GetInPlace failed, try to build from published parts
1955 SALOMEDS::SObject_var aNewSubSO;
1956 if (!CORBA::is_nil(theNewSO))
1957 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1959 // Restore published sub-shapes of the argument
1960 GEOM::ListOfGO_var aSubParts =
1961 RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1962 theNewO, theArgs, theFindMethod, theAddPrefix);
1963 // add to parts list
1964 addToListOfGO( aSubParts, aNewParts );
1966 if (aSubParts->length() > 0) {
1967 // try to build an object from a set of its sub-shapes,
1968 // that published and will be reconstructed
1969 if (aSubParts->length() > 1) {
1970 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1971 // add to parts list
1972 addToListOfGO( aNewSubO, aNewParts );
1975 aNewSubO = aSubParts[0];
1978 if (!CORBA::is_nil(aNewSubO)) {
1979 // add the part to the list
1980 aSubParts[i] = aNewSubO;
1983 // Publish the sub-shape
1984 if (!CORBA::is_nil(aNewSubSO)) {
1985 TCollection_AsciiString aSubName;
1987 aSubName = "from_parts_of_";
1989 aSubName += anArgName;
1990 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1992 aNewSubO->SetColor(anOldSubO->GetColor());
1994 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1995 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1996 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1997 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2002 else if (!CORBA::is_nil(aNewSubSO)) {
2003 // remove created aSubSO, because no parts have been found
2004 aStudyBuilder->RemoveObject(aNewSubSO);
2006 } // try to build from published parts
2009 } // iterate on published sub-shapes
2012 // add to parts list
2013 addToListOfGO( aNewParts, aParts );
2014 return aParts._retn();
2017 //============================================================================
2018 // function : register()
2019 // purpose : register 'name' in 'name_service'
2020 //============================================================================
2021 void GEOM_Gen_i::register_name(char * name)
2023 GEOM::GEOM_Gen_var g = _this();
2024 name_service->Register(g, name);
2027 //============================================================================
2030 //============================================================================
2031 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
2033 _impl->Undo(theStudyID);
2036 //============================================================================
2039 //============================================================================
2040 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
2042 _impl->Redo(theStudyID);
2045 //============================================================================
2046 // function : GetIBasicOperations
2048 //============================================================================
2049 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
2050 throw ( SALOME::SALOME_Exception )
2052 Unexpect aCatch(SALOME_SalomeException);
2053 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
2055 GEOM::GEOM_Gen_ptr engine = _this();
2057 //transfer reference on engine
2058 GEOM_IBasicOperations_i* aServant =
2059 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
2061 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2062 // activate the CORBA servant
2063 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
2064 return operations._retn();
2067 //============================================================================
2068 // function : GetITransformOperations
2070 //============================================================================
2071 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
2072 throw ( SALOME::SALOME_Exception )
2074 Unexpect aCatch(SALOME_SalomeException);
2075 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
2077 GEOM::GEOM_Gen_ptr engine = _this();
2079 GEOM_ITransformOperations_i* aServant =
2080 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
2082 // activate the CORBA servant
2083 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
2084 return operations._retn();
2087 //============================================================================
2088 // function : GetI3DPrimOperations
2090 //============================================================================
2091 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
2092 throw ( SALOME::SALOME_Exception )
2094 Unexpect aCatch(SALOME_SalomeException);
2095 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
2097 GEOM::GEOM_Gen_ptr engine = _this();
2099 GEOM_I3DPrimOperations_i* aServant =
2100 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
2101 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2103 // activate the CORBA servant
2104 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
2105 return operations._retn();
2108 //============================================================================
2109 // function : GetIShapesOperations
2111 //============================================================================
2112 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
2113 throw ( SALOME::SALOME_Exception )
2115 Unexpect aCatch(SALOME_SalomeException);
2116 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
2118 GEOM::GEOM_Gen_ptr engine = _this();
2120 GEOM_IShapesOperations_i* aServant =
2121 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
2123 // activate the CORBA servant
2124 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
2125 return operations._retn();
2128 //============================================================================
2129 // function : GetIBlocksOperations
2131 //============================================================================
2132 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
2133 throw ( SALOME::SALOME_Exception )
2135 Unexpect aCatch(SALOME_SalomeException);
2136 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
2138 GEOM::GEOM_Gen_ptr engine = _this();
2140 GEOM_IBlocksOperations_i* aServant =
2141 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
2143 // activate the CORBA servant
2144 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
2145 return operations._retn();
2148 //============================================================================
2149 // function : GetIBooleanOperations
2151 //============================================================================
2152 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
2153 throw ( SALOME::SALOME_Exception )
2155 Unexpect aCatch(SALOME_SalomeException);
2156 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
2158 GEOM::GEOM_Gen_ptr engine = _this();
2160 GEOM_IBooleanOperations_i* aServant =
2161 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
2163 // activate the CORBA servant
2164 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
2165 return operations._retn();
2168 //============================================================================
2169 // function : GetICurvesOperations
2171 //============================================================================
2172 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
2173 throw ( SALOME::SALOME_Exception )
2175 Unexpect aCatch(SALOME_SalomeException);
2176 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
2178 GEOM::GEOM_Gen_ptr engine = _this();
2180 GEOM_ICurvesOperations_i* aServant =
2181 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
2183 // activate the CORBA servant
2184 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
2185 return operations._retn();
2188 //============================================================================
2189 // function : GetILocalOperations
2191 //============================================================================
2192 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
2193 throw ( SALOME::SALOME_Exception )
2195 Unexpect aCatch(SALOME_SalomeException);
2196 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
2198 GEOM::GEOM_Gen_ptr engine = _this();
2200 GEOM_ILocalOperations_i* aServant =
2201 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
2203 // activate the CORBA servant
2204 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
2205 return operations._retn();
2208 //============================================================================
2209 // function : GetIHealingOperations
2211 //============================================================================
2212 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
2213 throw ( SALOME::SALOME_Exception )
2215 Unexpect aCatch(SALOME_SalomeException);
2216 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
2218 GEOM::GEOM_Gen_ptr engine = _this();
2220 GEOM_IHealingOperations_i* aServant =
2221 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
2223 // activate the CORBA servant
2224 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
2225 return operations._retn();
2228 //============================================================================
2229 // function : GetIInsertOperations
2231 //============================================================================
2232 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
2233 throw ( SALOME::SALOME_Exception )
2235 Unexpect aCatch(SALOME_SalomeException);
2236 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
2238 GEOM::GEOM_Gen_ptr engine = _this();
2240 GEOM_IInsertOperations_i* aServant =
2241 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
2243 // activate the CORBA servant
2244 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
2245 return operations._retn();
2248 //============================================================================
2249 // function : GetIMeasureOperations
2251 //============================================================================
2252 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
2253 throw ( SALOME::SALOME_Exception )
2255 Unexpect aCatch(SALOME_SalomeException);
2256 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
2258 GEOM::GEOM_Gen_ptr engine = _this();
2260 GEOM_IMeasureOperations_i* aServant =
2261 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
2263 // activate the CORBA servant
2264 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
2265 return operations._retn();
2268 //============================================================================
2269 // function : GetIGroupOperations
2271 //============================================================================
2272 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
2273 throw ( SALOME::SALOME_Exception )
2275 Unexpect aCatch(SALOME_SalomeException);
2276 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
2278 GEOM::GEOM_Gen_ptr engine = _this();
2280 GEOM_IGroupOperations_i* aServant =
2281 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
2283 // activate the CORBA servant
2284 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
2285 return operations._retn();
2288 //============================================================================
2289 // function : GetIAdvancedOperations
2291 //============================================================================
2292 GEOM::GEOM_IAdvancedOperations_ptr GEOM_Gen_i::GetIAdvancedOperations(CORBA::Long theStudyID)
2293 throw ( SALOME::SALOME_Exception )
2295 Unexpect aCatch(SALOME_SalomeException);
2296 MESSAGE( "GEOM_Gen_i::GetIAdvancedOperations" );
2298 GEOM::GEOM_Gen_ptr engine = _this();
2300 GEOM_IAdvancedOperations_i* aServant =
2301 new GEOM_IAdvancedOperations_i(_poa, engine, _impl->GetIAdvancedOperations(theStudyID));
2303 // activate the CORBA servant
2304 GEOM::GEOM_IAdvancedOperations_var operations = aServant->_this();
2305 return operations._retn();
2308 //=============================================================================
2312 //=============================================================================
2313 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
2314 const GEOM::ListOfLong& theIndices)
2316 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
2317 return GEOM::GEOM_Object::_nil();
2318 CORBA::String_var entry = theMainShape->GetEntry();
2319 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
2320 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
2322 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
2323 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
2325 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
2326 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
2328 TCollection_AsciiString anEntry;
2329 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
2330 return GetObject(anObject->GetDocID(), anEntry.ToCString());
2333 //=============================================================================
2337 //=============================================================================
2338 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
2340 CORBA::String_var anEntry = theObject->GetEntry();
2341 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false);
2342 if (anObject.IsNull()) return;
2343 _impl->RemoveObject(anObject);
2348 //=================================================================================
2349 // function : GetStringFromIOR()
2350 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
2351 //=================================================================================
2352 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
2353 return _orb->object_to_string(theObject);
2357 //=================================================================================
2358 // function : GetIORFromString()
2359 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
2360 //=================================================================================
2361 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
2362 GEOM::GEOM_Object_var aGeomObject;
2363 if(strcmp(stringIOR,"") != 0){
2364 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
2365 if(!CORBA::is_nil(anObject))
2366 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
2368 return aGeomObject._retn();
2371 //=================================================================================
2372 // function : GetObject()
2374 //=================================================================================
2375 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
2377 GEOM::GEOM_Object_var obj;
2378 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
2379 if (handle_object.IsNull()) return obj._retn();
2381 TCollection_AsciiString stringIOR = handle_object->GetIOR();
2382 if (stringIOR.Length() > 1) {
2383 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
2384 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
2388 GEOM::GEOM_Gen_ptr engine = _this();
2389 //transfer the reference to GEOM_Object_i
2390 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
2391 PortableServer::ObjectId_var id = _poa->activate_object(servant);
2393 obj = servant->_this();
2394 CORBA::String_var objStr = _orb->object_to_string(obj);
2395 TCollection_AsciiString anAscii( (char *)objStr.in() );
2396 handle_object->SetIOR( anAscii );
2400 //=================================================================================
2401 // function : hasObjectInfo()
2402 // purpose : shows if module provides information for its objects
2403 //=================================================================================
2404 bool GEOM_Gen_i::hasObjectInfo()
2409 //=================================================================================
2410 // function : getObjectInfo()
2411 // purpose : returns an information for a given object by its entry
2412 //=================================================================================
2413 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
2415 GEOM::GEOM_Object_var aGeomObject;
2417 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
2418 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
2419 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
2420 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
2421 SALOMEDS::SObject_var aResultSObj;
2422 if (aSObj->ReferencedObject(aResultSObj))
2423 aSObj = aResultSObj;
2425 SALOMEDS::GenericAttribute_var anAttr;
2426 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
2427 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2428 CORBA::String_var aVal = anIOR->Value();
2430 CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
2431 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
2433 if (!aSObj->_is_nil() )
2436 const char* aTypeInfo = "Object";
2437 if ( !aGeomObject->_is_nil() ) {
2438 GEOM::GEOM_IKindOfShape::shape_kind aKind;
2439 GEOM::ListOfLong_var anInts;
2440 GEOM::ListOfDouble_var aDbls;
2442 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
2443 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
2445 if ( anOp->IsDone() ) {
2447 case GEOM::GEOM_IKindOfShape::COMPOUND:
2448 aTypeInfo = "Compound";
2450 case GEOM::GEOM_IKindOfShape::COMPSOLID:
2451 aTypeInfo = "CompSolid";
2453 case GEOM::GEOM_IKindOfShape::SHELL:
2454 aTypeInfo = "Shell";
2456 case GEOM::GEOM_IKindOfShape::WIRE:
2457 if ( anInts[0] == 1 )
2458 aTypeInfo = "Closed Wire";
2459 else if ( anInts[0] == 2 )
2460 aTypeInfo = "Opened Wire";
2465 case GEOM::GEOM_IKindOfShape::SPHERE:
2466 aTypeInfo = "Sphere";
2468 case GEOM::GEOM_IKindOfShape::CYLINDER:
2469 aTypeInfo = "Cylinder";
2471 case GEOM::GEOM_IKindOfShape::BOX:
2472 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
2475 case GEOM::GEOM_IKindOfShape::TORUS:
2476 aTypeInfo = "Torus";
2478 case GEOM::GEOM_IKindOfShape::CONE:
2481 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
2482 aTypeInfo = "Polyhedron";
2484 case GEOM::GEOM_IKindOfShape::SOLID:
2485 aTypeInfo = "Solid";
2488 case GEOM::GEOM_IKindOfShape::SPHERE2D:
2489 aTypeInfo = "Spherical Face";
2491 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
2492 aTypeInfo = "Cylindrical Face";
2494 case GEOM::GEOM_IKindOfShape::TORUS2D:
2495 aTypeInfo = "Toroidal Face";
2497 case GEOM::GEOM_IKindOfShape::CONE2D:
2498 aTypeInfo = "Conical Face";
2500 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
2503 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
2504 aTypeInfo = "Elliptical Face";
2506 case GEOM::GEOM_IKindOfShape::POLYGON:
2507 aTypeInfo = "Polygon";
2509 case GEOM::GEOM_IKindOfShape::PLANE:
2510 aTypeInfo = "Plane";
2512 case GEOM::GEOM_IKindOfShape::PLANAR:
2513 aTypeInfo = "Planar Face";
2515 case GEOM::GEOM_IKindOfShape::FACE:
2519 case GEOM::GEOM_IKindOfShape::CIRCLE:
2520 aTypeInfo = "Circle";
2522 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
2523 aTypeInfo = "Arc Circle";
2525 case GEOM::GEOM_IKindOfShape::ELLIPSE:
2526 aTypeInfo = "Ellipse";
2528 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
2529 aTypeInfo = "Arc Ellipse";
2531 case GEOM::GEOM_IKindOfShape::LINE:
2534 case GEOM::GEOM_IKindOfShape::SEGMENT:
2535 aTypeInfo = "Segment";
2537 case GEOM::GEOM_IKindOfShape::EDGE:
2540 case GEOM::GEOM_IKindOfShape::VERTEX:
2541 aTypeInfo = "Vertex";
2549 char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
2550 sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
2552 char* ret = CORBA::string_dup(anInfo);
2557 //=====================================================================================
2559 //=====================================================================================
2564 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
2568 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb,
2569 PortableServer::POA_ptr poa,
2570 PortableServer::ObjectId* contId,
2571 const char* instanceName,
2572 const char* interfaceName)
2574 GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
2575 return myGEOM_Gen_i->getId();