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