Salome HOME
611be366371e18eef47d82d8f834bd32ce227a91
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_1.cxx
1 // Copyright (C) 2007-2023  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) || !GeometryGUI::IsInGeomComponent( aMainSObject )) return;
164
165   aMainObject->SetAutoColor( true );
166
167   QList<SALOMEDS::Color> aReservedColors;
168
169   GEOM_Displayer displayer;
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 ) || !GeometryGUI::IsInGeomComponent( aMainSObject ))
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;
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;
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;
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;
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;
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_coeff", 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     GEOM_Displayer aDisp;
498     aDisp.GlobalSelection(mode);
499     getGeometryGUI()->setLocalSelectionMode(mode);
500   }
501 }
502
503 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
504 {
505   SALOME_ListIO selected;
506   SalomeApp_Application* app =
507     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
508   
509   SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
510   
511   GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
512
513   if ( app && disp ) {
514     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
515     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
516     if ( aSelMgr && appStudy ) {
517       aSelMgr->selectedObjects( selected );
518       if ( !selected.IsEmpty() ) {
519         _PTR(Study) aStudy = appStudy->studyDS();
520         _PTR(StudyBuilder) B = aStudy->NewBuilder();
521
522         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
523         if ( aLocked ) {
524           SUIT_MessageBox::warning( app->desktop(),
525                                     QObject::tr( "WRN_WARNING" ),
526                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
527           return;
528         }
529
530         SUIT_OverrideCursor wc;
531         bool toUpdateColorScale = disp->SetUpdateColorScale( false ); // IPAL54049
532         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
533           Handle(SALOME_InteractiveObject) IObject = It.Value();
534
535           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
536           _PTR(GenericAttribute) anAttr;
537           if ( obj ) {
538             _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
539             aExp->SetExpandable( show );
540             if ( !show ) {
541               disp->EraseWithChildren(IObject,true);
542             }
543           } // if ( obj )
544         } // iterator
545         disp->SetUpdateColorScale( toUpdateColorScale );
546       }
547     }
548     app->updateObjectBrowser( false );
549     app->updateActions();
550   }
551 }
552
553 void GEOMToolsGUI::OnPointMarker()
554 {
555   GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
556   dlg.exec();
557 }
558
559 void GEOMToolsGUI::OnMaterialProperties()
560 {
561  GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
562  dlg->show();
563 }
564
565 void GEOMToolsGUI::OnMaterialsLibrary()
566 {
567         GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
568         dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
569   dlg.exec();
570 }
571
572 void GEOMToolsGUI::OnUnpublishObject() {
573   SALOME_ListIO selected;
574   SalomeApp_Application* app =
575     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
576
577   SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
578
579   GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
580   
581   if ( app && disp ) {
582     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
583     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
584     if ( aSelMgr && appStudy ) {
585       aSelMgr->selectedObjects( selected );
586       if ( !selected.IsEmpty() ) {
587         _PTR(Study) aStudy = appStudy->studyDS();
588         _PTR(StudyBuilder) B = aStudy->NewBuilder();
589
590         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
591         if ( aLocked ) {
592           SUIT_MessageBox::warning( app->desktop(),
593                                     QObject::tr( "WRN_WARNING" ),
594                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
595           return;
596         }
597         SUIT_OverrideCursor wc;
598         bool toUpdateColorScale = disp->SetUpdateColorScale( false ); // IPAL54049
599         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
600           Handle(SALOME_InteractiveObject) IObject = It.Value();
601
602           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
603           _PTR(GenericAttribute) anAttr;
604           if ( obj ) {
605             _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
606             aDrw->SetDrawable( false );
607             disp->EraseWithChildren(IObject);
608             // hide references if any
609             std::vector< _PTR(SObject) > vso = aStudy->FindDependances(obj);
610             for ( int i = 0; i < (int)vso.size(); i++ ) {
611               _PTR(SObject) refObj = vso[i];
612               aDrw = B->FindOrCreateAttribute( refObj, "AttributeDrawable" );
613               aDrw->SetDrawable( false );
614             }
615           } // if ( obj )
616         } // iterator
617         disp->SetUpdateColorScale( toUpdateColorScale ); // IPAL54049
618         aSelMgr->clearSelected();
619       }
620     }
621     app->updateObjectBrowser( false );
622     app->updateActions();
623   }
624 }
625
626 void GEOMToolsGUI::OnPublishObject() {
627   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
628   if(!app)
629     return;
630
631   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
632   if(!appStudy)
633     return;
634   
635   _PTR(Study) aStudy = appStudy->studyDS();
636   
637   if(!aStudy)
638     return;
639
640   //Check lock of the study
641   bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
642   if ( aLocked ) {
643     SUIT_MessageBox::warning( app->desktop(),
644                               QObject::tr( "WRN_WARNING" ),
645                               QObject::tr( "WRN_STUDY_LOCKED" ) );
646     return;
647   } 
648   
649   GEOMToolsGUI_PublishDlg* publishDlg =
650     new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
651   publishDlg->show();
652 }
653
654
655 void GEOMToolsGUI::OnEdgeWidth()
656 {
657   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
658   if ( !app ) return;
659
660   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
661   if ( !appStudy ) return;
662
663   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
664   if ( !aSelMgr ) return;
665
666   SALOME_ListIO selected;
667   aSelMgr->selectedObjects( selected );
668   if ( selected.IsEmpty() ) return;
669
670   GEOM_Displayer displayer;
671
672   SALOME_View* window = displayer.GetActiveView();
673   if ( !window ) return;
674
675   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
676
677   GEOMToolsGUI_LineWidthDlg* Dlg =
678     new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
679
680   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
681   int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
682
683   Dlg->setTheLW( aWidth );
684   if ( Dlg->exec() ) {
685     SUIT_OverrideCursor wc;
686     aWidth = Dlg->getTheLW();
687   } else
688     return; //Cancel case
689   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
690     Handle( SALOME_InteractiveObject ) io = It.Value();
691     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
692     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
693     }
694   displayer.UpdateViewer();
695   GeometryGUI::Modified();
696 }
697
698
699 void GEOMToolsGUI::OnIsosWidth() {
700   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
701   if ( !app ) return;
702
703   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
704   if ( !appStudy ) return;
705
706   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
707   if ( !aSelMgr ) return;
708
709   SALOME_ListIO selected;
710   aSelMgr->selectedObjects( selected );
711   if ( selected.IsEmpty() ) return;
712
713   GEOM_Displayer displayer;
714
715   SALOME_View* window = displayer.GetActiveView();
716   if ( !window ) return;
717
718   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
719
720   GEOMToolsGUI_LineWidthDlg* Dlg =
721     new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
722
723   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
724   int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
725
726   Dlg->setTheLW( aWidth );
727   if ( Dlg->exec() ) {
728     SUIT_OverrideCursor wc;
729     aWidth = Dlg->getTheLW();
730   } else
731     return; //Cancel case
732   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
733     Handle( SALOME_InteractiveObject ) io = It.Value();
734     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
735     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
736   }
737   displayer.UpdateViewer();
738   GeometryGUI::Modified();
739 }
740
741 void GEOMToolsGUI::OnBringToFront() {
742   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
743   if ( !app ) return;
744
745   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());  
746   if (!appStudy) return;
747
748   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
749   if ( !aSelMgr ) return;
750
751   SALOME_ListIO selected;
752   aSelMgr->selectedObjects( selected );
753   if ( selected.IsEmpty() ) return;
754
755   GEOM_Displayer displayer;
756
757   SALOME_View* window = displayer.GetActiveView();
758   if ( !window ) return;
759
760   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
761
762   QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
763   bool checked = a->isChecked();
764
765   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
766     Handle( SALOME_InteractiveObject ) io = It.Value();
767     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
768     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
769   }
770   displayer.UpdateViewer();
771   GeometryGUI::Modified();
772 }
773
774 void GEOMToolsGUI::OnClsBringToFront() {
775   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
776   if ( !app ) return;
777
778   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
779   if ( !appStudy ) return;
780
781   GEOM_Displayer displayer;
782
783   SALOME_View* window = displayer.GetActiveView();
784   if ( !window ) return;
785
786   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
787
788   SALOME_ListIO anIOlst;
789   window->GetVisible( anIOlst );
790
791   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
792     Handle( SALOME_InteractiveObject ) io = It.Value();
793     appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
794     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
795   }
796   displayer.Redisplay( anIOlst );
797   displayer.UpdateViewer();
798   GeometryGUI::Modified();
799 }
800   
801 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
802 {
803   if ( !theParam.canConvert<QString>() ) return;
804   
805   QString theName = theParam.toString();
806
807   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
808   if ( !app ) return;
809   
810   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
811   if ( !study ) return;
812   
813   LightApp_SelectionMgr* selMgr = app->selectionMgr();
814
815   SALOME_ListIO selected;
816   selMgr->selectedObjects( selected );
817
818   if ( selected.IsEmpty() ) return;
819   
820   GEOM_Displayer displayer;
821
822   SALOME_View* window = displayer.GetActiveView();
823   if ( !window ) return;
824   
825   int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
826
827   Material_Model aModel;
828   aModel.fromResources( theName );
829   QString prop = aModel.toProperties();
830
831   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
832     Handle(SALOME_InteractiveObject) io = It.Value();
833     study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
834     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
835   }
836   displayer.UpdateViewer();
837 }
838
839 void GEOMToolsGUI::OnCreateFolder()
840 {
841   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
842   if ( !app ) return;
843
844   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
845   if ( !appStudy ) return;
846
847   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
848   if ( !aSelMgr ) return;
849
850   SALOME_ListIO selected;
851   aSelMgr->selectedObjects( selected );
852   if ( selected.IsEmpty() ) return;
853
854   Handle(SALOME_InteractiveObject) anIObject = selected.First();
855
856   _PTR(Study) aStudy = appStudy->studyDS();
857   if( !aStudy ) return;
858   _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
859   if ( !aFatherSO ) return;
860
861   GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toUtf8().constData(), 
862                                            _CAST(SObject, aFatherSO)->GetSObject() );
863   app->updateObjectBrowser( false );
864 }
865
866 void GEOMToolsGUI::OnSortChildren()
867 {
868   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
869   if ( !app ) return;
870
871   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
872   if ( !appStudy ) return;
873
874   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
875   if ( !aSelMgr ) return;
876
877   SALOME_ListIO selected;
878   aSelMgr->selectedObjects( selected );
879   if ( selected.IsEmpty() ) return;
880
881   Handle(SALOME_InteractiveObject) anIObject = selected.First();
882
883   _PTR(Study) aStudy = appStudy->studyDS();
884   if( !aStudy ) return;
885   _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
886   if ( !aFatherSO ) return;
887
888   aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
889
890   app->updateObjectBrowser( true );
891 }
892
893 #ifndef DISABLE_GRAPHICSVIEW
894 void GEOMToolsGUI::OnShowDependencyTree()
895 {
896   //SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
897
898   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
899   if ( !app ) return;
900
901 #ifdef LAYOUT_DEPVIEW
902   SUIT_ViewManager* occVm = app->getViewManager( OCCViewer_Viewer::Type(), true );
903   SUIT_ViewWindow* occVw = occVm->getActiveView();
904 #endif
905   SUIT_ViewManager* depVm = app->getViewManager( GraphicsView_Viewer::Type(), false );
906   SUIT_ViewWindow* depVw = 0;
907
908   if ( !depVm ) {
909     DependencyTree_View* view = new DependencyTree_View();
910     DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
911     depVm = app->createViewManager( viewModel );
912
913     LightApp_SelectionMgr* selMgr = app->selectionMgr();
914     new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
915
916     depVw = depVm->getActiveView();
917     GraphicsView_ViewFrame* aViewFrame = 0;
918     if ( !depVw ) depVw = depVm->createViewWindow();
919     if ( depVw ) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( depVw );
920
921     view->init( aViewFrame );
922     depVm->setTitle( view->getViewName() );
923   }
924   else if ( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( depVm->getViewModel() ) ) {
925     if ( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
926       depVw = depVm->getActiveView();
927       view->updateModel();
928     }
929   }
930
931 #ifdef LAYOUT_DEPVIEW
932   // layout views properly
933   STD_TabDesktop* d = dynamic_cast<STD_TabDesktop*>( app->desktop() );
934   if ( d && depVw && occVw ) {
935     QtxWorkstack* ws = d->workstack();
936     ws->stack();
937     QApplication::instance()->processEvents();
938     ws->Split( depVw, Qt::Horizontal, QtxWorkstack::SplitMove );
939     occVw->setFocus();
940   }
941 #endif
942   depVw->setFocus();
943 }
944 #endif
945
946 void GEOMToolsGUI::OnReduceStudy()
947 {
948   QDialog* dlg = new GEOMToolsGUI_ReduceStudyDlg( SUIT_Session::session()->activeApplication()->desktop() );
949   if( dlg != NULL )
950     dlg->show();
951 }