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