Salome HOME
Merge from V6_main 12/04/2013
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_1.cxx
1 // Copyright (C) 2007-2013  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   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
135   if ( !app ) return;
136
137   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
138   if ( !appStudy ) return;
139
140   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
141   if ( !aSelMgr ) return;
142
143   SALOME_ListIO selected;
144   aSelMgr->selectedObjects( selected );
145   if ( selected.IsEmpty() ) return;
146
147   Handle(SALOME_InteractiveObject) anIObject = selected.First();
148
149   _PTR(Study) aStudy = appStudy->studyDS();
150   _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
151   GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
152   if (CORBA::is_nil(aMainObject)) return;
153
154   aMainObject->SetAutoColor( true );
155
156   QList<SALOMEDS::Color> aReservedColors;
157
158   GEOM_Displayer displayer ( appStudy );
159
160   SALOME_View* window = displayer.GetActiveView();
161   if ( !window ) return;
162
163   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
164
165   for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
166   {
167     _PTR(SObject) aChildSObject( it->Value() );
168     GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
169     if( CORBA::is_nil( aChildObject ) )
170       continue;
171
172 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
173     if( aChildObject->GetType() != GEOM_GROUP )
174       continue;
175 #endif                    // GENERAL_AUTOCOLOR
176
177 #ifdef SIMPLE_AUTOCOLOR   // simplified algorithm for auto-colors
178     SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
179 #else                     // old algorithm  for auto-colors
180     SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
181     aReservedColors.append( aColor );
182 #endif                    // SIMPLE_AUTOCOLOR
183     aChildObject->SetColor( aColor );
184   
185     QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
186
187     SUIT_OverrideCursor();
188     
189     appStudy->setObjectProperty( aMgrId, aChildObject->GetEntry(), GEOM::propertyName( GEOM::Color ), c );
190     Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject( aChildObject->GetStudyEntry(), "GEOM", "" );
191     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
192   }
193   displayer.UpdateViewer();
194
195   // update actions
196   appStudy->Modified();
197   app->updateActions(); //SRN: To update a Save button in the toolbar
198 }
199
200 void GEOMToolsGUI::OnDisableAutoColor()
201 {
202   SALOME_ListIO selected;
203   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
204   if( !app )
205     return;
206
207   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
208   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
209   if( !aSelMgr || !appStudy )
210     return;
211
212   aSelMgr->selectedObjects( selected );
213   if( selected.IsEmpty() )
214     return;
215
216   Handle(SALOME_InteractiveObject) anIObject = selected.First();
217
218   _PTR(Study) aStudy = appStudy->studyDS();
219   _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
220   GEOM::GEOM_Object_var aMainObject =  GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
221   if( CORBA::is_nil( aMainObject ) )
222     return;
223
224   aMainObject->SetAutoColor( false );
225 }
226
227 void GEOMToolsGUI::OnColor()
228 {
229   // get active application
230   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
231   if ( !app ) return;
232
233   // get current study
234   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
235   if ( !appStudy ) return;
236
237   // get selection manager
238   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
239   if ( !aSelMgr ) return;
240
241   // get selection
242   SALOME_ListIO selected;
243   aSelMgr->selectedObjects( selected );
244   if ( selected.IsEmpty() ) return;
245
246   GEOM_Displayer displayer( appStudy );
247
248   // get active view
249   SALOME_View* window = displayer.GetActiveView();
250   if ( !window ) return;
251
252   // get view id
253   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
254
255   QColor color;
256   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
257
258   // show Choose Color dialog box
259   color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
260   if ( !color.isValid() ) return;
261
262   // iterate through list of objects and assign new color
263   SUIT_OverrideCursor();
264   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
265     Handle( SALOME_InteractiveObject ) io = It.Value();
266     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Color ), color );
267     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
268   }
269   displayer.UpdateViewer();
270   GeometryGUI::Modified();
271
272   // update actions
273   app->updateActions(); //SRN: To update a Save button in the toolbar
274 }
275
276 void GEOMToolsGUI::OnTexture()
277 {
278   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
279   if ( !app ) return;
280
281   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
282   if ( !appStudy ) return;
283
284   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
285   if ( !aSelMgr ) return;
286
287   SALOME_ListIO selected;  
288   aSelMgr->selectedObjects( selected );
289   if ( selected.IsEmpty() ) return;
290
291   GEOM_Displayer displayer( appStudy );
292   SALOME_View* window = displayer.GetActiveView();
293   if ( !window ) return;
294
295   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
296
297   QString aTexture = QFileDialog::getOpenFileName( dynamic_cast< SUIT_ViewWindow* >( window ),tr("GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
298   if( !aTexture.isEmpty() ) {
299     displayer.SetTexture( aTexture.toStdString() );
300     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
301       Handle( SALOME_InteractiveObject ) io = It.Value();
302       appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), 3 );
303       if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
304     }
305   }
306   displayer.UpdateViewer();
307   GeometryGUI::Modified();
308
309   // update actions
310   app->updateActions(); //SRN: To update a Save button in the toolbar
311 }
312
313 void GEOMToolsGUI::OnTransparency()
314 {
315   GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
316   dlg.exec();
317 }
318
319 void GEOMToolsGUI::OnChangeTransparency( bool increase )
320 {
321   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
322   if ( !app ) return;
323
324   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
325   if( !appStudy) return;
326
327   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
328   if ( !aSelMgr ) return;
329
330   SALOME_ListIO selected;
331   aSelMgr->selectedObjects( selected );
332   if ( selected.IsEmpty() ) return;
333
334   GEOM_Displayer displayer( appStudy );
335   SALOME_View* window = displayer.GetActiveView();
336   if ( !window ) return;
337
338   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
339
340   // Delta
341   float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
342   if ( !increase )
343     delta *= -1;
344
345   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Transparency ), QVariant() );
346   float transp  = v.isValid() ? v.toFloat() : 1;
347
348   // Compute new transparency value
349   transp = transp + delta;
350   if ( transp < 0 )
351     transp = 0;
352   else if ( transp > 1 )
353     transp = 1;
354
355   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
356     Handle( SALOME_InteractiveObject ) io = It.Value();
357     appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::Transparency ), transp );
358     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
359   }
360   displayer.UpdateViewer();
361   GeometryGUI::Modified();
362 }
363
364 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
365 {
366   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
367   if ( !app ) return;
368
369   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
370   if ( !appStudy ) return;
371
372   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
373   if ( !aSelMgr ) return;
374
375   SALOME_ListIO selected;
376   aSelMgr->selectedObjects( selected );
377   if ( selected.IsEmpty() ) return;
378
379   GEOM_Displayer displayer( appStudy );
380   SALOME_View* window = displayer.GetActiveView();
381   if ( !window ) return;
382  
383   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
384
385   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::NbIsos ) , QVariant() );
386   QString aStr = v.toString();
387   QStringList aStrList = aStr.split( GEOM::subSectionSeparator() );
388   int UIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_u", 1 );
389   int VIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_v", 1 );
390   if ( aStrList.count() == 2 ) {
391     if ( !aStrList[0].isEmpty() ) UIso = aStrList[0].toInt();
392     if ( !aStrList[1].isEmpty() ) VIso = aStrList[1].toInt();
393   }
394
395   int newNbUIso = -1;
396   int newNbVIso = -1;
397
398   if ( actionType == SHOWDLG ) {
399     GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
400       new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
401
402     NbIsosDlg->setU( UIso );
403     NbIsosDlg->setV( VIso );
404
405     if ( NbIsosDlg->exec() ) {
406       SUIT_OverrideCursor();     
407       newNbUIso = NbIsosDlg->getU();
408       newNbVIso = NbIsosDlg->getV();
409     } else //Cancel case
410       return;
411   }
412   else if ( actionType == INCR || actionType == DECR ) {
413     int delta = 1;
414     if (actionType == DECR)
415       delta = -1;
416
417     newNbUIso = UIso + delta;
418     newNbVIso = VIso + delta;
419
420     if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
421       return;
422   }
423
424   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
425     Handle( SALOME_InteractiveObject ) io = It.Value();
426     QString anIsos = QString( "%1%2%3" ).arg( newNbUIso ).arg( GEOM::subSectionSeparator() ).arg( newNbVIso );
427     appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos );
428     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
429   }
430   displayer.UpdateViewer();
431   GeometryGUI::Modified();
432 }
433
434 void GEOMToolsGUI::OnDeflection()
435 {
436   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
437   if ( !app ) return;
438
439   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
440   if ( !appStudy ) return;
441
442   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
443   if ( !aSelMgr ) return;
444
445   SALOME_ListIO selected;
446   aSelMgr->selectedObjects( selected );
447   if ( selected.IsEmpty() ) return;
448
449   GEOM_Displayer displayer( appStudy );
450   SALOME_View* window = displayer.GetActiveView();
451   if ( !window ) return;
452
453   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
454
455   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
456   double aDC =  v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
457
458   GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
459     ( SUIT_Session::session()->activeApplication()->desktop() );
460   DeflectionDlg->setTheDC( aDC );
461   if ( DeflectionDlg->exec() ) {
462     SUIT_OverrideCursor();
463     aDC = DeflectionDlg->getTheDC();
464
465     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
466       Handle( SALOME_InteractiveObject ) io = It.Value();
467       appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC );
468       if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
469     }
470   }
471   displayer.UpdateViewer();
472   GeometryGUI::Modified();
473 }
474
475 void GEOMToolsGUI::OnSelectOnly(int mode)
476 {
477   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
478   if ( app ) {
479     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
480     GEOM_Displayer aDisp (appStudy);
481     aDisp.GlobalSelection(mode);
482     getGeometryGUI()->setLocalSelectionMode(mode);
483   }
484 }
485
486 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
487 {
488   SALOME_ListIO selected;
489   SalomeApp_Application* app =
490     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
491   
492   SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
493   
494   GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
495
496   if ( app && disp ) {
497     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
498     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
499     if ( aSelMgr && appStudy ) {
500       aSelMgr->selectedObjects( selected );
501       if ( !selected.IsEmpty() ) {
502         _PTR(Study) aStudy = appStudy->studyDS();
503         _PTR(StudyBuilder) B = aStudy->NewBuilder();
504
505         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
506         if ( aLocked ) {
507           SUIT_MessageBox::warning( app->desktop(),
508                                     QObject::tr( "WRN_WARNING" ),
509                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
510           return;
511         }
512
513         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
514           Handle(SALOME_InteractiveObject) IObject = It.Value();
515
516           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
517           _PTR(GenericAttribute) anAttr;
518           if ( obj ) {
519             _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
520             aExp->SetExpandable( show );
521             if(!show)
522               disp->EraseWithChildren(IObject,true);
523           } // if ( obj )
524         } // iterator
525       }
526     }
527     app->updateObjectBrowser( false );
528     app->updateActions();
529   }
530 }
531
532 void GEOMToolsGUI::OnPointMarker()
533 {
534   GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
535   dlg.exec();
536 }
537
538 void GEOMToolsGUI::OnMaterialProperties()
539 {
540  GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
541  dlg->show();
542 }
543
544 void GEOMToolsGUI::OnMaterialsLibrary()
545 {
546         GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
547         dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
548   dlg.exec();
549 }
550
551 void GEOMToolsGUI::OnUnpublishObject() {
552   SALOME_ListIO selected;
553   SalomeApp_Application* app =
554     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
555
556   SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
557
558   GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
559   
560   if ( app && disp ) {
561     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
562     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
563     if ( aSelMgr && appStudy ) {
564       aSelMgr->selectedObjects( selected );
565       if ( !selected.IsEmpty() ) {
566         _PTR(Study) aStudy = appStudy->studyDS();
567         _PTR(StudyBuilder) B = aStudy->NewBuilder();
568
569         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
570         if ( aLocked ) {
571           SUIT_MessageBox::warning( app->desktop(),
572                                     QObject::tr( "WRN_WARNING" ),
573                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
574           return;
575         }
576
577         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
578           Handle(SALOME_InteractiveObject) IObject = It.Value();
579
580           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
581           _PTR(GenericAttribute) anAttr;
582           if ( obj ) {
583             _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
584             aDrw->SetDrawable( false );
585             disp->EraseWithChildren(IObject);
586           } // if ( obj )
587         } // iterator
588         aSelMgr->clearSelected();
589       }
590     }
591     app->updateObjectBrowser( false );
592     app->updateActions();
593   }
594  
595 }
596
597 void GEOMToolsGUI::OnPublishObject() {
598   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
599   if(!app)
600     return;
601
602   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
603   if(!appStudy)
604     return;
605   
606   _PTR(Study) aStudy = appStudy->studyDS();
607   
608   if(!aStudy)
609     return;
610
611   //Check lock of the study
612   bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
613   if ( aLocked ) {
614     SUIT_MessageBox::warning( app->desktop(),
615                               QObject::tr( "WRN_WARNING" ),
616                               QObject::tr( "WRN_STUDY_LOCKED" ) );
617     return;
618   } 
619   
620   GEOMToolsGUI_PublishDlg * publishDlg =
621     new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
622   publishDlg->exec();
623 }
624
625
626 void GEOMToolsGUI::OnEdgeWidth()
627 {
628   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
629   if ( !app ) return;
630
631   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
632   if ( !appStudy ) return;
633
634   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
635   if ( !aSelMgr ) return;
636
637   SALOME_ListIO selected;
638   aSelMgr->selectedObjects( selected );
639   if ( selected.IsEmpty() ) return;
640
641   GEOM_Displayer displayer( appStudy );
642
643   SALOME_View* window = displayer.GetActiveView();
644   if ( !window ) return;
645
646   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
647
648   GEOMToolsGUI_LineWidthDlg* Dlg =
649     new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
650
651   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
652   int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
653
654   Dlg->setTheLW( aWidth );
655   if ( Dlg->exec() ) {
656     SUIT_OverrideCursor();
657     aWidth = Dlg->getTheLW();
658   } else
659     return; //Cancel case
660   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
661     Handle( SALOME_InteractiveObject ) io = It.Value();
662     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
663     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
664     }
665   displayer.UpdateViewer();
666   GeometryGUI::Modified();
667 }
668
669
670 void GEOMToolsGUI::OnIsosWidth() {
671   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
672   if ( !app ) return;
673
674   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
675   if ( !appStudy ) return;
676
677   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
678   if ( !aSelMgr ) return;
679
680   SALOME_ListIO selected;
681   aSelMgr->selectedObjects( selected );
682   if ( selected.IsEmpty() ) return;
683
684   GEOM_Displayer displayer( appStudy );
685
686   SALOME_View* window = displayer.GetActiveView();
687   if ( !window ) return;
688
689   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
690
691   GEOMToolsGUI_LineWidthDlg* Dlg =
692     new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
693
694   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
695   int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
696
697   Dlg->setTheLW( aWidth );
698   if ( Dlg->exec() ) {
699     SUIT_OverrideCursor();
700     aWidth = Dlg->getTheLW();
701   } else
702     return; //Cancel case
703   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
704     Handle( SALOME_InteractiveObject ) io = It.Value();
705     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
706     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
707   }
708   displayer.UpdateViewer();
709   GeometryGUI::Modified();
710 }
711
712 void GEOMToolsGUI::OnBringToFront() {
713   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
714   if ( !app ) return;
715
716   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());  
717   if (!appStudy) return;
718
719   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
720   if ( !aSelMgr ) return;
721
722   SALOME_ListIO selected;
723   aSelMgr->selectedObjects( selected );
724   if ( selected.IsEmpty() ) return;
725
726   GEOM_Displayer displayer( appStudy );
727
728   SALOME_View* window = displayer.GetActiveView();
729   if ( !window ) return;
730
731   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
732
733   QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
734   bool checked = a->isChecked();
735
736   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
737     Handle( SALOME_InteractiveObject ) io = It.Value();
738     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
739     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
740   }
741   displayer.UpdateViewer();
742   GeometryGUI::Modified();
743 }
744
745 void GEOMToolsGUI::OnClsBringToFront() {
746   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
747   if ( !app ) return;
748
749   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
750   if ( !appStudy ) return;
751
752   GEOM_Displayer displayer( appStudy );
753
754   SALOME_View* window = displayer.GetActiveView();
755   if ( !window ) return;
756
757   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
758
759   SALOME_ListIO anIOlst;
760   window->GetVisible( anIOlst );
761
762   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
763     Handle( SALOME_InteractiveObject ) io = It.Value();
764     appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
765     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
766   }
767   displayer.Redisplay( anIOlst );
768   displayer.UpdateViewer();
769   GeometryGUI::Modified();
770 }
771   
772 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
773 {
774   if ( !theParam.canConvert<QString>() ) return;
775   
776   QString theName = theParam.toString();
777
778   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
779   if ( !app ) return;
780   
781   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
782   if ( !study ) return;
783   
784   LightApp_SelectionMgr* selMgr = app->selectionMgr();
785
786   SALOME_ListIO selected;
787   selMgr->selectedObjects( selected );
788
789   if ( selected.IsEmpty() ) return;
790   
791   GEOM_Displayer displayer( study );
792
793   SALOME_View* window = displayer.GetActiveView();
794   if ( !window ) return;
795   
796   int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
797
798   Material_Model aModel;
799   aModel.fromResources( theName );
800   QString prop = aModel.toProperties();
801
802   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
803     Handle(SALOME_InteractiveObject) io = It.Value();
804     study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
805     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
806   }
807   displayer.UpdateViewer();
808 }