1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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)
27 #include <PyConsole_Console.h>
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>
40 #include <GEOM_VTKPropertyMaterial.hxx>
42 #include <GeometryGUI.h>
43 #include <GeometryGUI_Operations.h>
44 #include <GEOM_Constants.h>
45 #include <GEOM_Displayer.h>
48 #include <GEOM_Actor.h>
50 #include <DependencyTree_ViewModel.h>
51 #include <DependencyTree_View.h>
52 #include <DependencyTree_Selector.h>
54 #include <Basics_OCCTVersion.hxx>
56 #include <SALOME_ListIO.hxx>
57 #include <SALOME_ListIteratorOfListIO.hxx>
59 #include <SALOMEDS_SObject.hxx>
64 #include <SVTK_ViewModel.h>
65 #include <SVTK_ViewWindow.h>
66 #include <SVTK_View.h>
68 #include <OCCViewer_ViewModel.h>
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>
78 #include <SalomeApp_Application.h>
79 #include <SalomeApp_Study.h>
80 #include <SalomeApp_Module.h>
82 #include <LightApp_SelectionMgr.h>
83 #include <LightApp_NameDlg.h>
85 #include <GEOMImpl_Types.hxx>
87 #include "utilities.h"
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>
99 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
100 #include <TColStd_HArray1OfByte.hxx>
102 #include <Graphic3d_HArray1OfBytes.hxx>
107 #include <QColorDialog>
108 #include <QInputDialog>
109 #include <QFileDialog>
112 #include <QGridLayout>
115 #include <QPushButton>
119 #include <vtkRenderer.h>
122 // If the next macro is defined, autocolor feature works for all sub-shapes;
123 // if it is undefined, autocolor feature works for groups only
124 #define GENERAL_AUTOCOLOR
125 // Below macro, when uncommented, switches on simplified (more performant) algorithm
126 // of auto-color picking up
127 #define SIMPLE_AUTOCOLOR
129 void GEOMToolsGUI::OnCheckGeometry()
131 SalomeApp_Application* app =
132 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
133 PyConsole_Console* pyConsole = app->pythonConsole();
136 pyConsole->exec("from GEOM_usinggeom import *");
139 void GEOMToolsGUI::OnAutoColor()
141 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
144 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
145 if ( !appStudy ) return;
147 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
148 if ( !aSelMgr ) return;
150 SALOME_ListIO selected;
151 aSelMgr->selectedObjects( selected );
152 if ( selected.IsEmpty() ) return;
154 Handle(SALOME_InteractiveObject) anIObject = selected.First();
156 _PTR(Study) aStudy = appStudy->studyDS();
157 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
158 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
159 if (CORBA::is_nil(aMainObject)) return;
161 aMainObject->SetAutoColor( true );
163 QList<SALOMEDS::Color> aReservedColors;
165 GEOM_Displayer displayer ( appStudy );
167 SALOME_View* window = displayer.GetActiveView();
168 if ( !window ) return;
170 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
172 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
174 _PTR(SObject) aChildSObject( it->Value() );
175 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
176 if( CORBA::is_nil( aChildObject ) )
179 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
180 if( aChildObject->GetType() != GEOM_GROUP )
182 #endif // GENERAL_AUTOCOLOR
184 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
185 SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
186 #else // old algorithm for auto-colors
187 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
188 aReservedColors.append( aColor );
189 #endif // SIMPLE_AUTOCOLOR
190 aChildObject->SetColor( aColor );
192 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
194 SUIT_OverrideCursor();
196 appStudy->setObjectProperty( aMgrId, aChildObject->GetEntry(), GEOM::propertyName( GEOM::Color ), c );
197 Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject( aChildObject->GetStudyEntry(), "GEOM", "" );
198 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
200 displayer.UpdateViewer();
203 appStudy->Modified();
204 app->updateActions(); //SRN: To update a Save button in the toolbar
207 void GEOMToolsGUI::OnDisableAutoColor()
209 SALOME_ListIO selected;
210 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
214 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
215 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
216 if( !aSelMgr || !appStudy )
219 aSelMgr->selectedObjects( selected );
220 if( selected.IsEmpty() )
223 Handle(SALOME_InteractiveObject) anIObject = selected.First();
225 _PTR(Study) aStudy = appStudy->studyDS();
226 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
227 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
228 if( CORBA::is_nil( aMainObject ) )
231 aMainObject->SetAutoColor( false );
234 void GEOMToolsGUI::OnColor()
236 // get active application
237 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
241 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
242 if ( !appStudy ) return;
244 // get selection manager
245 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
246 if ( !aSelMgr ) return;
249 SALOME_ListIO selected;
250 aSelMgr->selectedObjects( selected );
251 if ( selected.IsEmpty() ) return;
253 GEOM_Displayer displayer( appStudy );
256 SALOME_View* window = displayer.GetActiveView();
257 if ( !window ) return;
260 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
263 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
265 // show Choose Color dialog box
266 color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
267 if ( !color.isValid() ) return;
269 // iterate through list of objects and assign new color
270 SUIT_OverrideCursor();
271 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
272 Handle( SALOME_InteractiveObject ) io = It.Value();
273 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Color ), color );
274 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
276 displayer.UpdateViewer();
277 GeometryGUI::Modified();
280 app->updateActions(); //SRN: To update a Save button in the toolbar
283 void GEOMToolsGUI::OnTexture()
285 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
288 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
289 if ( !appStudy ) return;
291 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
292 if ( !aSelMgr ) return;
294 SALOME_ListIO selected;
295 aSelMgr->selectedObjects( selected );
296 if ( selected.IsEmpty() ) return;
298 GEOM_Displayer displayer( appStudy );
299 SALOME_View* window = displayer.GetActiveView();
300 if ( !window ) return;
302 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
304 QString aTexture = QFileDialog::getOpenFileName( dynamic_cast< SUIT_ViewWindow* >( window ),tr("GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
305 if( !aTexture.isEmpty() ) {
306 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
307 Handle( SALOME_InteractiveObject ) io = It.Value();
308 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Texture ), aTexture );
309 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), 3 );
310 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
313 displayer.UpdateViewer();
314 GeometryGUI::Modified();
317 app->updateActions(); //SRN: To update a Save button in the toolbar
320 void GEOMToolsGUI::OnTransparency()
322 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
326 void GEOMToolsGUI::OnChangeTransparency( bool increase )
328 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
331 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
332 if( !appStudy) return;
334 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
335 if ( !aSelMgr ) return;
337 SALOME_ListIO selected;
338 aSelMgr->selectedObjects( selected );
339 if ( selected.IsEmpty() ) return;
341 GEOM_Displayer displayer( appStudy );
342 SALOME_View* window = displayer.GetActiveView();
343 if ( !window ) return;
345 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
348 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
352 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Transparency ), QVariant() );
353 float transp = v.isValid() ? v.toFloat() : 1;
355 // Compute new transparency value
356 transp = transp + delta;
359 else if ( transp > 1 )
362 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
363 Handle( SALOME_InteractiveObject ) io = It.Value();
364 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::Transparency ), transp );
365 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
367 displayer.UpdateViewer();
368 GeometryGUI::Modified();
371 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
373 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
376 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
377 if ( !appStudy ) return;
379 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
380 if ( !aSelMgr ) return;
382 SALOME_ListIO selected;
383 aSelMgr->selectedObjects( selected );
384 if ( selected.IsEmpty() ) return;
386 GEOM_Displayer displayer( appStudy );
387 SALOME_View* window = displayer.GetActiveView();
388 if ( !window ) return;
390 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
392 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::NbIsos ) , QVariant() );
393 QString aStr = v.toString();
394 QStringList aStrList = aStr.split( GEOM::subSectionSeparator() );
395 int UIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_u", 1 );
396 int VIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_v", 1 );
397 if ( aStrList.count() == 2 ) {
398 if ( !aStrList[0].isEmpty() ) UIso = aStrList[0].toInt();
399 if ( !aStrList[1].isEmpty() ) VIso = aStrList[1].toInt();
405 if ( actionType == SHOWDLG ) {
406 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
407 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
409 NbIsosDlg->setU( UIso );
410 NbIsosDlg->setV( VIso );
412 if ( NbIsosDlg->exec() ) {
413 SUIT_OverrideCursor();
414 newNbUIso = NbIsosDlg->getU();
415 newNbVIso = NbIsosDlg->getV();
419 else if ( actionType == INCR || actionType == DECR ) {
421 if (actionType == DECR)
424 newNbUIso = UIso + delta;
425 newNbVIso = VIso + delta;
427 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
431 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
432 Handle( SALOME_InteractiveObject ) io = It.Value();
433 QString anIsos = QString( "%1%2%3" ).arg( newNbUIso ).arg( GEOM::subSectionSeparator() ).arg( newNbVIso );
434 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos );
435 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
437 displayer.UpdateViewer();
438 GeometryGUI::Modified();
441 void GEOMToolsGUI::OnDeflection()
443 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
446 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
447 if ( !appStudy ) return;
449 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
450 if ( !aSelMgr ) return;
452 SALOME_ListIO selected;
453 aSelMgr->selectedObjects( selected );
454 if ( selected.IsEmpty() ) return;
456 GEOM_Displayer displayer( appStudy );
457 SALOME_View* window = displayer.GetActiveView();
458 if ( !window ) return;
460 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
462 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
463 double aDC = v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
465 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
466 ( SUIT_Session::session()->activeApplication()->desktop() );
467 DeflectionDlg->setTheDC( aDC );
468 if ( DeflectionDlg->exec() ) {
469 SUIT_OverrideCursor();
470 aDC = DeflectionDlg->getTheDC();
472 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
473 Handle( SALOME_InteractiveObject ) io = It.Value();
474 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC );
475 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
478 displayer.UpdateViewer();
479 GeometryGUI::Modified();
482 void GEOMToolsGUI::OnSelectOnly(int mode)
484 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
486 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
487 GEOM_Displayer aDisp (appStudy);
488 aDisp.GlobalSelection(mode);
489 getGeometryGUI()->setLocalSelectionMode(mode);
493 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
495 SALOME_ListIO selected;
496 SalomeApp_Application* app =
497 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
499 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
501 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
504 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
505 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
506 if ( aSelMgr && appStudy ) {
507 aSelMgr->selectedObjects( selected );
508 if ( !selected.IsEmpty() ) {
509 _PTR(Study) aStudy = appStudy->studyDS();
510 _PTR(StudyBuilder) B = aStudy->NewBuilder();
512 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
514 SUIT_MessageBox::warning( app->desktop(),
515 QObject::tr( "WRN_WARNING" ),
516 QObject::tr( "WRN_STUDY_LOCKED" ) );
520 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
521 Handle(SALOME_InteractiveObject) IObject = It.Value();
523 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
524 _PTR(GenericAttribute) anAttr;
526 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
527 aExp->SetExpandable( show );
529 disp->EraseWithChildren(IObject,true);
534 app->updateObjectBrowser( false );
535 app->updateActions();
539 void GEOMToolsGUI::OnPointMarker()
541 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
545 void GEOMToolsGUI::OnMaterialProperties()
547 GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
551 void GEOMToolsGUI::OnMaterialsLibrary()
553 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
554 dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
558 void GEOMToolsGUI::OnUnpublishObject() {
559 SALOME_ListIO selected;
560 SalomeApp_Application* app =
561 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
563 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
565 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
568 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
569 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
570 if ( aSelMgr && appStudy ) {
571 aSelMgr->selectedObjects( selected );
572 if ( !selected.IsEmpty() ) {
573 _PTR(Study) aStudy = appStudy->studyDS();
574 _PTR(StudyBuilder) B = aStudy->NewBuilder();
576 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
578 SUIT_MessageBox::warning( app->desktop(),
579 QObject::tr( "WRN_WARNING" ),
580 QObject::tr( "WRN_STUDY_LOCKED" ) );
584 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
585 Handle(SALOME_InteractiveObject) IObject = It.Value();
587 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
588 _PTR(GenericAttribute) anAttr;
590 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
591 aDrw->SetDrawable( false );
592 disp->EraseWithChildren(IObject);
595 aSelMgr->clearSelected();
598 app->updateObjectBrowser( false );
599 app->updateActions();
604 void GEOMToolsGUI::OnPublishObject() {
605 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
609 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
613 _PTR(Study) aStudy = appStudy->studyDS();
618 //Check lock of the study
619 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
621 SUIT_MessageBox::warning( app->desktop(),
622 QObject::tr( "WRN_WARNING" ),
623 QObject::tr( "WRN_STUDY_LOCKED" ) );
627 GEOMToolsGUI_PublishDlg* publishDlg =
628 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
633 void GEOMToolsGUI::OnEdgeWidth()
635 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
638 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
639 if ( !appStudy ) return;
641 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
642 if ( !aSelMgr ) return;
644 SALOME_ListIO selected;
645 aSelMgr->selectedObjects( selected );
646 if ( selected.IsEmpty() ) return;
648 GEOM_Displayer displayer( appStudy );
650 SALOME_View* window = displayer.GetActiveView();
651 if ( !window ) return;
653 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
655 GEOMToolsGUI_LineWidthDlg* Dlg =
656 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
658 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
659 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
661 Dlg->setTheLW( aWidth );
663 SUIT_OverrideCursor();
664 aWidth = Dlg->getTheLW();
666 return; //Cancel case
667 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
668 Handle( SALOME_InteractiveObject ) io = It.Value();
669 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
670 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
672 displayer.UpdateViewer();
673 GeometryGUI::Modified();
677 void GEOMToolsGUI::OnIsosWidth() {
678 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
681 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
682 if ( !appStudy ) return;
684 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
685 if ( !aSelMgr ) return;
687 SALOME_ListIO selected;
688 aSelMgr->selectedObjects( selected );
689 if ( selected.IsEmpty() ) return;
691 GEOM_Displayer displayer( appStudy );
693 SALOME_View* window = displayer.GetActiveView();
694 if ( !window ) return;
696 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
698 GEOMToolsGUI_LineWidthDlg* Dlg =
699 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
701 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
702 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
704 Dlg->setTheLW( aWidth );
706 SUIT_OverrideCursor();
707 aWidth = Dlg->getTheLW();
709 return; //Cancel case
710 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
711 Handle( SALOME_InteractiveObject ) io = It.Value();
712 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
713 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
715 displayer.UpdateViewer();
716 GeometryGUI::Modified();
719 void GEOMToolsGUI::OnBringToFront() {
720 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
723 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());
724 if (!appStudy) return;
726 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
727 if ( !aSelMgr ) return;
729 SALOME_ListIO selected;
730 aSelMgr->selectedObjects( selected );
731 if ( selected.IsEmpty() ) return;
733 GEOM_Displayer displayer( appStudy );
735 SALOME_View* window = displayer.GetActiveView();
736 if ( !window ) return;
738 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
740 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
741 bool checked = a->isChecked();
743 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
744 Handle( SALOME_InteractiveObject ) io = It.Value();
745 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
746 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
748 displayer.UpdateViewer();
749 GeometryGUI::Modified();
752 void GEOMToolsGUI::OnClsBringToFront() {
753 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
756 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
757 if ( !appStudy ) return;
759 GEOM_Displayer displayer( appStudy );
761 SALOME_View* window = displayer.GetActiveView();
762 if ( !window ) return;
764 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
766 SALOME_ListIO anIOlst;
767 window->GetVisible( anIOlst );
769 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
770 Handle( SALOME_InteractiveObject ) io = It.Value();
771 appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
772 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
774 displayer.Redisplay( anIOlst );
775 displayer.UpdateViewer();
776 GeometryGUI::Modified();
779 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
781 if ( !theParam.canConvert<QString>() ) return;
783 QString theName = theParam.toString();
785 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
788 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
789 if ( !study ) return;
791 LightApp_SelectionMgr* selMgr = app->selectionMgr();
793 SALOME_ListIO selected;
794 selMgr->selectedObjects( selected );
796 if ( selected.IsEmpty() ) return;
798 GEOM_Displayer displayer( study );
800 SALOME_View* window = displayer.GetActiveView();
801 if ( !window ) return;
803 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
805 Material_Model aModel;
806 aModel.fromResources( theName );
807 QString prop = aModel.toProperties();
809 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
810 Handle(SALOME_InteractiveObject) io = It.Value();
811 study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
812 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
814 displayer.UpdateViewer();
817 void GEOMToolsGUI::OnCreateFolder()
819 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
822 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
823 if ( !appStudy ) return;
825 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
826 if ( !aSelMgr ) return;
828 SALOME_ListIO selected;
829 aSelMgr->selectedObjects( selected );
830 if ( selected.IsEmpty() ) return;
832 Handle(SALOME_InteractiveObject) anIObject = selected.First();
834 _PTR(Study) aStudy = appStudy->studyDS();
835 if( !aStudy ) return;
836 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
837 if ( !aFatherSO ) return;
839 GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(),
840 _CAST(SObject, aFatherSO)->GetSObject() );
841 app->updateObjectBrowser( false );
844 void GEOMToolsGUI::OnSortChildren()
846 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
849 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
850 if ( !appStudy ) return;
852 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
853 if ( !aSelMgr ) return;
855 SALOME_ListIO selected;
856 aSelMgr->selectedObjects( selected );
857 if ( selected.IsEmpty() ) return;
859 Handle(SALOME_InteractiveObject) anIObject = selected.First();
861 _PTR(Study) aStudy = appStudy->studyDS();
862 if( !aStudy ) return;
863 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
864 if ( !aFatherSO ) return;
866 aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
868 app->updateObjectBrowser( true );
871 void GEOMToolsGUI::OnShowDependencyTree()
873 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
875 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
878 SUIT_ViewManager *svm = app->getViewManager( GraphicsView_Viewer::Type(), false );
881 DependencyTree_View* view = new DependencyTree_View();
882 DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
883 SUIT_ViewManager *svm = app->createViewManager( viewModel );
885 LightApp_SelectionMgr* selMgr = app->selectionMgr();
886 new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
888 SUIT_ViewWindow* svw = svm->getActiveView();
889 GraphicsView_ViewFrame* aViewFrame = 0;
890 if (!svw) svw = svm->createViewWindow();
891 if (svw) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>(svw);
893 view->init( aViewFrame );
894 svm->setTitle( view->getViewName() );
897 if( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( svm->getViewModel() ) )
898 if( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
899 svm->getActiveView()->setFocus();
904 void GEOMToolsGUI::OnReduceStudy()
906 GEOM::string_array_var objectsEntry = new GEOM::string_array();
907 SALOME_ListIO mainObjects;
910 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
912 app->selectionMgr()->selectedObjects( mainObjects );
913 // create a list of selected object entry
914 objectsEntry->length( mainObjects.Extent() );
915 for ( SALOME_ListIteratorOfListIO It( mainObjects ); It.More(); It.Next(), iter++ ) {
916 Handle( SALOME_InteractiveObject ) io = It.Value();
917 if( !io->hasEntry() )
919 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_nil();
920 geomObject = GEOMBase::ConvertIOinGEOMObject( io );
921 QString entry = geomObject->GetEntry();
922 objectsEntry[ iter ] = entry.toLatin1().constData();
924 GEOMToolsGUI_ReduceStudyDlg dlg( objectsEntry, SUIT_Session::session()->activeApplication()->desktop() );