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