1 // Copyright (C) 2007-2016 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>
62 #include <TDataStd_ChildNodeIterator.hxx>
63 #include <TDocStd_Owner.hxx>
64 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
66 #include <SALOMEDS_Tool.hxx>
67 #include <SALOMEDS_wrap.hxx>
68 #include <Basics_DirUtils.hxx>
81 #define LibHandle HMODULE
82 #define LoadLib( name ) LoadLibrary( name )
83 #define GetProc GetProcAddress
84 #define UnLoadLib( handle ) FreeLibrary( handle );
86 #define LibHandle void*
87 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
89 #define UnLoadLib( handle ) dlclose( handle );
92 //============================================================================
93 // function : GEOM_Gen_i()
94 // purpose : constructor to be called for servant creation.
95 //============================================================================
96 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
97 PortableServer::POA_ptr poa,
98 PortableServer::ObjectId* contId,
99 const char* instanceName,
100 const char* interfaceName) :
101 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
104 _id = _poa->activate_object(_thisObj);
105 name_service = new SALOME_NamingService(_orb);
107 _impl = new ::GEOMImpl_Gen;
109 //PAL10867: disable signals catching with "noexcepthandler" option
110 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
111 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
113 //work around PAL12004, PAL12628
114 //OSD::SetSignal( true );
115 bool raiseFPE = false;
116 #if defined(_DEBUG_) | defined(_DEBUG) //the Last for WIN32 default settings
117 char* envEnableFPE = getenv("ENABLE_FPE");
118 if (envEnableFPE && atoi(envEnableFPE))
121 OSD::SetSignal( raiseFPE );
124 GEOMUtils::PluginInfo plugins = GEOMUtils::ReadPluginInfo();
125 GEOMUtils::PluginInfo::const_iterator it;
126 for (it = plugins.begin(); it != plugins.end(); ++it)
129 LoadPlugin((*it).serverLib);
132 MESSAGE("Warning: can't load plugin library " << (*it).serverLib);
137 //============================================================================
138 // function : ~GEOM_Gen_i()
139 // purpose : destructor
140 //============================================================================
141 GEOM_Gen_i::~GEOM_Gen_i() {
144 std::map<std::string, GEOM_GenericOperationsCreator*>::const_iterator it;
145 for ( it = myOpCreatorMap.begin(); it != myOpCreatorMap.end(); ++it)
150 //============================================================================
151 // function : IORToLocalPersistentID()
153 //============================================================================
154 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
155 const char* IORString,
156 CORBA::Boolean isMultiFile,
157 CORBA::Boolean isASCII)
159 GEOM::GEOM_BaseObject_var anObject =
160 GEOM::GEOM_BaseObject::_narrow(_orb->string_to_object(IORString));
161 if (!CORBA::is_nil(anObject)) {
162 return CORBA::string_dup(anObject->GetEntry());
168 //============================================================================
169 // function : LocalPersistentIDToIOR()
170 // purpose : Create/Load CORBA object from a persistent ref (an entry)
171 // : Used when a study is loaded
172 // : The IOR (IORName) of object created is returned
173 //============================================================================
174 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
175 const char* aLocalPersistentID,
176 CORBA::Boolean isMultiFile,
177 CORBA::Boolean isASCII)
179 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
181 HANDLE_NAMESPACE(GEOM_BaseObject) anObject =
182 _impl->GetObject(aStudy->StudyId(), aLocalPersistentID);
183 if ( !anObject.IsNull() )
185 TCollection_AsciiString anEntry;
186 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
187 GEOM::GEOM_BaseObject_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
189 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
190 return CORBA::string_dup(aPersRefString);
194 return CORBA::string_dup("");
198 //============================================================================
199 // function : CanPublishInStudy
201 //============================================================================
202 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
204 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
205 return !(anObject->_is_nil());
209 //============================================================================
210 // function : PublishInStudy
212 //============================================================================
213 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
214 SALOMEDS::SObject_ptr theSObject,
215 CORBA::Object_ptr theObject,
217 throw (SALOME::SALOME_Exception)
219 Unexpect aCatch(SALOME_SalomeException);
220 SALOMEDS::SObject_var aResultSO;
221 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
222 GEOM::GEOM_BaseObject_var aBaseObj = GEOM::GEOM_BaseObject::_narrow(theObject);
223 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
224 if(aBaseObj->_is_nil()) return aResultSO;
226 SALOMEDS::GenericAttribute_var anAttr;
227 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
228 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = theStudy->GetUseCaseBuilder();
230 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
231 if (aFather->_is_nil()) {
232 aFather = aStudyBuilder->NewComponent("GEOM");
233 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
234 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
235 aName->SetValue("Geometry");
237 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
238 SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr);
239 aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry");
240 aPixMap->UnRegister();
241 aStudyBuilder->DefineComponentInstance(aFather, (GEOM::GEOM_Gen_var)GEOM_Gen::_this());
242 // add component to the use case tree
243 // (to support tree representation customization and drag-n-drop)
244 useCaseBuilder->SetRootCurrent();
245 useCaseBuilder->Append( aFather ); // component object is added as the top level item
247 if (aFather->_is_nil()) return aResultSO;
249 if (CORBA::is_nil(theSObject)) {
250 aResultSO = aStudyBuilder->NewObject(aFather);
252 if (!theSObject->ReferencedObject(aResultSO))
253 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
254 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
256 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
257 aResultSO->SetAttrString("AttributeIOR",aGeomObjIOR);
259 TCollection_AsciiString anObjectName, aNamePrefix("Shape_");
260 CORBA::Long mytype=aBaseObj->GetType();
262 // BEGIN: try to find existed name for current shape
263 if ( !aShape->_is_nil() && mytype != GEOM_GROUP)
265 // recieve current TopoDS shape
266 CORBA::String_var entry = aShape->GetEntry();
267 HANDLE_NAMESPACE(GEOM_Object) aGShape = HANDLE_NAMESPACE(GEOM_Object)::DownCast
268 ( _impl->GetObject( aShape->GetStudyID(), entry ));
269 TopoDS_Shape TopoSh = aGShape->GetValue();
270 // find label of main shape
271 GEOM::GEOM_Object_var aMainSh = aShape;
272 while( !aMainSh->IsMainShape() ) {
273 aMainSh = aMainSh->GetMainShape();
275 entry = aMainSh->GetEntry();
276 HANDLE_NAMESPACE(GEOM_BaseObject) anObj = _impl->GetObject( aMainSh->GetStudyID(), entry );
277 TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry();
279 // check all named shapes using iterator
280 TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
282 for (; anIt.More() && anObjectName.IsEmpty(); anIt.Next()) {
283 Handle(TNaming_NamedShape) anAttr =
284 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
285 if (anAttr.IsNull()) continue;
286 TopoDS_Shape S = anAttr->Get();
287 if (S.IsEqual(TopoSh)) {
288 TDF_Label L = anAttr->Label();
289 Handle(TDataStd_Name) aName;
290 if (L.FindAttribute(TDataStd_Name::GetID(), aName))
291 anObjectName = aName->Get();
295 // END: try to find existed name for current shape
297 if ( mytype == GEOM_GROUP ) {
298 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
299 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape )) {
301 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_PNT" );
302 aNamePrefix = "Group_Of_Vertices_";
305 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_EDGE");
306 aNamePrefix = "Group_Of_Edges_";
309 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_FACE");
310 aNamePrefix = "Group_Of_Faces_";
313 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_SOLID");
314 aNamePrefix = "Group_Of_Solids_";
317 } else if ( mytype == GEOM_MARKER ) {
318 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS");
319 aNamePrefix = "LocalCS_";
320 } else if ( mytype >= USER_TYPE_EX ) {
322 sprintf( buf, "%d", aBaseObj->GetType() );
323 GEOM::CreationInformationSeq_var infoSeq = aBaseObj->GetCreationInformation();
325 for ( size_t j = 0; j < infoSeq->length(); ++j )
326 for ( size_t i = 0; i < infoSeq[j].params.length(); ++i ) {
327 std::string param_name = infoSeq[j].params[i].name.in();
328 std::string param_value = infoSeq[j].params[i].value.in();
329 if( param_name == PLUGIN_NAME) {
334 if(plgId.length() > 0 ) {
337 plgId +="ICON_OBJBROWSER_";
339 aResultSO->SetAttrString("AttributePixMap",plgId.c_str());
340 } else if ( mytype > USER_TYPE ) {
342 sprintf( buf, "%d", aBaseObj->GetType() );
343 std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf;
344 aResultSO->SetAttrString("AttributePixMap",advId.c_str());
345 aNamePrefix = "Advanced_";
346 } else if ( mytype == GEOM_FIELD ) {
347 aNamePrefix = "Field_";
348 GEOM::GEOM_Field_var aField = GEOM::GEOM_Field::_narrow(theObject);
349 if ( !aField->_is_nil() )
350 switch( aField->GetDimension() ) {
352 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_PNT" ); break;
354 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_EDGE"); break;
356 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_FACE"); break;
358 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID"); break;
360 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID");
362 } else if ( mytype == GEOM_FIELD_STEP ) {
363 aNamePrefix = "Step_";
364 } else if ( !aShape->_is_nil() ) {
365 GEOM::shape_type myshapetype=aShape->GetShapeType();
366 if ( myshapetype == GEOM::COMPOUND ) {
367 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPOUND" );
368 aNamePrefix = "Compound_";
369 } else if ( myshapetype == GEOM::COMPSOLID ) {
370 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPSOLID");
371 aNamePrefix = "Compsolid_";
372 } else if ( myshapetype == GEOM::SOLID ) {
373 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SOLID");
374 aNamePrefix = "Solid_";
375 } else if ( myshapetype == GEOM::SHELL ) {
376 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SHELL");
377 aNamePrefix = "Shell_";
378 } else if ( myshapetype == GEOM::FACE ) {
379 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FACE");
380 aNamePrefix = "Face_";
381 } else if ( myshapetype == GEOM::WIRE ) {
382 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_WIRE");
383 aNamePrefix = "Wire_";
384 } else if ( myshapetype == GEOM::EDGE ) {
385 aResultSO->SetAttrString("AttributePixMap", "ICON_OBJBROWSER_EDGE");
386 aNamePrefix = "Edge_";
387 } else if ( myshapetype == GEOM::VERTEX ) {
388 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_VERTEX" );
389 aNamePrefix = "Vertex_";
392 if ( anObjectName.IsEmpty() )
394 //if (strlen(theName) == 0) aNamePrefix += TCollection_AsciiString(aResultSO->Tag());
395 //else anObjectName = TCollection_AsciiString(CORBA::string_dup(theName));
397 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
398 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
399 // of objects in the study, but compute a number of objects with the same prefix
400 // and build a new name as Prefix_N+1
401 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
402 int i = 0; // (WITH EMPTY NEW NAME)
403 SALOMEDS::SObject_var obj;
405 anObjectName = aNamePrefix + TCollection_AsciiString(++i);
406 obj = theStudy->FindObject( anObjectName.ToCString() );
408 while ( !obj->_is_nil() );
410 else { // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
411 anObjectName = theName;
415 //Set the study entry as a name of the published GEOM_Object
416 CORBA::String_var anID = aResultSO->GetID();
417 aBaseObj->SetStudyEntry(anID.in());
419 //Set a name of the added shape
420 aResultSO->SetAttrString("AttributeName",anObjectName.ToCString());
422 //Set NoteBook variables used in the object creation
423 TCollection_AsciiString aVars;
424 CORBA::String_var aString=aBaseObj->GetParameters();
425 SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aString);
426 for(int i = 0, n = aSections->length(); i < n; i++) {
427 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
428 for(int j = 0, m = aListOfVars.length(); j < m; j++) {
429 if(theStudy->IsVariable(aListOfVars[j].in()))
430 aVars += aListOfVars[j].in();
437 aResultSO->SetAttrString("AttributeString",aVars.ToCString());
439 aFather->UnRegister();
441 //Set a name of the GEOM object
442 aBaseObj->SetName(anObjectName.ToCString());
444 // add object to the use case tree
445 // (to support tree representation customization and drag-n-drop)
446 useCaseBuilder->AppendTo( aResultSO->GetFather(), aResultSO );
448 return aResultSO._retn();
451 //============================================================================
452 // function : CreateAndPublishGroup
453 // purpose : auxilary for PublishNamedShapesInStudy
454 //============================================================================
455 void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
456 GEOM::GEOM_Object_var theMainShape,
457 const TopTools_IndexedMapOfShape& anIndices,
458 const TopTools_SequenceOfShape& SeqS,
459 const TColStd_SequenceOfAsciiString& SeqN,
460 const Standard_CString& GrName,
461 GEOM::ListOfGO_var aResList)
463 CORBA::String_var entry = theMainShape->GetEntry();
464 //HANDLE_NAMESPACE(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
465 Handle(TColStd_HArray1OfInteger) anArray;
466 if(SeqS.Length()>0) {
468 GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId());
469 GEOM::GEOM_Object_wrap GrObj = GOp->CreateGroup( theMainShape, SeqS(1).ShapeType() );
470 AddInStudy(theStudy, GrObj, GrName, theMainShape._retn());
471 //CORBA::String_var GrEntry = GrObj->GetEntry();
472 //HANDLE_NAMESPACE(GEOM_Object) HGrObj = _impl->GetObject(GrObj->GetStudyID(), GrEntry);
474 //HANDLE_NAMESPACE(GEOM_Object) anObj;
475 for(int i=1; i<=SeqS.Length(); i++) {
476 TopoDS_Shape aValue = SeqS.Value(i);
477 //anArray = new TColStd_HArray1OfInteger(1,1);
478 Standard_Integer anIndex = anIndices.FindIndex(aValue);
479 //anArray->SetValue(1, anIndex);
480 GOp->AddObject(GrObj,anIndex);
481 //anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE);
482 //if (anObj.IsNull()) continue;
483 //HANDLE_NAMESPACE(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
484 //if (aFunction.IsNull()) continue;
485 //GEOM_ISubShape aSSI(aFunction);
486 //aSSI.SetMainShape(aMainShape->GetLastFunction());
487 //aSSI.SetIndices(anArray);
488 //aFunction->SetValue(aValue);
489 //GOp->UnionIDs(GrObj, anIndex);
490 //SALOMEDS::SObject_var aResultSO;
491 //TCollection_AsciiString anEntry;
492 //TDF_Tool::Entry(anObj->GetEntry(),anEntry);
493 //GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString());
494 //AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
500 //============================================================================
501 // function : PublishNamedShapesInStudy
503 //============================================================================
504 GEOM::ListOfGO* GEOM_Gen_i::
505 PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
506 //SALOMEDS::SObject_ptr theSObject,
507 CORBA::Object_ptr theObject)
509 //Unexpect aCatch(SALOME_SalomeException);
510 GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
512 //CORBA::Object_var theObject = theSObject->GetObject();
513 GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
514 if(theMainShape->_is_nil()) return aResList._retn();
516 CORBA::String_var entry = theMainShape->GetEntry();
517 HANDLE_NAMESPACE(GEOM_Object) aMainShape = HANDLE_NAMESPACE(GEOM_Object)::DownCast
518 ( _impl->GetObject( theMainShape->GetStudyID(), entry ));
519 if (aMainShape.IsNull()) return aResList._retn();
520 TopoDS_Shape MainSh = aMainShape->GetValue();
522 TDF_Label aMainLbl = aMainShape->GetEntry();
523 TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
524 TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
525 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
526 for(; anIt.More(); anIt.Next()) {
527 Handle(TNaming_NamedShape) anAttr =
528 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
529 if(anAttr.IsNull()) continue;
530 TopoDS_Shape S = anAttr->Get();
531 TDF_Label L = anAttr->Label();
532 //if(S.IsEqual(MainSh)) continue;
533 Handle(TDataStd_Name) aName;
534 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
535 TCollection_ExtendedString EName = aName->Get();
536 if(S.ShapeType()==TopAbs_SOLID) {
538 SolidSeqN.Append(aName->Get());
540 else if(S.ShapeType()==TopAbs_FACE) {
542 FaceSeqN.Append(aName->Get());
544 else if(S.ShapeType()==TopAbs_EDGE) {
546 EdgeSeqN.Append(aName->Get());
548 else if(S.ShapeType()==TopAbs_VERTEX) {
550 VertSeqN.Append(aName->Get());
555 TopTools_IndexedMapOfShape anIndices;
556 TopExp::MapShapes(MainSh, anIndices);
558 CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN,
559 "Group_Of_Named_Solids", aResList);
561 CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN,
562 "Group_Of_Named_Faces", aResList);
564 CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
565 "Group_Of_Named_Edges", aResList);
567 CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN,
568 "Group_Of_Named_Vertices", aResList);
570 return aResList._retn();
574 //============================================================================
576 // purpose : save OCAF/Geom document
577 //============================================================================
578 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
581 SALOMEDS::TMPFile_var aStreamFile;
582 // Get a temporary directory to store a file
583 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
585 // OCCT BUG: cannot save a document (in current folder)
586 // if directory name is empty
587 if (aTmpDir.size() == 0) {
595 // Create a list to store names of created files
596 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
598 // Prepare a file name to open
599 TCollection_AsciiString aNameWithExt("");
601 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
602 (theComponent->GetStudy()->URL())).c_str());
603 #if OCC_VERSION_MAJOR > 6
604 aNameWithExt += TCollection_AsciiString("_GEOM.cbf");
606 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
608 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
609 // Build a full file name of temporary file
610 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
611 // Save GEOM component in this file
612 _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
613 // Conver a file to the byte stream
614 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
615 // Remove the created file and tmp directory
616 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
618 // Return the created byte stream
619 return aStreamFile._retn();
623 //============================================================================
624 // function : SaveASCII()
626 //============================================================================
627 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
630 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
631 return aStreamFile._retn();
635 //============================================================================
638 //============================================================================
639 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
640 const SALOMEDS::TMPFile& theStream,
644 if (theStream.length() <= 9) {
645 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
649 // Get a temporary directory for a file
650 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
652 // OCCT BUG: cannot load a document (from current folder)
653 // if directory name is empty
654 if (aTmpDir.size() == 0) {
662 // Conver the byte stream theStream to a file and place it in tmp directory
663 SALOMEDS::ListOfFileNames_var aSeq =
664 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
666 // Prepare a file name to open
667 TCollection_AsciiString aNameWithExt("");
668 SALOMEDS::Study_var study = theComponent->GetStudy();
670 #if OCC_VERSION_MAJOR > 6
671 // Get the file name.
673 int aLength = aSeq->length();
674 const char *aGeomSgd = "_GEOM.sgd";
675 const char *aGeomcbf = "_GEOM.cbf";
677 for(i = 0; i < aLength; i++) {
678 std::string aName(aSeq[i]);
680 if (aName.rfind(aGeomSgd) != std::string::npos ||
681 aName.rfind(aGeomcbf) != std::string::npos) {
682 aNameWithExt = aName.c_str();
688 CORBA::String_var url = study->URL();
689 aNameWithExt = (char*)SALOMEDS_Tool::GetNameFromPath(url.in()).c_str();
692 aNameWithExt += "_GEOM.sgd";
695 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
698 if (!_impl->Load(study->StudyId(),(char*) aFullName.ToCString())) return false;
700 // Remove the created file and tmp directory
701 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
703 // creation of tree nodes for all data objects in the study
704 // to support tree representation customization and drag-n-drop:
705 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = study->GetUseCaseBuilder();
706 if ( !useCaseBuilder->IsUseCaseNode( theComponent ) ) {
707 useCaseBuilder->SetRootCurrent();
708 useCaseBuilder->Append( theComponent ); // component object is added as the top level item
711 SALOMEDS::ChildIterator_wrap it = study->NewChildIterator( theComponent );
712 for ( it->InitEx(true); it->More(); it->Next() ) {
713 if ( !useCaseBuilder->IsUseCaseNode( it->Value() ) ) {
714 useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() );
722 //============================================================================
723 // function : LoadASCII()
725 //============================================================================
726 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
727 const SALOMEDS::TMPFile& theStream,
730 return Load(theComponent, theStream, theURL, isMultiFile);
734 //============================================================================
735 // function : Close()
737 //============================================================================
738 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
740 SALOMEDS::Study_var aStudy= theComponent->GetStudy();
741 _impl->Close(aStudy->StudyId());
744 //============================================================================
745 // function : CanCopy()
747 //============================================================================
748 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
749 // Try to retrieve known by Geometry component GEOM_Object by given IOR
750 SALOMEDS::GenericAttribute_var anAttr;
751 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
753 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
755 CORBA::String_var aString=anIOR->Value();
757 CORBA::Object_var anObj = _orb->string_to_object(aString);
758 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(anObj);
759 // If the object is null one it can't be copied: return false
760 if (anObject->_is_nil()) return false;
764 //============================================================================
765 // function : CopyFrom()
767 //============================================================================
768 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
770 // Declare a sequence of the byte to store the copied object
771 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
773 // Try to get GEOM_Object object by given SObject
774 SALOMEDS::GenericAttribute_var anAttr;
775 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
776 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
777 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
778 if (anObject->_is_nil()) return aStreamFile._retn();
780 aStreamFile = anObject->GetShapeStream();
782 // Assign an ID the type of GEOM_Object
783 theObjectID = anObject->GetType();
785 // Return created TMPFile
786 return aStreamFile._retn();
789 //============================================================================
790 // function : CanPaste()
792 //============================================================================
793 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
794 // The Geometry component can paste only objects copied by Geometry component
795 // and with the object type = 1
796 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
800 //============================================================================
801 // function : PasteInto()
803 //============================================================================
804 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
805 CORBA::Long theObjectID,
806 SALOMEDS::SObject_ptr theObject) {
807 // Find the current Study and StudyBuilder
808 SALOMEDS::Study_var aStudy = theObject->GetStudy();
809 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
810 SALOMEDS::UseCaseBuilder_var anUseCaseBuilder = aStudy->GetUseCaseBuilder();
811 SALOMEDS::SObject_var aNewSO;
812 // Retrieve a TopoDS_Shape from byte stream
813 TopoDS_Shape aTopology;
814 std::istringstream aStreamedBrep((char*) &theStream[0]);
815 BRep_Builder aBuilder;
817 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
818 } catch (Standard_Failure) {
819 return aNewSO._retn();
822 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
823 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
824 aNewSO = aStudyBuilder->NewObject(theObject);
825 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
828 //Create a new GEOM_Object
829 HANDLE_NAMESPACE(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
830 HANDLE_NAMESPACE(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
831 aFunction->SetValue(aTopology);
833 TCollection_AsciiString anEntry;
834 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
835 GEOM::GEOM_BaseObject_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
837 //Set the study entry of the published GEOM_Object
838 obj->SetStudyEntry(aNewSO->GetID());
840 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
841 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
842 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
843 CORBA::String_var objStr = _orb->object_to_string(obj);
844 anIOR->SetValue(objStr.in());
847 // add object to the use case tree
848 // (to support tree representation customization and drag-n-drop)
849 anUseCaseBuilder->AppendTo( aNewSO->GetFather(), aNewSO );
851 // Return the created in the Study SObject
852 return aNewSO._retn();
855 //============================================================================
856 // function : ComponentDataType()
858 //============================================================================
859 char* GEOM_Gen_i::ComponentDataType()
861 return CORBA::string_dup("GEOM");
864 //============================================================================
865 // function : AddInStudy
867 //============================================================================
868 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
869 GEOM::GEOM_BaseObject_ptr theObject,
871 GEOM::GEOM_BaseObject_ptr theFather)
873 SALOMEDS::SObject_var aResultSO;
874 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
876 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
877 CORBA::String_var IOR;
879 if(!theFather->_is_nil()) {
880 IOR = _orb->object_to_string(theFather);
881 SALOMEDS::SObject_wrap aFatherSO = theStudy->FindObjectIOR(IOR.in());
882 if(aFatherSO->_is_nil()) return aResultSO._retn();
883 aResultSO = aStudyBuilder->NewObject(aFatherSO);
884 //aStudyBuilder->Addreference(aResultSO, aResultSO);
887 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
888 if(aResultSO->_is_nil()) return aResultSO._retn();
890 GEOM::ListOfGBO_var aList = theObject->GetDependency();
891 Standard_Integer aLength = aList->length();
892 if(aLength < 1) return aResultSO._retn();
894 //Publish the arguments
895 TCollection_AsciiString aPrevID; // to avoid multiple references to same object
896 for(Standard_Integer i = 0; i< aLength; i++) {
897 GEOM::GEOM_BaseObject_var anObject = aList[i];
898 if(anObject->_is_nil()) continue;
899 IOR = _orb->object_to_string(anObject);
900 SALOMEDS::SObject_wrap aSO = theStudy->FindObjectIOR(IOR.in());
901 if(aSO->_is_nil()) continue;
902 CORBA::String_var anID = aSO->GetID();
903 if ( aPrevID == anID.in() ) continue;
905 SALOMEDS::SObject_wrap aSubSO = aStudyBuilder->NewObject(aResultSO);
906 aStudyBuilder->Addreference(aSubSO, aSO);
907 theStudy->GetUseCaseBuilder()->AppendTo( aResultSO, aSubSO );
910 return aResultSO._retn();
913 //============================================================================
914 // function : RestoreSubShapesO
915 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
916 // To be used from python scripts out of geompy.addToStudy (non-default usage)
917 //============================================================================
918 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
919 GEOM::GEOM_Object_ptr theObject,
920 const GEOM::ListOfGO& theArgs,
921 GEOM::find_shape_method theFindMethod,
922 CORBA::Boolean theInheritFirstArg,
923 CORBA::Boolean theAddPrefix)
925 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
926 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
927 return aParts._retn();
929 // find SObject in the study if it is already published
930 CORBA::String_var anIORo = _orb->object_to_string(theObject);
931 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
932 //PTv, IMP 0020001, The salome object <aSO>
933 // is not obligatory in case of invokation from script
934 // if (CORBA::is_nil(aSO))
935 // return aParts._retn();
937 aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs,
938 theFindMethod, theInheritFirstArg, theAddPrefix);
939 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
940 return aParts._retn();
943 //============================================================================
944 // function : RestoreGivenSubShapesO
945 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
946 // To be used from python scripts, generated by Dump Python.
947 //============================================================================
948 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (SALOMEDS::Study_ptr theStudy,
949 GEOM::GEOM_Object_ptr theObject,
950 const GEOM::ListOfGO& theArgs,
951 GEOM::find_shape_method theFindMethod,
952 CORBA::Boolean theInheritFirstArg,
953 CORBA::Boolean theAddPrefix)
955 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
956 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
957 return aParts._retn();
959 // find SObject in the study if it is already published
960 CORBA::String_var anIORo = _orb->object_to_string(theObject);
961 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
962 //PTv, IMP 0020001, The salome object <aSO>
963 // is not obligatory in case of invokation from script
964 // if (CORBA::is_nil(aSO))
965 // return aParts._retn();
967 aParts = RestoreGivenSubShapes(theStudy, theObject, aSO, theArgs,
968 theFindMethod, theInheritFirstArg, theAddPrefix);
969 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
970 return aParts._retn();
973 //============================================================================
974 // function : RestoreSubShapesSO
975 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
976 // To be used from GUI and from geompy.addToStudy
977 //============================================================================
978 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
979 SALOMEDS::SObject_ptr theSObject,
980 const GEOM::ListOfGO& theArgs,
981 GEOM::find_shape_method theFindMethod,
982 CORBA::Boolean theInheritFirstArg,
983 CORBA::Boolean theAddPrefix)
985 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
986 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
987 return aParts._retn();
989 SALOMEDS::GenericAttribute_var anAttr;
990 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
991 return aParts._retn();
993 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
994 CORBA::String_var anIORso = anAttrIOR->Value();
996 // get Object from SObject
997 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
998 if (CORBA::is_nil(anO))
999 return aParts._retn();
1001 aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs,
1002 theFindMethod, theInheritFirstArg, theAddPrefix);
1003 return aParts._retn();
1006 //============================================================================
1007 // function : addToListOfGO
1008 // purpose : static local function
1009 //============================================================================
1010 static void addToListOfGO( GEOM::GEOM_Object_ptr theObject,
1011 GEOM::ListOfGO& theList )
1013 const int oldLen = theList.length();
1014 theList.length(oldLen + 1);
1015 theList[ oldLen ] = GEOM::GEOM_Object::_duplicate( theObject );
1018 //============================================================================
1019 // function : addToListOfGO
1020 // purpose : static local function
1021 //============================================================================
1022 static void addToListOfGO( const GEOM::ListOfGO& theSrcList,
1023 GEOM::ListOfGO& theTrgList )
1025 const int oldLen = theTrgList.length();
1026 const int srcLen = theSrcList.length();
1027 theTrgList.length(oldLen + srcLen);
1028 for( int i = 0; i < srcLen; i++ )
1029 theTrgList[ oldLen + i ] = GEOM::GEOM_Object::_duplicate( theSrcList[ i ] );
1032 //============================================================================
1033 // function : RestoreSubShapes
1034 // purpose : Private method. Works only if both theObject and theSObject
1035 // are defined, and does not check, if they correspond to each other.
1036 //============================================================================
1037 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy,
1038 GEOM::GEOM_Object_ptr theObject,
1039 SALOMEDS::SObject_ptr theSObject,
1040 const GEOM::ListOfGO& theArgs,
1041 GEOM::find_shape_method theFindMethod,
1042 CORBA::Boolean theInheritFirstArg,
1043 CORBA::Boolean theAddPrefix)
1045 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1046 //PTv, IMP 0020001, The salome object <theSObject>
1047 // is not obligatory in case of invokation from script
1048 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
1049 return aParts._retn();
1051 // For Dump Python (mantis issue 0020768)
1052 GEOM::ListOfGO_var anOutArgs = new GEOM::ListOfGO;
1054 // Arguments to be published
1055 GEOM::ListOfGO_var aList;
1057 // If theArgs list is empty, we try to publish all arguments,
1058 // otherwise publish only passed args
1059 Standard_Integer nbArgsActual = -1; // -1 means unknown
1060 Standard_Integer aLength = theArgs.length();
1062 aList = new GEOM::ListOfGO;
1063 aList->length(aLength);
1064 for (int i = 0; i < aLength; i++) {
1065 aList[i] = GEOM::GEOM_Object::_duplicate( theArgs[i] );
1069 // Get all arguments
1070 GEOM::ListOfGBO_var boList = theObject->GetDependency();
1071 aLength = boList->length();
1072 aList = new GEOM::ListOfGO;
1073 aList->length(aLength);
1074 for (int i = 0; i < aLength; i++)
1075 aList[i] = GEOM::GEOM_Object::_narrow( boList[i] );
1076 nbArgsActual = aLength;
1080 return aParts._retn();
1082 if (theInheritFirstArg || (nbArgsActual == 1)) {
1083 // Do not publish argument's reflection,
1084 // but only reconstruct its published sub-shapes
1086 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1087 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1089 // remember restored objects for Python Dump
1090 addToListOfGO(aList[0], anOutArgs);
1092 aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
1093 anOutArgs, theFindMethod, theAddPrefix);
1095 // set the color of the transformed shape to the color of initial shape
1096 theObject->SetColor(aList[0]->GetColor());
1098 if (theObject->GetShapeType() == GEOM::VERTEX) {
1099 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1100 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1101 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1104 anArgSO->UnRegister();
1107 // Get interface, containing method, which we will use to reconstruct sub-shapes
1108 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1109 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1110 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1112 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1113 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1115 // Reconstruct arguments and tree of sub-shapes of the arguments
1116 CORBA::String_var anIOR;
1117 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1118 for (Standard_Integer i = 0; i < aLength; i++)
1120 GEOM::GEOM_Object_var anArgO = aList[i];
1121 if (!CORBA::is_nil(anArgO)) {
1122 anIOR = _orb->object_to_string(anArgO);
1123 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1124 TCollection_AsciiString anArgName;
1125 if (CORBA::is_nil(anArgSO)) {
1127 anArgName += TCollection_AsciiString(i);
1130 anArgName = anArgSO->GetName();
1133 // Find a sub-shape of theObject in place of the argument
1134 GEOM::GEOM_Object_var aSubO;
1135 switch (theFindMethod) {
1136 case GEOM::FSM_GetInPlace:
1139 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1142 case GEOM::FSM_MultiTransformed:
1144 // Only for Multi-transformations
1145 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1146 if (!CORBA::is_nil(anArgOTrsf)) {
1147 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1148 HANDLE_NAMESPACE(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1149 HANDLE_NAMESPACE(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1150 anArgOTrsfFun->SetDescription("");
1151 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1154 HANDLE_NAMESPACE(GEOM_Function) anOFun = theObject->GetLastFunction();
1155 if (!anOFun.IsNull()) {
1156 CORBA::String_var entryArg = anArgO->GetEntry();
1157 HANDLE_NAMESPACE(GEOM_Object) anArgOImpl = _impl->GetObject(anArgO->GetStudyID(), entryArg);
1158 if (!anArgOImpl.IsNull()) {
1159 TopoDS_Shape anArgOShape = anArgOImpl->GetValue();
1160 TopoDS_Shape aMultiArgShape;
1161 //GEOM::GEOM_Object_var anArgOMulti; // ???
1162 switch (anOFun->GetType()) {
1165 GEOMImpl_ITranslate aTI (anOFun);
1166 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape1D(anArgOShape, &aTI);
1167 //anArgOMulti = aTrsfOpSv->Translate1D(anArgO, , , );
1172 GEOMImpl_ITranslate aTI (anOFun);
1173 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1178 GEOMImpl_IRotate aTI (anOFun);
1179 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1184 GEOMImpl_IRotate aTI (anOFun);
1185 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1191 GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO
1192 HANDLE_NAMESPACE(GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction();
1193 anArgOMultiFun->SetDescription("");
1194 aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti);
1200 case GEOM::FSM_Transformed:
1202 // transformation, cannot use GetInPlace, operate with indices
1203 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1204 if (anIDs->length() > 1) {
1206 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1207 if (!CORBA::is_nil(aSubO))
1208 aGroupOp->UnionIDs(aSubO, anIDs);
1210 else if (anIDs->length() > 0) {
1212 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1216 case GEOM::FSM_GetSame:
1219 aSubO = aShapesOp->GetSame(theObject, anArgO);
1222 case GEOM::FSM_GetShapesOnShape:
1224 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1225 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1226 (short)GEOM::SOLID, GEOM::ST_ONIN);
1229 case GEOM::FSM_GetInPlaceByHistory:
1231 // Use GetInPlaceByHistory
1232 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1239 if (!CORBA::is_nil(aSubO)) {
1240 // remember restored objects for Python Dump
1241 addToListOfGO(anArgO, anOutArgs);
1243 // add to parts list
1244 addToListOfGO( aSubO, aParts );
1246 // Publish the sub-shape
1247 SALOMEDS::SObject_var aSubSO;
1248 if (!CORBA::is_nil(theSObject)) {
1249 TCollection_AsciiString aSubName;
1253 aSubName += anArgName;
1254 aSubSO = aStudyBuilder->NewObject(theSObject);
1255 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1257 aSubO->SetColor(anArgO->GetColor());
1259 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1260 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1261 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1262 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1266 if (!CORBA::is_nil(anArgSO)) {
1267 // Restore published sub-shapes of the argument
1268 GEOM::ListOfGO_var aSubParts;
1269 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1270 // pass theObject, because only it has the history
1271 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1272 theObject, anOutArgs, theFindMethod, theAddPrefix);
1274 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1275 aSubO, anOutArgs, theFindMethod, theAddPrefix);
1276 // add to parts list
1277 addToListOfGO( aSubParts, aParts );
1280 else { // GetInPlace failed, try to build from published parts
1281 if (!CORBA::is_nil(anArgSO)) {
1282 SALOMEDS::SObject_var aSubSO;
1283 if (!CORBA::is_nil(theSObject))
1284 aSubSO = aStudyBuilder->NewObject(theSObject);
1286 // Restore published sub-shapes of the argument
1287 GEOM::ListOfGO_var aSubParts =
1288 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1289 theObject, anOutArgs, theFindMethod, theAddPrefix);
1291 // add to parts list
1292 addToListOfGO( aSubParts, aParts );
1294 if (aSubParts->length() > 0) {
1295 // remember restored objects for Python Dump
1296 addToListOfGO(anArgO, anOutArgs);
1298 // try to build an argument from a set of its sub-shapes,
1299 // that published and will be reconstructed
1300 if (aSubParts->length() > 1) {
1301 aSubO = aShapesOp->MakeCompound(aSubParts);
1302 // add to parts list
1303 addToListOfGO( aSubO, aParts );
1306 aSubO = aSubParts[0];
1308 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1309 // Publish the sub-shape
1310 TCollection_AsciiString aSubName;
1312 aSubName = "from_parts_of_";
1314 aSubName += anArgName;
1315 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1317 aSubO->SetColor(anArgO->GetColor());
1319 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1320 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1321 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1322 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1326 else if (!CORBA::is_nil(aSubSO)) {
1327 // remove created aSubSO, because no parts have been found
1328 aStudyBuilder->RemoveObject(aSubSO);
1331 } // try to build from published parts
1332 anArgSO->UnRegister();
1334 } // process arguments
1336 std::set<std::string> anObjEntryMap;
1337 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1339 int nb = aParts->length();
1340 aResParts->length(nb);
1343 HANDLE_NAMESPACE(GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1344 HANDLE_NAMESPACE(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1345 GEOM::TPythonDump pd (aFunction, true);
1348 for ( ; i < nb; i++ )
1350 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1351 if (CORBA::is_nil(anObj))
1353 char* anEntry = anObj->GetEntry();
1354 if (anObjEntryMap.count(anEntry))
1355 continue; // already treated
1356 anObjEntryMap.insert(anEntry);
1357 aResParts[nbRes++] = anObj;
1358 // clear python dump of object
1359 HANDLE_NAMESPACE(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1360 HANDLE_NAMESPACE(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1361 if ( !anObjFun.IsNull() )
1362 anObjFun->SetDescription( "" );
1368 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1369 //i = 0; nb = theArgs.length(); j = 0;
1370 i = 0; nb = anOutArgs->length(); j = 0;
1371 for ( ; i < nb; i++ )
1373 //GEOM::GEOM_Object_var anObj = theArgs[ i ];
1374 GEOM::GEOM_Object_var anObj = anOutArgs[ i ];
1375 if (CORBA::is_nil(anObj))
1377 HANDLE_NAMESPACE(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1383 pd <<"]" << ", " <<"GEOM.";
1384 switch (theFindMethod) {
1385 case GEOM::FSM_GetInPlace:
1386 pd << "FSM_GetInPlace"; break;
1387 case GEOM::FSM_MultiTransformed:
1388 pd << "FSM_MultiTransformed"; break;
1389 case GEOM::FSM_Transformed:
1390 pd << "FSM_Transformed"; break;
1391 case GEOM::FSM_GetSame:
1392 pd << "FSM_GetSame"; break;
1393 case GEOM::FSM_GetShapesOnShape:
1394 pd << "FSM_GetShapesOnShape"; break;
1395 case GEOM::FSM_GetInPlaceByHistory:
1397 pd << "FSM_GetInPlaceByHistory"; break;
1399 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1401 aResParts->length(nbRes);
1402 return aResParts._retn();
1405 //============================================================================
1406 // function : RestoreSubShapesOneLevel
1407 // purpose : Private method
1408 //============================================================================
1409 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1410 SALOMEDS::SObject_ptr theOldSO,
1411 SALOMEDS::SObject_ptr theNewSO,
1412 GEOM::GEOM_Object_ptr theNewO,
1413 GEOM::ListOfGO& theOutArgs,
1414 GEOM::find_shape_method theFindMethod,
1415 CORBA::Boolean theAddPrefix)
1418 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1419 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1420 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1421 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1422 return aParts._retn();
1424 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1426 // Get interface, containing method, which we will use to reconstruct sub-shapes
1427 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1428 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1429 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1431 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1432 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1434 // Reconstruct published sub-shapes
1435 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1438 for (it->Init(); it->More(); it->Next()) {
1441 aParts->length(aLen);
1443 for (it->Init(); it->More(); it->Next()) {
1444 SALOMEDS::SObject_var anOldSubSO = it->Value();
1446 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1448 SALOMEDS::GenericAttribute_var anAttr;
1449 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1450 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1451 GEOM::GEOM_Object_var anOldSubO =
1452 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1453 if (!CORBA::is_nil(anOldSubO)) {
1454 // Find a sub-shape of theNewO in place of anOldSubO
1455 GEOM::GEOM_Object_var aNewSubO;
1456 switch (theFindMethod) {
1457 case GEOM::FSM_GetInPlace:
1460 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1463 case GEOM::FSM_MultiTransformed:
1465 // Only for Multi-transformations
1466 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
1467 if (!CORBA::is_nil(anArgOTrsf)) {
1468 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1469 HANDLE_NAMESPACE(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1470 HANDLE_NAMESPACE(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1471 anArgOTrsfFun->SetDescription("");
1472 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1476 case GEOM::FSM_Transformed:
1478 // transformation, cannot use GetInPlace, operate with indices
1479 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1480 if (anIDs->length() > 1) {
1482 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1483 if (!CORBA::is_nil(aNewSubO))
1484 aGroupOp->UnionIDs(aNewSubO, anIDs);
1488 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1492 case GEOM::FSM_GetSame:
1495 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1498 case GEOM::FSM_GetShapesOnShape:
1500 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1501 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1502 (short)GEOM::SOLID, GEOM::ST_ONIN);
1505 case GEOM::FSM_GetInPlaceByHistory:
1507 // Use GetInPlaceByHistory
1508 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1515 if (!CORBA::is_nil(aNewSubO)) {
1516 // remember restored objects for Python Dump
1517 addToListOfGO(anOldSubO, theOutArgs);
1519 // add the part to the list
1520 aParts[i] = aNewSubO;
1522 // add to parts list
1523 addToListOfGO( aNewSubO, aNewParts );
1525 SALOMEDS::SObject_var aNewSubSO;
1526 if (!CORBA::is_nil(theNewSO)) {
1527 // Publish the sub-shape
1528 TCollection_AsciiString aSubName;
1532 aSubName += anArgName;
1533 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1534 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1536 aNewSubO->SetColor(anOldSubO->GetColor());
1538 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1539 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1540 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1541 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1544 // Restore published sub-shapes of the argument
1545 GEOM::ListOfGO_var aSubParts;
1546 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1547 // pass the main shape as Object, because only it has the history
1548 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1549 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1551 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1552 aNewSubO, theOutArgs, theFindMethod, theAddPrefix);
1553 // add to parts list
1554 addToListOfGO( aSubParts, aNewParts );
1556 else { // GetInPlace failed, try to build from published parts
1557 SALOMEDS::SObject_var aNewSubSO;
1558 if (!CORBA::is_nil(theNewSO))
1559 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1561 // Restore published sub-shapes of the argument
1562 GEOM::ListOfGO_var aSubParts =
1563 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1564 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1565 // add to parts list
1566 addToListOfGO( aSubParts, aNewParts );
1568 if (aSubParts->length() > 0) {
1569 // remember restored objects for Python Dump
1570 addToListOfGO(anOldSubO, theOutArgs);
1572 // try to build an object from a set of its sub-shapes,
1573 // that published and will be reconstructed
1574 if (aSubParts->length() > 1) {
1575 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1576 // add to parts list
1577 addToListOfGO( aNewSubO, aNewParts );
1580 aNewSubO = aSubParts[0];
1583 if (!CORBA::is_nil(aNewSubO)) {
1584 // add the part to the list
1585 aSubParts[i] = aNewSubO;
1588 // Publish the sub-shape
1589 if (!CORBA::is_nil(aNewSubSO)) {
1590 TCollection_AsciiString aSubName;
1592 aSubName = "from_parts_of_";
1594 aSubName += anArgName;
1595 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1597 aNewSubO->SetColor(anOldSubO->GetColor());
1599 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1600 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1601 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1602 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1607 else if (!CORBA::is_nil(aNewSubSO)) {
1608 // remove created aSubSO, because no parts have been found
1609 aStudyBuilder->RemoveObject(aNewSubSO);
1611 } // try to build from published parts
1614 } // iterate on published sub-shapes
1617 // add to parts list
1618 addToListOfGO( aNewParts, aParts );
1619 return aParts._retn();
1622 //============================================================================
1623 // function : RestoreGivenSubShapes
1624 // purpose : Private method. Works only if both theObject and theSObject
1625 // are defined, and does not check, if they correspond to each other.
1626 // List theArgs in this case contains not only operation arguments,
1627 // but also all subshapes, which must be published.
1628 //============================================================================
1629 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStudy,
1630 GEOM::GEOM_Object_ptr theObject,
1631 SALOMEDS::SObject_ptr theSObject,
1632 const GEOM::ListOfGO& theArgs,
1633 GEOM::find_shape_method theFindMethod,
1634 CORBA::Boolean theInheritFirstArg,
1635 CORBA::Boolean theAddPrefix)
1637 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1638 //PTv, IMP 0020001, The salome object <theSObject>
1639 // is not obligatory in case of invokation from script
1640 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
1641 return aParts._retn();
1643 // If theArgs list is empty, nothing to do
1644 Standard_Integer aLength = theArgs.length();
1646 return aParts._retn();
1648 // Get all arguments
1649 GEOM::ListOfGBO_var anOpArgsList = theObject->GetDependency();
1650 Standard_Integer nbArgsActual = anOpArgsList->length();
1652 // If anOpArgsList list is empty, nothing to do
1653 if (nbArgsActual == 0)
1654 return aParts._retn();
1656 // Entries of arguments and subshapes
1657 std::set<std::string> anArgs;
1658 for (int i = 0; i < aLength; i++) {
1659 CORBA::String_var anEntry = theArgs[i]->GetEntry();
1660 anArgs.insert(anEntry.in());
1663 // Arguments to be published
1664 // We try to publish all arguments, that are in theArgs list
1665 GEOM::ListOfGO_var aList = new GEOM::ListOfGO;
1666 aList->length(nbArgsActual);
1669 for (int j = 0; j < nbArgsActual; j++) {
1670 CORBA::String_var anEntry = anOpArgsList[j]->GetEntry();
1671 if (anArgs.count(anEntry.in())) {
1672 aList[k] = GEOM::GEOM_Object::_narrow(anOpArgsList[j]);
1677 //aList->length(nbArgsActual);
1679 if (nbArgsActual < 1)
1680 return aParts._retn();
1682 if (theInheritFirstArg || (nbArgsActual == 1)) {
1683 // Do not publish argument's reflection,
1684 // but only reconstruct its published sub-shapes
1686 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1687 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1689 aParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
1690 anArgs, theFindMethod, theAddPrefix);
1692 // set the color of the transformed shape to the color of initial shape
1693 theObject->SetColor(aList[0]->GetColor());
1695 if (theObject->GetShapeType() == GEOM::VERTEX) {
1696 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1697 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1698 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1701 anArgSO->UnRegister();
1704 // Get interface, containing method, which we will use to reconstruct sub-shapes
1705 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1706 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1707 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1709 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1710 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1712 // Reconstruct arguments and tree of sub-shapes of the arguments
1713 CORBA::String_var anIOR;
1714 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1715 for (Standard_Integer i = 0; i < nbArgsActual; i++)
1717 GEOM::GEOM_Object_var anArgO = aList[i];
1718 if (!CORBA::is_nil(anArgO)) {
1719 anIOR = _orb->object_to_string(anArgO);
1720 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1721 TCollection_AsciiString anArgName;
1722 if (CORBA::is_nil(anArgSO)) {
1724 anArgName += TCollection_AsciiString(i);
1727 anArgName = anArgSO->GetName();
1730 // Find a sub-shape of theObject in place of the argument
1731 GEOM::GEOM_Object_var aSubO;
1732 switch (theFindMethod) {
1733 case GEOM::FSM_GetInPlace:
1736 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1739 case GEOM::FSM_MultiTransformed:
1741 // Only for Multi-transformations
1742 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1743 if (!CORBA::is_nil(anArgOTrsf)) {
1744 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1745 HANDLE_NAMESPACE(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1746 HANDLE_NAMESPACE(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1747 anArgOTrsfFun->SetDescription("");
1748 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1752 case GEOM::FSM_Transformed:
1754 // transformation, cannot use GetInPlace, operate with indices
1755 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1756 if (anIDs->length() > 1) {
1758 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1759 if (!CORBA::is_nil(aSubO))
1760 aGroupOp->UnionIDs(aSubO, anIDs);
1762 else if (anIDs->length() > 0) {
1764 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1768 case GEOM::FSM_GetSame:
1771 aSubO = aShapesOp->GetSame(theObject, anArgO);
1774 case GEOM::FSM_GetShapesOnShape:
1776 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1777 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1778 (short)GEOM::SOLID, GEOM::ST_ONIN);
1781 case GEOM::FSM_GetInPlaceByHistory:
1783 // Use GetInPlaceByHistory
1784 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1791 if (!CORBA::is_nil(aSubO)) {
1792 // add to parts list
1793 addToListOfGO( aSubO, aParts );
1795 // Publish the sub-shape
1796 SALOMEDS::SObject_var aSubSO;
1797 if (!CORBA::is_nil(theSObject)) {
1798 TCollection_AsciiString aSubName;
1802 aSubName += anArgName;
1803 aSubSO = aStudyBuilder->NewObject(theSObject);
1804 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1806 aSubO->SetColor(anArgO->GetColor());
1808 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1809 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1810 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1811 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1815 if (!CORBA::is_nil(anArgSO)) {
1816 // Restore published sub-shapes of the argument
1817 GEOM::ListOfGO_var aSubParts;
1818 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1819 // pass theObject, because only it has the history
1820 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1821 theObject, anArgs, theFindMethod, theAddPrefix);
1823 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1824 aSubO, anArgs, theFindMethod, theAddPrefix);
1825 // add to parts list
1826 addToListOfGO( aSubParts, aParts );
1829 else { // GetInPlace failed, try to build from published parts
1830 if (!CORBA::is_nil(anArgSO)) {
1831 SALOMEDS::SObject_var aSubSO;
1832 if (!CORBA::is_nil(theSObject))
1833 aSubSO = aStudyBuilder->NewObject(theSObject);
1835 // Restore published sub-shapes of the argument
1836 GEOM::ListOfGO_var aSubParts =
1837 RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1838 theObject, anArgs, theFindMethod, theAddPrefix);
1840 // add to parts list
1841 addToListOfGO( aSubParts, aParts );
1843 if (aSubParts->length() > 0) {
1844 // try to build an argument from a set of its sub-shapes,
1845 // that published and will be reconstructed
1846 if (aSubParts->length() > 1) {
1847 aSubO = aShapesOp->MakeCompound(aSubParts);
1848 // add to parts list
1849 addToListOfGO( aSubO, aParts );
1852 aSubO = aSubParts[0];
1854 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1855 // Publish the sub-shape
1856 TCollection_AsciiString aSubName;
1858 aSubName = "from_parts_of_";
1860 aSubName += anArgName;
1861 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1863 aSubO->SetColor(anArgO->GetColor());
1865 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1866 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1867 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1868 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1872 else if (!CORBA::is_nil(aSubSO)) {
1873 // remove created aSubSO, because no parts have been found
1874 aStudyBuilder->RemoveObject(aSubSO);
1877 } // try to build from published parts
1878 anArgSO->UnRegister();
1880 } // process arguments
1882 std::set<std::string> anObjEntryMap;
1883 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1885 int nb = aParts->length();
1886 aResParts->length(nb);
1889 HANDLE_NAMESPACE(GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1890 HANDLE_NAMESPACE(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1891 GEOM::TPythonDump pd (aFunction, true);
1894 for ( ; i < nb; i++ )
1896 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1897 if (CORBA::is_nil(anObj))
1899 char* anEntry = anObj->GetEntry();
1900 if (anObjEntryMap.count(anEntry))
1901 continue; // already treated
1902 anObjEntryMap.insert(anEntry);
1903 aResParts[nbRes++] = anObj;
1904 // clear python dump of object
1905 HANDLE_NAMESPACE(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1906 HANDLE_NAMESPACE(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1907 if ( !anObjFun.IsNull() )
1908 anObjFun->SetDescription( "" );
1914 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1915 i = 0; nb = theArgs.length(); j = 0;
1916 for ( ; i < nb; i++ )
1918 GEOM::GEOM_Object_var anObj = theArgs[ i ];
1919 if (CORBA::is_nil(anObj))
1921 HANDLE_NAMESPACE(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1927 pd <<"]" << ", " <<"GEOM.";
1928 switch (theFindMethod) {
1929 case GEOM::FSM_GetInPlace:
1930 pd << "FSM_GetInPlace"; break;
1931 case GEOM::FSM_MultiTransformed:
1932 pd << "FSM_MultiTransformed"; break;
1933 case GEOM::FSM_Transformed:
1934 pd << "FSM_Transformed"; break;
1935 case GEOM::FSM_GetSame:
1936 pd << "FSM_GetSame"; break;
1937 case GEOM::FSM_GetShapesOnShape:
1938 pd << "FSM_GetShapesOnShape"; break;
1939 case GEOM::FSM_GetInPlaceByHistory:
1941 pd << "FSM_GetInPlaceByHistory"; break;
1943 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1945 aResParts->length(nbRes);
1946 return aResParts._retn();
1949 //============================================================================
1950 // function : RestoreGivenSubShapesOneLevel
1951 // purpose : Private method
1952 //============================================================================
1953 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1954 SALOMEDS::SObject_ptr theOldSO,
1955 SALOMEDS::SObject_ptr theNewSO,
1956 GEOM::GEOM_Object_ptr theNewO,
1957 std::set<std::string> theArgs,
1958 GEOM::find_shape_method theFindMethod,
1959 CORBA::Boolean theAddPrefix)
1962 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1963 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1964 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1965 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1966 return aParts._retn();
1968 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1970 // Get interface, containing method, which we will use to reconstruct sub-shapes
1971 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1972 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1973 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1975 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1976 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1978 // Reconstruct published sub-shapes
1979 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1982 for (it->Init(); it->More(); it->Next()) {
1985 aParts->length(aLen);
1987 for (it->Init(); it->More(); it->Next()) {
1988 SALOMEDS::SObject_var anOldSubSO = it->Value();
1990 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1992 SALOMEDS::GenericAttribute_var anAttr;
1993 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1994 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1995 GEOM::GEOM_Object_var anOldSubO =
1996 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1998 bool okToContinue = false;
2000 if (!CORBA::is_nil(anOldSubO)) {
2001 CORBA::String_var anEntry = anOldSubO->GetEntry();
2002 okToContinue = theArgs.count(anEntry.in());
2006 // Find a sub-shape of theNewO in place of anOldSubO
2007 GEOM::GEOM_Object_var aNewSubO;
2008 switch (theFindMethod) {
2009 case GEOM::FSM_GetInPlace:
2012 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
2015 case GEOM::FSM_MultiTransformed:
2017 // Only for Multi-transformations
2018 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
2019 if (!CORBA::is_nil(anArgOTrsf)) {
2020 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
2021 HANDLE_NAMESPACE(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
2022 HANDLE_NAMESPACE(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
2023 anArgOTrsfFun->SetDescription("");
2024 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
2028 case GEOM::FSM_Transformed:
2030 // transformation, cannot use GetInPlace, operate with indices
2031 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
2032 if (anIDs->length() > 1) {
2034 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
2035 if (!CORBA::is_nil(aNewSubO))
2036 aGroupOp->UnionIDs(aNewSubO, anIDs);
2040 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
2044 case GEOM::FSM_GetSame:
2047 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
2050 case GEOM::FSM_GetShapesOnShape:
2052 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
2053 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
2054 (short)GEOM::SOLID, GEOM::ST_ONIN);
2057 case GEOM::FSM_GetInPlaceByHistory:
2059 // Use GetInPlaceByHistory
2060 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
2067 if (!CORBA::is_nil(aNewSubO)) {
2068 // add the part to the list
2069 aParts[i] = aNewSubO;
2071 // add to parts list
2072 addToListOfGO( aNewSubO, aNewParts );
2074 SALOMEDS::SObject_var aNewSubSO;
2075 if (!CORBA::is_nil(theNewSO)) {
2076 // Publish the sub-shape
2077 TCollection_AsciiString aSubName;
2081 aSubName += anArgName;
2082 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
2083 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
2085 aNewSubO->SetColor(anOldSubO->GetColor());
2087 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2088 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2089 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2090 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2093 // Restore published sub-shapes of the argument
2094 GEOM::ListOfGO_var aSubParts;
2095 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
2096 // pass the main shape as Object, because only it has the history
2097 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
2098 theNewO, theArgs, theFindMethod, theAddPrefix);
2100 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
2101 aNewSubO, theArgs, theFindMethod, theAddPrefix);
2102 // add to parts list
2103 addToListOfGO( aSubParts, aNewParts );
2105 else { // GetInPlace failed, try to build from published parts
2106 SALOMEDS::SObject_var aNewSubSO;
2107 if (!CORBA::is_nil(theNewSO))
2108 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
2110 // Restore published sub-shapes of the argument
2111 GEOM::ListOfGO_var aSubParts =
2112 RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
2113 theNewO, theArgs, theFindMethod, theAddPrefix);
2114 // add to parts list
2115 addToListOfGO( aSubParts, aNewParts );
2117 if (aSubParts->length() > 0) {
2118 // try to build an object from a set of its sub-shapes,
2119 // that published and will be reconstructed
2120 if (aSubParts->length() > 1) {
2121 aNewSubO = aShapesOp->MakeCompound(aSubParts);
2122 // add to parts list
2123 addToListOfGO( aNewSubO, aNewParts );
2126 aNewSubO = aSubParts[0];
2129 if (!CORBA::is_nil(aNewSubO)) {
2130 // add the part to the list
2131 aSubParts[i] = aNewSubO;
2134 // Publish the sub-shape
2135 if (!CORBA::is_nil(aNewSubSO)) {
2136 TCollection_AsciiString aSubName;
2138 aSubName = "from_parts_of_";
2140 aSubName += anArgName;
2141 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
2143 aNewSubO->SetColor(anOldSubO->GetColor());
2145 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2146 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2147 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2148 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2153 else if (!CORBA::is_nil(aNewSubSO)) {
2154 // remove created aSubSO, because no parts have been found
2155 aStudyBuilder->RemoveObject(aNewSubSO);
2157 } // try to build from published parts
2160 } // iterate on published sub-shapes
2163 // add to parts list
2164 addToListOfGO( aNewParts, aParts );
2165 return aParts._retn();
2168 //============================================================================
2169 // function : register()
2170 // purpose : register 'name' in 'name_service'
2171 //============================================================================
2172 void GEOM_Gen_i::register_name(char * name)
2174 GEOM::GEOM_Gen_var g = _this();
2175 name_service->Register(g, name);
2178 //============================================================================
2181 //============================================================================
2182 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
2184 _impl->Undo(theStudyID);
2187 //============================================================================
2190 //============================================================================
2191 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
2193 _impl->Redo(theStudyID);
2196 //============================================================================
2197 // function : GetIBasicOperations
2199 //============================================================================
2200 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
2201 throw ( SALOME::SALOME_Exception )
2203 Unexpect aCatch(SALOME_SalomeException);
2204 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
2206 GEOM::GEOM_Gen_ptr engine = _this();
2208 //transfer reference on engine
2209 GEOM_IBasicOperations_i* aServant =
2210 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
2212 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2213 // activate the CORBA servant
2214 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
2215 return operations._retn();
2218 //============================================================================
2219 // function : GetITransformOperations
2221 //============================================================================
2222 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
2223 throw ( SALOME::SALOME_Exception )
2225 Unexpect aCatch(SALOME_SalomeException);
2226 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
2228 GEOM::GEOM_Gen_ptr engine = _this();
2230 GEOM_ITransformOperations_i* aServant =
2231 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
2233 // activate the CORBA servant
2234 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
2235 return operations._retn();
2238 //============================================================================
2239 // function : GetI3DPrimOperations
2241 //============================================================================
2242 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
2243 throw ( SALOME::SALOME_Exception )
2245 Unexpect aCatch(SALOME_SalomeException);
2246 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
2248 GEOM::GEOM_Gen_ptr engine = _this();
2250 GEOM_I3DPrimOperations_i* aServant =
2251 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
2252 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2254 // activate the CORBA servant
2255 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
2256 return operations._retn();
2259 //============================================================================
2260 // function : GetIShapesOperations
2262 //============================================================================
2263 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
2264 throw ( SALOME::SALOME_Exception )
2266 Unexpect aCatch(SALOME_SalomeException);
2267 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
2269 GEOM::GEOM_Gen_ptr engine = _this();
2271 GEOM_IShapesOperations_i* aServant =
2272 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
2274 // activate the CORBA servant
2275 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
2276 return operations._retn();
2279 //============================================================================
2280 // function : GetIBlocksOperations
2282 //============================================================================
2283 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
2284 throw ( SALOME::SALOME_Exception )
2286 Unexpect aCatch(SALOME_SalomeException);
2287 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
2289 GEOM::GEOM_Gen_ptr engine = _this();
2291 GEOM_IBlocksOperations_i* aServant =
2292 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
2294 // activate the CORBA servant
2295 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
2296 return operations._retn();
2299 //============================================================================
2300 // function : GetIBooleanOperations
2302 //============================================================================
2303 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
2304 throw ( SALOME::SALOME_Exception )
2306 Unexpect aCatch(SALOME_SalomeException);
2307 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
2309 GEOM::GEOM_Gen_ptr engine = _this();
2311 GEOM_IBooleanOperations_i* aServant =
2312 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
2314 // activate the CORBA servant
2315 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
2316 return operations._retn();
2319 //============================================================================
2320 // function : GetICurvesOperations
2322 //============================================================================
2323 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
2324 throw ( SALOME::SALOME_Exception )
2326 Unexpect aCatch(SALOME_SalomeException);
2327 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
2329 GEOM::GEOM_Gen_ptr engine = _this();
2331 GEOM_ICurvesOperations_i* aServant =
2332 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
2334 // activate the CORBA servant
2335 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
2336 return operations._retn();
2339 //============================================================================
2340 // function : GetILocalOperations
2342 //============================================================================
2343 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
2344 throw ( SALOME::SALOME_Exception )
2346 Unexpect aCatch(SALOME_SalomeException);
2347 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
2349 GEOM::GEOM_Gen_ptr engine = _this();
2351 GEOM_ILocalOperations_i* aServant =
2352 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
2354 // activate the CORBA servant
2355 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
2356 return operations._retn();
2359 //============================================================================
2360 // function : GetIHealingOperations
2362 //============================================================================
2363 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
2364 throw ( SALOME::SALOME_Exception )
2366 Unexpect aCatch(SALOME_SalomeException);
2367 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
2369 GEOM::GEOM_Gen_ptr engine = _this();
2371 GEOM_IHealingOperations_i* aServant =
2372 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
2374 // activate the CORBA servant
2375 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
2376 return operations._retn();
2379 //============================================================================
2380 // function : GetIInsertOperations
2382 //============================================================================
2383 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
2384 throw ( SALOME::SALOME_Exception )
2386 Unexpect aCatch(SALOME_SalomeException);
2387 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
2389 GEOM::GEOM_Gen_ptr engine = _this();
2391 GEOM_IInsertOperations_i* aServant =
2392 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
2394 // activate the CORBA servant
2395 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
2396 return operations._retn();
2399 //============================================================================
2400 // function : GetIMeasureOperations
2402 //============================================================================
2403 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
2404 throw ( SALOME::SALOME_Exception )
2406 Unexpect aCatch(SALOME_SalomeException);
2407 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
2409 GEOM::GEOM_Gen_ptr engine = _this();
2411 GEOM_IMeasureOperations_i* aServant =
2412 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
2414 // activate the CORBA servant
2415 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
2416 return operations._retn();
2419 //============================================================================
2420 // function : GetIGroupOperations
2422 //============================================================================
2423 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
2424 throw ( SALOME::SALOME_Exception )
2426 Unexpect aCatch(SALOME_SalomeException);
2427 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
2429 GEOM::GEOM_Gen_ptr engine = _this();
2431 GEOM_IGroupOperations_i* aServant =
2432 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
2434 // activate the CORBA servant
2435 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
2436 return operations._retn();
2439 //============================================================================
2440 // function : GetIFieldOperations
2442 //============================================================================
2443 GEOM::GEOM_IFieldOperations_ptr GEOM_Gen_i::GetIFieldOperations(CORBA::Long theStudyID)
2444 throw ( SALOME::SALOME_Exception )
2446 Unexpect aCatch(SALOME_SalomeException);
2447 MESSAGE( "GEOM_Gen_i::GetIFieldOperations" );
2449 GEOM::GEOM_Gen_ptr engine = _this();
2451 GEOM_IFieldOperations_i* aServant =
2452 new GEOM_IFieldOperations_i(_poa, engine, _impl->GetIFieldOperations(theStudyID));
2454 // activate the CORBA servant
2455 GEOM::GEOM_IFieldOperations_var operations = aServant->_this();
2456 return operations._retn();
2459 //============================================================================
2460 // function : GetPluginOperations
2462 //============================================================================
2463 GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(CORBA::Long theStudyID,
2464 const char* theLibName)
2465 throw ( SALOME::SALOME_Exception )
2467 Unexpect aCatch(SALOME_SalomeException);
2468 MESSAGE( "GEOM_Gen_i::GetPluginOperations" );
2470 GEOM::GEOM_Gen_ptr engine = _this();
2472 GEOM::GEOM_IOperations_var operations;
2474 std::string aLibName = theLibName;
2477 // load plugin library
2478 LoadPlugin(aLibName);
2479 // create a new operations object, store its ref. in engine
2480 if ( myOpCreatorMap.find(aLibName) != myOpCreatorMap.end() ) {
2481 GEOM_IOperations_i* aServant = 0;
2482 aServant = myOpCreatorMap[aLibName]->Create(_poa, theStudyID, engine, _impl);
2483 // activate the CORBA servant
2485 operations = aServant->_this();
2488 catch (SALOME_Exception& S_ex) {
2489 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
2492 return operations._retn();
2495 //============================================================================
2496 // function : LoadPlugin
2497 // purpose : load plugin library and retrieve an instance of operations creator
2498 //============================================================================
2499 void GEOM_Gen_i::LoadPlugin(const std::string& theLibName)
2501 std::string aPlatformLibName;
2503 aPlatformLibName = theLibName;
2504 aPlatformLibName += ".dll" ;
2506 aPlatformLibName = "lib";
2507 aPlatformLibName += theLibName;
2508 aPlatformLibName += ".so";
2511 // check, if corresponding operations are already created
2512 if (myOpCreatorMap.find(theLibName) == myOpCreatorMap.end()) {
2513 // load plugin library
2514 LibHandle libHandle = LoadLib( aPlatformLibName.c_str() );
2516 // report any error, if occured
2518 throw(SALOME_Exception(dlerror()));
2520 throw(SALOME_Exception(LOCALIZED( "Can't load server geometry plugin library" )));
2524 // get method, returning operations creator
2525 typedef GEOM_GenericOperationsCreator* (*GetOperationsCreator)();
2526 GetOperationsCreator procHandle =
2527 (GetOperationsCreator)GetProc( libHandle, "GetOperationsCreator" );
2529 UnLoadLib(libHandle);
2530 throw(SALOME_Exception(LOCALIZED("bad geometry plugin library")));
2533 // get operations creator
2534 GEOM_GenericOperationsCreator* aCreator = procHandle();
2536 // map operations creator to a plugin name
2537 myOpCreatorMap[theLibName] = aCreator;
2540 throw(SALOME_Exception(LOCALIZED("bad geometry plugin library implementation")));
2545 //=============================================================================
2549 //=============================================================================
2550 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
2551 const GEOM::ListOfLong& theIndices)
2553 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
2554 return GEOM::GEOM_Object::_nil();
2555 CORBA::String_var entry = theMainShape->GetEntry();
2556 HANDLE_NAMESPACE(GEOM_Object) aMainShape = HANDLE_NAMESPACE(GEOM_Object)::DownCast
2557 ( _impl->GetObject( theMainShape->GetStudyID(), entry ));
2558 if (aMainShape.IsNull()) return GEOM::GEOM_Object::_nil();
2560 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
2561 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
2563 HANDLE_NAMESPACE(GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true);
2564 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
2566 TCollection_AsciiString anEntry;
2567 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
2568 return GEOM::GEOM_Object::_narrow( GetObject(anObject->GetDocID(), anEntry.ToCString()));
2571 //=============================================================================
2575 //=============================================================================
2576 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_BaseObject_ptr theObject)
2578 CORBA::String_var anEntry = theObject->GetEntry();
2579 HANDLE_NAMESPACE(GEOM_BaseObject) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false);
2580 if (!anObject.IsNull())
2581 _impl->RemoveObject(anObject);
2584 //=================================================================================
2585 // function : GetStringFromIOR()
2586 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
2587 //=================================================================================
2588 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject)
2590 return _orb->object_to_string(theObject);
2593 //=================================================================================
2594 // function : GetIORFromString()
2595 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
2596 //=================================================================================
2597 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
2598 GEOM::GEOM_Object_var aGeomObject;
2599 if(strcmp(stringIOR,"") != 0){
2600 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
2601 if(!CORBA::is_nil(anObject))
2602 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
2604 return aGeomObject._retn();
2607 //=================================================================================
2608 // function : GetObject()
2610 //=================================================================================
2611 GEOM::GEOM_BaseObject_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
2613 GEOM::GEOM_BaseObject_var obj;
2614 HANDLE_NAMESPACE(GEOM_BaseObject) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
2615 if (handle_object.IsNull()) return obj._retn();
2617 TCollection_AsciiString stringIOR = handle_object->GetIOR();
2618 if (stringIOR.Length() > 1) {
2619 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
2620 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_BaseObject::_narrow(corba_object);
2624 GEOM::GEOM_Gen_ptr engine = _this();
2625 //transfer the reference to GEOM_Object_i
2626 GEOM_BaseObject_i* servant = 0;
2627 switch( handle_object->GetType() ) {
2629 servant = new GEOM_Field_i (_poa, engine, HANDLE_NAMESPACE(GEOM_Field)::DownCast( handle_object ));
2632 case GEOM_FIELD_STEP: {
2633 HANDLE_NAMESPACE(GEOM_FieldStep) step = HANDLE_NAMESPACE(GEOM_FieldStep)::DownCast( handle_object );
2634 HANDLE_NAMESPACE(GEOM_Field) field = step->GetField();
2635 int type = ( !field.IsNull() ? field->GetDataType() : 0 );
2637 case GEOM::FDT_Bool:
2638 servant = new GEOM_BoolFieldStep_i (_poa, engine, step );
2641 servant = new GEOM_IntFieldStep_i (_poa, engine, step );
2643 case GEOM::FDT_Double:
2644 servant = new GEOM_DoubleFieldStep_i (_poa, engine, step );
2647 servant = new GEOM_StringFieldStep_i (_poa, engine, step );
2652 servant = new GEOM_Object_i (_poa, engine, HANDLE_NAMESPACE(GEOM_Object)::DownCast( handle_object ));
2654 PortableServer::ObjectId_var id = _poa->activate_object(servant);
2656 obj = servant->_this();
2657 CORBA::String_var objStr = _orb->object_to_string(obj);
2658 TCollection_AsciiString anAscii( (char *)objStr.in() );
2659 handle_object->SetIOR( anAscii );
2663 //=================================================================================
2664 // function : hasObjectInfo()
2665 // purpose : shows if module provides information for its objects
2666 //=================================================================================
2667 bool GEOM_Gen_i::hasObjectInfo()
2672 //=================================================================================
2673 // function : getObjectInfo()
2674 // purpose : returns an information for a given object by its entry
2675 //=================================================================================
2676 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
2678 GEOM::GEOM_Object_var aGeomObject;
2680 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
2681 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
2682 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
2683 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
2684 SALOMEDS::SObject_var aResultSObj;
2685 if (aSObj->ReferencedObject(aResultSObj))
2686 aSObj = aResultSObj;
2688 SALOMEDS::GenericAttribute_var anAttr;
2689 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
2690 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2691 CORBA::String_var aVal = anIOR->Value();
2692 anIOR->UnRegister();
2693 CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
2694 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
2696 if (!aSObj->_is_nil() )
2697 aSObj->UnRegister();
2699 const char* aTypeInfo = "Object";
2700 if ( !aGeomObject->_is_nil() ) {
2701 GEOM::GEOM_IKindOfShape::shape_kind aKind;
2702 GEOM::ListOfLong_var anInts;
2703 GEOM::ListOfDouble_var aDbls;
2705 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
2706 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
2708 if ( anOp->IsDone() ) {
2710 case GEOM::GEOM_IKindOfShape::COMPOUND:
2711 aTypeInfo = "Compound";
2713 case GEOM::GEOM_IKindOfShape::COMPSOLID:
2714 aTypeInfo = "CompSolid";
2716 case GEOM::GEOM_IKindOfShape::SHELL:
2717 aTypeInfo = "Shell";
2719 case GEOM::GEOM_IKindOfShape::WIRE:
2720 if ( anInts[0] == 1 )
2721 aTypeInfo = "Closed Wire";
2722 else if ( anInts[0] == 2 )
2723 aTypeInfo = "Opened Wire";
2728 case GEOM::GEOM_IKindOfShape::SPHERE:
2729 aTypeInfo = "Sphere";
2731 case GEOM::GEOM_IKindOfShape::CYLINDER:
2732 aTypeInfo = "Cylinder";
2734 case GEOM::GEOM_IKindOfShape::BOX:
2735 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
2738 case GEOM::GEOM_IKindOfShape::TORUS:
2739 aTypeInfo = "Torus";
2741 case GEOM::GEOM_IKindOfShape::CONE:
2744 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
2745 aTypeInfo = "Polyhedron";
2747 case GEOM::GEOM_IKindOfShape::SOLID:
2748 aTypeInfo = "Solid";
2751 case GEOM::GEOM_IKindOfShape::SPHERE2D:
2752 aTypeInfo = "Spherical Face";
2754 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
2755 aTypeInfo = "Cylindrical Face";
2757 case GEOM::GEOM_IKindOfShape::TORUS2D:
2758 aTypeInfo = "Toroidal Face";
2760 case GEOM::GEOM_IKindOfShape::CONE2D:
2761 aTypeInfo = "Conical Face";
2763 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
2766 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
2767 aTypeInfo = "Elliptical Face";
2769 case GEOM::GEOM_IKindOfShape::POLYGON:
2770 aTypeInfo = "Polygon";
2772 case GEOM::GEOM_IKindOfShape::PLANE:
2773 aTypeInfo = "Plane";
2775 case GEOM::GEOM_IKindOfShape::PLANAR:
2776 aTypeInfo = "Planar Face";
2778 case GEOM::GEOM_IKindOfShape::FACE:
2782 case GEOM::GEOM_IKindOfShape::CIRCLE:
2783 aTypeInfo = "Circle";
2785 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
2786 aTypeInfo = "Arc Circle";
2788 case GEOM::GEOM_IKindOfShape::ELLIPSE:
2789 aTypeInfo = "Ellipse";
2791 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
2792 aTypeInfo = "Arc Ellipse";
2794 case GEOM::GEOM_IKindOfShape::LINE:
2797 case GEOM::GEOM_IKindOfShape::SEGMENT:
2798 aTypeInfo = "Segment";
2800 case GEOM::GEOM_IKindOfShape::EDGE:
2803 case GEOM::GEOM_IKindOfShape::VERTEX:
2804 aTypeInfo = "Vertex";
2812 CORBA::String_var compType = ComponentDataType();
2813 char* anInfo = new char[strlen("Module ") + strlen(compType.in()) + strlen(", ") + strlen(aTypeInfo) + 3];
2814 sprintf(anInfo, "Module %s, %s", compType.in(), aTypeInfo);
2816 char* ret = CORBA::string_dup(anInfo);
2821 // Version information
2822 char* GEOM_Gen_i::getVersion()
2824 #if GEOM_DEVELOPMENT
2825 return CORBA::string_dup(GEOM_VERSION_STR"dev");
2827 return CORBA::string_dup(GEOM_VERSION_STR);
2831 //=================================================================================
2832 // function : CreateFolder()
2833 // purpose : Creates and returns a new folder object
2834 //=================================================================================
2835 SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName,
2836 SALOMEDS::SObject_ptr theFather)
2838 SALOMEDS::SObject_var aFolderSO;
2840 if ( CORBA::is_nil(theFather) ) return aFolderSO._retn();
2842 SALOMEDS::GenericAttribute_var anAttr;
2843 if ( strcmp(theFather->GetFatherComponent()->GetID(), theFather->GetID()) != 0 ) {
2844 // not a GEOM component object was selected
2845 if ( !theFather->FindAttribute(anAttr, "AttributeLocalID") ) return aFolderSO._retn();
2846 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2847 if( aLocalID->Value() != 999 ) {
2848 // not a Folder object was selected
2849 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow(theFather);
2850 if ( CORBA::is_nil(aGeomObject) ) return aFolderSO._retn();
2851 // another GEOM object was selected, so get GEOM component as father object
2852 theFather = theFather->GetFatherComponent();
2854 aLocalID->UnRegister();
2857 SALOMEDS::Study_var aStudy = theFather->GetStudy();
2858 SALOMEDS::StudyBuilder_var aStudyBuilder( aStudy->NewBuilder() );
2859 aFolderSO = aStudyBuilder->NewObject( theFather );
2861 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeLocalID");
2862 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2863 aLocalID->SetValue( 999 ); // mark of the "Folder" object
2864 aLocalID->UnRegister();
2866 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeName");
2867 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
2868 aName->SetValue( theName );
2869 aName->UnRegister();
2871 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributePixMap");
2872 SALOMEDS::AttributePixMap_var aPixMap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2873 aPixMap->SetPixMap("ICON_FOLDER");
2874 aPixMap->UnRegister();
2876 // add object to the use case tree
2877 // (to support tree representation customization and drag-n-drop)
2878 SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder();
2879 useCaseBuilder->AppendTo( theFather, aFolderSO );
2881 return aFolderSO._retn();
2884 //=================================================================================
2885 // function : MoveToFolder()
2886 // purpose : Moves GEOM object to the specified folder
2887 //=================================================================================
2888 void GEOM_Gen_i::MoveToFolder(GEOM::GEOM_Object_ptr theObject,
2889 SALOMEDS::SObject_ptr theFolder) {
2890 GEOM::object_list_var objects = new GEOM::object_list();
2891 objects->length( 1 );
2892 SALOMEDS::SObject_var aSO = theFolder->GetStudy()->FindObjectID( theObject->GetStudyEntry() );
2894 Move( objects, theFolder, -1 );
2897 //=================================================================================
2898 // function : MoveListToFolder()
2899 // purpose : Moves list of GEOM objects to the specified folder
2900 //=================================================================================
2901 void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO,
2902 SALOMEDS::SObject_ptr theFolder) {
2903 int aLen = theListOfGO.length();
2904 GEOM::object_list_var objects = new GEOM::object_list();
2905 objects->length( aLen );
2906 GEOM::GEOM_Object_var aGO;
2907 SALOMEDS::SObject_var aSO;
2908 for (int i = 0; i < aLen; i++) {
2909 aGO = GEOM::GEOM_Object::_duplicate( theListOfGO[i] );
2910 aSO = theFolder->GetStudy()->FindObjectID( aGO->GetStudyEntry() );
2913 if ( objects->length() > 0 )
2914 Move( objects, theFolder, -1 );
2917 //=================================================================================
2918 // function : Move()
2919 // purpose : Moves objects to the specified position.
2920 // Is used in the drag-n-drop functionality.
2921 //=================================================================================
2922 void GEOM_Gen_i::Move( const GEOM::object_list& what,
2923 SALOMEDS::SObject_ptr where,
2926 if ( CORBA::is_nil( where ) ) return;
2928 SALOMEDS::Study_var study = where->GetStudy();
2929 SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder();
2930 SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder();
2931 SALOMEDS::SComponent_var father = where->GetFatherComponent();
2932 std::string dataType = father->ComponentDataType();
2933 if ( dataType != "GEOM" ) return; // not a GEOM component
2935 SALOMEDS::SObject_var objAfter;
2936 if ( row >= 0 && useCaseBuilder->HasChildren( where ) ) {
2937 // insert at given row -> find insertion position
2938 SALOMEDS::UseCaseIterator_var useCaseIt = useCaseBuilder->GetUseCaseIterator( where );
2940 for ( i = 0; i < row && useCaseIt->More(); i++, useCaseIt->Next() );
2941 if ( i == row && useCaseIt->More() ) {
2942 objAfter = useCaseIt->Value();
2946 for ( int i = 0; i < what.length(); i++ ) {
2947 SALOMEDS::SObject_var sobj = what[i];
2948 if ( CORBA::is_nil( sobj ) ) continue; // skip bad object
2949 // insert the object to the use case tree
2950 if ( !CORBA::is_nil( objAfter ) )
2951 useCaseBuilder->InsertBefore( sobj, objAfter ); // insert at given row
2953 useCaseBuilder->AppendTo( where, sobj ); // append to the end of list
2957 //=======================================================================
2958 // function : GetDependencyTree
2959 // purpose : Collects dependencies of the given objects from other ones
2960 //=======================================================================
2961 SALOMEDS::TMPFile* GEOM_Gen_i::GetDependencyTree( SALOMEDS::Study_ptr theStudy,
2962 const GEOM::string_array& theObjectEntries ) {
2963 // fill in the tree structure
2964 GEOMUtils::TreeModel tree;
2967 for ( int i = 0; i < theObjectEntries.length(); i++ ) {
2968 // process objects one-by-one
2969 entry = theObjectEntries[i].in();
2970 GEOM::GEOM_BaseObject_var anObj = GetObject( theStudy->StudyId(), entry.c_str() );
2971 if ( anObj->_is_nil() )
2973 std::map< std::string, std::set<std::string> > passedEntries;
2974 GEOMUtils::LevelsList upLevelList;
2975 // get objects from which current one depends on recursively
2976 getUpwardDependency( anObj, upLevelList, passedEntries );
2977 GEOMUtils::LevelsList downLevelList;
2978 // get objects that depends on current one recursively
2979 getDownwardDependency( anObj, downLevelList, passedEntries );
2980 tree.insert( std::pair<std::string, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList> >(entry, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList>( upLevelList, downLevelList ) ) );
2983 // translation the tree into string
2984 std::string treeStr;
2985 GEOMUtils::ConvertTreeToString( tree, treeStr );
2987 // put string into stream
2988 char* aBuffer = (char*)CORBA::string_dup(treeStr.c_str());
2989 int aBufferSize = strlen((char*)aBuffer);
2991 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
2993 SALOMEDS::TMPFile_var aStream = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
2995 return aStream._retn();
2998 //=======================================================================
2999 // function : getUpwardDependency
3000 // purpose : Collects the entries of objects on that the given one depends
3001 //=======================================================================
3002 void GEOM_Gen_i::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
3003 GEOMUtils::LevelsList &upLevelList,
3004 std::map< std::string, std::set<std::string> > &passedEntries,
3006 std::string aGboEntry = gbo->GetEntry();
3007 GEOMUtils::NodeLinks anEntries;
3008 GEOMUtils::LevelInfo aLevelMap;
3010 if ( level-1 >= upLevelList.size() ) {
3012 upLevelList.push_back( aLevelMap );
3014 // get the existent map
3015 aLevelMap = upLevelList.at(level-1);
3016 if ( aLevelMap.count( aGboEntry ) > 0 ) {
3017 anEntries = aLevelMap[ aGboEntry ];
3021 // get objects on that the current one depends
3022 GEOM::ListOfGBO_var depList = gbo->GetDependency();
3023 std::string aDepEntry;
3024 for( int j = 0; j < depList->length(); j++ ) {
3025 if ( depList[j]->_is_nil() )
3027 aDepEntry = depList[j]->GetEntry();
3028 if ( passedEntries.count( aGboEntry ) > 0 &&
3029 passedEntries[aGboEntry].count( aDepEntry ) > 0 ) {
3030 //avoid checking the passed objects
3033 passedEntries[aGboEntry].insert( aDepEntry );
3035 anEntries.push_back( aDepEntry );
3037 // get dependencies recursively
3038 getUpwardDependency(depList[j], upLevelList, passedEntries, level+1);
3041 aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGboEntry, anEntries) );
3042 upLevelList[level-1] = aLevelMap;
3046 //=======================================================================
3047 // function : getDownwardDependency
3048 // purpose : Collects the entries of objects that depends on the given one
3049 //=======================================================================
3050 void GEOM_Gen_i::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
3051 GEOMUtils::LevelsList &downLevelList,
3052 std::map< std::string, std::set<std::string> > &passedEntries,
3054 std::string aGboEntry = gbo->GetEntry();
3055 Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument(gbo->GetStudyID());
3056 Handle(TDataStd_TreeNode) aNode, aRoot;
3057 HANDLE_NAMESPACE(GEOM_Function) aFunction;
3058 if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
3059 // go through the whole OCAF tree
3060 TDataStd_ChildNodeIterator Itr( aRoot );
3061 for (; Itr.More(); Itr.Next()) {
3062 aNode = Itr.Value();
3063 aFunction = GEOM_Function::GetFunction(aNode->Label());
3064 if (aFunction.IsNull()) {
3067 TDF_Label aLabel = aFunction->GetOwnerEntry();
3068 if(aLabel.IsNull()) continue;
3069 TCollection_AsciiString anEntry;
3070 TDF_Tool::Entry(aLabel, anEntry);
3071 GEOM::GEOM_BaseObject_var geomObj = GetObject( gbo->GetStudyID(), anEntry.ToCString() );
3072 if( CORBA::is_nil( geomObj ) )
3074 // get dependencies for current object in the tree
3075 GEOM::ListOfGBO_var depList = geomObj->GetDependency();
3076 if( depList->length() == 0 )
3078 std::string aGoEntry = geomObj->GetEntry();
3079 // go through dependencies of current object to check whether it depends on the given object
3080 for( int i = 0; i < depList->length(); i++ ) {
3081 if ( depList[i]->_is_nil() )
3083 if ( depList[i]->_is_equivalent( gbo ) ) {
3084 // yes, the current object depends on the given object
3085 if ( passedEntries.count( aGoEntry ) > 0 &&
3086 passedEntries[aGoEntry].count( aGboEntry ) > 0 ) {
3087 //avoid checking the passed objects
3090 passedEntries[aGoEntry].insert( aGboEntry );
3091 GEOMUtils::NodeLinks anEntries;
3092 GEOMUtils::LevelInfo aLevelMap;
3093 anEntries.push_back( aGboEntry );
3094 if ( level >= downLevelList.size() ) {
3095 downLevelList.push_back( aLevelMap );
3097 aLevelMap = downLevelList.at(level);
3098 if ( aLevelMap.count( aGoEntry ) > 0 ) {
3099 anEntries = aLevelMap[ aGoEntry ];
3102 aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGoEntry, anEntries) );
3103 downLevelList[level] = aLevelMap;
3104 // get dependencies of the current object recursively
3105 getDownwardDependency(geomObj, downLevelList, passedEntries, level+1);
3113 //==============================================================================
3114 // function : GetEntriesToReduceStudy
3115 // purpose : Fills 3 lists that is used to clean study of redundant objects
3116 //==============================================================================
3117 void GEOM_Gen_i::GetEntriesToReduceStudy(SALOMEDS::Study_ptr theStudy,
3118 GEOM::string_array& theSelectedEntries,
3119 GEOM::string_array& theParentEntries,
3120 GEOM::string_array& theSubEntries,
3121 GEOM::string_array& theOtherEntries)
3123 std::set<std::string> aSelected, aParents, aChildren, anOthers;
3124 for ( int i = 0; i < theSelectedEntries.length(); i++ ) {
3125 aSelected.insert( CORBA::string_dup( theSelectedEntries[i] ) );
3128 Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument(theStudy->StudyId());
3129 Handle(TDataStd_TreeNode) aNode, aRoot;
3130 HANDLE_NAMESPACE(GEOM_Function) aFunction;
3131 if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
3132 // go through the whole OCAF tree
3134 std::string anEntry;
3135 TCollection_AsciiString anAsciiEntry;
3136 TDataStd_ChildNodeIterator Itr( aRoot );
3137 for (; Itr.More(); Itr.Next()) {
3138 aNode = Itr.Value();
3139 aFunction = GEOM_Function::GetFunction(aNode->Label());
3140 if (aFunction.IsNull()) {
3143 aLabel = aFunction->GetOwnerEntry();
3146 TDF_Tool::Entry(aLabel, anAsciiEntry);
3147 anEntry = anAsciiEntry.ToCString();
3148 GEOM::GEOM_BaseObject_var geomObj = GetObject( theStudy->StudyId(), anEntry.c_str() );
3149 if( CORBA::is_nil( geomObj ) )
3152 if ( aSelected.count( anEntry ) > 0 &&
3153 aParents.count( anEntry ) == 0 ) {
3154 includeParentDependencies( geomObj, aSelected, aParents, aChildren, anOthers );
3155 } else if ( aParents.count( anEntry ) == 0 &&
3156 aChildren.count( anEntry ) == 0 ) {
3157 anOthers.insert( geomObj->GetEntry() );
3161 std::set<std::string>::iterator it;
3162 std::set<std::string>::iterator foundIt;
3163 TCollection_AsciiString stringIOR;
3164 GEOM::GEOM_Object_var geomObj;
3166 // filling list of sub-objects
3167 for ( it = aSelected.begin(); it != aSelected.end(); ++it ) {
3168 includeSubObjects( theStudy, *it, aSelected, aParents, aChildren, anOthers );
3171 // if some selected object is not a main shape,
3172 // we move it's main shapes into 'selected' list,
3173 // because they could not be modified anyhow.
3174 std::set<std::string> aToBeInSelected;
3175 for ( it = aSelected.begin(); it != aSelected.end(); ++it ) {
3176 HANDLE_NAMESPACE(GEOM_BaseObject) handle_object = _impl->GetObject( theStudy->StudyId(), (*it).c_str(), false);
3177 if ( handle_object.IsNull() )
3180 stringIOR = handle_object->GetIOR();
3181 if ( !stringIOR.Length() > 1 )
3184 geomObj = GetIORFromString( stringIOR.ToCString() );
3185 while ( !geomObj->IsMainShape() ) {
3186 geomObj = geomObj->GetMainShape();
3187 anEntry = geomObj->GetEntry();
3189 foundIt = aParents.find( anEntry );
3190 if ( foundIt != aParents.end() )
3191 aParents.erase( foundIt );
3193 foundIt = aChildren.find( anEntry );
3194 if ( foundIt != aChildren.end() )
3195 aChildren.erase( foundIt );
3197 foundIt = anOthers.find( anEntry );
3198 if ( foundIt != anOthers.end() )
3199 anOthers.erase( foundIt );
3201 aToBeInSelected.insert( anEntry );
3204 aSelected.insert( aToBeInSelected.begin(), aToBeInSelected.end() );
3206 // fill the CORBA arrays with values from sets
3208 theSelectedEntries.length( aSelected.size() );
3209 for ( i = 0, it = aSelected.begin(); it != aSelected.end(); ++it, i++ )
3210 theSelectedEntries[i] = CORBA::string_dup( (*it).c_str() );
3211 theParentEntries.length( aParents.size() );
3212 for ( i = 0, it = aParents.begin(); it != aParents.end(); ++it, i++ )
3213 theParentEntries[i] = CORBA::string_dup( (*it).c_str() );
3214 theSubEntries.length( aChildren.size() );
3215 for ( i = 0, it = aChildren.begin(); it != aChildren.end(); ++it, i++ )
3216 theSubEntries[i] = CORBA::string_dup( (*it).c_str() );
3217 theOtherEntries.length( anOthers.size() );
3218 for ( i = 0, it = anOthers.begin(); it != anOthers.end(); ++it, i++ )
3219 theOtherEntries[i] = CORBA::string_dup( (*it).c_str() );
3223 //==============================================================================
3224 // function : includeParentDependencies
3226 //==============================================================================
3227 void GEOM_Gen_i::includeParentDependencies(GEOM::GEOM_BaseObject_ptr geomObj,
3228 std::set<std::string>& aSelected,
3229 std::set<std::string>& aParents,
3230 std::set<std::string>& aChildren,
3231 std::set<std::string>& anOthers)
3233 std::string anEntry = geomObj->GetEntry();
3234 if ( aSelected.count( anEntry ) == 0 ) {
3235 aParents.insert( anEntry );
3236 std::set<std::string>::iterator it;
3237 it = aChildren.find( anEntry );
3238 if ( it != aChildren.end() )
3239 aChildren.erase( it );
3240 it = anOthers.find( anEntry );
3241 if ( it != anOthers.end() )
3242 anOthers.erase( it );
3244 // get dependencies for current object in the tree
3245 GEOM::ListOfGBO_var depList = geomObj->GetDependency();
3246 if( depList->length() == 0 )
3248 // go through dependencies of current object to check whether it depends on the given object
3249 std::string aDepEntry;
3250 for( int i = 0; i < depList->length(); i++ ) {
3251 aDepEntry = depList[i]->GetEntry();
3252 if ( depList[i]->_is_nil() ||
3253 aDepEntry == anEntry || // skip self-depending
3254 aSelected.count( aDepEntry ) > 0 || // skip selected objects
3255 aParents.count( aDepEntry ) > 0 // skip already processed objects
3258 includeParentDependencies( depList[i], aSelected, aParents, aChildren, anOthers );
3262 //==============================================================================
3263 // function : includeSubObjects
3265 //==============================================================================
3266 void GEOM_Gen_i::includeSubObjects(SALOMEDS::Study_ptr theStudy,
3267 const std::string& aSelectedEntry,
3268 std::set<std::string>& aSelected,
3269 std::set<std::string>& aParents,
3270 std::set<std::string>& aChildren,
3271 std::set<std::string>& anOthers)
3273 std::set<std::string>::iterator foundIt;
3274 HANDLE_NAMESPACE(GEOM_BaseObject) handle_object = _impl->GetObject( theStudy->StudyId(), aSelectedEntry.c_str(), false);
3275 if ( handle_object.IsNull() )
3278 HANDLE_NAMESPACE(GEOM_Function) aShapeFun = handle_object->GetFunction(1);
3279 if ( aShapeFun.IsNull() || !aShapeFun->HasSubShapeReferences() )
3282 const TDataStd_ListOfExtendedString& aListEntries = aShapeFun->GetSubShapeReferences();
3283 if ( aListEntries.IsEmpty() )
3286 TDataStd_ListIteratorOfListOfExtendedString anIt (aListEntries);
3287 for ( ; anIt.More(); anIt.Next() ) {
3288 TCollection_ExtendedString aSubEntry = anIt.Value();
3289 Standard_Integer aStrLen = aSubEntry.LengthOfCString();
3290 char* aSubEntryStr = new char[aStrLen+1];
3291 aSubEntry.ToUTF8CString( aSubEntryStr );
3292 foundIt = aParents.find( aSubEntryStr );
3293 if ( foundIt == aParents.end() ) { // add to sub-objects if it is not in parents list
3294 foundIt = aSelected.find( aSubEntryStr );
3295 if ( foundIt == aSelected.end() ) { // add to sub-objects if it is not in selected list
3296 aChildren.insert( aSubEntryStr );
3297 foundIt = anOthers.find( aSubEntryStr );
3298 if ( foundIt != anOthers.end() )
3299 anOthers.erase( foundIt );
3302 includeSubObjects( theStudy, aSubEntryStr, aSelected, aParents, aChildren, anOthers );
3305 //=====================================================================================
3307 //=====================================================================================
3312 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
3316 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb,
3317 PortableServer::POA_ptr poa,
3318 PortableServer::ObjectId* contId,
3319 const char* instanceName,
3320 const char* interfaceName)
3322 GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
3323 return myGEOM_Gen_i->getId();