1 // Copyright (C) 2007-2012 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);
580 SALOMEDS::Study_var Study = theComponent->GetStudy();
581 TCollection_AsciiString name (Study->Name());
587 //============================================================================
588 // function : LoadASCII()
590 //============================================================================
591 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
592 const SALOMEDS::TMPFile& theStream,
595 return Load(theComponent, theStream, theURL, isMultiFile);
599 //============================================================================
600 // function : Close()
602 //============================================================================
603 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
605 SALOMEDS::Study_var aStudy= theComponent->GetStudy();
606 _impl->Close(aStudy->StudyId());
609 //============================================================================
610 // function : CanCopy()
612 //============================================================================
613 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
614 // Try to retrieve known by Geometry component GEOM_Object by given IOR
615 SALOMEDS::GenericAttribute_var anAttr;
616 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
618 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
620 CORBA::String_var aString=anIOR->Value();
622 CORBA::Object_var anObj = _orb->string_to_object(aString);
623 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(anObj);
624 // If the object is null one it can't be copied: return false
625 if (anObject->_is_nil()) return false;
629 //============================================================================
630 // function : CopyFrom()
632 //============================================================================
633 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
635 // Declare a sequence of the byte to store the copied object
636 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
638 // Try to get GEOM_Object object by given SObject
639 SALOMEDS::GenericAttribute_var anAttr;
640 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
641 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
642 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
643 if (anObject->_is_nil()) return aStreamFile._retn();
645 aStreamFile = anObject->GetShapeStream();
647 // Assign an ID the type of GEOM_Object
648 theObjectID = anObject->GetType();
650 // Return created TMPFile
651 return aStreamFile._retn();
654 //============================================================================
655 // function : CanPaste()
657 //============================================================================
658 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
659 // The Geometry component can paste only objects copied by Geometry component
660 // and with the object type = 1
661 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
665 //============================================================================
666 // function : PasteInto()
668 //============================================================================
669 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
670 CORBA::Long theObjectID,
671 SALOMEDS::SObject_ptr theObject) {
672 // Find the current Study and StudyBuilder
673 SALOMEDS::Study_var aStudy = theObject->GetStudy();
674 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
676 // Retrieve a TopoDS_Shape from byte stream
677 TopoDS_Shape aTopology;
678 std::istringstream aStreamedBrep((char*) &theStream[0]);
679 BRep_Builder aBuilder;
681 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
682 } catch (Standard_Failure) {
686 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
687 SALOMEDS::SObject_var aNewSO;
688 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
689 aNewSO = aStudyBuilder->NewObject(theObject);
690 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
693 //Create a new GEOM_Object
694 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
695 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
696 aFunction->SetValue(aTopology);
698 TCollection_AsciiString anEntry;
699 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
700 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
702 //Set the study entry of the published GEOM_Object
703 obj->SetStudyEntry(aNewSO->GetID());
705 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
706 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
707 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
708 CORBA::String_var objStr = _orb->object_to_string(obj);
709 anIOR->SetValue(objStr.in());
712 // Return the created in the Study SObject
713 return aNewSO._retn();
716 //============================================================================
717 // function : ComponentDataType()
719 //============================================================================
720 char* GEOM_Gen_i::ComponentDataType()
722 return CORBA::string_dup("GEOM");
725 //============================================================================
726 // function : AddInStudy
728 //============================================================================
729 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
730 GEOM::GEOM_Object_ptr theObject,
732 GEOM::GEOM_Object_ptr theFather)
734 SALOMEDS::SObject_var aResultSO;
735 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
737 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
738 CORBA::String_var IOR;
740 if(!theFather->_is_nil()) {
741 IOR = _orb->object_to_string(theFather);
742 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in());
743 if(aFatherSO->_is_nil()) return aResultSO._retn();
744 aResultSO = aStudyBuilder->NewObject(aFatherSO);
745 aFatherSO->UnRegister();
746 //aStudyBuilder->Addreference(aResultSO, aResultSO);
749 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
750 if(aResultSO->_is_nil()) return aResultSO._retn();
752 GEOM::ListOfGO_var aList = theObject->GetDependency();
753 Standard_Integer aLength = aList->length();
754 if(aLength < 1) return aResultSO._retn();
756 //Publish the arguments
757 TCollection_AsciiString aPrevID; // to avoid multiple references to same object
758 for(Standard_Integer i = 0; i< aLength; i++) {
759 GEOM::GEOM_Object_var anObject = aList[i];
760 if(anObject->_is_nil()) continue;
761 IOR = _orb->object_to_string(anObject);
762 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR.in());
763 if(aSO->_is_nil()) continue;
764 CORBA::String_var anID = aSO->GetID();
765 if ( aPrevID == anID.in() ) continue;
767 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
768 aStudyBuilder->Addreference(aSubSO, aSO);
770 aSubSO->UnRegister();
773 return aResultSO._retn();
776 //============================================================================
777 // function : RestoreSubShapesO
778 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
779 // To be used from python scripts out of geompy.addToStudy (non-default usage)
780 //============================================================================
781 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
782 GEOM::GEOM_Object_ptr theObject,
783 const GEOM::ListOfGO& theArgs,
784 GEOM::find_shape_method theFindMethod,
785 CORBA::Boolean theInheritFirstArg,
786 CORBA::Boolean theAddPrefix)
788 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
789 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
790 return aParts._retn();
792 // find SObject in the study if it is already published
793 CORBA::String_var anIORo = _orb->object_to_string(theObject);
794 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
795 //PTv, IMP 0020001, The salome object <aSO>
796 // is not obligatory in case of invokation from script
797 // if (CORBA::is_nil(aSO))
798 // return aParts._retn();
800 aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs,
801 theFindMethod, theInheritFirstArg, theAddPrefix);
802 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
803 return aParts._retn();
806 //============================================================================
807 // function : RestoreGivenSubShapesO
808 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
809 // To be used from python scripts, generated by Dump Python.
810 //============================================================================
811 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (SALOMEDS::Study_ptr theStudy,
812 GEOM::GEOM_Object_ptr theObject,
813 const GEOM::ListOfGO& theArgs,
814 GEOM::find_shape_method theFindMethod,
815 CORBA::Boolean theInheritFirstArg,
816 CORBA::Boolean theAddPrefix)
818 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
819 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
820 return aParts._retn();
822 // find SObject in the study if it is already published
823 CORBA::String_var anIORo = _orb->object_to_string(theObject);
824 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
825 //PTv, IMP 0020001, The salome object <aSO>
826 // is not obligatory in case of invokation from script
827 // if (CORBA::is_nil(aSO))
828 // return aParts._retn();
830 aParts = RestoreGivenSubShapes(theStudy, theObject, aSO, theArgs,
831 theFindMethod, theInheritFirstArg, theAddPrefix);
832 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
833 return aParts._retn();
836 //============================================================================
837 // function : RestoreSubShapesSO
838 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
839 // To be used from GUI and from geompy.addToStudy
840 //============================================================================
841 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
842 SALOMEDS::SObject_ptr theSObject,
843 const GEOM::ListOfGO& theArgs,
844 GEOM::find_shape_method theFindMethod,
845 CORBA::Boolean theInheritFirstArg,
846 CORBA::Boolean theAddPrefix)
848 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
849 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
850 return aParts._retn();
852 SALOMEDS::GenericAttribute_var anAttr;
853 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
854 return aParts._retn();
856 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
857 CORBA::String_var anIORso = anAttrIOR->Value();
859 // get Object from SObject
860 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
861 if (CORBA::is_nil(anO))
862 return aParts._retn();
864 aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs,
865 theFindMethod, theInheritFirstArg, theAddPrefix);
866 return aParts._retn();
869 //============================================================================
870 // function : addToListOfGO
871 // purpose : static local function
872 //============================================================================
873 static void addToListOfGO( GEOM::GEOM_Object_ptr theObject,
874 GEOM::ListOfGO& theList )
876 const int oldLen = theList.length();
877 theList.length(oldLen + 1);
878 theList[ oldLen ] = GEOM::GEOM_Object::_duplicate( theObject );
881 //============================================================================
882 // function : addToListOfGO
883 // purpose : static local function
884 //============================================================================
885 static void addToListOfGO( const GEOM::ListOfGO& theSrcList,
886 GEOM::ListOfGO& theTrgList )
888 const int oldLen = theTrgList.length();
889 const int srcLen = theSrcList.length();
890 theTrgList.length(oldLen + srcLen);
891 for( int i = 0; i < srcLen; i++ )
892 theTrgList[ oldLen + i ] = GEOM::GEOM_Object::_duplicate( theSrcList[ i ] );
895 //============================================================================
896 // function : RestoreSubShapes
897 // purpose : Private method. Works only if both theObject and theSObject
898 // are defined, and does not check, if they correspond to each other.
899 //============================================================================
900 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy,
901 GEOM::GEOM_Object_ptr theObject,
902 SALOMEDS::SObject_ptr theSObject,
903 const GEOM::ListOfGO& theArgs,
904 GEOM::find_shape_method theFindMethod,
905 CORBA::Boolean theInheritFirstArg,
906 CORBA::Boolean theAddPrefix)
908 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
909 //PTv, IMP 0020001, The salome object <theSObject>
910 // is not obligatory in case of invokation from script
911 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
912 return aParts._retn();
914 // For Dump Python (mantis issue 0020768)
915 GEOM::ListOfGO_var anOutArgs = new GEOM::ListOfGO;
917 // Arguments to be published
918 GEOM::ListOfGO_var aList;
920 // If theArgs list is empty, we try to publish all arguments,
921 // otherwise publish only passed args
922 Standard_Integer nbArgsActual = -1; // -1 means unknown
923 Standard_Integer aLength = theArgs.length();
925 aList = new GEOM::ListOfGO;
926 aList->length(aLength);
927 for (int i = 0; i < aLength; i++) {
928 aList[i] = GEOM::GEOM_Object::_duplicate( theArgs[i] );
933 aList = theObject->GetDependency();
934 aLength = aList->length();
935 nbArgsActual = aLength;
939 return aParts._retn();
941 if (theInheritFirstArg || (nbArgsActual == 1)) {
942 // Do not publish argument's reflection,
943 // but only reconstruct its published sub-shapes
945 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
946 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
948 // remember restored objects for Python Dump
949 addToListOfGO(aList[0], anOutArgs);
951 aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
952 anOutArgs, theFindMethod, theAddPrefix);
954 // set the color of the transformed shape to the color of initial shape
955 theObject->SetColor(aList[0]->GetColor());
957 if (theObject->GetShapeType() == GEOM::VERTEX) {
958 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
959 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
960 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
963 anArgSO->UnRegister();
966 // Get interface, containing method, which we will use to reconstruct sub-shapes
967 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
968 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
969 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
971 // Reconstruct arguments and tree of sub-shapes of the arguments
972 CORBA::String_var anIOR;
973 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
974 for (Standard_Integer i = 0; i < aLength; i++)
976 GEOM::GEOM_Object_var anArgO = aList[i];
977 if (!CORBA::is_nil(anArgO)) {
978 anIOR = _orb->object_to_string(anArgO);
979 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
980 TCollection_AsciiString anArgName;
981 if (CORBA::is_nil(anArgSO)) {
983 anArgName += TCollection_AsciiString(i);
986 anArgName = anArgSO->GetName();
989 // Find a sub-shape of theObject in place of the argument
990 GEOM::GEOM_Object_var aSubO;
991 switch (theFindMethod) {
992 case GEOM::FSM_GetInPlace:
995 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
998 case GEOM::FSM_MultiTransformed:
1000 // Only for Multi-transformations
1001 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anArgO, theObject);
1002 if (!CORBA::is_nil(anArgOTrsf)) {
1003 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1004 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1005 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1006 anArgOTrsfFun->SetDescription("");
1007 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1010 Handle(GEOM_Function) anOFun = theObject->GetLastFunction();
1011 if (!anOFun.IsNull()) {
1012 CORBA::String_var entryArg = anArgO->GetEntry();
1013 Handle(GEOM_Object) anArgOImpl = _impl->GetObject(anArgO->GetStudyID(), entryArg);
1014 if (!anArgOImpl.IsNull()) {
1015 TopoDS_Shape anArgOShape = anArgOImpl->GetValue();
1016 TopoDS_Shape aMultiArgShape;
1017 //GEOM::GEOM_Object_var anArgOMulti; // ???
1018 switch (anOFun->GetType()) {
1021 GEOMImpl_ITranslate aTI (anOFun);
1022 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape1D(anArgOShape, &aTI);
1023 //anArgOMulti = aTrsfOp->Translate1D(anArgO, , , );
1028 GEOMImpl_ITranslate aTI (anOFun);
1029 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1034 GEOMImpl_IRotate aTI (anOFun);
1035 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1040 GEOMImpl_IRotate aTI (anOFun);
1041 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1047 GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO
1048 Handle(GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction();
1049 anArgOMultiFun->SetDescription("");
1050 aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti);
1056 case GEOM::FSM_Transformed:
1058 // transformation, cannot use GetInPlace, operate with indices
1059 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1060 if (anIDs->length() > 1) {
1062 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1063 if (!CORBA::is_nil(aSubO))
1064 aGroupOp->UnionIDs(aSubO, anIDs);
1066 else if (anIDs->length() > 0) {
1068 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1072 case GEOM::FSM_GetSame:
1075 aSubO = aShapesOp->GetSame(theObject, anArgO);
1078 case GEOM::FSM_GetShapesOnShape:
1080 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1081 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1082 (short)GEOM::SOLID, GEOM::ST_ONIN);
1085 case GEOM::FSM_GetInPlaceByHistory:
1087 // Use GetInPlaceByHistory
1088 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1095 if (!CORBA::is_nil(aSubO)) {
1096 // remember restored objects for Python Dump
1097 addToListOfGO(anArgO, anOutArgs);
1099 // add to parts list
1100 addToListOfGO( aSubO, aParts );
1102 // Publish the sub-shape
1103 SALOMEDS::SObject_var aSubSO;
1104 if (!CORBA::is_nil(theSObject)) {
1105 TCollection_AsciiString aSubName;
1109 aSubName += anArgName;
1110 aSubSO = aStudyBuilder->NewObject(theSObject);
1111 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1113 aSubO->SetColor(anArgO->GetColor());
1115 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1116 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1117 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1118 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1122 if (!CORBA::is_nil(anArgSO)) {
1123 // Restore published sub-shapes of the argument
1124 GEOM::ListOfGO_var aSubParts;
1125 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1126 // pass theObject, because only it has the history
1127 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1128 theObject, anOutArgs, theFindMethod, theAddPrefix);
1130 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1131 aSubO, anOutArgs, theFindMethod, theAddPrefix);
1132 // add to parts list
1133 addToListOfGO( aSubParts, aParts );
1136 else { // GetInPlace failed, try to build from published parts
1137 if (!CORBA::is_nil(anArgSO)) {
1138 SALOMEDS::SObject_var aSubSO;
1139 if (!CORBA::is_nil(theSObject))
1140 aSubSO = aStudyBuilder->NewObject(theSObject);
1142 // Restore published sub-shapes of the argument
1143 GEOM::ListOfGO_var aSubParts =
1144 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1145 theObject, anOutArgs, theFindMethod, theAddPrefix);
1147 // add to parts list
1148 addToListOfGO( aSubParts, aParts );
1150 if (aSubParts->length() > 0) {
1151 // remember restored objects for Python Dump
1152 addToListOfGO(anArgO, anOutArgs);
1154 // try to build an argument from a set of its sub-shapes,
1155 // that published and will be reconstructed
1156 if (aSubParts->length() > 1) {
1157 aSubO = aShapesOp->MakeCompound(aSubParts);
1158 // add to parts list
1159 addToListOfGO( aSubO, aParts );
1162 aSubO = aSubParts[0];
1164 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1165 // Publish the sub-shape
1166 TCollection_AsciiString aSubName;
1168 aSubName = "from_parts_of_";
1170 aSubName += anArgName;
1171 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1173 aSubO->SetColor(anArgO->GetColor());
1175 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1176 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1177 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1178 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1182 else if (!CORBA::is_nil(aSubSO)) {
1183 // remove created aSubSO, because no parts have been found
1184 aStudyBuilder->RemoveObject(aSubSO);
1187 } // try to build from published parts
1188 anArgSO->UnRegister();
1190 } // process arguments
1192 std::set<std::string> anObjEntryMap;
1193 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1195 int nb = aParts->length();
1196 aResParts->length(nb);
1199 Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1200 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1201 GEOM::TPythonDump pd (aFunction, true);
1204 for ( ; i < nb; i++ )
1206 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1207 if (CORBA::is_nil(anObj))
1209 char* anEntry = anObj->GetEntry();
1210 if (anObjEntryMap.count(anEntry))
1211 continue; // already treated
1212 anObjEntryMap.insert(anEntry);
1213 aResParts[nbRes++] = anObj;
1214 // clear python dump of object
1215 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1216 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1217 if ( !anObjFun.IsNull() )
1218 anObjFun->SetDescription( "" );
1224 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1225 //i = 0; nb = theArgs.length(); j = 0;
1226 i = 0; nb = anOutArgs->length(); j = 0;
1227 for ( ; i < nb; i++ )
1229 //GEOM::GEOM_Object_var anObj = theArgs[ i ];
1230 GEOM::GEOM_Object_var anObj = anOutArgs[ i ];
1231 if (CORBA::is_nil(anObj))
1233 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1239 pd <<"]" << ", " <<"geompy.GEOM.";
1240 switch (theFindMethod) {
1241 case GEOM::FSM_GetInPlace:
1242 pd << "FSM_GetInPlace"; break;
1243 case GEOM::FSM_MultiTransformed:
1244 pd << "FSM_MultiTransformed"; break;
1245 case GEOM::FSM_Transformed:
1246 pd << "FSM_Transformed"; break;
1247 case GEOM::FSM_GetSame:
1248 pd << "FSM_GetSame"; break;
1249 case GEOM::FSM_GetShapesOnShape:
1250 pd << "FSM_GetShapesOnShape"; break;
1251 case GEOM::FSM_GetInPlaceByHistory:
1253 pd << "FSM_GetInPlaceByHistory"; break;
1255 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1257 aResParts->length(nbRes);
1258 return aResParts._retn();
1261 //============================================================================
1262 // function : RestoreSubShapesOneLevel
1263 // purpose : Private method
1264 //============================================================================
1265 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1266 SALOMEDS::SObject_ptr theOldSO,
1267 SALOMEDS::SObject_ptr theNewSO,
1268 GEOM::GEOM_Object_ptr theNewO,
1269 GEOM::ListOfGO& theOutArgs,
1270 GEOM::find_shape_method theFindMethod,
1271 CORBA::Boolean theAddPrefix)
1274 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1275 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1276 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1277 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1278 return aParts._retn();
1280 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1282 // Get interface, containing method, which we will use to reconstruct sub-shapes
1283 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1284 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1285 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1287 // Reconstruct published sub-shapes
1288 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1291 for (it->Init(); it->More(); it->Next()) {
1294 aParts->length(aLen);
1296 for (it->Init(); it->More(); it->Next()) {
1297 SALOMEDS::SObject_var anOldSubSO = it->Value();
1299 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1301 SALOMEDS::GenericAttribute_var anAttr;
1302 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1303 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1304 GEOM::GEOM_Object_var anOldSubO =
1305 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1306 if (!CORBA::is_nil(anOldSubO)) {
1307 // Find a sub-shape of theNewO in place of anOldSubO
1308 GEOM::GEOM_Object_var aNewSubO;
1309 switch (theFindMethod) {
1310 case GEOM::FSM_GetInPlace:
1313 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1316 case GEOM::FSM_MultiTransformed:
1318 // Only for Multi-transformations
1319 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anOldSubO, theNewO);
1320 if (!CORBA::is_nil(anArgOTrsf)) {
1321 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1322 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1323 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1324 anArgOTrsfFun->SetDescription("");
1325 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1329 case GEOM::FSM_Transformed:
1331 // transformation, cannot use GetInPlace, operate with indices
1332 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1333 if (anIDs->length() > 1) {
1335 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1336 if (!CORBA::is_nil(aNewSubO))
1337 aGroupOp->UnionIDs(aNewSubO, anIDs);
1341 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1345 case GEOM::FSM_GetSame:
1348 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1351 case GEOM::FSM_GetShapesOnShape:
1353 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1354 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1355 (short)GEOM::SOLID, GEOM::ST_ONIN);
1358 case GEOM::FSM_GetInPlaceByHistory:
1360 // Use GetInPlaceByHistory
1361 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1368 if (!CORBA::is_nil(aNewSubO)) {
1369 // remember restored objects for Python Dump
1370 addToListOfGO(anOldSubO, theOutArgs);
1372 // add the part to the list
1373 aParts[i] = aNewSubO;
1375 // add to parts list
1376 addToListOfGO( aNewSubO, aNewParts );
1378 SALOMEDS::SObject_var aNewSubSO;
1379 if (!CORBA::is_nil(theNewSO)) {
1380 // Publish the sub-shape
1381 TCollection_AsciiString aSubName;
1385 aSubName += anArgName;
1386 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1387 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1389 aNewSubO->SetColor(anOldSubO->GetColor());
1391 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1392 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1393 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1394 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1397 // Restore published sub-shapes of the argument
1398 GEOM::ListOfGO_var aSubParts;
1399 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1400 // pass the main shape as Object, because only it has the history
1401 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1402 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1404 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1405 aNewSubO, theOutArgs, theFindMethod, theAddPrefix);
1406 // add to parts list
1407 addToListOfGO( aSubParts, aNewParts );
1409 else { // GetInPlace failed, try to build from published parts
1410 SALOMEDS::SObject_var aNewSubSO;
1411 if (!CORBA::is_nil(theNewSO))
1412 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1414 // Restore published sub-shapes of the argument
1415 GEOM::ListOfGO_var aSubParts =
1416 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1417 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1418 // add to parts list
1419 addToListOfGO( aSubParts, aNewParts );
1421 if (aSubParts->length() > 0) {
1422 // remember restored objects for Python Dump
1423 addToListOfGO(anOldSubO, theOutArgs);
1425 // try to build an object from a set of its sub-shapes,
1426 // that published and will be reconstructed
1427 if (aSubParts->length() > 1) {
1428 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1429 // add to parts list
1430 addToListOfGO( aNewSubO, aNewParts );
1433 aNewSubO = aSubParts[0];
1436 if (!CORBA::is_nil(aNewSubO)) {
1437 // add the part to the list
1438 aSubParts[i] = aNewSubO;
1441 // Publish the sub-shape
1442 if (!CORBA::is_nil(aNewSubSO)) {
1443 TCollection_AsciiString aSubName;
1445 aSubName = "from_parts_of_";
1447 aSubName += anArgName;
1448 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1450 aNewSubO->SetColor(anOldSubO->GetColor());
1452 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1453 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1454 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1455 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1460 else if (!CORBA::is_nil(aNewSubSO)) {
1461 // remove created aSubSO, because no parts have been found
1462 aStudyBuilder->RemoveObject(aNewSubSO);
1464 } // try to build from published parts
1467 } // iterate on published sub-shapes
1470 // add to parts list
1471 addToListOfGO( aNewParts, aParts );
1472 return aParts._retn();
1475 //============================================================================
1476 // function : RestoreGivenSubShapes
1477 // purpose : Private method. Works only if both theObject and theSObject
1478 // are defined, and does not check, if they correspond to each other.
1479 // List theArgs in this case contains not only operation arguments,
1480 // but also all subshapes, which must be published.
1481 //============================================================================
1482 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStudy,
1483 GEOM::GEOM_Object_ptr theObject,
1484 SALOMEDS::SObject_ptr theSObject,
1485 const GEOM::ListOfGO& theArgs,
1486 GEOM::find_shape_method theFindMethod,
1487 CORBA::Boolean theInheritFirstArg,
1488 CORBA::Boolean theAddPrefix)
1490 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1491 //PTv, IMP 0020001, The salome object <theSObject>
1492 // is not obligatory in case of invokation from script
1493 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
1494 return aParts._retn();
1496 // If theArgs list is empty, nothing to do
1497 Standard_Integer aLength = theArgs.length();
1499 return aParts._retn();
1501 // Get all arguments
1502 GEOM::ListOfGO_var anOpArgsList = theObject->GetDependency();
1503 Standard_Integer nbArgsActual = anOpArgsList->length();
1505 // If anOpArgsList list is empty, nothing to do
1506 if (nbArgsActual == 0)
1507 return aParts._retn();
1509 // Entries of arguments and subshapes
1510 std::set<std::string> anArgs;
1511 for (int i = 0; i < aLength; i++) {
1512 CORBA::String_var anEntry = theArgs[i]->GetEntry();
1513 anArgs.insert(anEntry.in());
1516 // Arguments to be published
1517 // We try to publish all arguments, that are in theArgs list
1518 GEOM::ListOfGO_var aList = new GEOM::ListOfGO;
1519 aList->length(nbArgsActual);
1522 for (int j = 0; j < nbArgsActual; j++) {
1523 CORBA::String_var anEntry = anOpArgsList[j]->GetEntry();
1524 if (anArgs.count(anEntry.in())) {
1525 aList[k] = GEOM::GEOM_Object::_duplicate(anOpArgsList[j]);
1530 //aList->length(nbArgsActual);
1532 if (nbArgsActual < 1)
1533 return aParts._retn();
1535 if (theInheritFirstArg || (nbArgsActual == 1)) {
1536 // Do not publish argument's reflection,
1537 // but only reconstruct its published sub-shapes
1539 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1540 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1542 aParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
1543 anArgs, theFindMethod, theAddPrefix);
1545 // set the color of the transformed shape to the color of initial shape
1546 theObject->SetColor(aList[0]->GetColor());
1548 if (theObject->GetShapeType() == GEOM::VERTEX) {
1549 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1550 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1551 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1554 anArgSO->UnRegister();
1557 // Get interface, containing method, which we will use to reconstruct sub-shapes
1558 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1559 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1560 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1562 // Reconstruct arguments and tree of sub-shapes of the arguments
1563 CORBA::String_var anIOR;
1564 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1565 for (Standard_Integer i = 0; i < nbArgsActual; i++)
1567 GEOM::GEOM_Object_var anArgO = aList[i];
1568 if (!CORBA::is_nil(anArgO)) {
1569 anIOR = _orb->object_to_string(anArgO);
1570 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1571 TCollection_AsciiString anArgName;
1572 if (CORBA::is_nil(anArgSO)) {
1574 anArgName += TCollection_AsciiString(i);
1577 anArgName = anArgSO->GetName();
1580 // Find a sub-shape of theObject in place of the argument
1581 GEOM::GEOM_Object_var aSubO;
1582 switch (theFindMethod) {
1583 case GEOM::FSM_GetInPlace:
1586 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1589 case GEOM::FSM_MultiTransformed:
1591 // Only for Multi-transformations
1592 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anArgO, theObject);
1593 if (!CORBA::is_nil(anArgOTrsf)) {
1594 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1595 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1596 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1597 anArgOTrsfFun->SetDescription("");
1598 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1602 case GEOM::FSM_Transformed:
1604 // transformation, cannot use GetInPlace, operate with indices
1605 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1606 if (anIDs->length() > 1) {
1608 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1609 if (!CORBA::is_nil(aSubO))
1610 aGroupOp->UnionIDs(aSubO, anIDs);
1612 else if (anIDs->length() > 0) {
1614 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1618 case GEOM::FSM_GetSame:
1621 aSubO = aShapesOp->GetSame(theObject, anArgO);
1624 case GEOM::FSM_GetShapesOnShape:
1626 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1627 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1628 (short)GEOM::SOLID, GEOM::ST_ONIN);
1631 case GEOM::FSM_GetInPlaceByHistory:
1633 // Use GetInPlaceByHistory
1634 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1641 if (!CORBA::is_nil(aSubO)) {
1642 // add to parts list
1643 addToListOfGO( aSubO, aParts );
1645 // Publish the sub-shape
1646 SALOMEDS::SObject_var aSubSO;
1647 if (!CORBA::is_nil(theSObject)) {
1648 TCollection_AsciiString aSubName;
1652 aSubName += anArgName;
1653 aSubSO = aStudyBuilder->NewObject(theSObject);
1654 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1656 aSubO->SetColor(anArgO->GetColor());
1658 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1659 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1660 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1661 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1665 if (!CORBA::is_nil(anArgSO)) {
1666 // Restore published sub-shapes of the argument
1667 GEOM::ListOfGO_var aSubParts;
1668 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1669 // pass theObject, because only it has the history
1670 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1671 theObject, anArgs, theFindMethod, theAddPrefix);
1673 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1674 aSubO, anArgs, theFindMethod, theAddPrefix);
1675 // add to parts list
1676 addToListOfGO( aSubParts, aParts );
1679 else { // GetInPlace failed, try to build from published parts
1680 if (!CORBA::is_nil(anArgSO)) {
1681 SALOMEDS::SObject_var aSubSO;
1682 if (!CORBA::is_nil(theSObject))
1683 aSubSO = aStudyBuilder->NewObject(theSObject);
1685 // Restore published sub-shapes of the argument
1686 GEOM::ListOfGO_var aSubParts =
1687 RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1688 theObject, anArgs, theFindMethod, theAddPrefix);
1690 // add to parts list
1691 addToListOfGO( aSubParts, aParts );
1693 if (aSubParts->length() > 0) {
1694 // try to build an argument from a set of its sub-shapes,
1695 // that published and will be reconstructed
1696 if (aSubParts->length() > 1) {
1697 aSubO = aShapesOp->MakeCompound(aSubParts);
1698 // add to parts list
1699 addToListOfGO( aSubO, aParts );
1702 aSubO = aSubParts[0];
1704 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1705 // Publish the sub-shape
1706 TCollection_AsciiString aSubName;
1708 aSubName = "from_parts_of_";
1710 aSubName += anArgName;
1711 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1713 aSubO->SetColor(anArgO->GetColor());
1715 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1716 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1717 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1718 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1722 else if (!CORBA::is_nil(aSubSO)) {
1723 // remove created aSubSO, because no parts have been found
1724 aStudyBuilder->RemoveObject(aSubSO);
1727 } // try to build from published parts
1728 anArgSO->UnRegister();
1730 } // process arguments
1732 std::set<std::string> anObjEntryMap;
1733 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1735 int nb = aParts->length();
1736 aResParts->length(nb);
1739 Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1740 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1741 GEOM::TPythonDump pd (aFunction, true);
1744 for ( ; i < nb; i++ )
1746 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1747 if (CORBA::is_nil(anObj))
1749 char* anEntry = anObj->GetEntry();
1750 if (anObjEntryMap.count(anEntry))
1751 continue; // already treated
1752 anObjEntryMap.insert(anEntry);
1753 aResParts[nbRes++] = anObj;
1754 // clear python dump of object
1755 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1756 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1757 if ( !anObjFun.IsNull() )
1758 anObjFun->SetDescription( "" );
1764 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1765 i = 0; nb = theArgs.length(); j = 0;
1766 for ( ; i < nb; i++ )
1768 GEOM::GEOM_Object_var anObj = theArgs[ i ];
1769 if (CORBA::is_nil(anObj))
1771 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1777 pd <<"]" << ", " <<"geompy.GEOM.";
1778 switch (theFindMethod) {
1779 case GEOM::FSM_GetInPlace:
1780 pd << "FSM_GetInPlace"; break;
1781 case GEOM::FSM_MultiTransformed:
1782 pd << "FSM_MultiTransformed"; break;
1783 case GEOM::FSM_Transformed:
1784 pd << "FSM_Transformed"; break;
1785 case GEOM::FSM_GetSame:
1786 pd << "FSM_GetSame"; break;
1787 case GEOM::FSM_GetShapesOnShape:
1788 pd << "FSM_GetShapesOnShape"; break;
1789 case GEOM::FSM_GetInPlaceByHistory:
1791 pd << "FSM_GetInPlaceByHistory"; break;
1793 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1795 aResParts->length(nbRes);
1796 return aResParts._retn();
1799 //============================================================================
1800 // function : RestoreGivenSubShapesOneLevel
1801 // purpose : Private method
1802 //============================================================================
1803 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1804 SALOMEDS::SObject_ptr theOldSO,
1805 SALOMEDS::SObject_ptr theNewSO,
1806 GEOM::GEOM_Object_ptr theNewO,
1807 std::set<std::string> theArgs,
1808 GEOM::find_shape_method theFindMethod,
1809 CORBA::Boolean theAddPrefix)
1812 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1813 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1814 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1815 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1816 return aParts._retn();
1818 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1820 // Get interface, containing method, which we will use to reconstruct sub-shapes
1821 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1822 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1823 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1825 // Reconstruct published sub-shapes
1826 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1829 for (it->Init(); it->More(); it->Next()) {
1832 aParts->length(aLen);
1834 for (it->Init(); it->More(); it->Next()) {
1835 SALOMEDS::SObject_var anOldSubSO = it->Value();
1837 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1839 SALOMEDS::GenericAttribute_var anAttr;
1840 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1841 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1842 GEOM::GEOM_Object_var anOldSubO =
1843 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1845 bool okToContinue = false;
1847 if (!CORBA::is_nil(anOldSubO)) {
1848 CORBA::String_var anEntry = anOldSubO->GetEntry();
1849 okToContinue = theArgs.count(anEntry.in());
1853 // Find a sub-shape of theNewO in place of anOldSubO
1854 GEOM::GEOM_Object_var aNewSubO;
1855 switch (theFindMethod) {
1856 case GEOM::FSM_GetInPlace:
1859 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1862 case GEOM::FSM_MultiTransformed:
1864 // Only for Multi-transformations
1865 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anOldSubO, theNewO);
1866 if (!CORBA::is_nil(anArgOTrsf)) {
1867 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1868 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1869 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1870 anArgOTrsfFun->SetDescription("");
1871 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1875 case GEOM::FSM_Transformed:
1877 // transformation, cannot use GetInPlace, operate with indices
1878 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1879 if (anIDs->length() > 1) {
1881 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1882 if (!CORBA::is_nil(aNewSubO))
1883 aGroupOp->UnionIDs(aNewSubO, anIDs);
1887 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1891 case GEOM::FSM_GetSame:
1894 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1897 case GEOM::FSM_GetShapesOnShape:
1899 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1900 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1901 (short)GEOM::SOLID, GEOM::ST_ONIN);
1904 case GEOM::FSM_GetInPlaceByHistory:
1906 // Use GetInPlaceByHistory
1907 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1914 if (!CORBA::is_nil(aNewSubO)) {
1915 // add the part to the list
1916 aParts[i] = aNewSubO;
1918 // add to parts list
1919 addToListOfGO( aNewSubO, aNewParts );
1921 SALOMEDS::SObject_var aNewSubSO;
1922 if (!CORBA::is_nil(theNewSO)) {
1923 // Publish the sub-shape
1924 TCollection_AsciiString aSubName;
1928 aSubName += anArgName;
1929 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1930 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1932 aNewSubO->SetColor(anOldSubO->GetColor());
1934 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1935 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1936 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1937 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1940 // Restore published sub-shapes of the argument
1941 GEOM::ListOfGO_var aSubParts;
1942 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1943 // pass the main shape as Object, because only it has the history
1944 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1945 theNewO, theArgs, theFindMethod, theAddPrefix);
1947 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1948 aNewSubO, theArgs, theFindMethod, theAddPrefix);
1949 // add to parts list
1950 addToListOfGO( aSubParts, aNewParts );
1952 else { // GetInPlace failed, try to build from published parts
1953 SALOMEDS::SObject_var aNewSubSO;
1954 if (!CORBA::is_nil(theNewSO))
1955 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1957 // Restore published sub-shapes of the argument
1958 GEOM::ListOfGO_var aSubParts =
1959 RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1960 theNewO, theArgs, theFindMethod, theAddPrefix);
1961 // add to parts list
1962 addToListOfGO( aSubParts, aNewParts );
1964 if (aSubParts->length() > 0) {
1965 // try to build an object from a set of its sub-shapes,
1966 // that published and will be reconstructed
1967 if (aSubParts->length() > 1) {
1968 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1969 // add to parts list
1970 addToListOfGO( aNewSubO, aNewParts );
1973 aNewSubO = aSubParts[0];
1976 if (!CORBA::is_nil(aNewSubO)) {
1977 // add the part to the list
1978 aSubParts[i] = aNewSubO;
1981 // Publish the sub-shape
1982 if (!CORBA::is_nil(aNewSubSO)) {
1983 TCollection_AsciiString aSubName;
1985 aSubName = "from_parts_of_";
1987 aSubName += anArgName;
1988 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1990 aNewSubO->SetColor(anOldSubO->GetColor());
1992 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1993 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1994 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1995 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2000 else if (!CORBA::is_nil(aNewSubSO)) {
2001 // remove created aSubSO, because no parts have been found
2002 aStudyBuilder->RemoveObject(aNewSubSO);
2004 } // try to build from published parts
2007 } // iterate on published sub-shapes
2010 // add to parts list
2011 addToListOfGO( aNewParts, aParts );
2012 return aParts._retn();
2015 //============================================================================
2016 // function : register()
2017 // purpose : register 'name' in 'name_service'
2018 //============================================================================
2019 void GEOM_Gen_i::register_name(char * name)
2021 GEOM::GEOM_Gen_var g = _this();
2022 name_service->Register(g, name);
2025 //============================================================================
2028 //============================================================================
2029 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
2031 _impl->Undo(theStudyID);
2034 //============================================================================
2037 //============================================================================
2038 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
2040 _impl->Redo(theStudyID);
2043 //============================================================================
2044 // function : GetIBasicOperations
2046 //============================================================================
2047 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
2048 throw ( SALOME::SALOME_Exception )
2050 Unexpect aCatch(SALOME_SalomeException);
2051 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
2053 GEOM::GEOM_Gen_ptr engine = _this();
2055 //transfer reference on engine
2056 GEOM_IBasicOperations_i* aServant =
2057 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
2059 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2060 // activate the CORBA servant
2061 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
2062 return operations._retn();
2065 //============================================================================
2066 // function : GetITransformOperations
2068 //============================================================================
2069 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
2070 throw ( SALOME::SALOME_Exception )
2072 Unexpect aCatch(SALOME_SalomeException);
2073 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
2075 GEOM::GEOM_Gen_ptr engine = _this();
2077 GEOM_ITransformOperations_i* aServant =
2078 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
2080 // activate the CORBA servant
2081 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
2082 return operations._retn();
2085 //============================================================================
2086 // function : GetI3DPrimOperations
2088 //============================================================================
2089 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
2090 throw ( SALOME::SALOME_Exception )
2092 Unexpect aCatch(SALOME_SalomeException);
2093 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
2095 GEOM::GEOM_Gen_ptr engine = _this();
2097 GEOM_I3DPrimOperations_i* aServant =
2098 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
2099 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2101 // activate the CORBA servant
2102 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
2103 return operations._retn();
2106 //============================================================================
2107 // function : GetIShapesOperations
2109 //============================================================================
2110 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
2111 throw ( SALOME::SALOME_Exception )
2113 Unexpect aCatch(SALOME_SalomeException);
2114 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
2116 GEOM::GEOM_Gen_ptr engine = _this();
2118 GEOM_IShapesOperations_i* aServant =
2119 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
2121 // activate the CORBA servant
2122 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
2123 return operations._retn();
2126 //============================================================================
2127 // function : GetIBlocksOperations
2129 //============================================================================
2130 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
2131 throw ( SALOME::SALOME_Exception )
2133 Unexpect aCatch(SALOME_SalomeException);
2134 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
2136 GEOM::GEOM_Gen_ptr engine = _this();
2138 GEOM_IBlocksOperations_i* aServant =
2139 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
2141 // activate the CORBA servant
2142 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
2143 return operations._retn();
2146 //============================================================================
2147 // function : GetIBooleanOperations
2149 //============================================================================
2150 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
2151 throw ( SALOME::SALOME_Exception )
2153 Unexpect aCatch(SALOME_SalomeException);
2154 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
2156 GEOM::GEOM_Gen_ptr engine = _this();
2158 GEOM_IBooleanOperations_i* aServant =
2159 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
2161 // activate the CORBA servant
2162 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
2163 return operations._retn();
2166 //============================================================================
2167 // function : GetICurvesOperations
2169 //============================================================================
2170 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
2171 throw ( SALOME::SALOME_Exception )
2173 Unexpect aCatch(SALOME_SalomeException);
2174 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
2176 GEOM::GEOM_Gen_ptr engine = _this();
2178 GEOM_ICurvesOperations_i* aServant =
2179 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
2181 // activate the CORBA servant
2182 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
2183 return operations._retn();
2186 //============================================================================
2187 // function : GetILocalOperations
2189 //============================================================================
2190 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
2191 throw ( SALOME::SALOME_Exception )
2193 Unexpect aCatch(SALOME_SalomeException);
2194 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
2196 GEOM::GEOM_Gen_ptr engine = _this();
2198 GEOM_ILocalOperations_i* aServant =
2199 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
2201 // activate the CORBA servant
2202 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
2203 return operations._retn();
2206 //============================================================================
2207 // function : GetIHealingOperations
2209 //============================================================================
2210 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
2211 throw ( SALOME::SALOME_Exception )
2213 Unexpect aCatch(SALOME_SalomeException);
2214 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
2216 GEOM::GEOM_Gen_ptr engine = _this();
2218 GEOM_IHealingOperations_i* aServant =
2219 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
2221 // activate the CORBA servant
2222 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
2223 return operations._retn();
2226 //============================================================================
2227 // function : GetIInsertOperations
2229 //============================================================================
2230 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
2231 throw ( SALOME::SALOME_Exception )
2233 Unexpect aCatch(SALOME_SalomeException);
2234 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
2236 GEOM::GEOM_Gen_ptr engine = _this();
2238 GEOM_IInsertOperations_i* aServant =
2239 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
2241 // activate the CORBA servant
2242 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
2243 return operations._retn();
2246 //============================================================================
2247 // function : GetIMeasureOperations
2249 //============================================================================
2250 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
2251 throw ( SALOME::SALOME_Exception )
2253 Unexpect aCatch(SALOME_SalomeException);
2254 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
2256 GEOM::GEOM_Gen_ptr engine = _this();
2258 GEOM_IMeasureOperations_i* aServant =
2259 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
2261 // activate the CORBA servant
2262 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
2263 return operations._retn();
2266 //============================================================================
2267 // function : GetIGroupOperations
2269 //============================================================================
2270 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
2271 throw ( SALOME::SALOME_Exception )
2273 Unexpect aCatch(SALOME_SalomeException);
2274 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
2276 GEOM::GEOM_Gen_ptr engine = _this();
2278 GEOM_IGroupOperations_i* aServant =
2279 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
2281 // activate the CORBA servant
2282 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
2283 return operations._retn();
2286 //============================================================================
2287 // function : GetIAdvancedOperations
2289 //============================================================================
2290 GEOM::GEOM_IAdvancedOperations_ptr GEOM_Gen_i::GetIAdvancedOperations(CORBA::Long theStudyID)
2291 throw ( SALOME::SALOME_Exception )
2293 Unexpect aCatch(SALOME_SalomeException);
2294 MESSAGE( "GEOM_Gen_i::GetIAdvancedOperations" );
2296 GEOM::GEOM_Gen_ptr engine = _this();
2298 GEOM_IAdvancedOperations_i* aServant =
2299 new GEOM_IAdvancedOperations_i(_poa, engine, _impl->GetIAdvancedOperations(theStudyID));
2301 // activate the CORBA servant
2302 GEOM::GEOM_IAdvancedOperations_var operations = aServant->_this();
2303 return operations._retn();
2306 //=============================================================================
2310 //=============================================================================
2311 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
2312 const GEOM::ListOfLong& theIndices)
2314 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
2315 return GEOM::GEOM_Object::_nil();
2316 CORBA::String_var entry = theMainShape->GetEntry();
2317 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
2318 if (aMainShape.IsNull()) return GEOM::GEOM_Object::_nil();
2320 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
2321 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
2323 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true);
2324 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
2326 TCollection_AsciiString anEntry;
2327 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
2328 return GetObject(anObject->GetDocID(), anEntry.ToCString());
2331 //=============================================================================
2335 //=============================================================================
2336 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
2338 CORBA::String_var anEntry = theObject->GetEntry();
2339 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false);
2340 if (anObject.IsNull()) return;
2341 _impl->RemoveObject(anObject);
2346 //=================================================================================
2347 // function : GetStringFromIOR()
2348 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
2349 //=================================================================================
2350 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
2351 return _orb->object_to_string(theObject);
2355 //=================================================================================
2356 // function : GetIORFromString()
2357 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
2358 //=================================================================================
2359 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
2360 GEOM::GEOM_Object_var aGeomObject;
2361 if(strcmp(stringIOR,"") != 0){
2362 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
2363 if(!CORBA::is_nil(anObject))
2364 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
2366 return aGeomObject._retn();
2369 //=================================================================================
2370 // function : GetObject()
2372 //=================================================================================
2373 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
2375 GEOM::GEOM_Object_var obj;
2376 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
2377 if (handle_object.IsNull()) return obj._retn();
2379 TCollection_AsciiString stringIOR = handle_object->GetIOR();
2380 if (stringIOR.Length() > 1) {
2381 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
2382 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
2386 GEOM::GEOM_Gen_ptr engine = _this();
2387 //transfer the reference to GEOM_Object_i
2388 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
2389 PortableServer::ObjectId_var id = _poa->activate_object(servant);
2391 obj = servant->_this();
2392 CORBA::String_var objStr = _orb->object_to_string(obj);
2393 TCollection_AsciiString anAscii( (char *)objStr.in() );
2394 handle_object->SetIOR( anAscii );
2398 //=================================================================================
2399 // function : hasObjectInfo()
2400 // purpose : shows if module provides information for its objects
2401 //=================================================================================
2402 bool GEOM_Gen_i::hasObjectInfo()
2407 //=================================================================================
2408 // function : getObjectInfo()
2409 // purpose : returns an information for a given object by its entry
2410 //=================================================================================
2411 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
2413 GEOM::GEOM_Object_var aGeomObject;
2415 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
2416 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
2417 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
2418 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
2419 SALOMEDS::SObject_var aResultSObj;
2420 if (aSObj->ReferencedObject(aResultSObj))
2421 aSObj = aResultSObj;
2423 SALOMEDS::GenericAttribute_var anAttr;
2424 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
2425 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2426 CORBA::String_var aVal = anIOR->Value();
2427 anIOR->UnRegister();
2428 CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
2429 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
2431 if (!aSObj->_is_nil() )
2432 aSObj->UnRegister();
2434 const char* aTypeInfo = "Object";
2435 if ( !aGeomObject->_is_nil() ) {
2436 GEOM::GEOM_IKindOfShape::shape_kind aKind;
2437 GEOM::ListOfLong_var anInts;
2438 GEOM::ListOfDouble_var aDbls;
2440 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
2441 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
2443 if ( anOp->IsDone() ) {
2445 case GEOM::GEOM_IKindOfShape::COMPOUND:
2446 aTypeInfo = "Compound";
2448 case GEOM::GEOM_IKindOfShape::COMPSOLID:
2449 aTypeInfo = "CompSolid";
2451 case GEOM::GEOM_IKindOfShape::SHELL:
2452 aTypeInfo = "Shell";
2454 case GEOM::GEOM_IKindOfShape::WIRE:
2455 if ( anInts[0] == 1 )
2456 aTypeInfo = "Closed Wire";
2457 else if ( anInts[0] == 2 )
2458 aTypeInfo = "Opened Wire";
2463 case GEOM::GEOM_IKindOfShape::SPHERE:
2464 aTypeInfo = "Sphere";
2466 case GEOM::GEOM_IKindOfShape::CYLINDER:
2467 aTypeInfo = "Cylinder";
2469 case GEOM::GEOM_IKindOfShape::BOX:
2470 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
2473 case GEOM::GEOM_IKindOfShape::TORUS:
2474 aTypeInfo = "Torus";
2476 case GEOM::GEOM_IKindOfShape::CONE:
2479 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
2480 aTypeInfo = "Polyhedron";
2482 case GEOM::GEOM_IKindOfShape::SOLID:
2483 aTypeInfo = "Solid";
2486 case GEOM::GEOM_IKindOfShape::SPHERE2D:
2487 aTypeInfo = "Spherical Face";
2489 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
2490 aTypeInfo = "Cylindrical Face";
2492 case GEOM::GEOM_IKindOfShape::TORUS2D:
2493 aTypeInfo = "Toroidal Face";
2495 case GEOM::GEOM_IKindOfShape::CONE2D:
2496 aTypeInfo = "Conical Face";
2498 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
2501 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
2502 aTypeInfo = "Elliptical Face";
2504 case GEOM::GEOM_IKindOfShape::POLYGON:
2505 aTypeInfo = "Polygon";
2507 case GEOM::GEOM_IKindOfShape::PLANE:
2508 aTypeInfo = "Plane";
2510 case GEOM::GEOM_IKindOfShape::PLANAR:
2511 aTypeInfo = "Planar Face";
2513 case GEOM::GEOM_IKindOfShape::FACE:
2517 case GEOM::GEOM_IKindOfShape::CIRCLE:
2518 aTypeInfo = "Circle";
2520 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
2521 aTypeInfo = "Arc Circle";
2523 case GEOM::GEOM_IKindOfShape::ELLIPSE:
2524 aTypeInfo = "Ellipse";
2526 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
2527 aTypeInfo = "Arc Ellipse";
2529 case GEOM::GEOM_IKindOfShape::LINE:
2532 case GEOM::GEOM_IKindOfShape::SEGMENT:
2533 aTypeInfo = "Segment";
2535 case GEOM::GEOM_IKindOfShape::EDGE:
2538 case GEOM::GEOM_IKindOfShape::VERTEX:
2539 aTypeInfo = "Vertex";
2547 char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
2548 sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
2550 char* ret = CORBA::string_dup(anInfo);
2555 // Version information
2556 char* GEOM_Gen_i::getVersion()
2558 #if GEOM_DEVELOPMENT
2559 return CORBA::string_dup(GEOM_VERSION_STR"dev");
2561 return CORBA::string_dup(GEOM_VERSION_STR);
2565 //=====================================================================================
2567 //=====================================================================================
2572 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
2576 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb,
2577 PortableServer::POA_ptr poa,
2578 PortableServer::ObjectId* contId,
2579 const char* instanceName,
2580 const char* interfaceName)
2582 GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
2583 return myGEOM_Gen_i->getId();