1 // Copyright (C) 2007-2016 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 #ifndef DISABLE_PYCONSOLE
28 #include <PyConsole_Console.h>
31 #include "GEOMToolsGUI.h"
32 #include "GEOMToolsGUI_TransparencyDlg.h"
33 #include "GEOMToolsGUI_NbIsosDlg.h"
34 #include "GEOMToolsGUI_DeflectionDlg.h"
35 #include "GEOMToolsGUI_MarkerDlg.h"
36 #include "GEOMToolsGUI_PublishDlg.h"
37 #include "GEOMToolsGUI_MaterialPropertiesDlg.h"
38 #include "GEOMToolsGUI_LineWidthDlg.h"
39 #include "GEOMToolsGUI_ReduceStudyDlg.h"
40 #include <Material_Model.h>
42 #include <GEOM_VTKPropertyMaterial.hxx>
44 #include <GeometryGUI.h>
45 #include <GeometryGUI_Operations.h>
46 #include <GEOM_Constants.h>
47 #include <GEOM_Displayer.h>
50 #include <GEOM_Actor.h>
52 #ifndef DISABLE_GRAPHICSVIEW
53 #include <DependencyTree_ViewModel.h>
54 #include <DependencyTree_View.h>
55 #include <DependencyTree_Selector.h>
58 #include <SALOME_ListIO.hxx>
60 #include <SALOMEDS_SObject.hxx>
65 #include <SVTK_ViewModel.h>
66 #include <SVTK_ViewWindow.h>
67 #include <SVTK_View.h>
69 #include <OCCViewer_ViewModel.h>
71 #include <SUIT_ViewManager.h>
72 #include <SUIT_Desktop.h>
73 #include <SUIT_ResourceMgr.h>
74 #include <SUIT_Session.h>
75 #include <SUIT_OverrideCursor.h>
76 #include <SUIT_MessageBox.h>
77 #include <SUIT_Tools.h>
79 #include <STD_TabDesktop.h>
81 #include <QtxWorkstack.h>
83 #include <SalomeApp_Application.h>
84 #include <SalomeApp_Study.h>
85 #include <SalomeApp_Module.h>
87 #include <LightApp_SelectionMgr.h>
88 #include <LightApp_NameDlg.h>
90 #include <GEOMImpl_Types.hxx>
92 #include "utilities.h"
95 #include <Prs3d_IsoAspect.hxx>
96 #include <Prs3d_PointAspect.hxx>
97 #include <Graphic3d_AspectMarker3d.hxx>
98 #include <Graphic3d_AspectLine3d.hxx>
99 #include <AIS_ListIteratorOfListOfInteractive.hxx>
100 #include <AIS_ListOfInteractive.hxx>
102 #include <TColStd_HArray1OfByte.hxx>
106 #include <QApplication>
107 #include <QColorDialog>
108 #include <QInputDialog>
109 #include <QFileDialog>
112 #include <QGridLayout>
115 #include <QPushButton>
119 #include <vtkRenderer.h>
121 // If the next macro is defined, autocolor feature works for all sub-shapes;
122 // if it is undefined, autocolor feature works for groups only
123 #define GENERAL_AUTOCOLOR
124 // Below macro, when uncommented, switches on simplified (more performant) algorithm
125 // of auto-color picking up
126 #define SIMPLE_AUTOCOLOR
127 // Below macro, when defined, switches on automatic layouting of OCC and Dependency views
128 // on Show Dependencies operation
129 #define LAYOUT_DEPVIEW
131 #ifndef DISABLE_PYCONSOLE
132 void GEOMToolsGUI::OnCheckGeometry()
134 SalomeApp_Application* app =
135 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
136 PyConsole_Console* pyConsole = app->pythonConsole();
139 pyConsole->exec("from GEOM_usinggeom import *");
143 void GEOMToolsGUI::OnAutoColor()
145 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
148 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
149 if ( !appStudy ) return;
151 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
152 if ( !aSelMgr ) return;
154 SALOME_ListIO selected;
155 aSelMgr->selectedObjects( selected );
156 if ( selected.IsEmpty() ) return;
158 Handle(SALOME_InteractiveObject) anIObject = selected.First();
160 _PTR(Study) aStudy = appStudy->studyDS();
161 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
162 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
163 if (CORBA::is_nil(aMainObject)) return;
165 aMainObject->SetAutoColor( true );
167 QList<SALOMEDS::Color> aReservedColors;
169 GEOM_Displayer displayer;
171 SALOME_View* window = displayer.GetActiveView();
172 if ( !window ) return;
174 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
176 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
178 _PTR(SObject) aChildSObject( it->Value() );
179 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
180 if( CORBA::is_nil( aChildObject ) )
183 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
184 if( aChildObject->GetType() != GEOM_GROUP )
186 #endif // GENERAL_AUTOCOLOR
188 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
189 SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
190 #else // old algorithm for auto-colors
191 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
192 aReservedColors.append( aColor );
193 #endif // SIMPLE_AUTOCOLOR
194 aChildObject->SetColor( aColor );
196 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
198 SUIT_OverrideCursor wc;
200 appStudy->setObjectProperty( aMgrId, aChildObject->GetStudyEntry(), GEOM::propertyName( GEOM::Color ), c );
201 Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject( aChildObject->GetStudyEntry(), "GEOM", "" );
202 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
204 displayer.UpdateViewer();
207 appStudy->Modified();
208 app->updateActions(); //SRN: To update a Save button in the toolbar
211 void GEOMToolsGUI::OnDisableAutoColor()
213 SALOME_ListIO selected;
214 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
218 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
219 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
220 if( !aSelMgr || !appStudy )
223 aSelMgr->selectedObjects( selected );
224 if( selected.IsEmpty() )
227 Handle(SALOME_InteractiveObject) anIObject = selected.First();
229 _PTR(Study) aStudy = appStudy->studyDS();
230 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
231 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
232 if( CORBA::is_nil( aMainObject ) )
235 aMainObject->SetAutoColor( false );
238 void GEOMToolsGUI::OnColor()
240 // get active application
241 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
245 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
246 if ( !appStudy ) return;
248 // get selection manager
249 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
250 if ( !aSelMgr ) return;
253 SALOME_ListIO selected;
254 aSelMgr->selectedObjects( selected );
255 if ( selected.IsEmpty() ) return;
257 GEOM_Displayer displayer;
260 SALOME_View* window = displayer.GetActiveView();
261 if ( !window ) return;
264 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
267 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
269 // show Choose Color dialog box
270 color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
271 if ( !color.isValid() ) return;
273 SALOMEDS::Color aSColor;
274 aSColor.R = (double)color.red() / 255.0;
275 aSColor.G = (double)color.green() / 255.0;
276 aSColor.B = (double)color.blue() / 255.0;
278 // iterate through list of objects and assign new color
279 SUIT_OverrideCursor wc;
280 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
281 Handle( SALOME_InteractiveObject ) io = It.Value();
282 GEOM::GEOM_Object_var aObject = GEOMBase::ConvertIOinGEOMObject( io );
283 if ( !CORBA::is_nil( aObject ) ) aObject->SetColor( aSColor );
284 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Color ), color );
285 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
287 displayer.UpdateViewer();
288 GeometryGUI::Modified();
291 app->updateActions(); //SRN: To update a Save button in the toolbar
294 void GEOMToolsGUI::OnTexture()
296 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
299 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
300 if ( !appStudy ) return;
302 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
303 if ( !aSelMgr ) return;
305 SALOME_ListIO selected;
306 aSelMgr->selectedObjects( selected );
307 if ( selected.IsEmpty() ) return;
309 GEOM_Displayer displayer;
310 SALOME_View* window = displayer.GetActiveView();
311 if ( !window ) return;
313 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
315 QString aTexture = QFileDialog::getOpenFileName( dynamic_cast< SUIT_ViewWindow* >( window ),tr("GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
316 if( !aTexture.isEmpty() ) {
317 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
318 Handle( SALOME_InteractiveObject ) io = It.Value();
319 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Texture ), aTexture );
320 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), 3 );
321 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
324 displayer.UpdateViewer();
325 GeometryGUI::Modified();
328 app->updateActions(); //SRN: To update a Save button in the toolbar
331 void GEOMToolsGUI::OnTransparency()
333 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
337 void GEOMToolsGUI::OnChangeTransparency( bool increase )
339 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
342 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
343 if( !appStudy) return;
345 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
346 if ( !aSelMgr ) return;
348 SALOME_ListIO selected;
349 aSelMgr->selectedObjects( selected );
350 if ( selected.IsEmpty() ) return;
352 GEOM_Displayer displayer;
353 SALOME_View* window = displayer.GetActiveView();
354 if ( !window ) return;
356 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
359 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
363 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Transparency ), QVariant() );
364 float transp = v.isValid() ? v.toFloat() : 1;
366 // Compute new transparency value
367 transp = transp + delta;
370 else if ( transp > 1 )
373 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
374 Handle( SALOME_InteractiveObject ) io = It.Value();
375 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::Transparency ), transp );
376 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
378 displayer.UpdateViewer();
379 GeometryGUI::Modified();
382 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
384 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
387 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
388 if ( !appStudy ) return;
390 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
391 if ( !aSelMgr ) return;
393 SALOME_ListIO selected;
394 aSelMgr->selectedObjects( selected );
395 if ( selected.IsEmpty() ) return;
397 GEOM_Displayer displayer;
398 SALOME_View* window = displayer.GetActiveView();
399 if ( !window ) return;
401 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
403 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::NbIsos ) , QVariant() );
404 QString aStr = v.toString();
405 QStringList aStrList = aStr.split( GEOM::subSectionSeparator() );
406 int UIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_u", 1 );
407 int VIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_v", 1 );
408 if ( aStrList.count() == 2 ) {
409 if ( !aStrList[0].isEmpty() ) UIso = aStrList[0].toInt();
410 if ( !aStrList[1].isEmpty() ) VIso = aStrList[1].toInt();
416 if ( actionType == SHOWDLG ) {
417 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
418 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
420 NbIsosDlg->setU( UIso );
421 NbIsosDlg->setV( VIso );
423 if ( NbIsosDlg->exec() ) {
424 SUIT_OverrideCursor wc;
425 newNbUIso = NbIsosDlg->getU();
426 newNbVIso = NbIsosDlg->getV();
430 else if ( actionType == INCR || actionType == DECR ) {
432 if (actionType == DECR)
435 newNbUIso = UIso + delta;
436 newNbVIso = VIso + delta;
438 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
442 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
443 Handle( SALOME_InteractiveObject ) io = It.Value();
444 QString anIsos = QString( "%1%2%3" ).arg( newNbUIso ).arg( GEOM::subSectionSeparator() ).arg( newNbVIso );
445 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos );
446 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
448 displayer.UpdateViewer();
449 GeometryGUI::Modified();
452 void GEOMToolsGUI::OnDeflection()
454 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
457 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
458 if ( !appStudy ) return;
460 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
461 if ( !aSelMgr ) return;
463 SALOME_ListIO selected;
464 aSelMgr->selectedObjects( selected );
465 if ( selected.IsEmpty() ) return;
467 GEOM_Displayer displayer;
468 SALOME_View* window = displayer.GetActiveView();
469 if ( !window ) return;
471 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
473 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
474 double aDC = v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
476 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
477 ( SUIT_Session::session()->activeApplication()->desktop() );
478 DeflectionDlg->setTheDC( aDC );
479 if ( DeflectionDlg->exec() ) {
480 SUIT_OverrideCursor wc;
481 aDC = DeflectionDlg->getTheDC();
483 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
484 Handle( SALOME_InteractiveObject ) io = It.Value();
485 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC );
486 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
489 displayer.UpdateViewer();
490 GeometryGUI::Modified();
493 void GEOMToolsGUI::OnSelectOnly(int mode)
495 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
497 GEOM_Displayer aDisp;
498 aDisp.GlobalSelection(mode);
499 getGeometryGUI()->setLocalSelectionMode(mode);
503 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
505 SALOME_ListIO selected;
506 SalomeApp_Application* app =
507 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
509 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
511 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
514 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
515 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
516 if ( aSelMgr && appStudy ) {
517 aSelMgr->selectedObjects( selected );
518 if ( !selected.IsEmpty() ) {
519 _PTR(Study) aStudy = appStudy->studyDS();
520 _PTR(StudyBuilder) B = aStudy->NewBuilder();
522 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
524 SUIT_MessageBox::warning( app->desktop(),
525 QObject::tr( "WRN_WARNING" ),
526 QObject::tr( "WRN_STUDY_LOCKED" ) );
530 SUIT_OverrideCursor wc;
531 bool toUpdateColorScale = disp->SetUpdateColorScale( false ); // IPAL54049
532 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
533 Handle(SALOME_InteractiveObject) IObject = It.Value();
535 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
536 _PTR(GenericAttribute) anAttr;
538 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
539 aExp->SetExpandable( show );
541 disp->EraseWithChildren(IObject,true);
545 disp->SetUpdateColorScale( toUpdateColorScale );
548 app->updateObjectBrowser( false );
549 app->updateActions();
553 void GEOMToolsGUI::OnPointMarker()
555 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
559 void GEOMToolsGUI::OnMaterialProperties()
561 GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
565 void GEOMToolsGUI::OnMaterialsLibrary()
567 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
568 dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
572 void GEOMToolsGUI::OnUnpublishObject() {
573 SALOME_ListIO selected;
574 SalomeApp_Application* app =
575 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
577 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
579 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
582 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
583 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
584 if ( aSelMgr && appStudy ) {
585 aSelMgr->selectedObjects( selected );
586 if ( !selected.IsEmpty() ) {
587 _PTR(Study) aStudy = appStudy->studyDS();
588 _PTR(StudyBuilder) B = aStudy->NewBuilder();
590 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
592 SUIT_MessageBox::warning( app->desktop(),
593 QObject::tr( "WRN_WARNING" ),
594 QObject::tr( "WRN_STUDY_LOCKED" ) );
597 SUIT_OverrideCursor wc;
598 bool toUpdateColorScale = disp->SetUpdateColorScale( false ); // IPAL54049
599 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
600 Handle(SALOME_InteractiveObject) IObject = It.Value();
602 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
603 _PTR(GenericAttribute) anAttr;
605 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
606 aDrw->SetDrawable( false );
607 disp->EraseWithChildren(IObject);
608 // hide references if any
609 std::vector< _PTR(SObject) > vso = aStudy->FindDependances(obj);
610 for ( int i = 0; i < vso.size(); i++ ) {
611 _PTR(SObject) refObj = vso[i];
612 aDrw = B->FindOrCreateAttribute( refObj, "AttributeDrawable" );
613 aDrw->SetDrawable( false );
617 disp->SetUpdateColorScale( toUpdateColorScale ); // IPAL54049
618 aSelMgr->clearSelected();
621 app->updateObjectBrowser( false );
622 app->updateActions();
626 void GEOMToolsGUI::OnPublishObject() {
627 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
631 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
635 _PTR(Study) aStudy = appStudy->studyDS();
640 //Check lock of the study
641 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
643 SUIT_MessageBox::warning( app->desktop(),
644 QObject::tr( "WRN_WARNING" ),
645 QObject::tr( "WRN_STUDY_LOCKED" ) );
649 GEOMToolsGUI_PublishDlg* publishDlg =
650 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
655 void GEOMToolsGUI::OnEdgeWidth()
657 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
660 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
661 if ( !appStudy ) return;
663 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
664 if ( !aSelMgr ) return;
666 SALOME_ListIO selected;
667 aSelMgr->selectedObjects( selected );
668 if ( selected.IsEmpty() ) return;
670 GEOM_Displayer displayer;
672 SALOME_View* window = displayer.GetActiveView();
673 if ( !window ) return;
675 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
677 GEOMToolsGUI_LineWidthDlg* Dlg =
678 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
680 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
681 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
683 Dlg->setTheLW( aWidth );
685 SUIT_OverrideCursor wc;
686 aWidth = Dlg->getTheLW();
688 return; //Cancel case
689 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
690 Handle( SALOME_InteractiveObject ) io = It.Value();
691 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
692 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
694 displayer.UpdateViewer();
695 GeometryGUI::Modified();
699 void GEOMToolsGUI::OnIsosWidth() {
700 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
703 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
704 if ( !appStudy ) return;
706 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
707 if ( !aSelMgr ) return;
709 SALOME_ListIO selected;
710 aSelMgr->selectedObjects( selected );
711 if ( selected.IsEmpty() ) return;
713 GEOM_Displayer displayer;
715 SALOME_View* window = displayer.GetActiveView();
716 if ( !window ) return;
718 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
720 GEOMToolsGUI_LineWidthDlg* Dlg =
721 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
723 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
724 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
726 Dlg->setTheLW( aWidth );
728 SUIT_OverrideCursor wc;
729 aWidth = Dlg->getTheLW();
731 return; //Cancel case
732 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
733 Handle( SALOME_InteractiveObject ) io = It.Value();
734 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
735 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
737 displayer.UpdateViewer();
738 GeometryGUI::Modified();
741 void GEOMToolsGUI::OnBringToFront() {
742 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
745 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());
746 if (!appStudy) return;
748 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
749 if ( !aSelMgr ) return;
751 SALOME_ListIO selected;
752 aSelMgr->selectedObjects( selected );
753 if ( selected.IsEmpty() ) return;
755 GEOM_Displayer displayer;
757 SALOME_View* window = displayer.GetActiveView();
758 if ( !window ) return;
760 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
762 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
763 bool checked = a->isChecked();
765 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
766 Handle( SALOME_InteractiveObject ) io = It.Value();
767 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
768 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
770 displayer.UpdateViewer();
771 GeometryGUI::Modified();
774 void GEOMToolsGUI::OnClsBringToFront() {
775 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
778 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
779 if ( !appStudy ) return;
781 GEOM_Displayer displayer;
783 SALOME_View* window = displayer.GetActiveView();
784 if ( !window ) return;
786 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
788 SALOME_ListIO anIOlst;
789 window->GetVisible( anIOlst );
791 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
792 Handle( SALOME_InteractiveObject ) io = It.Value();
793 appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
794 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
796 displayer.Redisplay( anIOlst );
797 displayer.UpdateViewer();
798 GeometryGUI::Modified();
801 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
803 if ( !theParam.canConvert<QString>() ) return;
805 QString theName = theParam.toString();
807 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
810 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
811 if ( !study ) return;
813 LightApp_SelectionMgr* selMgr = app->selectionMgr();
815 SALOME_ListIO selected;
816 selMgr->selectedObjects( selected );
818 if ( selected.IsEmpty() ) return;
820 GEOM_Displayer displayer;
822 SALOME_View* window = displayer.GetActiveView();
823 if ( !window ) return;
825 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
827 Material_Model aModel;
828 aModel.fromResources( theName );
829 QString prop = aModel.toProperties();
831 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
832 Handle(SALOME_InteractiveObject) io = It.Value();
833 study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
834 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
836 displayer.UpdateViewer();
839 void GEOMToolsGUI::OnCreateFolder()
841 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
844 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
845 if ( !appStudy ) return;
847 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
848 if ( !aSelMgr ) return;
850 SALOME_ListIO selected;
851 aSelMgr->selectedObjects( selected );
852 if ( selected.IsEmpty() ) return;
854 Handle(SALOME_InteractiveObject) anIObject = selected.First();
856 _PTR(Study) aStudy = appStudy->studyDS();
857 if( !aStudy ) return;
858 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
859 if ( !aFatherSO ) return;
861 GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(),
862 _CAST(SObject, aFatherSO)->GetSObject() );
863 app->updateObjectBrowser( false );
866 void GEOMToolsGUI::OnSortChildren()
868 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
871 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
872 if ( !appStudy ) return;
874 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
875 if ( !aSelMgr ) return;
877 SALOME_ListIO selected;
878 aSelMgr->selectedObjects( selected );
879 if ( selected.IsEmpty() ) return;
881 Handle(SALOME_InteractiveObject) anIObject = selected.First();
883 _PTR(Study) aStudy = appStudy->studyDS();
884 if( !aStudy ) return;
885 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
886 if ( !aFatherSO ) return;
888 aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
890 app->updateObjectBrowser( true );
893 #ifndef DISABLE_GRAPHICSVIEW
894 void GEOMToolsGUI::OnShowDependencyTree()
896 //SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
898 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
901 #ifdef LAYOUT_DEPVIEW
902 SUIT_ViewManager* occVm = app->getViewManager( OCCViewer_Viewer::Type(), true );
903 SUIT_ViewWindow* occVw = occVm->getActiveView();
905 SUIT_ViewManager* depVm = app->getViewManager( GraphicsView_Viewer::Type(), false );
906 SUIT_ViewWindow* depVw = 0;
909 DependencyTree_View* view = new DependencyTree_View();
910 DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
911 depVm = app->createViewManager( viewModel );
913 LightApp_SelectionMgr* selMgr = app->selectionMgr();
914 new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
916 depVw = depVm->getActiveView();
917 GraphicsView_ViewFrame* aViewFrame = 0;
918 if ( !depVw ) depVw = depVm->createViewWindow();
919 if ( depVw ) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( depVw );
921 view->init( aViewFrame );
922 depVm->setTitle( view->getViewName() );
924 else if ( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( depVm->getViewModel() ) ) {
925 if ( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
926 depVw = depVm->getActiveView();
931 #ifdef LAYOUT_DEPVIEW
932 // layout views properly
933 STD_TabDesktop* d = dynamic_cast<STD_TabDesktop*>( app->desktop() );
934 if ( d && depVw && occVw ) {
935 QtxWorkstack* ws = d->workstack();
937 QApplication::instance()->processEvents();
938 ws->Split( depVw, Qt::Horizontal, QtxWorkstack::SplitMove );
946 void GEOMToolsGUI::OnReduceStudy()
948 QDialog* dlg = new GEOMToolsGUI_ReduceStudyDlg( SUIT_Session::session()->activeApplication()->desktop() );