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 Dependecy 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 ( appStudy );
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( appStudy );
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( appStudy );
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( appStudy );
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( appStudy );
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( appStudy );
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 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
498 GEOM_Displayer aDisp (appStudy);
499 aDisp.GlobalSelection(mode);
500 getGeometryGUI()->setLocalSelectionMode(mode);
504 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
506 SALOME_ListIO selected;
507 SalomeApp_Application* app =
508 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
510 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
512 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
515 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
516 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
517 if ( aSelMgr && appStudy ) {
518 aSelMgr->selectedObjects( selected );
519 if ( !selected.IsEmpty() ) {
520 _PTR(Study) aStudy = appStudy->studyDS();
521 _PTR(StudyBuilder) B = aStudy->NewBuilder();
523 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
525 SUIT_MessageBox::warning( app->desktop(),
526 QObject::tr( "WRN_WARNING" ),
527 QObject::tr( "WRN_STUDY_LOCKED" ) );
531 SUIT_OverrideCursor wc;
532 bool toUpdateColorScale = disp->SetUpdateColorScale( false ); // IPAL54049
533 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
534 Handle(SALOME_InteractiveObject) IObject = It.Value();
536 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
537 _PTR(GenericAttribute) anAttr;
539 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
540 aExp->SetExpandable( show );
542 disp->EraseWithChildren(IObject,true);
546 disp->SetUpdateColorScale( toUpdateColorScale );
549 app->updateObjectBrowser( false );
550 app->updateActions();
554 void GEOMToolsGUI::OnPointMarker()
556 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
560 void GEOMToolsGUI::OnMaterialProperties()
562 GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
566 void GEOMToolsGUI::OnMaterialsLibrary()
568 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
569 dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
573 void GEOMToolsGUI::OnUnpublishObject() {
574 SALOME_ListIO selected;
575 SalomeApp_Application* app =
576 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
578 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
580 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
583 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
584 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
585 if ( aSelMgr && appStudy ) {
586 aSelMgr->selectedObjects( selected );
587 if ( !selected.IsEmpty() ) {
588 _PTR(Study) aStudy = appStudy->studyDS();
589 _PTR(StudyBuilder) B = aStudy->NewBuilder();
591 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
593 SUIT_MessageBox::warning( app->desktop(),
594 QObject::tr( "WRN_WARNING" ),
595 QObject::tr( "WRN_STUDY_LOCKED" ) );
598 SUIT_OverrideCursor wc;
599 bool toUpdateColorScale = disp->SetUpdateColorScale( false ); // IPAL54049
600 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
601 Handle(SALOME_InteractiveObject) IObject = It.Value();
603 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
604 _PTR(GenericAttribute) anAttr;
606 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
607 aDrw->SetDrawable( false );
608 disp->EraseWithChildren(IObject);
609 // hide references if any
610 std::vector< _PTR(SObject) > vso = aStudy->FindDependances(obj);
611 for ( int i = 0; i < vso.size(); i++ ) {
612 _PTR(SObject) refObj = vso[i];
613 aDrw = B->FindOrCreateAttribute( refObj, "AttributeDrawable" );
614 aDrw->SetDrawable( false );
618 disp->SetUpdateColorScale( toUpdateColorScale ); // IPAL54049
619 aSelMgr->clearSelected();
622 app->updateObjectBrowser( false );
623 app->updateActions();
627 void GEOMToolsGUI::OnPublishObject() {
628 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
632 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
636 _PTR(Study) aStudy = appStudy->studyDS();
641 //Check lock of the study
642 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
644 SUIT_MessageBox::warning( app->desktop(),
645 QObject::tr( "WRN_WARNING" ),
646 QObject::tr( "WRN_STUDY_LOCKED" ) );
650 GEOMToolsGUI_PublishDlg* publishDlg =
651 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
656 void GEOMToolsGUI::OnEdgeWidth()
658 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
661 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
662 if ( !appStudy ) return;
664 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
665 if ( !aSelMgr ) return;
667 SALOME_ListIO selected;
668 aSelMgr->selectedObjects( selected );
669 if ( selected.IsEmpty() ) return;
671 GEOM_Displayer displayer( appStudy );
673 SALOME_View* window = displayer.GetActiveView();
674 if ( !window ) return;
676 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
678 GEOMToolsGUI_LineWidthDlg* Dlg =
679 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
681 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
682 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
684 Dlg->setTheLW( aWidth );
686 SUIT_OverrideCursor wc;
687 aWidth = Dlg->getTheLW();
689 return; //Cancel case
690 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
691 Handle( SALOME_InteractiveObject ) io = It.Value();
692 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
693 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
695 displayer.UpdateViewer();
696 GeometryGUI::Modified();
700 void GEOMToolsGUI::OnIsosWidth() {
701 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
704 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
705 if ( !appStudy ) return;
707 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
708 if ( !aSelMgr ) return;
710 SALOME_ListIO selected;
711 aSelMgr->selectedObjects( selected );
712 if ( selected.IsEmpty() ) return;
714 GEOM_Displayer displayer( appStudy );
716 SALOME_View* window = displayer.GetActiveView();
717 if ( !window ) return;
719 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
721 GEOMToolsGUI_LineWidthDlg* Dlg =
722 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
724 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
725 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
727 Dlg->setTheLW( aWidth );
729 SUIT_OverrideCursor wc;
730 aWidth = Dlg->getTheLW();
732 return; //Cancel case
733 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
734 Handle( SALOME_InteractiveObject ) io = It.Value();
735 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
736 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
738 displayer.UpdateViewer();
739 GeometryGUI::Modified();
742 void GEOMToolsGUI::OnBringToFront() {
743 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
746 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());
747 if (!appStudy) return;
749 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
750 if ( !aSelMgr ) return;
752 SALOME_ListIO selected;
753 aSelMgr->selectedObjects( selected );
754 if ( selected.IsEmpty() ) return;
756 GEOM_Displayer displayer( appStudy );
758 SALOME_View* window = displayer.GetActiveView();
759 if ( !window ) return;
761 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
763 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
764 bool checked = a->isChecked();
766 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
767 Handle( SALOME_InteractiveObject ) io = It.Value();
768 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
769 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
771 displayer.UpdateViewer();
772 GeometryGUI::Modified();
775 void GEOMToolsGUI::OnClsBringToFront() {
776 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
779 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
780 if ( !appStudy ) return;
782 GEOM_Displayer displayer( appStudy );
784 SALOME_View* window = displayer.GetActiveView();
785 if ( !window ) return;
787 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
789 SALOME_ListIO anIOlst;
790 window->GetVisible( anIOlst );
792 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
793 Handle( SALOME_InteractiveObject ) io = It.Value();
794 appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
795 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
797 displayer.Redisplay( anIOlst );
798 displayer.UpdateViewer();
799 GeometryGUI::Modified();
802 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
804 if ( !theParam.canConvert<QString>() ) return;
806 QString theName = theParam.toString();
808 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
811 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
812 if ( !study ) return;
814 LightApp_SelectionMgr* selMgr = app->selectionMgr();
816 SALOME_ListIO selected;
817 selMgr->selectedObjects( selected );
819 if ( selected.IsEmpty() ) return;
821 GEOM_Displayer displayer( study );
823 SALOME_View* window = displayer.GetActiveView();
824 if ( !window ) return;
826 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
828 Material_Model aModel;
829 aModel.fromResources( theName );
830 QString prop = aModel.toProperties();
832 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
833 Handle(SALOME_InteractiveObject) io = It.Value();
834 study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
835 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
837 displayer.UpdateViewer();
840 void GEOMToolsGUI::OnCreateFolder()
842 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
845 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
846 if ( !appStudy ) return;
848 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
849 if ( !aSelMgr ) return;
851 SALOME_ListIO selected;
852 aSelMgr->selectedObjects( selected );
853 if ( selected.IsEmpty() ) return;
855 Handle(SALOME_InteractiveObject) anIObject = selected.First();
857 _PTR(Study) aStudy = appStudy->studyDS();
858 if( !aStudy ) return;
859 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
860 if ( !aFatherSO ) return;
862 GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(),
863 _CAST(SObject, aFatherSO)->GetSObject() );
864 app->updateObjectBrowser( false );
867 void GEOMToolsGUI::OnSortChildren()
869 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
872 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
873 if ( !appStudy ) return;
875 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
876 if ( !aSelMgr ) return;
878 SALOME_ListIO selected;
879 aSelMgr->selectedObjects( selected );
880 if ( selected.IsEmpty() ) return;
882 Handle(SALOME_InteractiveObject) anIObject = selected.First();
884 _PTR(Study) aStudy = appStudy->studyDS();
885 if( !aStudy ) return;
886 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
887 if ( !aFatherSO ) return;
889 aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
891 app->updateObjectBrowser( true );
894 #ifndef DISABLE_GRAPHICSVIEW
895 void GEOMToolsGUI::OnShowDependencyTree()
897 //SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
899 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
902 #ifdef LAYOUT_DEPVIEW
903 SUIT_ViewManager* occVm = app->getViewManager( OCCViewer_Viewer::Type(), true );
904 SUIT_ViewWindow* occVw = occVm->getActiveView();
906 SUIT_ViewManager* depVm = app->getViewManager( GraphicsView_Viewer::Type(), false );
907 SUIT_ViewWindow* depVw = 0;
910 DependencyTree_View* view = new DependencyTree_View();
911 DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
912 depVm = app->createViewManager( viewModel );
914 LightApp_SelectionMgr* selMgr = app->selectionMgr();
915 new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
917 depVw = depVm->getActiveView();
918 GraphicsView_ViewFrame* aViewFrame = 0;
919 if ( !depVw ) depVw = depVm->createViewWindow();
920 if ( depVw ) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( depVw );
922 view->init( aViewFrame );
923 depVm->setTitle( view->getViewName() );
925 else if ( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( depVm->getViewModel() ) ) {
926 if ( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
927 depVw = depVm->getActiveView();
932 #ifdef LAYOUT_DEPVIEW
933 // layout views properly
934 STD_TabDesktop* d = dynamic_cast<STD_TabDesktop*>( app->desktop() );
935 if ( d && depVw && occVw ) {
936 QtxWorkstack* ws = d->workstack();
938 QApplication::instance()->processEvents();
939 ws->Split( depVw, Qt::Horizontal, QtxWorkstack::SplitMove );
947 void GEOMToolsGUI::OnReduceStudy()
949 QDialog* dlg = new GEOMToolsGUI_ReduceStudyDlg( SUIT_Session::session()->activeApplication()->desktop() );