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