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