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();
179 SALOMEDS::UseCaseBuilder_var useCaseBuilder = theStudy->GetUseCaseBuilder();
181 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
182 if (aFather->_is_nil()) {
183 aFather = aStudyBuilder->NewComponent("GEOM");
184 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
185 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
186 aName->SetValue("Geometry");
188 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
189 SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr);
190 aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry");
191 aPixMap->UnRegister();
192 aStudyBuilder->DefineComponentInstance(aFather, (GEOM::GEOM_Gen_var)GEOM_Gen::_this());
193 // add component to the use case tree
194 // (to support tree representation customization and drag-n-drop)
195 useCaseBuilder->SetRootCurrent();
196 useCaseBuilder->Append( aFather ); // component object is added as the top level item
198 if (aFather->_is_nil()) return aResultSO;
200 if (CORBA::is_nil(theSObject)) {
201 aResultSO = aStudyBuilder->NewObject(aFather);
203 if (!theSObject->ReferencedObject(aResultSO))
204 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
205 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
207 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
208 aResultSO->SetAttrString("AttributeIOR",aGeomObjIOR);
210 TCollection_AsciiString aShapeName("Shape_");
212 CORBA::Long mytype=aShape->GetType();
213 if ( mytype == GEOM_GROUP ) {
214 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
215 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
217 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_PNT" );
218 aShapeName = "Group_Of_Vertices_";
221 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_EDGE");
222 aShapeName = "Group_Of_Edges_";
225 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_FACE");
226 aShapeName = "Group_Of_Faces_";
229 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_SOLID");
230 aShapeName = "Group_Of_Solids_";
233 } else if ( mytype == GEOM_MARKER ) {
234 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS");
235 aShapeName = "LocalCS_";
236 } else if ( mytype > ADVANCED_BASE ) {
238 sprintf( buf, "%d", aShape->GetType() );
239 std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf;
240 aResultSO->SetAttrString("AttributePixMap",advId.c_str());
241 aShapeName = "Advanced_";
243 GEOM::shape_type myshapetype=aShape->GetShapeType();
244 if ( myshapetype == GEOM::COMPOUND ) {
245 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPOUND" );
246 aShapeName = "Compound_";
247 } else if ( myshapetype == GEOM::COMPSOLID ) {
248 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPSOLID");
249 aShapeName = "Compsolid_";
250 } else if ( myshapetype == GEOM::SOLID ) {
251 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SOLID");
252 aShapeName = "Solid_";
253 } else if ( myshapetype == GEOM::SHELL ) {
254 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SHELL");
255 aShapeName = "Shell_";
256 } else if ( myshapetype == GEOM::FACE ) {
257 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FACE");
258 aShapeName = "Face_";
259 } else if ( myshapetype == GEOM::WIRE ) {
260 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_WIRE");
261 aShapeName = "Wire_";
262 } else if ( myshapetype == GEOM::EDGE ) {
263 aResultSO->SetAttrString("AttributePixMap", "ICON_OBJBROWSER_EDGE");
264 aShapeName = "Edge_";
265 } else if ( myshapetype == GEOM::VERTEX ) {
266 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_VERTEX" );
267 aShapeName = "Vertex_";
270 //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
271 //else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName));
273 // BEGIN: try to find existed name for current shape
274 bool HasName = false;
275 // recieve current TopoDS shape
276 CORBA::String_var entry = aShape->GetEntry();
277 Handle(GEOM_Object) aGShape = _impl->GetObject(aShape->GetStudyID(), entry);
278 TopoDS_Shape TopoSh = aGShape->GetValue();
279 // find label of main shape
280 GEOM::GEOM_Object_var aMainSh = aShape;
281 while( !aMainSh->IsMainShape() ) {
282 aMainSh = aMainSh->GetMainShape();
284 entry = aMainSh->GetEntry();
285 Handle(GEOM_Object) anObj = _impl->GetObject(aMainSh->GetStudyID(), entry);
286 TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry();
288 // check all named shapes using iterator
289 TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
291 for (; anIt.More() && !HasName; anIt.Next()) {
292 Handle(TNaming_NamedShape) anAttr =
293 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
294 if (anAttr.IsNull()) continue;
295 TopoDS_Shape S = anAttr->Get();
296 if (S.IsEqual(TopoSh)) {
297 TDF_Label L = anAttr->Label();
298 Handle(TDataStd_Name) aName;
299 if (L.FindAttribute(TDataStd_Name::GetID(), aName)) {
300 aShapeName = aName->Get();
305 // END: try to find existed name for current shape
308 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
309 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
310 // of objects in the study, but compute a number of objects with the same prefix
311 // and build a new name as Prefix_N+1
312 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
313 int i = 0; // (WITH EMPTY NEW NAME)
314 SALOMEDS::SObject_var obj;
315 TCollection_AsciiString aNewShapeName;
317 aNewShapeName = aShapeName + TCollection_AsciiString(++i);
318 obj = theStudy->FindObject( aNewShapeName.ToCString() );
320 while ( !obj->_is_nil() );
321 aShapeName = aNewShapeName;
323 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
324 aShapeName = TCollection_AsciiString((char*)theName);
327 //Set the study entry as a name of the published GEOM_Object
328 CORBA::String_var anID =aResultSO->GetID();
329 aShape->SetStudyEntry(anID.in());
331 //Set a name of the added shape
332 aResultSO->SetAttrString("AttributeName",aShapeName.ToCString());
334 //Set NoteBook variables used in the object creation
335 TCollection_AsciiString aVars;
336 CORBA::String_var aString=aShape->GetParameters();
337 SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aString);
338 for(int i = 0, n = aSections->length(); i < n; i++) {
339 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
340 for(int j = 0, m = aListOfVars.length(); j < m; j++) {
341 if(theStudy->IsVariable(aListOfVars[j].in()))
342 aVars += TCollection_AsciiString(aListOfVars[j].in());
349 aResultSO->SetAttrString("AttributeString",aVars.ToCString());
351 aFather->UnRegister();
353 //Set a name of the GEOM object
354 aShape->SetName(aShapeName.ToCString());
356 // add object to the use case tree
357 // (to support tree representation customization and drag-n-drop)
358 useCaseBuilder->AppendTo( aResultSO->GetFather(), aResultSO );
360 return aResultSO._retn();
364 //============================================================================
365 // function : CreateAndPublishGroup
366 // purpose : auxilary for PublishNamedShapesInStudy
367 //============================================================================
368 void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
369 GEOM::GEOM_Object_var theMainShape,
370 const TopTools_IndexedMapOfShape& anIndices,
371 const TopTools_SequenceOfShape& SeqS,
372 const TColStd_SequenceOfAsciiString& SeqN,
373 const Standard_CString& GrName,
374 GEOM::ListOfGO_var aResList)
376 CORBA::String_var entry = theMainShape->GetEntry();
377 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
378 Handle(TColStd_HArray1OfInteger) anArray;
379 if(SeqS.Length()>0) {
381 GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId());
382 GEOM::GEOM_Object_ptr GrObj =
383 GOp->CreateGroup( theMainShape, SeqS.Value(1).ShapeType() );
384 AddInStudy(theStudy, GrObj, GrName, theMainShape._retn());
385 CORBA::String_var GrEntry = GrObj->GetEntry();
386 Handle(GEOM_Object) HGrObj = _impl->GetObject(GrObj->GetStudyID(), GrEntry);
388 //Handle(GEOM_Object) anObj;
389 for(int i=1; i<=SeqS.Length(); i++) {
390 TopoDS_Shape aValue = SeqS.Value(i);
391 //anArray = new TColStd_HArray1OfInteger(1,1);
392 Standard_Integer anIndex = anIndices.FindIndex(aValue);
393 //anArray->SetValue(1, anIndex);
394 GOp->AddObject(GrObj,anIndex);
395 //anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE);
396 //if (anObj.IsNull()) continue;
397 //Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
398 //if (aFunction.IsNull()) continue;
399 //GEOM_ISubShape aSSI(aFunction);
400 //aSSI.SetMainShape(aMainShape->GetLastFunction());
401 //aSSI.SetIndices(anArray);
402 //aFunction->SetValue(aValue);
403 //GOp->UnionIDs(GrObj, anIndex);
404 //SALOMEDS::SObject_var aResultSO;
405 //TCollection_AsciiString anEntry;
406 //TDF_Tool::Entry(anObj->GetEntry(),anEntry);
407 //GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString());
408 //AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
414 //============================================================================
415 // function : PublishNamedShapesInStudy
417 //============================================================================
418 GEOM::ListOfGO* GEOM_Gen_i::
419 PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
420 //SALOMEDS::SObject_ptr theSObject,
421 CORBA::Object_ptr theObject)
423 //Unexpect aCatch(SALOME_SalomeException);
424 GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
426 //CORBA::Object_var theObject = theSObject->GetObject();
427 GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
428 if(theMainShape->_is_nil()) return aResList._retn();
430 CORBA::String_var entry = theMainShape->GetEntry();
431 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
432 if (aMainShape.IsNull()) return aResList._retn();
433 TopoDS_Shape MainSh = aMainShape->GetValue();
435 TDF_Label aMainLbl = aMainShape->GetEntry();
436 TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
437 TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
438 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
439 for(; anIt.More(); anIt.Next()) {
440 Handle(TNaming_NamedShape) anAttr =
441 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
442 if(anAttr.IsNull()) continue;
443 TopoDS_Shape S = anAttr->Get();
444 TDF_Label L = anAttr->Label();
445 //if(S.IsEqual(MainSh)) continue;
446 Handle(TDataStd_Name) aName;
447 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
448 TCollection_ExtendedString EName = aName->Get();
449 if(S.ShapeType()==TopAbs_SOLID) {
451 SolidSeqN.Append(aName->Get());
453 else if(S.ShapeType()==TopAbs_FACE) {
455 FaceSeqN.Append(aName->Get());
457 else if(S.ShapeType()==TopAbs_EDGE) {
459 EdgeSeqN.Append(aName->Get());
461 else if(S.ShapeType()==TopAbs_VERTEX) {
463 VertSeqN.Append(aName->Get());
468 TopTools_IndexedMapOfShape anIndices;
469 TopExp::MapShapes(MainSh, anIndices);
471 CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN,
472 "Group_Of_Named_Solids", aResList);
474 CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN,
475 "Group_Of_Named_Faces", aResList);
477 CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
478 "Group_Of_Named_Edges", aResList);
480 CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN,
481 "Group_Of_Named_Vertices", aResList);
483 return aResList._retn();
487 //============================================================================
489 // purpose : save OCAF/Geom document
490 //============================================================================
491 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
494 SALOMEDS::TMPFile_var aStreamFile;
495 // Get a temporary directory to store a file
496 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
498 // OCCT BUG: cannot save a document (in current folder)
499 // if directory name is empty
500 if (aTmpDir.size() == 0) {
508 // Create a list to store names of created files
509 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
511 // Prepare a file name to open
512 TCollection_AsciiString aNameWithExt("");
514 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
515 (theComponent->GetStudy()->URL())).c_str());
516 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
517 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
518 // Build a full file name of temporary file
519 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
520 // Save GEOM component in this file
521 _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
522 // Conver a file to the byte stream
523 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
524 // Remove the created file and tmp directory
525 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
527 // Return the created byte stream
528 return aStreamFile._retn();
532 //============================================================================
533 // function : SaveASCII()
535 //============================================================================
536 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
539 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
540 return aStreamFile._retn();
544 //============================================================================
547 //============================================================================
548 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
549 const SALOMEDS::TMPFile& theStream,
553 if (theStream.length() <= 9) {
554 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
558 // Get a temporary directory for a file
559 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
561 // OCCT BUG: cannot load a document (from current folder)
562 // if directory name is empty
563 if (aTmpDir.size() == 0) {
571 // Conver the byte stream theStream to a file and place it in tmp directory
572 SALOMEDS::ListOfFileNames_var aSeq =
573 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
575 // Prepare a file name to open
576 TCollection_AsciiString aNameWithExt("");
578 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
579 (theComponent->GetStudy()->URL())).c_str());
580 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
581 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
584 if (!_impl->Load(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString())) return false;
586 // Remove the created file and tmp directory
587 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
589 // creation of tree nodes for all data objects in the study
590 // to support tree representation customization and drag-n-drop:
591 SALOMEDS::UseCaseBuilder_var useCaseBuilder = theComponent->GetStudy()->GetUseCaseBuilder();
592 if ( !useCaseBuilder->IsUseCaseNode( theComponent ) ) {
593 useCaseBuilder->SetRootCurrent();
594 useCaseBuilder->Append( theComponent ); // component object is added as the top level item
595 SALOMEDS::ChildIterator_var it = theComponent->GetStudy()->NewChildIterator( theComponent );
596 for (it->InitEx(true); it->More(); it->Next()) {
597 useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() );
605 //============================================================================
606 // function : LoadASCII()
608 //============================================================================
609 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
610 const SALOMEDS::TMPFile& theStream,
613 return Load(theComponent, theStream, theURL, isMultiFile);
617 //============================================================================
618 // function : Close()
620 //============================================================================
621 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
623 SALOMEDS::Study_var aStudy= theComponent->GetStudy();
624 _impl->Close(aStudy->StudyId());
627 //============================================================================
628 // function : CanCopy()
630 //============================================================================
631 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
632 // Try to retrieve known by Geometry component GEOM_Object by given IOR
633 SALOMEDS::GenericAttribute_var anAttr;
634 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
636 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
638 CORBA::String_var aString=anIOR->Value();
640 CORBA::Object_var anObj = _orb->string_to_object(aString);
641 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(anObj);
642 // If the object is null one it can't be copied: return false
643 if (anObject->_is_nil()) return false;
647 //============================================================================
648 // function : CopyFrom()
650 //============================================================================
651 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
653 // Declare a sequence of the byte to store the copied object
654 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
656 // Try to get GEOM_Object object by given SObject
657 SALOMEDS::GenericAttribute_var anAttr;
658 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
659 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
660 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
661 if (anObject->_is_nil()) return aStreamFile._retn();
663 aStreamFile = anObject->GetShapeStream();
665 // Assign an ID the type of GEOM_Object
666 theObjectID = anObject->GetType();
668 // Return created TMPFile
669 return aStreamFile._retn();
672 //============================================================================
673 // function : CanPaste()
675 //============================================================================
676 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
677 // The Geometry component can paste only objects copied by Geometry component
678 // and with the object type = 1
679 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
683 //============================================================================
684 // function : PasteInto()
686 //============================================================================
687 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
688 CORBA::Long theObjectID,
689 SALOMEDS::SObject_ptr theObject) {
690 // Find the current Study and StudyBuilder
691 SALOMEDS::Study_var aStudy = theObject->GetStudy();
692 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
693 SALOMEDS::SObject_var aNewSO;
694 // Retrieve a TopoDS_Shape from byte stream
695 TopoDS_Shape aTopology;
696 std::istringstream aStreamedBrep((char*) &theStream[0]);
697 BRep_Builder aBuilder;
699 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
700 } catch (Standard_Failure) {
701 return aNewSO._retn();
704 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
705 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
706 aNewSO = aStudyBuilder->NewObject(theObject);
707 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
710 //Create a new GEOM_Object
711 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
712 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
713 aFunction->SetValue(aTopology);
715 TCollection_AsciiString anEntry;
716 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
717 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
719 //Set the study entry of the published GEOM_Object
720 obj->SetStudyEntry(aNewSO->GetID());
722 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
723 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
724 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
725 CORBA::String_var objStr = _orb->object_to_string(obj);
726 anIOR->SetValue(objStr.in());
729 // Return the created in the Study SObject
730 return aNewSO._retn();
733 //============================================================================
734 // function : ComponentDataType()
736 //============================================================================
737 char* GEOM_Gen_i::ComponentDataType()
739 return CORBA::string_dup("GEOM");
742 //============================================================================
743 // function : AddInStudy
745 //============================================================================
746 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
747 GEOM::GEOM_Object_ptr theObject,
749 GEOM::GEOM_Object_ptr theFather)
751 SALOMEDS::SObject_var aResultSO;
752 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
754 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
755 CORBA::String_var IOR;
757 if(!theFather->_is_nil()) {
758 IOR = _orb->object_to_string(theFather);
759 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in());
760 if(aFatherSO->_is_nil()) return aResultSO._retn();
761 aResultSO = aStudyBuilder->NewObject(aFatherSO);
762 aFatherSO->UnRegister();
763 //aStudyBuilder->Addreference(aResultSO, aResultSO);
766 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
767 if(aResultSO->_is_nil()) return aResultSO._retn();
769 GEOM::ListOfGO_var aList = theObject->GetDependency();
770 Standard_Integer aLength = aList->length();
771 if(aLength < 1) return aResultSO._retn();
773 //Publish the arguments
774 TCollection_AsciiString aPrevID; // to avoid multiple references to same object
775 for(Standard_Integer i = 0; i< aLength; i++) {
776 GEOM::GEOM_Object_var anObject = aList[i];
777 if(anObject->_is_nil()) continue;
778 IOR = _orb->object_to_string(anObject);
779 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR.in());
780 if(aSO->_is_nil()) continue;
781 CORBA::String_var anID = aSO->GetID();
782 if ( aPrevID == anID.in() ) continue;
784 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
785 aStudyBuilder->Addreference(aSubSO, aSO);
787 aSubSO->UnRegister();
790 return aResultSO._retn();
793 //============================================================================
794 // function : RestoreSubShapesO
795 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
796 // To be used from python scripts out of geompy.addToStudy (non-default usage)
797 //============================================================================
798 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
799 GEOM::GEOM_Object_ptr theObject,
800 const GEOM::ListOfGO& theArgs,
801 GEOM::find_shape_method theFindMethod,
802 CORBA::Boolean theInheritFirstArg,
803 CORBA::Boolean theAddPrefix)
805 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
806 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
807 return aParts._retn();
809 // find SObject in the study if it is already published
810 CORBA::String_var anIORo = _orb->object_to_string(theObject);
811 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
812 //PTv, IMP 0020001, The salome object <aSO>
813 // is not obligatory in case of invokation from script
814 // if (CORBA::is_nil(aSO))
815 // return aParts._retn();
817 aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs,
818 theFindMethod, theInheritFirstArg, theAddPrefix);
819 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
820 return aParts._retn();
823 //============================================================================
824 // function : RestoreGivenSubShapesO
825 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
826 // To be used from python scripts, generated by Dump Python.
827 //============================================================================
828 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (SALOMEDS::Study_ptr theStudy,
829 GEOM::GEOM_Object_ptr theObject,
830 const GEOM::ListOfGO& theArgs,
831 GEOM::find_shape_method theFindMethod,
832 CORBA::Boolean theInheritFirstArg,
833 CORBA::Boolean theAddPrefix)
835 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
836 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
837 return aParts._retn();
839 // find SObject in the study if it is already published
840 CORBA::String_var anIORo = _orb->object_to_string(theObject);
841 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
842 //PTv, IMP 0020001, The salome object <aSO>
843 // is not obligatory in case of invokation from script
844 // if (CORBA::is_nil(aSO))
845 // return aParts._retn();
847 aParts = RestoreGivenSubShapes(theStudy, theObject, aSO, theArgs,
848 theFindMethod, theInheritFirstArg, theAddPrefix);
849 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
850 return aParts._retn();
853 //============================================================================
854 // function : RestoreSubShapesSO
855 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
856 // To be used from GUI and from geompy.addToStudy
857 //============================================================================
858 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
859 SALOMEDS::SObject_ptr theSObject,
860 const GEOM::ListOfGO& theArgs,
861 GEOM::find_shape_method theFindMethod,
862 CORBA::Boolean theInheritFirstArg,
863 CORBA::Boolean theAddPrefix)
865 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
866 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
867 return aParts._retn();
869 SALOMEDS::GenericAttribute_var anAttr;
870 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
871 return aParts._retn();
873 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
874 CORBA::String_var anIORso = anAttrIOR->Value();
876 // get Object from SObject
877 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
878 if (CORBA::is_nil(anO))
879 return aParts._retn();
881 aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs,
882 theFindMethod, theInheritFirstArg, theAddPrefix);
883 return aParts._retn();
886 //============================================================================
887 // function : addToListOfGO
888 // purpose : static local function
889 //============================================================================
890 static void addToListOfGO( GEOM::GEOM_Object_ptr theObject,
891 GEOM::ListOfGO& theList )
893 const int oldLen = theList.length();
894 theList.length(oldLen + 1);
895 theList[ oldLen ] = GEOM::GEOM_Object::_duplicate( theObject );
898 //============================================================================
899 // function : addToListOfGO
900 // purpose : static local function
901 //============================================================================
902 static void addToListOfGO( const GEOM::ListOfGO& theSrcList,
903 GEOM::ListOfGO& theTrgList )
905 const int oldLen = theTrgList.length();
906 const int srcLen = theSrcList.length();
907 theTrgList.length(oldLen + srcLen);
908 for( int i = 0; i < srcLen; i++ )
909 theTrgList[ oldLen + i ] = GEOM::GEOM_Object::_duplicate( theSrcList[ i ] );
912 //============================================================================
913 // function : RestoreSubShapes
914 // purpose : Private method. Works only if both theObject and theSObject
915 // are defined, and does not check, if they correspond to each other.
916 //============================================================================
917 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy,
918 GEOM::GEOM_Object_ptr theObject,
919 SALOMEDS::SObject_ptr theSObject,
920 const GEOM::ListOfGO& theArgs,
921 GEOM::find_shape_method theFindMethod,
922 CORBA::Boolean theInheritFirstArg,
923 CORBA::Boolean theAddPrefix)
925 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
926 //PTv, IMP 0020001, The salome object <theSObject>
927 // is not obligatory in case of invokation from script
928 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
929 return aParts._retn();
931 // For Dump Python (mantis issue 0020768)
932 GEOM::ListOfGO_var anOutArgs = new GEOM::ListOfGO;
934 // Arguments to be published
935 GEOM::ListOfGO_var aList;
937 // If theArgs list is empty, we try to publish all arguments,
938 // otherwise publish only passed args
939 Standard_Integer nbArgsActual = -1; // -1 means unknown
940 Standard_Integer aLength = theArgs.length();
942 aList = new GEOM::ListOfGO;
943 aList->length(aLength);
944 for (int i = 0; i < aLength; i++) {
945 aList[i] = GEOM::GEOM_Object::_duplicate( theArgs[i] );
950 aList = theObject->GetDependency();
951 aLength = aList->length();
952 nbArgsActual = aLength;
956 return aParts._retn();
958 if (theInheritFirstArg || (nbArgsActual == 1)) {
959 // Do not publish argument's reflection,
960 // but only reconstruct its published sub-shapes
962 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
963 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
965 // remember restored objects for Python Dump
966 addToListOfGO(aList[0], anOutArgs);
968 aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
969 anOutArgs, theFindMethod, theAddPrefix);
971 // set the color of the transformed shape to the color of initial shape
972 theObject->SetColor(aList[0]->GetColor());
974 if (theObject->GetShapeType() == GEOM::VERTEX) {
975 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
976 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
977 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
980 anArgSO->UnRegister();
983 // Get interface, containing method, which we will use to reconstruct sub-shapes
984 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
985 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
986 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
988 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
989 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
991 // Reconstruct arguments and tree of sub-shapes of the arguments
992 CORBA::String_var anIOR;
993 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
994 for (Standard_Integer i = 0; i < aLength; i++)
996 GEOM::GEOM_Object_var anArgO = aList[i];
997 if (!CORBA::is_nil(anArgO)) {
998 anIOR = _orb->object_to_string(anArgO);
999 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1000 TCollection_AsciiString anArgName;
1001 if (CORBA::is_nil(anArgSO)) {
1003 anArgName += TCollection_AsciiString(i);
1006 anArgName = anArgSO->GetName();
1009 // Find a sub-shape of theObject in place of the argument
1010 GEOM::GEOM_Object_var aSubO;
1011 switch (theFindMethod) {
1012 case GEOM::FSM_GetInPlace:
1015 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1018 case GEOM::FSM_MultiTransformed:
1020 // Only for Multi-transformations
1021 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1022 if (!CORBA::is_nil(anArgOTrsf)) {
1023 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1024 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1025 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1026 anArgOTrsfFun->SetDescription("");
1027 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1030 Handle(GEOM_Function) anOFun = theObject->GetLastFunction();
1031 if (!anOFun.IsNull()) {
1032 CORBA::String_var entryArg = anArgO->GetEntry();
1033 Handle(GEOM_Object) anArgOImpl = _impl->GetObject(anArgO->GetStudyID(), entryArg);
1034 if (!anArgOImpl.IsNull()) {
1035 TopoDS_Shape anArgOShape = anArgOImpl->GetValue();
1036 TopoDS_Shape aMultiArgShape;
1037 //GEOM::GEOM_Object_var anArgOMulti; // ???
1038 switch (anOFun->GetType()) {
1041 GEOMImpl_ITranslate aTI (anOFun);
1042 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape1D(anArgOShape, &aTI);
1043 //anArgOMulti = aTrsfOpSv->Translate1D(anArgO, , , );
1048 GEOMImpl_ITranslate aTI (anOFun);
1049 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1054 GEOMImpl_IRotate aTI (anOFun);
1055 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1060 GEOMImpl_IRotate aTI (anOFun);
1061 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1067 GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO
1068 Handle(GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction();
1069 anArgOMultiFun->SetDescription("");
1070 aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti);
1076 case GEOM::FSM_Transformed:
1078 // transformation, cannot use GetInPlace, operate with indices
1079 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1080 if (anIDs->length() > 1) {
1082 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1083 if (!CORBA::is_nil(aSubO))
1084 aGroupOp->UnionIDs(aSubO, anIDs);
1086 else if (anIDs->length() > 0) {
1088 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1092 case GEOM::FSM_GetSame:
1095 aSubO = aShapesOp->GetSame(theObject, anArgO);
1098 case GEOM::FSM_GetShapesOnShape:
1100 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1101 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1102 (short)GEOM::SOLID, GEOM::ST_ONIN);
1105 case GEOM::FSM_GetInPlaceByHistory:
1107 // Use GetInPlaceByHistory
1108 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1115 if (!CORBA::is_nil(aSubO)) {
1116 // remember restored objects for Python Dump
1117 addToListOfGO(anArgO, anOutArgs);
1119 // add to parts list
1120 addToListOfGO( aSubO, aParts );
1122 // Publish the sub-shape
1123 SALOMEDS::SObject_var aSubSO;
1124 if (!CORBA::is_nil(theSObject)) {
1125 TCollection_AsciiString aSubName;
1129 aSubName += anArgName;
1130 aSubSO = aStudyBuilder->NewObject(theSObject);
1131 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1133 aSubO->SetColor(anArgO->GetColor());
1135 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1136 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1137 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1138 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1142 if (!CORBA::is_nil(anArgSO)) {
1143 // Restore published sub-shapes of the argument
1144 GEOM::ListOfGO_var aSubParts;
1145 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1146 // pass theObject, because only it has the history
1147 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1148 theObject, anOutArgs, theFindMethod, theAddPrefix);
1150 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1151 aSubO, anOutArgs, theFindMethod, theAddPrefix);
1152 // add to parts list
1153 addToListOfGO( aSubParts, aParts );
1156 else { // GetInPlace failed, try to build from published parts
1157 if (!CORBA::is_nil(anArgSO)) {
1158 SALOMEDS::SObject_var aSubSO;
1159 if (!CORBA::is_nil(theSObject))
1160 aSubSO = aStudyBuilder->NewObject(theSObject);
1162 // Restore published sub-shapes of the argument
1163 GEOM::ListOfGO_var aSubParts =
1164 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1165 theObject, anOutArgs, theFindMethod, theAddPrefix);
1167 // add to parts list
1168 addToListOfGO( aSubParts, aParts );
1170 if (aSubParts->length() > 0) {
1171 // remember restored objects for Python Dump
1172 addToListOfGO(anArgO, anOutArgs);
1174 // try to build an argument from a set of its sub-shapes,
1175 // that published and will be reconstructed
1176 if (aSubParts->length() > 1) {
1177 aSubO = aShapesOp->MakeCompound(aSubParts);
1178 // add to parts list
1179 addToListOfGO( aSubO, aParts );
1182 aSubO = aSubParts[0];
1184 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1185 // Publish the sub-shape
1186 TCollection_AsciiString aSubName;
1188 aSubName = "from_parts_of_";
1190 aSubName += anArgName;
1191 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1193 aSubO->SetColor(anArgO->GetColor());
1195 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1196 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1197 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1198 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1202 else if (!CORBA::is_nil(aSubSO)) {
1203 // remove created aSubSO, because no parts have been found
1204 aStudyBuilder->RemoveObject(aSubSO);
1207 } // try to build from published parts
1208 anArgSO->UnRegister();
1210 } // process arguments
1212 std::set<std::string> anObjEntryMap;
1213 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1215 int nb = aParts->length();
1216 aResParts->length(nb);
1219 Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1220 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1221 GEOM::TPythonDump pd (aFunction, true);
1224 for ( ; i < nb; i++ )
1226 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1227 if (CORBA::is_nil(anObj))
1229 char* anEntry = anObj->GetEntry();
1230 if (anObjEntryMap.count(anEntry))
1231 continue; // already treated
1232 anObjEntryMap.insert(anEntry);
1233 aResParts[nbRes++] = anObj;
1234 // clear python dump of object
1235 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1236 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1237 if ( !anObjFun.IsNull() )
1238 anObjFun->SetDescription( "" );
1244 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1245 //i = 0; nb = theArgs.length(); j = 0;
1246 i = 0; nb = anOutArgs->length(); j = 0;
1247 for ( ; i < nb; i++ )
1249 //GEOM::GEOM_Object_var anObj = theArgs[ i ];
1250 GEOM::GEOM_Object_var anObj = anOutArgs[ i ];
1251 if (CORBA::is_nil(anObj))
1253 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1259 pd <<"]" << ", " <<"GEOM.";
1260 switch (theFindMethod) {
1261 case GEOM::FSM_GetInPlace:
1262 pd << "FSM_GetInPlace"; break;
1263 case GEOM::FSM_MultiTransformed:
1264 pd << "FSM_MultiTransformed"; break;
1265 case GEOM::FSM_Transformed:
1266 pd << "FSM_Transformed"; break;
1267 case GEOM::FSM_GetSame:
1268 pd << "FSM_GetSame"; break;
1269 case GEOM::FSM_GetShapesOnShape:
1270 pd << "FSM_GetShapesOnShape"; break;
1271 case GEOM::FSM_GetInPlaceByHistory:
1273 pd << "FSM_GetInPlaceByHistory"; break;
1275 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1277 aResParts->length(nbRes);
1278 return aResParts._retn();
1281 //============================================================================
1282 // function : RestoreSubShapesOneLevel
1283 // purpose : Private method
1284 //============================================================================
1285 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1286 SALOMEDS::SObject_ptr theOldSO,
1287 SALOMEDS::SObject_ptr theNewSO,
1288 GEOM::GEOM_Object_ptr theNewO,
1289 GEOM::ListOfGO& theOutArgs,
1290 GEOM::find_shape_method theFindMethod,
1291 CORBA::Boolean theAddPrefix)
1294 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1295 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1296 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1297 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1298 return aParts._retn();
1300 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1302 // Get interface, containing method, which we will use to reconstruct sub-shapes
1303 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1304 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1305 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1307 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1308 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1310 // Reconstruct published sub-shapes
1311 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1314 for (it->Init(); it->More(); it->Next()) {
1317 aParts->length(aLen);
1319 for (it->Init(); it->More(); it->Next()) {
1320 SALOMEDS::SObject_var anOldSubSO = it->Value();
1322 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1324 SALOMEDS::GenericAttribute_var anAttr;
1325 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1326 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1327 GEOM::GEOM_Object_var anOldSubO =
1328 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1329 if (!CORBA::is_nil(anOldSubO)) {
1330 // Find a sub-shape of theNewO in place of anOldSubO
1331 GEOM::GEOM_Object_var aNewSubO;
1332 switch (theFindMethod) {
1333 case GEOM::FSM_GetInPlace:
1336 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1339 case GEOM::FSM_MultiTransformed:
1341 // Only for Multi-transformations
1342 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
1343 if (!CORBA::is_nil(anArgOTrsf)) {
1344 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1345 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1346 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1347 anArgOTrsfFun->SetDescription("");
1348 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1352 case GEOM::FSM_Transformed:
1354 // transformation, cannot use GetInPlace, operate with indices
1355 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1356 if (anIDs->length() > 1) {
1358 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1359 if (!CORBA::is_nil(aNewSubO))
1360 aGroupOp->UnionIDs(aNewSubO, anIDs);
1364 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1368 case GEOM::FSM_GetSame:
1371 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1374 case GEOM::FSM_GetShapesOnShape:
1376 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1377 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1378 (short)GEOM::SOLID, GEOM::ST_ONIN);
1381 case GEOM::FSM_GetInPlaceByHistory:
1383 // Use GetInPlaceByHistory
1384 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1391 if (!CORBA::is_nil(aNewSubO)) {
1392 // remember restored objects for Python Dump
1393 addToListOfGO(anOldSubO, theOutArgs);
1395 // add the part to the list
1396 aParts[i] = aNewSubO;
1398 // add to parts list
1399 addToListOfGO( aNewSubO, aNewParts );
1401 SALOMEDS::SObject_var aNewSubSO;
1402 if (!CORBA::is_nil(theNewSO)) {
1403 // Publish the sub-shape
1404 TCollection_AsciiString aSubName;
1408 aSubName += anArgName;
1409 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1410 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1412 aNewSubO->SetColor(anOldSubO->GetColor());
1414 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1415 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1416 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1417 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1420 // Restore published sub-shapes of the argument
1421 GEOM::ListOfGO_var aSubParts;
1422 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1423 // pass the main shape as Object, because only it has the history
1424 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1425 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1427 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1428 aNewSubO, theOutArgs, theFindMethod, theAddPrefix);
1429 // add to parts list
1430 addToListOfGO( aSubParts, aNewParts );
1432 else { // GetInPlace failed, try to build from published parts
1433 SALOMEDS::SObject_var aNewSubSO;
1434 if (!CORBA::is_nil(theNewSO))
1435 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1437 // Restore published sub-shapes of the argument
1438 GEOM::ListOfGO_var aSubParts =
1439 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1440 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1441 // add to parts list
1442 addToListOfGO( aSubParts, aNewParts );
1444 if (aSubParts->length() > 0) {
1445 // remember restored objects for Python Dump
1446 addToListOfGO(anOldSubO, theOutArgs);
1448 // try to build an object from a set of its sub-shapes,
1449 // that published and will be reconstructed
1450 if (aSubParts->length() > 1) {
1451 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1452 // add to parts list
1453 addToListOfGO( aNewSubO, aNewParts );
1456 aNewSubO = aSubParts[0];
1459 if (!CORBA::is_nil(aNewSubO)) {
1460 // add the part to the list
1461 aSubParts[i] = aNewSubO;
1464 // Publish the sub-shape
1465 if (!CORBA::is_nil(aNewSubSO)) {
1466 TCollection_AsciiString aSubName;
1468 aSubName = "from_parts_of_";
1470 aSubName += anArgName;
1471 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1473 aNewSubO->SetColor(anOldSubO->GetColor());
1475 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1476 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1477 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1478 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1483 else if (!CORBA::is_nil(aNewSubSO)) {
1484 // remove created aSubSO, because no parts have been found
1485 aStudyBuilder->RemoveObject(aNewSubSO);
1487 } // try to build from published parts
1490 } // iterate on published sub-shapes
1493 // add to parts list
1494 addToListOfGO( aNewParts, aParts );
1495 return aParts._retn();
1498 //============================================================================
1499 // function : RestoreGivenSubShapes
1500 // purpose : Private method. Works only if both theObject and theSObject
1501 // are defined, and does not check, if they correspond to each other.
1502 // List theArgs in this case contains not only operation arguments,
1503 // but also all subshapes, which must be published.
1504 //============================================================================
1505 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStudy,
1506 GEOM::GEOM_Object_ptr theObject,
1507 SALOMEDS::SObject_ptr theSObject,
1508 const GEOM::ListOfGO& theArgs,
1509 GEOM::find_shape_method theFindMethod,
1510 CORBA::Boolean theInheritFirstArg,
1511 CORBA::Boolean theAddPrefix)
1513 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1514 //PTv, IMP 0020001, The salome object <theSObject>
1515 // is not obligatory in case of invokation from script
1516 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
1517 return aParts._retn();
1519 // If theArgs list is empty, nothing to do
1520 Standard_Integer aLength = theArgs.length();
1522 return aParts._retn();
1524 // Get all arguments
1525 GEOM::ListOfGO_var anOpArgsList = theObject->GetDependency();
1526 Standard_Integer nbArgsActual = anOpArgsList->length();
1528 // If anOpArgsList list is empty, nothing to do
1529 if (nbArgsActual == 0)
1530 return aParts._retn();
1532 // Entries of arguments and subshapes
1533 std::set<std::string> anArgs;
1534 for (int i = 0; i < aLength; i++) {
1535 CORBA::String_var anEntry = theArgs[i]->GetEntry();
1536 anArgs.insert(anEntry.in());
1539 // Arguments to be published
1540 // We try to publish all arguments, that are in theArgs list
1541 GEOM::ListOfGO_var aList = new GEOM::ListOfGO;
1542 aList->length(nbArgsActual);
1545 for (int j = 0; j < nbArgsActual; j++) {
1546 CORBA::String_var anEntry = anOpArgsList[j]->GetEntry();
1547 if (anArgs.count(anEntry.in())) {
1548 aList[k] = GEOM::GEOM_Object::_duplicate(anOpArgsList[j]);
1553 //aList->length(nbArgsActual);
1555 if (nbArgsActual < 1)
1556 return aParts._retn();
1558 if (theInheritFirstArg || (nbArgsActual == 1)) {
1559 // Do not publish argument's reflection,
1560 // but only reconstruct its published sub-shapes
1562 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1563 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1565 aParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
1566 anArgs, theFindMethod, theAddPrefix);
1568 // set the color of the transformed shape to the color of initial shape
1569 theObject->SetColor(aList[0]->GetColor());
1571 if (theObject->GetShapeType() == GEOM::VERTEX) {
1572 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1573 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1574 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1577 anArgSO->UnRegister();
1580 // Get interface, containing method, which we will use to reconstruct sub-shapes
1581 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1582 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1583 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1585 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1586 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1588 // Reconstruct arguments and tree of sub-shapes of the arguments
1589 CORBA::String_var anIOR;
1590 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1591 for (Standard_Integer i = 0; i < nbArgsActual; i++)
1593 GEOM::GEOM_Object_var anArgO = aList[i];
1594 if (!CORBA::is_nil(anArgO)) {
1595 anIOR = _orb->object_to_string(anArgO);
1596 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1597 TCollection_AsciiString anArgName;
1598 if (CORBA::is_nil(anArgSO)) {
1600 anArgName += TCollection_AsciiString(i);
1603 anArgName = anArgSO->GetName();
1606 // Find a sub-shape of theObject in place of the argument
1607 GEOM::GEOM_Object_var aSubO;
1608 switch (theFindMethod) {
1609 case GEOM::FSM_GetInPlace:
1612 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1615 case GEOM::FSM_MultiTransformed:
1617 // Only for Multi-transformations
1618 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1619 if (!CORBA::is_nil(anArgOTrsf)) {
1620 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1621 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1622 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1623 anArgOTrsfFun->SetDescription("");
1624 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1628 case GEOM::FSM_Transformed:
1630 // transformation, cannot use GetInPlace, operate with indices
1631 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1632 if (anIDs->length() > 1) {
1634 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1635 if (!CORBA::is_nil(aSubO))
1636 aGroupOp->UnionIDs(aSubO, anIDs);
1638 else if (anIDs->length() > 0) {
1640 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1644 case GEOM::FSM_GetSame:
1647 aSubO = aShapesOp->GetSame(theObject, anArgO);
1650 case GEOM::FSM_GetShapesOnShape:
1652 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1653 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1654 (short)GEOM::SOLID, GEOM::ST_ONIN);
1657 case GEOM::FSM_GetInPlaceByHistory:
1659 // Use GetInPlaceByHistory
1660 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1667 if (!CORBA::is_nil(aSubO)) {
1668 // add to parts list
1669 addToListOfGO( aSubO, aParts );
1671 // Publish the sub-shape
1672 SALOMEDS::SObject_var aSubSO;
1673 if (!CORBA::is_nil(theSObject)) {
1674 TCollection_AsciiString aSubName;
1678 aSubName += anArgName;
1679 aSubSO = aStudyBuilder->NewObject(theSObject);
1680 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1682 aSubO->SetColor(anArgO->GetColor());
1684 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1685 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1686 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1687 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1691 if (!CORBA::is_nil(anArgSO)) {
1692 // Restore published sub-shapes of the argument
1693 GEOM::ListOfGO_var aSubParts;
1694 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1695 // pass theObject, because only it has the history
1696 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1697 theObject, anArgs, theFindMethod, theAddPrefix);
1699 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1700 aSubO, anArgs, theFindMethod, theAddPrefix);
1701 // add to parts list
1702 addToListOfGO( aSubParts, aParts );
1705 else { // GetInPlace failed, try to build from published parts
1706 if (!CORBA::is_nil(anArgSO)) {
1707 SALOMEDS::SObject_var aSubSO;
1708 if (!CORBA::is_nil(theSObject))
1709 aSubSO = aStudyBuilder->NewObject(theSObject);
1711 // Restore published sub-shapes of the argument
1712 GEOM::ListOfGO_var aSubParts =
1713 RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1714 theObject, anArgs, theFindMethod, theAddPrefix);
1716 // add to parts list
1717 addToListOfGO( aSubParts, aParts );
1719 if (aSubParts->length() > 0) {
1720 // try to build an argument from a set of its sub-shapes,
1721 // that published and will be reconstructed
1722 if (aSubParts->length() > 1) {
1723 aSubO = aShapesOp->MakeCompound(aSubParts);
1724 // add to parts list
1725 addToListOfGO( aSubO, aParts );
1728 aSubO = aSubParts[0];
1730 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1731 // Publish the sub-shape
1732 TCollection_AsciiString aSubName;
1734 aSubName = "from_parts_of_";
1736 aSubName += anArgName;
1737 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1739 aSubO->SetColor(anArgO->GetColor());
1741 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1742 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1743 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1744 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1748 else if (!CORBA::is_nil(aSubSO)) {
1749 // remove created aSubSO, because no parts have been found
1750 aStudyBuilder->RemoveObject(aSubSO);
1753 } // try to build from published parts
1754 anArgSO->UnRegister();
1756 } // process arguments
1758 std::set<std::string> anObjEntryMap;
1759 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1761 int nb = aParts->length();
1762 aResParts->length(nb);
1765 Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1766 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1767 GEOM::TPythonDump pd (aFunction, true);
1770 for ( ; i < nb; i++ )
1772 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1773 if (CORBA::is_nil(anObj))
1775 char* anEntry = anObj->GetEntry();
1776 if (anObjEntryMap.count(anEntry))
1777 continue; // already treated
1778 anObjEntryMap.insert(anEntry);
1779 aResParts[nbRes++] = anObj;
1780 // clear python dump of object
1781 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1782 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1783 if ( !anObjFun.IsNull() )
1784 anObjFun->SetDescription( "" );
1790 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1791 i = 0; nb = theArgs.length(); j = 0;
1792 for ( ; i < nb; i++ )
1794 GEOM::GEOM_Object_var anObj = theArgs[ i ];
1795 if (CORBA::is_nil(anObj))
1797 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1803 pd <<"]" << ", " <<"GEOM.";
1804 switch (theFindMethod) {
1805 case GEOM::FSM_GetInPlace:
1806 pd << "FSM_GetInPlace"; break;
1807 case GEOM::FSM_MultiTransformed:
1808 pd << "FSM_MultiTransformed"; break;
1809 case GEOM::FSM_Transformed:
1810 pd << "FSM_Transformed"; break;
1811 case GEOM::FSM_GetSame:
1812 pd << "FSM_GetSame"; break;
1813 case GEOM::FSM_GetShapesOnShape:
1814 pd << "FSM_GetShapesOnShape"; break;
1815 case GEOM::FSM_GetInPlaceByHistory:
1817 pd << "FSM_GetInPlaceByHistory"; break;
1819 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1821 aResParts->length(nbRes);
1822 return aResParts._retn();
1825 //============================================================================
1826 // function : RestoreGivenSubShapesOneLevel
1827 // purpose : Private method
1828 //============================================================================
1829 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1830 SALOMEDS::SObject_ptr theOldSO,
1831 SALOMEDS::SObject_ptr theNewSO,
1832 GEOM::GEOM_Object_ptr theNewO,
1833 std::set<std::string> theArgs,
1834 GEOM::find_shape_method theFindMethod,
1835 CORBA::Boolean theAddPrefix)
1838 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1839 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1840 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1841 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1842 return aParts._retn();
1844 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1846 // Get interface, containing method, which we will use to reconstruct sub-shapes
1847 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1848 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1849 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1851 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1852 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1854 // Reconstruct published sub-shapes
1855 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1858 for (it->Init(); it->More(); it->Next()) {
1861 aParts->length(aLen);
1863 for (it->Init(); it->More(); it->Next()) {
1864 SALOMEDS::SObject_var anOldSubSO = it->Value();
1866 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1868 SALOMEDS::GenericAttribute_var anAttr;
1869 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1870 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1871 GEOM::GEOM_Object_var anOldSubO =
1872 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1874 bool okToContinue = false;
1876 if (!CORBA::is_nil(anOldSubO)) {
1877 CORBA::String_var anEntry = anOldSubO->GetEntry();
1878 okToContinue = theArgs.count(anEntry.in());
1882 // Find a sub-shape of theNewO in place of anOldSubO
1883 GEOM::GEOM_Object_var aNewSubO;
1884 switch (theFindMethod) {
1885 case GEOM::FSM_GetInPlace:
1888 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1891 case GEOM::FSM_MultiTransformed:
1893 // Only for Multi-transformations
1894 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
1895 if (!CORBA::is_nil(anArgOTrsf)) {
1896 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1897 Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1898 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1899 anArgOTrsfFun->SetDescription("");
1900 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1904 case GEOM::FSM_Transformed:
1906 // transformation, cannot use GetInPlace, operate with indices
1907 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1908 if (anIDs->length() > 1) {
1910 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1911 if (!CORBA::is_nil(aNewSubO))
1912 aGroupOp->UnionIDs(aNewSubO, anIDs);
1916 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1920 case GEOM::FSM_GetSame:
1923 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1926 case GEOM::FSM_GetShapesOnShape:
1928 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1929 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1930 (short)GEOM::SOLID, GEOM::ST_ONIN);
1933 case GEOM::FSM_GetInPlaceByHistory:
1935 // Use GetInPlaceByHistory
1936 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1943 if (!CORBA::is_nil(aNewSubO)) {
1944 // add the part to the list
1945 aParts[i] = aNewSubO;
1947 // add to parts list
1948 addToListOfGO( aNewSubO, aNewParts );
1950 SALOMEDS::SObject_var aNewSubSO;
1951 if (!CORBA::is_nil(theNewSO)) {
1952 // Publish the sub-shape
1953 TCollection_AsciiString aSubName;
1957 aSubName += anArgName;
1958 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1959 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1961 aNewSubO->SetColor(anOldSubO->GetColor());
1963 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1964 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1965 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1966 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1969 // Restore published sub-shapes of the argument
1970 GEOM::ListOfGO_var aSubParts;
1971 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1972 // pass the main shape as Object, because only it has the history
1973 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1974 theNewO, theArgs, theFindMethod, theAddPrefix);
1976 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1977 aNewSubO, theArgs, theFindMethod, theAddPrefix);
1978 // add to parts list
1979 addToListOfGO( aSubParts, aNewParts );
1981 else { // GetInPlace failed, try to build from published parts
1982 SALOMEDS::SObject_var aNewSubSO;
1983 if (!CORBA::is_nil(theNewSO))
1984 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1986 // Restore published sub-shapes of the argument
1987 GEOM::ListOfGO_var aSubParts =
1988 RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1989 theNewO, theArgs, theFindMethod, theAddPrefix);
1990 // add to parts list
1991 addToListOfGO( aSubParts, aNewParts );
1993 if (aSubParts->length() > 0) {
1994 // try to build an object from a set of its sub-shapes,
1995 // that published and will be reconstructed
1996 if (aSubParts->length() > 1) {
1997 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1998 // add to parts list
1999 addToListOfGO( aNewSubO, aNewParts );
2002 aNewSubO = aSubParts[0];
2005 if (!CORBA::is_nil(aNewSubO)) {
2006 // add the part to the list
2007 aSubParts[i] = aNewSubO;
2010 // Publish the sub-shape
2011 if (!CORBA::is_nil(aNewSubSO)) {
2012 TCollection_AsciiString aSubName;
2014 aSubName = "from_parts_of_";
2016 aSubName += anArgName;
2017 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
2019 aNewSubO->SetColor(anOldSubO->GetColor());
2021 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2022 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2023 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2024 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2029 else if (!CORBA::is_nil(aNewSubSO)) {
2030 // remove created aSubSO, because no parts have been found
2031 aStudyBuilder->RemoveObject(aNewSubSO);
2033 } // try to build from published parts
2036 } // iterate on published sub-shapes
2039 // add to parts list
2040 addToListOfGO( aNewParts, aParts );
2041 return aParts._retn();
2044 //============================================================================
2045 // function : register()
2046 // purpose : register 'name' in 'name_service'
2047 //============================================================================
2048 void GEOM_Gen_i::register_name(char * name)
2050 GEOM::GEOM_Gen_var g = _this();
2051 name_service->Register(g, name);
2054 //============================================================================
2057 //============================================================================
2058 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
2060 _impl->Undo(theStudyID);
2063 //============================================================================
2066 //============================================================================
2067 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
2069 _impl->Redo(theStudyID);
2072 //============================================================================
2073 // function : GetIBasicOperations
2075 //============================================================================
2076 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
2077 throw ( SALOME::SALOME_Exception )
2079 Unexpect aCatch(SALOME_SalomeException);
2080 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
2082 GEOM::GEOM_Gen_ptr engine = _this();
2084 //transfer reference on engine
2085 GEOM_IBasicOperations_i* aServant =
2086 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
2088 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2089 // activate the CORBA servant
2090 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
2091 return operations._retn();
2094 //============================================================================
2095 // function : GetITransformOperations
2097 //============================================================================
2098 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
2099 throw ( SALOME::SALOME_Exception )
2101 Unexpect aCatch(SALOME_SalomeException);
2102 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
2104 GEOM::GEOM_Gen_ptr engine = _this();
2106 GEOM_ITransformOperations_i* aServant =
2107 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
2109 // activate the CORBA servant
2110 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
2111 return operations._retn();
2114 //============================================================================
2115 // function : GetI3DPrimOperations
2117 //============================================================================
2118 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
2119 throw ( SALOME::SALOME_Exception )
2121 Unexpect aCatch(SALOME_SalomeException);
2122 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
2124 GEOM::GEOM_Gen_ptr engine = _this();
2126 GEOM_I3DPrimOperations_i* aServant =
2127 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
2128 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2130 // activate the CORBA servant
2131 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
2132 return operations._retn();
2135 //============================================================================
2136 // function : GetIShapesOperations
2138 //============================================================================
2139 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
2140 throw ( SALOME::SALOME_Exception )
2142 Unexpect aCatch(SALOME_SalomeException);
2143 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
2145 GEOM::GEOM_Gen_ptr engine = _this();
2147 GEOM_IShapesOperations_i* aServant =
2148 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
2150 // activate the CORBA servant
2151 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
2152 return operations._retn();
2155 //============================================================================
2156 // function : GetIBlocksOperations
2158 //============================================================================
2159 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
2160 throw ( SALOME::SALOME_Exception )
2162 Unexpect aCatch(SALOME_SalomeException);
2163 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
2165 GEOM::GEOM_Gen_ptr engine = _this();
2167 GEOM_IBlocksOperations_i* aServant =
2168 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
2170 // activate the CORBA servant
2171 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
2172 return operations._retn();
2175 //============================================================================
2176 // function : GetIBooleanOperations
2178 //============================================================================
2179 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
2180 throw ( SALOME::SALOME_Exception )
2182 Unexpect aCatch(SALOME_SalomeException);
2183 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
2185 GEOM::GEOM_Gen_ptr engine = _this();
2187 GEOM_IBooleanOperations_i* aServant =
2188 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
2190 // activate the CORBA servant
2191 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
2192 return operations._retn();
2195 //============================================================================
2196 // function : GetICurvesOperations
2198 //============================================================================
2199 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
2200 throw ( SALOME::SALOME_Exception )
2202 Unexpect aCatch(SALOME_SalomeException);
2203 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
2205 GEOM::GEOM_Gen_ptr engine = _this();
2207 GEOM_ICurvesOperations_i* aServant =
2208 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
2210 // activate the CORBA servant
2211 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
2212 return operations._retn();
2215 //============================================================================
2216 // function : GetILocalOperations
2218 //============================================================================
2219 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
2220 throw ( SALOME::SALOME_Exception )
2222 Unexpect aCatch(SALOME_SalomeException);
2223 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
2225 GEOM::GEOM_Gen_ptr engine = _this();
2227 GEOM_ILocalOperations_i* aServant =
2228 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
2230 // activate the CORBA servant
2231 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
2232 return operations._retn();
2235 //============================================================================
2236 // function : GetIHealingOperations
2238 //============================================================================
2239 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
2240 throw ( SALOME::SALOME_Exception )
2242 Unexpect aCatch(SALOME_SalomeException);
2243 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
2245 GEOM::GEOM_Gen_ptr engine = _this();
2247 GEOM_IHealingOperations_i* aServant =
2248 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
2250 // activate the CORBA servant
2251 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
2252 return operations._retn();
2255 //============================================================================
2256 // function : GetIInsertOperations
2258 //============================================================================
2259 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
2260 throw ( SALOME::SALOME_Exception )
2262 Unexpect aCatch(SALOME_SalomeException);
2263 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
2265 GEOM::GEOM_Gen_ptr engine = _this();
2267 GEOM_IInsertOperations_i* aServant =
2268 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
2270 // activate the CORBA servant
2271 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
2272 return operations._retn();
2275 //============================================================================
2276 // function : GetIMeasureOperations
2278 //============================================================================
2279 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
2280 throw ( SALOME::SALOME_Exception )
2282 Unexpect aCatch(SALOME_SalomeException);
2283 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
2285 GEOM::GEOM_Gen_ptr engine = _this();
2287 GEOM_IMeasureOperations_i* aServant =
2288 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
2290 // activate the CORBA servant
2291 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
2292 return operations._retn();
2295 //============================================================================
2296 // function : GetIGroupOperations
2298 //============================================================================
2299 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
2300 throw ( SALOME::SALOME_Exception )
2302 Unexpect aCatch(SALOME_SalomeException);
2303 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
2305 GEOM::GEOM_Gen_ptr engine = _this();
2307 GEOM_IGroupOperations_i* aServant =
2308 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
2310 // activate the CORBA servant
2311 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
2312 return operations._retn();
2315 //============================================================================
2316 // function : GetIAdvancedOperations
2318 //============================================================================
2319 GEOM::GEOM_IAdvancedOperations_ptr GEOM_Gen_i::GetIAdvancedOperations(CORBA::Long theStudyID)
2320 throw ( SALOME::SALOME_Exception )
2322 Unexpect aCatch(SALOME_SalomeException);
2323 MESSAGE( "GEOM_Gen_i::GetIAdvancedOperations" );
2325 GEOM::GEOM_Gen_ptr engine = _this();
2327 GEOM_IAdvancedOperations_i* aServant =
2328 new GEOM_IAdvancedOperations_i(_poa, engine, _impl->GetIAdvancedOperations(theStudyID));
2330 // activate the CORBA servant
2331 GEOM::GEOM_IAdvancedOperations_var operations = aServant->_this();
2332 return operations._retn();
2335 //=============================================================================
2339 //=============================================================================
2340 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
2341 const GEOM::ListOfLong& theIndices)
2343 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
2344 return GEOM::GEOM_Object::_nil();
2345 CORBA::String_var entry = theMainShape->GetEntry();
2346 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
2347 if (aMainShape.IsNull()) return GEOM::GEOM_Object::_nil();
2349 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
2350 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
2352 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true);
2353 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
2355 TCollection_AsciiString anEntry;
2356 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
2357 return GetObject(anObject->GetDocID(), anEntry.ToCString());
2360 //=============================================================================
2364 //=============================================================================
2365 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
2367 CORBA::String_var anEntry = theObject->GetEntry();
2368 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false);
2369 if (anObject.IsNull()) return;
2370 _impl->RemoveObject(anObject);
2375 //=================================================================================
2376 // function : GetStringFromIOR()
2377 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
2378 //=================================================================================
2379 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
2380 return _orb->object_to_string(theObject);
2384 //=================================================================================
2385 // function : GetIORFromString()
2386 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
2387 //=================================================================================
2388 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
2389 GEOM::GEOM_Object_var aGeomObject;
2390 if(strcmp(stringIOR,"") != 0){
2391 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
2392 if(!CORBA::is_nil(anObject))
2393 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
2395 return aGeomObject._retn();
2398 //=================================================================================
2399 // function : GetObject()
2401 //=================================================================================
2402 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
2404 GEOM::GEOM_Object_var obj;
2405 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
2406 if (handle_object.IsNull()) return obj._retn();
2408 TCollection_AsciiString stringIOR = handle_object->GetIOR();
2409 if (stringIOR.Length() > 1) {
2410 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
2411 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
2415 GEOM::GEOM_Gen_ptr engine = _this();
2416 //transfer the reference to GEOM_Object_i
2417 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
2418 PortableServer::ObjectId_var id = _poa->activate_object(servant);
2420 obj = servant->_this();
2421 CORBA::String_var objStr = _orb->object_to_string(obj);
2422 TCollection_AsciiString anAscii( (char *)objStr.in() );
2423 handle_object->SetIOR( anAscii );
2427 //=================================================================================
2428 // function : hasObjectInfo()
2429 // purpose : shows if module provides information for its objects
2430 //=================================================================================
2431 bool GEOM_Gen_i::hasObjectInfo()
2436 //=================================================================================
2437 // function : getObjectInfo()
2438 // purpose : returns an information for a given object by its entry
2439 //=================================================================================
2440 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
2442 GEOM::GEOM_Object_var aGeomObject;
2444 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
2445 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
2446 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
2447 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
2448 SALOMEDS::SObject_var aResultSObj;
2449 if (aSObj->ReferencedObject(aResultSObj))
2450 aSObj = aResultSObj;
2452 SALOMEDS::GenericAttribute_var anAttr;
2453 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
2454 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2455 CORBA::String_var aVal = anIOR->Value();
2456 anIOR->UnRegister();
2457 CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
2458 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
2460 if (!aSObj->_is_nil() )
2461 aSObj->UnRegister();
2463 const char* aTypeInfo = "Object";
2464 if ( !aGeomObject->_is_nil() ) {
2465 GEOM::GEOM_IKindOfShape::shape_kind aKind;
2466 GEOM::ListOfLong_var anInts;
2467 GEOM::ListOfDouble_var aDbls;
2469 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
2470 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
2472 if ( anOp->IsDone() ) {
2474 case GEOM::GEOM_IKindOfShape::COMPOUND:
2475 aTypeInfo = "Compound";
2477 case GEOM::GEOM_IKindOfShape::COMPSOLID:
2478 aTypeInfo = "CompSolid";
2480 case GEOM::GEOM_IKindOfShape::SHELL:
2481 aTypeInfo = "Shell";
2483 case GEOM::GEOM_IKindOfShape::WIRE:
2484 if ( anInts[0] == 1 )
2485 aTypeInfo = "Closed Wire";
2486 else if ( anInts[0] == 2 )
2487 aTypeInfo = "Opened Wire";
2492 case GEOM::GEOM_IKindOfShape::SPHERE:
2493 aTypeInfo = "Sphere";
2495 case GEOM::GEOM_IKindOfShape::CYLINDER:
2496 aTypeInfo = "Cylinder";
2498 case GEOM::GEOM_IKindOfShape::BOX:
2499 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
2502 case GEOM::GEOM_IKindOfShape::TORUS:
2503 aTypeInfo = "Torus";
2505 case GEOM::GEOM_IKindOfShape::CONE:
2508 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
2509 aTypeInfo = "Polyhedron";
2511 case GEOM::GEOM_IKindOfShape::SOLID:
2512 aTypeInfo = "Solid";
2515 case GEOM::GEOM_IKindOfShape::SPHERE2D:
2516 aTypeInfo = "Spherical Face";
2518 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
2519 aTypeInfo = "Cylindrical Face";
2521 case GEOM::GEOM_IKindOfShape::TORUS2D:
2522 aTypeInfo = "Toroidal Face";
2524 case GEOM::GEOM_IKindOfShape::CONE2D:
2525 aTypeInfo = "Conical Face";
2527 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
2530 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
2531 aTypeInfo = "Elliptical Face";
2533 case GEOM::GEOM_IKindOfShape::POLYGON:
2534 aTypeInfo = "Polygon";
2536 case GEOM::GEOM_IKindOfShape::PLANE:
2537 aTypeInfo = "Plane";
2539 case GEOM::GEOM_IKindOfShape::PLANAR:
2540 aTypeInfo = "Planar Face";
2542 case GEOM::GEOM_IKindOfShape::FACE:
2546 case GEOM::GEOM_IKindOfShape::CIRCLE:
2547 aTypeInfo = "Circle";
2549 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
2550 aTypeInfo = "Arc Circle";
2552 case GEOM::GEOM_IKindOfShape::ELLIPSE:
2553 aTypeInfo = "Ellipse";
2555 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
2556 aTypeInfo = "Arc Ellipse";
2558 case GEOM::GEOM_IKindOfShape::LINE:
2561 case GEOM::GEOM_IKindOfShape::SEGMENT:
2562 aTypeInfo = "Segment";
2564 case GEOM::GEOM_IKindOfShape::EDGE:
2567 case GEOM::GEOM_IKindOfShape::VERTEX:
2568 aTypeInfo = "Vertex";
2576 char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
2577 sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
2579 char* ret = CORBA::string_dup(anInfo);
2584 // Version information
2585 char* GEOM_Gen_i::getVersion()
2587 #if GEOM_DEVELOPMENT
2588 return CORBA::string_dup(GEOM_VERSION_STR"dev");
2590 return CORBA::string_dup(GEOM_VERSION_STR);
2594 //=================================================================================
2595 // function : CreateFolder()
2596 // purpose : Creates and returns a new folder object
2597 //=================================================================================
2598 SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName,
2599 SALOMEDS::SObject_ptr theFather)
2601 SALOMEDS::SObject_var aFolderSO;
2603 if ( CORBA::is_nil(theFather) ) return aFolderSO._retn();
2605 SALOMEDS::GenericAttribute_var anAttr;
2606 if ( strcmp(theFather->GetFatherComponent()->GetID(), theFather->GetID()) != 0 ) {
2607 // not a GEOM component object was selected
2608 if ( !theFather->FindAttribute(anAttr, "AttributeLocalID") ) return aFolderSO._retn();
2609 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2610 if( aLocalID->Value() != 999 ) {
2611 // not a Folder object was selected
2612 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow(theFather);
2613 if ( CORBA::is_nil(aGeomObject) ) return aFolderSO._retn();
2614 // another GEOM object was selected, so get GEOM component as father object
2615 theFather = theFather->GetFatherComponent();
2617 aLocalID->UnRegister();
2620 SALOMEDS::Study_var aStudy = theFather->GetStudy();
2621 SALOMEDS::StudyBuilder_var aStudyBuilder( aStudy->NewBuilder() );
2622 aFolderSO = aStudyBuilder->NewObject( theFather );
2624 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeLocalID");
2625 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2626 aLocalID->SetValue( 999 ); // mark of the "Folder" object
2627 aLocalID->UnRegister();
2629 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeName");
2630 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
2631 aName->SetValue( theName );
2632 aName->UnRegister();
2634 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributePixMap");
2635 SALOMEDS::AttributePixMap_var aPixMap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2636 aPixMap->SetPixMap("ICON_FOLDER");
2637 aPixMap->UnRegister();
2639 // add object to the use case tree
2640 // (to support tree representation customization and drag-n-drop)
2641 SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder();
2642 useCaseBuilder->AppendTo( theFather, aFolderSO );
2644 return aFolderSO._retn();
2647 //=================================================================================
2648 // function : MoveToFolder()
2649 // purpose : Moves GEOM object to the specified folder
2650 //=================================================================================
2651 void GEOM_Gen_i::MoveToFolder(GEOM::GEOM_Object_ptr theObject,
2652 SALOMEDS::SObject_ptr theFolder) {
2653 GEOM::object_list_var objects = new GEOM::object_list();
2654 objects->length( 1 );
2655 SALOMEDS::SObject_var aSO = theFolder->GetStudy()->FindObjectID( theObject->GetStudyEntry() );
2657 Move( objects, theFolder, -1 );
2660 //=================================================================================
2661 // function : MoveListToFolder()
2662 // purpose : Moves list of GEOM objects to the specified folder
2663 //=================================================================================
2664 void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO,
2665 SALOMEDS::SObject_ptr theFolder) {
2666 int aLen = theListOfGO.length();
2667 GEOM::object_list_var objects = new GEOM::object_list();
2668 objects->length( aLen );
2669 GEOM::GEOM_Object_var aGO;
2670 SALOMEDS::SObject_var aSO;
2671 for (int i = 0; i < aLen; i++) {
2672 aGO = GEOM::GEOM_Object::_duplicate( theListOfGO[i] );
2673 aSO = theFolder->GetStudy()->FindObjectID( aGO->GetStudyEntry() );
2676 if ( objects->length() > 0 )
2677 Move( objects, theFolder, -1 );
2680 //=================================================================================
2681 // function : Move()
2682 // purpose : Moves objects to the specified position.
2683 // Is used in the drag-n-drop functionality.
2684 //=================================================================================
2685 void GEOM_Gen_i::Move( const GEOM::object_list& what,
2686 SALOMEDS::SObject_ptr where,
2689 if ( CORBA::is_nil( where ) ) return;
2691 SALOMEDS::Study_var study = where->GetStudy();
2692 SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder();
2693 SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder();
2694 SALOMEDS::SComponent_var father = where->GetFatherComponent();
2695 std::string dataType = father->ComponentDataType();
2696 if ( dataType != "GEOM" ) return; // not a GEOM component
2698 SALOMEDS::SObject_var objAfter;
2699 if ( row >= 0 && useCaseBuilder->HasChildren( where ) ) {
2700 // insert at given row -> find insertion position
2701 SALOMEDS::UseCaseIterator_var useCaseIt = useCaseBuilder->GetUseCaseIterator( where );
2703 for ( i = 0; i < row && useCaseIt->More(); i++, useCaseIt->Next() );
2704 if ( i == row && useCaseIt->More() ) {
2705 objAfter = useCaseIt->Value();
2709 for ( int i = 0; i < what.length(); i++ ) {
2710 SALOMEDS::SObject_var sobj = what[i];
2711 if ( CORBA::is_nil( sobj ) ) continue; // skip bad object
2712 // insert the object to the use case tree
2713 if ( !CORBA::is_nil( objAfter ) )
2714 useCaseBuilder->InsertBefore( sobj, objAfter ); // insert at given row
2716 useCaseBuilder->AppendTo( where, sobj ); // append to the end of list
2720 //=====================================================================================
2722 //=====================================================================================
2727 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
2731 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb,
2732 PortableServer::POA_ptr poa,
2733 PortableServer::ObjectId* contId,
2734 const char* instanceName,
2735 const char* interfaceName)
2737 GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
2738 return myGEOM_Gen_i->getId();