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