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>
98 #include <TColStd_HArray1OfByte.hxx>
102 #include <QColorDialog>
103 #include <QInputDialog>
104 #include <QFileDialog>
107 #include <QGridLayout>
110 #include <QPushButton>
114 #include <vtkRenderer.h>
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
124 void GEOMToolsGUI::OnCheckGeometry()
126 SalomeApp_Application* app =
127 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
128 PyConsole_Console* pyConsole = app->pythonConsole();
131 pyConsole->exec("from GEOM_usinggeom import *");
134 void GEOMToolsGUI::OnAutoColor()
136 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
139 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
140 if ( !appStudy ) return;
142 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
143 if ( !aSelMgr ) return;
145 SALOME_ListIO selected;
146 aSelMgr->selectedObjects( selected );
147 if ( selected.IsEmpty() ) return;
149 Handle(SALOME_InteractiveObject) anIObject = selected.First();
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;
156 aMainObject->SetAutoColor( true );
158 QList<SALOMEDS::Color> aReservedColors;
160 GEOM_Displayer displayer ( appStudy );
162 SALOME_View* window = displayer.GetActiveView();
163 if ( !window ) return;
165 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
167 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
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 ) )
174 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
175 if( aChildObject->GetType() != GEOM_GROUP )
177 #endif // GENERAL_AUTOCOLOR
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 );
187 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
189 SUIT_OverrideCursor();
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 );
195 displayer.UpdateViewer();
198 appStudy->Modified();
199 app->updateActions(); //SRN: To update a Save button in the toolbar
202 void GEOMToolsGUI::OnDisableAutoColor()
204 SALOME_ListIO selected;
205 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
209 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
210 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
211 if( !aSelMgr || !appStudy )
214 aSelMgr->selectedObjects( selected );
215 if( selected.IsEmpty() )
218 Handle(SALOME_InteractiveObject) anIObject = selected.First();
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 ) )
226 aMainObject->SetAutoColor( false );
229 void GEOMToolsGUI::OnColor()
231 // get active application
232 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
236 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
237 if ( !appStudy ) return;
239 // get selection manager
240 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
241 if ( !aSelMgr ) return;
244 SALOME_ListIO selected;
245 aSelMgr->selectedObjects( selected );
246 if ( selected.IsEmpty() ) return;
248 GEOM_Displayer displayer( appStudy );
251 SALOME_View* window = displayer.GetActiveView();
252 if ( !window ) return;
255 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
258 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
260 // show Choose Color dialog box
261 color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
262 if ( !color.isValid() ) return;
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 );
271 displayer.UpdateViewer();
272 GeometryGUI::Modified();
275 app->updateActions(); //SRN: To update a Save button in the toolbar
278 void GEOMToolsGUI::OnTexture()
280 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
283 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
284 if ( !appStudy ) return;
286 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
287 if ( !aSelMgr ) return;
289 SALOME_ListIO selected;
290 aSelMgr->selectedObjects( selected );
291 if ( selected.IsEmpty() ) return;
293 GEOM_Displayer displayer( appStudy );
294 SALOME_View* window = displayer.GetActiveView();
295 if ( !window ) return;
297 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
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 );
308 displayer.UpdateViewer();
309 GeometryGUI::Modified();
312 app->updateActions(); //SRN: To update a Save button in the toolbar
315 void GEOMToolsGUI::OnTransparency()
317 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
321 void GEOMToolsGUI::OnChangeTransparency( bool increase )
323 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
326 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
327 if( !appStudy) return;
329 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
330 if ( !aSelMgr ) return;
332 SALOME_ListIO selected;
333 aSelMgr->selectedObjects( selected );
334 if ( selected.IsEmpty() ) return;
336 GEOM_Displayer displayer( appStudy );
337 SALOME_View* window = displayer.GetActiveView();
338 if ( !window ) return;
340 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
343 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
347 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Transparency ), QVariant() );
348 float transp = v.isValid() ? v.toFloat() : 1;
350 // Compute new transparency value
351 transp = transp + delta;
354 else if ( transp > 1 )
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 );
362 displayer.UpdateViewer();
363 GeometryGUI::Modified();
366 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
368 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
371 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
372 if ( !appStudy ) return;
374 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
375 if ( !aSelMgr ) return;
377 SALOME_ListIO selected;
378 aSelMgr->selectedObjects( selected );
379 if ( selected.IsEmpty() ) return;
381 GEOM_Displayer displayer( appStudy );
382 SALOME_View* window = displayer.GetActiveView();
383 if ( !window ) return;
385 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
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();
400 if ( actionType == SHOWDLG ) {
401 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
402 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
404 NbIsosDlg->setU( UIso );
405 NbIsosDlg->setV( VIso );
407 if ( NbIsosDlg->exec() ) {
408 SUIT_OverrideCursor();
409 newNbUIso = NbIsosDlg->getU();
410 newNbVIso = NbIsosDlg->getV();
414 else if ( actionType == INCR || actionType == DECR ) {
416 if (actionType == DECR)
419 newNbUIso = UIso + delta;
420 newNbVIso = VIso + delta;
422 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
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 );
432 displayer.UpdateViewer();
433 GeometryGUI::Modified();
436 void GEOMToolsGUI::OnDeflection()
438 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
441 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
442 if ( !appStudy ) return;
444 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
445 if ( !aSelMgr ) return;
447 SALOME_ListIO selected;
448 aSelMgr->selectedObjects( selected );
449 if ( selected.IsEmpty() ) return;
451 GEOM_Displayer displayer( appStudy );
452 SALOME_View* window = displayer.GetActiveView();
453 if ( !window ) return;
455 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
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 );
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();
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 );
473 displayer.UpdateViewer();
474 GeometryGUI::Modified();
477 void GEOMToolsGUI::OnSelectOnly(int mode)
479 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
481 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
482 GEOM_Displayer aDisp (appStudy);
483 aDisp.GlobalSelection(mode);
484 getGeometryGUI()->setLocalSelectionMode(mode);
488 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
490 SALOME_ListIO selected;
491 SalomeApp_Application* app =
492 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
494 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
496 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
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();
507 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
509 SUIT_MessageBox::warning( app->desktop(),
510 QObject::tr( "WRN_WARNING" ),
511 QObject::tr( "WRN_STUDY_LOCKED" ) );
515 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
516 Handle(SALOME_InteractiveObject) IObject = It.Value();
518 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
519 _PTR(GenericAttribute) anAttr;
521 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
522 aExp->SetExpandable( show );
524 disp->EraseWithChildren(IObject,true);
529 app->updateObjectBrowser( false );
530 app->updateActions();
534 void GEOMToolsGUI::OnPointMarker()
536 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
540 void GEOMToolsGUI::OnMaterialProperties()
542 GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
546 void GEOMToolsGUI::OnMaterialsLibrary()
548 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
549 dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
553 void GEOMToolsGUI::OnUnpublishObject() {
554 SALOME_ListIO selected;
555 SalomeApp_Application* app =
556 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
558 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
560 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
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();
571 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
573 SUIT_MessageBox::warning( app->desktop(),
574 QObject::tr( "WRN_WARNING" ),
575 QObject::tr( "WRN_STUDY_LOCKED" ) );
579 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
580 Handle(SALOME_InteractiveObject) IObject = It.Value();
582 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
583 _PTR(GenericAttribute) anAttr;
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 );
597 aSelMgr->clearSelected();
600 app->updateObjectBrowser( false );
601 app->updateActions();
606 void GEOMToolsGUI::OnPublishObject() {
607 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
611 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
615 _PTR(Study) aStudy = appStudy->studyDS();
620 //Check lock of the study
621 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
623 SUIT_MessageBox::warning( app->desktop(),
624 QObject::tr( "WRN_WARNING" ),
625 QObject::tr( "WRN_STUDY_LOCKED" ) );
629 GEOMToolsGUI_PublishDlg* publishDlg =
630 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
635 void GEOMToolsGUI::OnEdgeWidth()
637 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
640 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
641 if ( !appStudy ) return;
643 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
644 if ( !aSelMgr ) return;
646 SALOME_ListIO selected;
647 aSelMgr->selectedObjects( selected );
648 if ( selected.IsEmpty() ) return;
650 GEOM_Displayer displayer( appStudy );
652 SALOME_View* window = displayer.GetActiveView();
653 if ( !window ) return;
655 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
657 GEOMToolsGUI_LineWidthDlg* Dlg =
658 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
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 );
663 Dlg->setTheLW( aWidth );
665 SUIT_OverrideCursor();
666 aWidth = Dlg->getTheLW();
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 );
674 displayer.UpdateViewer();
675 GeometryGUI::Modified();
679 void GEOMToolsGUI::OnIsosWidth() {
680 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
683 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
684 if ( !appStudy ) return;
686 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
687 if ( !aSelMgr ) return;
689 SALOME_ListIO selected;
690 aSelMgr->selectedObjects( selected );
691 if ( selected.IsEmpty() ) return;
693 GEOM_Displayer displayer( appStudy );
695 SALOME_View* window = displayer.GetActiveView();
696 if ( !window ) return;
698 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
700 GEOMToolsGUI_LineWidthDlg* Dlg =
701 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
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 );
706 Dlg->setTheLW( aWidth );
708 SUIT_OverrideCursor();
709 aWidth = Dlg->getTheLW();
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 );
717 displayer.UpdateViewer();
718 GeometryGUI::Modified();
721 void GEOMToolsGUI::OnBringToFront() {
722 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
725 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());
726 if (!appStudy) return;
728 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
729 if ( !aSelMgr ) return;
731 SALOME_ListIO selected;
732 aSelMgr->selectedObjects( selected );
733 if ( selected.IsEmpty() ) return;
735 GEOM_Displayer displayer( appStudy );
737 SALOME_View* window = displayer.GetActiveView();
738 if ( !window ) return;
740 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
742 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
743 bool checked = a->isChecked();
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 );
750 displayer.UpdateViewer();
751 GeometryGUI::Modified();
754 void GEOMToolsGUI::OnClsBringToFront() {
755 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
758 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
759 if ( !appStudy ) return;
761 GEOM_Displayer displayer( appStudy );
763 SALOME_View* window = displayer.GetActiveView();
764 if ( !window ) return;
766 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
768 SALOME_ListIO anIOlst;
769 window->GetVisible( anIOlst );
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 );
776 displayer.Redisplay( anIOlst );
777 displayer.UpdateViewer();
778 GeometryGUI::Modified();
781 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
783 if ( !theParam.canConvert<QString>() ) return;
785 QString theName = theParam.toString();
787 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
790 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
791 if ( !study ) return;
793 LightApp_SelectionMgr* selMgr = app->selectionMgr();
795 SALOME_ListIO selected;
796 selMgr->selectedObjects( selected );
798 if ( selected.IsEmpty() ) return;
800 GEOM_Displayer displayer( study );
802 SALOME_View* window = displayer.GetActiveView();
803 if ( !window ) return;
805 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
807 Material_Model aModel;
808 aModel.fromResources( theName );
809 QString prop = aModel.toProperties();
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 );
816 displayer.UpdateViewer();
819 void GEOMToolsGUI::OnCreateFolder()
821 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
824 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
825 if ( !appStudy ) return;
827 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
828 if ( !aSelMgr ) return;
830 SALOME_ListIO selected;
831 aSelMgr->selectedObjects( selected );
832 if ( selected.IsEmpty() ) return;
834 Handle(SALOME_InteractiveObject) anIObject = selected.First();
836 _PTR(Study) aStudy = appStudy->studyDS();
837 if( !aStudy ) return;
838 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
839 if ( !aFatherSO ) return;
841 GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(),
842 _CAST(SObject, aFatherSO)->GetSObject() );
843 app->updateObjectBrowser( false );
846 void GEOMToolsGUI::OnSortChildren()
848 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
851 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
852 if ( !appStudy ) return;
854 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
855 if ( !aSelMgr ) return;
857 SALOME_ListIO selected;
858 aSelMgr->selectedObjects( selected );
859 if ( selected.IsEmpty() ) return;
861 Handle(SALOME_InteractiveObject) anIObject = selected.First();
863 _PTR(Study) aStudy = appStudy->studyDS();
864 if( !aStudy ) return;
865 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
866 if ( !aFatherSO ) return;
868 aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
870 app->updateObjectBrowser( true );
873 void GEOMToolsGUI::OnShowDependencyTree()
875 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
877 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
880 SUIT_ViewManager *svm = app->getViewManager( GraphicsView_Viewer::Type(), false );
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 );
887 LightApp_SelectionMgr* selMgr = app->selectionMgr();
888 new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
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);
895 view->init( aViewFrame );
896 svm->setTitle( view->getViewName() );
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();
906 void GEOMToolsGUI::OnReduceStudy()
908 QDialog* dlg = new GEOMToolsGUI_ReduceStudyDlg( SUIT_Session::session()->activeApplication()->desktop() );