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