Salome HOME
Mantis issue 0020626: EDF 1200 GEOM: the discretisation of the circles in the OCC...
[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       double aNewDC = 0.0;
561       bool ok = false;
562       while (!ok) {
563         if (DeflectionDlg->exec()) {
564           SUIT_OverrideCursor();
565           aNewDC = DeflectionDlg->getDC();
566           ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
567           if (ok) {
568             for (; ic->MoreCurrent(); ic->NextCurrent()) {
569               CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
570               ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
571               ic->Redisplay(CurObject);
572             }
573           }
574         }
575         else {
576           ok = true;
577         }
578       }
579     }
580   }
581   else if (isVTK) { // if is VTKViewer
582     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
583       (SUIT_Session::session()->activeApplication());
584     if (!app)
585       return;
586
587     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
588     if (!aSelMgr)
589       return;
590
591     SALOME_ListIO selected;
592     aSelMgr->selectedObjects(selected);
593     if (selected.IsEmpty())
594       return;
595
596     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
597     if (!vtkVW)
598       return;
599
600     SALOME_View* view = GEOM_Displayer::GetActiveView();
601
602     vtkActorCollection* aCollection = vtkActorCollection::New();
603
604     for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
605       Handle(SALOME_InteractiveObject) anIObject = It.Value();
606       SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
607       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
608       if (vtkPrs) {
609         vtkActorCollection* anActors = vtkPrs->GetObjects();
610         anActors->InitTraversal();
611         vtkActor* anAct = anActors->GetNextActor();
612         aCollection->AddItem(anAct);
613       }
614     }
615
616     if (aCollection)
617       aCollection->InitTraversal();
618     else
619       return;
620
621     double aDC = 0.;
622
623     vtkActor* anAct = aCollection->GetNextActor();
624     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
625       aDC = anActor->GetDeflection();
626     else
627       return;
628
629     GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
630       (SUIT_Session::session()->activeApplication()->desktop());
631     DeflectionDlg->setDC(aDC);
632     if (DeflectionDlg->exec()) {
633       SUIT_OverrideCursor();
634       aDC = DeflectionDlg->getDC();
635       while (anAct != NULL) {
636         if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
637           // There are no casting to needed actor.
638           bool isRel = anActor->GetIsRelative();
639           anActor->SetDeflection(aDC, isRel);
640         }
641         anAct = aCollection->GetNextActor();
642       }
643     }
644   } // end vtkviewer
645 }
646
647 void GEOMToolsGUI::OnOpen()
648 {
649 /*
650   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
651   _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
652
653   SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
654   Handle(SALOME_InteractiveObject) anIObject;
655   for(;It.More();It.Next()) {
656     anIObject = It.Value();
657     _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
658     _PTR(AttributePersistentRef) aPersist;
659     _PTR(AttributeIOR) anIOR;
660     if(obj) {
661       // this SObject may be GEOM module root SObject
662       _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
663       _PTR(GenericAttribute) anAttr;
664       bool useSubItems = false;
665       while (anIter->More() && !useSubItems) {
666         _PTR(SObject) subobj ( anIter->Value() );
667         if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
668           useSubItems = true;
669           obj =  subobj;
670         }
671         else
672           anIter->Next();
673       }
674       obj->FindAttribute(anAttr, "AttributePersistentRef");
675
676       while(useSubItems?anIter->More():!anAttr->_is_nil()) {
677         if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
678            obj->FindAttribute(anAttr, "AttributePersistentRef")) {
679           _PTR(SComponent) FComp ( obj->GetFatherComponent() );
680           if (FComp) {
681             if (FComp->FindAttribute(anAttr, "AttributeName")) {
682               _PTR(AttributeName) aName ( anAttr );
683               QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
684               //                    parent->loadComponentData(parent->getComponentName(aName->Value()));
685               Engines::Component_var comp ;
686               if ( compName.compare("SUPERV") == 0 ) {
687                 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
688               }
689               else {
690                 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
691                 if ( comp->_is_nil() )
692                   comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
693               }
694
695               if (!CORBA::is_nil(comp)) {
696                 SALOMEDS::Driver_var   driver = SALOMEDS::Driver::_narrow(comp);
697                 if (!CORBA::is_nil(driver)) {
698                   SALOMEDS::StudyBuilder_var  B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
699                   if (!CORBA::is_nil(B)) {
700                     B->LoadWith(FComp,driver);
701                   } else {
702                     return;
703                   }
704                 }
705                 else {
706                   MESSAGE("loadComponentData(): Driver is null");
707                   return;
708                 }
709               }
710               else {
711                 MESSAGE("loadComponentData(): Engine is null");
712                 return;
713               }
714                 //              // load
715                 //              Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
716                 //              if (!CORBA::is_nil(comp)) {
717                 //                SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
718                 //                SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
719                 //                SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
720                 //                if (!CORBA::is_nil(SC))
721                 //                  aStudyBuilder->LoadWith(SC,driver);
722             }
723           }
724           else {
725             MESSAGE("Component is null");
726           }
727         }
728         if(useSubItems) {
729           anIter->Next();
730           obj.reset( anIter->Value() );
731         }
732         else
733           anAttr = NULL;
734       }
735     }
736   }
737 */
738 }
739
740 void GEOMToolsGUI::OnSelectOnly(int mode)
741 {
742   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
743   if ( app ) {
744     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
745     GEOM_Displayer aDisp (appStudy);
746     aDisp.GlobalSelection(mode);
747     getGeometryGUI()->setLocalSelectionMode(mode);
748   }
749 }
750
751 void GEOMToolsGUI::OnShowHideChildren( bool show )
752 {
753   SALOME_ListIO selected;
754   SalomeApp_Application* app =
755     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
756   if ( app ) {
757     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
758     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
759     if ( aSelMgr && appStudy ) {
760       aSelMgr->selectedObjects( selected );
761       if ( !selected.IsEmpty() ) {
762         _PTR(Study) aStudy = appStudy->studyDS();
763         _PTR(StudyBuilder) B = aStudy->NewBuilder();
764
765         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
766         if ( aLocked ) {
767           SUIT_MessageBox::warning( app->desktop(),
768                                     QObject::tr( "WRN_WARNING" ),
769                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
770           return;
771         }
772
773         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
774           Handle(SALOME_InteractiveObject) IObject = It.Value();
775
776           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
777           _PTR(GenericAttribute) anAttr;
778           if ( obj ) {
779             _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
780             aExp->SetExpandable( show );
781           } // if ( obj )
782         } // iterator
783       }
784     }
785     app->updateObjectBrowser( false );
786     app->updateActions();
787   }
788 }
789
790 void GEOMToolsGUI::OnPointMarker()
791 {
792   GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
793   dlg.exec();
794 }