]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMToolsGUI/GEOMToolsGUI_1.cxx
Salome HOME
IPAL21354 Deleting of referenced father object doesn't work.
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_1.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : GEOMToolsGUI_1.cxx
24 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
25 //
26 #include <PyConsole_Console.h>
27
28 #include "GEOMToolsGUI.h"
29 #include "GEOMToolsGUI_TransparencyDlg.h"
30 #include "GEOMToolsGUI_NbIsosDlg.h"
31 #include "GEOMToolsGUI_MarkerDlg.h"
32
33 #include <GeometryGUI.h>
34 #include <GEOM_Displayer.h>
35
36 #include <GEOMBase.h>
37 #include <GEOM_Actor.h>
38
39 #include <SALOME_ListIO.hxx>
40 #include <SALOME_ListIteratorOfListIO.hxx>
41
42 #include <SOCC_Prs.h>
43
44 #include <SVTK_Prs.h>
45 #include <SVTK_ViewModel.h>
46 #include <SVTK_ViewWindow.h>
47 #include <SVTK_View.h>
48
49 #include <OCCViewer_ViewModel.h>
50
51 #include <SUIT_ViewManager.h>
52 #include <SUIT_Desktop.h>
53 #include <SUIT_ResourceMgr.h>
54 #include <SUIT_Session.h>
55 #include <SUIT_OverrideCursor.h>
56 #include <SUIT_MessageBox.h>
57
58 #include <SalomeApp_Application.h>
59 #include <SalomeApp_Study.h>
60 #include <SalomeApp_Module.h>
61
62 #include <LightApp_SelectionMgr.h>
63 #include <LightApp_NameDlg.h>
64
65 #include <GEOMImpl_Types.hxx>
66
67 #include "utilities.h"
68
69 // OCCT Includes
70 #include <AIS_Drawer.hxx>
71 #include <Prs3d_IsoAspect.hxx>
72 #include <Prs3d_PointAspect.hxx>
73 #include <Graphic3d_AspectMarker3d.hxx>
74 #include <Graphic3d_HArray1OfBytes.hxx>
75
76 // QT Includes
77 #include <QColorDialog>
78 #include <QList>
79
80 // VTK includes
81 #include <vtkRenderer.h>
82
83 void GEOMToolsGUI::OnSettingsColor()
84 {
85   SUIT_Session* sess = SUIT_Session::session();
86   SUIT_ResourceMgr* resMgr = sess->resourceMgr();
87   SUIT_Desktop* desk = sess->activeApplication()->desktop();
88
89   QColor anInitColor = resMgr->colorValue( "Geometry", "SettingsShadingColor", QColor( "yellow" ) );
90
91   QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
92   if( aDialogColor.isValid() )
93   {
94     QString type = desk->activeWindow()->getViewManager()->getType();
95     if( type != OCCViewer_Viewer::Type() && type != SVTK_Viewer::Type() )
96       MESSAGE("Settings Color is not supported for current Viewer");
97
98     resMgr->setValue( "Geometry", "SettingsShadingColor", aDialogColor );
99   }
100 }
101
102 void GEOMToolsGUI::OnRename()
103 {
104   SALOME_ListIO selected;
105   SalomeApp_Application* app =
106     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
107   if ( app ) {
108     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
109     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
110     if ( aSelMgr && appStudy ) {
111       aSelMgr->selectedObjects( selected );
112       if ( !selected.IsEmpty() ) {
113         _PTR(Study) aStudy = appStudy->studyDS();
114
115         bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
116         if ( aLocked ) {
117           SUIT_MessageBox::warning ( app->desktop(),
118                                      QObject::tr("WRN_WARNING"),
119                                      QObject::tr("WRN_STUDY_LOCKED") );
120           return;
121         }
122
123         bool isAny = false; // is there any appropriate object selected
124         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
125           Handle(SALOME_InteractiveObject) IObject = It.Value();
126
127           _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
128           _PTR(GenericAttribute) anAttr;
129           if ( obj ) {
130             if ( obj->FindAttribute(anAttr, "AttributeName") ) {
131               _PTR(AttributeName) aName (anAttr);
132
133               GEOM::GEOM_Object_var anObj =
134                 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
135               if (!CORBA::is_nil(anObj)) {
136                 isAny = true;
137                 QString newName = LightApp_NameDlg::getName( app->desktop(), aName->Value().c_str() );
138                 if (!newName.isEmpty()) {
139                   aName->SetValue( newName.toLatin1().data() ); // rename the SObject
140                   IObject->setName( newName.toLatin1().data() );// rename the InteractiveObject
141                   anObj->SetName( newName.toLatin1().data() );  // Rename the corresponding GEOM_Object
142                   (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
143                 }
144               } // if ( anObj )
145             } // if ( name attribute )
146           } // if ( obj )
147         } // iterator
148
149         if (!isAny) {
150           SUIT_MessageBox::warning( app->desktop(),
151                                     QObject::tr("WRN_WARNING"),
152                                     QObject::tr("GEOM_WRN_NO_APPROPRIATE_SELECTION") );
153           return;
154         }
155       }
156     }
157   }
158   
159   app->updateActions(); //SRN: To update a Save button in the toolbar
160 }
161
162 void GEOMToolsGUI::OnCheckGeometry()
163 {
164   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
165   PyConsole_Console* pyConsole = app->pythonConsole();
166
167   if(pyConsole)
168     pyConsole->exec("from GEOM_usinggeom import *");
169 }
170
171 void GEOMToolsGUI::OnAutoColor()
172 {
173   SALOME_ListIO selected;
174   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
175   if( !app )
176     return;
177
178   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
179   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
180   if( !aSelMgr || !appStudy )
181     return;
182
183   aSelMgr->selectedObjects( selected );
184   if( selected.IsEmpty() )
185     return;
186
187   Handle(SALOME_InteractiveObject) anIObject = selected.First();
188
189   _PTR(Study) aStudy = appStudy->studyDS();
190   _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
191   GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
192   if( CORBA::is_nil( aMainObject ) )
193     return;
194
195   aMainObject->SetAutoColor( true );
196
197   QList<SALOMEDS::Color> aReservedColors;
198
199   GEOM_Displayer aDisp (appStudy);
200
201   SALOME_View* vf = aDisp.GetActiveView();
202
203   SUIT_ViewWindow* window = app->desktop()->activeWindow();
204   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
205   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
206
207   for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
208   {
209     _PTR(SObject) aChildSObject( it->Value() );
210     GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
211     if( CORBA::is_nil( aChildObject ) )
212       continue;
213
214     if( aChildObject->GetType() != GEOM_GROUP )
215       continue;
216
217     SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
218     aChildObject->SetColor( aColor );
219     aReservedColors.append( aColor );
220
221     QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
222
223     SALOME_Prs* aPrs = vf->CreatePrs( aChildSObject->GetID().c_str() );
224
225     if ( isVTK )
226     {
227       SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
228       if ( !vtkVW )
229         return;
230       SVTK_View* aView = vtkVW->getView();
231       SUIT_OverrideCursor();
232       for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
233         aView->SetColor( It.Value(), c );
234     }
235     else if ( isOCC )
236     {
237       OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
238       Handle(AIS_InteractiveContext) ic = vm->getAISContext();
239
240       SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
241       if( !anOCCPrs )
242         continue;
243
244       AIS_ListOfInteractive aList;
245       anOCCPrs->GetObjects( aList );
246       if( !aList.Extent() )
247         continue;
248
249       Handle(AIS_InteractiveObject) io = aList.First();
250       if( io.IsNull() )
251         continue;
252
253       Quantity_Color aQuanColor( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
254
255       // Set color for a point
256       Handle(AIS_Drawer) aCurDrawer = io->Attributes();
257       Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
258       Quantity_Color aCurColor;
259       Standard_Real aCurScale;
260       Aspect_TypeOfMarker aCurTypeOfMarker;
261       aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
262       if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
263         aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
264       }
265       else {
266         Standard_Integer aWidth, aHeight;
267         aCurPointAspect->GetTextureSize( aWidth, aHeight );
268         Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
269         aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aQuanColor, 1, aWidth, aHeight, aTexture ) );
270       }
271       ic->SetLocalAttributes( io, aCurDrawer );
272
273       io->SetColor( aQuanColor );
274       if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
275         Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aQuanColor );
276
277       io->Redisplay( Standard_True );
278     }
279   }
280
281   app->updateActions(); //SRN: To update a Save button in the toolbar
282 }
283
284 void GEOMToolsGUI::OnDisableAutoColor()
285 {
286   SALOME_ListIO selected;
287   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
288   if( !app )
289     return;
290
291   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
292   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
293   if( !aSelMgr || !appStudy )
294     return;
295
296   aSelMgr->selectedObjects( selected );
297   if( selected.IsEmpty() )
298     return;
299
300   Handle(SALOME_InteractiveObject) anIObject = selected.First();
301
302   _PTR(Study) aStudy = appStudy->studyDS();
303   _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
304   GEOM::GEOM_Object_var aMainObject =  GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
305   if( CORBA::is_nil( aMainObject ) )
306     return;
307
308   aMainObject->SetAutoColor( false );
309
310 }
311
312 void GEOMToolsGUI::OnColor()
313 {
314   SALOME_ListIO selected;
315   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
316   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
317   if ( app && appStudy ) {
318     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
319     if ( aSelMgr ) {
320       aSelMgr->selectedObjects( selected );
321       if ( !selected.IsEmpty() ) {
322         SUIT_ViewWindow* window = app->desktop()->activeWindow();
323         bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
324         bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
325         if ( isVTK ) {
326           SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
327           if ( !vtkVW )
328             return;
329           SVTK_View* aView = vtkVW->getView();
330           QColor initcolor = aView->GetColor( selected.First()  );
331           QColor c = QColorDialog::getColor( initcolor, app->desktop() );
332           if ( c.isValid() ) {
333             SUIT_OverrideCursor();
334             for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
335               aView->SetColor( It.Value(), c );
336             }
337           }
338         } // if ( isVTK )
339         else if ( isOCC ) {
340           Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
341           if ( !io.IsNull() ) {
342             Quantity_Color aColor;
343             io->Color( aColor );
344             QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
345             QColor c =  QColorDialog::getColor( initcolor, app->desktop() );
346             if ( c.isValid() ) {
347               SUIT_OverrideCursor();
348               aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
349               for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
350                 io = GEOMBase::GetAIS( It.Value(), true );
351                 if ( !io.IsNull() ) {
352                   // Set color for a point
353                   OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
354                   Handle (AIS_InteractiveContext) ic = vm->getAISContext();
355                   Handle(AIS_Drawer) aCurDrawer = io->Attributes();
356                   Handle(Prs3d_PointAspect) aCurPointAspect =  aCurDrawer->PointAspect();
357                   Quantity_Color aCurColor;
358                   Standard_Real aCurScale;
359                   Aspect_TypeOfMarker aCurTypeOfMarker;
360                   aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
361                   if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
362                     aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aColor, aCurScale) );
363                   }
364                   else {
365                     Standard_Integer aWidth, aHeight;
366                     aCurPointAspect->GetTextureSize( aWidth, aHeight );
367                     Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
368                     aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aColor, 1, aWidth, aHeight, aTexture ) );
369                   }
370                   ic->SetLocalAttributes(io, aCurDrawer);
371                   
372                   io->SetColor( aColor );
373                   if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
374                     Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
375
376                   io->Redisplay( Standard_True );
377
378                   // store color to GEOM_Object
379                   _PTR(Study) aStudy = appStudy->studyDS();
380                   _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
381                   GEOM::GEOM_Object_var anObject =
382                     GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
383
384                   SALOMEDS::Color aSColor;
385                   aSColor.R = (double)c.red() / 255.0;
386                   aSColor.G = (double)c.green() / 255.0;
387                   aSColor.B = (double)c.blue() / 255.0;
388                   anObject->SetColor( aSColor );
389                   anObject->SetAutoColor( false );
390                 }
391               }
392             } // if c.isValid()
393           } // first IO is not null
394         } // if ( isOCC )
395       } // if ( selection not empty )
396     }
397   }
398   
399   app->updateActions(); //SRN: To update a Save button in the toolbar
400 }
401
402 void GEOMToolsGUI::OnTransparency()
403 {
404   GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
405   dlg.exec();
406 }
407
408 void GEOMToolsGUI::OnNbIsos()
409 {
410   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
411   
412   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
413   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
414
415   if(isOCC){ // if is OCCViewer
416
417     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
418     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
419
420     ic->InitCurrent();
421     if ( ic->MoreCurrent() ) {
422       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
423       Handle(AIS_Drawer)    CurDrawer = CurObject->Attributes();
424       
425       int UIso = CurDrawer->UIsoAspect()->Number();
426       int VIso = CurDrawer->VIsoAspect()->Number();
427       
428       GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
429         new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
430       
431       NbIsosDlg->setU( UIso );
432       NbIsosDlg->setV( VIso );
433       
434       if ( NbIsosDlg->exec() ) {
435         SUIT_OverrideCursor();
436         for(; ic->MoreCurrent(); ic->NextCurrent()) {
437           CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
438           Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
439           
440           int nbUIso = NbIsosDlg->getU();
441           int nbVIso = NbIsosDlg->getV();
442           
443           CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
444           CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
445           
446           ic->SetLocalAttributes(CurObject, CurDrawer);
447           ic->Redisplay(CurObject);
448         }
449       }
450     }
451   }
452   else if(isVTK){ // if is VTKViewer
453     //
454     // Warning. It's works incorrect. must be recheked.
455     //
456     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
457     if ( !app )
458       return;
459     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
460     if ( !aSelMgr )
461       return;
462     SALOME_ListIO selected;
463     aSelMgr->selectedObjects( selected );
464     if ( selected.IsEmpty() )
465       return;
466     
467     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
468     if ( !vtkVW )
469       return;
470
471     SALOME_View* view = GEOM_Displayer::GetActiveView();
472
473     vtkActorCollection* aCollection = vtkActorCollection::New();
474     
475     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
476       Handle(SALOME_InteractiveObject) anIObject = It.Value();
477       SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() ); 
478       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
479       if ( vtkPrs ) {
480         vtkActorCollection* anActors = vtkPrs->GetObjects();
481         anActors->InitTraversal();
482         vtkActor* anAct = anActors->GetNextActor();
483         aCollection->AddItem(anAct);
484       }
485     }
486   
487     if(aCollection)
488       aCollection->InitTraversal();
489     else
490       return;
491    
492     int UIso = 0;
493     int VIso = 0;
494     
495     vtkActor* anAct = aCollection->GetNextActor();
496     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
497       anActor->GetNbIsos(UIso,VIso);
498     else
499       return;
500     
501     GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
502       new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
503
504     NbIsosDlg->setU( UIso );
505     NbIsosDlg->setV( VIso );
506
507     if ( NbIsosDlg->exec() ) {
508       SUIT_OverrideCursor();
509       
510       while( anAct!=NULL ) {
511         if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
512           // There are no casting to needed actor.
513           UIso = NbIsosDlg->getU();
514           VIso = NbIsosDlg->getV();
515           int aIsos[2]={UIso,VIso};
516           anActor->SetNbIsos(aIsos);
517         }
518         anAct = aCollection->GetNextActor();
519       }
520     }
521   } // end vtkviewer
522 }
523
524 void GEOMToolsGUI::OnOpen()
525 {
526 /*
527   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
528   _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
529
530   SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
531   Handle(SALOME_InteractiveObject) anIObject;
532   for(;It.More();It.Next()) {
533     anIObject = It.Value();
534     _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
535     _PTR(AttributePersistentRef) aPersist;
536     _PTR(AttributeIOR) anIOR;
537     if(obj) {
538       // this SObject may be GEOM module root SObject
539       _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
540       _PTR(GenericAttribute) anAttr;
541       bool useSubItems = false;
542       while (anIter->More() && !useSubItems) {
543         _PTR(SObject) subobj ( anIter->Value() );
544         if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
545           useSubItems = true;
546           obj =  subobj;
547         }
548         else
549           anIter->Next();
550       }
551       obj->FindAttribute(anAttr, "AttributePersistentRef");
552
553       while(useSubItems?anIter->More():!anAttr->_is_nil()) {
554         if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
555            obj->FindAttribute(anAttr, "AttributePersistentRef")) {
556           _PTR(SComponent) FComp ( obj->GetFatherComponent() );
557           if (FComp) {
558             if (FComp->FindAttribute(anAttr, "AttributeName")) {
559               _PTR(AttributeName) aName ( anAttr );
560               QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
561               //                    parent->loadComponentData(parent->getComponentName(aName->Value()));
562               Engines::Component_var comp ;
563               if ( compName.compare("SUPERV") == 0 ) {
564                 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
565               }
566               else {
567                 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
568                 if ( comp->_is_nil() )
569                   comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
570               }
571
572               if (!CORBA::is_nil(comp)) {
573                 SALOMEDS::Driver_var   driver = SALOMEDS::Driver::_narrow(comp);
574                 if (!CORBA::is_nil(driver)) {
575                   SALOMEDS::StudyBuilder_var  B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
576                   if (!CORBA::is_nil(B)) {
577                     B->LoadWith(FComp,driver);
578                   } else {
579                     return;
580                   }
581                 }
582                 else {
583                   MESSAGE("loadComponentData(): Driver is null");
584                   return;
585                 }
586               }
587               else {
588                 MESSAGE("loadComponentData(): Engine is null");
589                 return;
590               }
591                 //              // load
592                 //              Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
593                 //              if (!CORBA::is_nil(comp)) {
594                 //                SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
595                 //                SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
596                 //                SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
597                 //                if (!CORBA::is_nil(SC))
598                 //                  aStudyBuilder->LoadWith(SC,driver);
599             }
600           }
601           else {
602             MESSAGE("Component is null");
603           }
604         }
605         if(useSubItems) {
606           anIter->Next();
607           obj.reset( anIter->Value() );
608         }
609         else
610           anAttr = NULL;
611       }
612     }
613   }
614 */
615 }
616
617 void GEOMToolsGUI::OnSelectOnly(int mode)
618 {
619   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
620   if ( app ) {
621     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
622     GEOM_Displayer aDisp (appStudy);
623     aDisp.GlobalSelection(mode);
624     getGeometryGUI()->setLocalSelectionMode(mode);
625   }
626 }
627
628 void GEOMToolsGUI::OnShowHideChildren( bool show )
629 {
630   SALOME_ListIO selected;
631   SalomeApp_Application* app =
632     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
633   if ( app ) {
634     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
635     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
636     if ( aSelMgr && appStudy ) {
637       aSelMgr->selectedObjects( selected );
638       if ( !selected.IsEmpty() ) {
639         _PTR(Study) aStudy = appStudy->studyDS();
640         _PTR(StudyBuilder) B = aStudy->NewBuilder();
641
642         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
643         if ( aLocked ) {
644           SUIT_MessageBox::warning( app->desktop(),
645                                     QObject::tr( "WRN_WARNING" ),
646                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
647           return;
648         }
649
650         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
651           Handle(SALOME_InteractiveObject) IObject = It.Value();
652
653           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
654           _PTR(GenericAttribute) anAttr;
655           if ( obj ) {
656             _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
657             aExp->SetExpandable( show );
658           } // if ( obj )
659         } // iterator
660       }
661     }
662     app->updateObjectBrowser( false );
663     app->updateActions();
664   }
665 }
666
667 void GEOMToolsGUI::OnPointMarker()
668 {
669   GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
670   dlg.exec();
671 }