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