Salome HOME
9057a8988dfbfa5214478890d01fc7716bfe01f0
[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 #include "GEOMToolsGUI_LineWidthDlg.h"
36
37 #include <GeometryGUI.h>
38 #include <GeometryGUI_Operations.h>
39 #include <GEOM_Constants.h>
40 #include <GEOM_Displayer.h>
41
42 #include <GEOMBase.h>
43 #include <GEOM_Actor.h>
44
45 #include <Basics_OCCTVersion.hxx>
46
47 #include <SALOME_ListIO.hxx>
48 #include <SALOME_ListIteratorOfListIO.hxx>
49
50 #include <SOCC_Prs.h>
51
52 #include <SVTK_Prs.h>
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SVTK_View.h>
56
57 #include <OCCViewer_ViewModel.h>
58
59 #include <SUIT_ViewManager.h>
60 #include <SUIT_Desktop.h>
61 #include <SUIT_ResourceMgr.h>
62 #include <SUIT_Session.h>
63 #include <SUIT_OverrideCursor.h>
64 #include <SUIT_MessageBox.h>
65 #include <SUIT_Tools.h>
66
67 #include <SalomeApp_Application.h>
68 #include <SalomeApp_Study.h>
69 #include <SalomeApp_Module.h>
70
71 #include <LightApp_SelectionMgr.h>
72 #include <LightApp_NameDlg.h>
73
74 #include <GEOMImpl_Types.hxx>
75
76 #include "utilities.h"
77
78 // OCCT Includes
79 #include <AIS_Drawer.hxx>
80 #include <Prs3d_IsoAspect.hxx>
81 #include <Prs3d_PointAspect.hxx>
82 #include <Graphic3d_AspectMarker3d.hxx>
83 #include <Graphic3d_AspectLine3d.hxx>
84 #include <AIS_ListIteratorOfListOfInteractive.hxx>
85 #include <AIS_ListOfInteractive.hxx>
86
87
88 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
89 #include <TColStd_HArray1OfByte.hxx>
90 #else
91 #include <Graphic3d_HArray1OfBytes.hxx>
92 #endif
93
94 // QT Includes
95 #include <QAction>
96 #include <QColorDialog>
97 #include <QInputDialog>
98 #include <QFileDialog>
99 #include <QList>
100
101 #include <QGridLayout>
102 #include <QGroupBox>
103 #include <QSpinBox>
104 #include <QPushButton>
105 #include <QKeyEvent>
106
107 // VTK includes
108 #include <vtkRenderer.h>
109
110 void GEOMToolsGUI::OnCheckGeometry()
111 {
112   SalomeApp_Application* app =
113     dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
114   PyConsole_Console* pyConsole = app->pythonConsole();
115
116   if (pyConsole)
117     pyConsole->exec("from GEOM_usinggeom import *");
118 }
119
120 void GEOMToolsGUI::OnAutoColor()
121 {
122   SALOME_ListIO selected;
123   SalomeApp_Application* app =
124     dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
125   if (!app)
126     return;
127
128   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
129   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
130   if (!aSelMgr || !appStudy)
131     return;
132
133   aSelMgr->selectedObjects(selected);
134   if (selected.IsEmpty())
135     return;
136
137   Handle(SALOME_InteractiveObject) anIObject = selected.First();
138
139   _PTR(Study) aStudy = appStudy->studyDS();
140   _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
141   GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
142   if (CORBA::is_nil(aMainObject))
143     return;
144
145   aMainObject->SetAutoColor( true );
146
147   QList<SALOMEDS::Color> aReservedColors;
148
149   GEOM_Displayer aDisp (appStudy);
150
151   SALOME_View* vf = aDisp.GetActiveView();
152
153   SUIT_ViewWindow* window = app->desktop()->activeWindow();
154   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
155   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
156
157   for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
158   {
159     _PTR(SObject) aChildSObject( it->Value() );
160     GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
161     if( CORBA::is_nil( aChildObject ) )
162       continue;
163
164     if( aChildObject->GetType() != GEOM_GROUP )
165       continue;
166
167     SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
168     aChildObject->SetColor( aColor );
169     aReservedColors.append( aColor );
170
171     QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
172
173     SALOME_Prs* aPrs = vf->CreatePrs( aChildSObject->GetID().c_str() );
174
175     if ( isVTK )
176     {
177       SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
178       if ( !vtkVW )
179         return;
180       SVTK_View* aView = vtkVW->getView();
181       SUIT_OverrideCursor();
182       for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
183         aView->SetColor( It.Value(), c );
184     }
185     else if ( isOCC )
186     {
187       OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
188       Handle(AIS_InteractiveContext) ic = vm->getAISContext();
189
190       SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
191       if( !anOCCPrs )
192         continue;
193
194       AIS_ListOfInteractive aList;
195       anOCCPrs->GetObjects( aList );
196       if( !aList.Extent() )
197         continue;
198
199       Handle(AIS_InteractiveObject) io = aList.First();
200       if( io.IsNull() )
201         continue;
202
203       Quantity_Color aQuanColor( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
204
205       // Set color for a point
206       Handle(AIS_Drawer) aCurDrawer = io->Attributes();
207       Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
208       Quantity_Color aCurColor;
209       Standard_Real aCurScale;
210       Aspect_TypeOfMarker aCurTypeOfMarker;
211       aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
212       if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
213         aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
214       }
215       else {
216         Standard_Integer aWidth, aHeight;
217         aCurPointAspect->GetTextureSize( aWidth, aHeight );
218
219 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
220         Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
221 #else
222         Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
223 #endif
224
225         aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aQuanColor, 1, aWidth, aHeight, aTexture ) );
226       }
227       ic->SetLocalAttributes( io, aCurDrawer );
228
229       io->SetColor( aQuanColor );
230       if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) {
231         Handle(GEOM_AISShape) aGAISShape = Handle(GEOM_AISShape)::DownCast( io );
232         aGAISShape->SetShadingColor( aQuanColor );
233         aGAISShape->storeBoundaryColors();
234       }
235
236       io->Redisplay( Standard_True );
237     }
238   }
239
240   app->updateActions(); //SRN: To update a Save button in the toolbar
241 }
242
243 void GEOMToolsGUI::OnDisableAutoColor()
244 {
245   SALOME_ListIO selected;
246   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
247   if( !app )
248     return;
249
250   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
251   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
252   if( !aSelMgr || !appStudy )
253     return;
254
255   aSelMgr->selectedObjects( selected );
256   if( selected.IsEmpty() )
257     return;
258
259   Handle(SALOME_InteractiveObject) anIObject = selected.First();
260
261   _PTR(Study) aStudy = appStudy->studyDS();
262   _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
263   GEOM::GEOM_Object_var aMainObject =  GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
264   if( CORBA::is_nil( aMainObject ) )
265     return;
266
267   aMainObject->SetAutoColor( false );
268
269 }
270
271 void GEOMToolsGUI::OnColor()
272 {
273   SALOME_ListIO selected;
274   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
275   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
276   if ( app && appStudy ) {
277     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
278     if ( aSelMgr ) {
279       aSelMgr->selectedObjects( selected );
280       if ( !selected.IsEmpty() ) {
281         SUIT_ViewWindow* window = app->desktop()->activeWindow();
282         bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
283         bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
284         int mgrId = window->getViewManager()->getGlobalId();
285         if ( isVTK ) {
286           SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
287           if ( !vtkVW )
288             return;
289           SVTK_View* aView = vtkVW->getView();
290           QColor initcolor = aView->GetColor( selected.First()  );
291           QColor c = QColorDialog::getColor( initcolor, app->desktop() );
292           if ( c.isValid() ) {
293             SUIT_OverrideCursor();
294             for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
295               aView->SetColor( It.Value(), c );
296               appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c);
297             }
298             GeometryGUI::Modified();
299           }
300         } // if ( isVTK )
301         else if ( isOCC ) {
302           Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
303           if ( !io.IsNull() ) {
304             Quantity_Color aColor;
305             io->Color( aColor ); 
306             QColor ic = QColor((int )( aColor.Red() * 255.0 ),
307                               (int)( aColor.Green() * 255.0 ),
308                               (int)( aColor.Blue() * 255.0 ));      
309
310             QVariant v = appStudy->getObjectProperty(mgrId,selected.First()->getEntry(), COLOR_PROP, ic);
311
312             QColor initcolor = v.value<QColor>();
313             QColor c =  QColorDialog::getColor( initcolor, app->desktop() );
314             if ( c.isValid() ) {
315               SUIT_OverrideCursor();
316               aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
317               OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
318               Handle (AIS_InteractiveContext) ic = vm->getAISContext();
319               for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
320                 io = GEOMBase::GetAIS( It.Value(), true );
321                 if ( !io.IsNull() ) {
322                   
323                   if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) {
324                     TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape();
325                     bool onlyVertex = (theShape.ShapeType() == TopAbs_VERTEX || GEOM_Displayer::isCompoundOfVertices( theShape ));
326                     if (onlyVertex) {
327                       // Set color for a point
328
329                       Handle(AIS_Drawer) aCurDrawer = io->Attributes();
330                       Handle(Prs3d_PointAspect) aCurPointAspect =  aCurDrawer->PointAspect();
331                       Quantity_Color aCurColor;
332                       Standard_Real aCurScale;
333                       Aspect_TypeOfMarker aCurTypeOfMarker;
334                       aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
335                       if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
336                         aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aCurTypeOfMarker, aColor, aCurScale));
337                       }
338                       else {
339                         Standard_Integer aWidth, aHeight;
340                         aCurPointAspect->GetTextureSize( aWidth, aHeight );
341
342 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
343                         Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
344 #else
345                         Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
346 #endif
347
348                         aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aColor, 1, aWidth, aHeight, aTexture));
349                       }
350                       ic->SetLocalAttributes(io, aCurDrawer, Standard_False);
351                     }
352                   }
353                   
354                   io->SetColor( aColor );
355                   if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) {
356                     Handle(GEOM_AISShape) aGAISShape = Handle(GEOM_AISShape)::DownCast( io );
357                     aGAISShape->SetShadingColor( aColor );
358                     aGAISShape->storeBoundaryColors();
359                   }
360                   
361                   appStudy->setObjectProperty(mgrId,It.Value()->getEntry(), COLOR_PROP, c);
362                   
363                   io->Redisplay( Standard_True );
364
365                   // store color to GEOM_Object
366                   _PTR(Study) aStudy = appStudy->studyDS();
367                   _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
368                   GEOM::GEOM_Object_var anObject =
369                     GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
370
371
372                   SALOMEDS::Color aSColor;
373                   aSColor.R = (double)c.red() / 255.0;
374                   aSColor.G = (double)c.green() / 255.0;
375                   aSColor.B = (double)c.blue() / 255.0;
376                   anObject->SetColor( aSColor );
377                   anObject->SetAutoColor( false );                
378                 }
379               } // for
380               ic->UpdateCurrentViewer();
381               GeometryGUI::Modified();
382             } // if c.isValid()
383           } // first IO is not null
384         } // if ( isOCC )
385       } // if ( selection not empty )
386     }
387   }
388
389   app->updateActions(); //SRN: To update a Save button in the toolbar
390 }
391
392 void GEOMToolsGUI::OnTexture()
393 {
394   SALOME_ListIO selected;
395   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
396   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
397   if ( app && appStudy ) {
398     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
399     if ( aSelMgr ) {
400       aSelMgr->selectedObjects( selected );
401       if ( !selected.IsEmpty() ) {
402         SUIT_ViewWindow* window = app->desktop()->activeWindow();
403         bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
404         if ( isOCC ) {
405           QString aTexture = QFileDialog::getOpenFileName(window,tr( "GEOM_SELECT_IMAGE"),QString(), tr("OCC_IMAGE_FILES"));
406           if( !aTexture.isEmpty() )
407           {
408             SUIT_OverrideCursor();
409             OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
410             Handle (AIS_InteractiveContext) ic = vm->getAISContext();
411             Handle(AIS_InteractiveObject) io ;
412             for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
413               io = GEOMBase::GetAIS( It.Value(), true );
414               if ( !io.IsNull() ) {
415                 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
416                   Handle(GEOM_AISShape)::DownCast( io )->SetTextureFileName(TCollection_AsciiString(aTexture.toStdString().c_str()));
417                 io->Redisplay( Standard_True );
418               } // if ( !io.IsNull() )
419             } // for
420             ic->UpdateCurrentViewer();
421             GeometryGUI::Modified();
422             GeometryGUI* myGeomGUI = getGeometryGUI();
423             myGeomGUI->OnGUIEvent(GEOMOp::OpTexture);
424           } // if ( !selFile.isEmpty() )
425         } // if ( isOCC )
426       } // if ( selection not empty )
427     }
428   }
429
430   app->updateActions(); //SRN: To update a Save button in the toolbar
431 }
432
433 void GEOMToolsGUI::OnTransparency()
434 {
435   GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
436   dlg.exec();
437 }
438
439 void GEOMToolsGUI::OnChangeTransparency( bool increase )
440 {
441  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
442   if ( !app )
443     return;
444   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
445   if ( !aSelMgr )
446     return;
447   SALOME_ListIO selected;
448   aSelMgr->selectedObjects( selected );
449   if ( selected.IsEmpty() )
450     return;
451
452   Handle(SALOME_InteractiveObject) FirstIOS =  selected.First();
453   if ( FirstIOS.IsNull() )
454     return;
455
456   // Delta
457   float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
458   if ( !increase )
459     delta *= -1;
460         
461   SUIT_ViewWindow* window = app->desktop()->activeWindow();
462   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
463   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
464
465   if ( isVTK ) {
466     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
467     if ( !vtkVW )
468       return;
469     SVTK_View* aView = vtkVW->getView();
470    
471     float transp = aView->GetTransparency(FirstIOS);
472     
473     // Compute new transparency value
474     transp = transp + delta;
475     if ( transp < 0 )
476       transp = 0;
477     else if ( transp > 1 )
478       transp = 1;
479
480     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
481       aView->SetTransparency( It.Value(), transp );
482     }
483     aView->Repaint();
484     GeometryGUI::Modified();
485   } // if ( isVTK )
486         
487   else if ( isOCC ) {
488     GEOMBase* gb = new GEOMBase();
489     Handle(GEOM_AISShape) aisShape;
490    
491     aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
492     if( aisShape.IsNull() )
493       return;
494     float transp = aisShape->Transparency();
495
496     // Compute new transparency value
497     transp = transp + delta;
498     if ( transp < 0 )
499       transp = 0;
500     else if ( transp > 1 )
501       transp = 1;
502
503     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
504     if ( !vm )
505       return;
506     Handle(AIS_InteractiveContext) ic = vm->getAISContext();
507     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
508       aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
509       if ( !aisShape.IsNull() ) {
510         ic->SetTransparency( aisShape, transp, false );
511         ic->Redisplay( aisShape, Standard_False, Standard_True );
512       }
513     } // for...
514     ic->UpdateCurrentViewer();
515     GeometryGUI::Modified();
516   } // if ( isOCC )
517 }
518
519 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
520 {
521   SalomeApp_Application* app =
522     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
523   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
524   SUIT_ViewWindow* window = app->desktop()->activeWindow();
525
526   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
527   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
528
529   if(isOCC){ // if is OCCViewer
530
531     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
532     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
533
534     ic->InitCurrent();
535     if ( ic->MoreCurrent() ) {
536       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
537       CurObject->restoreIsoNumbers();
538       Handle(AIS_Drawer)    CurDrawer = CurObject->Attributes();
539
540       int UIso = CurDrawer->UIsoAspect()->Number();
541       int VIso = CurDrawer->VIsoAspect()->Number();
542
543       int newNbUIso = -1;
544       int newNbVIso = -1;
545
546       if ( actionType == SHOWDLG ) {
547         GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
548           new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
549
550         NbIsosDlg->setU( UIso );
551         NbIsosDlg->setV( VIso );
552
553         if ( NbIsosDlg->exec() ) {
554           SUIT_OverrideCursor();
555           
556           newNbUIso = NbIsosDlg->getU();
557           newNbVIso = NbIsosDlg->getV();
558         } else //Cancel case
559           return;
560       }
561       else if ( actionType == INCR || actionType == DECR ) {
562         int delta = 1;
563         if (actionType == DECR)
564           delta = -1;
565         
566         newNbUIso = UIso + delta;
567         newNbVIso = VIso + delta;
568
569         if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
570           return;
571       }
572
573       for(; ic->MoreCurrent(); ic->NextCurrent()) {
574         int aMgrId = window->getViewManager()->getGlobalId();
575         CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
576
577         Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
578
579         QVariant v = aStudy->getObjectProperty( aMgrId, CurObject->getIO()->getEntry(), EDGE_WIDTH_PROP , QVariant() );
580
581         int width = v.isValid() ? v.toInt() : 1;
582
583         CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, width , newNbUIso) );
584         CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, width , newNbVIso) );
585
586         CurObject->storeIsoNumbers();
587         
588         ic->SetLocalAttributes(CurObject, CurDrawer);
589         ic->Redisplay(CurObject);
590
591         QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
592         aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_WIDTH_PROP, anIsos);
593       }
594     }
595     GeometryGUI::Modified();
596   }
597   else if(isVTK){ // if is VTKViewer
598     //
599     // Warning. It's works incorrect. must be recheked.
600     //
601     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
602       ( SUIT_Session::session()->activeApplication() );
603     if ( !app )
604       return;
605     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
606     if ( !aSelMgr )
607       return;
608     SALOME_ListIO selected;
609     aSelMgr->selectedObjects( selected );
610     if ( selected.IsEmpty() )
611       return;
612
613     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
614     if ( !vtkVW )
615       return;
616
617     SALOME_View* view = GEOM_Displayer::GetActiveView();
618
619     vtkActorCollection* aCollection = vtkActorCollection::New();
620
621     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
622       Handle(SALOME_InteractiveObject) anIObject = It.Value();
623       SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
624       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
625       if ( vtkPrs ) {
626         vtkActorCollection* anActors = vtkPrs->GetObjects();
627         anActors->InitTraversal();
628         vtkActor* anAct = anActors->GetNextActor();
629         aCollection->AddItem(anAct);
630       }
631     }
632
633     if(aCollection)
634       aCollection->InitTraversal();
635     else
636       return;
637
638     int UIso = 0;
639     int VIso = 0;
640
641     vtkActor* anAct = aCollection->GetNextActor();
642     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
643       anActor->RestoreIsoNumbers();
644       anActor->GetNbIsos(UIso,VIso);
645     }
646     else
647       return;
648     
649     int newNbUIso = -1;
650     int newNbVIso = -1;
651
652     if ( actionType == SHOWDLG ) {
653       GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
654         new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
655
656       NbIsosDlg->setU( UIso );
657       NbIsosDlg->setV( VIso );
658
659       if ( NbIsosDlg->exec() ) {
660         SUIT_OverrideCursor();
661
662         newNbUIso = NbIsosDlg->getU();
663         newNbVIso = NbIsosDlg->getV();
664       } else 
665         return; //Cancel case 
666     }
667     else if ( actionType == INCR || actionType == DECR ) {
668       int delta = 1;
669       if (actionType == DECR)
670         delta = -1;
671       
672       newNbUIso = UIso + delta;
673       newNbVIso = VIso + delta;
674       
675       if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
676         return;
677     } 
678     
679     while( anAct!=NULL ) {
680       if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
681         // There are no casting to needed actor.
682         int aIsos[2]={newNbUIso,newNbVIso};
683         anActor->SetNbIsos(aIsos);
684         anActor->StoreIsoNumbers();
685
686         QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
687         int aMgrId = window->getViewManager()->getGlobalId();
688         aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos);
689       }
690       anAct = aCollection->GetNextActor();
691     }
692     view->Repaint();
693     GeometryGUI::Modified();
694   } // end vtkviewer
695 }
696
697 void GEOMToolsGUI::OnDeflection()
698 {
699   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
700   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
701
702
703   bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
704   bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
705   int mgrId = window->getViewManager()->getGlobalId();
706
707   if (isOCC) { // if is OCCViewer
708     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
709     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
710
711     ic->InitCurrent();
712     if (ic->MoreCurrent()) {
713       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
714
715       Standard_Real aDC, aPrevDC;
716       Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
717       if (!isOwnDC)
718         aDC = ic->DeviationCoefficient();
719
720       GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
721         (SUIT_Session::session()->activeApplication()->desktop());
722       DeflectionDlg->setTheDC(aDC);
723       double aNewDC = 0.0;
724       bool ok = false;
725       while (!ok) {
726         if (DeflectionDlg->exec()) {
727           SUIT_OverrideCursor();
728           aNewDC = DeflectionDlg->getTheDC();
729           ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
730           if (ok) {
731             for (; ic->MoreCurrent(); ic->NextCurrent()) {
732               CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
733               ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
734               ic->Redisplay(CurObject);
735               appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC);
736             }
737           }
738         }
739         else {
740           ok = true;
741         }
742       }
743     }
744     GeometryGUI::Modified();
745   }
746   else if (isVTK) { // if is VTKViewer
747     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
748       (SUIT_Session::session()->activeApplication());
749     if (!app)
750       return;
751
752     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
753     if (!aSelMgr)
754       return;
755
756     SALOME_ListIO selected;
757     aSelMgr->selectedObjects(selected);
758     if (selected.IsEmpty())
759       return;
760
761     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
762     if (!vtkVW)
763       return;
764
765     SALOME_View* view = GEOM_Displayer::GetActiveView();
766
767     vtkActorCollection* aCollection = vtkActorCollection::New();
768
769     for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
770       Handle(SALOME_InteractiveObject) anIObject = It.Value();
771       SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
772       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
773       if (vtkPrs) {
774         vtkActorCollection* anActors = vtkPrs->GetObjects();
775         anActors->InitTraversal();
776         vtkActor* anAct = anActors->GetNextActor();
777         aCollection->AddItem(anAct);
778       }
779     }
780
781     if (aCollection)
782       aCollection->InitTraversal();
783     else
784       return;
785
786     double aDC = 0.;
787
788     vtkActor* anAct = aCollection->GetNextActor();
789     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
790       aDC = anActor->GetDeflection();
791     else
792       return;
793
794     GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
795       (SUIT_Session::session()->activeApplication()->desktop());
796     DeflectionDlg->setTheDC(aDC);
797     if (DeflectionDlg->exec()) {
798       SUIT_OverrideCursor();
799       aDC = DeflectionDlg->getTheDC();
800       while (anAct != NULL) {
801         if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
802           // There are no casting to needed actor.
803           anActor->SetDeflection(aDC);
804           appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC);
805         }
806         anAct = aCollection->GetNextActor();
807       }
808     }
809     GeometryGUI::Modified();
810   } // end vtkviewer
811 }
812
813 void GEOMToolsGUI::OnSelectOnly(int mode)
814 {
815   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
816   if ( app ) {
817     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
818     GEOM_Displayer aDisp (appStudy);
819     aDisp.GlobalSelection(mode);
820     getGeometryGUI()->setLocalSelectionMode(mode);
821   }
822 }
823
824 void GEOMToolsGUI::OnShowHideChildren( bool show )
825 {
826   SALOME_ListIO selected;
827   SalomeApp_Application* app =
828     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
829   
830   SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
831   
832   GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
833
834   if ( app && disp ) {
835     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
836     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
837     if ( aSelMgr && appStudy ) {
838       aSelMgr->selectedObjects( selected );
839       if ( !selected.IsEmpty() ) {
840         _PTR(Study) aStudy = appStudy->studyDS();
841         _PTR(StudyBuilder) B = aStudy->NewBuilder();
842
843         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
844         if ( aLocked ) {
845           SUIT_MessageBox::warning( app->desktop(),
846                                     QObject::tr( "WRN_WARNING" ),
847                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
848           return;
849         }
850
851         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
852           Handle(SALOME_InteractiveObject) IObject = It.Value();
853
854           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
855           _PTR(GenericAttribute) anAttr;
856           if ( obj ) {
857             _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
858             aExp->SetExpandable( show );
859             if(!show)
860               disp->EraseWithChildren(IObject,true);
861           } // if ( obj )
862         } // iterator
863       }
864     }
865     app->updateObjectBrowser( false );
866     app->updateActions();
867   }
868 }
869
870 void GEOMToolsGUI::OnPointMarker()
871 {
872   GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
873   dlg.exec();
874 }
875
876 void GEOMToolsGUI::OnMaterialProperties()
877 {
878   GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
879   dlg.exec();
880 }
881
882 void GEOMToolsGUI::OnUnpublishObject() {
883   SALOME_ListIO selected;
884   SalomeApp_Application* app =
885     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
886
887   SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
888
889   GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
890   
891   if ( app && disp ) {
892     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
893     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
894     if ( aSelMgr && appStudy ) {
895       aSelMgr->selectedObjects( selected );
896       if ( !selected.IsEmpty() ) {
897         _PTR(Study) aStudy = appStudy->studyDS();
898         _PTR(StudyBuilder) B = aStudy->NewBuilder();
899
900         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
901         if ( aLocked ) {
902           SUIT_MessageBox::warning( app->desktop(),
903                                     QObject::tr( "WRN_WARNING" ),
904                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
905           return;
906         }
907
908         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
909           Handle(SALOME_InteractiveObject) IObject = It.Value();
910
911           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
912           _PTR(GenericAttribute) anAttr;
913           if ( obj ) {
914             _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
915             aDrw->SetDrawable( false );
916             disp->EraseWithChildren(IObject);
917           } // if ( obj )
918         } // iterator
919         aSelMgr->clearSelected();
920       }
921     }
922     app->updateObjectBrowser( false );
923     app->updateActions();
924   }
925  
926 }
927
928 void GEOMToolsGUI::OnPublishObject() {
929   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
930   if(!app)
931     return;
932
933   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
934   if(!appStudy)
935     return;
936   
937   _PTR(Study) aStudy = appStudy->studyDS();
938   
939   if(!aStudy)
940     return;
941
942   //Check lock of the study
943   bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
944   if ( aLocked ) {
945     SUIT_MessageBox::warning( app->desktop(),
946                               QObject::tr( "WRN_WARNING" ),
947                               QObject::tr( "WRN_STUDY_LOCKED" ) );
948     return;
949   } 
950   
951   GEOMToolsGUI_PublishDlg * publishDlg =
952     new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
953   publishDlg->exec();
954 }
955
956
957 void GEOMToolsGUI::OnEdgeWidth()
958 {
959   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
960   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
961
962
963   bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
964   bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
965   int mgrId = window->getViewManager()->getGlobalId();
966
967   if (isOCC) { // if is OCCViewer
968     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
969     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
970     ic->InitCurrent();
971     if (ic->MoreCurrent()) {
972       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
973
974       int aWidth = (int)CurObject->Width();
975
976       GEOMToolsGUI_LineWidthDlg * Dlg = new GEOMToolsGUI_LineWidthDlg
977         (SUIT_Session::session()->activeApplication()->desktop(),"EDGE_WIDTH_TLT");
978       Dlg->setTheLW(aWidth);
979       int aNewWidth = 0;
980       if (Dlg->exec()) {
981         aNewWidth = Dlg->getTheLW();
982         bool ok = (aNewWidth != aWidth && aNewWidth != 0 );
983         if (ok) {
984           for(; ic->MoreCurrent(); ic->NextCurrent()) {
985             CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
986             CurObject->SetWidth(aNewWidth);
987             ic->Redisplay(CurObject);
988             appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), EDGE_WIDTH_PROP, aNewWidth);
989           }
990         }
991       }
992     }
993     else {
994       return;
995     }
996     GeometryGUI::Modified();
997   }
998   else if (isVTK) { // if is VTKViewer
999     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
1000       (SUIT_Session::session()->activeApplication());
1001     if (!app)
1002       return;
1003
1004     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1005     if (!aSelMgr)
1006       return;
1007
1008     SALOME_ListIO selected;
1009     aSelMgr->selectedObjects(selected);
1010     if (selected.IsEmpty())
1011       return;
1012
1013     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
1014     if (!vtkVW)
1015       return;
1016
1017     SALOME_View* view = GEOM_Displayer::GetActiveView();
1018
1019     vtkActorCollection* aCollection = vtkActorCollection::New();
1020
1021     for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
1022       Handle(SALOME_InteractiveObject) anIObject = It.Value();
1023       SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
1024       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
1025       if (vtkPrs) {
1026         vtkActorCollection* anActors = vtkPrs->GetObjects();
1027         anActors->InitTraversal();
1028         vtkActor* anAct = anActors->GetNextActor();
1029         aCollection->AddItem(anAct);
1030       }
1031     }
1032
1033     if (aCollection)
1034       aCollection->InitTraversal();
1035     else
1036       return;
1037
1038     int aWidth = 1;
1039
1040     vtkActor* anAct = aCollection->GetNextActor();
1041     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
1042       aWidth = anActor->GetWidth();
1043     else
1044       return;
1045
1046     GEOMToolsGUI_LineWidthDlg * Dlg = new GEOMToolsGUI_LineWidthDlg
1047       (SUIT_Session::session()->activeApplication()->desktop(),"EDGE_WIDTH_TLT");
1048     
1049     Dlg->setTheLW(aWidth);
1050     if (Dlg->exec()) {
1051       SUIT_OverrideCursor();
1052       aWidth = Dlg->getTheLW();
1053       while (anAct != NULL) {
1054         if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
1055           // There are no casting to needed actor.
1056           anActor->SetWidth(aWidth);
1057           appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), EDGE_WIDTH_PROP, aWidth);
1058         }
1059         anAct = aCollection->GetNextActor();
1060       }
1061     }
1062     GeometryGUI::Modified();
1063   } // end vtkviewer
1064 }
1065
1066
1067 void GEOMToolsGUI::OnIsosWidth() {
1068   SalomeApp_Application* app =
1069     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1070   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1071   SUIT_ViewWindow* window = app->desktop()->activeWindow();
1072
1073   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1074   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
1075
1076   if(isOCC){ // if is OCCViewer
1077
1078     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
1079     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
1080
1081     ic->InitCurrent();
1082     if ( ic->MoreCurrent() ) {
1083       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
1084       CurObject->restoreIsoNumbers();
1085       Handle(AIS_Drawer)    CurDrawer = CurObject->Attributes();
1086
1087       Handle(Graphic3d_AspectLine3d) asp = CurDrawer->UIsoAspect()->Aspect();
1088       
1089       Quantity_Color C;
1090       Aspect_TypeOfLine T;
1091       Standard_Real W;
1092       asp->Values(C,T,W);
1093
1094       int aWidth = (int)W;
1095
1096       GEOMToolsGUI_LineWidthDlg * Dlg =
1097         new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(),"ISOS_WIDTH_TLT" );
1098
1099       Dlg->setTheLW( aWidth );
1100
1101       if ( Dlg->exec() ) {
1102         SUIT_OverrideCursor();          
1103         aWidth = Dlg->getTheLW();
1104       } else //Cancel case
1105         return;
1106       
1107       for(; ic->MoreCurrent(); ic->NextCurrent()) {
1108         int aMgrId = window->getViewManager()->getGlobalId();
1109         CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
1110         
1111         Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
1112         
1113         CurObject->Attributes()->UIsoAspect()->SetWidth(aWidth);
1114         CurObject->Attributes()->VIsoAspect()->SetWidth(aWidth);
1115         
1116         ic->Redisplay(CurObject);
1117         
1118         aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_WIDTH_PROP, aWidth);
1119       }
1120       GeometryGUI::Modified();
1121     }
1122   }
1123   else if(isVTK){ // if is VTKViewer
1124     //
1125     // Warning. It's works incorrect. must be recheked.
1126     //
1127     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
1128       ( SUIT_Session::session()->activeApplication() );
1129     if ( !app )
1130       return;
1131     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1132     if ( !aSelMgr )
1133       return;
1134     SALOME_ListIO selected;
1135     aSelMgr->selectedObjects( selected );
1136     if ( selected.IsEmpty() )
1137       return;
1138
1139     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
1140     if ( !vtkVW )
1141       return;
1142
1143     SALOME_View* view = GEOM_Displayer::GetActiveView();
1144
1145     vtkActorCollection* aCollection = vtkActorCollection::New();
1146
1147     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
1148       Handle(SALOME_InteractiveObject) anIObject = It.Value();
1149       SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
1150       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
1151       if ( vtkPrs ) {
1152         vtkActorCollection* anActors = vtkPrs->GetObjects();
1153         anActors->InitTraversal();
1154         vtkActor* anAct = anActors->GetNextActor();
1155         aCollection->AddItem(anAct);
1156       }
1157     }
1158
1159     if(aCollection)
1160       aCollection->InitTraversal();
1161     else
1162       return;
1163
1164     int aWidth = 1;
1165
1166     vtkActor* anAct = aCollection->GetNextActor();
1167     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
1168       aWidth = anActor->GetIsosWidth();
1169     }
1170     else
1171       return;
1172     
1173     GEOMToolsGUI_LineWidthDlg* Dlg =
1174       new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
1175     
1176     Dlg->setTheLW( aWidth );
1177     if (Dlg->exec() ) {
1178       SUIT_OverrideCursor();
1179       aWidth = Dlg->getTheLW();
1180     } else 
1181       return; //Cancel case 
1182     
1183     while( anAct!= NULL ) {
1184       if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
1185         // There are no casting to needed actor.
1186         anActor->SetIsosWidth(aWidth);
1187         int aMgrId = window->getViewManager()->getGlobalId();
1188         aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_WIDTH_PROP, aWidth);
1189       }
1190       anAct = aCollection->GetNextActor();
1191     }
1192     
1193     view->Repaint();
1194     GeometryGUI::Modified();
1195   } // end vtkviewer  
1196 }
1197
1198 void GEOMToolsGUI::OnBringToFront() {
1199  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1200   if ( !app )
1201     return;
1202
1203   SalomeApp_Module* mod = dynamic_cast<SalomeApp_Module*>(app->activeModule());
1204   if(!mod)
1205     return;
1206   
1207   GEOM_Displayer* disp  = dynamic_cast<GEOM_Displayer*>(mod->displayer());
1208   
1209   if(!disp)
1210     return;
1211   
1212   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1213   if ( !aSelMgr )
1214     return;
1215
1216   SALOME_ListIO selected;
1217   aSelMgr->selectedObjects( selected );
1218   if ( selected.IsEmpty() )
1219     return;
1220
1221   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());  
1222   if(!appStudy)
1223     return;
1224
1225   SUIT_ViewWindow* window = app->desktop()->activeWindow();
1226
1227   OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
1228   if ( !vm )
1229     return;
1230   
1231   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1232
1233   QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
1234   bool checked = a->isChecked();
1235   
1236   if ( isOCC ) {
1237     GEOMBase* gb = new GEOMBase();
1238     Handle(GEOM_AISShape) aisShape;
1239    
1240     Handle(AIS_InteractiveContext) ic = vm->getAISContext();
1241     SALOME_ListIO anIOlst;
1242     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
1243       aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
1244       if ( !aisShape.IsNull() ) {
1245         aisShape->setTopLevel(checked);
1246         int aMgrId = window->getViewManager()->getGlobalId();
1247         appStudy->setObjectProperty( aMgrId, aisShape->getIO()->getEntry(), TOP_LEVEL_PROP, checked );
1248         anIOlst.Append(aisShape->getIO());
1249       }
1250     } // for...
1251     disp->Redisplay(anIOlst);
1252     GeometryGUI::Modified();
1253   } // if ( isOCC )
1254 }
1255
1256 void GEOMToolsGUI::OnClsBringToFront() {
1257   SalomeApp_Application* app =
1258     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1259   if(!app)
1260     return;
1261
1262   SalomeApp_Module* mod = dynamic_cast<SalomeApp_Module*>(app->activeModule());
1263   if(!mod)
1264     return;
1265   
1266   GEOM_Displayer* disp  = dynamic_cast<GEOM_Displayer*>(mod->displayer());
1267   
1268   if(!disp)
1269     return;
1270
1271
1272   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());  
1273   if(!appStudy)
1274     return;
1275   
1276   SUIT_ViewWindow* window = app->desktop()->activeWindow();  
1277   
1278   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1279   
1280   if(isOCC){ // if is OCCViewer
1281     
1282     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
1283     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
1284     
1285     SALOME_ListIO anIOlst;
1286     AIS_ListOfInteractive aList;
1287     ic->DisplayedObjects( aList );
1288     for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() ) {
1289       
1290       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(it.Value());
1291       
1292       if(CurObject.IsNull())
1293         continue;
1294       
1295       CurObject->setTopLevel(Standard_False);
1296       
1297       int aMgrId = window->getViewManager()->getGlobalId();
1298       appStudy->setObjectProperty( aMgrId, QString(CurObject->getIO()->getEntry()), TOP_LEVEL_PROP, Standard_False );
1299       anIOlst.Append(CurObject->getIO());
1300     }
1301     disp->Redisplay(anIOlst);
1302     GeometryGUI::Modified();
1303   }
1304 }
1305