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