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