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