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