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