Salome HOME
90ea6bf251878f26c845254fc5fd68b8f019fc3a
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_1.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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 <DependencyTree_ViewModel.h>
50 #include <DependencyTree_View.h>
51 #include <DependencyTree_Selector.h>
52
53 #include <Basics_OCCTVersion.hxx>
54
55 #include <SALOME_ListIO.hxx>
56 #include <SALOME_ListIteratorOfListIO.hxx>
57
58 #include <SALOMEDS_SObject.hxx>
59
60 #include <SOCC_Prs.h>
61
62 #include <SVTK_Prs.h>
63 #include <SVTK_ViewModel.h>
64 #include <SVTK_ViewWindow.h>
65 #include <SVTK_View.h>
66
67 #include <OCCViewer_ViewModel.h>
68
69 #include <SUIT_ViewManager.h>
70 #include <SUIT_Desktop.h>
71 #include <SUIT_ResourceMgr.h>
72 #include <SUIT_Session.h>
73 #include <SUIT_OverrideCursor.h>
74 #include <SUIT_MessageBox.h>
75 #include <SUIT_Tools.h>
76
77 #include <SalomeApp_Application.h>
78 #include <SalomeApp_Study.h>
79 #include <SalomeApp_Module.h>
80
81 #include <LightApp_SelectionMgr.h>
82 #include <LightApp_NameDlg.h>
83
84 #include <GEOMImpl_Types.hxx>
85
86 #include "utilities.h"
87
88 // OCCT Includes
89 #include <AIS_Drawer.hxx>
90 #include <Prs3d_IsoAspect.hxx>
91 #include <Prs3d_PointAspect.hxx>
92 #include <Graphic3d_AspectMarker3d.hxx>
93 #include <Graphic3d_AspectLine3d.hxx>
94 #include <AIS_ListIteratorOfListOfInteractive.hxx>
95 #include <AIS_ListOfInteractive.hxx>
96
97
98 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
99 #include <TColStd_HArray1OfByte.hxx>
100 #else
101 #include <Graphic3d_HArray1OfBytes.hxx>
102 #endif
103
104 // QT Includes
105 #include <QAction>
106 #include <QColorDialog>
107 #include <QInputDialog>
108 #include <QFileDialog>
109 #include <QList>
110
111 #include <QGridLayout>
112 #include <QGroupBox>
113 #include <QSpinBox>
114 #include <QPushButton>
115 #include <QKeyEvent>
116
117 // VTK includes
118 #include <vtkRenderer.h>
119
120 class QtxDialog;
121 // If the next macro is defined, autocolor feature works for all sub-shapes;
122 // if it is undefined, autocolor feature works for groups only
123 #define GENERAL_AUTOCOLOR
124 // Below macro, when uncommented, switches on simplified (more performant) algorithm
125 // of auto-color picking up
126 #define SIMPLE_AUTOCOLOR
127
128 void GEOMToolsGUI::OnCheckGeometry()
129 {
130   SalomeApp_Application* app =
131     dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
132   PyConsole_Console* pyConsole = app->pythonConsole();
133
134   if (pyConsole)
135     pyConsole->exec("from GEOM_usinggeom import *");
136 }
137
138 void GEOMToolsGUI::OnAutoColor()
139 {
140   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
141   if ( !app ) return;
142
143   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
144   if ( !appStudy ) return;
145
146   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
147   if ( !aSelMgr ) return;
148
149   SALOME_ListIO selected;
150   aSelMgr->selectedObjects( selected );
151   if ( selected.IsEmpty() ) return;
152
153   Handle(SALOME_InteractiveObject) anIObject = selected.First();
154
155   _PTR(Study) aStudy = appStudy->studyDS();
156   _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
157   GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
158   if (CORBA::is_nil(aMainObject)) return;
159
160   aMainObject->SetAutoColor( true );
161
162   QList<SALOMEDS::Color> aReservedColors;
163
164   GEOM_Displayer displayer ( appStudy );
165
166   SALOME_View* window = displayer.GetActiveView();
167   if ( !window ) return;
168
169   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
170
171   for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
172   {
173     _PTR(SObject) aChildSObject( it->Value() );
174     GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
175     if( CORBA::is_nil( aChildObject ) )
176       continue;
177
178 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
179     if( aChildObject->GetType() != GEOM_GROUP )
180       continue;
181 #endif                    // GENERAL_AUTOCOLOR
182
183 #ifdef SIMPLE_AUTOCOLOR   // simplified algorithm for auto-colors
184     SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
185 #else                     // old algorithm  for auto-colors
186     SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
187     aReservedColors.append( aColor );
188 #endif                    // SIMPLE_AUTOCOLOR
189     aChildObject->SetColor( aColor );
190   
191     QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
192
193     SUIT_OverrideCursor();
194     
195     appStudy->setObjectProperty( aMgrId, aChildObject->GetEntry(), GEOM::propertyName( GEOM::Color ), c );
196     Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject( aChildObject->GetStudyEntry(), "GEOM", "" );
197     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
198   }
199   displayer.UpdateViewer();
200
201   // update actions
202   appStudy->Modified();
203   app->updateActions(); //SRN: To update a Save button in the toolbar
204 }
205
206 void GEOMToolsGUI::OnDisableAutoColor()
207 {
208   SALOME_ListIO selected;
209   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
210   if( !app )
211     return;
212
213   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
214   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
215   if( !aSelMgr || !appStudy )
216     return;
217
218   aSelMgr->selectedObjects( selected );
219   if( selected.IsEmpty() )
220     return;
221
222   Handle(SALOME_InteractiveObject) anIObject = selected.First();
223
224   _PTR(Study) aStudy = appStudy->studyDS();
225   _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
226   GEOM::GEOM_Object_var aMainObject =  GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
227   if( CORBA::is_nil( aMainObject ) )
228     return;
229
230   aMainObject->SetAutoColor( false );
231 }
232
233 void GEOMToolsGUI::OnColor()
234 {
235   // get active application
236   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
237   if ( !app ) return;
238
239   // get current study
240   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
241   if ( !appStudy ) return;
242
243   // get selection manager
244   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
245   if ( !aSelMgr ) return;
246
247   // get selection
248   SALOME_ListIO selected;
249   aSelMgr->selectedObjects( selected );
250   if ( selected.IsEmpty() ) return;
251
252   GEOM_Displayer displayer( appStudy );
253
254   // get active view
255   SALOME_View* window = displayer.GetActiveView();
256   if ( !window ) return;
257
258   // get view id
259   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
260
261   QColor color;
262   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
263
264   // show Choose Color dialog box
265   color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
266   if ( !color.isValid() ) return;
267
268   // iterate through list of objects and assign new color
269   SUIT_OverrideCursor();
270   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
271     Handle( SALOME_InteractiveObject ) io = It.Value();
272     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Color ), color );
273     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
274   }
275   displayer.UpdateViewer();
276   GeometryGUI::Modified();
277
278   // update actions
279   app->updateActions(); //SRN: To update a Save button in the toolbar
280 }
281
282 void GEOMToolsGUI::OnTexture()
283 {
284   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
285   if ( !app ) return;
286
287   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
288   if ( !appStudy ) return;
289
290   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
291   if ( !aSelMgr ) return;
292
293   SALOME_ListIO selected;  
294   aSelMgr->selectedObjects( selected );
295   if ( selected.IsEmpty() ) return;
296
297   GEOM_Displayer displayer( appStudy );
298   SALOME_View* window = displayer.GetActiveView();
299   if ( !window ) return;
300
301   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
302
303   QString aTexture = QFileDialog::getOpenFileName( dynamic_cast< SUIT_ViewWindow* >( window ),tr("GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
304   if( !aTexture.isEmpty() ) {
305     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
306       Handle( SALOME_InteractiveObject ) io = It.Value();
307       appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Texture ), aTexture );
308       appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), 3 );
309       if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
310     }
311   }
312   displayer.UpdateViewer();
313   GeometryGUI::Modified();
314
315   // update actions
316   app->updateActions(); //SRN: To update a Save button in the toolbar
317 }
318
319 void GEOMToolsGUI::OnTransparency()
320 {
321   GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
322   dlg.exec();
323 }
324
325 void GEOMToolsGUI::OnChangeTransparency( bool increase )
326 {
327   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
328   if ( !app ) return;
329
330   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
331   if( !appStudy) return;
332
333   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
334   if ( !aSelMgr ) return;
335
336   SALOME_ListIO selected;
337   aSelMgr->selectedObjects( selected );
338   if ( selected.IsEmpty() ) return;
339
340   GEOM_Displayer displayer( appStudy );
341   SALOME_View* window = displayer.GetActiveView();
342   if ( !window ) return;
343
344   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
345
346   // Delta
347   float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
348   if ( !increase )
349     delta *= -1;
350
351   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Transparency ), QVariant() );
352   float transp  = v.isValid() ? v.toFloat() : 1;
353
354   // Compute new transparency value
355   transp = transp + delta;
356   if ( transp < 0 )
357     transp = 0;
358   else if ( transp > 1 )
359     transp = 1;
360
361   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
362     Handle( SALOME_InteractiveObject ) io = It.Value();
363     appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::Transparency ), transp );
364     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
365   }
366   displayer.UpdateViewer();
367   GeometryGUI::Modified();
368 }
369
370 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
371 {
372   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
373   if ( !app ) return;
374
375   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
376   if ( !appStudy ) return;
377
378   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
379   if ( !aSelMgr ) return;
380
381   SALOME_ListIO selected;
382   aSelMgr->selectedObjects( selected );
383   if ( selected.IsEmpty() ) return;
384
385   GEOM_Displayer displayer( appStudy );
386   SALOME_View* window = displayer.GetActiveView();
387   if ( !window ) return;
388  
389   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
390
391   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::NbIsos ) , QVariant() );
392   QString aStr = v.toString();
393   QStringList aStrList = aStr.split( GEOM::subSectionSeparator() );
394   int UIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_u", 1 );
395   int VIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_v", 1 );
396   if ( aStrList.count() == 2 ) {
397     if ( !aStrList[0].isEmpty() ) UIso = aStrList[0].toInt();
398     if ( !aStrList[1].isEmpty() ) VIso = aStrList[1].toInt();
399   }
400
401   int newNbUIso = -1;
402   int newNbVIso = -1;
403
404   if ( actionType == SHOWDLG ) {
405     GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
406       new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
407
408     NbIsosDlg->setU( UIso );
409     NbIsosDlg->setV( VIso );
410
411     if ( NbIsosDlg->exec() ) {
412       SUIT_OverrideCursor();     
413       newNbUIso = NbIsosDlg->getU();
414       newNbVIso = NbIsosDlg->getV();
415     } else //Cancel case
416       return;
417   }
418   else if ( actionType == INCR || actionType == DECR ) {
419     int delta = 1;
420     if (actionType == DECR)
421       delta = -1;
422
423     newNbUIso = UIso + delta;
424     newNbVIso = VIso + delta;
425
426     if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
427       return;
428   }
429
430   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
431     Handle( SALOME_InteractiveObject ) io = It.Value();
432     QString anIsos = QString( "%1%2%3" ).arg( newNbUIso ).arg( GEOM::subSectionSeparator() ).arg( newNbVIso );
433     appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos );
434     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
435   }
436   displayer.UpdateViewer();
437   GeometryGUI::Modified();
438 }
439
440 void GEOMToolsGUI::OnDeflection()
441 {
442   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
443   if ( !app ) return;
444
445   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
446   if ( !appStudy ) return;
447
448   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
449   if ( !aSelMgr ) return;
450
451   SALOME_ListIO selected;
452   aSelMgr->selectedObjects( selected );
453   if ( selected.IsEmpty() ) return;
454
455   GEOM_Displayer displayer( appStudy );
456   SALOME_View* window = displayer.GetActiveView();
457   if ( !window ) return;
458
459   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
460
461   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
462   double aDC =  v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
463
464   GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
465     ( SUIT_Session::session()->activeApplication()->desktop() );
466   DeflectionDlg->setTheDC( aDC );
467   if ( DeflectionDlg->exec() ) {
468     SUIT_OverrideCursor();
469     aDC = DeflectionDlg->getTheDC();
470
471     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
472       Handle( SALOME_InteractiveObject ) io = It.Value();
473       appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC );
474       if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
475     }
476   }
477   displayer.UpdateViewer();
478   GeometryGUI::Modified();
479 }
480
481 void GEOMToolsGUI::OnSelectOnly(int mode)
482 {
483   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
484   if ( app ) {
485     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
486     GEOM_Displayer aDisp (appStudy);
487     aDisp.GlobalSelection(mode);
488     getGeometryGUI()->setLocalSelectionMode(mode);
489   }
490 }
491
492 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
493 {
494   SALOME_ListIO selected;
495   SalomeApp_Application* app =
496     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
497   
498   SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
499   
500   GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
501
502   if ( app && disp ) {
503     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
504     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
505     if ( aSelMgr && appStudy ) {
506       aSelMgr->selectedObjects( selected );
507       if ( !selected.IsEmpty() ) {
508         _PTR(Study) aStudy = appStudy->studyDS();
509         _PTR(StudyBuilder) B = aStudy->NewBuilder();
510
511         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
512         if ( aLocked ) {
513           SUIT_MessageBox::warning( app->desktop(),
514                                     QObject::tr( "WRN_WARNING" ),
515                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
516           return;
517         }
518
519         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
520           Handle(SALOME_InteractiveObject) IObject = It.Value();
521
522           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
523           _PTR(GenericAttribute) anAttr;
524           if ( obj ) {
525             _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
526             aExp->SetExpandable( show );
527             if(!show)
528               disp->EraseWithChildren(IObject,true);
529           } // if ( obj )
530         } // iterator
531       }
532     }
533     app->updateObjectBrowser( false );
534     app->updateActions();
535   }
536 }
537
538 void GEOMToolsGUI::OnPointMarker()
539 {
540   GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
541   dlg.exec();
542 }
543
544 void GEOMToolsGUI::OnMaterialProperties()
545 {
546  GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
547  dlg->show();
548 }
549
550 void GEOMToolsGUI::OnMaterialsLibrary()
551 {
552         GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
553         dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
554   dlg.exec();
555 }
556
557 void GEOMToolsGUI::OnUnpublishObject() {
558   SALOME_ListIO selected;
559   SalomeApp_Application* app =
560     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
561
562   SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
563
564   GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
565   
566   if ( app && disp ) {
567     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
568     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
569     if ( aSelMgr && appStudy ) {
570       aSelMgr->selectedObjects( selected );
571       if ( !selected.IsEmpty() ) {
572         _PTR(Study) aStudy = appStudy->studyDS();
573         _PTR(StudyBuilder) B = aStudy->NewBuilder();
574
575         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
576         if ( aLocked ) {
577           SUIT_MessageBox::warning( app->desktop(),
578                                     QObject::tr( "WRN_WARNING" ),
579                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
580           return;
581         }
582
583         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
584           Handle(SALOME_InteractiveObject) IObject = It.Value();
585
586           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
587           _PTR(GenericAttribute) anAttr;
588           if ( obj ) {
589             _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
590             aDrw->SetDrawable( false );
591             disp->EraseWithChildren(IObject);
592           } // if ( obj )
593         } // iterator
594         aSelMgr->clearSelected();
595       }
596     }
597     app->updateObjectBrowser( false );
598     app->updateActions();
599   }
600  
601 }
602
603 void GEOMToolsGUI::OnPublishObject() {
604   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
605   if(!app)
606     return;
607
608   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
609   if(!appStudy)
610     return;
611   
612   _PTR(Study) aStudy = appStudy->studyDS();
613   
614   if(!aStudy)
615     return;
616
617   //Check lock of the study
618   bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
619   if ( aLocked ) {
620     SUIT_MessageBox::warning( app->desktop(),
621                               QObject::tr( "WRN_WARNING" ),
622                               QObject::tr( "WRN_STUDY_LOCKED" ) );
623     return;
624   } 
625   
626   GEOMToolsGUI_PublishDlg* publishDlg =
627     new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
628   publishDlg->show();
629 }
630
631
632 void GEOMToolsGUI::OnEdgeWidth()
633 {
634   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
635   if ( !app ) return;
636
637   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
638   if ( !appStudy ) return;
639
640   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
641   if ( !aSelMgr ) return;
642
643   SALOME_ListIO selected;
644   aSelMgr->selectedObjects( selected );
645   if ( selected.IsEmpty() ) return;
646
647   GEOM_Displayer displayer( appStudy );
648
649   SALOME_View* window = displayer.GetActiveView();
650   if ( !window ) return;
651
652   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
653
654   GEOMToolsGUI_LineWidthDlg* Dlg =
655     new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
656
657   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
658   int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
659
660   Dlg->setTheLW( aWidth );
661   if ( Dlg->exec() ) {
662     SUIT_OverrideCursor();
663     aWidth = Dlg->getTheLW();
664   } else
665     return; //Cancel case
666   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
667     Handle( SALOME_InteractiveObject ) io = It.Value();
668     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
669     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
670     }
671   displayer.UpdateViewer();
672   GeometryGUI::Modified();
673 }
674
675
676 void GEOMToolsGUI::OnIsosWidth() {
677   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
678   if ( !app ) return;
679
680   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
681   if ( !appStudy ) return;
682
683   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
684   if ( !aSelMgr ) return;
685
686   SALOME_ListIO selected;
687   aSelMgr->selectedObjects( selected );
688   if ( selected.IsEmpty() ) return;
689
690   GEOM_Displayer displayer( appStudy );
691
692   SALOME_View* window = displayer.GetActiveView();
693   if ( !window ) return;
694
695   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
696
697   GEOMToolsGUI_LineWidthDlg* Dlg =
698     new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
699
700   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
701   int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
702
703   Dlg->setTheLW( aWidth );
704   if ( Dlg->exec() ) {
705     SUIT_OverrideCursor();
706     aWidth = Dlg->getTheLW();
707   } else
708     return; //Cancel case
709   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
710     Handle( SALOME_InteractiveObject ) io = It.Value();
711     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
712     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
713   }
714   displayer.UpdateViewer();
715   GeometryGUI::Modified();
716 }
717
718 void GEOMToolsGUI::OnBringToFront() {
719   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
720   if ( !app ) return;
721
722   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());  
723   if (!appStudy) return;
724
725   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
726   if ( !aSelMgr ) return;
727
728   SALOME_ListIO selected;
729   aSelMgr->selectedObjects( selected );
730   if ( selected.IsEmpty() ) return;
731
732   GEOM_Displayer displayer( appStudy );
733
734   SALOME_View* window = displayer.GetActiveView();
735   if ( !window ) return;
736
737   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
738
739   QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
740   bool checked = a->isChecked();
741
742   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
743     Handle( SALOME_InteractiveObject ) io = It.Value();
744     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
745     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
746   }
747   displayer.UpdateViewer();
748   GeometryGUI::Modified();
749 }
750
751 void GEOMToolsGUI::OnClsBringToFront() {
752   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
753   if ( !app ) return;
754
755   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
756   if ( !appStudy ) return;
757
758   GEOM_Displayer displayer( appStudy );
759
760   SALOME_View* window = displayer.GetActiveView();
761   if ( !window ) return;
762
763   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
764
765   SALOME_ListIO anIOlst;
766   window->GetVisible( anIOlst );
767
768   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
769     Handle( SALOME_InteractiveObject ) io = It.Value();
770     appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
771     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
772   }
773   displayer.Redisplay( anIOlst );
774   displayer.UpdateViewer();
775   GeometryGUI::Modified();
776 }
777   
778 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
779 {
780   if ( !theParam.canConvert<QString>() ) return;
781   
782   QString theName = theParam.toString();
783
784   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
785   if ( !app ) return;
786   
787   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
788   if ( !study ) return;
789   
790   LightApp_SelectionMgr* selMgr = app->selectionMgr();
791
792   SALOME_ListIO selected;
793   selMgr->selectedObjects( selected );
794
795   if ( selected.IsEmpty() ) return;
796   
797   GEOM_Displayer displayer( study );
798
799   SALOME_View* window = displayer.GetActiveView();
800   if ( !window ) return;
801   
802   int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
803
804   Material_Model aModel;
805   aModel.fromResources( theName );
806   QString prop = aModel.toProperties();
807
808   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
809     Handle(SALOME_InteractiveObject) io = It.Value();
810     study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
811     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
812   }
813   displayer.UpdateViewer();
814 }
815
816 void GEOMToolsGUI::OnCreateFolder()
817 {
818   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
819   if ( !app ) return;
820
821   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
822   if ( !appStudy ) return;
823
824   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
825   if ( !aSelMgr ) return;
826
827   SALOME_ListIO selected;
828   aSelMgr->selectedObjects( selected );
829   if ( selected.IsEmpty() ) return;
830
831   Handle(SALOME_InteractiveObject) anIObject = selected.First();
832
833   _PTR(Study) aStudy = appStudy->studyDS();
834   if( !aStudy ) return;
835   _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
836   if ( !aFatherSO ) return;
837
838   GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(), 
839                                            _CAST(SObject, aFatherSO)->GetSObject() );
840   app->updateObjectBrowser( false );
841 }
842
843 void GEOMToolsGUI::OnSortChildren()
844 {
845   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
846   if ( !app ) return;
847
848   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
849   if ( !appStudy ) return;
850
851   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
852   if ( !aSelMgr ) return;
853
854   SALOME_ListIO selected;
855   aSelMgr->selectedObjects( selected );
856   if ( selected.IsEmpty() ) return;
857
858   Handle(SALOME_InteractiveObject) anIObject = selected.First();
859
860   _PTR(Study) aStudy = appStudy->studyDS();
861   if( !aStudy ) return;
862   _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
863   if ( !aFatherSO ) return;
864
865   aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
866
867   app->updateObjectBrowser( true );
868 }
869
870 void GEOMToolsGUI::OnShowDependencyTree()
871 {
872   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
873
874   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
875   if ( !app ) return;
876
877   SUIT_ViewManager *svm = app->getViewManager( GraphicsView_Viewer::Type(), false );
878
879   if( !svm ) {
880     DependencyTree_View* view = new DependencyTree_View();
881     DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
882     SUIT_ViewManager *svm = app->createViewManager( viewModel );
883
884     LightApp_SelectionMgr* selMgr = app->selectionMgr();
885     new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
886
887     SUIT_ViewWindow* svw = svm->getActiveView();
888     GraphicsView_ViewFrame* aViewFrame = 0;
889     if (!svw) svw = svm->createViewWindow();
890     if (svw) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>(svw);
891
892     view->init( aViewFrame );
893     svm->setTitle( view->getViewName() );
894   }
895   else
896     if( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( svm->getViewModel() ) )
897       if( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
898         svm->getActiveView()->setFocus();
899         view->updateModel();
900       }
901 }