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