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