]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMToolsGUI/GEOMToolsGUI_1.cxx
Salome HOME
GDD & CCAR:
[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               OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
344               Handle (AIS_InteractiveContext) ic = vm->getAISContext();
345               for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
346                 io = GEOMBase::GetAIS( It.Value(), true );
347                 if ( !io.IsNull() ) {
348                   
349                   if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) {
350                     TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape();
351                     if (theShape.ShapeType() == TopAbs_VERTEX) {
352                       // Set color for a point
353
354                       Handle(AIS_Drawer) aCurDrawer = io->Attributes();
355                       Handle(Prs3d_PointAspect) aCurPointAspect =  aCurDrawer->PointAspect();
356                       Quantity_Color aCurColor;
357                       Standard_Real aCurScale;
358                       Aspect_TypeOfMarker aCurTypeOfMarker;
359                       aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
360                       if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
361                         aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aCurTypeOfMarker, aColor, aCurScale));
362                       }
363                       else {
364                         Standard_Integer aWidth, aHeight;
365                         aCurPointAspect->GetTextureSize( aWidth, aHeight );
366                         Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
367                         aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aColor, 1, aWidth, aHeight, aTexture));
368                       }
369                       ic->SetLocalAttributes(io, aCurDrawer, Standard_False);
370                     }
371                   }
372
373                   io->SetColor( aColor );
374                   if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
375                     Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
376
377                   io->Redisplay( Standard_True );
378
379                   // store color to GEOM_Object
380                   _PTR(Study) aStudy = appStudy->studyDS();
381                   _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
382                   GEOM::GEOM_Object_var anObject =
383                     GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
384
385                   SALOMEDS::Color aSColor;
386                   aSColor.R = (double)c.red() / 255.0;
387                   aSColor.G = (double)c.green() / 255.0;
388                   aSColor.B = (double)c.blue() / 255.0;
389                   anObject->SetColor( aSColor );
390                   anObject->SetAutoColor( false );
391                 }
392               } // for
393               ic->UpdateCurrentViewer();
394               GeometryGUI::Modified();
395             } // if c.isValid()
396           } // first IO is not null
397         } // if ( isOCC )
398       } // if ( selection not empty )
399     }
400   }
401
402   app->updateActions(); //SRN: To update a Save button in the toolbar
403 }
404
405 void GEOMToolsGUI::OnTransparency()
406 {
407   GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
408   dlg.exec();
409 }
410
411 void GEOMToolsGUI::OnChangeTransparency( bool increase )
412 {
413  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
414   if ( !app )
415     return;
416   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
417   if ( !aSelMgr )
418     return;
419   SALOME_ListIO selected;
420   aSelMgr->selectedObjects( selected );
421   if ( selected.IsEmpty() )
422     return;
423
424   Handle(SALOME_InteractiveObject) FirstIOS =  selected.First();
425   if ( FirstIOS.IsNull() )
426     return;
427
428   // Delta
429   float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
430   if ( !increase )
431     delta *= -1;
432         
433   SUIT_ViewWindow* window = app->desktop()->activeWindow();
434   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
435   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
436
437   if ( isVTK ) {
438     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
439     if ( !vtkVW )
440       return;
441     SVTK_View* aView = vtkVW->getView();
442    
443     float transp = aView->GetTransparency(FirstIOS);
444     
445     // Compute new transparency value
446     transp = transp + delta;
447     if ( transp < 0 )
448       transp = 0;
449     else if ( transp > 1 )
450       transp = 1;
451
452     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
453       aView->SetTransparency( It.Value(), transp );
454     }
455     aView->Repaint();
456     GeometryGUI::Modified();
457   } // if ( isVTK )
458         
459   else if ( isOCC ) {
460     GEOMBase* gb = new GEOMBase();
461     Standard_Boolean found;
462     Handle(GEOM_AISShape) aisShape;
463    
464     aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, found );
465     if( !found )
466       return;
467     float transp = aisShape->Transparency();
468
469     // Compute new transparency value
470     transp = transp + delta;
471     if ( transp < 0 )
472       transp = 0;
473     else if ( transp > 1 )
474       transp = 1;
475
476     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
477     if ( !vm )
478       return;
479     Handle(AIS_InteractiveContext) ic = vm->getAISContext();
480     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
481       aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), found );
482       if ( found ) {
483         ic->SetTransparency( aisShape, transp, false );
484         ic->Redisplay( aisShape, Standard_False, Standard_True );
485       }
486     } // for...
487     ic->UpdateCurrentViewer();
488     GeometryGUI::Modified();
489   } // if ( isOCC )
490 }
491
492 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
493 {
494   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
495
496   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
497   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
498
499   if(isOCC){ // if is OCCViewer
500
501     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
502     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
503
504     ic->InitCurrent();
505     if ( ic->MoreCurrent() ) {
506       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
507       Handle(AIS_Drawer)    CurDrawer = CurObject->Attributes();
508
509       int UIso = CurDrawer->UIsoAspect()->Number();
510       int VIso = CurDrawer->VIsoAspect()->Number();
511
512       int newNbUIso = -1;
513       int newNbVIso = -1;
514
515       if ( actionType == SHOWDLG ) {
516         GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
517           new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
518
519         NbIsosDlg->setU( UIso );
520         NbIsosDlg->setV( VIso );
521
522         if ( NbIsosDlg->exec() ) {
523           SUIT_OverrideCursor();
524           
525           newNbUIso = NbIsosDlg->getU();
526           newNbVIso = NbIsosDlg->getV();
527         }
528       }
529       else if ( actionType == INCR || actionType == DECR ) {
530         int delta = 1;
531         if (actionType == DECR)
532           delta = -1;
533         
534         newNbUIso = UIso + delta;
535         newNbVIso = VIso + delta;
536
537         if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
538           return;
539       }
540
541       for(; ic->MoreCurrent(); ic->NextCurrent()) {
542         CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
543         Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
544         
545         CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbUIso) );
546         CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbVIso) );
547         
548         ic->SetLocalAttributes(CurObject, CurDrawer);
549         ic->Redisplay(CurObject);
550       }
551     }
552     GeometryGUI::Modified();
553   }
554   else if(isVTK){ // if is VTKViewer
555     //
556     // Warning. It's works incorrect. must be recheked.
557     //
558     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
559       ( SUIT_Session::session()->activeApplication() );
560     if ( !app )
561       return;
562     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
563     if ( !aSelMgr )
564       return;
565     SALOME_ListIO selected;
566     aSelMgr->selectedObjects( selected );
567     if ( selected.IsEmpty() )
568       return;
569
570     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
571     if ( !vtkVW )
572       return;
573
574     SALOME_View* view = GEOM_Displayer::GetActiveView();
575
576     vtkActorCollection* aCollection = vtkActorCollection::New();
577
578     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
579       Handle(SALOME_InteractiveObject) anIObject = It.Value();
580       SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
581       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
582       if ( vtkPrs ) {
583         vtkActorCollection* anActors = vtkPrs->GetObjects();
584         anActors->InitTraversal();
585         vtkActor* anAct = anActors->GetNextActor();
586         aCollection->AddItem(anAct);
587       }
588     }
589
590     if(aCollection)
591       aCollection->InitTraversal();
592     else
593       return;
594
595     int UIso = 0;
596     int VIso = 0;
597
598     vtkActor* anAct = aCollection->GetNextActor();
599     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
600       anActor->GetNbIsos(UIso,VIso);
601     else
602       return;
603     
604     int newNbUIso = -1;
605     int newNbVIso = -1;
606
607     if ( actionType == SHOWDLG ) {
608       GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
609         new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
610
611       NbIsosDlg->setU( UIso );
612       NbIsosDlg->setV( VIso );
613
614       if ( NbIsosDlg->exec() ) {
615         SUIT_OverrideCursor();
616
617         newNbUIso = NbIsosDlg->getU();
618         newNbVIso = NbIsosDlg->getV();
619       }
620     }
621     else if ( actionType == INCR || actionType == DECR ) {
622       int delta = 1;
623       if (actionType == DECR)
624         delta = -1;
625       
626       newNbUIso = UIso + delta;
627       newNbVIso = VIso + delta;
628       
629       if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
630         return;
631     } 
632     
633     while( anAct!=NULL ) {
634       if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
635         // There are no casting to needed actor.
636         int aIsos[2]={newNbUIso,newNbVIso};
637         anActor->SetNbIsos(aIsos);
638       }
639       anAct = aCollection->GetNextActor();
640     }
641     view->Repaint();
642     GeometryGUI::Modified();
643   } // end vtkviewer
644 }
645
646 void GEOMToolsGUI::OnDeflection()
647 {
648   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
649
650   bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
651   bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
652
653   if (isOCC) { // if is OCCViewer
654     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
655     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
656
657     ic->InitCurrent();
658     if (ic->MoreCurrent()) {
659       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
660
661       Standard_Real aDC, aPrevDC;
662       Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
663       if (!isOwnDC)
664         aDC = ic->DeviationCoefficient();
665
666       GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
667         (SUIT_Session::session()->activeApplication()->desktop());
668       DeflectionDlg->setTheDC(aDC);
669       double aNewDC = 0.0;
670       bool ok = false;
671       while (!ok) {
672         if (DeflectionDlg->exec()) {
673           SUIT_OverrideCursor();
674           aNewDC = DeflectionDlg->getTheDC();
675           ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
676           if (ok) {
677             for (; ic->MoreCurrent(); ic->NextCurrent()) {
678               CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
679               ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
680               ic->Redisplay(CurObject);
681             }
682           }
683         }
684         else {
685           ok = true;
686         }
687       }
688     }
689     GeometryGUI::Modified();
690   }
691   else if (isVTK) { // if is VTKViewer
692     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
693       (SUIT_Session::session()->activeApplication());
694     if (!app)
695       return;
696
697     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
698     if (!aSelMgr)
699       return;
700
701     SALOME_ListIO selected;
702     aSelMgr->selectedObjects(selected);
703     if (selected.IsEmpty())
704       return;
705
706     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
707     if (!vtkVW)
708       return;
709
710     SALOME_View* view = GEOM_Displayer::GetActiveView();
711
712     vtkActorCollection* aCollection = vtkActorCollection::New();
713
714     for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
715       Handle(SALOME_InteractiveObject) anIObject = It.Value();
716       SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
717       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
718       if (vtkPrs) {
719         vtkActorCollection* anActors = vtkPrs->GetObjects();
720         anActors->InitTraversal();
721         vtkActor* anAct = anActors->GetNextActor();
722         aCollection->AddItem(anAct);
723       }
724     }
725
726     if (aCollection)
727       aCollection->InitTraversal();
728     else
729       return;
730
731     double aDC = 0.;
732
733     vtkActor* anAct = aCollection->GetNextActor();
734     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
735       aDC = anActor->GetDeflection();
736     else
737       return;
738
739     GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
740       (SUIT_Session::session()->activeApplication()->desktop());
741     DeflectionDlg->setTheDC(aDC);
742     if (DeflectionDlg->exec()) {
743       SUIT_OverrideCursor();
744       aDC = DeflectionDlg->getTheDC();
745       while (anAct != NULL) {
746         if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
747           // There are no casting to needed actor.
748           bool isRel = anActor->GetIsRelative();
749           anActor->SetDeflection(aDC, isRel);
750         }
751         anAct = aCollection->GetNextActor();
752       }
753     }
754     GeometryGUI::Modified();
755   } // end vtkviewer
756 }
757
758 void GEOMToolsGUI::OnSelectOnly(int mode)
759 {
760   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
761   if ( app ) {
762     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
763     GEOM_Displayer aDisp (appStudy);
764     aDisp.GlobalSelection(mode);
765     getGeometryGUI()->setLocalSelectionMode(mode);
766   }
767 }
768
769 void GEOMToolsGUI::OnShowHideChildren( bool show )
770 {
771   SALOME_ListIO selected;
772   SalomeApp_Application* app =
773     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
774   if ( app ) {
775     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
776     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
777     if ( aSelMgr && appStudy ) {
778       aSelMgr->selectedObjects( selected );
779       if ( !selected.IsEmpty() ) {
780         _PTR(Study) aStudy = appStudy->studyDS();
781         _PTR(StudyBuilder) B = aStudy->NewBuilder();
782
783         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
784         if ( aLocked ) {
785           SUIT_MessageBox::warning( app->desktop(),
786                                     QObject::tr( "WRN_WARNING" ),
787                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
788           return;
789         }
790
791         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
792           Handle(SALOME_InteractiveObject) IObject = It.Value();
793
794           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
795           _PTR(GenericAttribute) anAttr;
796           if ( obj ) {
797             _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
798             aExp->SetExpandable( show );
799           } // if ( obj )
800         } // iterator
801       }
802     }
803     app->updateObjectBrowser( false );
804     app->updateActions();
805   }
806 }
807
808 void GEOMToolsGUI::OnPointMarker()
809 {
810   GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
811   dlg.exec();
812 }