1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 #pragma warning( disable:4786 )
27 #include <Standard_Stream.hxx>
29 #include "GEOM_Gen_i.hh"
30 #include "GEOM_Object_i.hh"
31 #include "GEOM_Field_i.hh"
32 #include "GEOM_version.h"
34 #include "Utils_CorbaException.hxx"
36 #include "Utils_ExceptHandlers.hxx"
37 #include "utilities.h"
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 "GEOMImpl_IInsertOperations.hxx"
46 #include "GEOM_wrap.hxx"
47 #include "GEOMUtils_XmlHandler.hxx"
50 #include <BRep_Builder.hxx>
51 #include <BRepTools.hxx>
52 #include <TDF_Label.hxx>
53 #include <TDF_Tool.hxx>
54 #include <TDF_ChildIDIterator.hxx>
55 #include <TNaming_NamedShape.hxx>
56 #include <TDataStd_Name.hxx>
57 #include <TCollection_AsciiString.hxx>
58 #include <TColStd_HArray1OfInteger.hxx>
59 #include <TopAbs_ShapeEnum.hxx>
61 #include <TopTools_SequenceOfShape.hxx>
63 #include <TDataStd_ChildNodeIterator.hxx>
64 #include <TDocStd_Owner.hxx>
65 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
67 #include <SALOMEDS_Tool.hxx>
68 #include <SALOMEDS_wrap.hxx>
69 #include <SALOME_DataContainer_i.hxx>
70 #include <Basics_DirUtils.hxx>
83 #define LibHandle HMODULE
84 #define LoadLib( name ) LoadLibrary( name )
85 #define GetProc GetProcAddress
86 #define UnLoadLib( handle ) FreeLibrary( handle );
88 #define LibHandle void*
89 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
91 #define UnLoadLib( handle ) dlclose( handle );
94 //============================================================================
95 // function : GEOM_Gen_i()
96 // purpose : constructor to be called for servant creation.
97 //============================================================================
98 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
99 PortableServer::POA_ptr poa,
100 PortableServer::ObjectId* contId,
101 const char* instanceName,
102 const char* interfaceName) :
103 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
106 _id = _poa->activate_object(_thisObj);
107 name_service = new SALOME_NamingService(_orb);
109 _impl = new ::GEOMImpl_Gen;
111 //PAL10867: disable signals catching with "noexcepthandler" option
112 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
113 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
115 //work around PAL12004, PAL12628
116 //OSD::SetSignal( true );
117 bool raiseFPE = false;
118 #if defined(_DEBUG_) | defined(_DEBUG) //the Last for WIN32 default settings
119 char* envEnableFPE = getenv("ENABLE_FPE");
120 if (envEnableFPE && atoi(envEnableFPE))
123 OSD::SetSignal( raiseFPE );
126 GEOMUtils::PluginInfo plugins = GEOMUtils::ReadPluginInfo();
127 GEOMUtils::PluginInfo::const_iterator it;
128 for (it = plugins.begin(); it != plugins.end(); ++it)
131 LoadPlugin((*it).serverLib);
134 MESSAGE("Warning: can't load plugin library " << (*it).serverLib);
139 //============================================================================
140 // function : ~GEOM_Gen_i()
141 // purpose : destructor
142 //============================================================================
143 GEOM_Gen_i::~GEOM_Gen_i() {
149 //============================================================================
150 // function : IORToLocalPersistentID()
152 //============================================================================
153 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
154 const char* IORString,
155 CORBA::Boolean isMultiFile,
156 CORBA::Boolean isASCII)
158 GEOM::GEOM_BaseObject_var anObject =
159 GEOM::GEOM_BaseObject::_narrow(_orb->string_to_object(IORString));
160 if (!CORBA::is_nil(anObject)) {
161 return CORBA::string_dup(anObject->GetEntry());
167 //============================================================================
168 // function : LocalPersistentIDToIOR()
169 // purpose : Create/Load CORBA object from a persistent ref (an entry)
170 // : Used when a study is loaded
171 // : The IOR (IORName) of object created is returned
172 //============================================================================
173 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
174 const char* aLocalPersistentID,
175 CORBA::Boolean isMultiFile,
176 CORBA::Boolean isASCII)
178 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
180 Handle(GEOM_BaseObject) anObject =
181 _impl->GetObject(aStudy->StudyId(), aLocalPersistentID);
182 if ( !anObject.IsNull() )
184 TCollection_AsciiString anEntry;
185 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
186 GEOM::GEOM_BaseObject_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
188 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
189 return CORBA::string_dup(aPersRefString);
193 return CORBA::string_dup("");
197 //============================================================================
198 // function : CanPublishInStudy
200 //============================================================================
201 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
203 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
204 return !(anObject->_is_nil());
208 //============================================================================
209 // function : PublishInStudy
211 //============================================================================
212 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
213 SALOMEDS::SObject_ptr theSObject,
214 CORBA::Object_ptr theObject,
216 throw (SALOME::SALOME_Exception)
218 Unexpect aCatch(SALOME_SalomeException);
219 SALOMEDS::SObject_var aResultSO;
220 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
221 GEOM::GEOM_BaseObject_var aBaseObj = GEOM::GEOM_BaseObject::_narrow(theObject);
222 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
223 if(aBaseObj->_is_nil()) return aResultSO;
225 SALOMEDS::GenericAttribute_var anAttr;
226 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
227 SALOMEDS::UseCaseBuilder_var useCaseBuilder = theStudy->GetUseCaseBuilder();
229 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
230 if (aFather->_is_nil()) {
231 aFather = aStudyBuilder->NewComponent("GEOM");
232 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
233 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
234 aName->SetValue("Geometry");
236 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
237 SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr);
238 aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry");
239 aPixMap->UnRegister();
240 aStudyBuilder->DefineComponentInstance(aFather, (GEOM::GEOM_Gen_var)GEOM_Gen::_this());
241 // add component to the use case tree
242 // (to support tree representation customization and drag-n-drop)
243 useCaseBuilder->SetRootCurrent();
244 useCaseBuilder->Append( aFather ); // component object is added as the top level item
246 if (aFather->_is_nil()) return aResultSO;
248 if (CORBA::is_nil(theSObject)) {
249 aResultSO = aStudyBuilder->NewObject(aFather);
251 if (!theSObject->ReferencedObject(aResultSO))
252 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
253 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
255 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
256 aResultSO->SetAttrString("AttributeIOR",aGeomObjIOR);
258 TCollection_AsciiString anObjectName, aNamePrefix("Shape_");
259 CORBA::Long mytype=aBaseObj->GetType();
261 // BEGIN: try to find existed name for current shape
262 if ( !aShape->_is_nil() && mytype != GEOM_GROUP)
264 // recieve current TopoDS shape
265 CORBA::String_var entry = aShape->GetEntry();
266 Handle(GEOM_Object) aGShape = Handle(GEOM_Object)::DownCast
267 ( _impl->GetObject( aShape->GetStudyID(), entry ));
268 TopoDS_Shape TopoSh = aGShape->GetValue();
269 // find label of main shape
270 GEOM::GEOM_Object_var aMainSh = aShape;
271 while( !aMainSh->IsMainShape() ) {
272 aMainSh = aMainSh->GetMainShape();
274 entry = aMainSh->GetEntry();
275 Handle(GEOM_BaseObject) anObj = _impl->GetObject( aMainSh->GetStudyID(), entry );
276 TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry();
278 // check all named shapes using iterator
279 TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
281 for (; anIt.More() && anObjectName.IsEmpty(); anIt.Next()) {
282 Handle(TNaming_NamedShape) anAttr =
283 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
284 if (anAttr.IsNull()) continue;
285 TopoDS_Shape S = anAttr->Get();
286 if (S.IsEqual(TopoSh)) {
287 TDF_Label L = anAttr->Label();
288 Handle(TDataStd_Name) aName;
289 if (L.FindAttribute(TDataStd_Name::GetID(), aName))
290 anObjectName = aName->Get();
294 // END: try to find existed name for current shape
296 if ( mytype == GEOM_GROUP ) {
297 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
298 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape )) {
300 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_PNT" );
301 aNamePrefix = "Group_Of_Vertices_";
304 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_EDGE");
305 aNamePrefix = "Group_Of_Edges_";
308 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_FACE");
309 aNamePrefix = "Group_Of_Faces_";
312 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_SOLID");
313 aNamePrefix = "Group_Of_Solids_";
316 } else if ( mytype == GEOM_MARKER ) {
317 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS");
318 aNamePrefix = "LocalCS_";
319 } else if ( mytype >= USER_TYPE_EX ) {
321 sprintf( buf, "%d", aBaseObj->GetType() );
322 GEOM::CreationInformation_var info = aBaseObj->GetCreationInformation();
324 for ( size_t i = 0; i < info->params.length(); ++i ) {
325 std::string param_name = info->params[i].name.in();
326 std::string param_value = info->params[i].value.in();
327 if( param_name == PLUGIN_NAME) {
332 if(plgId.length() > 0 ) {
335 plgId +="ICON_OBJBROWSER_";
337 aResultSO->SetAttrString("AttributePixMap",plgId.c_str());
338 } else if ( mytype > USER_TYPE ) {
340 sprintf( buf, "%d", aBaseObj->GetType() );
341 std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf;
342 aResultSO->SetAttrString("AttributePixMap",advId.c_str());
343 aNamePrefix = "Advanced_";
344 } else if ( mytype == GEOM_FIELD ) {
345 aNamePrefix = "Field_";
346 GEOM::GEOM_Field_var aField = GEOM::GEOM_Field::_narrow(theObject);
347 if ( !aField->_is_nil() )
348 switch( aField->GetDimension() ) {
350 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_PNT" ); break;
352 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_EDGE"); break;
354 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_FACE"); break;
356 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID"); break;
358 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID");
360 } else if ( mytype == GEOM_FIELD_STEP ) {
361 aNamePrefix = "Step_";
362 } else if ( !aShape->_is_nil() ) {
363 GEOM::shape_type myshapetype=aShape->GetShapeType();
364 if ( myshapetype == GEOM::COMPOUND ) {
365 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPOUND" );
366 aNamePrefix = "Compound_";
367 } else if ( myshapetype == GEOM::COMPSOLID ) {
368 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPSOLID");
369 aNamePrefix = "Compsolid_";
370 } else if ( myshapetype == GEOM::SOLID ) {
371 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SOLID");
372 aNamePrefix = "Solid_";
373 } else if ( myshapetype == GEOM::SHELL ) {
374 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SHELL");
375 aNamePrefix = "Shell_";
376 } else if ( myshapetype == GEOM::FACE ) {
377 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FACE");
378 aNamePrefix = "Face_";
379 } else if ( myshapetype == GEOM::WIRE ) {
380 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_WIRE");
381 aNamePrefix = "Wire_";
382 } else if ( myshapetype == GEOM::EDGE ) {
383 aResultSO->SetAttrString("AttributePixMap", "ICON_OBJBROWSER_EDGE");
384 aNamePrefix = "Edge_";
385 } else if ( myshapetype == GEOM::VERTEX ) {
386 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_VERTEX" );
387 aNamePrefix = "Vertex_";
390 if ( anObjectName.IsEmpty() )
392 //if (strlen(theName) == 0) aNamePrefix += TCollection_AsciiString(aResultSO->Tag());
393 //else anObjectName = TCollection_AsciiString(CORBA::string_dup(theName));
395 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
396 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
397 // of objects in the study, but compute a number of objects with the same prefix
398 // and build a new name as Prefix_N+1
399 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
400 int i = 0; // (WITH EMPTY NEW NAME)
401 SALOMEDS::SObject_var obj;
403 anObjectName = aNamePrefix + TCollection_AsciiString(++i);
404 obj = theStudy->FindObject( anObjectName.ToCString() );
406 while ( !obj->_is_nil() );
408 else { // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
409 anObjectName = theName;
413 //Set the study entry as a name of the published GEOM_Object
414 CORBA::String_var anID = aResultSO->GetID();
415 aBaseObj->SetStudyEntry(anID.in());
417 //Set a name of the added shape
418 aResultSO->SetAttrString("AttributeName",anObjectName.ToCString());
420 //Set NoteBook variables used in the object creation
421 TCollection_AsciiString aVars;
422 CORBA::String_var aString=aBaseObj->GetParameters();
423 SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aString);
424 for(int i = 0, n = aSections->length(); i < n; i++) {
425 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
426 for(int j = 0, m = aListOfVars.length(); j < m; j++) {
427 if(theStudy->IsVariable(aListOfVars[j].in()))
428 aVars += aListOfVars[j].in();
435 aResultSO->SetAttrString("AttributeString",aVars.ToCString());
437 aFather->UnRegister();
439 //Set a name of the GEOM object
440 aBaseObj->SetName(anObjectName.ToCString());
442 // add object to the use case tree
443 // (to support tree representation customization and drag-n-drop)
444 useCaseBuilder->AppendTo( aResultSO->GetFather(), aResultSO );
446 return aResultSO._retn();
449 //============================================================================
450 // function : CreateAndPublishGroup
451 // purpose : auxilary for PublishNamedShapesInStudy
452 //============================================================================
453 void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
454 GEOM::GEOM_Object_var theMainShape,
455 const TopTools_IndexedMapOfShape& anIndices,
456 const TopTools_SequenceOfShape& SeqS,
457 const TColStd_SequenceOfAsciiString& SeqN,
458 const Standard_CString& GrName,
459 GEOM::ListOfGO_var aResList)
461 CORBA::String_var entry = theMainShape->GetEntry();
462 //Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
463 Handle(TColStd_HArray1OfInteger) anArray;
464 if(SeqS.Length()>0) {
466 GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId());
467 GEOM::GEOM_Object_wrap GrObj = GOp->CreateGroup( theMainShape, SeqS(1).ShapeType() );
468 AddInStudy(theStudy, GrObj, GrName, theMainShape._retn());
469 //CORBA::String_var GrEntry = GrObj->GetEntry();
470 //Handle(GEOM_Object) HGrObj = _impl->GetObject(GrObj->GetStudyID(), GrEntry);
472 //Handle(GEOM_Object) anObj;
473 for(int i=1; i<=SeqS.Length(); i++) {
474 TopoDS_Shape aValue = SeqS.Value(i);
475 //anArray = new TColStd_HArray1OfInteger(1,1);
476 Standard_Integer anIndex = anIndices.FindIndex(aValue);
477 //anArray->SetValue(1, anIndex);
478 GOp->AddObject(GrObj,anIndex);
479 //anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE);
480 //if (anObj.IsNull()) continue;
481 //Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
482 //if (aFunction.IsNull()) continue;
483 //GEOM_ISubShape aSSI(aFunction);
484 //aSSI.SetMainShape(aMainShape->GetLastFunction());
485 //aSSI.SetIndices(anArray);
486 //aFunction->SetValue(aValue);
487 //GOp->UnionIDs(GrObj, anIndex);
488 //SALOMEDS::SObject_var aResultSO;
489 //TCollection_AsciiString anEntry;
490 //TDF_Tool::Entry(anObj->GetEntry(),anEntry);
491 //GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString());
492 //AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
498 //============================================================================
499 // function : PublishNamedShapesInStudy
501 //============================================================================
502 GEOM::ListOfGO* GEOM_Gen_i::
503 PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
504 //SALOMEDS::SObject_ptr theSObject,
505 CORBA::Object_ptr theObject)
507 //Unexpect aCatch(SALOME_SalomeException);
508 GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
510 //CORBA::Object_var theObject = theSObject->GetObject();
511 GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
512 if(theMainShape->_is_nil()) return aResList._retn();
514 CORBA::String_var entry = theMainShape->GetEntry();
515 Handle(GEOM_Object) aMainShape = Handle(GEOM_Object)::DownCast
516 ( _impl->GetObject( theMainShape->GetStudyID(), entry ));
517 if (aMainShape.IsNull()) return aResList._retn();
518 TopoDS_Shape MainSh = aMainShape->GetValue();
520 TDF_Label aMainLbl = aMainShape->GetEntry();
521 TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
522 TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
523 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
524 for(; anIt.More(); anIt.Next()) {
525 Handle(TNaming_NamedShape) anAttr =
526 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
527 if(anAttr.IsNull()) continue;
528 TopoDS_Shape S = anAttr->Get();
529 TDF_Label L = anAttr->Label();
530 //if(S.IsEqual(MainSh)) continue;
531 Handle(TDataStd_Name) aName;
532 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
533 TCollection_ExtendedString EName = aName->Get();
534 if(S.ShapeType()==TopAbs_SOLID) {
536 SolidSeqN.Append(aName->Get());
538 else if(S.ShapeType()==TopAbs_FACE) {
540 FaceSeqN.Append(aName->Get());
542 else if(S.ShapeType()==TopAbs_EDGE) {
544 EdgeSeqN.Append(aName->Get());
546 else if(S.ShapeType()==TopAbs_VERTEX) {
548 VertSeqN.Append(aName->Get());
553 TopTools_IndexedMapOfShape anIndices;
554 TopExp::MapShapes(MainSh, anIndices);
556 CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN,
557 "Group_Of_Named_Solids", aResList);
559 CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN,
560 "Group_Of_Named_Faces", aResList);
562 CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
563 "Group_Of_Named_Edges", aResList);
565 CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN,
566 "Group_Of_Named_Vertices", aResList);
568 return aResList._retn();
572 //============================================================================
574 // purpose : save OCAF/Geom document
575 //============================================================================
576 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
579 SALOMEDS::TMPFile_var aStreamFile;
580 // Get a temporary directory to store a file
581 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
583 // OCCT BUG: cannot save a document (in current folder)
584 // if directory name is empty
585 if (aTmpDir.size() == 0) {
593 // Create a list to store names of created files
594 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
596 // Prepare a file name to open
597 TCollection_AsciiString aNameWithExt("");
599 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
600 (theComponent->GetStudy()->URL())).c_str());
601 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
602 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
603 // Build a full file name of temporary file
604 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
605 // Save GEOM component in this file
606 _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
607 // Conver a file to the byte stream
608 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
609 // Remove the created file and tmp directory
610 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
612 // Return the created byte stream
613 return aStreamFile._retn();
617 //============================================================================
618 // function : SaveASCII()
620 //============================================================================
621 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
624 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
625 return aStreamFile._retn();
629 //============================================================================
632 //============================================================================
633 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
634 const SALOMEDS::TMPFile& theStream,
638 if (theStream.length() <= 9) {
639 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
643 // Get a temporary directory for a file
644 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
646 // OCCT BUG: cannot load a document (from current folder)
647 // if directory name is empty
648 if (aTmpDir.size() == 0) {
656 // Conver the byte stream theStream to a file and place it in tmp directory
657 SALOMEDS::ListOfFileNames_var aSeq =
658 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
660 // Prepare a file name to open
661 TCollection_AsciiString aNameWithExt("");
662 SALOMEDS::Study_var study = theComponent->GetStudy();
664 CORBA::String_var url = study->URL();
665 aNameWithExt = (char*)SALOMEDS_Tool::GetNameFromPath(url.in()).c_str();
667 aNameWithExt += "_GEOM.sgd";
668 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
671 if (!_impl->Load(study->StudyId(),(char*) aFullName.ToCString())) return false;
673 // Remove the created file and tmp directory
674 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
676 // creation of tree nodes for all data objects in the study
677 // to support tree representation customization and drag-n-drop:
678 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = study->GetUseCaseBuilder();
679 if ( !useCaseBuilder->IsUseCaseNode( theComponent ) ) {
680 useCaseBuilder->SetRootCurrent();
681 useCaseBuilder->Append( theComponent ); // component object is added as the top level item
684 SALOMEDS::ChildIterator_wrap it = study->NewChildIterator( theComponent );
685 for ( it->InitEx(true); it->More(); it->Next() ) {
686 if ( !useCaseBuilder->IsUseCaseNode( it->Value() ) ) {
687 useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() );
695 //============================================================================
696 // function : LoadASCII()
698 //============================================================================
699 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
700 const SALOMEDS::TMPFile& theStream,
703 return Load(theComponent, theStream, theURL, isMultiFile);
707 //============================================================================
708 // function : Close()
710 //============================================================================
711 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
713 SALOMEDS::Study_var aStudy= theComponent->GetStudy();
714 _impl->Close(aStudy->StudyId());
717 //============================================================================
718 // function : CanCopy()
720 //============================================================================
721 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
722 // Try to retrieve known by Geometry component GEOM_Object by given IOR
723 SALOMEDS::GenericAttribute_var anAttr;
724 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
726 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
728 CORBA::String_var aString=anIOR->Value();
730 CORBA::Object_var anObj = _orb->string_to_object(aString);
731 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(anObj);
732 // If the object is null one it can't be copied: return false
733 if (anObject->_is_nil()) return false;
737 //============================================================================
738 // function : CopyFrom()
740 //============================================================================
741 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
743 // Declare a sequence of the byte to store the copied object
744 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
746 // Try to get GEOM_Object object by given SObject
747 SALOMEDS::GenericAttribute_var anAttr;
748 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
749 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
750 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
751 if (anObject->_is_nil()) return aStreamFile._retn();
753 aStreamFile = anObject->GetShapeStream();
755 // Assign an ID the type of GEOM_Object
756 theObjectID = anObject->GetType();
758 // Return created TMPFile
759 return aStreamFile._retn();
762 //============================================================================
763 // function : CanPaste()
765 //============================================================================
766 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
767 // The Geometry component can paste only objects copied by Geometry component
768 // and with the object type = 1
769 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
773 //============================================================================
774 // function : PasteInto()
776 //============================================================================
777 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
778 CORBA::Long theObjectID,
779 SALOMEDS::SObject_ptr theObject) {
780 // Find the current Study and StudyBuilder
781 SALOMEDS::Study_var aStudy = theObject->GetStudy();
782 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
783 SALOMEDS::UseCaseBuilder_var anUseCaseBuilder = aStudy->GetUseCaseBuilder();
784 SALOMEDS::SObject_var aNewSO;
785 // Retrieve a TopoDS_Shape from byte stream
786 TopoDS_Shape aTopology;
787 std::istringstream aStreamedBrep((char*) &theStream[0]);
788 BRep_Builder aBuilder;
790 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
791 } catch (Standard_Failure) {
792 return aNewSO._retn();
795 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
796 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
797 aNewSO = aStudyBuilder->NewObject(theObject);
798 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
801 //Create a new GEOM_Object
802 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
803 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
804 aFunction->SetValue(aTopology);
806 TCollection_AsciiString anEntry;
807 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
808 GEOM::GEOM_BaseObject_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
810 //Set the study entry of the published GEOM_Object
811 obj->SetStudyEntry(aNewSO->GetID());
813 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
814 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
815 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
816 CORBA::String_var objStr = _orb->object_to_string(obj);
817 anIOR->SetValue(objStr.in());
820 // add object to the use case tree
821 // (to support tree representation customization and drag-n-drop)
822 anUseCaseBuilder->AppendTo( aNewSO->GetFather(), aNewSO );
824 // Return the created in the Study SObject
825 return aNewSO._retn();
828 //============================================================================
829 // function : ComponentDataType()
831 //============================================================================
832 char* GEOM_Gen_i::ComponentDataType()
834 return CORBA::string_dup("GEOM");
837 //============================================================================
838 // function : AddInStudy
840 //============================================================================
841 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
842 GEOM::GEOM_BaseObject_ptr theObject,
844 GEOM::GEOM_BaseObject_ptr theFather)
846 SALOMEDS::SObject_var aResultSO;
847 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
849 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
850 CORBA::String_var IOR;
852 if(!theFather->_is_nil()) {
853 IOR = _orb->object_to_string(theFather);
854 SALOMEDS::SObject_wrap aFatherSO = theStudy->FindObjectIOR(IOR.in());
855 if(aFatherSO->_is_nil()) return aResultSO._retn();
856 aResultSO = aStudyBuilder->NewObject(aFatherSO);
857 //aStudyBuilder->Addreference(aResultSO, aResultSO);
860 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
861 if(aResultSO->_is_nil()) return aResultSO._retn();
863 GEOM::ListOfGBO_var aList = theObject->GetDependency();
864 Standard_Integer aLength = aList->length();
865 if(aLength < 1) return aResultSO._retn();
867 //Publish the arguments
868 TCollection_AsciiString aPrevID; // to avoid multiple references to same object
869 for(Standard_Integer i = 0; i< aLength; i++) {
870 GEOM::GEOM_BaseObject_var anObject = aList[i];
871 if(anObject->_is_nil()) continue;
872 IOR = _orb->object_to_string(anObject);
873 SALOMEDS::SObject_wrap aSO = theStudy->FindObjectIOR(IOR.in());
874 if(aSO->_is_nil()) continue;
875 CORBA::String_var anID = aSO->GetID();
876 if ( aPrevID == anID.in() ) continue;
878 SALOMEDS::SObject_wrap aSubSO = aStudyBuilder->NewObject(aResultSO);
879 aStudyBuilder->Addreference(aSubSO, aSO);
880 theStudy->GetUseCaseBuilder()->AppendTo( aResultSO, aSubSO );
883 return aResultSO._retn();
886 //============================================================================
887 // function : RestoreSubShapesO
888 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
889 // To be used from python scripts out of geompy.addToStudy (non-default usage)
890 //============================================================================
891 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
892 GEOM::GEOM_Object_ptr theObject,
893 const GEOM::ListOfGO& theArgs,
894 GEOM::find_shape_method theFindMethod,
895 CORBA::Boolean theInheritFirstArg,
896 CORBA::Boolean theAddPrefix)
898 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
899 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
900 return aParts._retn();
902 // find SObject in the study if it is already published
903 CORBA::String_var anIORo = _orb->object_to_string(theObject);
904 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
905 //PTv, IMP 0020001, The salome object <aSO>
906 // is not obligatory in case of invokation from script
907 // if (CORBA::is_nil(aSO))
908 // return aParts._retn();
910 aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs,
911 theFindMethod, theInheritFirstArg, theAddPrefix);
912 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
913 return aParts._retn();
916 //============================================================================
917 // function : RestoreGivenSubShapesO
918 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
919 // To be used from python scripts, generated by Dump Python.
920 //============================================================================
921 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (SALOMEDS::Study_ptr theStudy,
922 GEOM::GEOM_Object_ptr theObject,
923 const GEOM::ListOfGO& theArgs,
924 GEOM::find_shape_method theFindMethod,
925 CORBA::Boolean theInheritFirstArg,
926 CORBA::Boolean theAddPrefix)
928 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
929 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
930 return aParts._retn();
932 // find SObject in the study if it is already published
933 CORBA::String_var anIORo = _orb->object_to_string(theObject);
934 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
935 //PTv, IMP 0020001, The salome object <aSO>
936 // is not obligatory in case of invokation from script
937 // if (CORBA::is_nil(aSO))
938 // return aParts._retn();
940 aParts = RestoreGivenSubShapes(theStudy, theObject, aSO, theArgs,
941 theFindMethod, theInheritFirstArg, theAddPrefix);
942 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
943 return aParts._retn();
946 //============================================================================
947 // function : RestoreSubShapesSO
948 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
949 // To be used from GUI and from geompy.addToStudy
950 //============================================================================
951 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
952 SALOMEDS::SObject_ptr theSObject,
953 const GEOM::ListOfGO& theArgs,
954 GEOM::find_shape_method theFindMethod,
955 CORBA::Boolean theInheritFirstArg,
956 CORBA::Boolean theAddPrefix)
958 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
959 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
960 return aParts._retn();
962 SALOMEDS::GenericAttribute_var anAttr;
963 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
964 return aParts._retn();
966 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
967 CORBA::String_var anIORso = anAttrIOR->Value();
969 // get Object from SObject
970 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
971 if (CORBA::is_nil(anO))
972 return aParts._retn();
974 aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs,
975 theFindMethod, theInheritFirstArg, theAddPrefix);
976 return aParts._retn();
979 //============================================================================
980 // function : addToListOfGO
981 // purpose : static local function
982 //============================================================================
983 static void addToListOfGO( GEOM::GEOM_Object_ptr theObject,
984 GEOM::ListOfGO& theList )
986 const int oldLen = theList.length();
987 theList.length(oldLen + 1);
988 theList[ oldLen ] = GEOM::GEOM_Object::_duplicate( theObject );
991 //============================================================================
992 // function : addToListOfGO
993 // purpose : static local function
994 //============================================================================
995 static void addToListOfGO( const GEOM::ListOfGO& theSrcList,
996 GEOM::ListOfGO& theTrgList )
998 const int oldLen = theTrgList.length();
999 const int srcLen = theSrcList.length();
1000 theTrgList.length(oldLen + srcLen);
1001 for( int i = 0; i < srcLen; i++ )
1002 theTrgList[ oldLen + i ] = GEOM::GEOM_Object::_duplicate( theSrcList[ i ] );
1005 //============================================================================
1006 // function : RestoreSubShapes
1007 // purpose : Private method. Works only if both theObject and theSObject
1008 // are defined, and does not check, if they correspond to each other.
1009 //============================================================================
1010 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy,
1011 GEOM::GEOM_Object_ptr theObject,
1012 SALOMEDS::SObject_ptr theSObject,
1013 const GEOM::ListOfGO& theArgs,
1014 GEOM::find_shape_method theFindMethod,
1015 CORBA::Boolean theInheritFirstArg,
1016 CORBA::Boolean theAddPrefix)
1018 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1019 //PTv, IMP 0020001, The salome object <theSObject>
1020 // is not obligatory in case of invokation from script
1021 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
1022 return aParts._retn();
1024 // For Dump Python (mantis issue 0020768)
1025 GEOM::ListOfGO_var anOutArgs = new GEOM::ListOfGO;
1027 // Arguments to be published
1028 GEOM::ListOfGO_var aList;
1030 // If theArgs list is empty, we try to publish all arguments,
1031 // otherwise publish only passed args
1032 Standard_Integer nbArgsActual = -1; // -1 means unknown
1033 Standard_Integer aLength = theArgs.length();
1035 aList = new GEOM::ListOfGO;
1036 aList->length(aLength);
1037 for (int i = 0; i < aLength; i++) {
1038 aList[i] = GEOM::GEOM_Object::_duplicate( theArgs[i] );
1042 // Get all arguments
1043 GEOM::ListOfGBO_var boList = theObject->GetDependency();
1044 aLength = boList->length();
1045 aList = new GEOM::ListOfGO;
1046 aList->length(aLength);
1047 for (int i = 0; i < aLength; i++)
1048 aList[i] = GEOM::GEOM_Object::_narrow( boList[i] );
1049 nbArgsActual = aLength;
1053 return aParts._retn();
1055 if (theInheritFirstArg || (nbArgsActual == 1)) {
1056 // Do not publish argument's reflection,
1057 // but only reconstruct its published sub-shapes
1059 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1060 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1062 // remember restored objects for Python Dump
1063 addToListOfGO(aList[0], anOutArgs);
1065 aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
1066 anOutArgs, theFindMethod, theAddPrefix);
1068 // set the color of the transformed shape to the color of initial shape
1069 theObject->SetColor(aList[0]->GetColor());
1071 if (theObject->GetShapeType() == GEOM::VERTEX) {
1072 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1073 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1074 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1077 anArgSO->UnRegister();
1080 // Get interface, containing method, which we will use to reconstruct sub-shapes
1081 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1082 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1083 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1085 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1086 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1088 // Reconstruct arguments and tree of sub-shapes of the arguments
1089 CORBA::String_var anIOR;
1090 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1091 for (Standard_Integer i = 0; i < aLength; i++)
1093 GEOM::GEOM_Object_var anArgO = aList[i];
1094 if (!CORBA::is_nil(anArgO)) {
1095 anIOR = _orb->object_to_string(anArgO);
1096 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1097 TCollection_AsciiString anArgName;
1098 if (CORBA::is_nil(anArgSO)) {
1100 anArgName += TCollection_AsciiString(i);
1103 anArgName = anArgSO->GetName();
1106 // Find a sub-shape of theObject in place of the argument
1107 GEOM::GEOM_Object_var aSubO;
1108 switch (theFindMethod) {
1109 case GEOM::FSM_GetInPlace:
1112 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1115 case GEOM::FSM_MultiTransformed:
1117 // Only for Multi-transformations
1118 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1119 if (!CORBA::is_nil(anArgOTrsf)) {
1120 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1121 Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1122 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1123 anArgOTrsfFun->SetDescription("");
1124 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1127 Handle(GEOM_Function) anOFun = theObject->GetLastFunction();
1128 if (!anOFun.IsNull()) {
1129 CORBA::String_var entryArg = anArgO->GetEntry();
1130 Handle(GEOM_Object) anArgOImpl = _impl->GetObject(anArgO->GetStudyID(), entryArg);
1131 if (!anArgOImpl.IsNull()) {
1132 TopoDS_Shape anArgOShape = anArgOImpl->GetValue();
1133 TopoDS_Shape aMultiArgShape;
1134 //GEOM::GEOM_Object_var anArgOMulti; // ???
1135 switch (anOFun->GetType()) {
1138 GEOMImpl_ITranslate aTI (anOFun);
1139 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape1D(anArgOShape, &aTI);
1140 //anArgOMulti = aTrsfOpSv->Translate1D(anArgO, , , );
1145 GEOMImpl_ITranslate aTI (anOFun);
1146 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1151 GEOMImpl_IRotate aTI (anOFun);
1152 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1157 GEOMImpl_IRotate aTI (anOFun);
1158 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1164 GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO
1165 Handle(GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction();
1166 anArgOMultiFun->SetDescription("");
1167 aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti);
1173 case GEOM::FSM_Transformed:
1175 // transformation, cannot use GetInPlace, operate with indices
1176 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1177 if (anIDs->length() > 1) {
1179 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1180 if (!CORBA::is_nil(aSubO))
1181 aGroupOp->UnionIDs(aSubO, anIDs);
1183 else if (anIDs->length() > 0) {
1185 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1189 case GEOM::FSM_GetSame:
1192 aSubO = aShapesOp->GetSame(theObject, anArgO);
1195 case GEOM::FSM_GetShapesOnShape:
1197 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1198 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1199 (short)GEOM::SOLID, GEOM::ST_ONIN);
1202 case GEOM::FSM_GetInPlaceByHistory:
1204 // Use GetInPlaceByHistory
1205 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1212 if (!CORBA::is_nil(aSubO)) {
1213 // remember restored objects for Python Dump
1214 addToListOfGO(anArgO, anOutArgs);
1216 // add to parts list
1217 addToListOfGO( aSubO, aParts );
1219 // Publish the sub-shape
1220 SALOMEDS::SObject_var aSubSO;
1221 if (!CORBA::is_nil(theSObject)) {
1222 TCollection_AsciiString aSubName;
1226 aSubName += anArgName;
1227 aSubSO = aStudyBuilder->NewObject(theSObject);
1228 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1230 aSubO->SetColor(anArgO->GetColor());
1232 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1233 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1234 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1235 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1239 if (!CORBA::is_nil(anArgSO)) {
1240 // Restore published sub-shapes of the argument
1241 GEOM::ListOfGO_var aSubParts;
1242 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1243 // pass theObject, because only it has the history
1244 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1245 theObject, anOutArgs, theFindMethod, theAddPrefix);
1247 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1248 aSubO, anOutArgs, theFindMethod, theAddPrefix);
1249 // add to parts list
1250 addToListOfGO( aSubParts, aParts );
1253 else { // GetInPlace failed, try to build from published parts
1254 if (!CORBA::is_nil(anArgSO)) {
1255 SALOMEDS::SObject_var aSubSO;
1256 if (!CORBA::is_nil(theSObject))
1257 aSubSO = aStudyBuilder->NewObject(theSObject);
1259 // Restore published sub-shapes of the argument
1260 GEOM::ListOfGO_var aSubParts =
1261 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1262 theObject, anOutArgs, theFindMethod, theAddPrefix);
1264 // add to parts list
1265 addToListOfGO( aSubParts, aParts );
1267 if (aSubParts->length() > 0) {
1268 // remember restored objects for Python Dump
1269 addToListOfGO(anArgO, anOutArgs);
1271 // try to build an argument from a set of its sub-shapes,
1272 // that published and will be reconstructed
1273 if (aSubParts->length() > 1) {
1274 aSubO = aShapesOp->MakeCompound(aSubParts);
1275 // add to parts list
1276 addToListOfGO( aSubO, aParts );
1279 aSubO = aSubParts[0];
1281 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1282 // Publish the sub-shape
1283 TCollection_AsciiString aSubName;
1285 aSubName = "from_parts_of_";
1287 aSubName += anArgName;
1288 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1290 aSubO->SetColor(anArgO->GetColor());
1292 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1293 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1294 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1295 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1299 else if (!CORBA::is_nil(aSubSO)) {
1300 // remove created aSubSO, because no parts have been found
1301 aStudyBuilder->RemoveObject(aSubSO);
1304 } // try to build from published parts
1305 anArgSO->UnRegister();
1307 } // process arguments
1309 std::set<std::string> anObjEntryMap;
1310 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1312 int nb = aParts->length();
1313 aResParts->length(nb);
1316 Handle(GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1317 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1318 GEOM::TPythonDump pd (aFunction, true);
1321 for ( ; i < nb; i++ )
1323 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1324 if (CORBA::is_nil(anObj))
1326 char* anEntry = anObj->GetEntry();
1327 if (anObjEntryMap.count(anEntry))
1328 continue; // already treated
1329 anObjEntryMap.insert(anEntry);
1330 aResParts[nbRes++] = anObj;
1331 // clear python dump of object
1332 Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1333 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1334 if ( !anObjFun.IsNull() )
1335 anObjFun->SetDescription( "" );
1341 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1342 //i = 0; nb = theArgs.length(); j = 0;
1343 i = 0; nb = anOutArgs->length(); j = 0;
1344 for ( ; i < nb; i++ )
1346 //GEOM::GEOM_Object_var anObj = theArgs[ i ];
1347 GEOM::GEOM_Object_var anObj = anOutArgs[ i ];
1348 if (CORBA::is_nil(anObj))
1350 Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1356 pd <<"]" << ", " <<"GEOM.";
1357 switch (theFindMethod) {
1358 case GEOM::FSM_GetInPlace:
1359 pd << "FSM_GetInPlace"; break;
1360 case GEOM::FSM_MultiTransformed:
1361 pd << "FSM_MultiTransformed"; break;
1362 case GEOM::FSM_Transformed:
1363 pd << "FSM_Transformed"; break;
1364 case GEOM::FSM_GetSame:
1365 pd << "FSM_GetSame"; break;
1366 case GEOM::FSM_GetShapesOnShape:
1367 pd << "FSM_GetShapesOnShape"; break;
1368 case GEOM::FSM_GetInPlaceByHistory:
1370 pd << "FSM_GetInPlaceByHistory"; break;
1372 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1374 aResParts->length(nbRes);
1375 return aResParts._retn();
1378 //============================================================================
1379 // function : RestoreSubShapesOneLevel
1380 // purpose : Private method
1381 //============================================================================
1382 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1383 SALOMEDS::SObject_ptr theOldSO,
1384 SALOMEDS::SObject_ptr theNewSO,
1385 GEOM::GEOM_Object_ptr theNewO,
1386 GEOM::ListOfGO& theOutArgs,
1387 GEOM::find_shape_method theFindMethod,
1388 CORBA::Boolean theAddPrefix)
1391 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1392 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1393 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1394 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1395 return aParts._retn();
1397 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1399 // Get interface, containing method, which we will use to reconstruct sub-shapes
1400 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1401 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1402 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1404 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1405 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1407 // Reconstruct published sub-shapes
1408 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1411 for (it->Init(); it->More(); it->Next()) {
1414 aParts->length(aLen);
1416 for (it->Init(); it->More(); it->Next()) {
1417 SALOMEDS::SObject_var anOldSubSO = it->Value();
1419 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1421 SALOMEDS::GenericAttribute_var anAttr;
1422 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1423 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1424 GEOM::GEOM_Object_var anOldSubO =
1425 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1426 if (!CORBA::is_nil(anOldSubO)) {
1427 // Find a sub-shape of theNewO in place of anOldSubO
1428 GEOM::GEOM_Object_var aNewSubO;
1429 switch (theFindMethod) {
1430 case GEOM::FSM_GetInPlace:
1433 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1436 case GEOM::FSM_MultiTransformed:
1438 // Only for Multi-transformations
1439 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
1440 if (!CORBA::is_nil(anArgOTrsf)) {
1441 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1442 Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1443 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1444 anArgOTrsfFun->SetDescription("");
1445 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1449 case GEOM::FSM_Transformed:
1451 // transformation, cannot use GetInPlace, operate with indices
1452 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1453 if (anIDs->length() > 1) {
1455 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1456 if (!CORBA::is_nil(aNewSubO))
1457 aGroupOp->UnionIDs(aNewSubO, anIDs);
1461 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1465 case GEOM::FSM_GetSame:
1468 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1471 case GEOM::FSM_GetShapesOnShape:
1473 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1474 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1475 (short)GEOM::SOLID, GEOM::ST_ONIN);
1478 case GEOM::FSM_GetInPlaceByHistory:
1480 // Use GetInPlaceByHistory
1481 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1488 if (!CORBA::is_nil(aNewSubO)) {
1489 // remember restored objects for Python Dump
1490 addToListOfGO(anOldSubO, theOutArgs);
1492 // add the part to the list
1493 aParts[i] = aNewSubO;
1495 // add to parts list
1496 addToListOfGO( aNewSubO, aNewParts );
1498 SALOMEDS::SObject_var aNewSubSO;
1499 if (!CORBA::is_nil(theNewSO)) {
1500 // Publish the sub-shape
1501 TCollection_AsciiString aSubName;
1505 aSubName += anArgName;
1506 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1507 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1509 aNewSubO->SetColor(anOldSubO->GetColor());
1511 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1512 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1513 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1514 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1517 // Restore published sub-shapes of the argument
1518 GEOM::ListOfGO_var aSubParts;
1519 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1520 // pass the main shape as Object, because only it has the history
1521 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1522 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1524 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1525 aNewSubO, theOutArgs, theFindMethod, theAddPrefix);
1526 // add to parts list
1527 addToListOfGO( aSubParts, aNewParts );
1529 else { // GetInPlace failed, try to build from published parts
1530 SALOMEDS::SObject_var aNewSubSO;
1531 if (!CORBA::is_nil(theNewSO))
1532 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1534 // Restore published sub-shapes of the argument
1535 GEOM::ListOfGO_var aSubParts =
1536 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1537 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1538 // add to parts list
1539 addToListOfGO( aSubParts, aNewParts );
1541 if (aSubParts->length() > 0) {
1542 // remember restored objects for Python Dump
1543 addToListOfGO(anOldSubO, theOutArgs);
1545 // try to build an object from a set of its sub-shapes,
1546 // that published and will be reconstructed
1547 if (aSubParts->length() > 1) {
1548 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1549 // add to parts list
1550 addToListOfGO( aNewSubO, aNewParts );
1553 aNewSubO = aSubParts[0];
1556 if (!CORBA::is_nil(aNewSubO)) {
1557 // add the part to the list
1558 aSubParts[i] = aNewSubO;
1561 // Publish the sub-shape
1562 if (!CORBA::is_nil(aNewSubSO)) {
1563 TCollection_AsciiString aSubName;
1565 aSubName = "from_parts_of_";
1567 aSubName += anArgName;
1568 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1570 aNewSubO->SetColor(anOldSubO->GetColor());
1572 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1573 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1574 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1575 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1580 else if (!CORBA::is_nil(aNewSubSO)) {
1581 // remove created aSubSO, because no parts have been found
1582 aStudyBuilder->RemoveObject(aNewSubSO);
1584 } // try to build from published parts
1587 } // iterate on published sub-shapes
1590 // add to parts list
1591 addToListOfGO( aNewParts, aParts );
1592 return aParts._retn();
1595 //============================================================================
1596 // function : RestoreGivenSubShapes
1597 // purpose : Private method. Works only if both theObject and theSObject
1598 // are defined, and does not check, if they correspond to each other.
1599 // List theArgs in this case contains not only operation arguments,
1600 // but also all subshapes, which must be published.
1601 //============================================================================
1602 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStudy,
1603 GEOM::GEOM_Object_ptr theObject,
1604 SALOMEDS::SObject_ptr theSObject,
1605 const GEOM::ListOfGO& theArgs,
1606 GEOM::find_shape_method theFindMethod,
1607 CORBA::Boolean theInheritFirstArg,
1608 CORBA::Boolean theAddPrefix)
1610 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1611 //PTv, IMP 0020001, The salome object <theSObject>
1612 // is not obligatory in case of invokation from script
1613 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
1614 return aParts._retn();
1616 // If theArgs list is empty, nothing to do
1617 Standard_Integer aLength = theArgs.length();
1619 return aParts._retn();
1621 // Get all arguments
1622 GEOM::ListOfGBO_var anOpArgsList = theObject->GetDependency();
1623 Standard_Integer nbArgsActual = anOpArgsList->length();
1625 // If anOpArgsList list is empty, nothing to do
1626 if (nbArgsActual == 0)
1627 return aParts._retn();
1629 // Entries of arguments and subshapes
1630 std::set<std::string> anArgs;
1631 for (int i = 0; i < aLength; i++) {
1632 CORBA::String_var anEntry = theArgs[i]->GetEntry();
1633 anArgs.insert(anEntry.in());
1636 // Arguments to be published
1637 // We try to publish all arguments, that are in theArgs list
1638 GEOM::ListOfGO_var aList = new GEOM::ListOfGO;
1639 aList->length(nbArgsActual);
1642 for (int j = 0; j < nbArgsActual; j++) {
1643 CORBA::String_var anEntry = anOpArgsList[j]->GetEntry();
1644 if (anArgs.count(anEntry.in())) {
1645 aList[k] = GEOM::GEOM_Object::_narrow(anOpArgsList[j]);
1650 //aList->length(nbArgsActual);
1652 if (nbArgsActual < 1)
1653 return aParts._retn();
1655 if (theInheritFirstArg || (nbArgsActual == 1)) {
1656 // Do not publish argument's reflection,
1657 // but only reconstruct its published sub-shapes
1659 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1660 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1662 aParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
1663 anArgs, theFindMethod, theAddPrefix);
1665 // set the color of the transformed shape to the color of initial shape
1666 theObject->SetColor(aList[0]->GetColor());
1668 if (theObject->GetShapeType() == GEOM::VERTEX) {
1669 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1670 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1671 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1674 anArgSO->UnRegister();
1677 // Get interface, containing method, which we will use to reconstruct sub-shapes
1678 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1679 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1680 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1682 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1683 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1685 // Reconstruct arguments and tree of sub-shapes of the arguments
1686 CORBA::String_var anIOR;
1687 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1688 for (Standard_Integer i = 0; i < nbArgsActual; i++)
1690 GEOM::GEOM_Object_var anArgO = aList[i];
1691 if (!CORBA::is_nil(anArgO)) {
1692 anIOR = _orb->object_to_string(anArgO);
1693 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1694 TCollection_AsciiString anArgName;
1695 if (CORBA::is_nil(anArgSO)) {
1697 anArgName += TCollection_AsciiString(i);
1700 anArgName = anArgSO->GetName();
1703 // Find a sub-shape of theObject in place of the argument
1704 GEOM::GEOM_Object_var aSubO;
1705 switch (theFindMethod) {
1706 case GEOM::FSM_GetInPlace:
1709 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1712 case GEOM::FSM_MultiTransformed:
1714 // Only for Multi-transformations
1715 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1716 if (!CORBA::is_nil(anArgOTrsf)) {
1717 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1718 Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1719 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1720 anArgOTrsfFun->SetDescription("");
1721 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1725 case GEOM::FSM_Transformed:
1727 // transformation, cannot use GetInPlace, operate with indices
1728 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1729 if (anIDs->length() > 1) {
1731 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1732 if (!CORBA::is_nil(aSubO))
1733 aGroupOp->UnionIDs(aSubO, anIDs);
1735 else if (anIDs->length() > 0) {
1737 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1741 case GEOM::FSM_GetSame:
1744 aSubO = aShapesOp->GetSame(theObject, anArgO);
1747 case GEOM::FSM_GetShapesOnShape:
1749 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1750 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1751 (short)GEOM::SOLID, GEOM::ST_ONIN);
1754 case GEOM::FSM_GetInPlaceByHistory:
1756 // Use GetInPlaceByHistory
1757 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1764 if (!CORBA::is_nil(aSubO)) {
1765 // add to parts list
1766 addToListOfGO( aSubO, aParts );
1768 // Publish the sub-shape
1769 SALOMEDS::SObject_var aSubSO;
1770 if (!CORBA::is_nil(theSObject)) {
1771 TCollection_AsciiString aSubName;
1775 aSubName += anArgName;
1776 aSubSO = aStudyBuilder->NewObject(theSObject);
1777 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1779 aSubO->SetColor(anArgO->GetColor());
1781 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1782 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1783 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1784 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1788 if (!CORBA::is_nil(anArgSO)) {
1789 // Restore published sub-shapes of the argument
1790 GEOM::ListOfGO_var aSubParts;
1791 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1792 // pass theObject, because only it has the history
1793 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1794 theObject, anArgs, theFindMethod, theAddPrefix);
1796 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1797 aSubO, anArgs, theFindMethod, theAddPrefix);
1798 // add to parts list
1799 addToListOfGO( aSubParts, aParts );
1802 else { // GetInPlace failed, try to build from published parts
1803 if (!CORBA::is_nil(anArgSO)) {
1804 SALOMEDS::SObject_var aSubSO;
1805 if (!CORBA::is_nil(theSObject))
1806 aSubSO = aStudyBuilder->NewObject(theSObject);
1808 // Restore published sub-shapes of the argument
1809 GEOM::ListOfGO_var aSubParts =
1810 RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1811 theObject, anArgs, theFindMethod, theAddPrefix);
1813 // add to parts list
1814 addToListOfGO( aSubParts, aParts );
1816 if (aSubParts->length() > 0) {
1817 // try to build an argument from a set of its sub-shapes,
1818 // that published and will be reconstructed
1819 if (aSubParts->length() > 1) {
1820 aSubO = aShapesOp->MakeCompound(aSubParts);
1821 // add to parts list
1822 addToListOfGO( aSubO, aParts );
1825 aSubO = aSubParts[0];
1827 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1828 // Publish the sub-shape
1829 TCollection_AsciiString aSubName;
1831 aSubName = "from_parts_of_";
1833 aSubName += anArgName;
1834 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1836 aSubO->SetColor(anArgO->GetColor());
1838 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1839 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1840 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1841 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1845 else if (!CORBA::is_nil(aSubSO)) {
1846 // remove created aSubSO, because no parts have been found
1847 aStudyBuilder->RemoveObject(aSubSO);
1850 } // try to build from published parts
1851 anArgSO->UnRegister();
1853 } // process arguments
1855 std::set<std::string> anObjEntryMap;
1856 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1858 int nb = aParts->length();
1859 aResParts->length(nb);
1862 Handle(GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1863 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1864 GEOM::TPythonDump pd (aFunction, true);
1867 for ( ; i < nb; i++ )
1869 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1870 if (CORBA::is_nil(anObj))
1872 char* anEntry = anObj->GetEntry();
1873 if (anObjEntryMap.count(anEntry))
1874 continue; // already treated
1875 anObjEntryMap.insert(anEntry);
1876 aResParts[nbRes++] = anObj;
1877 // clear python dump of object
1878 Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1879 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1880 if ( !anObjFun.IsNull() )
1881 anObjFun->SetDescription( "" );
1887 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1888 i = 0; nb = theArgs.length(); j = 0;
1889 for ( ; i < nb; i++ )
1891 GEOM::GEOM_Object_var anObj = theArgs[ i ];
1892 if (CORBA::is_nil(anObj))
1894 Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1900 pd <<"]" << ", " <<"GEOM.";
1901 switch (theFindMethod) {
1902 case GEOM::FSM_GetInPlace:
1903 pd << "FSM_GetInPlace"; break;
1904 case GEOM::FSM_MultiTransformed:
1905 pd << "FSM_MultiTransformed"; break;
1906 case GEOM::FSM_Transformed:
1907 pd << "FSM_Transformed"; break;
1908 case GEOM::FSM_GetSame:
1909 pd << "FSM_GetSame"; break;
1910 case GEOM::FSM_GetShapesOnShape:
1911 pd << "FSM_GetShapesOnShape"; break;
1912 case GEOM::FSM_GetInPlaceByHistory:
1914 pd << "FSM_GetInPlaceByHistory"; break;
1916 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1918 aResParts->length(nbRes);
1919 return aResParts._retn();
1922 //============================================================================
1923 // function : RestoreGivenSubShapesOneLevel
1924 // purpose : Private method
1925 //============================================================================
1926 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1927 SALOMEDS::SObject_ptr theOldSO,
1928 SALOMEDS::SObject_ptr theNewSO,
1929 GEOM::GEOM_Object_ptr theNewO,
1930 std::set<std::string> theArgs,
1931 GEOM::find_shape_method theFindMethod,
1932 CORBA::Boolean theAddPrefix)
1935 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1936 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1937 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1938 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1939 return aParts._retn();
1941 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1943 // Get interface, containing method, which we will use to reconstruct sub-shapes
1944 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1945 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1946 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1948 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1949 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1951 // Reconstruct published sub-shapes
1952 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1955 for (it->Init(); it->More(); it->Next()) {
1958 aParts->length(aLen);
1960 for (it->Init(); it->More(); it->Next()) {
1961 SALOMEDS::SObject_var anOldSubSO = it->Value();
1963 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1965 SALOMEDS::GenericAttribute_var anAttr;
1966 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1967 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1968 GEOM::GEOM_Object_var anOldSubO =
1969 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1971 bool okToContinue = false;
1973 if (!CORBA::is_nil(anOldSubO)) {
1974 CORBA::String_var anEntry = anOldSubO->GetEntry();
1975 okToContinue = theArgs.count(anEntry.in());
1979 // Find a sub-shape of theNewO in place of anOldSubO
1980 GEOM::GEOM_Object_var aNewSubO;
1981 switch (theFindMethod) {
1982 case GEOM::FSM_GetInPlace:
1985 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1988 case GEOM::FSM_MultiTransformed:
1990 // Only for Multi-transformations
1991 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
1992 if (!CORBA::is_nil(anArgOTrsf)) {
1993 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1994 Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1995 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1996 anArgOTrsfFun->SetDescription("");
1997 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
2001 case GEOM::FSM_Transformed:
2003 // transformation, cannot use GetInPlace, operate with indices
2004 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
2005 if (anIDs->length() > 1) {
2007 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
2008 if (!CORBA::is_nil(aNewSubO))
2009 aGroupOp->UnionIDs(aNewSubO, anIDs);
2013 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
2017 case GEOM::FSM_GetSame:
2020 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
2023 case GEOM::FSM_GetShapesOnShape:
2025 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
2026 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
2027 (short)GEOM::SOLID, GEOM::ST_ONIN);
2030 case GEOM::FSM_GetInPlaceByHistory:
2032 // Use GetInPlaceByHistory
2033 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
2040 if (!CORBA::is_nil(aNewSubO)) {
2041 // add the part to the list
2042 aParts[i] = aNewSubO;
2044 // add to parts list
2045 addToListOfGO( aNewSubO, aNewParts );
2047 SALOMEDS::SObject_var aNewSubSO;
2048 if (!CORBA::is_nil(theNewSO)) {
2049 // Publish the sub-shape
2050 TCollection_AsciiString aSubName;
2054 aSubName += anArgName;
2055 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
2056 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
2058 aNewSubO->SetColor(anOldSubO->GetColor());
2060 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2061 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2062 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2063 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2066 // Restore published sub-shapes of the argument
2067 GEOM::ListOfGO_var aSubParts;
2068 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
2069 // pass the main shape as Object, because only it has the history
2070 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
2071 theNewO, theArgs, theFindMethod, theAddPrefix);
2073 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
2074 aNewSubO, theArgs, theFindMethod, theAddPrefix);
2075 // add to parts list
2076 addToListOfGO( aSubParts, aNewParts );
2078 else { // GetInPlace failed, try to build from published parts
2079 SALOMEDS::SObject_var aNewSubSO;
2080 if (!CORBA::is_nil(theNewSO))
2081 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
2083 // Restore published sub-shapes of the argument
2084 GEOM::ListOfGO_var aSubParts =
2085 RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
2086 theNewO, theArgs, theFindMethod, theAddPrefix);
2087 // add to parts list
2088 addToListOfGO( aSubParts, aNewParts );
2090 if (aSubParts->length() > 0) {
2091 // try to build an object from a set of its sub-shapes,
2092 // that published and will be reconstructed
2093 if (aSubParts->length() > 1) {
2094 aNewSubO = aShapesOp->MakeCompound(aSubParts);
2095 // add to parts list
2096 addToListOfGO( aNewSubO, aNewParts );
2099 aNewSubO = aSubParts[0];
2102 if (!CORBA::is_nil(aNewSubO)) {
2103 // add the part to the list
2104 aSubParts[i] = aNewSubO;
2107 // Publish the sub-shape
2108 if (!CORBA::is_nil(aNewSubSO)) {
2109 TCollection_AsciiString aSubName;
2111 aSubName = "from_parts_of_";
2113 aSubName += anArgName;
2114 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
2116 aNewSubO->SetColor(anOldSubO->GetColor());
2118 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2119 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2120 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2121 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2126 else if (!CORBA::is_nil(aNewSubSO)) {
2127 // remove created aSubSO, because no parts have been found
2128 aStudyBuilder->RemoveObject(aNewSubSO);
2130 } // try to build from published parts
2133 } // iterate on published sub-shapes
2136 // add to parts list
2137 addToListOfGO( aNewParts, aParts );
2138 return aParts._retn();
2141 //============================================================================
2142 // function : register()
2143 // purpose : register 'name' in 'name_service'
2144 //============================================================================
2145 void GEOM_Gen_i::register_name(char * name)
2147 GEOM::GEOM_Gen_var g = _this();
2148 name_service->Register(g, name);
2151 //============================================================================
2154 //============================================================================
2155 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
2157 _impl->Undo(theStudyID);
2160 //============================================================================
2163 //============================================================================
2164 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
2166 _impl->Redo(theStudyID);
2169 //============================================================================
2170 // function : GetIBasicOperations
2172 //============================================================================
2173 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
2174 throw ( SALOME::SALOME_Exception )
2176 Unexpect aCatch(SALOME_SalomeException);
2177 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
2179 GEOM::GEOM_Gen_ptr engine = _this();
2181 //transfer reference on engine
2182 GEOM_IBasicOperations_i* aServant =
2183 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
2185 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2186 // activate the CORBA servant
2187 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
2188 return operations._retn();
2191 //============================================================================
2192 // function : GetITransformOperations
2194 //============================================================================
2195 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
2196 throw ( SALOME::SALOME_Exception )
2198 Unexpect aCatch(SALOME_SalomeException);
2199 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
2201 GEOM::GEOM_Gen_ptr engine = _this();
2203 GEOM_ITransformOperations_i* aServant =
2204 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
2206 // activate the CORBA servant
2207 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
2208 return operations._retn();
2211 //============================================================================
2212 // function : GetI3DPrimOperations
2214 //============================================================================
2215 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
2216 throw ( SALOME::SALOME_Exception )
2218 Unexpect aCatch(SALOME_SalomeException);
2219 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
2221 GEOM::GEOM_Gen_ptr engine = _this();
2223 GEOM_I3DPrimOperations_i* aServant =
2224 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
2225 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2227 // activate the CORBA servant
2228 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
2229 return operations._retn();
2232 //============================================================================
2233 // function : GetIShapesOperations
2235 //============================================================================
2236 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
2237 throw ( SALOME::SALOME_Exception )
2239 Unexpect aCatch(SALOME_SalomeException);
2240 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
2242 GEOM::GEOM_Gen_ptr engine = _this();
2244 GEOM_IShapesOperations_i* aServant =
2245 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
2247 // activate the CORBA servant
2248 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
2249 return operations._retn();
2252 //============================================================================
2253 // function : GetIBlocksOperations
2255 //============================================================================
2256 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
2257 throw ( SALOME::SALOME_Exception )
2259 Unexpect aCatch(SALOME_SalomeException);
2260 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
2262 GEOM::GEOM_Gen_ptr engine = _this();
2264 GEOM_IBlocksOperations_i* aServant =
2265 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
2267 // activate the CORBA servant
2268 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
2269 return operations._retn();
2272 //============================================================================
2273 // function : GetIBooleanOperations
2275 //============================================================================
2276 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
2277 throw ( SALOME::SALOME_Exception )
2279 Unexpect aCatch(SALOME_SalomeException);
2280 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
2282 GEOM::GEOM_Gen_ptr engine = _this();
2284 GEOM_IBooleanOperations_i* aServant =
2285 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
2287 // activate the CORBA servant
2288 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
2289 return operations._retn();
2292 //============================================================================
2293 // function : GetICurvesOperations
2295 //============================================================================
2296 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
2297 throw ( SALOME::SALOME_Exception )
2299 Unexpect aCatch(SALOME_SalomeException);
2300 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
2302 GEOM::GEOM_Gen_ptr engine = _this();
2304 GEOM_ICurvesOperations_i* aServant =
2305 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
2307 // activate the CORBA servant
2308 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
2309 return operations._retn();
2312 //============================================================================
2313 // function : GetILocalOperations
2315 //============================================================================
2316 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
2317 throw ( SALOME::SALOME_Exception )
2319 Unexpect aCatch(SALOME_SalomeException);
2320 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
2322 GEOM::GEOM_Gen_ptr engine = _this();
2324 GEOM_ILocalOperations_i* aServant =
2325 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
2327 // activate the CORBA servant
2328 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
2329 return operations._retn();
2332 //============================================================================
2333 // function : GetIHealingOperations
2335 //============================================================================
2336 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
2337 throw ( SALOME::SALOME_Exception )
2339 Unexpect aCatch(SALOME_SalomeException);
2340 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
2342 GEOM::GEOM_Gen_ptr engine = _this();
2344 GEOM_IHealingOperations_i* aServant =
2345 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
2347 // activate the CORBA servant
2348 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
2349 return operations._retn();
2352 //============================================================================
2353 // function : GetIInsertOperations
2355 //============================================================================
2356 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
2357 throw ( SALOME::SALOME_Exception )
2359 Unexpect aCatch(SALOME_SalomeException);
2360 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
2362 GEOM::GEOM_Gen_ptr engine = _this();
2364 GEOM_IInsertOperations_i* aServant =
2365 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
2367 // activate the CORBA servant
2368 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
2369 return operations._retn();
2372 //============================================================================
2373 // function : GetIMeasureOperations
2375 //============================================================================
2376 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
2377 throw ( SALOME::SALOME_Exception )
2379 Unexpect aCatch(SALOME_SalomeException);
2380 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
2382 GEOM::GEOM_Gen_ptr engine = _this();
2384 GEOM_IMeasureOperations_i* aServant =
2385 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
2387 // activate the CORBA servant
2388 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
2389 return operations._retn();
2392 //============================================================================
2393 // function : GetIGroupOperations
2395 //============================================================================
2396 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
2397 throw ( SALOME::SALOME_Exception )
2399 Unexpect aCatch(SALOME_SalomeException);
2400 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
2402 GEOM::GEOM_Gen_ptr engine = _this();
2404 GEOM_IGroupOperations_i* aServant =
2405 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
2407 // activate the CORBA servant
2408 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
2409 return operations._retn();
2412 //============================================================================
2413 // function : GetIFieldOperations
2415 //============================================================================
2416 GEOM::GEOM_IFieldOperations_ptr GEOM_Gen_i::GetIFieldOperations(CORBA::Long theStudyID)
2417 throw ( SALOME::SALOME_Exception )
2419 Unexpect aCatch(SALOME_SalomeException);
2420 MESSAGE( "GEOM_Gen_i::GetIFieldOperations" );
2422 GEOM::GEOM_Gen_ptr engine = _this();
2424 GEOM_IFieldOperations_i* aServant =
2425 new GEOM_IFieldOperations_i(_poa, engine, _impl->GetIFieldOperations(theStudyID));
2427 // activate the CORBA servant
2428 GEOM::GEOM_IFieldOperations_var operations = aServant->_this();
2429 return operations._retn();
2432 //============================================================================
2433 // function : GetPluginOperations
2435 //============================================================================
2436 GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(CORBA::Long theStudyID,
2437 const char* theLibName)
2438 throw ( SALOME::SALOME_Exception )
2440 Unexpect aCatch(SALOME_SalomeException);
2441 MESSAGE( "GEOM_Gen_i::GetPluginOperations" );
2443 GEOM::GEOM_Gen_ptr engine = _this();
2445 GEOM::GEOM_IOperations_var operations;
2447 std::string aLibName = theLibName;
2450 // load plugin library
2451 LoadPlugin(aLibName);
2452 // create a new operations object, store its ref. in engine
2453 if ( myOpCreatorMap.find(aLibName) != myOpCreatorMap.end() ) {
2454 GEOM_IOperations_i* aServant = 0;
2455 aServant = myOpCreatorMap[aLibName]->Create(_poa, theStudyID, engine, _impl);
2456 // activate the CORBA servant
2458 operations = aServant->_this();
2461 catch (SALOME_Exception& S_ex) {
2462 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
2465 return operations._retn();
2468 //============================================================================
2469 // function : LoadPlugin
2470 // purpose : load plugin library and retrieve an instance of operations creator
2471 //============================================================================
2472 void GEOM_Gen_i::LoadPlugin(const std::string& theLibName)
2474 std::string aPlatformLibName;
2476 aPlatformLibName = theLibName;
2477 aPlatformLibName += ".dll" ;
2479 aPlatformLibName = "lib";
2480 aPlatformLibName += theLibName;
2481 aPlatformLibName += ".so";
2484 // check, if corresponding operations are already created
2485 if (myOpCreatorMap.find(theLibName) == myOpCreatorMap.end()) {
2486 // load plugin library
2487 LibHandle libHandle = LoadLib( aPlatformLibName.c_str() );
2489 // report any error, if occured
2491 throw(SALOME_Exception(dlerror()));
2493 throw(SALOME_Exception(LOCALIZED( "Can't load server geometry plugin library" )));
2497 // get method, returning operations creator
2498 typedef GEOM_GenericOperationsCreator* (*GetOperationsCreator)();
2499 GetOperationsCreator procHandle =
2500 (GetOperationsCreator)GetProc( libHandle, "GetOperationsCreator" );
2502 UnLoadLib(libHandle);
2503 throw(SALOME_Exception(LOCALIZED("bad geometry plugin library")));
2506 // get operations creator
2507 GEOM_GenericOperationsCreator* aCreator = procHandle();
2509 // map operations creator to a plugin name
2510 myOpCreatorMap[theLibName] = aCreator;
2513 throw(SALOME_Exception(LOCALIZED("bad geometry plugin library implementation")));
2518 //=============================================================================
2522 //=============================================================================
2523 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
2524 const GEOM::ListOfLong& theIndices)
2526 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
2527 return GEOM::GEOM_Object::_nil();
2528 CORBA::String_var entry = theMainShape->GetEntry();
2529 Handle(GEOM_Object) aMainShape = Handle(GEOM_Object)::DownCast
2530 ( _impl->GetObject( theMainShape->GetStudyID(), entry ));
2531 if (aMainShape.IsNull()) return GEOM::GEOM_Object::_nil();
2533 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
2534 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
2536 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true);
2537 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
2539 TCollection_AsciiString anEntry;
2540 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
2541 return GEOM::GEOM_Object::_narrow( GetObject(anObject->GetDocID(), anEntry.ToCString()));
2544 //=============================================================================
2548 //=============================================================================
2549 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_BaseObject_ptr theObject)
2551 CORBA::String_var anEntry = theObject->GetEntry();
2552 Handle(GEOM_BaseObject) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false);
2553 if (!anObject.IsNull())
2554 _impl->RemoveObject(anObject);
2557 //=================================================================================
2558 // function : GetStringFromIOR()
2559 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
2560 //=================================================================================
2561 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject)
2563 return _orb->object_to_string(theObject);
2566 //=================================================================================
2567 // function : GetIORFromString()
2568 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
2569 //=================================================================================
2570 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
2571 GEOM::GEOM_Object_var aGeomObject;
2572 if(strcmp(stringIOR,"") != 0){
2573 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
2574 if(!CORBA::is_nil(anObject))
2575 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
2577 return aGeomObject._retn();
2580 //=================================================================================
2581 // function : GetObject()
2583 //=================================================================================
2584 GEOM::GEOM_BaseObject_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
2586 GEOM::GEOM_BaseObject_var obj;
2587 Handle(GEOM_BaseObject) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
2588 if (handle_object.IsNull()) return obj._retn();
2590 TCollection_AsciiString stringIOR = handle_object->GetIOR();
2591 if (stringIOR.Length() > 1) {
2592 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
2593 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_BaseObject::_narrow(corba_object);
2597 GEOM::GEOM_Gen_ptr engine = _this();
2598 //transfer the reference to GEOM_Object_i
2599 GEOM_BaseObject_i* servant = 0;
2600 switch( handle_object->GetType() ) {
2602 servant = new GEOM_Field_i (_poa, engine, Handle(GEOM_Field)::DownCast( handle_object ));
2605 case GEOM_FIELD_STEP: {
2606 Handle(GEOM_FieldStep) step = Handle(GEOM_FieldStep)::DownCast( handle_object );
2607 Handle(GEOM_Field) field = step->GetField();
2608 int type = ( !field.IsNull() ? field->GetDataType() : 0 );
2610 case GEOM::FDT_Bool:
2611 servant = new GEOM_BoolFieldStep_i (_poa, engine, step );
2614 servant = new GEOM_IntFieldStep_i (_poa, engine, step );
2616 case GEOM::FDT_Double:
2617 servant = new GEOM_DoubleFieldStep_i (_poa, engine, step );
2620 servant = new GEOM_StringFieldStep_i (_poa, engine, step );
2625 servant = new GEOM_Object_i (_poa, engine, Handle(GEOM_Object)::DownCast( handle_object ));
2627 PortableServer::ObjectId_var id = _poa->activate_object(servant);
2629 obj = servant->_this();
2630 CORBA::String_var objStr = _orb->object_to_string(obj);
2631 TCollection_AsciiString anAscii( (char *)objStr.in() );
2632 handle_object->SetIOR( anAscii );
2636 //=================================================================================
2637 // function : hasObjectInfo()
2638 // purpose : shows if module provides information for its objects
2639 //=================================================================================
2640 bool GEOM_Gen_i::hasObjectInfo()
2645 //=================================================================================
2646 // function : getObjectInfo()
2647 // purpose : returns an information for a given object by its entry
2648 //=================================================================================
2649 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
2651 GEOM::GEOM_Object_var aGeomObject;
2653 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
2654 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
2655 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
2656 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
2657 SALOMEDS::SObject_var aResultSObj;
2658 if (aSObj->ReferencedObject(aResultSObj))
2659 aSObj = aResultSObj;
2661 SALOMEDS::GenericAttribute_var anAttr;
2662 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
2663 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2664 CORBA::String_var aVal = anIOR->Value();
2665 anIOR->UnRegister();
2666 CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
2667 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
2669 if (!aSObj->_is_nil() )
2670 aSObj->UnRegister();
2672 const char* aTypeInfo = "Object";
2673 if ( !aGeomObject->_is_nil() ) {
2674 GEOM::GEOM_IKindOfShape::shape_kind aKind;
2675 GEOM::ListOfLong_var anInts;
2676 GEOM::ListOfDouble_var aDbls;
2678 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
2679 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
2681 if ( anOp->IsDone() ) {
2683 case GEOM::GEOM_IKindOfShape::COMPOUND:
2684 aTypeInfo = "Compound";
2686 case GEOM::GEOM_IKindOfShape::COMPSOLID:
2687 aTypeInfo = "CompSolid";
2689 case GEOM::GEOM_IKindOfShape::SHELL:
2690 aTypeInfo = "Shell";
2692 case GEOM::GEOM_IKindOfShape::WIRE:
2693 if ( anInts[0] == 1 )
2694 aTypeInfo = "Closed Wire";
2695 else if ( anInts[0] == 2 )
2696 aTypeInfo = "Opened Wire";
2701 case GEOM::GEOM_IKindOfShape::SPHERE:
2702 aTypeInfo = "Sphere";
2704 case GEOM::GEOM_IKindOfShape::CYLINDER:
2705 aTypeInfo = "Cylinder";
2707 case GEOM::GEOM_IKindOfShape::BOX:
2708 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
2711 case GEOM::GEOM_IKindOfShape::TORUS:
2712 aTypeInfo = "Torus";
2714 case GEOM::GEOM_IKindOfShape::CONE:
2717 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
2718 aTypeInfo = "Polyhedron";
2720 case GEOM::GEOM_IKindOfShape::SOLID:
2721 aTypeInfo = "Solid";
2724 case GEOM::GEOM_IKindOfShape::SPHERE2D:
2725 aTypeInfo = "Spherical Face";
2727 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
2728 aTypeInfo = "Cylindrical Face";
2730 case GEOM::GEOM_IKindOfShape::TORUS2D:
2731 aTypeInfo = "Toroidal Face";
2733 case GEOM::GEOM_IKindOfShape::CONE2D:
2734 aTypeInfo = "Conical Face";
2736 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
2739 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
2740 aTypeInfo = "Elliptical Face";
2742 case GEOM::GEOM_IKindOfShape::POLYGON:
2743 aTypeInfo = "Polygon";
2745 case GEOM::GEOM_IKindOfShape::PLANE:
2746 aTypeInfo = "Plane";
2748 case GEOM::GEOM_IKindOfShape::PLANAR:
2749 aTypeInfo = "Planar Face";
2751 case GEOM::GEOM_IKindOfShape::FACE:
2755 case GEOM::GEOM_IKindOfShape::CIRCLE:
2756 aTypeInfo = "Circle";
2758 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
2759 aTypeInfo = "Arc Circle";
2761 case GEOM::GEOM_IKindOfShape::ELLIPSE:
2762 aTypeInfo = "Ellipse";
2764 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
2765 aTypeInfo = "Arc Ellipse";
2767 case GEOM::GEOM_IKindOfShape::LINE:
2770 case GEOM::GEOM_IKindOfShape::SEGMENT:
2771 aTypeInfo = "Segment";
2773 case GEOM::GEOM_IKindOfShape::EDGE:
2776 case GEOM::GEOM_IKindOfShape::VERTEX:
2777 aTypeInfo = "Vertex";
2785 char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
2786 sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
2788 char* ret = CORBA::string_dup(anInfo);
2793 // Version information
2794 char* GEOM_Gen_i::getVersion()
2796 #if GEOM_DEVELOPMENT
2797 return CORBA::string_dup(GEOM_VERSION_STR"dev");
2799 return CORBA::string_dup(GEOM_VERSION_STR);
2803 //=================================================================================
2804 // function : CreateFolder()
2805 // purpose : Creates and returns a new folder object
2806 //=================================================================================
2807 SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName,
2808 SALOMEDS::SObject_ptr theFather)
2810 SALOMEDS::SObject_var aFolderSO;
2812 if ( CORBA::is_nil(theFather) ) return aFolderSO._retn();
2814 SALOMEDS::GenericAttribute_var anAttr;
2815 if ( strcmp(theFather->GetFatherComponent()->GetID(), theFather->GetID()) != 0 ) {
2816 // not a GEOM component object was selected
2817 if ( !theFather->FindAttribute(anAttr, "AttributeLocalID") ) return aFolderSO._retn();
2818 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2819 if( aLocalID->Value() != 999 ) {
2820 // not a Folder object was selected
2821 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow(theFather);
2822 if ( CORBA::is_nil(aGeomObject) ) return aFolderSO._retn();
2823 // another GEOM object was selected, so get GEOM component as father object
2824 theFather = theFather->GetFatherComponent();
2826 aLocalID->UnRegister();
2829 SALOMEDS::Study_var aStudy = theFather->GetStudy();
2830 SALOMEDS::StudyBuilder_var aStudyBuilder( aStudy->NewBuilder() );
2831 aFolderSO = aStudyBuilder->NewObject( theFather );
2833 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeLocalID");
2834 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2835 aLocalID->SetValue( 999 ); // mark of the "Folder" object
2836 aLocalID->UnRegister();
2838 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeName");
2839 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
2840 aName->SetValue( theName );
2841 aName->UnRegister();
2843 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributePixMap");
2844 SALOMEDS::AttributePixMap_var aPixMap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2845 aPixMap->SetPixMap("ICON_FOLDER");
2846 aPixMap->UnRegister();
2848 // add object to the use case tree
2849 // (to support tree representation customization and drag-n-drop)
2850 SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder();
2851 useCaseBuilder->AppendTo( theFather, aFolderSO );
2853 return aFolderSO._retn();
2856 //=================================================================================
2857 // function : MoveToFolder()
2858 // purpose : Moves GEOM object to the specified folder
2859 //=================================================================================
2860 void GEOM_Gen_i::MoveToFolder(GEOM::GEOM_Object_ptr theObject,
2861 SALOMEDS::SObject_ptr theFolder) {
2862 GEOM::object_list_var objects = new GEOM::object_list();
2863 objects->length( 1 );
2864 SALOMEDS::SObject_var aSO = theFolder->GetStudy()->FindObjectID( theObject->GetStudyEntry() );
2866 Move( objects, theFolder, -1 );
2869 //=================================================================================
2870 // function : MoveListToFolder()
2871 // purpose : Moves list of GEOM objects to the specified folder
2872 //=================================================================================
2873 void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO,
2874 SALOMEDS::SObject_ptr theFolder) {
2875 int aLen = theListOfGO.length();
2876 GEOM::object_list_var objects = new GEOM::object_list();
2877 objects->length( aLen );
2878 GEOM::GEOM_Object_var aGO;
2879 SALOMEDS::SObject_var aSO;
2880 for (int i = 0; i < aLen; i++) {
2881 aGO = GEOM::GEOM_Object::_duplicate( theListOfGO[i] );
2882 aSO = theFolder->GetStudy()->FindObjectID( aGO->GetStudyEntry() );
2885 if ( objects->length() > 0 )
2886 Move( objects, theFolder, -1 );
2889 //=================================================================================
2890 // function : Move()
2891 // purpose : Moves objects to the specified position.
2892 // Is used in the drag-n-drop functionality.
2893 //=================================================================================
2894 void GEOM_Gen_i::Move( const GEOM::object_list& what,
2895 SALOMEDS::SObject_ptr where,
2898 if ( CORBA::is_nil( where ) ) return;
2900 SALOMEDS::Study_var study = where->GetStudy();
2901 SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder();
2902 SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder();
2903 SALOMEDS::SComponent_var father = where->GetFatherComponent();
2904 std::string dataType = father->ComponentDataType();
2905 if ( dataType != "GEOM" ) return; // not a GEOM component
2907 SALOMEDS::SObject_var objAfter;
2908 if ( row >= 0 && useCaseBuilder->HasChildren( where ) ) {
2909 // insert at given row -> find insertion position
2910 SALOMEDS::UseCaseIterator_var useCaseIt = useCaseBuilder->GetUseCaseIterator( where );
2912 for ( i = 0; i < row && useCaseIt->More(); i++, useCaseIt->Next() );
2913 if ( i == row && useCaseIt->More() ) {
2914 objAfter = useCaseIt->Value();
2918 for ( int i = 0; i < what.length(); i++ ) {
2919 SALOMEDS::SObject_var sobj = what[i];
2920 if ( CORBA::is_nil( sobj ) ) continue; // skip bad object
2921 // insert the object to the use case tree
2922 if ( !CORBA::is_nil( objAfter ) )
2923 useCaseBuilder->InsertBefore( sobj, objAfter ); // insert at given row
2925 useCaseBuilder->AppendTo( where, sobj ); // append to the end of list
2929 //=================================================================================
2930 // function : importData
2931 // purpose : imports geometrical data file into the GEOM internal data structure
2932 //=================================================================================
2933 Engines::ListOfIdentifiers* GEOM_Gen_i::importData(
2934 CORBA::Long studyId, Engines::DataContainer_ptr data, const Engines::ListOfOptions& options)
2936 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
2937 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
2938 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
2940 Engines::ListOfIdentifiers_var aResult = new Engines::ListOfIdentifiers;
2941 GEOM::GEOM_IInsertOperations_var aInsOp = GetIInsertOperations(aStudy->StudyId());
2942 if (aInsOp->_is_nil()) {
2943 MESSAGE("No insert operations!");
2944 return aResult._retn();
2947 // Get a temporary directory to store a file
2948 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
2949 std::string aFileName("file");
2950 if (aFileName.rfind("/") != std::string::npos) { // remove folders from the name
2951 aFileName = aFileName.substr(aFileName.rfind("/") + 1);
2954 std::string anExtension(data->extension());
2955 aFileName += "." + anExtension;
2956 // convert extension to upper case
2957 std::transform(anExtension.begin(), anExtension.end(), anExtension.begin(), ::toupper);
2958 std::string aFullPath = aTmpDir + aFileName;
2960 Engines::TMPFile* aFileStream = data->get();
2961 const char *aBuffer = (const char*)aFileStream->NP_data();
2963 std::ofstream aFile(aFullPath.c_str(), std::ios::binary);
2965 std::ofstream aFile(aFullPath.c_str());
2967 aFile.write(aBuffer, aFileStream->length());
2970 GEOM::ListOfGBO_var aObjects = aInsOp->ImportFile(aFullPath.c_str(), "XAO");
2972 if ( aObjects->length() > 0 && aInsOp->IsDone() ) {
2973 aResult->length(aObjects->length());
2974 // publish main object (first in the list of returned geom objects)
2975 CORBA::String_var aName = aObjects[0]->GetName();
2976 SALOMEDS::SObject_var aSO = PublishInStudy(aStudy.in(), SALOMEDS::SObject::_nil(), aObjects[0].in(), aName.in());
2977 aResult[0] = aSO->GetID();
2978 // publish groups && fields
2979 for (int i = 1; i < aObjects->length(); i++ ) {
2980 aName = aObjects[i]->GetName();
2981 aSO = AddInStudy(aStudy.in(), aObjects[0].in(), aName.in(), aObjects[0].in());
2982 aResult[i] = aSO->GetID();
2986 if (aObjects->length() == 0)
2987 MESSAGE("ImportXAO operation is failed for file "<<aFullPath.c_str());
2988 if (!aInsOp->IsDone())
2989 MESSAGE("Import operation is not done for file "<<aFullPath.c_str());
2990 return aResult._retn();
2993 // remove temporary file and directory
2994 SALOMEDS::ListOfFileNames aTmpFiles;
2995 aTmpFiles.length(1);
2996 aTmpFiles[0] = aFileName.c_str();
2997 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aTmpFiles, true);
2999 _impl->DocumentModified(studyId, false);
3000 return aResult._retn();
3003 //=================================================================================
3004 // function : getModifiedData
3005 // purpose : exports all geometry of this GEOM module into one BRep file
3006 //=================================================================================
3007 Engines::ListOfData* GEOM_Gen_i::getModifiedData(CORBA::Long studyId)
3009 Engines::ListOfData_var aResult = new Engines::ListOfData;
3011 if (!_impl->DocumentModified(studyId)) {
3012 MESSAGE("Document is not modified")
3013 return aResult._retn();
3016 CORBA::Object_var aSMObject = name_service->Resolve("/myStudyManager");
3017 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
3018 if (CORBA::is_nil(aStudyManager))
3019 return aResult._retn();
3020 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
3021 if (CORBA::is_nil(aStudy))
3022 return aResult._retn();
3023 SALOMEDS::SComponent_var aComponent = aStudy->FindComponent("GEOM");
3024 if (CORBA::is_nil(aComponent))
3025 return aResult._retn();
3026 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(aComponent); // check only published shapes
3028 GEOM::GEOM_IInsertOperations_var aInsOp = GetIInsertOperations(aStudy->StudyId());
3029 if (aInsOp->_is_nil()) {
3030 MESSAGE("No insert operations!");
3031 return aResult._retn();
3034 GEOM::GEOM_Object_var shapeObj;
3036 for(; anIter->More(); anIter->Next()) {
3037 SALOMEDS::SObject_var aSO = anIter->Value();
3038 SALOMEDS::SObject_var aRefSO;
3039 // export only not referenced objects, or referenced outside of GEOM
3040 if (!aSO->ReferencedObject(aRefSO) || aRefSO->GetFatherComponent()->GetID() != aComponent->GetID()) {
3041 CORBA::Object_var anObj = aSO->GetObject();
3042 if (!CORBA::is_nil(anObj)) {
3043 GEOM::GEOM_Object_var aCORBAMainShape = GEOM::GEOM_Object::_narrow(anObj);
3044 if(!aCORBAMainShape->_is_nil()) {
3045 CORBA::String_var entry = aCORBAMainShape->GetEntry();
3046 Handle(GEOM_Object) aMainShape = Handle(GEOM_Object)::DownCast(_impl->GetObject(studyId, entry));
3048 GEOM::shape_type aCORBAShapeType = aCORBAMainShape->GetShapeType();
3049 if (!aMainShape.IsNull() && !(aCORBAShapeType == GEOM::VERTEX) && !(aCORBAShapeType == GEOM::EDGE)) {
3050 shapeObj = aCORBAMainShape;
3058 if (!CORBA::is_nil(shapeObj)) { // Shape is correct, write it to the temporary file
3059 std::string aPath = Kernel_Utils::GetTmpFileName() + ".xao";
3060 aInsOp->Export(shapeObj.in(), aPath.c_str(), "XAO");
3062 Engines::DataContainer_var aData = (new Engines_DataContainer_i(
3063 aPath.c_str(), "", "", true))->_this();
3066 MESSAGE("No shapes to export");
3069 return aResult._retn();
3072 //=======================================================================
3073 // function : GetDependencyTree
3074 // purpose : Collects dependencies of the given objects from other ones
3075 //=======================================================================
3076 SALOMEDS::TMPFile* GEOM_Gen_i::GetDependencyTree( SALOMEDS::Study_ptr theStudy,
3077 const GEOM::string_array& theObjectEntries ) {
3078 // fill in the tree structure
3079 GEOMUtils::TreeModel tree;
3082 for ( int i = 0; i < theObjectEntries.length(); i++ ) {
3083 // process objects one-by-one
3084 entry = theObjectEntries[i].in();
3085 GEOM::GEOM_BaseObject_var anObj = GetObject( theStudy->StudyId(), entry.c_str() );
3086 if ( anObj->_is_nil() )
3088 std::map< std::string, std::set<std::string> > passedEntries;
3089 GEOMUtils::LevelsList upLevelList;
3090 // get objects from which current one depends on recursively
3091 getUpwardDependency( anObj, upLevelList, passedEntries );
3092 GEOMUtils::LevelsList downLevelList;
3093 // get objects that depends on current one recursively
3094 getDownwardDependency( anObj, downLevelList, passedEntries );
3095 tree.insert( std::pair<std::string, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList> >(entry, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList>( upLevelList, downLevelList ) ) );
3098 // translation the tree into string
3099 std::string treeStr;
3100 GEOMUtils::ConvertTreeToString( tree, treeStr );
3102 // put string into stream
3103 char* aBuffer = (char*)CORBA::string_dup(treeStr.c_str());
3104 int aBufferSize = strlen((char*)aBuffer);
3106 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
3108 SALOMEDS::TMPFile_var aStream = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
3110 return aStream._retn();
3113 //=======================================================================
3114 // function : getUpwardDependency
3115 // purpose : Collects the entries of objects on that the given one depends
3116 //=======================================================================
3117 void GEOM_Gen_i::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
3118 GEOMUtils::LevelsList &upLevelList,
3119 std::map< std::string, std::set<std::string> > &passedEntries,
3121 std::string aGboEntry = gbo->GetEntry();
3122 GEOMUtils::NodeLinks anEntries;
3123 GEOMUtils::LevelInfo aLevelMap;
3125 if ( level-1 >= upLevelList.size() ) {
3127 upLevelList.push_back( aLevelMap );
3129 // get the existent map
3130 aLevelMap = upLevelList.at(level-1);
3131 if ( aLevelMap.count( aGboEntry ) > 0 ) {
3132 anEntries = aLevelMap[ aGboEntry ];
3136 // get objects on that the current one depends
3137 GEOM::ListOfGBO_var depList = gbo->GetDependency();
3138 std::string aDepEntry;
3139 for( int j = 0; j < depList->length(); j++ ) {
3140 if ( depList[j]->_is_nil() )
3142 aDepEntry = depList[j]->GetEntry();
3143 if ( passedEntries.count( aGboEntry ) > 0 &&
3144 passedEntries[aGboEntry].count( aDepEntry ) > 0 ) {
3145 //avoid checking the passed objects
3148 passedEntries[aGboEntry].insert( aDepEntry );
3150 anEntries.push_back( aDepEntry );
3152 // get dependencies recursively
3153 getUpwardDependency(depList[j], upLevelList, passedEntries, level+1);
3156 aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGboEntry, anEntries) );
3157 upLevelList[level-1] = aLevelMap;
3161 //=======================================================================
3162 // function : getDownwardDependency
3163 // purpose : Collects the entries of objects that depends on the given one
3164 //=======================================================================
3165 void GEOM_Gen_i::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
3166 GEOMUtils::LevelsList &downLevelList,
3167 std::map< std::string, std::set<std::string> > &passedEntries,
3169 std::string aGboEntry = gbo->GetEntry();
3170 Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument(gbo->GetStudyID());
3171 Handle(TDataStd_TreeNode) aNode, aRoot;
3172 Handle(GEOM_Function) aFunction;
3173 if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
3174 // go through the whole OCAF tree
3175 TDataStd_ChildNodeIterator Itr( aRoot );
3176 for (; Itr.More(); Itr.Next()) {
3177 aNode = Itr.Value();
3178 aFunction = GEOM_Function::GetFunction(aNode->Label());
3179 if (aFunction.IsNull()) {
3182 TDF_Label aLabel = aFunction->GetOwnerEntry();
3183 if(aLabel.IsNull()) continue;
3184 TCollection_AsciiString anEntry;
3185 TDF_Tool::Entry(aLabel, anEntry);
3186 GEOM::GEOM_BaseObject_var geomObj = GetObject( gbo->GetStudyID(), anEntry.ToCString() );
3187 if( CORBA::is_nil( geomObj ) )
3189 // get dependencies for current object in the tree
3190 GEOM::ListOfGBO_var depList = geomObj->GetDependency();
3191 if( depList->length() == 0 )
3193 std::string aGoEntry = geomObj->GetEntry();
3194 // go through dependencies of current object to check whether it depends on the given object
3195 for( int i = 0; i < depList->length(); i++ ) {
3196 if ( depList[i]->_is_nil() )
3198 if ( depList[i]->_is_equivalent( gbo ) ) {
3199 // yes, the current object depends on the given object
3200 if ( passedEntries.count( aGoEntry ) > 0 &&
3201 passedEntries[aGoEntry].count( aGboEntry ) > 0 ) {
3202 //avoid checking the passed objects
3205 passedEntries[aGoEntry].insert( aGboEntry );
3206 GEOMUtils::NodeLinks anEntries;
3207 GEOMUtils::LevelInfo aLevelMap;
3208 anEntries.push_back( aGboEntry );
3209 if ( level >= downLevelList.size() ) {
3210 downLevelList.push_back( aLevelMap );
3212 aLevelMap = downLevelList.at(level);
3213 if ( aLevelMap.count( aGoEntry ) > 0 ) {
3214 anEntries = aLevelMap[ aGoEntry ];
3217 aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGoEntry, anEntries) );
3218 downLevelList[level] = aLevelMap;
3219 // get dependencies of the current object recursively
3220 getDownwardDependency(geomObj, downLevelList, passedEntries, level+1);
3228 //==============================================================================
3229 // function : GetEntriesToReduceStudy
3230 // purpose : Fills 3 lists that is used to clean study of redundant objects
3231 //==============================================================================
3232 void GEOM_Gen_i::GetEntriesToReduceStudy(SALOMEDS::Study_ptr theStudy,
3233 GEOM::string_array& theSelectedEntries,
3234 GEOM::string_array& theParentEntries,
3235 GEOM::string_array& theSubEntries,
3236 GEOM::string_array& theOtherEntries)
3238 std::set<std::string> aSelected, aParents, aChildren, anOthers;
3239 for ( int i = 0; i < theSelectedEntries.length(); i++ ) {
3240 aSelected.insert( CORBA::string_dup( theSelectedEntries[i] ) );
3243 Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument(theStudy->StudyId());
3244 Handle(TDataStd_TreeNode) aNode, aRoot;
3245 Handle(GEOM_Function) aFunction;
3246 if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
3247 // go through the whole OCAF tree
3249 std::string anEntry;
3250 TCollection_AsciiString anAsciiEntry;
3251 TDataStd_ChildNodeIterator Itr( aRoot );
3252 for (; Itr.More(); Itr.Next()) {
3253 aNode = Itr.Value();
3254 aFunction = GEOM_Function::GetFunction(aNode->Label());
3255 if (aFunction.IsNull()) {
3258 aLabel = aFunction->GetOwnerEntry();
3261 TDF_Tool::Entry(aLabel, anAsciiEntry);
3262 anEntry = anAsciiEntry.ToCString();
3263 GEOM::GEOM_BaseObject_var geomObj = GetObject( theStudy->StudyId(), anEntry.c_str() );
3264 if( CORBA::is_nil( geomObj ) )
3267 if ( aSelected.count( anEntry ) > 0 &&
3268 aParents.count( anEntry ) == 0 ) {
3269 includeParentDependencies( geomObj, aSelected, aParents, aChildren, anOthers );
3270 } else if ( aParents.count( anEntry ) == 0 &&
3271 aChildren.count( anEntry ) == 0 ) {
3272 anOthers.insert( geomObj->GetEntry() );
3276 std::set<std::string>::iterator it;
3277 std::set<std::string>::iterator foundIt;
3278 TCollection_AsciiString stringIOR;
3279 GEOM::GEOM_Object_var geomObj;
3281 // filling list of sub-objects
3282 for ( it = aSelected.begin(); it != aSelected.end(); ++it ) {
3283 includeSubObjects( theStudy, *it, aSelected, aParents, aChildren, anOthers );
3286 // if some selected object is not a main shape,
3287 // we move it's main shapes into 'selected' list,
3288 // because they could not be modified anyhow.
3289 std::set<std::string> aToBeInSelected;
3290 for ( it = aSelected.begin(); it != aSelected.end(); ++it ) {
3291 Handle(GEOM_BaseObject) handle_object = _impl->GetObject( theStudy->StudyId(), (*it).c_str(), false);
3292 if ( handle_object.IsNull() )
3295 stringIOR = handle_object->GetIOR();
3296 if ( !stringIOR.Length() > 1 )
3299 geomObj = GetIORFromString( stringIOR.ToCString() );
3300 while ( !geomObj->IsMainShape() ) {
3301 geomObj = geomObj->GetMainShape();
3302 anEntry = geomObj->GetEntry();
3304 foundIt = aParents.find( anEntry );
3305 if ( foundIt != aParents.end() )
3306 aParents.erase( foundIt );
3308 foundIt = aChildren.find( anEntry );
3309 if ( foundIt != aChildren.end() )
3310 aChildren.erase( foundIt );
3312 foundIt = anOthers.find( anEntry );
3313 if ( foundIt != anOthers.end() )
3314 anOthers.erase( foundIt );
3316 aToBeInSelected.insert( anEntry );
3319 aSelected.insert( aToBeInSelected.begin(), aToBeInSelected.end() );
3321 // fill the CORBA arrays with values from sets
3323 theSelectedEntries.length( aSelected.size() );
3324 for ( i = 0, it = aSelected.begin(); it != aSelected.end(); ++it, i++ )
3325 theSelectedEntries[i] = CORBA::string_dup( (*it).c_str() );
3326 theParentEntries.length( aParents.size() );
3327 for ( i = 0, it = aParents.begin(); it != aParents.end(); ++it, i++ )
3328 theParentEntries[i] = CORBA::string_dup( (*it).c_str() );
3329 theSubEntries.length( aChildren.size() );
3330 for ( i = 0, it = aChildren.begin(); it != aChildren.end(); ++it, i++ )
3331 theSubEntries[i] = CORBA::string_dup( (*it).c_str() );
3332 theOtherEntries.length( anOthers.size() );
3333 for ( i = 0, it = anOthers.begin(); it != anOthers.end(); ++it, i++ )
3334 theOtherEntries[i] = CORBA::string_dup( (*it).c_str() );
3338 //==============================================================================
3339 // function : includeParentDependencies
3341 //==============================================================================
3342 void GEOM_Gen_i::includeParentDependencies(GEOM::GEOM_BaseObject_ptr geomObj,
3343 std::set<std::string>& aSelected,
3344 std::set<std::string>& aParents,
3345 std::set<std::string>& aChildren,
3346 std::set<std::string>& anOthers)
3348 std::string anEntry = geomObj->GetEntry();
3349 if ( aSelected.count( anEntry ) == 0 ) {
3350 aParents.insert( anEntry );
3351 std::set<std::string>::iterator it;
3352 it = aChildren.find( anEntry );
3353 if ( it != aChildren.end() )
3354 aChildren.erase( it );
3355 it = anOthers.find( anEntry );
3356 if ( it != anOthers.end() )
3357 anOthers.erase( it );
3359 // get dependencies for current object in the tree
3360 GEOM::ListOfGBO_var depList = geomObj->GetDependency();
3361 if( depList->length() == 0 )
3363 // go through dependencies of current object to check whether it depends on the given object
3364 std::string aDepEntry;
3365 for( int i = 0; i < depList->length(); i++ ) {
3366 aDepEntry = depList[i]->GetEntry();
3367 if ( depList[i]->_is_nil() ||
3368 aDepEntry == anEntry || // skip self-depending
3369 aSelected.count( aDepEntry ) > 0 || // skip selected objects
3370 aParents.count( aDepEntry ) > 0 // skip already processed objects
3373 includeParentDependencies( depList[i], aSelected, aParents, aChildren, anOthers );
3377 //==============================================================================
3378 // function : includeSubObjects
3380 //==============================================================================
3381 void GEOM_Gen_i::includeSubObjects(SALOMEDS::Study_ptr theStudy,
3382 const std::string& aSelectedEntry,
3383 std::set<std::string>& aSelected,
3384 std::set<std::string>& aParents,
3385 std::set<std::string>& aChildren,
3386 std::set<std::string>& anOthers)
3388 std::set<std::string>::iterator foundIt;
3389 Handle(GEOM_BaseObject) handle_object = _impl->GetObject( theStudy->StudyId(), aSelectedEntry.c_str(), false);
3390 if ( handle_object.IsNull() )
3393 Handle(GEOM_Function) aShapeFun = handle_object->GetFunction(1);
3394 if ( aShapeFun.IsNull() || !aShapeFun->HasSubShapeReferences() )
3397 const TDataStd_ListOfExtendedString& aListEntries = aShapeFun->GetSubShapeReferences();
3398 if ( aListEntries.IsEmpty() )
3401 TDataStd_ListIteratorOfListOfExtendedString anIt (aListEntries);
3402 for ( ; anIt.More(); anIt.Next() ) {
3403 TCollection_ExtendedString aSubEntry = anIt.Value();
3404 Standard_Integer aStrLen = aSubEntry.LengthOfCString();
3405 char* aSubEntryStr = new char[aStrLen+1];
3406 aSubEntry.ToUTF8CString( aSubEntryStr );
3407 foundIt = aParents.find( aSubEntryStr );
3408 if ( foundIt == aParents.end() ) { // add to sub-objects if it is not in parents list
3409 foundIt = aSelected.find( aSubEntryStr );
3410 if ( foundIt == aSelected.end() ) { // add to sub-objects if it is not in selected list
3411 aChildren.insert( aSubEntryStr );
3412 foundIt = anOthers.find( aSubEntryStr );
3413 if ( foundIt != anOthers.end() )
3414 anOthers.erase( foundIt );
3417 includeSubObjects( theStudy, aSubEntryStr, aSelected, aParents, aChildren, anOthers );
3420 //=====================================================================================
3422 //=====================================================================================
3427 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
3431 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb,
3432 PortableServer::POA_ptr poa,
3433 PortableServer::ObjectId* contId,
3434 const char* instanceName,
3435 const char* interfaceName)
3437 GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
3438 return myGEOM_Gen_i->getId();