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