Salome HOME
Remove obsolete OCC_VERSION_LARGE defines.
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_1.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  GEOM GEOMGUI : GUI for Geometry component
24 //  File   : GEOMToolsGUI_1.cxx
25 //  Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26
27 #include <PyConsole_Console.h>
28
29 #include "GEOMToolsGUI.h"
30 #include "GEOMToolsGUI_TransparencyDlg.h"
31 #include "GEOMToolsGUI_NbIsosDlg.h"
32 #include "GEOMToolsGUI_DeflectionDlg.h"
33 #include "GEOMToolsGUI_MarkerDlg.h"
34 #include "GEOMToolsGUI_PublishDlg.h"
35 #include "GEOMToolsGUI_MaterialPropertiesDlg.h"
36 #include "GEOMToolsGUI_LineWidthDlg.h"
37 #include "GEOMToolsGUI_ReduceStudyDlg.h"
38 #include <Material_Model.h>
39
40 #include <GEOM_VTKPropertyMaterial.hxx>
41
42 #include <GeometryGUI.h>
43 #include <GeometryGUI_Operations.h>
44 #include <GEOM_Constants.h>
45 #include <GEOM_Displayer.h>
46
47 #include <GEOMBase.h>
48 #include <GEOM_Actor.h>
49
50 #include <DependencyTree_ViewModel.h>
51 #include <DependencyTree_View.h>
52 #include <DependencyTree_Selector.h>
53
54 #include <Basics_OCCTVersion.hxx>
55
56 #include <SALOME_ListIO.hxx>
57 #include <SALOME_ListIteratorOfListIO.hxx>
58
59 #include <SALOMEDS_SObject.hxx>
60
61 #include <SOCC_Prs.h>
62
63 #include <SVTK_Prs.h>
64 #include <SVTK_ViewModel.h>
65 #include <SVTK_ViewWindow.h>
66 #include <SVTK_View.h>
67
68 #include <OCCViewer_ViewModel.h>
69
70 #include <SUIT_ViewManager.h>
71 #include <SUIT_Desktop.h>
72 #include <SUIT_ResourceMgr.h>
73 #include <SUIT_Session.h>
74 #include <SUIT_OverrideCursor.h>
75 #include <SUIT_MessageBox.h>
76 #include <SUIT_Tools.h>
77
78 #include <SalomeApp_Application.h>
79 #include <SalomeApp_Study.h>
80 #include <SalomeApp_Module.h>
81
82 #include <LightApp_SelectionMgr.h>
83 #include <LightApp_NameDlg.h>
84
85 #include <GEOMImpl_Types.hxx>
86
87 #include "utilities.h"
88
89 // OCCT Includes
90 #include <AIS_Drawer.hxx>
91 #include <Prs3d_IsoAspect.hxx>
92 #include <Prs3d_PointAspect.hxx>
93 #include <Graphic3d_AspectMarker3d.hxx>
94 #include <Graphic3d_AspectLine3d.hxx>
95 #include <AIS_ListIteratorOfListOfInteractive.hxx>
96 #include <AIS_ListOfInteractive.hxx>
97
98 #include <TColStd_HArray1OfByte.hxx>
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     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
302       Handle( SALOME_InteractiveObject ) io = It.Value();
303       appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Texture ), aTexture );
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             // hide references if any
589             std::vector< _PTR(SObject) > vso = aStudy->FindDependances(obj);
590             for ( int i = 0; i < vso.size(); i++ ) {
591               _PTR(SObject) refObj = vso[i];
592               aDrw = B->FindOrCreateAttribute( refObj, "AttributeDrawable" );
593               aDrw->SetDrawable( false );
594             }
595           } // if ( obj )
596         } // iterator
597         aSelMgr->clearSelected();
598       }
599     }
600     app->updateObjectBrowser( false );
601     app->updateActions();
602   }
603  
604 }
605
606 void GEOMToolsGUI::OnPublishObject() {
607   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
608   if(!app)
609     return;
610
611   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
612   if(!appStudy)
613     return;
614   
615   _PTR(Study) aStudy = appStudy->studyDS();
616   
617   if(!aStudy)
618     return;
619
620   //Check lock of the study
621   bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
622   if ( aLocked ) {
623     SUIT_MessageBox::warning( app->desktop(),
624                               QObject::tr( "WRN_WARNING" ),
625                               QObject::tr( "WRN_STUDY_LOCKED" ) );
626     return;
627   } 
628   
629   GEOMToolsGUI_PublishDlg* publishDlg =
630     new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
631   publishDlg->show();
632 }
633
634
635 void GEOMToolsGUI::OnEdgeWidth()
636 {
637   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
638   if ( !app ) return;
639
640   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
641   if ( !appStudy ) return;
642
643   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
644   if ( !aSelMgr ) return;
645
646   SALOME_ListIO selected;
647   aSelMgr->selectedObjects( selected );
648   if ( selected.IsEmpty() ) return;
649
650   GEOM_Displayer displayer( appStudy );
651
652   SALOME_View* window = displayer.GetActiveView();
653   if ( !window ) return;
654
655   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
656
657   GEOMToolsGUI_LineWidthDlg* Dlg =
658     new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
659
660   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
661   int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
662
663   Dlg->setTheLW( aWidth );
664   if ( Dlg->exec() ) {
665     SUIT_OverrideCursor();
666     aWidth = Dlg->getTheLW();
667   } else
668     return; //Cancel case
669   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
670     Handle( SALOME_InteractiveObject ) io = It.Value();
671     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
672     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
673     }
674   displayer.UpdateViewer();
675   GeometryGUI::Modified();
676 }
677
678
679 void GEOMToolsGUI::OnIsosWidth() {
680   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
681   if ( !app ) return;
682
683   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
684   if ( !appStudy ) return;
685
686   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
687   if ( !aSelMgr ) return;
688
689   SALOME_ListIO selected;
690   aSelMgr->selectedObjects( selected );
691   if ( selected.IsEmpty() ) return;
692
693   GEOM_Displayer displayer( appStudy );
694
695   SALOME_View* window = displayer.GetActiveView();
696   if ( !window ) return;
697
698   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
699
700   GEOMToolsGUI_LineWidthDlg* Dlg =
701     new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
702
703   QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
704   int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
705
706   Dlg->setTheLW( aWidth );
707   if ( Dlg->exec() ) {
708     SUIT_OverrideCursor();
709     aWidth = Dlg->getTheLW();
710   } else
711     return; //Cancel case
712   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
713     Handle( SALOME_InteractiveObject ) io = It.Value();
714     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
715     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
716   }
717   displayer.UpdateViewer();
718   GeometryGUI::Modified();
719 }
720
721 void GEOMToolsGUI::OnBringToFront() {
722   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
723   if ( !app ) return;
724
725   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());  
726   if (!appStudy) return;
727
728   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
729   if ( !aSelMgr ) return;
730
731   SALOME_ListIO selected;
732   aSelMgr->selectedObjects( selected );
733   if ( selected.IsEmpty() ) return;
734
735   GEOM_Displayer displayer( appStudy );
736
737   SALOME_View* window = displayer.GetActiveView();
738   if ( !window ) return;
739
740   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
741
742   QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
743   bool checked = a->isChecked();
744
745   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
746     Handle( SALOME_InteractiveObject ) io = It.Value();
747     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
748     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
749   }
750   displayer.UpdateViewer();
751   GeometryGUI::Modified();
752 }
753
754 void GEOMToolsGUI::OnClsBringToFront() {
755   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
756   if ( !app ) return;
757
758   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
759   if ( !appStudy ) return;
760
761   GEOM_Displayer displayer( appStudy );
762
763   SALOME_View* window = displayer.GetActiveView();
764   if ( !window ) return;
765
766   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
767
768   SALOME_ListIO anIOlst;
769   window->GetVisible( anIOlst );
770
771   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
772     Handle( SALOME_InteractiveObject ) io = It.Value();
773     appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
774     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
775   }
776   displayer.Redisplay( anIOlst );
777   displayer.UpdateViewer();
778   GeometryGUI::Modified();
779 }
780   
781 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
782 {
783   if ( !theParam.canConvert<QString>() ) return;
784   
785   QString theName = theParam.toString();
786
787   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
788   if ( !app ) return;
789   
790   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
791   if ( !study ) return;
792   
793   LightApp_SelectionMgr* selMgr = app->selectionMgr();
794
795   SALOME_ListIO selected;
796   selMgr->selectedObjects( selected );
797
798   if ( selected.IsEmpty() ) return;
799   
800   GEOM_Displayer displayer( study );
801
802   SALOME_View* window = displayer.GetActiveView();
803   if ( !window ) return;
804   
805   int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
806
807   Material_Model aModel;
808   aModel.fromResources( theName );
809   QString prop = aModel.toProperties();
810
811   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
812     Handle(SALOME_InteractiveObject) io = It.Value();
813     study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
814     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
815   }
816   displayer.UpdateViewer();
817 }
818
819 void GEOMToolsGUI::OnCreateFolder()
820 {
821   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
822   if ( !app ) return;
823
824   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
825   if ( !appStudy ) return;
826
827   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
828   if ( !aSelMgr ) return;
829
830   SALOME_ListIO selected;
831   aSelMgr->selectedObjects( selected );
832   if ( selected.IsEmpty() ) return;
833
834   Handle(SALOME_InteractiveObject) anIObject = selected.First();
835
836   _PTR(Study) aStudy = appStudy->studyDS();
837   if( !aStudy ) return;
838   _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
839   if ( !aFatherSO ) return;
840
841   GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(), 
842                                            _CAST(SObject, aFatherSO)->GetSObject() );
843   app->updateObjectBrowser( false );
844 }
845
846 void GEOMToolsGUI::OnSortChildren()
847 {
848   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
849   if ( !app ) return;
850
851   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
852   if ( !appStudy ) return;
853
854   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
855   if ( !aSelMgr ) return;
856
857   SALOME_ListIO selected;
858   aSelMgr->selectedObjects( selected );
859   if ( selected.IsEmpty() ) return;
860
861   Handle(SALOME_InteractiveObject) anIObject = selected.First();
862
863   _PTR(Study) aStudy = appStudy->studyDS();
864   if( !aStudy ) return;
865   _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
866   if ( !aFatherSO ) return;
867
868   aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
869
870   app->updateObjectBrowser( true );
871 }
872
873 void GEOMToolsGUI::OnShowDependencyTree()
874 {
875   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
876
877   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
878   if ( !app ) return;
879
880   SUIT_ViewManager *svm = app->getViewManager( GraphicsView_Viewer::Type(), false );
881
882   if( !svm ) {
883     DependencyTree_View* view = new DependencyTree_View();
884     DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
885     SUIT_ViewManager *svm = app->createViewManager( viewModel );
886
887     LightApp_SelectionMgr* selMgr = app->selectionMgr();
888     new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
889
890     SUIT_ViewWindow* svw = svm->getActiveView();
891     GraphicsView_ViewFrame* aViewFrame = 0;
892     if (!svw) svw = svm->createViewWindow();
893     if (svw) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>(svw);
894
895     view->init( aViewFrame );
896     svm->setTitle( view->getViewName() );
897   }
898   else
899     if( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( svm->getViewModel() ) )
900       if( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
901         svm->getActiveView()->setFocus();
902         view->updateModel();
903       }
904 }
905
906 void GEOMToolsGUI::OnReduceStudy()
907 {
908   QDialog* dlg = new GEOMToolsGUI_ReduceStudyDlg( SUIT_Session::session()->activeApplication()->desktop() );
909   if( dlg != NULL )
910     dlg->show();
911 }