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