Salome HOME
Merge remote branch 'origin/V7_4_BR'
[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             // hide references if any
594             std::vector< _PTR(SObject) > vso = aStudy->FindDependances(obj);
595             for ( int i = 0; i < vso.size(); i++ ) {
596               _PTR(SObject) refObj = vso[i];
597               aDrw = B->FindOrCreateAttribute( refObj, "AttributeDrawable" );
598               aDrw->SetDrawable( false );
599             }
600           } // if ( obj )
601         } // iterator
602         aSelMgr->clearSelected();
603       }
604     }
605     app->updateObjectBrowser( false );
606     app->updateActions();
607   }
608  
609 }
610
611 void GEOMToolsGUI::OnPublishObject() {
612   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
613   if(!app)
614     return;
615
616   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
617   if(!appStudy)
618     return;
619   
620   _PTR(Study) aStudy = appStudy->studyDS();
621   
622   if(!aStudy)
623     return;
624
625   //Check lock of the study
626   bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
627   if ( aLocked ) {
628     SUIT_MessageBox::warning( app->desktop(),
629                               QObject::tr( "WRN_WARNING" ),
630                               QObject::tr( "WRN_STUDY_LOCKED" ) );
631     return;
632   } 
633   
634   GEOMToolsGUI_PublishDlg* publishDlg =
635     new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
636   publishDlg->show();
637 }
638
639
640 void GEOMToolsGUI::OnEdgeWidth()
641 {
642   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
643   if ( !app ) return;
644
645   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
646   if ( !appStudy ) return;
647
648   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
649   if ( !aSelMgr ) return;
650
651   SALOME_ListIO selected;
652   aSelMgr->selectedObjects( selected );
653   if ( selected.IsEmpty() ) return;
654
655   GEOM_Displayer displayer( appStudy );
656
657   SALOME_View* window = displayer.GetActiveView();
658   if ( !window ) return;
659
660   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
661
662   GEOMToolsGUI_LineWidthDlg* Dlg =
663     new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
664
665   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
666   int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
667
668   Dlg->setTheLW( aWidth );
669   if ( Dlg->exec() ) {
670     SUIT_OverrideCursor();
671     aWidth = Dlg->getTheLW();
672   } else
673     return; //Cancel case
674   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
675     Handle( SALOME_InteractiveObject ) io = It.Value();
676     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
677     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
678     }
679   displayer.UpdateViewer();
680   GeometryGUI::Modified();
681 }
682
683
684 void GEOMToolsGUI::OnIsosWidth() {
685   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
686   if ( !app ) return;
687
688   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
689   if ( !appStudy ) return;
690
691   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
692   if ( !aSelMgr ) return;
693
694   SALOME_ListIO selected;
695   aSelMgr->selectedObjects( selected );
696   if ( selected.IsEmpty() ) return;
697
698   GEOM_Displayer displayer( appStudy );
699
700   SALOME_View* window = displayer.GetActiveView();
701   if ( !window ) return;
702
703   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
704
705   GEOMToolsGUI_LineWidthDlg* Dlg =
706     new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
707
708   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
709   int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
710
711   Dlg->setTheLW( aWidth );
712   if ( Dlg->exec() ) {
713     SUIT_OverrideCursor();
714     aWidth = Dlg->getTheLW();
715   } else
716     return; //Cancel case
717   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
718     Handle( SALOME_InteractiveObject ) io = It.Value();
719     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
720     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
721   }
722   displayer.UpdateViewer();
723   GeometryGUI::Modified();
724 }
725
726 void GEOMToolsGUI::OnBringToFront() {
727   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
728   if ( !app ) return;
729
730   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());  
731   if (!appStudy) return;
732
733   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
734   if ( !aSelMgr ) return;
735
736   SALOME_ListIO selected;
737   aSelMgr->selectedObjects( selected );
738   if ( selected.IsEmpty() ) return;
739
740   GEOM_Displayer displayer( appStudy );
741
742   SALOME_View* window = displayer.GetActiveView();
743   if ( !window ) return;
744
745   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
746
747   QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
748   bool checked = a->isChecked();
749
750   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
751     Handle( SALOME_InteractiveObject ) io = It.Value();
752     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
753     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
754   }
755   displayer.UpdateViewer();
756   GeometryGUI::Modified();
757 }
758
759 void GEOMToolsGUI::OnClsBringToFront() {
760   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
761   if ( !app ) return;
762
763   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
764   if ( !appStudy ) return;
765
766   GEOM_Displayer displayer( appStudy );
767
768   SALOME_View* window = displayer.GetActiveView();
769   if ( !window ) return;
770
771   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
772
773   SALOME_ListIO anIOlst;
774   window->GetVisible( anIOlst );
775
776   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
777     Handle( SALOME_InteractiveObject ) io = It.Value();
778     appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
779     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
780   }
781   displayer.Redisplay( anIOlst );
782   displayer.UpdateViewer();
783   GeometryGUI::Modified();
784 }
785   
786 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
787 {
788   if ( !theParam.canConvert<QString>() ) return;
789   
790   QString theName = theParam.toString();
791
792   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
793   if ( !app ) return;
794   
795   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
796   if ( !study ) return;
797   
798   LightApp_SelectionMgr* selMgr = app->selectionMgr();
799
800   SALOME_ListIO selected;
801   selMgr->selectedObjects( selected );
802
803   if ( selected.IsEmpty() ) return;
804   
805   GEOM_Displayer displayer( study );
806
807   SALOME_View* window = displayer.GetActiveView();
808   if ( !window ) return;
809   
810   int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
811
812   Material_Model aModel;
813   aModel.fromResources( theName );
814   QString prop = aModel.toProperties();
815
816   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
817     Handle(SALOME_InteractiveObject) io = It.Value();
818     study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
819     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
820   }
821   displayer.UpdateViewer();
822 }
823
824 void GEOMToolsGUI::OnCreateFolder()
825 {
826   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
827   if ( !app ) return;
828
829   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
830   if ( !appStudy ) return;
831
832   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
833   if ( !aSelMgr ) return;
834
835   SALOME_ListIO selected;
836   aSelMgr->selectedObjects( selected );
837   if ( selected.IsEmpty() ) return;
838
839   Handle(SALOME_InteractiveObject) anIObject = selected.First();
840
841   _PTR(Study) aStudy = appStudy->studyDS();
842   if( !aStudy ) return;
843   _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
844   if ( !aFatherSO ) return;
845
846   GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(), 
847                                            _CAST(SObject, aFatherSO)->GetSObject() );
848   app->updateObjectBrowser( false );
849 }
850
851 void GEOMToolsGUI::OnSortChildren()
852 {
853   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
854   if ( !app ) return;
855
856   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
857   if ( !appStudy ) return;
858
859   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
860   if ( !aSelMgr ) return;
861
862   SALOME_ListIO selected;
863   aSelMgr->selectedObjects( selected );
864   if ( selected.IsEmpty() ) return;
865
866   Handle(SALOME_InteractiveObject) anIObject = selected.First();
867
868   _PTR(Study) aStudy = appStudy->studyDS();
869   if( !aStudy ) return;
870   _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
871   if ( !aFatherSO ) return;
872
873   aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
874
875   app->updateObjectBrowser( true );
876 }
877
878 void GEOMToolsGUI::OnShowDependencyTree()
879 {
880   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
881
882   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
883   if ( !app ) return;
884
885   SUIT_ViewManager *svm = app->getViewManager( GraphicsView_Viewer::Type(), false );
886
887   if( !svm ) {
888     DependencyTree_View* view = new DependencyTree_View();
889     DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
890     SUIT_ViewManager *svm = app->createViewManager( viewModel );
891
892     LightApp_SelectionMgr* selMgr = app->selectionMgr();
893     new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
894
895     SUIT_ViewWindow* svw = svm->getActiveView();
896     GraphicsView_ViewFrame* aViewFrame = 0;
897     if (!svw) svw = svm->createViewWindow();
898     if (svw) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>(svw);
899
900     view->init( aViewFrame );
901     svm->setTitle( view->getViewName() );
902   }
903   else
904     if( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( svm->getViewModel() ) )
905       if( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
906         svm->getActiveView()->setFocus();
907         view->updateModel();
908       }
909 }
910
911 void GEOMToolsGUI::OnReduceStudy()
912 {
913   QDialog* dlg = new GEOMToolsGUI_ReduceStudyDlg( SUIT_Session::session()->activeApplication()->desktop() );
914   if( dlg != NULL )
915     dlg->show();
916 }