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
23 #pragma warning( disable:4786 )
26 #include <Standard_Stream.hxx>
28 #include "GEOM_Gen_i.hh"
29 #include "GEOM_Object_i.hh"
30 #include "GEOM_Field_i.hh"
31 #include "GEOM_version.h"
33 #include "Utils_CorbaException.hxx"
35 #include "Utils_ExceptHandlers.hxx"
36 #include "utilities.h"
38 #include "GEOM_Object_i.hh"
39 #include "GEOM_Object.hxx"
40 #include "GEOM_Function.hxx"
41 #include "GEOM_ISubShape.hxx"
42 #include "GEOM_PythonDump.hxx"
43 #include "GEOMImpl_Types.hxx"
44 #include "GEOMImpl_CopyDriver.hxx"
45 #include "GEOM_wrap.hxx"
48 #include <BRep_Builder.hxx>
49 #include <BRepTools.hxx>
50 #include <TDF_Label.hxx>
51 #include <TDF_Tool.hxx>
52 #include <TDF_ChildIDIterator.hxx>
53 #include <TNaming_NamedShape.hxx>
54 #include <TDataStd_Name.hxx>
55 #include <TCollection_AsciiString.hxx>
56 #include <TColStd_HArray1OfInteger.hxx>
57 #include <TopAbs_ShapeEnum.hxx>
61 #include <SALOMEDS_Tool.hxx>
62 #include <SALOMEDS_wrap.hxx>
75 #define LibHandle HMODULE
76 #define LoadLib( name ) LoadLibrary( name )
77 #define GetProc GetProcAddress
78 #define UnLoadLib( handle ) FreeLibrary( handle );
80 #define LibHandle void*
81 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
83 #define UnLoadLib( handle ) dlclose( handle );
86 //============================================================================
87 // function : GEOM_Gen_i()
88 // purpose : constructor to be called for servant creation.
89 //============================================================================
90 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
91 PortableServer::POA_ptr poa,
92 PortableServer::ObjectId* contId,
93 const char* instanceName,
94 const char* interfaceName) :
95 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
98 _id = _poa->activate_object(_thisObj);
99 name_service = new SALOME_NamingService(_orb);
101 _impl = new ::GEOMImpl_Gen;
103 //PAL10867: disable signals catching with "noexcepthandler" option
104 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
105 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
107 //work around PAL12004, PAL12628
108 //OSD::SetSignal( true );
112 char* envDisableFPE = getenv("DISABLE_FPE");
113 if (envDisableFPE && atoi(envDisableFPE))
118 OSD::SetSignal( raiseFPE );
122 //============================================================================
123 // function : ~GEOM_Gen_i()
124 // purpose : destructor
125 //============================================================================
126 GEOM_Gen_i::~GEOM_Gen_i() {
132 //============================================================================
133 // function : IORToLocalPersistentID()
135 //============================================================================
136 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
137 const char* IORString,
138 CORBA::Boolean isMultiFile,
139 CORBA::Boolean isASCII)
141 GEOM::GEOM_BaseObject_var anObject =
142 GEOM::GEOM_BaseObject::_narrow(_orb->string_to_object(IORString));
143 if (!CORBA::is_nil(anObject)) {
144 return CORBA::string_dup(anObject->GetEntry());
150 //============================================================================
151 // function : LocalPersistentIDToIOR()
152 // purpose : Create/Load CORBA object from a persistent ref (an entry)
153 // : Used when a study is loaded
154 // : The IOR (IORName) of object created is returned
155 //============================================================================
156 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
157 const char* aLocalPersistentID,
158 CORBA::Boolean isMultiFile,
159 CORBA::Boolean isASCII)
161 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
163 Handle(GEOM_BaseObject) anObject =
164 _impl->GetObject(aStudy->StudyId(), aLocalPersistentID);
165 if ( !anObject.IsNull() )
167 TCollection_AsciiString anEntry;
168 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
169 GEOM::GEOM_BaseObject_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
171 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
172 return CORBA::string_dup(aPersRefString);
176 return CORBA::string_dup("");
180 //============================================================================
181 // function : CanPublishInStudy
183 //============================================================================
184 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
186 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
187 return !(anObject->_is_nil());
191 //============================================================================
192 // function : PublishInStudy
194 //============================================================================
195 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
196 SALOMEDS::SObject_ptr theSObject,
197 CORBA::Object_ptr theObject,
199 throw (SALOME::SALOME_Exception)
201 Unexpect aCatch(SALOME_SalomeException);
202 SALOMEDS::SObject_var aResultSO;
203 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
204 GEOM::GEOM_BaseObject_var aBaseObj = GEOM::GEOM_BaseObject::_narrow(theObject);
205 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
206 if(aBaseObj->_is_nil()) return aResultSO;
208 SALOMEDS::GenericAttribute_var anAttr;
209 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
210 SALOMEDS::UseCaseBuilder_var useCaseBuilder = theStudy->GetUseCaseBuilder();
212 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
213 if (aFather->_is_nil()) {
214 aFather = aStudyBuilder->NewComponent("GEOM");
215 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
216 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
217 aName->SetValue("Geometry");
219 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
220 SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr);
221 aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry");
222 aPixMap->UnRegister();
223 aStudyBuilder->DefineComponentInstance(aFather, (GEOM::GEOM_Gen_var)GEOM_Gen::_this());
224 // add component to the use case tree
225 // (to support tree representation customization and drag-n-drop)
226 useCaseBuilder->SetRootCurrent();
227 useCaseBuilder->Append( aFather ); // component object is added as the top level item
229 if (aFather->_is_nil()) return aResultSO;
231 if (CORBA::is_nil(theSObject)) {
232 aResultSO = aStudyBuilder->NewObject(aFather);
234 if (!theSObject->ReferencedObject(aResultSO))
235 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
236 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
238 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
239 aResultSO->SetAttrString("AttributeIOR",aGeomObjIOR);
241 TCollection_AsciiString anObjectName("Shape_");
243 // BEGIN: try to find existed name for current shape
244 bool HasName = false;
245 if ( !aShape->_is_nil() )
247 // recieve current TopoDS shape
248 CORBA::String_var entry = aShape->GetEntry();
249 Handle(GEOM_Object) aGShape = Handle(GEOM_Object)::DownCast
250 ( _impl->GetObject( aShape->GetStudyID(), entry ));
251 TopoDS_Shape TopoSh = aGShape->GetValue();
252 // find label of main shape
253 GEOM::GEOM_Object_var aMainSh = aShape;
254 while( !aMainSh->IsMainShape() ) {
255 aMainSh = aMainSh->GetMainShape();
257 entry = aMainSh->GetEntry();
258 Handle(GEOM_BaseObject) anObj = _impl->GetObject( aMainSh->GetStudyID(), entry );
259 TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry();
261 // check all named shapes using iterator
262 TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
264 for (; anIt.More() && !HasName; anIt.Next()) {
265 Handle(TNaming_NamedShape) anAttr =
266 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
267 if (anAttr.IsNull()) continue;
268 TopoDS_Shape S = anAttr->Get();
269 if (S.IsEqual(TopoSh)) {
270 TDF_Label L = anAttr->Label();
271 Handle(TDataStd_Name) aName;
272 if (L.FindAttribute(TDataStd_Name::GetID(), aName)) {
273 anObjectName = aName->Get();
279 // END: try to find existed name for current shape
281 CORBA::Long mytype=aBaseObj->GetType();
282 if ( mytype == GEOM_GROUP ) {
283 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
284 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape )) {
286 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_PNT" );
287 anObjectName = "Group_Of_Vertices_";
290 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_EDGE");
291 anObjectName = "Group_Of_Edges_";
294 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_FACE");
295 anObjectName = "Group_Of_Faces_";
298 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_SOLID");
299 anObjectName = "Group_Of_Solids_";
302 } else if ( mytype == GEOM_MARKER ) {
303 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS");
304 anObjectName = "LocalCS_";
305 } else if ( mytype > ADVANCED_BASE ) {
307 sprintf( buf, "%d", aBaseObj->GetType() );
308 std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf;
309 aResultSO->SetAttrString("AttributePixMap",advId.c_str());
310 anObjectName = "Advanced_";
311 } else if ( mytype == GEOM_FIELD ) {
312 anObjectName = "Field_";
313 GEOM::GEOM_Field_var aField = GEOM::GEOM_Field::_narrow(theObject);
314 if ( !aField->_is_nil() )
315 switch( aField->GetDimension() ) {
317 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_PNT" ); break;
319 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_EDGE"); break;
321 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_FACE"); break;
323 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID"); break;
325 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID");
327 } else if ( mytype == GEOM_FIELD_STEP ) {
328 anObjectName = "Step_";
329 } else if ( !aShape->_is_nil() ) {
330 GEOM::shape_type myshapetype=aShape->GetShapeType();
331 if ( myshapetype == GEOM::COMPOUND ) {
332 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPOUND" );
333 anObjectName = "Compound_";
334 } else if ( myshapetype == GEOM::COMPSOLID ) {
335 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPSOLID");
336 anObjectName = "Compsolid_";
337 } else if ( myshapetype == GEOM::SOLID ) {
338 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SOLID");
339 anObjectName = "Solid_";
340 } else if ( myshapetype == GEOM::SHELL ) {
341 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SHELL");
342 anObjectName = "Shell_";
343 } else if ( myshapetype == GEOM::FACE ) {
344 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FACE");
345 anObjectName = "Face_";
346 } else if ( myshapetype == GEOM::WIRE ) {
347 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_WIRE");
348 anObjectName = "Wire_";
349 } else if ( myshapetype == GEOM::EDGE ) {
350 aResultSO->SetAttrString("AttributePixMap", "ICON_OBJBROWSER_EDGE");
351 anObjectName = "Edge_";
352 } else if ( myshapetype == GEOM::VERTEX ) {
353 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_VERTEX" );
354 anObjectName = "Vertex_";
359 //if (strlen(theName) == 0) anObjectName += TCollection_AsciiString(aResultSO->Tag());
360 //else anObjectName = TCollection_AsciiString(CORBA::string_dup(theName));
362 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
363 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
364 // of objects in the study, but compute a number of objects with the same prefix
365 // and build a new name as Prefix_N+1
366 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
367 int i = 0; // (WITH EMPTY NEW NAME)
368 SALOMEDS::SObject_var obj;
369 TCollection_AsciiString aNewObjectName;
371 aNewObjectName = anObjectName + TCollection_AsciiString(++i);
372 obj = theStudy->FindObject( aNewObjectName.ToCString() );
374 while ( !obj->_is_nil() );
375 anObjectName = aNewObjectName;
377 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
378 anObjectName = theName;
381 //Set the study entry as a name of the published GEOM_Object
382 CORBA::String_var anID = aResultSO->GetID();
383 aBaseObj->SetStudyEntry(anID.in());
385 //Set a name of the added shape
386 aResultSO->SetAttrString("AttributeName",anObjectName.ToCString());
388 //Set NoteBook variables used in the object creation
389 TCollection_AsciiString aVars;
390 CORBA::String_var aString=aBaseObj->GetParameters();
391 SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aString);
392 for(int i = 0, n = aSections->length(); i < n; i++) {
393 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
394 for(int j = 0, m = aListOfVars.length(); j < m; j++) {
395 if(theStudy->IsVariable(aListOfVars[j].in()))
396 aVars += aListOfVars[j].in();
403 aResultSO->SetAttrString("AttributeString",aVars.ToCString());
405 aFather->UnRegister();
407 //Set a name of the GEOM object
408 aBaseObj->SetName(anObjectName.ToCString());
410 // add object to the use case tree
411 // (to support tree representation customization and drag-n-drop)
412 useCaseBuilder->AppendTo( aResultSO->GetFather(), aResultSO );
414 return aResultSO._retn();
417 //============================================================================
418 // function : CreateAndPublishGroup
419 // purpose : auxilary for PublishNamedShapesInStudy
420 //============================================================================
421 void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
422 GEOM::GEOM_Object_var theMainShape,
423 const TopTools_IndexedMapOfShape& anIndices,
424 const TopTools_SequenceOfShape& SeqS,
425 const TColStd_SequenceOfAsciiString& SeqN,
426 const Standard_CString& GrName,
427 GEOM::ListOfGO_var aResList)
429 CORBA::String_var entry = theMainShape->GetEntry();
430 //Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
431 Handle(TColStd_HArray1OfInteger) anArray;
432 if(SeqS.Length()>0) {
434 GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId());
435 GEOM::GEOM_Object_wrap GrObj = GOp->CreateGroup( theMainShape, SeqS(1).ShapeType() );
436 AddInStudy(theStudy, GrObj, GrName, theMainShape._retn());
437 //CORBA::String_var GrEntry = GrObj->GetEntry();
438 //Handle(GEOM_Object) HGrObj = _impl->GetObject(GrObj->GetStudyID(), GrEntry);
440 //Handle(GEOM_Object) anObj;
441 for(int i=1; i<=SeqS.Length(); i++) {
442 TopoDS_Shape aValue = SeqS.Value(i);
443 //anArray = new TColStd_HArray1OfInteger(1,1);
444 Standard_Integer anIndex = anIndices.FindIndex(aValue);
445 //anArray->SetValue(1, anIndex);
446 GOp->AddObject(GrObj,anIndex);
447 //anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE);
448 //if (anObj.IsNull()) continue;
449 //Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
450 //if (aFunction.IsNull()) continue;
451 //GEOM_ISubShape aSSI(aFunction);
452 //aSSI.SetMainShape(aMainShape->GetLastFunction());
453 //aSSI.SetIndices(anArray);
454 //aFunction->SetValue(aValue);
455 //GOp->UnionIDs(GrObj, anIndex);
456 //SALOMEDS::SObject_var aResultSO;
457 //TCollection_AsciiString anEntry;
458 //TDF_Tool::Entry(anObj->GetEntry(),anEntry);
459 //GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString());
460 //AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
466 //============================================================================
467 // function : PublishNamedShapesInStudy
469 //============================================================================
470 GEOM::ListOfGO* GEOM_Gen_i::
471 PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
472 //SALOMEDS::SObject_ptr theSObject,
473 CORBA::Object_ptr theObject)
475 //Unexpect aCatch(SALOME_SalomeException);
476 GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
478 //CORBA::Object_var theObject = theSObject->GetObject();
479 GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
480 if(theMainShape->_is_nil()) return aResList._retn();
482 CORBA::String_var entry = theMainShape->GetEntry();
483 Handle(GEOM_Object) aMainShape = Handle(GEOM_Object)::DownCast
484 ( _impl->GetObject( theMainShape->GetStudyID(), entry ));
485 if (aMainShape.IsNull()) return aResList._retn();
486 TopoDS_Shape MainSh = aMainShape->GetValue();
488 TDF_Label aMainLbl = aMainShape->GetEntry();
489 TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
490 TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
491 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
492 for(; anIt.More(); anIt.Next()) {
493 Handle(TNaming_NamedShape) anAttr =
494 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
495 if(anAttr.IsNull()) continue;
496 TopoDS_Shape S = anAttr->Get();
497 TDF_Label L = anAttr->Label();
498 //if(S.IsEqual(MainSh)) continue;
499 Handle(TDataStd_Name) aName;
500 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
501 TCollection_ExtendedString EName = aName->Get();
502 if(S.ShapeType()==TopAbs_SOLID) {
504 SolidSeqN.Append(aName->Get());
506 else if(S.ShapeType()==TopAbs_FACE) {
508 FaceSeqN.Append(aName->Get());
510 else if(S.ShapeType()==TopAbs_EDGE) {
512 EdgeSeqN.Append(aName->Get());
514 else if(S.ShapeType()==TopAbs_VERTEX) {
516 VertSeqN.Append(aName->Get());
521 TopTools_IndexedMapOfShape anIndices;
522 TopExp::MapShapes(MainSh, anIndices);
524 CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN,
525 "Group_Of_Named_Solids", aResList);
527 CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN,
528 "Group_Of_Named_Faces", aResList);
530 CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
531 "Group_Of_Named_Edges", aResList);
533 CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN,
534 "Group_Of_Named_Vertices", aResList);
536 return aResList._retn();
540 //============================================================================
542 // purpose : save OCAF/Geom document
543 //============================================================================
544 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
547 SALOMEDS::TMPFile_var aStreamFile;
548 // Get a temporary directory to store a file
549 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
551 // OCCT BUG: cannot save a document (in current folder)
552 // if directory name is empty
553 if (aTmpDir.size() == 0) {
561 // Create a list to store names of created files
562 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
564 // Prepare a file name to open
565 TCollection_AsciiString aNameWithExt("");
567 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
568 (theComponent->GetStudy()->URL())).c_str());
569 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
570 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
571 // Build a full file name of temporary file
572 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
573 // Save GEOM component in this file
574 _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
575 // Conver a file to the byte stream
576 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
577 // Remove the created file and tmp directory
578 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
580 // Return the created byte stream
581 return aStreamFile._retn();
585 //============================================================================
586 // function : SaveASCII()
588 //============================================================================
589 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
592 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
593 return aStreamFile._retn();
597 //============================================================================
600 //============================================================================
601 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
602 const SALOMEDS::TMPFile& theStream,
606 if (theStream.length() <= 9) {
607 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
611 // Get a temporary directory for a file
612 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
614 // OCCT BUG: cannot load a document (from current folder)
615 // if directory name is empty
616 if (aTmpDir.size() == 0) {
624 // Conver the byte stream theStream to a file and place it in tmp directory
625 SALOMEDS::ListOfFileNames_var aSeq =
626 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
628 // Prepare a file name to open
629 TCollection_AsciiString aNameWithExt("");
630 SALOMEDS::Study_var study = theComponent->GetStudy();
632 CORBA::String_var url = study->URL();
633 aNameWithExt = (char*)SALOMEDS_Tool::GetNameFromPath(url.in()).c_str();
635 aNameWithExt += "_GEOM.sgd";
636 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
639 if (!_impl->Load(study->StudyId(),(char*) aFullName.ToCString())) return false;
641 // Remove the created file and tmp directory
642 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
644 // creation of tree nodes for all data objects in the study
645 // to support tree representation customization and drag-n-drop:
646 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = study->GetUseCaseBuilder();
647 if ( !useCaseBuilder->IsUseCaseNode( theComponent ) ) {
648 useCaseBuilder->SetRootCurrent();
649 useCaseBuilder->Append( theComponent ); // component object is added as the top level item
652 SALOMEDS::ChildIterator_wrap it = study->NewChildIterator( theComponent );
653 for ( it->InitEx(true); it->More(); it->Next() ) {
654 if ( !useCaseBuilder->IsUseCaseNode( it->Value() ) ) {
655 useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() );
663 //============================================================================
664 // function : LoadASCII()
666 //============================================================================
667 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
668 const SALOMEDS::TMPFile& theStream,
671 return Load(theComponent, theStream, theURL, isMultiFile);
675 //============================================================================
676 // function : Close()
678 //============================================================================
679 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
681 SALOMEDS::Study_var aStudy= theComponent->GetStudy();
682 _impl->Close(aStudy->StudyId());
685 //============================================================================
686 // function : CanCopy()
688 //============================================================================
689 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
690 // Try to retrieve known by Geometry component GEOM_Object by given IOR
691 SALOMEDS::GenericAttribute_var anAttr;
692 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
694 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
696 CORBA::String_var aString=anIOR->Value();
698 CORBA::Object_var anObj = _orb->string_to_object(aString);
699 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(anObj);
700 // If the object is null one it can't be copied: return false
701 if (anObject->_is_nil()) return false;
705 //============================================================================
706 // function : CopyFrom()
708 //============================================================================
709 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
711 // Declare a sequence of the byte to store the copied object
712 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
714 // Try to get GEOM_Object object by given SObject
715 SALOMEDS::GenericAttribute_var anAttr;
716 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
717 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
718 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
719 if (anObject->_is_nil()) return aStreamFile._retn();
721 aStreamFile = anObject->GetShapeStream();
723 // Assign an ID the type of GEOM_Object
724 theObjectID = anObject->GetType();
726 // Return created TMPFile
727 return aStreamFile._retn();
730 //============================================================================
731 // function : CanPaste()
733 //============================================================================
734 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
735 // The Geometry component can paste only objects copied by Geometry component
736 // and with the object type = 1
737 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
741 //============================================================================
742 // function : PasteInto()
744 //============================================================================
745 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
746 CORBA::Long theObjectID,
747 SALOMEDS::SObject_ptr theObject) {
748 // Find the current Study and StudyBuilder
749 SALOMEDS::Study_var aStudy = theObject->GetStudy();
750 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
751 SALOMEDS::SObject_var aNewSO;
752 // Retrieve a TopoDS_Shape from byte stream
753 TopoDS_Shape aTopology;
754 std::istringstream aStreamedBrep((char*) &theStream[0]);
755 BRep_Builder aBuilder;
757 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
758 } catch (Standard_Failure) {
759 return aNewSO._retn();
762 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
763 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
764 aNewSO = aStudyBuilder->NewObject(theObject);
765 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
768 //Create a new GEOM_Object
769 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
770 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
771 aFunction->SetValue(aTopology);
773 TCollection_AsciiString anEntry;
774 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
775 GEOM::GEOM_BaseObject_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
777 //Set the study entry of the published GEOM_Object
778 obj->SetStudyEntry(aNewSO->GetID());
780 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
781 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
782 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
783 CORBA::String_var objStr = _orb->object_to_string(obj);
784 anIOR->SetValue(objStr.in());
787 // Return the created in the Study SObject
788 return aNewSO._retn();
791 //============================================================================
792 // function : ComponentDataType()
794 //============================================================================
795 char* GEOM_Gen_i::ComponentDataType()
797 return CORBA::string_dup("GEOM");
800 //============================================================================
801 // function : AddInStudy
803 //============================================================================
804 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
805 GEOM::GEOM_BaseObject_ptr theObject,
807 GEOM::GEOM_BaseObject_ptr theFather)
809 SALOMEDS::SObject_var aResultSO;
810 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
812 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
813 CORBA::String_var IOR;
815 if(!theFather->_is_nil()) {
816 IOR = _orb->object_to_string(theFather);
817 SALOMEDS::SObject_wrap aFatherSO = theStudy->FindObjectIOR(IOR.in());
818 if(aFatherSO->_is_nil()) return aResultSO._retn();
819 aResultSO = aStudyBuilder->NewObject(aFatherSO);
820 //aStudyBuilder->Addreference(aResultSO, aResultSO);
823 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
824 if(aResultSO->_is_nil()) return aResultSO._retn();
826 GEOM::ListOfGBO_var aList = theObject->GetDependency();
827 Standard_Integer aLength = aList->length();
828 if(aLength < 1) return aResultSO._retn();
830 //Publish the arguments
831 TCollection_AsciiString aPrevID; // to avoid multiple references to same object
832 for(Standard_Integer i = 0; i< aLength; i++) {
833 GEOM::GEOM_BaseObject_var anObject = aList[i];
834 if(anObject->_is_nil()) continue;
835 IOR = _orb->object_to_string(anObject);
836 SALOMEDS::SObject_wrap aSO = theStudy->FindObjectIOR(IOR.in());
837 if(aSO->_is_nil()) continue;
838 CORBA::String_var anID = aSO->GetID();
839 if ( aPrevID == anID.in() ) continue;
841 SALOMEDS::SObject_wrap aSubSO = aStudyBuilder->NewObject(aResultSO);
842 aStudyBuilder->Addreference(aSubSO, aSO);
843 theStudy->GetUseCaseBuilder()->AppendTo( aResultSO, aSubSO );
846 return aResultSO._retn();
849 //============================================================================
850 // function : RestoreSubShapesO
851 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
852 // To be used from python scripts out of geompy.addToStudy (non-default usage)
853 //============================================================================
854 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
855 GEOM::GEOM_Object_ptr theObject,
856 const GEOM::ListOfGO& theArgs,
857 GEOM::find_shape_method theFindMethod,
858 CORBA::Boolean theInheritFirstArg,
859 CORBA::Boolean theAddPrefix)
861 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
862 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
863 return aParts._retn();
865 // find SObject in the study if it is already published
866 CORBA::String_var anIORo = _orb->object_to_string(theObject);
867 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
868 //PTv, IMP 0020001, The salome object <aSO>
869 // is not obligatory in case of invokation from script
870 // if (CORBA::is_nil(aSO))
871 // return aParts._retn();
873 aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs,
874 theFindMethod, theInheritFirstArg, theAddPrefix);
875 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
876 return aParts._retn();
879 //============================================================================
880 // function : RestoreGivenSubShapesO
881 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
882 // To be used from python scripts, generated by Dump Python.
883 //============================================================================
884 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (SALOMEDS::Study_ptr theStudy,
885 GEOM::GEOM_Object_ptr theObject,
886 const GEOM::ListOfGO& theArgs,
887 GEOM::find_shape_method theFindMethod,
888 CORBA::Boolean theInheritFirstArg,
889 CORBA::Boolean theAddPrefix)
891 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
892 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
893 return aParts._retn();
895 // find SObject in the study if it is already published
896 CORBA::String_var anIORo = _orb->object_to_string(theObject);
897 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
898 //PTv, IMP 0020001, The salome object <aSO>
899 // is not obligatory in case of invokation from script
900 // if (CORBA::is_nil(aSO))
901 // return aParts._retn();
903 aParts = RestoreGivenSubShapes(theStudy, theObject, aSO, theArgs,
904 theFindMethod, theInheritFirstArg, theAddPrefix);
905 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
906 return aParts._retn();
909 //============================================================================
910 // function : RestoreSubShapesSO
911 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
912 // To be used from GUI and from geompy.addToStudy
913 //============================================================================
914 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
915 SALOMEDS::SObject_ptr theSObject,
916 const GEOM::ListOfGO& theArgs,
917 GEOM::find_shape_method theFindMethod,
918 CORBA::Boolean theInheritFirstArg,
919 CORBA::Boolean theAddPrefix)
921 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
922 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
923 return aParts._retn();
925 SALOMEDS::GenericAttribute_var anAttr;
926 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
927 return aParts._retn();
929 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
930 CORBA::String_var anIORso = anAttrIOR->Value();
932 // get Object from SObject
933 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
934 if (CORBA::is_nil(anO))
935 return aParts._retn();
937 aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs,
938 theFindMethod, theInheritFirstArg, theAddPrefix);
939 return aParts._retn();
942 //============================================================================
943 // function : addToListOfGO
944 // purpose : static local function
945 //============================================================================
946 static void addToListOfGO( GEOM::GEOM_Object_ptr theObject,
947 GEOM::ListOfGO& theList )
949 const int oldLen = theList.length();
950 theList.length(oldLen + 1);
951 theList[ oldLen ] = GEOM::GEOM_Object::_duplicate( theObject );
954 //============================================================================
955 // function : addToListOfGO
956 // purpose : static local function
957 //============================================================================
958 static void addToListOfGO( const GEOM::ListOfGO& theSrcList,
959 GEOM::ListOfGO& theTrgList )
961 const int oldLen = theTrgList.length();
962 const int srcLen = theSrcList.length();
963 theTrgList.length(oldLen + srcLen);
964 for( int i = 0; i < srcLen; i++ )
965 theTrgList[ oldLen + i ] = GEOM::GEOM_Object::_duplicate( theSrcList[ i ] );
968 //============================================================================
969 // function : RestoreSubShapes
970 // purpose : Private method. Works only if both theObject and theSObject
971 // are defined, and does not check, if they correspond to each other.
972 //============================================================================
973 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy,
974 GEOM::GEOM_Object_ptr theObject,
975 SALOMEDS::SObject_ptr theSObject,
976 const GEOM::ListOfGO& theArgs,
977 GEOM::find_shape_method theFindMethod,
978 CORBA::Boolean theInheritFirstArg,
979 CORBA::Boolean theAddPrefix)
981 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
982 //PTv, IMP 0020001, The salome object <theSObject>
983 // is not obligatory in case of invokation from script
984 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
985 return aParts._retn();
987 // For Dump Python (mantis issue 0020768)
988 GEOM::ListOfGO_var anOutArgs = new GEOM::ListOfGO;
990 // Arguments to be published
991 GEOM::ListOfGO_var aList;
993 // If theArgs list is empty, we try to publish all arguments,
994 // otherwise publish only passed args
995 Standard_Integer nbArgsActual = -1; // -1 means unknown
996 Standard_Integer aLength = theArgs.length();
998 aList = new GEOM::ListOfGO;
999 aList->length(aLength);
1000 for (int i = 0; i < aLength; i++) {
1001 aList[i] = GEOM::GEOM_Object::_duplicate( theArgs[i] );
1005 // Get all arguments
1006 GEOM::ListOfGBO_var boList = theObject->GetDependency();
1007 aLength = boList->length();
1008 aList = new GEOM::ListOfGO;
1009 aList->length(aLength);
1010 for (int i = 0; i < aLength; i++)
1011 aList[i] = GEOM::GEOM_Object::_narrow( boList[i] );
1012 nbArgsActual = aLength;
1016 return aParts._retn();
1018 if (theInheritFirstArg || (nbArgsActual == 1)) {
1019 // Do not publish argument's reflection,
1020 // but only reconstruct its published sub-shapes
1022 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1023 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1025 // remember restored objects for Python Dump
1026 addToListOfGO(aList[0], anOutArgs);
1028 aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
1029 anOutArgs, theFindMethod, theAddPrefix);
1031 // set the color of the transformed shape to the color of initial shape
1032 theObject->SetColor(aList[0]->GetColor());
1034 if (theObject->GetShapeType() == GEOM::VERTEX) {
1035 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1036 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1037 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1040 anArgSO->UnRegister();
1043 // Get interface, containing method, which we will use to reconstruct sub-shapes
1044 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1045 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1046 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1048 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1049 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1051 // Reconstruct arguments and tree of sub-shapes of the arguments
1052 CORBA::String_var anIOR;
1053 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1054 for (Standard_Integer i = 0; i < aLength; i++)
1056 GEOM::GEOM_Object_var anArgO = aList[i];
1057 if (!CORBA::is_nil(anArgO)) {
1058 anIOR = _orb->object_to_string(anArgO);
1059 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1060 TCollection_AsciiString anArgName;
1061 if (CORBA::is_nil(anArgSO)) {
1063 anArgName += TCollection_AsciiString(i);
1066 anArgName = anArgSO->GetName();
1069 // Find a sub-shape of theObject in place of the argument
1070 GEOM::GEOM_Object_var aSubO;
1071 switch (theFindMethod) {
1072 case GEOM::FSM_GetInPlace:
1075 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1078 case GEOM::FSM_MultiTransformed:
1080 // Only for Multi-transformations
1081 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1082 if (!CORBA::is_nil(anArgOTrsf)) {
1083 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1084 Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1085 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1086 anArgOTrsfFun->SetDescription("");
1087 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1090 Handle(GEOM_Function) anOFun = theObject->GetLastFunction();
1091 if (!anOFun.IsNull()) {
1092 CORBA::String_var entryArg = anArgO->GetEntry();
1093 Handle(GEOM_Object) anArgOImpl = _impl->GetObject(anArgO->GetStudyID(), entryArg);
1094 if (!anArgOImpl.IsNull()) {
1095 TopoDS_Shape anArgOShape = anArgOImpl->GetValue();
1096 TopoDS_Shape aMultiArgShape;
1097 //GEOM::GEOM_Object_var anArgOMulti; // ???
1098 switch (anOFun->GetType()) {
1101 GEOMImpl_ITranslate aTI (anOFun);
1102 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape1D(anArgOShape, &aTI);
1103 //anArgOMulti = aTrsfOpSv->Translate1D(anArgO, , , );
1108 GEOMImpl_ITranslate aTI (anOFun);
1109 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1114 GEOMImpl_IRotate aTI (anOFun);
1115 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1120 GEOMImpl_IRotate aTI (anOFun);
1121 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1127 GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO
1128 Handle(GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction();
1129 anArgOMultiFun->SetDescription("");
1130 aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti);
1136 case GEOM::FSM_Transformed:
1138 // transformation, cannot use GetInPlace, operate with indices
1139 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1140 if (anIDs->length() > 1) {
1142 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1143 if (!CORBA::is_nil(aSubO))
1144 aGroupOp->UnionIDs(aSubO, anIDs);
1146 else if (anIDs->length() > 0) {
1148 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1152 case GEOM::FSM_GetSame:
1155 aSubO = aShapesOp->GetSame(theObject, anArgO);
1158 case GEOM::FSM_GetShapesOnShape:
1160 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1161 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1162 (short)GEOM::SOLID, GEOM::ST_ONIN);
1165 case GEOM::FSM_GetInPlaceByHistory:
1167 // Use GetInPlaceByHistory
1168 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1175 if (!CORBA::is_nil(aSubO)) {
1176 // remember restored objects for Python Dump
1177 addToListOfGO(anArgO, anOutArgs);
1179 // add to parts list
1180 addToListOfGO( aSubO, aParts );
1182 // Publish the sub-shape
1183 SALOMEDS::SObject_var aSubSO;
1184 if (!CORBA::is_nil(theSObject)) {
1185 TCollection_AsciiString aSubName;
1189 aSubName += anArgName;
1190 aSubSO = aStudyBuilder->NewObject(theSObject);
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 if (!CORBA::is_nil(anArgSO)) {
1203 // Restore published sub-shapes of the argument
1204 GEOM::ListOfGO_var aSubParts;
1205 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1206 // pass theObject, because only it has the history
1207 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1208 theObject, anOutArgs, theFindMethod, theAddPrefix);
1210 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1211 aSubO, anOutArgs, theFindMethod, theAddPrefix);
1212 // add to parts list
1213 addToListOfGO( aSubParts, aParts );
1216 else { // GetInPlace failed, try to build from published parts
1217 if (!CORBA::is_nil(anArgSO)) {
1218 SALOMEDS::SObject_var aSubSO;
1219 if (!CORBA::is_nil(theSObject))
1220 aSubSO = aStudyBuilder->NewObject(theSObject);
1222 // Restore published sub-shapes of the argument
1223 GEOM::ListOfGO_var aSubParts =
1224 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1225 theObject, anOutArgs, theFindMethod, theAddPrefix);
1227 // add to parts list
1228 addToListOfGO( aSubParts, aParts );
1230 if (aSubParts->length() > 0) {
1231 // remember restored objects for Python Dump
1232 addToListOfGO(anArgO, anOutArgs);
1234 // try to build an argument from a set of its sub-shapes,
1235 // that published and will be reconstructed
1236 if (aSubParts->length() > 1) {
1237 aSubO = aShapesOp->MakeCompound(aSubParts);
1238 // add to parts list
1239 addToListOfGO( aSubO, aParts );
1242 aSubO = aSubParts[0];
1244 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1245 // Publish the sub-shape
1246 TCollection_AsciiString aSubName;
1248 aSubName = "from_parts_of_";
1250 aSubName += anArgName;
1251 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1253 aSubO->SetColor(anArgO->GetColor());
1255 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1256 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1257 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1258 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1262 else if (!CORBA::is_nil(aSubSO)) {
1263 // remove created aSubSO, because no parts have been found
1264 aStudyBuilder->RemoveObject(aSubSO);
1267 } // try to build from published parts
1268 anArgSO->UnRegister();
1270 } // process arguments
1272 std::set<std::string> anObjEntryMap;
1273 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1275 int nb = aParts->length();
1276 aResParts->length(nb);
1279 Handle(GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1280 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1281 GEOM::TPythonDump pd (aFunction, true);
1284 for ( ; i < nb; i++ )
1286 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1287 if (CORBA::is_nil(anObj))
1289 char* anEntry = anObj->GetEntry();
1290 if (anObjEntryMap.count(anEntry))
1291 continue; // already treated
1292 anObjEntryMap.insert(anEntry);
1293 aResParts[nbRes++] = anObj;
1294 // clear python dump of object
1295 Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1296 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1297 if ( !anObjFun.IsNull() )
1298 anObjFun->SetDescription( "" );
1304 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1305 //i = 0; nb = theArgs.length(); j = 0;
1306 i = 0; nb = anOutArgs->length(); j = 0;
1307 for ( ; i < nb; i++ )
1309 //GEOM::GEOM_Object_var anObj = theArgs[ i ];
1310 GEOM::GEOM_Object_var anObj = anOutArgs[ i ];
1311 if (CORBA::is_nil(anObj))
1313 Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1319 pd <<"]" << ", " <<"GEOM.";
1320 switch (theFindMethod) {
1321 case GEOM::FSM_GetInPlace:
1322 pd << "FSM_GetInPlace"; break;
1323 case GEOM::FSM_MultiTransformed:
1324 pd << "FSM_MultiTransformed"; break;
1325 case GEOM::FSM_Transformed:
1326 pd << "FSM_Transformed"; break;
1327 case GEOM::FSM_GetSame:
1328 pd << "FSM_GetSame"; break;
1329 case GEOM::FSM_GetShapesOnShape:
1330 pd << "FSM_GetShapesOnShape"; break;
1331 case GEOM::FSM_GetInPlaceByHistory:
1333 pd << "FSM_GetInPlaceByHistory"; break;
1335 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1337 aResParts->length(nbRes);
1338 return aResParts._retn();
1341 //============================================================================
1342 // function : RestoreSubShapesOneLevel
1343 // purpose : Private method
1344 //============================================================================
1345 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1346 SALOMEDS::SObject_ptr theOldSO,
1347 SALOMEDS::SObject_ptr theNewSO,
1348 GEOM::GEOM_Object_ptr theNewO,
1349 GEOM::ListOfGO& theOutArgs,
1350 GEOM::find_shape_method theFindMethod,
1351 CORBA::Boolean theAddPrefix)
1354 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1355 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1356 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1357 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1358 return aParts._retn();
1360 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1362 // Get interface, containing method, which we will use to reconstruct sub-shapes
1363 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1364 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1365 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1367 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1368 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1370 // Reconstruct published sub-shapes
1371 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1374 for (it->Init(); it->More(); it->Next()) {
1377 aParts->length(aLen);
1379 for (it->Init(); it->More(); it->Next()) {
1380 SALOMEDS::SObject_var anOldSubSO = it->Value();
1382 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1384 SALOMEDS::GenericAttribute_var anAttr;
1385 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1386 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1387 GEOM::GEOM_Object_var anOldSubO =
1388 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1389 if (!CORBA::is_nil(anOldSubO)) {
1390 // Find a sub-shape of theNewO in place of anOldSubO
1391 GEOM::GEOM_Object_var aNewSubO;
1392 switch (theFindMethod) {
1393 case GEOM::FSM_GetInPlace:
1396 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1399 case GEOM::FSM_MultiTransformed:
1401 // Only for Multi-transformations
1402 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
1403 if (!CORBA::is_nil(anArgOTrsf)) {
1404 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1405 Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1406 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1407 anArgOTrsfFun->SetDescription("");
1408 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1412 case GEOM::FSM_Transformed:
1414 // transformation, cannot use GetInPlace, operate with indices
1415 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1416 if (anIDs->length() > 1) {
1418 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1419 if (!CORBA::is_nil(aNewSubO))
1420 aGroupOp->UnionIDs(aNewSubO, anIDs);
1424 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1428 case GEOM::FSM_GetSame:
1431 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1434 case GEOM::FSM_GetShapesOnShape:
1436 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1437 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1438 (short)GEOM::SOLID, GEOM::ST_ONIN);
1441 case GEOM::FSM_GetInPlaceByHistory:
1443 // Use GetInPlaceByHistory
1444 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1451 if (!CORBA::is_nil(aNewSubO)) {
1452 // remember restored objects for Python Dump
1453 addToListOfGO(anOldSubO, theOutArgs);
1455 // add the part to the list
1456 aParts[i] = aNewSubO;
1458 // add to parts list
1459 addToListOfGO( aNewSubO, aNewParts );
1461 SALOMEDS::SObject_var aNewSubSO;
1462 if (!CORBA::is_nil(theNewSO)) {
1463 // Publish the sub-shape
1464 TCollection_AsciiString aSubName;
1468 aSubName += anArgName;
1469 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1470 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1472 aNewSubO->SetColor(anOldSubO->GetColor());
1474 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1475 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1476 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1477 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1480 // Restore published sub-shapes of the argument
1481 GEOM::ListOfGO_var aSubParts;
1482 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1483 // pass the main shape as Object, because only it has the history
1484 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1485 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1487 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1488 aNewSubO, theOutArgs, theFindMethod, theAddPrefix);
1489 // add to parts list
1490 addToListOfGO( aSubParts, aNewParts );
1492 else { // GetInPlace failed, try to build from published parts
1493 SALOMEDS::SObject_var aNewSubSO;
1494 if (!CORBA::is_nil(theNewSO))
1495 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1497 // Restore published sub-shapes of the argument
1498 GEOM::ListOfGO_var aSubParts =
1499 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1500 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1501 // add to parts list
1502 addToListOfGO( aSubParts, aNewParts );
1504 if (aSubParts->length() > 0) {
1505 // remember restored objects for Python Dump
1506 addToListOfGO(anOldSubO, theOutArgs);
1508 // try to build an object from a set of its sub-shapes,
1509 // that published and will be reconstructed
1510 if (aSubParts->length() > 1) {
1511 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1512 // add to parts list
1513 addToListOfGO( aNewSubO, aNewParts );
1516 aNewSubO = aSubParts[0];
1519 if (!CORBA::is_nil(aNewSubO)) {
1520 // add the part to the list
1521 aSubParts[i] = aNewSubO;
1524 // Publish the sub-shape
1525 if (!CORBA::is_nil(aNewSubSO)) {
1526 TCollection_AsciiString aSubName;
1528 aSubName = "from_parts_of_";
1530 aSubName += anArgName;
1531 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1533 aNewSubO->SetColor(anOldSubO->GetColor());
1535 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1536 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1537 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1538 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1543 else if (!CORBA::is_nil(aNewSubSO)) {
1544 // remove created aSubSO, because no parts have been found
1545 aStudyBuilder->RemoveObject(aNewSubSO);
1547 } // try to build from published parts
1550 } // iterate on published sub-shapes
1553 // add to parts list
1554 addToListOfGO( aNewParts, aParts );
1555 return aParts._retn();
1558 //============================================================================
1559 // function : RestoreGivenSubShapes
1560 // purpose : Private method. Works only if both theObject and theSObject
1561 // are defined, and does not check, if they correspond to each other.
1562 // List theArgs in this case contains not only operation arguments,
1563 // but also all subshapes, which must be published.
1564 //============================================================================
1565 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStudy,
1566 GEOM::GEOM_Object_ptr theObject,
1567 SALOMEDS::SObject_ptr theSObject,
1568 const GEOM::ListOfGO& theArgs,
1569 GEOM::find_shape_method theFindMethod,
1570 CORBA::Boolean theInheritFirstArg,
1571 CORBA::Boolean theAddPrefix)
1573 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1574 //PTv, IMP 0020001, The salome object <theSObject>
1575 // is not obligatory in case of invokation from script
1576 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
1577 return aParts._retn();
1579 // If theArgs list is empty, nothing to do
1580 Standard_Integer aLength = theArgs.length();
1582 return aParts._retn();
1584 // Get all arguments
1585 GEOM::ListOfGBO_var anOpArgsList = theObject->GetDependency();
1586 Standard_Integer nbArgsActual = anOpArgsList->length();
1588 // If anOpArgsList list is empty, nothing to do
1589 if (nbArgsActual == 0)
1590 return aParts._retn();
1592 // Entries of arguments and subshapes
1593 std::set<std::string> anArgs;
1594 for (int i = 0; i < aLength; i++) {
1595 CORBA::String_var anEntry = theArgs[i]->GetEntry();
1596 anArgs.insert(anEntry.in());
1599 // Arguments to be published
1600 // We try to publish all arguments, that are in theArgs list
1601 GEOM::ListOfGO_var aList = new GEOM::ListOfGO;
1602 aList->length(nbArgsActual);
1605 for (int j = 0; j < nbArgsActual; j++) {
1606 CORBA::String_var anEntry = anOpArgsList[j]->GetEntry();
1607 if (anArgs.count(anEntry.in())) {
1608 aList[k] = GEOM::GEOM_Object::_narrow(anOpArgsList[j]);
1613 //aList->length(nbArgsActual);
1615 if (nbArgsActual < 1)
1616 return aParts._retn();
1618 if (theInheritFirstArg || (nbArgsActual == 1)) {
1619 // Do not publish argument's reflection,
1620 // but only reconstruct its published sub-shapes
1622 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1623 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1625 aParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
1626 anArgs, theFindMethod, theAddPrefix);
1628 // set the color of the transformed shape to the color of initial shape
1629 theObject->SetColor(aList[0]->GetColor());
1631 if (theObject->GetShapeType() == GEOM::VERTEX) {
1632 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1633 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1634 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1637 anArgSO->UnRegister();
1640 // Get interface, containing method, which we will use to reconstruct sub-shapes
1641 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1642 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1643 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1645 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1646 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1648 // Reconstruct arguments and tree of sub-shapes of the arguments
1649 CORBA::String_var anIOR;
1650 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1651 for (Standard_Integer i = 0; i < nbArgsActual; i++)
1653 GEOM::GEOM_Object_var anArgO = aList[i];
1654 if (!CORBA::is_nil(anArgO)) {
1655 anIOR = _orb->object_to_string(anArgO);
1656 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1657 TCollection_AsciiString anArgName;
1658 if (CORBA::is_nil(anArgSO)) {
1660 anArgName += TCollection_AsciiString(i);
1663 anArgName = anArgSO->GetName();
1666 // Find a sub-shape of theObject in place of the argument
1667 GEOM::GEOM_Object_var aSubO;
1668 switch (theFindMethod) {
1669 case GEOM::FSM_GetInPlace:
1672 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1675 case GEOM::FSM_MultiTransformed:
1677 // Only for Multi-transformations
1678 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1679 if (!CORBA::is_nil(anArgOTrsf)) {
1680 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1681 Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1682 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1683 anArgOTrsfFun->SetDescription("");
1684 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1688 case GEOM::FSM_Transformed:
1690 // transformation, cannot use GetInPlace, operate with indices
1691 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1692 if (anIDs->length() > 1) {
1694 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1695 if (!CORBA::is_nil(aSubO))
1696 aGroupOp->UnionIDs(aSubO, anIDs);
1698 else if (anIDs->length() > 0) {
1700 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1704 case GEOM::FSM_GetSame:
1707 aSubO = aShapesOp->GetSame(theObject, anArgO);
1710 case GEOM::FSM_GetShapesOnShape:
1712 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1713 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1714 (short)GEOM::SOLID, GEOM::ST_ONIN);
1717 case GEOM::FSM_GetInPlaceByHistory:
1719 // Use GetInPlaceByHistory
1720 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1727 if (!CORBA::is_nil(aSubO)) {
1728 // add to parts list
1729 addToListOfGO( aSubO, aParts );
1731 // Publish the sub-shape
1732 SALOMEDS::SObject_var aSubSO;
1733 if (!CORBA::is_nil(theSObject)) {
1734 TCollection_AsciiString aSubName;
1738 aSubName += anArgName;
1739 aSubSO = aStudyBuilder->NewObject(theSObject);
1740 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1742 aSubO->SetColor(anArgO->GetColor());
1744 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1745 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1746 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1747 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1751 if (!CORBA::is_nil(anArgSO)) {
1752 // Restore published sub-shapes of the argument
1753 GEOM::ListOfGO_var aSubParts;
1754 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1755 // pass theObject, because only it has the history
1756 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1757 theObject, anArgs, theFindMethod, theAddPrefix);
1759 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1760 aSubO, anArgs, theFindMethod, theAddPrefix);
1761 // add to parts list
1762 addToListOfGO( aSubParts, aParts );
1765 else { // GetInPlace failed, try to build from published parts
1766 if (!CORBA::is_nil(anArgSO)) {
1767 SALOMEDS::SObject_var aSubSO;
1768 if (!CORBA::is_nil(theSObject))
1769 aSubSO = aStudyBuilder->NewObject(theSObject);
1771 // Restore published sub-shapes of the argument
1772 GEOM::ListOfGO_var aSubParts =
1773 RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1774 theObject, anArgs, theFindMethod, theAddPrefix);
1776 // add to parts list
1777 addToListOfGO( aSubParts, aParts );
1779 if (aSubParts->length() > 0) {
1780 // try to build an argument from a set of its sub-shapes,
1781 // that published and will be reconstructed
1782 if (aSubParts->length() > 1) {
1783 aSubO = aShapesOp->MakeCompound(aSubParts);
1784 // add to parts list
1785 addToListOfGO( aSubO, aParts );
1788 aSubO = aSubParts[0];
1790 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1791 // Publish the sub-shape
1792 TCollection_AsciiString aSubName;
1794 aSubName = "from_parts_of_";
1796 aSubName += anArgName;
1797 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1799 aSubO->SetColor(anArgO->GetColor());
1801 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1802 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1803 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1804 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1808 else if (!CORBA::is_nil(aSubSO)) {
1809 // remove created aSubSO, because no parts have been found
1810 aStudyBuilder->RemoveObject(aSubSO);
1813 } // try to build from published parts
1814 anArgSO->UnRegister();
1816 } // process arguments
1818 std::set<std::string> anObjEntryMap;
1819 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1821 int nb = aParts->length();
1822 aResParts->length(nb);
1825 Handle(GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1826 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1827 GEOM::TPythonDump pd (aFunction, true);
1830 for ( ; i < nb; i++ )
1832 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1833 if (CORBA::is_nil(anObj))
1835 char* anEntry = anObj->GetEntry();
1836 if (anObjEntryMap.count(anEntry))
1837 continue; // already treated
1838 anObjEntryMap.insert(anEntry);
1839 aResParts[nbRes++] = anObj;
1840 // clear python dump of object
1841 Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1842 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1843 if ( !anObjFun.IsNull() )
1844 anObjFun->SetDescription( "" );
1850 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1851 i = 0; nb = theArgs.length(); j = 0;
1852 for ( ; i < nb; i++ )
1854 GEOM::GEOM_Object_var anObj = theArgs[ i ];
1855 if (CORBA::is_nil(anObj))
1857 Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1863 pd <<"]" << ", " <<"GEOM.";
1864 switch (theFindMethod) {
1865 case GEOM::FSM_GetInPlace:
1866 pd << "FSM_GetInPlace"; break;
1867 case GEOM::FSM_MultiTransformed:
1868 pd << "FSM_MultiTransformed"; break;
1869 case GEOM::FSM_Transformed:
1870 pd << "FSM_Transformed"; break;
1871 case GEOM::FSM_GetSame:
1872 pd << "FSM_GetSame"; break;
1873 case GEOM::FSM_GetShapesOnShape:
1874 pd << "FSM_GetShapesOnShape"; break;
1875 case GEOM::FSM_GetInPlaceByHistory:
1877 pd << "FSM_GetInPlaceByHistory"; break;
1879 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1881 aResParts->length(nbRes);
1882 return aResParts._retn();
1885 //============================================================================
1886 // function : RestoreGivenSubShapesOneLevel
1887 // purpose : Private method
1888 //============================================================================
1889 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1890 SALOMEDS::SObject_ptr theOldSO,
1891 SALOMEDS::SObject_ptr theNewSO,
1892 GEOM::GEOM_Object_ptr theNewO,
1893 std::set<std::string> theArgs,
1894 GEOM::find_shape_method theFindMethod,
1895 CORBA::Boolean theAddPrefix)
1898 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1899 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1900 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1901 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1902 return aParts._retn();
1904 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1906 // Get interface, containing method, which we will use to reconstruct sub-shapes
1907 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1908 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1909 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1911 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1912 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1914 // Reconstruct published sub-shapes
1915 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1918 for (it->Init(); it->More(); it->Next()) {
1921 aParts->length(aLen);
1923 for (it->Init(); it->More(); it->Next()) {
1924 SALOMEDS::SObject_var anOldSubSO = it->Value();
1926 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1928 SALOMEDS::GenericAttribute_var anAttr;
1929 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1930 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1931 GEOM::GEOM_Object_var anOldSubO =
1932 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1934 bool okToContinue = false;
1936 if (!CORBA::is_nil(anOldSubO)) {
1937 CORBA::String_var anEntry = anOldSubO->GetEntry();
1938 okToContinue = theArgs.count(anEntry.in());
1942 // Find a sub-shape of theNewO in place of anOldSubO
1943 GEOM::GEOM_Object_var aNewSubO;
1944 switch (theFindMethod) {
1945 case GEOM::FSM_GetInPlace:
1948 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1951 case GEOM::FSM_MultiTransformed:
1953 // Only for Multi-transformations
1954 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
1955 if (!CORBA::is_nil(anArgOTrsf)) {
1956 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1957 Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1958 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1959 anArgOTrsfFun->SetDescription("");
1960 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1964 case GEOM::FSM_Transformed:
1966 // transformation, cannot use GetInPlace, operate with indices
1967 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1968 if (anIDs->length() > 1) {
1970 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1971 if (!CORBA::is_nil(aNewSubO))
1972 aGroupOp->UnionIDs(aNewSubO, anIDs);
1976 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1980 case GEOM::FSM_GetSame:
1983 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1986 case GEOM::FSM_GetShapesOnShape:
1988 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1989 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1990 (short)GEOM::SOLID, GEOM::ST_ONIN);
1993 case GEOM::FSM_GetInPlaceByHistory:
1995 // Use GetInPlaceByHistory
1996 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
2003 if (!CORBA::is_nil(aNewSubO)) {
2004 // add the part to the list
2005 aParts[i] = aNewSubO;
2007 // add to parts list
2008 addToListOfGO( aNewSubO, aNewParts );
2010 SALOMEDS::SObject_var aNewSubSO;
2011 if (!CORBA::is_nil(theNewSO)) {
2012 // Publish the sub-shape
2013 TCollection_AsciiString aSubName;
2017 aSubName += anArgName;
2018 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
2019 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
2021 aNewSubO->SetColor(anOldSubO->GetColor());
2023 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2024 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2025 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2026 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2029 // Restore published sub-shapes of the argument
2030 GEOM::ListOfGO_var aSubParts;
2031 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
2032 // pass the main shape as Object, because only it has the history
2033 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
2034 theNewO, theArgs, theFindMethod, theAddPrefix);
2036 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
2037 aNewSubO, theArgs, theFindMethod, theAddPrefix);
2038 // add to parts list
2039 addToListOfGO( aSubParts, aNewParts );
2041 else { // GetInPlace failed, try to build from published parts
2042 SALOMEDS::SObject_var aNewSubSO;
2043 if (!CORBA::is_nil(theNewSO))
2044 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
2046 // Restore published sub-shapes of the argument
2047 GEOM::ListOfGO_var aSubParts =
2048 RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
2049 theNewO, theArgs, theFindMethod, theAddPrefix);
2050 // add to parts list
2051 addToListOfGO( aSubParts, aNewParts );
2053 if (aSubParts->length() > 0) {
2054 // try to build an object from a set of its sub-shapes,
2055 // that published and will be reconstructed
2056 if (aSubParts->length() > 1) {
2057 aNewSubO = aShapesOp->MakeCompound(aSubParts);
2058 // add to parts list
2059 addToListOfGO( aNewSubO, aNewParts );
2062 aNewSubO = aSubParts[0];
2065 if (!CORBA::is_nil(aNewSubO)) {
2066 // add the part to the list
2067 aSubParts[i] = aNewSubO;
2070 // Publish the sub-shape
2071 if (!CORBA::is_nil(aNewSubSO)) {
2072 TCollection_AsciiString aSubName;
2074 aSubName = "from_parts_of_";
2076 aSubName += anArgName;
2077 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
2079 aNewSubO->SetColor(anOldSubO->GetColor());
2081 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2082 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2083 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2084 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2089 else if (!CORBA::is_nil(aNewSubSO)) {
2090 // remove created aSubSO, because no parts have been found
2091 aStudyBuilder->RemoveObject(aNewSubSO);
2093 } // try to build from published parts
2096 } // iterate on published sub-shapes
2099 // add to parts list
2100 addToListOfGO( aNewParts, aParts );
2101 return aParts._retn();
2104 //============================================================================
2105 // function : register()
2106 // purpose : register 'name' in 'name_service'
2107 //============================================================================
2108 void GEOM_Gen_i::register_name(char * name)
2110 GEOM::GEOM_Gen_var g = _this();
2111 name_service->Register(g, name);
2114 //============================================================================
2117 //============================================================================
2118 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
2120 _impl->Undo(theStudyID);
2123 //============================================================================
2126 //============================================================================
2127 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
2129 _impl->Redo(theStudyID);
2132 //============================================================================
2133 // function : GetIBasicOperations
2135 //============================================================================
2136 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
2137 throw ( SALOME::SALOME_Exception )
2139 Unexpect aCatch(SALOME_SalomeException);
2140 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
2142 GEOM::GEOM_Gen_ptr engine = _this();
2144 //transfer reference on engine
2145 GEOM_IBasicOperations_i* aServant =
2146 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
2148 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2149 // activate the CORBA servant
2150 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
2151 return operations._retn();
2154 //============================================================================
2155 // function : GetITransformOperations
2157 //============================================================================
2158 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
2159 throw ( SALOME::SALOME_Exception )
2161 Unexpect aCatch(SALOME_SalomeException);
2162 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
2164 GEOM::GEOM_Gen_ptr engine = _this();
2166 GEOM_ITransformOperations_i* aServant =
2167 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
2169 // activate the CORBA servant
2170 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
2171 return operations._retn();
2174 //============================================================================
2175 // function : GetI3DPrimOperations
2177 //============================================================================
2178 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
2179 throw ( SALOME::SALOME_Exception )
2181 Unexpect aCatch(SALOME_SalomeException);
2182 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
2184 GEOM::GEOM_Gen_ptr engine = _this();
2186 GEOM_I3DPrimOperations_i* aServant =
2187 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
2188 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2190 // activate the CORBA servant
2191 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
2192 return operations._retn();
2195 //============================================================================
2196 // function : GetIShapesOperations
2198 //============================================================================
2199 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
2200 throw ( SALOME::SALOME_Exception )
2202 Unexpect aCatch(SALOME_SalomeException);
2203 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
2205 GEOM::GEOM_Gen_ptr engine = _this();
2207 GEOM_IShapesOperations_i* aServant =
2208 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
2210 // activate the CORBA servant
2211 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
2212 return operations._retn();
2215 //============================================================================
2216 // function : GetIBlocksOperations
2218 //============================================================================
2219 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
2220 throw ( SALOME::SALOME_Exception )
2222 Unexpect aCatch(SALOME_SalomeException);
2223 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
2225 GEOM::GEOM_Gen_ptr engine = _this();
2227 GEOM_IBlocksOperations_i* aServant =
2228 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
2230 // activate the CORBA servant
2231 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
2232 return operations._retn();
2235 //============================================================================
2236 // function : GetIBooleanOperations
2238 //============================================================================
2239 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
2240 throw ( SALOME::SALOME_Exception )
2242 Unexpect aCatch(SALOME_SalomeException);
2243 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
2245 GEOM::GEOM_Gen_ptr engine = _this();
2247 GEOM_IBooleanOperations_i* aServant =
2248 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
2250 // activate the CORBA servant
2251 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
2252 return operations._retn();
2255 //============================================================================
2256 // function : GetICurvesOperations
2258 //============================================================================
2259 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
2260 throw ( SALOME::SALOME_Exception )
2262 Unexpect aCatch(SALOME_SalomeException);
2263 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
2265 GEOM::GEOM_Gen_ptr engine = _this();
2267 GEOM_ICurvesOperations_i* aServant =
2268 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
2270 // activate the CORBA servant
2271 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
2272 return operations._retn();
2275 //============================================================================
2276 // function : GetILocalOperations
2278 //============================================================================
2279 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
2280 throw ( SALOME::SALOME_Exception )
2282 Unexpect aCatch(SALOME_SalomeException);
2283 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
2285 GEOM::GEOM_Gen_ptr engine = _this();
2287 GEOM_ILocalOperations_i* aServant =
2288 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
2290 // activate the CORBA servant
2291 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
2292 return operations._retn();
2295 //============================================================================
2296 // function : GetIHealingOperations
2298 //============================================================================
2299 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
2300 throw ( SALOME::SALOME_Exception )
2302 Unexpect aCatch(SALOME_SalomeException);
2303 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
2305 GEOM::GEOM_Gen_ptr engine = _this();
2307 GEOM_IHealingOperations_i* aServant =
2308 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
2310 // activate the CORBA servant
2311 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
2312 return operations._retn();
2315 //============================================================================
2316 // function : GetIInsertOperations
2318 //============================================================================
2319 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
2320 throw ( SALOME::SALOME_Exception )
2322 Unexpect aCatch(SALOME_SalomeException);
2323 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
2325 GEOM::GEOM_Gen_ptr engine = _this();
2327 GEOM_IInsertOperations_i* aServant =
2328 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
2330 // activate the CORBA servant
2331 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
2332 return operations._retn();
2335 //============================================================================
2336 // function : GetIMeasureOperations
2338 //============================================================================
2339 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
2340 throw ( SALOME::SALOME_Exception )
2342 Unexpect aCatch(SALOME_SalomeException);
2343 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
2345 GEOM::GEOM_Gen_ptr engine = _this();
2347 GEOM_IMeasureOperations_i* aServant =
2348 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
2350 // activate the CORBA servant
2351 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
2352 return operations._retn();
2355 //============================================================================
2356 // function : GetIGroupOperations
2358 //============================================================================
2359 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
2360 throw ( SALOME::SALOME_Exception )
2362 Unexpect aCatch(SALOME_SalomeException);
2363 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
2365 GEOM::GEOM_Gen_ptr engine = _this();
2367 GEOM_IGroupOperations_i* aServant =
2368 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
2370 // activate the CORBA servant
2371 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
2372 return operations._retn();
2375 //============================================================================
2376 // function : GetIFieldOperations
2378 //============================================================================
2379 GEOM::GEOM_IFieldOperations_ptr GEOM_Gen_i::GetIFieldOperations(CORBA::Long theStudyID)
2380 throw ( SALOME::SALOME_Exception )
2382 Unexpect aCatch(SALOME_SalomeException);
2383 MESSAGE( "GEOM_Gen_i::GetIFieldOperations" );
2385 GEOM::GEOM_Gen_ptr engine = _this();
2387 GEOM_IFieldOperations_i* aServant =
2388 new GEOM_IFieldOperations_i(_poa, engine, _impl->GetIFieldOperations(theStudyID));
2390 // activate the CORBA servant
2391 GEOM::GEOM_IFieldOperations_var operations = aServant->_this();
2392 return operations._retn();
2395 //============================================================================
2396 // function : GetPluginOperations
2398 //============================================================================
2399 GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(CORBA::Long theStudyID,
2400 const char* theLibName)
2401 throw ( SALOME::SALOME_Exception )
2403 std::string aPlatformLibName;
2405 aPlatformLibName = theLibName;
2406 aPlatformLibName += ".dll" ;
2408 aPlatformLibName = "lib";
2409 aPlatformLibName += theLibName;
2410 aPlatformLibName += ".so";
2413 Unexpect aCatch(SALOME_SalomeException);
2414 MESSAGE( "GEOM_Gen_i::GetPluginOperations" );
2416 GEOM::GEOM_Gen_ptr engine = _this();
2418 GEOM_IOperations_i* aServant = 0;
2419 GEOM::GEOM_IOperations_var operations;
2422 // check, if corresponding operations are already created
2423 if (myOpCreatorMap.find(std::string(theLibName)) == myOpCreatorMap.end()) {
2424 // load plugin library
2425 LibHandle libHandle = LoadLib( aPlatformLibName.c_str()/*theLibName*/ );
2427 // report any error, if occured
2429 const char* anError = dlerror();
2430 throw(SALOME_Exception(anError));
2432 throw(SALOME_Exception(LOCALIZED( "Can't load server geometry plugin library" )));
2436 // get method, returning operations creator
2437 typedef GEOM_GenericOperationsCreator* (*GetOperationsCreator)();
2438 GetOperationsCreator procHandle =
2439 (GetOperationsCreator)GetProc( libHandle, "GetOperationsCreator" );
2441 throw(SALOME_Exception(LOCALIZED("bad geometry plugin library")));
2442 UnLoadLib(libHandle);
2445 // get operations creator
2446 GEOM_GenericOperationsCreator* aCreator = procHandle();
2448 throw(SALOME_Exception(LOCALIZED("bad geometry plugin library implementation")));
2451 // map operations creator to a plugin name
2452 myOpCreatorMap[std::string(theLibName)] = aCreator;
2455 // create a new operations object, store its ref. in engine
2456 aServant = myOpCreatorMap[std::string(theLibName)]->Create(_poa, theStudyID, engine, _impl);
2457 //??? aServant->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance
2459 catch (SALOME_Exception& S_ex) {
2460 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
2464 return operations._retn();
2466 // activate the CORBA servant
2467 operations = GEOM::GEOM_IOperations::_narrow( aServant->_this() );
2468 return operations._retn();
2471 //=============================================================================
2475 //=============================================================================
2476 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
2477 const GEOM::ListOfLong& theIndices)
2479 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
2480 return GEOM::GEOM_Object::_nil();
2481 CORBA::String_var entry = theMainShape->GetEntry();
2482 Handle(GEOM_Object) aMainShape = Handle(GEOM_Object)::DownCast
2483 ( _impl->GetObject( theMainShape->GetStudyID(), entry ));
2484 if (aMainShape.IsNull()) return GEOM::GEOM_Object::_nil();
2486 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
2487 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
2489 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true);
2490 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
2492 TCollection_AsciiString anEntry;
2493 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
2494 return GEOM::GEOM_Object::_narrow( GetObject(anObject->GetDocID(), anEntry.ToCString()));
2497 //=============================================================================
2501 //=============================================================================
2502 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_BaseObject_ptr theObject)
2504 CORBA::String_var anEntry = theObject->GetEntry();
2505 Handle(GEOM_BaseObject) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false);
2506 if (!anObject.IsNull())
2507 _impl->RemoveObject(anObject);
2510 //=================================================================================
2511 // function : GetStringFromIOR()
2512 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
2513 //=================================================================================
2514 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject)
2516 return _orb->object_to_string(theObject);
2519 //=================================================================================
2520 // function : GetIORFromString()
2521 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
2522 //=================================================================================
2523 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
2524 GEOM::GEOM_Object_var aGeomObject;
2525 if(strcmp(stringIOR,"") != 0){
2526 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
2527 if(!CORBA::is_nil(anObject))
2528 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
2530 return aGeomObject._retn();
2533 //=================================================================================
2534 // function : GetObject()
2536 //=================================================================================
2537 GEOM::GEOM_BaseObject_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
2539 GEOM::GEOM_BaseObject_var obj;
2540 Handle(GEOM_BaseObject) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
2541 if (handle_object.IsNull()) return obj._retn();
2543 TCollection_AsciiString stringIOR = handle_object->GetIOR();
2544 if (stringIOR.Length() > 1) {
2545 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
2546 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_BaseObject::_narrow(corba_object);
2550 GEOM::GEOM_Gen_ptr engine = _this();
2551 //transfer the reference to GEOM_Object_i
2552 GEOM_BaseObject_i* servant = 0;
2553 switch( handle_object->GetType() ) {
2555 servant = new GEOM_Field_i (_poa, engine, Handle(GEOM_Field)::DownCast( handle_object ));
2558 case GEOM_FIELD_STEP: {
2559 Handle(GEOM_FieldStep) step = Handle(GEOM_FieldStep)::DownCast( handle_object );
2560 Handle(GEOM_Field) field = step->GetField();
2561 int type = ( !field.IsNull() ? field->GetDataType() : 0 );
2563 case GEOM::FDT_Bool:
2564 servant = new GEOM_BoolFieldStep_i (_poa, engine, step );
2567 servant = new GEOM_IntFieldStep_i (_poa, engine, step );
2569 case GEOM::FDT_Double:
2570 servant = new GEOM_DoubleFieldStep_i (_poa, engine, step );
2573 servant = new GEOM_StringFieldStep_i (_poa, engine, step );
2578 servant = new GEOM_Object_i (_poa, engine, Handle(GEOM_Object)::DownCast( handle_object ));
2580 PortableServer::ObjectId_var id = _poa->activate_object(servant);
2582 obj = servant->_this();
2583 CORBA::String_var objStr = _orb->object_to_string(obj);
2584 TCollection_AsciiString anAscii( (char *)objStr.in() );
2585 handle_object->SetIOR( anAscii );
2589 //=================================================================================
2590 // function : hasObjectInfo()
2591 // purpose : shows if module provides information for its objects
2592 //=================================================================================
2593 bool GEOM_Gen_i::hasObjectInfo()
2598 //=================================================================================
2599 // function : getObjectInfo()
2600 // purpose : returns an information for a given object by its entry
2601 //=================================================================================
2602 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
2604 GEOM::GEOM_Object_var aGeomObject;
2606 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
2607 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
2608 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
2609 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
2610 SALOMEDS::SObject_var aResultSObj;
2611 if (aSObj->ReferencedObject(aResultSObj))
2612 aSObj = aResultSObj;
2614 SALOMEDS::GenericAttribute_var anAttr;
2615 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
2616 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2617 CORBA::String_var aVal = anIOR->Value();
2618 anIOR->UnRegister();
2619 CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
2620 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
2622 if (!aSObj->_is_nil() )
2623 aSObj->UnRegister();
2625 const char* aTypeInfo = "Object";
2626 if ( !aGeomObject->_is_nil() ) {
2627 GEOM::GEOM_IKindOfShape::shape_kind aKind;
2628 GEOM::ListOfLong_var anInts;
2629 GEOM::ListOfDouble_var aDbls;
2631 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
2632 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
2634 if ( anOp->IsDone() ) {
2636 case GEOM::GEOM_IKindOfShape::COMPOUND:
2637 aTypeInfo = "Compound";
2639 case GEOM::GEOM_IKindOfShape::COMPSOLID:
2640 aTypeInfo = "CompSolid";
2642 case GEOM::GEOM_IKindOfShape::SHELL:
2643 aTypeInfo = "Shell";
2645 case GEOM::GEOM_IKindOfShape::WIRE:
2646 if ( anInts[0] == 1 )
2647 aTypeInfo = "Closed Wire";
2648 else if ( anInts[0] == 2 )
2649 aTypeInfo = "Opened Wire";
2654 case GEOM::GEOM_IKindOfShape::SPHERE:
2655 aTypeInfo = "Sphere";
2657 case GEOM::GEOM_IKindOfShape::CYLINDER:
2658 aTypeInfo = "Cylinder";
2660 case GEOM::GEOM_IKindOfShape::BOX:
2661 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
2664 case GEOM::GEOM_IKindOfShape::TORUS:
2665 aTypeInfo = "Torus";
2667 case GEOM::GEOM_IKindOfShape::CONE:
2670 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
2671 aTypeInfo = "Polyhedron";
2673 case GEOM::GEOM_IKindOfShape::SOLID:
2674 aTypeInfo = "Solid";
2677 case GEOM::GEOM_IKindOfShape::SPHERE2D:
2678 aTypeInfo = "Spherical Face";
2680 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
2681 aTypeInfo = "Cylindrical Face";
2683 case GEOM::GEOM_IKindOfShape::TORUS2D:
2684 aTypeInfo = "Toroidal Face";
2686 case GEOM::GEOM_IKindOfShape::CONE2D:
2687 aTypeInfo = "Conical Face";
2689 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
2692 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
2693 aTypeInfo = "Elliptical Face";
2695 case GEOM::GEOM_IKindOfShape::POLYGON:
2696 aTypeInfo = "Polygon";
2698 case GEOM::GEOM_IKindOfShape::PLANE:
2699 aTypeInfo = "Plane";
2701 case GEOM::GEOM_IKindOfShape::PLANAR:
2702 aTypeInfo = "Planar Face";
2704 case GEOM::GEOM_IKindOfShape::FACE:
2708 case GEOM::GEOM_IKindOfShape::CIRCLE:
2709 aTypeInfo = "Circle";
2711 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
2712 aTypeInfo = "Arc Circle";
2714 case GEOM::GEOM_IKindOfShape::ELLIPSE:
2715 aTypeInfo = "Ellipse";
2717 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
2718 aTypeInfo = "Arc Ellipse";
2720 case GEOM::GEOM_IKindOfShape::LINE:
2723 case GEOM::GEOM_IKindOfShape::SEGMENT:
2724 aTypeInfo = "Segment";
2726 case GEOM::GEOM_IKindOfShape::EDGE:
2729 case GEOM::GEOM_IKindOfShape::VERTEX:
2730 aTypeInfo = "Vertex";
2738 char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
2739 sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
2741 char* ret = CORBA::string_dup(anInfo);
2746 // Version information
2747 char* GEOM_Gen_i::getVersion()
2749 #if GEOM_DEVELOPMENT
2750 return CORBA::string_dup(GEOM_VERSION_STR"dev");
2752 return CORBA::string_dup(GEOM_VERSION_STR);
2756 //=================================================================================
2757 // function : CreateFolder()
2758 // purpose : Creates and returns a new folder object
2759 //=================================================================================
2760 SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName,
2761 SALOMEDS::SObject_ptr theFather)
2763 SALOMEDS::SObject_var aFolderSO;
2765 if ( CORBA::is_nil(theFather) ) return aFolderSO._retn();
2767 SALOMEDS::GenericAttribute_var anAttr;
2768 if ( strcmp(theFather->GetFatherComponent()->GetID(), theFather->GetID()) != 0 ) {
2769 // not a GEOM component object was selected
2770 if ( !theFather->FindAttribute(anAttr, "AttributeLocalID") ) return aFolderSO._retn();
2771 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2772 if( aLocalID->Value() != 999 ) {
2773 // not a Folder object was selected
2774 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow(theFather);
2775 if ( CORBA::is_nil(aGeomObject) ) return aFolderSO._retn();
2776 // another GEOM object was selected, so get GEOM component as father object
2777 theFather = theFather->GetFatherComponent();
2779 aLocalID->UnRegister();
2782 SALOMEDS::Study_var aStudy = theFather->GetStudy();
2783 SALOMEDS::StudyBuilder_var aStudyBuilder( aStudy->NewBuilder() );
2784 aFolderSO = aStudyBuilder->NewObject( theFather );
2786 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeLocalID");
2787 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2788 aLocalID->SetValue( 999 ); // mark of the "Folder" object
2789 aLocalID->UnRegister();
2791 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeName");
2792 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
2793 aName->SetValue( theName );
2794 aName->UnRegister();
2796 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributePixMap");
2797 SALOMEDS::AttributePixMap_var aPixMap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2798 aPixMap->SetPixMap("ICON_FOLDER");
2799 aPixMap->UnRegister();
2801 // add object to the use case tree
2802 // (to support tree representation customization and drag-n-drop)
2803 SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder();
2804 useCaseBuilder->AppendTo( theFather, aFolderSO );
2806 return aFolderSO._retn();
2809 //=================================================================================
2810 // function : MoveToFolder()
2811 // purpose : Moves GEOM object to the specified folder
2812 //=================================================================================
2813 void GEOM_Gen_i::MoveToFolder(GEOM::GEOM_Object_ptr theObject,
2814 SALOMEDS::SObject_ptr theFolder) {
2815 GEOM::object_list_var objects = new GEOM::object_list();
2816 objects->length( 1 );
2817 SALOMEDS::SObject_var aSO = theFolder->GetStudy()->FindObjectID( theObject->GetStudyEntry() );
2819 Move( objects, theFolder, -1 );
2822 //=================================================================================
2823 // function : MoveListToFolder()
2824 // purpose : Moves list of GEOM objects to the specified folder
2825 //=================================================================================
2826 void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO,
2827 SALOMEDS::SObject_ptr theFolder) {
2828 int aLen = theListOfGO.length();
2829 GEOM::object_list_var objects = new GEOM::object_list();
2830 objects->length( aLen );
2831 GEOM::GEOM_Object_var aGO;
2832 SALOMEDS::SObject_var aSO;
2833 for (int i = 0; i < aLen; i++) {
2834 aGO = GEOM::GEOM_Object::_duplicate( theListOfGO[i] );
2835 aSO = theFolder->GetStudy()->FindObjectID( aGO->GetStudyEntry() );
2838 if ( objects->length() > 0 )
2839 Move( objects, theFolder, -1 );
2842 //=================================================================================
2843 // function : Move()
2844 // purpose : Moves objects to the specified position.
2845 // Is used in the drag-n-drop functionality.
2846 //=================================================================================
2847 void GEOM_Gen_i::Move( const GEOM::object_list& what,
2848 SALOMEDS::SObject_ptr where,
2851 if ( CORBA::is_nil( where ) ) return;
2853 SALOMEDS::Study_var study = where->GetStudy();
2854 SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder();
2855 SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder();
2856 SALOMEDS::SComponent_var father = where->GetFatherComponent();
2857 std::string dataType = father->ComponentDataType();
2858 if ( dataType != "GEOM" ) return; // not a GEOM component
2860 SALOMEDS::SObject_var objAfter;
2861 if ( row >= 0 && useCaseBuilder->HasChildren( where ) ) {
2862 // insert at given row -> find insertion position
2863 SALOMEDS::UseCaseIterator_var useCaseIt = useCaseBuilder->GetUseCaseIterator( where );
2865 for ( i = 0; i < row && useCaseIt->More(); i++, useCaseIt->Next() );
2866 if ( i == row && useCaseIt->More() ) {
2867 objAfter = useCaseIt->Value();
2871 for ( int i = 0; i < what.length(); i++ ) {
2872 SALOMEDS::SObject_var sobj = what[i];
2873 if ( CORBA::is_nil( sobj ) ) continue; // skip bad object
2874 // insert the object to the use case tree
2875 if ( !CORBA::is_nil( objAfter ) )
2876 useCaseBuilder->InsertBefore( sobj, objAfter ); // insert at given row
2878 useCaseBuilder->AppendTo( where, sobj ); // append to the end of list
2882 //=====================================================================================
2884 //=====================================================================================
2889 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
2893 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb,
2894 PortableServer::POA_ptr poa,
2895 PortableServer::ObjectId* contId,
2896 const char* instanceName,
2897 const char* interfaceName)
2899 GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
2900 return myGEOM_Gen_i->getId();