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