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