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