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 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( true );
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 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( true ); // IPAL54049
619 aSelMgr->clearSelected();
622 app->updateObjectBrowser( false );
623 app->updateActions();
628 void GEOMToolsGUI::OnPublishObject() {
629 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
633 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
637 _PTR(Study) aStudy = appStudy->studyDS();
642 //Check lock of the study
643 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
645 SUIT_MessageBox::warning( app->desktop(),
646 QObject::tr( "WRN_WARNING" ),
647 QObject::tr( "WRN_STUDY_LOCKED" ) );
651 GEOMToolsGUI_PublishDlg* publishDlg =
652 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
657 void GEOMToolsGUI::OnEdgeWidth()
659 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
662 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
663 if ( !appStudy ) return;
665 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
666 if ( !aSelMgr ) return;
668 SALOME_ListIO selected;
669 aSelMgr->selectedObjects( selected );
670 if ( selected.IsEmpty() ) return;
672 GEOM_Displayer displayer( appStudy );
674 SALOME_View* window = displayer.GetActiveView();
675 if ( !window ) return;
677 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
679 GEOMToolsGUI_LineWidthDlg* Dlg =
680 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
682 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
683 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
685 Dlg->setTheLW( aWidth );
687 SUIT_OverrideCursor wc;
688 aWidth = Dlg->getTheLW();
690 return; //Cancel case
691 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
692 Handle( SALOME_InteractiveObject ) io = It.Value();
693 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
694 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
696 displayer.UpdateViewer();
697 GeometryGUI::Modified();
701 void GEOMToolsGUI::OnIsosWidth() {
702 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
705 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
706 if ( !appStudy ) return;
708 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
709 if ( !aSelMgr ) return;
711 SALOME_ListIO selected;
712 aSelMgr->selectedObjects( selected );
713 if ( selected.IsEmpty() ) return;
715 GEOM_Displayer displayer( appStudy );
717 SALOME_View* window = displayer.GetActiveView();
718 if ( !window ) return;
720 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
722 GEOMToolsGUI_LineWidthDlg* Dlg =
723 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
725 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
726 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
728 Dlg->setTheLW( aWidth );
730 SUIT_OverrideCursor wc;
731 aWidth = Dlg->getTheLW();
733 return; //Cancel case
734 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
735 Handle( SALOME_InteractiveObject ) io = It.Value();
736 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
737 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
739 displayer.UpdateViewer();
740 GeometryGUI::Modified();
743 void GEOMToolsGUI::OnBringToFront() {
744 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
747 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());
748 if (!appStudy) return;
750 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
751 if ( !aSelMgr ) return;
753 SALOME_ListIO selected;
754 aSelMgr->selectedObjects( selected );
755 if ( selected.IsEmpty() ) return;
757 GEOM_Displayer displayer( appStudy );
759 SALOME_View* window = displayer.GetActiveView();
760 if ( !window ) return;
762 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
764 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
765 bool checked = a->isChecked();
767 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
768 Handle( SALOME_InteractiveObject ) io = It.Value();
769 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
770 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
772 displayer.UpdateViewer();
773 GeometryGUI::Modified();
776 void GEOMToolsGUI::OnClsBringToFront() {
777 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
780 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
781 if ( !appStudy ) return;
783 GEOM_Displayer displayer( appStudy );
785 SALOME_View* window = displayer.GetActiveView();
786 if ( !window ) return;
788 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
790 SALOME_ListIO anIOlst;
791 window->GetVisible( anIOlst );
793 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
794 Handle( SALOME_InteractiveObject ) io = It.Value();
795 appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
796 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
798 displayer.Redisplay( anIOlst );
799 displayer.UpdateViewer();
800 GeometryGUI::Modified();
803 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
805 if ( !theParam.canConvert<QString>() ) return;
807 QString theName = theParam.toString();
809 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
812 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
813 if ( !study ) return;
815 LightApp_SelectionMgr* selMgr = app->selectionMgr();
817 SALOME_ListIO selected;
818 selMgr->selectedObjects( selected );
820 if ( selected.IsEmpty() ) return;
822 GEOM_Displayer displayer( study );
824 SALOME_View* window = displayer.GetActiveView();
825 if ( !window ) return;
827 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
829 Material_Model aModel;
830 aModel.fromResources( theName );
831 QString prop = aModel.toProperties();
833 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
834 Handle(SALOME_InteractiveObject) io = It.Value();
835 study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
836 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
838 displayer.UpdateViewer();
841 void GEOMToolsGUI::OnCreateFolder()
843 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
846 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
847 if ( !appStudy ) return;
849 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
850 if ( !aSelMgr ) return;
852 SALOME_ListIO selected;
853 aSelMgr->selectedObjects( selected );
854 if ( selected.IsEmpty() ) return;
856 Handle(SALOME_InteractiveObject) anIObject = selected.First();
858 _PTR(Study) aStudy = appStudy->studyDS();
859 if( !aStudy ) return;
860 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
861 if ( !aFatherSO ) return;
863 GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(),
864 _CAST(SObject, aFatherSO)->GetSObject() );
865 app->updateObjectBrowser( false );
868 void GEOMToolsGUI::OnSortChildren()
870 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
873 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
874 if ( !appStudy ) return;
876 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
877 if ( !aSelMgr ) return;
879 SALOME_ListIO selected;
880 aSelMgr->selectedObjects( selected );
881 if ( selected.IsEmpty() ) return;
883 Handle(SALOME_InteractiveObject) anIObject = selected.First();
885 _PTR(Study) aStudy = appStudy->studyDS();
886 if( !aStudy ) return;
887 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
888 if ( !aFatherSO ) return;
890 aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
892 app->updateObjectBrowser( true );
895 #ifndef DISABLE_GRAPHICSVIEW
896 void GEOMToolsGUI::OnShowDependencyTree()
898 //SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
900 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
903 #ifdef LAYOUT_DEPVIEW
904 SUIT_ViewManager* occVm = app->getViewManager( OCCViewer_Viewer::Type(), true );
905 SUIT_ViewWindow* occVw = occVm->getActiveView();
907 SUIT_ViewManager* depVm = app->getViewManager( GraphicsView_Viewer::Type(), false );
908 SUIT_ViewWindow* depVw = 0;
911 DependencyTree_View* view = new DependencyTree_View();
912 DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
913 depVm = app->createViewManager( viewModel );
915 LightApp_SelectionMgr* selMgr = app->selectionMgr();
916 new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
918 depVw = depVm->getActiveView();
919 GraphicsView_ViewFrame* aViewFrame = 0;
920 if ( !depVw ) depVw = depVm->createViewWindow();
921 if ( depVw ) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( depVw );
923 view->init( aViewFrame );
924 depVm->setTitle( view->getViewName() );
926 else if ( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( depVm->getViewModel() ) ) {
927 if ( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
928 depVw = depVm->getActiveView();
933 #ifdef LAYOUT_DEPVIEW
934 // layout views properly
935 STD_TabDesktop* d = dynamic_cast<STD_TabDesktop*>( app->desktop() );
936 if ( d && depVw && occVw ) {
937 QtxWorkstack* ws = d->workstack();
939 QApplication::instance()->processEvents();
940 ws->Split( depVw, Qt::Horizontal, QtxWorkstack::SplitMove );
948 void GEOMToolsGUI::OnReduceStudy()
950 QDialog* dlg = new GEOMToolsGUI_ReduceStudyDlg( SUIT_Session::session()->activeApplication()->desktop() );