]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMToolsGUI/GEOMToolsGUI_1.cxx
Salome HOME
Mantis issue 0021432: EDF GEOM: Faces with huge tolerance can be built in GEOM.
[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)::DownCast( io )->SetShadingColor( aColor );
345
346                   appStudy->setObjectProperty(mgrId,It.Value()->getEntry(), COLOR_PROP, c);
347
348                   io->Redisplay( Standard_True );
349
350                   // store color to GEOM_Object
351                   _PTR(Study) aStudy = appStudy->studyDS();
352                   _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
353                   GEOM::GEOM_Object_var anObject =
354                     GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
355
356
357                   SALOMEDS::Color aSColor;
358                   aSColor.R = (double)c.red() / 255.0;
359                   aSColor.G = (double)c.green() / 255.0;
360                   aSColor.B = (double)c.blue() / 255.0;
361                   anObject->SetColor( aSColor );
362                   anObject->SetAutoColor( false );
363                 }
364               } // for
365               ic->UpdateCurrentViewer();
366               GeometryGUI::Modified();
367             } // if c.isValid()
368           } // first IO is not null
369         } // if ( isOCC )
370       } // if ( selection not empty )
371     }
372   }
373
374   app->updateActions(); //SRN: To update a Save button in the toolbar
375 }
376
377 void GEOMToolsGUI::OnTexture()
378 {
379   SALOME_ListIO selected;
380   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
381   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
382   if ( app && appStudy ) {
383     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
384     if ( aSelMgr ) {
385       aSelMgr->selectedObjects( selected );
386       if ( !selected.IsEmpty() ) {
387         SUIT_ViewWindow* window = app->desktop()->activeWindow();
388         bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
389         int mgrId = window->getViewManager()->getGlobalId();
390         if ( isOCC ) {
391           QString aTexture = QFileDialog::getOpenFileName(window,tr( "GEOM_SELECT_IMAGE"),QString(), tr("OCC_IMAGE_FILES"));
392           if( !aTexture.isEmpty() )
393           {
394             SUIT_OverrideCursor();
395             OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
396             Handle (AIS_InteractiveContext) ic = vm->getAISContext();
397             Handle(AIS_InteractiveObject) io ;
398             for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
399               io = GEOMBase::GetAIS( It.Value(), true );
400               if ( !io.IsNull() ) {
401                 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
402                   Handle(GEOM_AISShape)::DownCast( io )->SetTextureFileName(TCollection_AsciiString(aTexture.toStdString().c_str()));
403                 io->Redisplay( Standard_True );
404               } // if ( !io.IsNull() )
405             } // for
406             ic->UpdateCurrentViewer();
407             GeometryGUI::Modified();
408             GeometryGUI* myGeomGUI = getGeometryGUI();
409             myGeomGUI->OnGUIEvent(GEOMOp::OpTexture);
410           } // if ( !selFile.isEmpty() )
411         } // if ( isOCC )
412       } // if ( selection not empty )
413     }
414   }
415
416   app->updateActions(); //SRN: To update a Save button in the toolbar
417 }
418
419 void GEOMToolsGUI::OnTransparency()
420 {
421   GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
422   dlg.exec();
423 }
424
425 void GEOMToolsGUI::OnChangeTransparency( bool increase )
426 {
427  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
428   if ( !app )
429     return;
430   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
431   if ( !aSelMgr )
432     return;
433   SALOME_ListIO selected;
434   aSelMgr->selectedObjects( selected );
435   if ( selected.IsEmpty() )
436     return;
437
438   Handle(SALOME_InteractiveObject) FirstIOS =  selected.First();
439   if ( FirstIOS.IsNull() )
440     return;
441
442   // Delta
443   float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
444   if ( !increase )
445     delta *= -1;
446         
447   SUIT_ViewWindow* window = app->desktop()->activeWindow();
448   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
449   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
450
451   if ( isVTK ) {
452     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
453     if ( !vtkVW )
454       return;
455     SVTK_View* aView = vtkVW->getView();
456    
457     float transp = aView->GetTransparency(FirstIOS);
458     
459     // Compute new transparency value
460     transp = transp + delta;
461     if ( transp < 0 )
462       transp = 0;
463     else if ( transp > 1 )
464       transp = 1;
465
466     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
467       aView->SetTransparency( It.Value(), transp );
468     }
469     aView->Repaint();
470     GeometryGUI::Modified();
471   } // if ( isVTK )
472         
473   else if ( isOCC ) {
474     GEOMBase* gb = new GEOMBase();
475     Handle(GEOM_AISShape) aisShape;
476    
477     aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
478     if( aisShape.IsNull() )
479       return;
480     float transp = aisShape->Transparency();
481
482     // Compute new transparency value
483     transp = transp + delta;
484     if ( transp < 0 )
485       transp = 0;
486     else if ( transp > 1 )
487       transp = 1;
488
489     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
490     if ( !vm )
491       return;
492     Handle(AIS_InteractiveContext) ic = vm->getAISContext();
493     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
494       aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
495       if ( !aisShape.IsNull() ) {
496         ic->SetTransparency( aisShape, transp, false );
497         ic->Redisplay( aisShape, Standard_False, Standard_True );
498       }
499     } // for...
500     ic->UpdateCurrentViewer();
501     GeometryGUI::Modified();
502   } // if ( isOCC )
503 }
504
505 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
506 {
507   SalomeApp_Application* app =
508     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
509   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
510   SUIT_ViewWindow* window = app->desktop()->activeWindow();
511
512   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
513   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
514
515   if(isOCC){ // if is OCCViewer
516
517     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
518     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
519
520     ic->InitCurrent();
521     if ( ic->MoreCurrent() ) {
522       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
523       CurObject->restoreIsoNumbers();
524       Handle(AIS_Drawer)    CurDrawer = CurObject->Attributes();
525
526       int UIso = CurDrawer->UIsoAspect()->Number();
527       int VIso = CurDrawer->VIsoAspect()->Number();
528
529       int newNbUIso = -1;
530       int newNbVIso = -1;
531
532       if ( actionType == SHOWDLG ) {
533         GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
534           new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
535
536         NbIsosDlg->setU( UIso );
537         NbIsosDlg->setV( VIso );
538
539         if ( NbIsosDlg->exec() ) {
540           SUIT_OverrideCursor();
541           
542           newNbUIso = NbIsosDlg->getU();
543           newNbVIso = NbIsosDlg->getV();
544         } else //Cancel case
545           return;
546       }
547       else if ( actionType == INCR || actionType == DECR ) {
548         int delta = 1;
549         if (actionType == DECR)
550           delta = -1;
551         
552         newNbUIso = UIso + delta;
553         newNbVIso = VIso + delta;
554
555         if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
556           return;
557       }
558
559       for(; ic->MoreCurrent(); ic->NextCurrent()) {
560         CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
561
562         Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
563
564         CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbUIso) );
565         CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbVIso) );
566
567         CurObject->storeIsoNumbers();
568         
569         ic->SetLocalAttributes(CurObject, CurDrawer);
570         ic->Redisplay(CurObject);
571
572         QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
573         int aMgrId = window->getViewManager()->getGlobalId();
574         aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_PROP, anIsos);
575       }
576     }
577     GeometryGUI::Modified();
578   }
579   else if(isVTK){ // if is VTKViewer
580     //
581     // Warning. It's works incorrect. must be recheked.
582     //
583     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
584       ( SUIT_Session::session()->activeApplication() );
585     if ( !app )
586       return;
587     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
588     if ( !aSelMgr )
589       return;
590     SALOME_ListIO selected;
591     aSelMgr->selectedObjects( selected );
592     if ( selected.IsEmpty() )
593       return;
594
595     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
596     if ( !vtkVW )
597       return;
598
599     SALOME_View* view = GEOM_Displayer::GetActiveView();
600
601     vtkActorCollection* aCollection = vtkActorCollection::New();
602
603     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
604       Handle(SALOME_InteractiveObject) anIObject = It.Value();
605       SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
606       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
607       if ( vtkPrs ) {
608         vtkActorCollection* anActors = vtkPrs->GetObjects();
609         anActors->InitTraversal();
610         vtkActor* anAct = anActors->GetNextActor();
611         aCollection->AddItem(anAct);
612       }
613     }
614
615     if(aCollection)
616       aCollection->InitTraversal();
617     else
618       return;
619
620     int UIso = 0;
621     int VIso = 0;
622
623     vtkActor* anAct = aCollection->GetNextActor();
624     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
625       anActor->RestoreIsoNumbers();
626       anActor->GetNbIsos(UIso,VIso);
627     }
628     else
629       return;
630     
631     int newNbUIso = -1;
632     int newNbVIso = -1;
633
634     if ( actionType == SHOWDLG ) {
635       GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
636         new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
637
638       NbIsosDlg->setU( UIso );
639       NbIsosDlg->setV( VIso );
640
641       if ( NbIsosDlg->exec() ) {
642         SUIT_OverrideCursor();
643
644         newNbUIso = NbIsosDlg->getU();
645         newNbVIso = NbIsosDlg->getV();
646       } else 
647         return; //Cancel case 
648     }
649     else if ( actionType == INCR || actionType == DECR ) {
650       int delta = 1;
651       if (actionType == DECR)
652         delta = -1;
653       
654       newNbUIso = UIso + delta;
655       newNbVIso = VIso + delta;
656       
657       if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
658         return;
659     } 
660     
661     while( anAct!=NULL ) {
662       if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
663         // There are no casting to needed actor.
664         int aIsos[2]={newNbUIso,newNbVIso};
665         anActor->SetNbIsos(aIsos);
666         anActor->StoreIsoNumbers();
667
668         QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
669         int aMgrId = window->getViewManager()->getGlobalId();
670         aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos);
671       }
672       anAct = aCollection->GetNextActor();
673     }
674     view->Repaint();
675     GeometryGUI::Modified();
676   } // end vtkviewer
677 }
678
679 void GEOMToolsGUI::OnDeflection()
680 {
681   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
682   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
683
684
685   bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
686   bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
687   int mgrId = window->getViewManager()->getGlobalId();
688
689   if (isOCC) { // if is OCCViewer
690     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
691     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
692
693     ic->InitCurrent();
694     if (ic->MoreCurrent()) {
695       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
696
697       Standard_Real aDC, aPrevDC;
698       Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
699       if (!isOwnDC)
700         aDC = ic->DeviationCoefficient();
701
702       GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
703         (SUIT_Session::session()->activeApplication()->desktop());
704       DeflectionDlg->setTheDC(aDC);
705       double aNewDC = 0.0;
706       bool ok = false;
707       while (!ok) {
708         if (DeflectionDlg->exec()) {
709           SUIT_OverrideCursor();
710           aNewDC = DeflectionDlg->getTheDC();
711           ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
712           if (ok) {
713             for (; ic->MoreCurrent(); ic->NextCurrent()) {
714               CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
715               ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
716               ic->Redisplay(CurObject);
717               appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC);
718             }
719           }
720         }
721         else {
722           ok = true;
723         }
724       }
725     }
726     GeometryGUI::Modified();
727   }
728   else if (isVTK) { // if is VTKViewer
729     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
730       (SUIT_Session::session()->activeApplication());
731     if (!app)
732       return;
733
734     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
735     if (!aSelMgr)
736       return;
737
738     SALOME_ListIO selected;
739     aSelMgr->selectedObjects(selected);
740     if (selected.IsEmpty())
741       return;
742
743     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
744     if (!vtkVW)
745       return;
746
747     SALOME_View* view = GEOM_Displayer::GetActiveView();
748
749     vtkActorCollection* aCollection = vtkActorCollection::New();
750
751     for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
752       Handle(SALOME_InteractiveObject) anIObject = It.Value();
753       SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
754       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
755       if (vtkPrs) {
756         vtkActorCollection* anActors = vtkPrs->GetObjects();
757         anActors->InitTraversal();
758         vtkActor* anAct = anActors->GetNextActor();
759         aCollection->AddItem(anAct);
760       }
761     }
762
763     if (aCollection)
764       aCollection->InitTraversal();
765     else
766       return;
767
768     double aDC = 0.;
769
770     vtkActor* anAct = aCollection->GetNextActor();
771     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
772       aDC = anActor->GetDeflection();
773     else
774       return;
775
776     GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
777       (SUIT_Session::session()->activeApplication()->desktop());
778     DeflectionDlg->setTheDC(aDC);
779     if (DeflectionDlg->exec()) {
780       SUIT_OverrideCursor();
781       aDC = DeflectionDlg->getTheDC();
782       while (anAct != NULL) {
783         if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
784           // There are no casting to needed actor.
785           anActor->SetDeflection(aDC);
786           appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC);
787         }
788         anAct = aCollection->GetNextActor();
789       }
790     }
791     GeometryGUI::Modified();
792   } // end vtkviewer
793 }
794
795 void GEOMToolsGUI::OnSelectOnly(int mode)
796 {
797   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
798   if ( app ) {
799     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
800     GEOM_Displayer aDisp (appStudy);
801     aDisp.GlobalSelection(mode);
802     getGeometryGUI()->setLocalSelectionMode(mode);
803   }
804 }
805
806 void GEOMToolsGUI::OnShowHideChildren( bool show )
807 {
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(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
840             aExp->SetExpandable( show );
841             if(!show)
842               disp->EraseWithChildren(IObject,true);
843           } // if ( obj )
844         } // iterator
845       }
846     }
847     app->updateObjectBrowser( false );
848     app->updateActions();
849   }
850 }
851
852 void GEOMToolsGUI::OnPointMarker()
853 {
854   GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
855   dlg.exec();
856 }
857
858 void GEOMToolsGUI::OnMaterialProperties()
859 {
860   GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
861   dlg.exec();
862 }
863
864 void GEOMToolsGUI::OnUnpublishObject() {
865   SALOME_ListIO selected;
866   SalomeApp_Application* app =
867     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
868
869   SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
870
871   GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
872   
873   if ( app && disp ) {
874     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
875     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
876     if ( aSelMgr && appStudy ) {
877       aSelMgr->selectedObjects( selected );
878       if ( !selected.IsEmpty() ) {
879         _PTR(Study) aStudy = appStudy->studyDS();
880         _PTR(StudyBuilder) B = aStudy->NewBuilder();
881
882         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
883         if ( aLocked ) {
884           SUIT_MessageBox::warning( app->desktop(),
885                                     QObject::tr( "WRN_WARNING" ),
886                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
887           return;
888         }
889
890         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
891           Handle(SALOME_InteractiveObject) IObject = It.Value();
892
893           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
894           _PTR(GenericAttribute) anAttr;
895           if ( obj ) {
896             _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
897             aDrw->SetDrawable( false );
898             disp->EraseWithChildren(IObject);
899           } // if ( obj )
900         } // iterator
901         aSelMgr->clearSelected();
902       }
903     }
904     app->updateObjectBrowser( false );
905     app->updateActions();
906   }
907  
908 }
909
910 void GEOMToolsGUI::OnPublishObject() {
911   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
912   if(!app)
913     return;
914
915   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
916   if(!appStudy)
917     return;
918   
919   _PTR(Study) aStudy = appStudy->studyDS();
920   
921   if(!aStudy)
922     return;
923
924   //Check lock of the study
925   bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
926   if ( aLocked ) {
927     SUIT_MessageBox::warning( app->desktop(),
928                               QObject::tr( "WRN_WARNING" ),
929                               QObject::tr( "WRN_STUDY_LOCKED" ) );
930     return;
931   } 
932   
933   GEOMToolsGUI_PublishDlg * publishDlg =
934     new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
935   publishDlg->exec();
936 }