Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_1.cxx
1 // Copyright (C) 2007-2012  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
23 //  GEOM GEOMGUI : GUI for Geometry component
24 //  File   : GEOMToolsGUI_1.cxx
25 //  Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26
27 #include <PyConsole_Console.h>
28
29 #include "GEOMToolsGUI.h"
30 #include "GEOMToolsGUI_TransparencyDlg.h"
31 #include "GEOMToolsGUI_NbIsosDlg.h"
32 #include "GEOMToolsGUI_DeflectionDlg.h"
33 #include "GEOMToolsGUI_MarkerDlg.h"
34 #include "GEOMToolsGUI_PublishDlg.h"
35 #include "GEOMToolsGUI_MaterialPropertiesDlg.h"
36 #include "GEOMToolsGUI_LineWidthDlg.h"
37 #include "Material_Model.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               QString matProp;
298               matProp = appStudy->getObjectProperty(mgrId,It.Value()->getEntry(), MATERIAL_PROP, matProp).toString();
299               Material_Model material;
300               material.fromProperties( matProp );
301               if ( !material.isPhysical() ) {
302                 aView->SetColor( It.Value(), c );
303                 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c);
304               }
305               // store color to GEOM_Object
306               _PTR(Study) aStudy = appStudy->studyDS();
307               _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
308               GEOM::GEOM_Object_var anObject =
309               GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
310               SALOMEDS::Color aSColor;
311               aSColor.R = (double)c.red() / 255.0;
312               aSColor.G = (double)c.green() / 255.0;
313               aSColor.B = (double)c.blue() / 255.0;
314               anObject->SetColor( aSColor );
315               anObject->SetAutoColor( false );           
316             }
317             GeometryGUI::Modified();
318           }
319         } // if ( isVTK )
320         else if ( isOCC ) {
321                 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
322           if ( !io.IsNull() ) {
323             Quantity_Color aColor;
324             io->Color( aColor ); 
325             QColor ic = QColor((int )( aColor.Red() * 255.0 ),
326                               (int)( aColor.Green() * 255.0 ),
327                               (int)( aColor.Blue() * 255.0 ));      
328
329                               QVariant v = appStudy->getObjectProperty(mgrId,selected.First()->getEntry(), COLOR_PROP, ic);
330
331             QColor initcolor = v.value<QColor>();
332             QColor c =  QColorDialog::getColor( initcolor, app->desktop() );
333             if ( c.isValid() ) {
334               SUIT_OverrideCursor();
335               aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
336               OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
337               Handle (AIS_InteractiveContext) ic = vm->getAISContext();
338               for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
339                 QString matProp;
340                 matProp = appStudy->getObjectProperty(mgrId,It.Value()->getEntry(), MATERIAL_PROP, matProp).toString();
341                 Material_Model material;
342                 material.fromProperties( matProp );
343                 io = GEOMBase::GetAIS( It.Value(), true );
344                 if ( !io.IsNull()  && !material.isPhysical() ) { // change color only for shapes with not physical type of material
345                   
346                   if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) {
347                     TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape();
348                     bool onlyVertex = (theShape.ShapeType() == TopAbs_VERTEX || GEOM_Displayer::isCompoundOfVertices( theShape ));
349                     if (onlyVertex) {
350                       // Set color for a point
351
352                       Handle(AIS_Drawer) aCurDrawer = io->Attributes();
353                       Handle(Prs3d_PointAspect) aCurPointAspect =  aCurDrawer->PointAspect();
354                       Quantity_Color aCurColor;
355                       Standard_Real aCurScale;
356                       Aspect_TypeOfMarker aCurTypeOfMarker;
357                       aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
358                       if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
359                         aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aCurTypeOfMarker, aColor, aCurScale));
360                       }
361                       else {
362                         Standard_Integer aWidth, aHeight;
363                         aCurPointAspect->GetTextureSize( aWidth, aHeight );
364
365 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
366                         Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
367 #else
368                         Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
369 #endif
370
371                         aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aColor, 1, aWidth, aHeight, aTexture));
372                       }
373                       ic->SetLocalAttributes(io, aCurDrawer, Standard_False);
374                     }
375                   }
376
377                   io->SetColor( aColor );
378                   if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) {
379                     Handle(GEOM_AISShape) aGAISShape = Handle(GEOM_AISShape)::DownCast( io );
380                     aGAISShape->SetShadingColor( aColor );
381                     aGAISShape->storeBoundaryColors();
382                   }
383
384                   appStudy->setObjectProperty(mgrId,It.Value()->getEntry(), COLOR_PROP, c);
385                   
386                   io->Redisplay( Standard_True );
387
388                   // store color to GEOM_Object
389                   _PTR(Study) aStudy = appStudy->studyDS();
390                   _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
391                   GEOM::GEOM_Object_var anObject =
392                     GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
393
394
395                   SALOMEDS::Color aSColor;
396                   aSColor.R = (double)c.red() / 255.0;
397                   aSColor.G = (double)c.green() / 255.0;
398                   aSColor.B = (double)c.blue() / 255.0;
399                   anObject->SetColor( aSColor );
400                   anObject->SetAutoColor( false );               
401                 }
402               } // for
403               ic->UpdateCurrentViewer();
404               GeometryGUI::Modified();
405             } // if c.isValid()
406           } // first IO is not null
407         } // if ( isOCC )
408       } // if ( selection not empty )
409     }
410   }
411
412   app->updateActions(); //SRN: To update a Save button in the toolbar
413 }
414
415 void GEOMToolsGUI::OnTexture()
416 {
417   SALOME_ListIO selected;
418   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
419   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
420   if ( app && appStudy ) {
421     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
422     if ( aSelMgr ) {
423       aSelMgr->selectedObjects( selected );
424       if ( !selected.IsEmpty() ) {
425         SUIT_ViewWindow* window = app->desktop()->activeWindow();
426         bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
427         if ( isOCC ) {
428           QString aTexture = QFileDialog::getOpenFileName(window,tr( "GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
429           if( !aTexture.isEmpty() )
430           {
431             SUIT_OverrideCursor();
432             OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
433             Handle (AIS_InteractiveContext) ic = vm->getAISContext();
434             Handle(AIS_InteractiveObject) io ;
435             for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
436               io = GEOMBase::GetAIS( It.Value(), true );
437               if ( !io.IsNull() ) {
438                 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
439                   Handle(GEOM_AISShape)::DownCast( io )->SetTextureFileName(TCollection_AsciiString(aTexture.toStdString().c_str()));
440                 io->Redisplay( Standard_True );
441               } // if ( !io.IsNull() )
442             } // for
443             ic->UpdateCurrentViewer();
444             GeometryGUI::Modified();
445             GeometryGUI* myGeomGUI = getGeometryGUI();
446             myGeomGUI->OnGUIEvent(GEOMOp::OpTexture);
447           } // if ( !selFile.isEmpty() )
448         } // if ( isOCC )
449       } // if ( selection not empty )
450     }
451   }
452
453   app->updateActions(); //SRN: To update a Save button in the toolbar
454 }
455
456 void GEOMToolsGUI::OnTransparency()
457 {
458   GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
459   dlg.exec();
460 }
461
462 void GEOMToolsGUI::OnChangeTransparency( bool increase )
463 {
464  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
465   if ( !app )
466     return;
467   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
468   if ( !aSelMgr )
469     return;
470   SALOME_ListIO selected;
471   aSelMgr->selectedObjects( selected );
472   if ( selected.IsEmpty() )
473     return;
474
475   Handle(SALOME_InteractiveObject) FirstIOS =  selected.First();
476   if ( FirstIOS.IsNull() )
477     return;
478
479   // Delta
480   float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
481   if ( !increase )
482     delta *= -1;
483         
484   SUIT_ViewWindow* window = app->desktop()->activeWindow();
485   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
486   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
487
488   if ( isVTK ) {
489     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
490     if ( !vtkVW )
491       return;
492     SVTK_View* aView = vtkVW->getView();
493    
494     float transp = aView->GetTransparency(FirstIOS);
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     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
504       aView->SetTransparency( It.Value(), transp );
505     }
506     aView->Repaint();
507     GeometryGUI::Modified();
508   } // if ( isVTK )
509         
510   else if ( isOCC ) {
511     GEOMBase* gb = new GEOMBase();
512     Handle(GEOM_AISShape) aisShape;
513    
514     aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
515     if( aisShape.IsNull() )
516       return;
517     float transp = aisShape->Transparency();
518
519     // Compute new transparency value
520     transp = transp + delta;
521     if ( transp < 0 )
522       transp = 0;
523     else if ( transp > 1 )
524       transp = 1;
525
526     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
527     if ( !vm )
528       return;
529     Handle(AIS_InteractiveContext) ic = vm->getAISContext();
530     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
531       aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
532       if ( !aisShape.IsNull() ) {
533         ic->SetTransparency( aisShape, transp, false );
534         ic->Redisplay( aisShape, Standard_False, Standard_True );
535       }
536     } // for...
537     ic->UpdateCurrentViewer();
538     GeometryGUI::Modified();
539   } // if ( isOCC )
540 }
541
542 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
543 {
544   SalomeApp_Application* app =
545     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
546   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
547   SUIT_ViewWindow* window = app->desktop()->activeWindow();
548
549   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
550   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
551
552   if(isOCC){ // if is OCCViewer
553
554     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
555     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
556
557     ic->InitCurrent();
558     if ( ic->MoreCurrent() ) {
559       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
560       CurObject->restoreIsoNumbers();
561       Handle(AIS_Drawer)    CurDrawer = CurObject->Attributes();
562
563       int UIso = CurDrawer->UIsoAspect()->Number();
564       int VIso = CurDrawer->VIsoAspect()->Number();
565
566       int newNbUIso = -1;
567       int newNbVIso = -1;
568
569       if ( actionType == SHOWDLG ) {
570         GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
571           new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
572
573         NbIsosDlg->setU( UIso );
574         NbIsosDlg->setV( VIso );
575
576         if ( NbIsosDlg->exec() ) {
577           SUIT_OverrideCursor();
578           
579           newNbUIso = NbIsosDlg->getU();
580           newNbVIso = NbIsosDlg->getV();
581         } else //Cancel case
582           return;
583       }
584       else if ( actionType == INCR || actionType == DECR ) {
585         int delta = 1;
586         if (actionType == DECR)
587           delta = -1;
588         
589         newNbUIso = UIso + delta;
590         newNbVIso = VIso + delta;
591
592         if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
593           return;
594       }
595
596       for(; ic->MoreCurrent(); ic->NextCurrent()) {
597         int aMgrId = window->getViewManager()->getGlobalId();
598         CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
599
600         Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
601
602         QVariant v = aStudy->getObjectProperty( aMgrId, CurObject->getIO()->getEntry(), EDGE_WIDTH_PROP , QVariant() );
603
604         int width = v.isValid() ? v.toInt() : 1;
605
606         CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, width , newNbUIso) );
607         CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, width , newNbVIso) );
608
609         CurObject->storeIsoNumbers();
610         
611         ic->SetLocalAttributes(CurObject, CurDrawer);
612         ic->Redisplay(CurObject);
613
614         QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
615         aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_PROP, anIsos);
616       }
617     }
618     GeometryGUI::Modified();
619   }
620   else if(isVTK){ // if is VTKViewer
621     //
622     // Warning. It's works incorrect. must be recheked.
623     //
624     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
625       ( SUIT_Session::session()->activeApplication() );
626     if ( !app )
627       return;
628     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
629     if ( !aSelMgr )
630       return;
631     SALOME_ListIO selected;
632     aSelMgr->selectedObjects( selected );
633     if ( selected.IsEmpty() )
634       return;
635
636     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
637     if ( !vtkVW )
638       return;
639
640     SALOME_View* view = GEOM_Displayer::GetActiveView();
641
642     vtkActorCollection* aCollection = vtkActorCollection::New();
643
644     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
645       Handle(SALOME_InteractiveObject) anIObject = It.Value();
646       SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
647       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
648       if ( vtkPrs ) {
649         vtkActorCollection* anActors = vtkPrs->GetObjects();
650         anActors->InitTraversal();
651         vtkActor* anAct = anActors->GetNextActor();
652         aCollection->AddItem(anAct);
653       }
654     }
655
656     if(aCollection)
657       aCollection->InitTraversal();
658     else
659       return;
660
661     int UIso = 0;
662     int VIso = 0;
663
664     vtkActor* anAct = aCollection->GetNextActor();
665     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
666       anActor->RestoreIsoNumbers();
667       anActor->GetNbIsos(UIso,VIso);
668     }
669     else
670       return;
671     
672     int newNbUIso = -1;
673     int newNbVIso = -1;
674
675     if ( actionType == SHOWDLG ) {
676       GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
677         new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
678
679       NbIsosDlg->setU( UIso );
680       NbIsosDlg->setV( VIso );
681
682       if ( NbIsosDlg->exec() ) {
683         SUIT_OverrideCursor();
684
685         newNbUIso = NbIsosDlg->getU();
686         newNbVIso = NbIsosDlg->getV();
687       } else 
688         return; //Cancel case 
689     }
690     else if ( actionType == INCR || actionType == DECR ) {
691       int delta = 1;
692       if (actionType == DECR)
693         delta = -1;
694       
695       newNbUIso = UIso + delta;
696       newNbVIso = VIso + delta;
697       
698       if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
699         return;
700     } 
701     
702     while( anAct!=NULL ) {
703       if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
704         // There are no casting to needed actor.
705         int aIsos[2]={newNbUIso,newNbVIso};
706         anActor->SetNbIsos(aIsos);
707         anActor->StoreIsoNumbers();
708
709         QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
710         int aMgrId = window->getViewManager()->getGlobalId();
711         aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos);
712       }
713       anAct = aCollection->GetNextActor();
714     }
715     view->Repaint();
716     GeometryGUI::Modified();
717   } // end vtkviewer
718 }
719
720 void GEOMToolsGUI::OnDeflection()
721 {
722   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
723   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
724
725
726   bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
727   bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
728   int mgrId = window->getViewManager()->getGlobalId();
729
730   if (isOCC) { // if is OCCViewer
731     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
732     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
733
734     ic->InitCurrent();
735     if (ic->MoreCurrent()) {
736       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
737
738       Standard_Real aDC, aPrevDC;
739       Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
740       if (!isOwnDC)
741         aDC = ic->DeviationCoefficient();
742
743       GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
744         (SUIT_Session::session()->activeApplication()->desktop());
745       DeflectionDlg->setTheDC(aDC);
746       double aNewDC = 0.0;
747       bool ok = false;
748       while (!ok) {
749         if (DeflectionDlg->exec()) {
750           SUIT_OverrideCursor();
751           aNewDC = DeflectionDlg->getTheDC();
752           ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
753           if (ok) {
754             for (; ic->MoreCurrent(); ic->NextCurrent()) {
755               CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
756               ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
757               ic->Redisplay(CurObject);
758               appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC);
759             }
760           }
761         }
762         else {
763           ok = true;
764         }
765       }
766     }
767     GeometryGUI::Modified();
768   }
769   else if (isVTK) { // if is VTKViewer
770     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
771       (SUIT_Session::session()->activeApplication());
772     if (!app)
773       return;
774
775     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
776     if (!aSelMgr)
777       return;
778
779     SALOME_ListIO selected;
780     aSelMgr->selectedObjects(selected);
781     if (selected.IsEmpty())
782       return;
783
784     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
785     if (!vtkVW)
786       return;
787
788     SALOME_View* view = GEOM_Displayer::GetActiveView();
789
790     vtkActorCollection* aCollection = vtkActorCollection::New();
791
792     for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
793       Handle(SALOME_InteractiveObject) anIObject = It.Value();
794       SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
795       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
796       if (vtkPrs) {
797         vtkActorCollection* anActors = vtkPrs->GetObjects();
798         anActors->InitTraversal();
799         vtkActor* anAct = anActors->GetNextActor();
800         aCollection->AddItem(anAct);
801       }
802     }
803
804     if (aCollection)
805       aCollection->InitTraversal();
806     else
807       return;
808
809     double aDC = 0.;
810
811     vtkActor* anAct = aCollection->GetNextActor();
812     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
813       aDC = anActor->GetDeflection();
814     else
815       return;
816
817     GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
818       (SUIT_Session::session()->activeApplication()->desktop());
819     DeflectionDlg->setTheDC(aDC);
820     if (DeflectionDlg->exec()) {
821       SUIT_OverrideCursor();
822       aDC = DeflectionDlg->getTheDC();
823       while (anAct != NULL) {
824         if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
825           // There are no casting to needed actor.
826           anActor->SetDeflection(aDC);
827           appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC);
828         }
829         anAct = aCollection->GetNextActor();
830       }
831     }
832     GeometryGUI::Modified();
833   } // end vtkviewer
834 }
835
836 void GEOMToolsGUI::OnSelectOnly(int mode)
837 {
838   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
839   if ( app ) {
840     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
841     GEOM_Displayer aDisp (appStudy);
842     aDisp.GlobalSelection(mode);
843     getGeometryGUI()->setLocalSelectionMode(mode);
844   }
845 }
846
847 void GEOMToolsGUI::OnShowHideChildren( bool show )
848 {
849   SALOME_ListIO selected;
850   SalomeApp_Application* app =
851     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
852   
853   SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
854   
855   GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
856
857   if ( app && disp ) {
858     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
859     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
860     if ( aSelMgr && appStudy ) {
861       aSelMgr->selectedObjects( selected );
862       if ( !selected.IsEmpty() ) {
863         _PTR(Study) aStudy = appStudy->studyDS();
864         _PTR(StudyBuilder) B = aStudy->NewBuilder();
865
866         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
867         if ( aLocked ) {
868           SUIT_MessageBox::warning( app->desktop(),
869                                     QObject::tr( "WRN_WARNING" ),
870                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
871           return;
872         }
873
874         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
875           Handle(SALOME_InteractiveObject) IObject = It.Value();
876
877           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
878           _PTR(GenericAttribute) anAttr;
879           if ( obj ) {
880             _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
881             aExp->SetExpandable( show );
882             if(!show)
883               disp->EraseWithChildren(IObject,true);
884           } // if ( obj )
885         } // iterator
886       }
887     }
888     app->updateObjectBrowser( false );
889     app->updateActions();
890   }
891 }
892
893 void GEOMToolsGUI::OnPointMarker()
894 {
895   GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
896   dlg.exec();
897 }
898
899 void GEOMToolsGUI::OnMaterialProperties()
900 {
901   GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
902   dlg.exec();
903 }
904
905 void GEOMToolsGUI::OnUnpublishObject() {
906   SALOME_ListIO selected;
907   SalomeApp_Application* app =
908     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
909
910   SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
911
912   GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
913   
914   if ( app && disp ) {
915     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
916     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
917     if ( aSelMgr && appStudy ) {
918       aSelMgr->selectedObjects( selected );
919       if ( !selected.IsEmpty() ) {
920         _PTR(Study) aStudy = appStudy->studyDS();
921         _PTR(StudyBuilder) B = aStudy->NewBuilder();
922
923         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
924         if ( aLocked ) {
925           SUIT_MessageBox::warning( app->desktop(),
926                                     QObject::tr( "WRN_WARNING" ),
927                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
928           return;
929         }
930
931         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
932           Handle(SALOME_InteractiveObject) IObject = It.Value();
933
934           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
935           _PTR(GenericAttribute) anAttr;
936           if ( obj ) {
937             _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
938             aDrw->SetDrawable( false );
939             disp->EraseWithChildren(IObject);
940           } // if ( obj )
941         } // iterator
942         aSelMgr->clearSelected();
943       }
944     }
945     app->updateObjectBrowser( false );
946     app->updateActions();
947   }
948  
949 }
950
951 void GEOMToolsGUI::OnPublishObject() {
952   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
953   if(!app)
954     return;
955
956   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
957   if(!appStudy)
958     return;
959   
960   _PTR(Study) aStudy = appStudy->studyDS();
961   
962   if(!aStudy)
963     return;
964
965   //Check lock of the study
966   bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
967   if ( aLocked ) {
968     SUIT_MessageBox::warning( app->desktop(),
969                               QObject::tr( "WRN_WARNING" ),
970                               QObject::tr( "WRN_STUDY_LOCKED" ) );
971     return;
972   } 
973   
974   GEOMToolsGUI_PublishDlg * publishDlg =
975     new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
976   publishDlg->exec();
977 }
978
979
980 void GEOMToolsGUI::OnEdgeWidth()
981 {
982   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
983   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
984
985
986   bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
987   bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
988   int mgrId = window->getViewManager()->getGlobalId();
989
990   if (isOCC) { // if is OCCViewer
991     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
992     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
993     SALOME_View* view = GEOM_Displayer::GetActiveView();
994     ic->InitCurrent();
995     if (ic->MoreCurrent()) {
996       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
997
998       int aWidth = (int)CurObject->Width();
999
1000       GEOMToolsGUI_LineWidthDlg * Dlg = new GEOMToolsGUI_LineWidthDlg
1001         (SUIT_Session::session()->activeApplication()->desktop(),"EDGE_WIDTH_TLT");
1002       Dlg->setTheLW(aWidth);
1003       int aNewWidth = 0;
1004       if (Dlg->exec()) {
1005                 aNewWidth = Dlg->getTheLW();
1006                 bool ok = (aNewWidth != aWidth && aNewWidth != 0 );
1007                 if (ok) {
1008                   for(; ic->MoreCurrent(); ic->NextCurrent()) {
1009                         CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
1010                                 SOCC_Prs* aPrs =  dynamic_cast<SOCC_Prs*>(view->CreatePrs(CurObject->getIO()->getEntry()));
1011                                 AIS_ListOfInteractive anAISObjects;
1012                                 aPrs->GetObjects( anAISObjects );
1013                                 AIS_ListIteratorOfListOfInteractive aIter( anAISObjects );
1014                                 for ( ; aIter.More(); aIter.Next() ) {
1015                                   Handle(SALOME_AISShape) cur =  Handle(SALOME_AISShape)::DownCast(aIter.Value());
1016                                   if ( !cur.IsNull() ) {
1017                                         cur->SetWidth(aNewWidth);
1018                                         ic->Redisplay(cur);
1019                                   }
1020                                 }
1021                         appStudy->setObjectProperty(mgrId, CurObject->getIO()->getEntry(), EDGE_WIDTH_PROP, aNewWidth);
1022                   }
1023                 }
1024           }
1025     }
1026     else {
1027       return;
1028     }
1029     GeometryGUI::Modified();
1030   }
1031   else if (isVTK) { // if is VTKViewer
1032     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
1033       (SUIT_Session::session()->activeApplication());
1034     if (!app)
1035       return;
1036
1037     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1038     if (!aSelMgr)
1039       return;
1040
1041     SALOME_ListIO selected;
1042     aSelMgr->selectedObjects(selected);
1043     if (selected.IsEmpty())
1044       return;
1045
1046     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
1047     if (!vtkVW)
1048       return;
1049
1050     SALOME_View* view = GEOM_Displayer::GetActiveView();
1051
1052     vtkActorCollection* aCollection = vtkActorCollection::New();
1053
1054     for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
1055       Handle(SALOME_InteractiveObject) anIObject = It.Value();
1056       SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
1057       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
1058       if (vtkPrs) {
1059         vtkActorCollection* anActors = vtkPrs->GetObjects();
1060         anActors->InitTraversal();
1061         vtkActor* anAct = anActors->GetNextActor();
1062         aCollection->AddItem(anAct);
1063       }
1064     }
1065
1066     if (aCollection)
1067       aCollection->InitTraversal();
1068     else
1069       return;
1070
1071     int aWidth = 1;
1072
1073     vtkActor* anAct = aCollection->GetNextActor();
1074     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
1075       aWidth = anActor->GetWidth();
1076     else
1077       return;
1078
1079     GEOMToolsGUI_LineWidthDlg * Dlg = new GEOMToolsGUI_LineWidthDlg
1080       (SUIT_Session::session()->activeApplication()->desktop(),"EDGE_WIDTH_TLT");
1081     
1082     Dlg->setTheLW(aWidth);
1083     if (Dlg->exec()) {
1084       SUIT_OverrideCursor();
1085       aWidth = Dlg->getTheLW();
1086       while (anAct != NULL) {
1087         if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
1088           // There are no casting to needed actor.
1089           anActor->SetWidth(aWidth);
1090           appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), EDGE_WIDTH_PROP, aWidth);
1091         }
1092         anAct = aCollection->GetNextActor();
1093       }
1094     }
1095     GeometryGUI::Modified();
1096   } // end vtkviewer
1097 }
1098
1099
1100 void GEOMToolsGUI::OnIsosWidth() {
1101   SalomeApp_Application* app =
1102     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1103   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1104   SUIT_ViewWindow* window = app->desktop()->activeWindow();
1105
1106   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1107   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
1108
1109   if(isOCC){ // if is OCCViewer
1110
1111     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
1112     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
1113
1114     ic->InitCurrent();
1115     if ( ic->MoreCurrent() ) {
1116       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
1117       CurObject->restoreIsoNumbers();
1118       Handle(AIS_Drawer)    CurDrawer = CurObject->Attributes();
1119
1120       Handle(Graphic3d_AspectLine3d) asp = CurDrawer->UIsoAspect()->Aspect();
1121       
1122       Quantity_Color C;
1123       Aspect_TypeOfLine T;
1124       Standard_Real W;
1125       asp->Values(C,T,W);
1126
1127       int aWidth = (int)W;
1128
1129       GEOMToolsGUI_LineWidthDlg * Dlg =
1130         new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(),"ISOS_WIDTH_TLT" );
1131
1132       Dlg->setTheLW( aWidth );
1133
1134       if ( Dlg->exec() ) {
1135         SUIT_OverrideCursor();          
1136         aWidth = Dlg->getTheLW();
1137       } else //Cancel case
1138         return;
1139       
1140       for(; ic->MoreCurrent(); ic->NextCurrent()) {
1141         int aMgrId = window->getViewManager()->getGlobalId();
1142         CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
1143         
1144         Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
1145         
1146         CurObject->Attributes()->UIsoAspect()->SetWidth(aWidth);
1147         CurObject->Attributes()->VIsoAspect()->SetWidth(aWidth);
1148         
1149         ic->Redisplay(CurObject);
1150         
1151         aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_WIDTH_PROP, aWidth);
1152       }
1153       GeometryGUI::Modified();
1154     }
1155   }
1156   else if(isVTK){ // if is VTKViewer
1157     //
1158     // Warning. It's works incorrect. must be recheked.
1159     //
1160     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
1161       ( SUIT_Session::session()->activeApplication() );
1162     if ( !app )
1163       return;
1164     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1165     if ( !aSelMgr )
1166       return;
1167     SALOME_ListIO selected;
1168     aSelMgr->selectedObjects( selected );
1169     if ( selected.IsEmpty() )
1170       return;
1171
1172     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
1173     if ( !vtkVW )
1174       return;
1175
1176     SALOME_View* view = GEOM_Displayer::GetActiveView();
1177
1178     vtkActorCollection* aCollection = vtkActorCollection::New();
1179
1180     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
1181       Handle(SALOME_InteractiveObject) anIObject = It.Value();
1182       SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
1183       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
1184       if ( vtkPrs ) {
1185         vtkActorCollection* anActors = vtkPrs->GetObjects();
1186         anActors->InitTraversal();
1187         vtkActor* anAct = anActors->GetNextActor();
1188         aCollection->AddItem(anAct);
1189       }
1190     }
1191
1192     if(aCollection)
1193       aCollection->InitTraversal();
1194     else
1195       return;
1196
1197     int aWidth = 1;
1198
1199     vtkActor* anAct = aCollection->GetNextActor();
1200     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
1201       aWidth = anActor->GetIsosWidth();
1202     }
1203     else
1204       return;
1205     
1206     GEOMToolsGUI_LineWidthDlg* Dlg =
1207       new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
1208     
1209     Dlg->setTheLW( aWidth );
1210     if (Dlg->exec() ) {
1211       SUIT_OverrideCursor();
1212       aWidth = Dlg->getTheLW();
1213     } else 
1214       return; //Cancel case 
1215     
1216     while( anAct!= NULL ) {
1217       if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
1218         // There are no casting to needed actor.
1219         anActor->SetIsosWidth(aWidth);
1220         int aMgrId = window->getViewManager()->getGlobalId();
1221         aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_WIDTH_PROP, aWidth);
1222       }
1223       anAct = aCollection->GetNextActor();
1224     }
1225     
1226     view->Repaint();
1227     GeometryGUI::Modified();
1228   } // end vtkviewer  
1229 }
1230
1231 void GEOMToolsGUI::OnBringToFront() {
1232  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1233   if ( !app )
1234     return;
1235
1236   SalomeApp_Module* mod = dynamic_cast<SalomeApp_Module*>(app->activeModule());
1237   if(!mod)
1238     return;
1239   
1240   GEOM_Displayer* disp  = dynamic_cast<GEOM_Displayer*>(mod->displayer());
1241   
1242   if(!disp)
1243     return;
1244   
1245   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1246   if ( !aSelMgr )
1247     return;
1248
1249   SALOME_ListIO selected;
1250   aSelMgr->selectedObjects( selected );
1251   if ( selected.IsEmpty() )
1252     return;
1253
1254   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());  
1255   if(!appStudy)
1256     return;
1257
1258   SUIT_ViewWindow* window = app->desktop()->activeWindow();
1259
1260   OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
1261   if ( !vm )
1262     return;
1263   
1264   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1265
1266   QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
1267   bool checked = a->isChecked();
1268   
1269   if ( isOCC ) {
1270     GEOMBase* gb = new GEOMBase();
1271     Handle(GEOM_AISShape) aisShape;
1272    
1273     Handle(AIS_InteractiveContext) ic = vm->getAISContext();
1274     SALOME_ListIO anIOlst;
1275     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
1276       aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
1277       if ( !aisShape.IsNull() ) {
1278         aisShape->setTopLevel(checked);
1279         int aMgrId = window->getViewManager()->getGlobalId();
1280         appStudy->setObjectProperty( aMgrId, aisShape->getIO()->getEntry(), TOP_LEVEL_PROP, checked );
1281         anIOlst.Append(aisShape->getIO());
1282       }
1283     } // for...
1284     disp->Redisplay(anIOlst);
1285     GeometryGUI::Modified();
1286   } // if ( isOCC )
1287 }
1288
1289 void GEOMToolsGUI::OnClsBringToFront() {
1290   SalomeApp_Application* app =
1291     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1292   if(!app)
1293     return;
1294
1295   SalomeApp_Module* mod = dynamic_cast<SalomeApp_Module*>(app->activeModule());
1296   if(!mod)
1297     return;
1298   
1299   GEOM_Displayer* disp  = dynamic_cast<GEOM_Displayer*>(mod->displayer());
1300   
1301   if(!disp)
1302     return;
1303
1304
1305   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());  
1306   if(!appStudy)
1307     return;
1308   
1309   SUIT_ViewWindow* window = app->desktop()->activeWindow();  
1310   
1311   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1312   
1313   if(isOCC){ // if is OCCViewer
1314     
1315     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
1316     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
1317     
1318     SALOME_ListIO anIOlst;
1319     AIS_ListOfInteractive aList;
1320     ic->DisplayedObjects( aList );
1321     for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() ) {
1322       
1323       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(it.Value());
1324       
1325       if(CurObject.IsNull())
1326         continue;
1327       
1328       CurObject->setTopLevel(Standard_False);
1329       
1330       int aMgrId = window->getViewManager()->getGlobalId();
1331       appStudy->setObjectProperty( aMgrId, QString(CurObject->getIO()->getEntry()), TOP_LEVEL_PROP, Standard_False );
1332       anIOlst.Append(CurObject->getIO());
1333     }
1334     disp->Redisplay(anIOlst);
1335     GeometryGUI::Modified();
1336   }
1337 }
1338