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