1 // Copyright (C) 2007-2013 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
24 #pragma warning( disable:4786 )
27 #include <Standard_Stream.hxx>
29 #include "GEOM_Gen_i.hh"
30 #include "GEOM_Object_i.hh"
31 #include "GEOM_version.h"
36 #include "Utils_CorbaException.hxx"
38 #include "Utils_ExceptHandlers.hxx"
39 #include "utilities.h"
41 #include "GEOM_Object_i.hh"
42 #include "GEOM_Object.hxx"
43 #include "GEOM_Function.hxx"
44 #include "GEOM_ISubShape.hxx"
45 #include <GEOM_PythonDump.hxx>
46 #include "GEOMImpl_Types.hxx"
47 #include "GEOMImpl_CopyDriver.hxx"
50 #include <BRep_Builder.hxx>
51 #include <BRepTools.hxx>
52 #include <TDF_Label.hxx>
53 #include <TDF_Tool.hxx>
54 #include <TDF_ChildIDIterator.hxx>
55 #include <TNaming_NamedShape.hxx>
56 #include <TDataStd_Name.hxx>
57 #include <TCollection_AsciiString.hxx>
58 #include <TColStd_HArray1OfInteger.hxx>
59 #include <TopAbs_ShapeEnum.hxx>
60 //#include <TopTools_IndexedMapOfShape.hxx>
64 #include <SALOMEDS_Tool.hxx>
66 //============================================================================
67 // function : GEOM_Gen_i()
68 // purpose : constructor to be called for servant creation.
69 //============================================================================
70 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
71 PortableServer::POA_ptr poa,
72 PortableServer::ObjectId* contId,
73 const char* instanceName,
74 const char* interfaceName) :
75 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
78 _id = _poa->activate_object(_thisObj);
79 name_service = new SALOME_NamingService(_orb);
81 _impl = new ::GEOMImpl_Gen;
83 //PAL10867: disable signals catching with "noexcepthandler" option
84 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
85 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
87 //work around PAL12004, PAL12628
88 //OSD::SetSignal( true );
92 char* envDisableFPE = getenv("DISABLE_FPE");
93 if (envDisableFPE && atoi(envDisableFPE))
98 OSD::SetSignal( raiseFPE );
102 //============================================================================
103 // function : ~GEOM_Gen_i()
104 // purpose : destructor
105 //============================================================================
106 GEOM_Gen_i::~GEOM_Gen_i() {
112 //============================================================================
113 // function : IORToLocalPersistentID()
115 //============================================================================
116 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
117 const char* IORString,
118 CORBA::Boolean isMultiFile,
119 CORBA::Boolean isASCII)
121 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
122 if (!CORBA::is_nil(anObject)) {
123 return CORBA::string_dup(anObject->GetEntry());
129 //============================================================================
130 // function : LocalPersistentIDToIOR()
131 // purpose : Create/Load CORBA object from a persistent ref (an entry)
132 // : Used when a study is loaded
133 // : The IOR (IORName) of object created is returned
134 //============================================================================
135 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
136 const char* aLocalPersistentID,
137 CORBA::Boolean isMultiFile,
138 CORBA::Boolean isASCII)
140 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
142 Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
143 TCollection_AsciiString anEntry;
144 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
145 GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
147 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
148 return CORBA::string_dup(aPersRefString);
151 //============================================================================
152 // function : CanPublishInStudy
154 //============================================================================
155 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
157 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
158 return !(anObject->_is_nil());
162 //============================================================================
163 // function : PublishInStudy
165 //============================================================================
166 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
167 SALOMEDS::SObject_ptr theSObject,
168 CORBA::Object_ptr theObject,
169 const char* theName) throw (SALOME::SALOME_Exception)
171 Unexpect aCatch(SALOME_SalomeException);
172 SALOMEDS::SObject_var aResultSO;
173 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
174 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
175 if(aShape->_is_nil()) return aResultSO;
177 SALOMEDS::GenericAttribute_var anAttr;
178 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
180 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
181 if (aFather->_is_nil()) {
182 aFather = aStudyBuilder->NewComponent("GEOM");
183 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
184 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
185 aName->SetValue("Geometry");
187 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
188 SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr);
189 aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry");
190 aPixMap->UnRegister();
191 aStudyBuilder->DefineComponentInstance(aFather, (GEOM::GEOM_Gen_var)GEOM_Gen::_this());
193 if (aFather->_is_nil()) return aResultSO;
195 if (CORBA::is_nil(theSObject)) {
196 aResultSO = aStudyBuilder->NewObject(aFather);
198 if (!theSObject->ReferencedObject(aResultSO))
199 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
200 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
202 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
203 aResultSO->SetAttrString("AttributeIOR",aGeomObjIOR);
205 TCollection_AsciiString aShapeName("Shape_");
207 CORBA::Long mytype=aShape->GetType();
208 if ( mytype == GEOM_GROUP ) {
209 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
210 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
212 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_PNT" );
213 aShapeName = "Group_Of_Vertices_";
216 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_EDGE");
217 aShapeName = "Group_Of_Edges_";
220 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_FACE");
221 aShapeName = "Group_Of_Faces_";
224 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_SOLID");
225 aShapeName = "Group_Of_Solids_";
228 } else if ( mytype == GEOM_MARKER ) {
229 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS");
230 aShapeName = "LocalCS_";
231 } else if ( mytype > ADVANCED_BASE ) {
233 sprintf( buf, "%d", aShape->GetType() );
234 std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf;
235 aResultSO->SetAttrString("AttributePixMap",advId.c_str());
236 aShapeName = "Advanced_";
238 GEOM::shape_type myshapetype=aShape->GetShapeType();
239 if ( myshapetype == GEOM::COMPOUND ) {
240 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPOUND" );
241 aShapeName = "Compound_";
242 } else if ( myshapetype == GEOM::COMPSOLID ) {
243 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPSOLID");
244 aShapeName = "Compsolid_";
245 } else if ( myshapetype == GEOM::SOLID ) {
246 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SOLID");
247 aShapeName = "Solid_";
248 } else if ( myshapetype == GEOM::SHELL ) {
249 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SHELL");
250 aShapeName = "Shell_";
251 } else if ( myshapetype == GEOM::FACE ) {
252 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FACE");
253 aShapeName = "Face_";
254 } else if ( myshapetype == GEOM::WIRE ) {
255 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_WIRE");
256 aShapeName = "Wire_";
257 } else if ( myshapetype == GEOM::EDGE ) {
258 aResultSO->SetAttrString("AttributePixMap", "ICON_OBJBROWSER_EDGE");
259 aShapeName = "Edge_";
260 } else if ( myshapetype == GEOM::VERTEX ) {
261 aResultSO->SetAttrString("AttributePixMap","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 aResultSO->SetAttrString("AttributeName",aShapeName.ToCString());
329 //Set NoteBook variables used in the object creation
330 TCollection_AsciiString aVars;
331 CORBA::String_var aString=aShape->GetParameters();
332 SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aString);
333 for(int i = 0, n = aSections->length(); i < n; i++) {
334 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
335 for(int j = 0, m = aListOfVars.length(); j < m; j++) {
336 if(theStudy->IsVariable(aListOfVars[j].in()))
337 aVars += TCollection_AsciiString(aListOfVars[j].in());
344 aResultSO->SetAttrString("AttributeString",aVars.ToCString());
346 aFather->UnRegister();
348 //Set a name of the GEOM object
349 aShape->SetName(aShapeName.ToCString());
351 return aResultSO._retn();
355 //============================================================================
356 // function : CreateAndPublishGroup
357 // purpose : auxilary for PublishNamedShapesInStudy
358 //============================================================================
359 void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
360 GEOM::GEOM_Object_var theMainShape,
361 const TopTools_IndexedMapOfShape& anIndices,
362 const TopTools_SequenceOfShape& SeqS,
363 const TColStd_SequenceOfAsciiString& SeqN,
364 const Standard_CString& GrName,
365 GEOM::ListOfGO_var aResList)
367 CORBA::String_var entry = theMainShape->GetEntry();
368 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
369 Handle(TColStd_HArray1OfInteger) anArray;
370 if(SeqS.Length()>0) {
372 GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId());
373 GEOM::GEOM_Object_ptr GrObj =
374 GOp->CreateGroup( theMainShape, SeqS.Value(1).ShapeType() );
375 AddInStudy(theStudy, GrObj, GrName, theMainShape._retn());
376 CORBA::String_var GrEntry = GrObj->GetEntry();
377 Handle(GEOM_Object) HGrObj = _impl->GetObject(GrObj->GetStudyID(), GrEntry);
379 //Handle(GEOM_Object) anObj;
380 for(int i=1; i<=SeqS.Length(); i++) {
381 TopoDS_Shape aValue = SeqS.Value(i);
382 //anArray = new TColStd_HArray1OfInteger(1,1);
383 Standard_Integer anIndex = anIndices.FindIndex(aValue);
384 //anArray->SetValue(1, anIndex);
385 GOp->AddObject(GrObj,anIndex);
386 //anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE);
387 //if (anObj.IsNull()) continue;
388 //Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
389 //if (aFunction.IsNull()) continue;
390 //GEOM_ISubShape aSSI(aFunction);
391 //aSSI.SetMainShape(aMainShape->GetLastFunction());
392 //aSSI.SetIndices(anArray);
393 //aFunction->SetValue(aValue);
394 //GOp->UnionIDs(GrObj, anIndex);
395 //SALOMEDS::SObject_var aResultSO;
396 //TCollection_AsciiString anEntry;
397 //TDF_Tool::Entry(anObj->GetEntry(),anEntry);
398 //GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString());
399 //AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
405 //============================================================================
406 // function : PublishNamedShapesInStudy
408 //============================================================================
409 GEOM::ListOfGO* GEOM_Gen_i::
410 PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
411 //SALOMEDS::SObject_ptr theSObject,
412 CORBA::Object_ptr theObject)
414 //Unexpect aCatch(SALOME_SalomeException);
415 GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
417 //CORBA::Object_var theObject = theSObject->GetObject();
418 GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
419 if(theMainShape->_is_nil()) return aResList._retn();
421 CORBA::String_var entry = theMainShape->GetEntry();
422 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
423 if (aMainShape.IsNull()) return aResList._retn();
424 TopoDS_Shape MainSh = aMainShape->GetValue();
426 TDF_Label aMainLbl = aMainShape->GetEntry();
427 TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
428 TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
429 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
430 for(; anIt.More(); anIt.Next()) {
431 Handle(TNaming_NamedShape) anAttr =
432 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
433 if(anAttr.IsNull()) continue;
434 TopoDS_Shape S = anAttr->Get();
435 TDF_Label L = anAttr->Label();
436 //if(S.IsEqual(MainSh)) continue;
437 Handle(TDataStd_Name) aName;
438 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
439 TCollection_ExtendedString EName = aName->Get();
440 if(S.ShapeType()==TopAbs_SOLID) {
442 SolidSeqN.Append(aName->Get());
444 else if(S.ShapeType()==TopAbs_FACE) {
446 FaceSeqN.Append(aName->Get());
448 else if(S.ShapeType()==TopAbs_EDGE) {
450 EdgeSeqN.Append(aName->Get());
452 else if(S.ShapeType()==TopAbs_VERTEX) {
454 VertSeqN.Append(aName->Get());
459 TopTools_IndexedMapOfShape anIndices;
460 TopExp::MapShapes(MainSh, anIndices);
462 CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN,
463 "Group_Of_Named_Solids", aResList);
465 CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN,
466 "Group_Of_Named_Faces", aResList);
468 CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
469 "Group_Of_Named_Edges", aResList);
471 CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN,
472 "Group_Of_Named_Vertices", aResList);
474 return aResList._retn();
478 //============================================================================
480 // purpose : save OCAF/Geom document
481 //============================================================================
482 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
485 SALOMEDS::TMPFile_var aStreamFile;
486 // Get a temporary directory to store a file
487 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
489 // OCCT BUG: cannot save a document (in current folder)
490 // if directory name is empty
491 if (aTmpDir.size() == 0) {
499 // Create a list to store names of created files
500 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
502 // Prepare a file name to open
503 TCollection_AsciiString aNameWithExt("");
505 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
506 (theComponent->GetStudy()->URL())).c_str());
507 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
508 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
509 // Build a full file name of temporary file
510 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
511 // Save GEOM component in this file
512 _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
513 // Conver a file to the byte stream
514 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
515 // Remove the created file and tmp directory
516 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
518 // Return the created byte stream
519 return aStreamFile._retn();
523 //============================================================================
524 // function : SaveASCII()
526 //============================================================================
527 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
530 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
531 return aStreamFile._retn();
535 //============================================================================
538 //============================================================================
539 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
540 const SALOMEDS::TMPFile& theStream,
544 if (theStream.length() <= 9) {
545 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
549 // Get a temporary directory for a file
550 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
552 // OCCT BUG: cannot load a document (from current folder)
553 // if directory name is empty
554 if (aTmpDir.size() == 0) {
562 // Conver the byte stream theStream to a file and place it in tmp directory
563 SALOMEDS::ListOfFileNames_var aSeq =
564 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
566 // Prepare a file name to open
567 TCollection_AsciiString aNameWithExt("");
569 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
570 (theComponent->GetStudy()->URL())).c_str());
571 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
572 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
575 if (!_impl->Load(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString())) return false;
577 // Remove the created file and tmp directory
578 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
584 //============================================================================
585 // function : LoadASCII()
587 //============================================================================
588 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
589 const SALOMEDS::TMPFile& theStream,
592 return Load(theComponent, theStream, theURL, isMultiFile);
596 //============================================================================
597 // function : Close()
599 //============================================================================
600 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
602 SALOMEDS::Study_var aStudy= theComponent->GetStudy();
603 _impl->Close(aStudy->StudyId());
606 //============================================================================
607 // function : CanCopy()
609 //============================================================================
610 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
611 // Try to retrieve known by Geometry component GEOM_Object by given IOR
612 SALOMEDS::GenericAttribute_var anAttr;
613 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
615 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
617 CORBA::String_var aString=anIOR->Value();
619 CORBA::Object_var anObj = _orb->string_to_object(aString);
620 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(anObj);
621 // If the object is null one it can't be copied: return false
622 if (anObject->_is_nil()) return false;
626 //============================================================================
627 // function : CopyFrom()
629 //============================================================================
630 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
632 // Declare a sequence of the byte to store the copied object
633 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
635 // Try to get GEOM_Object object by given SObject
636 SALOMEDS::GenericAttribute_var anAttr;
637 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
638 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
639 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
640 if (anObject->_is_nil()) return aStreamFile._retn();
642 aStreamFile = anObject->GetShapeStream();
644 // Assign an ID the type of GEOM_Object
645 theObjectID = anObject->GetType();
647 // Return created TMPFile
648 return aStreamFile._retn();
651 //============================================================================
652 // function : CanPaste()
654 //============================================================================
655 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
656 // The Geometry component can paste only objects copied by Geometry component
657 // and with the object type = 1
658 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
662 //============================================================================
663 // function : PasteInto()
665 //============================================================================
666 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
667 CORBA::Long theObjectID,
668 SALOMEDS::SObject_ptr theObject) {
669 // Find the current Study and StudyBuilder
670 SALOMEDS::Study_var aStudy = theObject->GetStudy();
671 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
672 SALOMEDS::SObject_var aNewSO;
673 // Retrieve a TopoDS_Shape from byte stream
674 TopoDS_Shape aTopology;
675 std::istringstream aStreamedBrep((char*) &theStream[0]);
676 BRep_Builder aBuilder;
678 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
679 } catch (Standard_Failure) {
680 return aNewSO._retn();
683 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
684 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
685 aNewSO = aStudyBuilder->NewObject(theObject);
686 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
689 //Create a new GEOM_Object
690 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
691 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
692 aFunction->SetValue(aTopology);
694 TCollection_AsciiString anEntry;
695 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
696 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
698 //Set the study entry of the published GEOM_Object
699 obj->SetStudyEntry(aNewSO->GetID());
701 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
702 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
703 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
704 CORBA::String_var objStr = _orb->object_to_string(obj);
705 anIOR->SetValue(objStr.in());
708 // Return the created in the Study SObject
709 return aNewSO._retn();
712 //============================================================================
713 // function : ComponentDataType()
715 //============================================================================
716 char* GEOM_Gen_i::ComponentDataType()
718 return CORBA::string_dup("GEOM");
721 //============================================================================
722 // function : AddInStudy
724 //============================================================================
725 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
726 GEOM::GEOM_Object_ptr theObject,
728 GEOM::GEOM_Object_ptr theFather)
730 SALOMEDS::SObject_var aResultSO;
731 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
733 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
734 CORBA::String_var IOR;
736 if(!theFather->_is_nil()) {
737 IOR = _orb->object_to_string(theFather);
738 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in());
739 if(aFatherSO->_is_nil()) return aResultSO._retn();
740 aResultSO = aStudyBuilder->NewObject(aFatherSO);
741 aFatherSO->UnRegister();
742 //aStudyBuilder->Addreference(aResultSO, aResultSO);
745 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
746 if(aResultSO->_is_nil()) return aResultSO._retn();
748 GEOM::ListOfGO_var aList = theObject->GetDependency();
749 Standard_Integer aLength = aList->length();
750 if(aLength < 1) return aResultSO._retn();
752 //Publish the arguments
753 TCollection_AsciiString aPrevID; // to avoid multiple references to same object
754 for(Standard_Integer i = 0; i< aLength; i++) {
755 GEOM::GEOM_Object_var anObject = aList[i];
756 if(anObject->_is_nil()) continue;
757 IOR = _orb->object_to_string(anObject);
758 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR.in());
759 if(aSO->_is_nil()) continue;
760 CORBA::String_var anID = aSO->GetID();
761 if ( aPrevID == anID.in() ) continue;
763 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
764 aStudyBuilder->Addreference(aSubSO, aSO);
766 aSubSO->UnRegister();
769 return aResultSO._retn();
772 //============================================================================
773 // function : RestoreSubShapesO
774 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
775 // To be used from python scripts out of geompy.addToStudy (non-default usage)
776 //============================================================================
777 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
778 GEOM::GEOM_Object_ptr theObject,
779 const GEOM::ListOfGO& theArgs,
780 GEOM::find_shape_method theFindMethod,
781 CORBA::Boolean theInheritFirstArg,
782 CORBA::Boolean theAddPrefix)
784 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
785 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
786 return aParts._retn();
788 // find SObject in the study if it is already published
789 CORBA::String_var anIORo = _orb->object_to_string(theObject);
790 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
791 //PTv, IMP 0020001, The salome object <aSO>
792 // is not obligatory in case of invokation from script
793 // if (CORBA::is_nil(aSO))
794 // return aParts._retn();
796 aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs,
797 theFindMethod, theInheritFirstArg, theAddPrefix);
798 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
799 return aParts._retn();
802 //============================================================================
803 // function : RestoreGivenSubShapesO
804 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
805 // To be used from python scripts, generated by Dump Python.
806 //============================================================================
807 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (SALOMEDS::Study_ptr theStudy,
808 GEOM::GEOM_Object_ptr theObject,
809 const GEOM::ListOfGO& theArgs,
810 GEOM::find_shape_method theFindMethod,
811 CORBA::Boolean theInheritFirstArg,
812 CORBA::Boolean theAddPrefix)
814 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
815 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
816 return aParts._retn();
818 // find SObject in the study if it is already published
819 CORBA::String_var anIORo = _orb->object_to_string(theObject);
820 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
821 //PTv, IMP 0020001, The salome object <aSO>
822 // is not obligatory in case of invokation from script
823 // if (CORBA::is_nil(aSO))
824 // return aParts._retn();
826 aParts = RestoreGivenSubShapes(theStudy, theObject, aSO, theArgs,
827 theFindMethod, theInheritFirstArg, theAddPrefix);
828 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
829 return aParts._retn();
832 //============================================================================
833 // function : RestoreSubShapesSO
834 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
835 // To be used from GUI and from geompy.addToStudy
836 //============================================================================
837 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
838 SALOMEDS::SObject_ptr theSObject,
839 const GEOM::ListOfGO& theArgs,
840 GEOM::find_shape_method theFindMethod,
841 CORBA::Boolean theInheritFirstArg,
842 CORBA::Boolean theAddPrefix)
844 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
845 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
846 return aParts._retn();
848 SALOMEDS::GenericAttribute_var anAttr;
849 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
850 return aParts._retn();
852 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
853 CORBA::String_var anIORso = anAttrIOR->Value();
855 // get Object from SObject
856 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
857 if (CORBA::is_nil(anO))
858 return aParts._retn();
860 aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs,
861 theFindMethod, theInheritFirstArg, theAddPrefix);
862 return aParts._retn();
865 //============================================================================
866 // function : addToListOfGO
867 // purpose : static local function
868 //============================================================================
869 static void addToListOfGO( GEOM::GEOM_Object_ptr theObject,
870 GEOM::ListOfGO& theList )
872 const int oldLen = theList.length();
873 theList.length(oldLen + 1);
874 theList[ oldLen ] = GEOM::GEOM_Object::_duplicate( theObject );
877 //============================================================================
878 // function : addToListOfGO
879 // purpose : static local function
880 //============================================================================
881 static void addToListOfGO( const GEOM::ListOfGO& theSrcList,
882 GEOM::ListOfGO& theTrgList )
884 const int oldLen = theTrgList.length();
885 const int srcLen = theSrcList.length();
886 theTrgList.length(oldLen + srcLen);
887 for( int i = 0; i < srcLen; i++ )
888 theTrgList[ oldLen + i ] = GEOM::GEOM_Object::_duplicate( theSrcList[ i ] );
891 //============================================================================
892 // function : RestoreSubShapes
893 // purpose : Private method. Works only if both theObject and theSObject
894 // are defined, and does not check, if they correspond to each other.
895 //============================================================================
896 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy,
897 GEOM::GEOM_Object_ptr theObject,
898 SALOMEDS::SObject_ptr theSObject,
899 const GEOM::ListOfGO& theArgs,
900 GEOM::find_shape_method theFindMethod,
901 CORBA::Boolean theInheritFirstArg,
902 CORBA::Boolean theAddPrefix)
904 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
905 //PTv, IMP 0020001, The salome object <theSObject>
906 // is not obligatory in case of invokation from script
907 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
908 return aParts._retn();
910 // For Dump Python (mantis issue 0020768)
911 GEOM::ListOfGO_var anOutArgs = new GEOM::ListOfGO;
913 // Arguments to be published
914 GEOM::ListOfGO_var aList;
916 // If theArgs list is empty, we try to publish all arguments,
917 // otherwise publish only passed args
918 Standard_Integer nbArgsActual = -1; // -1 means unknown
919 Standard_Integer aLength = theArgs.length();
921 aList = new GEOM::ListOfGO;
922 aList->length(aLength);
923 for (int i = 0; i < aLength; i++) {
924 aList[i] = GEOM::GEOM_Object::_duplicate( theArgs[i] );
929 aList = theObject->GetDependency();
930 aLength = aList->length();
931 nbArgsActual = aLength;
935 return aParts._retn();
937 if (theInheritFirstArg || (nbArgsActual == 1)) {
938 // Do not publish argument's reflection,
939 // but only reconstruct its published sub-shapes
941 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
942 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
944 // remember restored objects for Python Dump
945 addToListOfGO(aList[0], anOutArgs);
947 aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
948 anOutArgs, theFindMethod, theAddPrefix);
950 // set the color of the transformed shape to the color of initial shape
951 theObject->SetColor(aList[0]->GetColor());
953 if (theObject->GetShapeType() == GEOM::VERTEX) {
954 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
955 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
956 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
959 anArgSO->UnRegister();
962 // Get interface, containing method, which we will use to reconstruct sub-shapes
963 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
964 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
965 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
967 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
968 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
970 // Reconstruct arguments and tree of sub-shapes of the arguments
971 CORBA::String_var anIOR;
972 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
973 for (Standard_Integer i = 0; i < aLength; i++)
975 GEOM::GEOM_Object_var anArgO = aList[i];
976 if (!CORBA::is_nil(anArgO)) {
977 anIOR = _orb->object_to_string(anArgO);
978 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
979 TCollection_AsciiString anArgName;
980 if (CORBA::is_nil(anArgSO)) {
982 anArgName += TCollection_AsciiString(i);
985 anArgName = anArgSO->GetName();
988 // Find a sub-shape of theObject in place of the argument
989 GEOM::GEOM_Object_var aSubO;
990 switch (theFindMethod) {
991 case GEOM::FSM_GetInPlace:
994 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
997 case GEOM::FSM_MultiTransformed:
999 // Only for Multi-transformations
1000 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1001 if (!CORBA::is_nil(anArgOTrsf)) {
1002 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1003 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1004 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1005 anArgOTrsfFun->SetDescription("");
1006 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1009 Handle(GEOM_Function) anOFun = theObject->GetLastFunction();
1010 if (!anOFun.IsNull()) {
1011 CORBA::String_var entryArg = anArgO->GetEntry();
1012 Handle(GEOM_Object) anArgOImpl = _impl->GetObject(anArgO->GetStudyID(), entryArg);
1013 if (!anArgOImpl.IsNull()) {
1014 TopoDS_Shape anArgOShape = anArgOImpl->GetValue();
1015 TopoDS_Shape aMultiArgShape;
1016 //GEOM::GEOM_Object_var anArgOMulti; // ???
1017 switch (anOFun->GetType()) {
1020 GEOMImpl_ITranslate aTI (anOFun);
1021 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape1D(anArgOShape, &aTI);
1022 //anArgOMulti = aTrsfOpSv->Translate1D(anArgO, , , );
1027 GEOMImpl_ITranslate aTI (anOFun);
1028 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1033 GEOMImpl_IRotate aTI (anOFun);
1034 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1039 GEOMImpl_IRotate aTI (anOFun);
1040 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1046 GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO
1047 Handle(GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction();
1048 anArgOMultiFun->SetDescription("");
1049 aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti);
1055 case GEOM::FSM_Transformed:
1057 // transformation, cannot use GetInPlace, operate with indices
1058 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1059 if (anIDs->length() > 1) {
1061 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1062 if (!CORBA::is_nil(aSubO))
1063 aGroupOp->UnionIDs(aSubO, anIDs);
1065 else if (anIDs->length() > 0) {
1067 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1071 case GEOM::FSM_GetSame:
1074 aSubO = aShapesOp->GetSame(theObject, anArgO);
1077 case GEOM::FSM_GetShapesOnShape:
1079 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1080 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1081 (short)GEOM::SOLID, GEOM::ST_ONIN);
1084 case GEOM::FSM_GetInPlaceByHistory:
1086 // Use GetInPlaceByHistory
1087 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1094 if (!CORBA::is_nil(aSubO)) {
1095 // remember restored objects for Python Dump
1096 addToListOfGO(anArgO, anOutArgs);
1098 // add to parts list
1099 addToListOfGO( aSubO, aParts );
1101 // Publish the sub-shape
1102 SALOMEDS::SObject_var aSubSO;
1103 if (!CORBA::is_nil(theSObject)) {
1104 TCollection_AsciiString aSubName;
1108 aSubName += anArgName;
1109 aSubSO = aStudyBuilder->NewObject(theSObject);
1110 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1112 aSubO->SetColor(anArgO->GetColor());
1114 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1115 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1116 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1117 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1121 if (!CORBA::is_nil(anArgSO)) {
1122 // Restore published sub-shapes of the argument
1123 GEOM::ListOfGO_var aSubParts;
1124 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1125 // pass theObject, because only it has the history
1126 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1127 theObject, anOutArgs, theFindMethod, theAddPrefix);
1129 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1130 aSubO, anOutArgs, theFindMethod, theAddPrefix);
1131 // add to parts list
1132 addToListOfGO( aSubParts, aParts );
1135 else { // GetInPlace failed, try to build from published parts
1136 if (!CORBA::is_nil(anArgSO)) {
1137 SALOMEDS::SObject_var aSubSO;
1138 if (!CORBA::is_nil(theSObject))
1139 aSubSO = aStudyBuilder->NewObject(theSObject);
1141 // Restore published sub-shapes of the argument
1142 GEOM::ListOfGO_var aSubParts =
1143 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1144 theObject, anOutArgs, theFindMethod, theAddPrefix);
1146 // add to parts list
1147 addToListOfGO( aSubParts, aParts );
1149 if (aSubParts->length() > 0) {
1150 // remember restored objects for Python Dump
1151 addToListOfGO(anArgO, anOutArgs);
1153 // try to build an argument from a set of its sub-shapes,
1154 // that published and will be reconstructed
1155 if (aSubParts->length() > 1) {
1156 aSubO = aShapesOp->MakeCompound(aSubParts);
1157 // add to parts list
1158 addToListOfGO( aSubO, aParts );
1161 aSubO = aSubParts[0];
1163 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1164 // Publish the sub-shape
1165 TCollection_AsciiString aSubName;
1167 aSubName = "from_parts_of_";
1169 aSubName += anArgName;
1170 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1172 aSubO->SetColor(anArgO->GetColor());
1174 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1175 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1176 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1177 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1181 else if (!CORBA::is_nil(aSubSO)) {
1182 // remove created aSubSO, because no parts have been found
1183 aStudyBuilder->RemoveObject(aSubSO);
1186 } // try to build from published parts
1187 anArgSO->UnRegister();
1189 } // process arguments
1191 std::set<std::string> anObjEntryMap;
1192 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1194 int nb = aParts->length();
1195 aResParts->length(nb);
1198 Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1199 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1200 GEOM::TPythonDump pd (aFunction, true);
1203 for ( ; i < nb; i++ )
1205 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1206 if (CORBA::is_nil(anObj))
1208 char* anEntry = anObj->GetEntry();
1209 if (anObjEntryMap.count(anEntry))
1210 continue; // already treated
1211 anObjEntryMap.insert(anEntry);
1212 aResParts[nbRes++] = anObj;
1213 // clear python dump of object
1214 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1215 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1216 if ( !anObjFun.IsNull() )
1217 anObjFun->SetDescription( "" );
1223 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1224 //i = 0; nb = theArgs.length(); j = 0;
1225 i = 0; nb = anOutArgs->length(); j = 0;
1226 for ( ; i < nb; i++ )
1228 //GEOM::GEOM_Object_var anObj = theArgs[ i ];
1229 GEOM::GEOM_Object_var anObj = anOutArgs[ i ];
1230 if (CORBA::is_nil(anObj))
1232 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1238 pd <<"]" << ", " <<"GEOM.";
1239 switch (theFindMethod) {
1240 case GEOM::FSM_GetInPlace:
1241 pd << "FSM_GetInPlace"; break;
1242 case GEOM::FSM_MultiTransformed:
1243 pd << "FSM_MultiTransformed"; break;
1244 case GEOM::FSM_Transformed:
1245 pd << "FSM_Transformed"; break;
1246 case GEOM::FSM_GetSame:
1247 pd << "FSM_GetSame"; break;
1248 case GEOM::FSM_GetShapesOnShape:
1249 pd << "FSM_GetShapesOnShape"; break;
1250 case GEOM::FSM_GetInPlaceByHistory:
1252 pd << "FSM_GetInPlaceByHistory"; break;
1254 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1256 aResParts->length(nbRes);
1257 return aResParts._retn();
1260 //============================================================================
1261 // function : RestoreSubShapesOneLevel
1262 // purpose : Private method
1263 //============================================================================
1264 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1265 SALOMEDS::SObject_ptr theOldSO,
1266 SALOMEDS::SObject_ptr theNewSO,
1267 GEOM::GEOM_Object_ptr theNewO,
1268 GEOM::ListOfGO& theOutArgs,
1269 GEOM::find_shape_method theFindMethod,
1270 CORBA::Boolean theAddPrefix)
1273 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1274 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1275 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1276 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1277 return aParts._retn();
1279 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1281 // Get interface, containing method, which we will use to reconstruct sub-shapes
1282 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1283 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1284 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1286 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1287 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
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 = aTrsfOpSv->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());
1556 anArgSO->UnRegister();
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 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1565 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1567 // Reconstruct arguments and tree of sub-shapes of the arguments
1568 CORBA::String_var anIOR;
1569 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1570 for (Standard_Integer i = 0; i < nbArgsActual; i++)
1572 GEOM::GEOM_Object_var anArgO = aList[i];
1573 if (!CORBA::is_nil(anArgO)) {
1574 anIOR = _orb->object_to_string(anArgO);
1575 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1576 TCollection_AsciiString anArgName;
1577 if (CORBA::is_nil(anArgSO)) {
1579 anArgName += TCollection_AsciiString(i);
1582 anArgName = anArgSO->GetName();
1585 // Find a sub-shape of theObject in place of the argument
1586 GEOM::GEOM_Object_var aSubO;
1587 switch (theFindMethod) {
1588 case GEOM::FSM_GetInPlace:
1591 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1594 case GEOM::FSM_MultiTransformed:
1596 // Only for Multi-transformations
1597 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1598 if (!CORBA::is_nil(anArgOTrsf)) {
1599 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1600 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1601 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1602 anArgOTrsfFun->SetDescription("");
1603 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1607 case GEOM::FSM_Transformed:
1609 // transformation, cannot use GetInPlace, operate with indices
1610 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1611 if (anIDs->length() > 1) {
1613 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1614 if (!CORBA::is_nil(aSubO))
1615 aGroupOp->UnionIDs(aSubO, anIDs);
1617 else if (anIDs->length() > 0) {
1619 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1623 case GEOM::FSM_GetSame:
1626 aSubO = aShapesOp->GetSame(theObject, anArgO);
1629 case GEOM::FSM_GetShapesOnShape:
1631 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1632 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1633 (short)GEOM::SOLID, GEOM::ST_ONIN);
1636 case GEOM::FSM_GetInPlaceByHistory:
1638 // Use GetInPlaceByHistory
1639 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1646 if (!CORBA::is_nil(aSubO)) {
1647 // add to parts list
1648 addToListOfGO( aSubO, aParts );
1650 // Publish the sub-shape
1651 SALOMEDS::SObject_var aSubSO;
1652 if (!CORBA::is_nil(theSObject)) {
1653 TCollection_AsciiString aSubName;
1657 aSubName += anArgName;
1658 aSubSO = aStudyBuilder->NewObject(theSObject);
1659 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1661 aSubO->SetColor(anArgO->GetColor());
1663 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1664 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1665 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1666 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1670 if (!CORBA::is_nil(anArgSO)) {
1671 // Restore published sub-shapes of the argument
1672 GEOM::ListOfGO_var aSubParts;
1673 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1674 // pass theObject, because only it has the history
1675 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1676 theObject, anArgs, theFindMethod, theAddPrefix);
1678 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1679 aSubO, anArgs, theFindMethod, theAddPrefix);
1680 // add to parts list
1681 addToListOfGO( aSubParts, aParts );
1684 else { // GetInPlace failed, try to build from published parts
1685 if (!CORBA::is_nil(anArgSO)) {
1686 SALOMEDS::SObject_var aSubSO;
1687 if (!CORBA::is_nil(theSObject))
1688 aSubSO = aStudyBuilder->NewObject(theSObject);
1690 // Restore published sub-shapes of the argument
1691 GEOM::ListOfGO_var aSubParts =
1692 RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1693 theObject, anArgs, theFindMethod, theAddPrefix);
1695 // add to parts list
1696 addToListOfGO( aSubParts, aParts );
1698 if (aSubParts->length() > 0) {
1699 // try to build an argument from a set of its sub-shapes,
1700 // that published and will be reconstructed
1701 if (aSubParts->length() > 1) {
1702 aSubO = aShapesOp->MakeCompound(aSubParts);
1703 // add to parts list
1704 addToListOfGO( aSubO, aParts );
1707 aSubO = aSubParts[0];
1709 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1710 // Publish the sub-shape
1711 TCollection_AsciiString aSubName;
1713 aSubName = "from_parts_of_";
1715 aSubName += anArgName;
1716 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1718 aSubO->SetColor(anArgO->GetColor());
1720 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1721 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1722 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1723 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1727 else if (!CORBA::is_nil(aSubSO)) {
1728 // remove created aSubSO, because no parts have been found
1729 aStudyBuilder->RemoveObject(aSubSO);
1732 } // try to build from published parts
1733 anArgSO->UnRegister();
1735 } // process arguments
1737 std::set<std::string> anObjEntryMap;
1738 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1740 int nb = aParts->length();
1741 aResParts->length(nb);
1744 Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1745 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1746 GEOM::TPythonDump pd (aFunction, true);
1749 for ( ; i < nb; i++ )
1751 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1752 if (CORBA::is_nil(anObj))
1754 char* anEntry = anObj->GetEntry();
1755 if (anObjEntryMap.count(anEntry))
1756 continue; // already treated
1757 anObjEntryMap.insert(anEntry);
1758 aResParts[nbRes++] = anObj;
1759 // clear python dump of object
1760 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1761 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1762 if ( !anObjFun.IsNull() )
1763 anObjFun->SetDescription( "" );
1769 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1770 i = 0; nb = theArgs.length(); j = 0;
1771 for ( ; i < nb; i++ )
1773 GEOM::GEOM_Object_var anObj = theArgs[ i ];
1774 if (CORBA::is_nil(anObj))
1776 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1782 pd <<"]" << ", " <<"GEOM.";
1783 switch (theFindMethod) {
1784 case GEOM::FSM_GetInPlace:
1785 pd << "FSM_GetInPlace"; break;
1786 case GEOM::FSM_MultiTransformed:
1787 pd << "FSM_MultiTransformed"; break;
1788 case GEOM::FSM_Transformed:
1789 pd << "FSM_Transformed"; break;
1790 case GEOM::FSM_GetSame:
1791 pd << "FSM_GetSame"; break;
1792 case GEOM::FSM_GetShapesOnShape:
1793 pd << "FSM_GetShapesOnShape"; break;
1794 case GEOM::FSM_GetInPlaceByHistory:
1796 pd << "FSM_GetInPlaceByHistory"; break;
1798 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1800 aResParts->length(nbRes);
1801 return aResParts._retn();
1804 //============================================================================
1805 // function : RestoreGivenSubShapesOneLevel
1806 // purpose : Private method
1807 //============================================================================
1808 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1809 SALOMEDS::SObject_ptr theOldSO,
1810 SALOMEDS::SObject_ptr theNewSO,
1811 GEOM::GEOM_Object_ptr theNewO,
1812 std::set<std::string> theArgs,
1813 GEOM::find_shape_method theFindMethod,
1814 CORBA::Boolean theAddPrefix)
1817 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1818 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1819 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1820 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1821 return aParts._retn();
1823 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1825 // Get interface, containing method, which we will use to reconstruct sub-shapes
1826 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1827 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1828 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1830 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1831 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1833 // Reconstruct published sub-shapes
1834 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1837 for (it->Init(); it->More(); it->Next()) {
1840 aParts->length(aLen);
1842 for (it->Init(); it->More(); it->Next()) {
1843 SALOMEDS::SObject_var anOldSubSO = it->Value();
1845 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1847 SALOMEDS::GenericAttribute_var anAttr;
1848 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1849 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1850 GEOM::GEOM_Object_var anOldSubO =
1851 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1853 bool okToContinue = false;
1855 if (!CORBA::is_nil(anOldSubO)) {
1856 CORBA::String_var anEntry = anOldSubO->GetEntry();
1857 okToContinue = theArgs.count(anEntry.in());
1861 // Find a sub-shape of theNewO in place of anOldSubO
1862 GEOM::GEOM_Object_var aNewSubO;
1863 switch (theFindMethod) {
1864 case GEOM::FSM_GetInPlace:
1867 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1870 case GEOM::FSM_MultiTransformed:
1872 // Only for Multi-transformations
1873 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
1874 if (!CORBA::is_nil(anArgOTrsf)) {
1875 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1876 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1877 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1878 anArgOTrsfFun->SetDescription("");
1879 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1883 case GEOM::FSM_Transformed:
1885 // transformation, cannot use GetInPlace, operate with indices
1886 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1887 if (anIDs->length() > 1) {
1889 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1890 if (!CORBA::is_nil(aNewSubO))
1891 aGroupOp->UnionIDs(aNewSubO, anIDs);
1895 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1899 case GEOM::FSM_GetSame:
1902 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1905 case GEOM::FSM_GetShapesOnShape:
1907 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1908 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1909 (short)GEOM::SOLID, GEOM::ST_ONIN);
1912 case GEOM::FSM_GetInPlaceByHistory:
1914 // Use GetInPlaceByHistory
1915 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1922 if (!CORBA::is_nil(aNewSubO)) {
1923 // add the part to the list
1924 aParts[i] = aNewSubO;
1926 // add to parts list
1927 addToListOfGO( aNewSubO, aNewParts );
1929 SALOMEDS::SObject_var aNewSubSO;
1930 if (!CORBA::is_nil(theNewSO)) {
1931 // Publish the sub-shape
1932 TCollection_AsciiString aSubName;
1936 aSubName += anArgName;
1937 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1938 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1940 aNewSubO->SetColor(anOldSubO->GetColor());
1942 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1943 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1944 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1945 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1948 // Restore published sub-shapes of the argument
1949 GEOM::ListOfGO_var aSubParts;
1950 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1951 // pass the main shape as Object, because only it has the history
1952 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1953 theNewO, theArgs, theFindMethod, theAddPrefix);
1955 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1956 aNewSubO, theArgs, theFindMethod, theAddPrefix);
1957 // add to parts list
1958 addToListOfGO( aSubParts, aNewParts );
1960 else { // GetInPlace failed, try to build from published parts
1961 SALOMEDS::SObject_var aNewSubSO;
1962 if (!CORBA::is_nil(theNewSO))
1963 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1965 // Restore published sub-shapes of the argument
1966 GEOM::ListOfGO_var aSubParts =
1967 RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1968 theNewO, theArgs, theFindMethod, theAddPrefix);
1969 // add to parts list
1970 addToListOfGO( aSubParts, aNewParts );
1972 if (aSubParts->length() > 0) {
1973 // try to build an object from a set of its sub-shapes,
1974 // that published and will be reconstructed
1975 if (aSubParts->length() > 1) {
1976 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1977 // add to parts list
1978 addToListOfGO( aNewSubO, aNewParts );
1981 aNewSubO = aSubParts[0];
1984 if (!CORBA::is_nil(aNewSubO)) {
1985 // add the part to the list
1986 aSubParts[i] = aNewSubO;
1989 // Publish the sub-shape
1990 if (!CORBA::is_nil(aNewSubSO)) {
1991 TCollection_AsciiString aSubName;
1993 aSubName = "from_parts_of_";
1995 aSubName += anArgName;
1996 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1998 aNewSubO->SetColor(anOldSubO->GetColor());
2000 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2001 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2002 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2003 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2008 else if (!CORBA::is_nil(aNewSubSO)) {
2009 // remove created aSubSO, because no parts have been found
2010 aStudyBuilder->RemoveObject(aNewSubSO);
2012 } // try to build from published parts
2015 } // iterate on published sub-shapes
2018 // add to parts list
2019 addToListOfGO( aNewParts, aParts );
2020 return aParts._retn();
2023 //============================================================================
2024 // function : register()
2025 // purpose : register 'name' in 'name_service'
2026 //============================================================================
2027 void GEOM_Gen_i::register_name(char * name)
2029 GEOM::GEOM_Gen_var g = _this();
2030 name_service->Register(g, name);
2033 //============================================================================
2036 //============================================================================
2037 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
2039 _impl->Undo(theStudyID);
2042 //============================================================================
2045 //============================================================================
2046 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
2048 _impl->Redo(theStudyID);
2051 //============================================================================
2052 // function : GetIBasicOperations
2054 //============================================================================
2055 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
2056 throw ( SALOME::SALOME_Exception )
2058 Unexpect aCatch(SALOME_SalomeException);
2059 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
2061 GEOM::GEOM_Gen_ptr engine = _this();
2063 //transfer reference on engine
2064 GEOM_IBasicOperations_i* aServant =
2065 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
2067 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2068 // activate the CORBA servant
2069 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
2070 return operations._retn();
2073 //============================================================================
2074 // function : GetITransformOperations
2076 //============================================================================
2077 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
2078 throw ( SALOME::SALOME_Exception )
2080 Unexpect aCatch(SALOME_SalomeException);
2081 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
2083 GEOM::GEOM_Gen_ptr engine = _this();
2085 GEOM_ITransformOperations_i* aServant =
2086 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
2088 // activate the CORBA servant
2089 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
2090 return operations._retn();
2093 //============================================================================
2094 // function : GetI3DPrimOperations
2096 //============================================================================
2097 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
2098 throw ( SALOME::SALOME_Exception )
2100 Unexpect aCatch(SALOME_SalomeException);
2101 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
2103 GEOM::GEOM_Gen_ptr engine = _this();
2105 GEOM_I3DPrimOperations_i* aServant =
2106 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
2107 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2109 // activate the CORBA servant
2110 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
2111 return operations._retn();
2114 //============================================================================
2115 // function : GetIShapesOperations
2117 //============================================================================
2118 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
2119 throw ( SALOME::SALOME_Exception )
2121 Unexpect aCatch(SALOME_SalomeException);
2122 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
2124 GEOM::GEOM_Gen_ptr engine = _this();
2126 GEOM_IShapesOperations_i* aServant =
2127 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
2129 // activate the CORBA servant
2130 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
2131 return operations._retn();
2134 //============================================================================
2135 // function : GetIBlocksOperations
2137 //============================================================================
2138 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
2139 throw ( SALOME::SALOME_Exception )
2141 Unexpect aCatch(SALOME_SalomeException);
2142 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
2144 GEOM::GEOM_Gen_ptr engine = _this();
2146 GEOM_IBlocksOperations_i* aServant =
2147 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
2149 // activate the CORBA servant
2150 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
2151 return operations._retn();
2154 //============================================================================
2155 // function : GetIBooleanOperations
2157 //============================================================================
2158 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
2159 throw ( SALOME::SALOME_Exception )
2161 Unexpect aCatch(SALOME_SalomeException);
2162 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
2164 GEOM::GEOM_Gen_ptr engine = _this();
2166 GEOM_IBooleanOperations_i* aServant =
2167 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
2169 // activate the CORBA servant
2170 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
2171 return operations._retn();
2174 //============================================================================
2175 // function : GetICurvesOperations
2177 //============================================================================
2178 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
2179 throw ( SALOME::SALOME_Exception )
2181 Unexpect aCatch(SALOME_SalomeException);
2182 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
2184 GEOM::GEOM_Gen_ptr engine = _this();
2186 GEOM_ICurvesOperations_i* aServant =
2187 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
2189 // activate the CORBA servant
2190 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
2191 return operations._retn();
2194 //============================================================================
2195 // function : GetILocalOperations
2197 //============================================================================
2198 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
2199 throw ( SALOME::SALOME_Exception )
2201 Unexpect aCatch(SALOME_SalomeException);
2202 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
2204 GEOM::GEOM_Gen_ptr engine = _this();
2206 GEOM_ILocalOperations_i* aServant =
2207 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
2209 // activate the CORBA servant
2210 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
2211 return operations._retn();
2214 //============================================================================
2215 // function : GetIHealingOperations
2217 //============================================================================
2218 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
2219 throw ( SALOME::SALOME_Exception )
2221 Unexpect aCatch(SALOME_SalomeException);
2222 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
2224 GEOM::GEOM_Gen_ptr engine = _this();
2226 GEOM_IHealingOperations_i* aServant =
2227 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
2229 // activate the CORBA servant
2230 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
2231 return operations._retn();
2234 //============================================================================
2235 // function : GetIInsertOperations
2237 //============================================================================
2238 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
2239 throw ( SALOME::SALOME_Exception )
2241 Unexpect aCatch(SALOME_SalomeException);
2242 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
2244 GEOM::GEOM_Gen_ptr engine = _this();
2246 GEOM_IInsertOperations_i* aServant =
2247 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
2249 // activate the CORBA servant
2250 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
2251 return operations._retn();
2254 //============================================================================
2255 // function : GetIMeasureOperations
2257 //============================================================================
2258 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
2259 throw ( SALOME::SALOME_Exception )
2261 Unexpect aCatch(SALOME_SalomeException);
2262 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
2264 GEOM::GEOM_Gen_ptr engine = _this();
2266 GEOM_IMeasureOperations_i* aServant =
2267 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
2269 // activate the CORBA servant
2270 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
2271 return operations._retn();
2274 //============================================================================
2275 // function : GetIGroupOperations
2277 //============================================================================
2278 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
2279 throw ( SALOME::SALOME_Exception )
2281 Unexpect aCatch(SALOME_SalomeException);
2282 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
2284 GEOM::GEOM_Gen_ptr engine = _this();
2286 GEOM_IGroupOperations_i* aServant =
2287 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
2289 // activate the CORBA servant
2290 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
2291 return operations._retn();
2294 //============================================================================
2295 // function : GetIAdvancedOperations
2297 //============================================================================
2298 GEOM::GEOM_IAdvancedOperations_ptr GEOM_Gen_i::GetIAdvancedOperations(CORBA::Long theStudyID)
2299 throw ( SALOME::SALOME_Exception )
2301 Unexpect aCatch(SALOME_SalomeException);
2302 MESSAGE( "GEOM_Gen_i::GetIAdvancedOperations" );
2304 GEOM::GEOM_Gen_ptr engine = _this();
2306 GEOM_IAdvancedOperations_i* aServant =
2307 new GEOM_IAdvancedOperations_i(_poa, engine, _impl->GetIAdvancedOperations(theStudyID));
2309 // activate the CORBA servant
2310 GEOM::GEOM_IAdvancedOperations_var operations = aServant->_this();
2311 return operations._retn();
2314 //=============================================================================
2318 //=============================================================================
2319 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
2320 const GEOM::ListOfLong& theIndices)
2322 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
2323 return GEOM::GEOM_Object::_nil();
2324 CORBA::String_var entry = theMainShape->GetEntry();
2325 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
2326 if (aMainShape.IsNull()) return GEOM::GEOM_Object::_nil();
2328 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
2329 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
2331 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true);
2332 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
2334 TCollection_AsciiString anEntry;
2335 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
2336 return GetObject(anObject->GetDocID(), anEntry.ToCString());
2339 //=============================================================================
2343 //=============================================================================
2344 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
2346 CORBA::String_var anEntry = theObject->GetEntry();
2347 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false);
2348 if (anObject.IsNull()) return;
2349 _impl->RemoveObject(anObject);
2354 //=================================================================================
2355 // function : GetStringFromIOR()
2356 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
2357 //=================================================================================
2358 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
2359 return _orb->object_to_string(theObject);
2363 //=================================================================================
2364 // function : GetIORFromString()
2365 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
2366 //=================================================================================
2367 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
2368 GEOM::GEOM_Object_var aGeomObject;
2369 if(strcmp(stringIOR,"") != 0){
2370 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
2371 if(!CORBA::is_nil(anObject))
2372 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
2374 return aGeomObject._retn();
2377 //=================================================================================
2378 // function : GetObject()
2380 //=================================================================================
2381 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
2383 GEOM::GEOM_Object_var obj;
2384 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
2385 if (handle_object.IsNull()) return obj._retn();
2387 TCollection_AsciiString stringIOR = handle_object->GetIOR();
2388 if (stringIOR.Length() > 1) {
2389 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
2390 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
2394 GEOM::GEOM_Gen_ptr engine = _this();
2395 //transfer the reference to GEOM_Object_i
2396 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
2397 PortableServer::ObjectId_var id = _poa->activate_object(servant);
2399 obj = servant->_this();
2400 CORBA::String_var objStr = _orb->object_to_string(obj);
2401 TCollection_AsciiString anAscii( (char *)objStr.in() );
2402 handle_object->SetIOR( anAscii );
2406 //=================================================================================
2407 // function : hasObjectInfo()
2408 // purpose : shows if module provides information for its objects
2409 //=================================================================================
2410 bool GEOM_Gen_i::hasObjectInfo()
2415 //=================================================================================
2416 // function : getObjectInfo()
2417 // purpose : returns an information for a given object by its entry
2418 //=================================================================================
2419 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
2421 GEOM::GEOM_Object_var aGeomObject;
2423 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
2424 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
2425 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
2426 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
2427 SALOMEDS::SObject_var aResultSObj;
2428 if (aSObj->ReferencedObject(aResultSObj))
2429 aSObj = aResultSObj;
2431 SALOMEDS::GenericAttribute_var anAttr;
2432 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
2433 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2434 CORBA::String_var aVal = anIOR->Value();
2435 anIOR->UnRegister();
2436 CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
2437 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
2439 if (!aSObj->_is_nil() )
2440 aSObj->UnRegister();
2442 const char* aTypeInfo = "Object";
2443 if ( !aGeomObject->_is_nil() ) {
2444 GEOM::GEOM_IKindOfShape::shape_kind aKind;
2445 GEOM::ListOfLong_var anInts;
2446 GEOM::ListOfDouble_var aDbls;
2448 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
2449 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
2451 if ( anOp->IsDone() ) {
2453 case GEOM::GEOM_IKindOfShape::COMPOUND:
2454 aTypeInfo = "Compound";
2456 case GEOM::GEOM_IKindOfShape::COMPSOLID:
2457 aTypeInfo = "CompSolid";
2459 case GEOM::GEOM_IKindOfShape::SHELL:
2460 aTypeInfo = "Shell";
2462 case GEOM::GEOM_IKindOfShape::WIRE:
2463 if ( anInts[0] == 1 )
2464 aTypeInfo = "Closed Wire";
2465 else if ( anInts[0] == 2 )
2466 aTypeInfo = "Opened Wire";
2471 case GEOM::GEOM_IKindOfShape::SPHERE:
2472 aTypeInfo = "Sphere";
2474 case GEOM::GEOM_IKindOfShape::CYLINDER:
2475 aTypeInfo = "Cylinder";
2477 case GEOM::GEOM_IKindOfShape::BOX:
2478 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
2481 case GEOM::GEOM_IKindOfShape::TORUS:
2482 aTypeInfo = "Torus";
2484 case GEOM::GEOM_IKindOfShape::CONE:
2487 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
2488 aTypeInfo = "Polyhedron";
2490 case GEOM::GEOM_IKindOfShape::SOLID:
2491 aTypeInfo = "Solid";
2494 case GEOM::GEOM_IKindOfShape::SPHERE2D:
2495 aTypeInfo = "Spherical Face";
2497 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
2498 aTypeInfo = "Cylindrical Face";
2500 case GEOM::GEOM_IKindOfShape::TORUS2D:
2501 aTypeInfo = "Toroidal Face";
2503 case GEOM::GEOM_IKindOfShape::CONE2D:
2504 aTypeInfo = "Conical Face";
2506 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
2509 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
2510 aTypeInfo = "Elliptical Face";
2512 case GEOM::GEOM_IKindOfShape::POLYGON:
2513 aTypeInfo = "Polygon";
2515 case GEOM::GEOM_IKindOfShape::PLANE:
2516 aTypeInfo = "Plane";
2518 case GEOM::GEOM_IKindOfShape::PLANAR:
2519 aTypeInfo = "Planar Face";
2521 case GEOM::GEOM_IKindOfShape::FACE:
2525 case GEOM::GEOM_IKindOfShape::CIRCLE:
2526 aTypeInfo = "Circle";
2528 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
2529 aTypeInfo = "Arc Circle";
2531 case GEOM::GEOM_IKindOfShape::ELLIPSE:
2532 aTypeInfo = "Ellipse";
2534 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
2535 aTypeInfo = "Arc Ellipse";
2537 case GEOM::GEOM_IKindOfShape::LINE:
2540 case GEOM::GEOM_IKindOfShape::SEGMENT:
2541 aTypeInfo = "Segment";
2543 case GEOM::GEOM_IKindOfShape::EDGE:
2546 case GEOM::GEOM_IKindOfShape::VERTEX:
2547 aTypeInfo = "Vertex";
2555 char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
2556 sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
2558 char* ret = CORBA::string_dup(anInfo);
2563 // Version information
2564 char* GEOM_Gen_i::getVersion()
2566 #if GEOM_DEVELOPMENT
2567 return CORBA::string_dup(GEOM_VERSION_STR"dev");
2569 return CORBA::string_dup(GEOM_VERSION_STR);
2573 //=====================================================================================
2575 //=====================================================================================
2580 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
2584 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb,
2585 PortableServer::POA_ptr poa,
2586 PortableServer::ObjectId* contId,
2587 const char* instanceName,
2588 const char* interfaceName)
2590 GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
2591 return myGEOM_Gen_i->getId();