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 <Basics_OCCTVersion.hxx>
60 #include <SALOME_ListIO.hxx>
62 #include <SALOMEDS_SObject.hxx>
67 #include <SVTK_ViewModel.h>
68 #include <SVTK_ViewWindow.h>
69 #include <SVTK_View.h>
71 #include <OCCViewer_ViewModel.h>
73 #include <SUIT_ViewManager.h>
74 #include <SUIT_Desktop.h>
75 #include <SUIT_ResourceMgr.h>
76 #include <SUIT_Session.h>
77 #include <SUIT_OverrideCursor.h>
78 #include <SUIT_MessageBox.h>
79 #include <SUIT_Tools.h>
81 #include <STD_TabDesktop.h>
83 #include <QtxWorkstack.h>
85 #include <SalomeApp_Application.h>
86 #include <SalomeApp_Study.h>
87 #include <SalomeApp_Module.h>
89 #include <LightApp_SelectionMgr.h>
90 #include <LightApp_NameDlg.h>
92 #include <GEOMImpl_Types.hxx>
94 #include "utilities.h"
97 #include <Prs3d_IsoAspect.hxx>
98 #include <Prs3d_PointAspect.hxx>
99 #include <Graphic3d_AspectMarker3d.hxx>
100 #include <Graphic3d_AspectLine3d.hxx>
101 #include <AIS_ListIteratorOfListOfInteractive.hxx>
102 #include <AIS_ListOfInteractive.hxx>
104 #include <TColStd_HArray1OfByte.hxx>
108 #include <QApplication>
109 #include <QColorDialog>
110 #include <QInputDialog>
111 #include <QFileDialog>
114 #include <QGridLayout>
117 #include <QPushButton>
121 #include <vtkRenderer.h>
123 // If the next macro is defined, autocolor feature works for all sub-shapes;
124 // if it is undefined, autocolor feature works for groups only
125 #define GENERAL_AUTOCOLOR
126 // Below macro, when uncommented, switches on simplified (more performant) algorithm
127 // of auto-color picking up
128 #define SIMPLE_AUTOCOLOR
129 // Below macro, when defined, switches on automatic layouting of OCC and Dependecy views
130 // on Show Dependencies operation
131 #define LAYOUT_DEPVIEW
133 #ifndef DISABLE_PYCONSOLE
134 void GEOMToolsGUI::OnCheckGeometry()
136 SalomeApp_Application* app =
137 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
138 PyConsole_Console* pyConsole = app->pythonConsole();
141 pyConsole->exec("from GEOM_usinggeom import *");
145 void GEOMToolsGUI::OnAutoColor()
147 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
150 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
151 if ( !appStudy ) return;
153 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
154 if ( !aSelMgr ) return;
156 SALOME_ListIO selected;
157 aSelMgr->selectedObjects( selected );
158 if ( selected.IsEmpty() ) return;
160 Handle(SALOME_InteractiveObject) anIObject = selected.First();
162 _PTR(Study) aStudy = appStudy->studyDS();
163 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
164 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
165 if (CORBA::is_nil(aMainObject)) return;
167 aMainObject->SetAutoColor( true );
169 QList<SALOMEDS::Color> aReservedColors;
171 GEOM_Displayer displayer;
173 SALOME_View* window = displayer.GetActiveView();
174 if ( !window ) return;
176 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
178 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
180 _PTR(SObject) aChildSObject( it->Value() );
181 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
182 if( CORBA::is_nil( aChildObject ) )
185 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
186 if( aChildObject->GetType() != GEOM_GROUP )
188 #endif // GENERAL_AUTOCOLOR
190 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
191 SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
192 #else // old algorithm for auto-colors
193 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
194 aReservedColors.append( aColor );
195 #endif // SIMPLE_AUTOCOLOR
196 aChildObject->SetColor( aColor );
198 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
200 SUIT_OverrideCursor wc;
202 appStudy->setObjectProperty( aMgrId, aChildObject->GetStudyEntry(), GEOM::propertyName( GEOM::Color ), c );
203 Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject( aChildObject->GetStudyEntry(), "GEOM", "" );
204 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
206 displayer.UpdateViewer();
209 appStudy->Modified();
210 app->updateActions(); //SRN: To update a Save button in the toolbar
213 void GEOMToolsGUI::OnDisableAutoColor()
215 SALOME_ListIO selected;
216 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
220 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
221 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
222 if( !aSelMgr || !appStudy )
225 aSelMgr->selectedObjects( selected );
226 if( selected.IsEmpty() )
229 Handle(SALOME_InteractiveObject) anIObject = selected.First();
231 _PTR(Study) aStudy = appStudy->studyDS();
232 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
233 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
234 if( CORBA::is_nil( aMainObject ) )
237 aMainObject->SetAutoColor( false );
240 void GEOMToolsGUI::OnColor()
242 // get active application
243 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
247 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
248 if ( !appStudy ) return;
250 // get selection manager
251 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
252 if ( !aSelMgr ) return;
255 SALOME_ListIO selected;
256 aSelMgr->selectedObjects( selected );
257 if ( selected.IsEmpty() ) return;
259 GEOM_Displayer displayer;
262 SALOME_View* window = displayer.GetActiveView();
263 if ( !window ) return;
266 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
269 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
271 // show Choose Color dialog box
272 color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
273 if ( !color.isValid() ) return;
275 SALOMEDS::Color aSColor;
276 aSColor.R = (double)color.red() / 255.0;
277 aSColor.G = (double)color.green() / 255.0;
278 aSColor.B = (double)color.blue() / 255.0;
280 // iterate through list of objects and assign new color
281 SUIT_OverrideCursor wc;
282 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
283 Handle( SALOME_InteractiveObject ) io = It.Value();
284 GEOM::GEOM_Object_var aObject = GEOMBase::ConvertIOinGEOMObject( io );
285 if ( !CORBA::is_nil( aObject ) ) aObject->SetColor( aSColor );
286 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Color ), color );
287 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
289 displayer.UpdateViewer();
290 GeometryGUI::Modified();
293 app->updateActions(); //SRN: To update a Save button in the toolbar
296 void GEOMToolsGUI::OnTexture()
298 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
301 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
302 if ( !appStudy ) return;
304 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
305 if ( !aSelMgr ) return;
307 SALOME_ListIO selected;
308 aSelMgr->selectedObjects( selected );
309 if ( selected.IsEmpty() ) return;
311 GEOM_Displayer displayer;
312 SALOME_View* window = displayer.GetActiveView();
313 if ( !window ) return;
315 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
317 QString aTexture = QFileDialog::getOpenFileName( dynamic_cast< SUIT_ViewWindow* >( window ),tr("GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
318 if( !aTexture.isEmpty() ) {
319 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
320 Handle( SALOME_InteractiveObject ) io = It.Value();
321 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Texture ), aTexture );
322 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), 3 );
323 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
326 displayer.UpdateViewer();
327 GeometryGUI::Modified();
330 app->updateActions(); //SRN: To update a Save button in the toolbar
333 void GEOMToolsGUI::OnTransparency()
335 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
339 void GEOMToolsGUI::OnChangeTransparency( bool increase )
341 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
344 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
345 if( !appStudy) return;
347 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
348 if ( !aSelMgr ) return;
350 SALOME_ListIO selected;
351 aSelMgr->selectedObjects( selected );
352 if ( selected.IsEmpty() ) return;
354 GEOM_Displayer displayer;
355 SALOME_View* window = displayer.GetActiveView();
356 if ( !window ) return;
358 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
361 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
365 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Transparency ), QVariant() );
366 float transp = v.isValid() ? v.toFloat() : 1;
368 // Compute new transparency value
369 transp = transp + delta;
372 else if ( transp > 1 )
375 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
376 Handle( SALOME_InteractiveObject ) io = It.Value();
377 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::Transparency ), transp );
378 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
380 displayer.UpdateViewer();
381 GeometryGUI::Modified();
384 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
386 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
389 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
390 if ( !appStudy ) return;
392 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
393 if ( !aSelMgr ) return;
395 SALOME_ListIO selected;
396 aSelMgr->selectedObjects( selected );
397 if ( selected.IsEmpty() ) return;
399 GEOM_Displayer displayer;
400 SALOME_View* window = displayer.GetActiveView();
401 if ( !window ) return;
403 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
405 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::NbIsos ) , QVariant() );
406 QString aStr = v.toString();
407 QStringList aStrList = aStr.split( GEOM::subSectionSeparator() );
408 int UIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_u", 1 );
409 int VIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_v", 1 );
410 if ( aStrList.count() == 2 ) {
411 if ( !aStrList[0].isEmpty() ) UIso = aStrList[0].toInt();
412 if ( !aStrList[1].isEmpty() ) VIso = aStrList[1].toInt();
418 if ( actionType == SHOWDLG ) {
419 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
420 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
422 NbIsosDlg->setU( UIso );
423 NbIsosDlg->setV( VIso );
425 if ( NbIsosDlg->exec() ) {
426 SUIT_OverrideCursor wc;
427 newNbUIso = NbIsosDlg->getU();
428 newNbVIso = NbIsosDlg->getV();
432 else if ( actionType == INCR || actionType == DECR ) {
434 if (actionType == DECR)
437 newNbUIso = UIso + delta;
438 newNbVIso = VIso + delta;
440 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
444 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
445 Handle( SALOME_InteractiveObject ) io = It.Value();
446 QString anIsos = QString( "%1%2%3" ).arg( newNbUIso ).arg( GEOM::subSectionSeparator() ).arg( newNbVIso );
447 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos );
448 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
450 displayer.UpdateViewer();
451 GeometryGUI::Modified();
454 void GEOMToolsGUI::OnDeflection()
456 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
459 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
460 if ( !appStudy ) return;
462 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
463 if ( !aSelMgr ) return;
465 SALOME_ListIO selected;
466 aSelMgr->selectedObjects( selected );
467 if ( selected.IsEmpty() ) return;
469 GEOM_Displayer displayer;
470 SALOME_View* window = displayer.GetActiveView();
471 if ( !window ) return;
473 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
475 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
476 double aDC = v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
478 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
479 ( SUIT_Session::session()->activeApplication()->desktop() );
480 DeflectionDlg->setTheDC( aDC );
481 if ( DeflectionDlg->exec() ) {
482 SUIT_OverrideCursor wc;
483 aDC = DeflectionDlg->getTheDC();
485 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
486 Handle( SALOME_InteractiveObject ) io = It.Value();
487 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC );
488 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
491 displayer.UpdateViewer();
492 GeometryGUI::Modified();
495 void GEOMToolsGUI::OnSelectOnly(int mode)
497 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
499 GEOM_Displayer aDisp;
500 aDisp.GlobalSelection(mode);
501 getGeometryGUI()->setLocalSelectionMode(mode);
505 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
507 SALOME_ListIO selected;
508 SalomeApp_Application* app =
509 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
511 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
513 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
516 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
517 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
518 if ( aSelMgr && appStudy ) {
519 aSelMgr->selectedObjects( selected );
520 if ( !selected.IsEmpty() ) {
521 _PTR(Study) aStudy = appStudy->studyDS();
522 _PTR(StudyBuilder) B = aStudy->NewBuilder();
524 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
526 SUIT_MessageBox::warning( app->desktop(),
527 QObject::tr( "WRN_WARNING" ),
528 QObject::tr( "WRN_STUDY_LOCKED" ) );
532 SUIT_OverrideCursor wc;
533 disp->SetUpdateColorScale( false ); // IPAL54049
534 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
535 Handle(SALOME_InteractiveObject) IObject = It.Value();
537 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
538 _PTR(GenericAttribute) anAttr;
540 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
541 aExp->SetExpandable( show );
543 disp->EraseWithChildren(IObject,true);
547 disp->SetUpdateColorScale( true );
550 app->updateObjectBrowser( false );
551 app->updateActions();
555 void GEOMToolsGUI::OnPointMarker()
557 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
561 void GEOMToolsGUI::OnMaterialProperties()
563 GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
567 void GEOMToolsGUI::OnMaterialsLibrary()
569 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
570 dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
574 void GEOMToolsGUI::OnUnpublishObject() {
575 SALOME_ListIO selected;
576 SalomeApp_Application* app =
577 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
579 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
581 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
584 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
585 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
586 if ( aSelMgr && appStudy ) {
587 aSelMgr->selectedObjects( selected );
588 if ( !selected.IsEmpty() ) {
589 _PTR(Study) aStudy = appStudy->studyDS();
590 _PTR(StudyBuilder) B = aStudy->NewBuilder();
592 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
594 SUIT_MessageBox::warning( app->desktop(),
595 QObject::tr( "WRN_WARNING" ),
596 QObject::tr( "WRN_STUDY_LOCKED" ) );
599 SUIT_OverrideCursor wc;
600 disp->SetUpdateColorScale( false ); // IPAL54049
601 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
602 Handle(SALOME_InteractiveObject) IObject = It.Value();
604 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
605 _PTR(GenericAttribute) anAttr;
607 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
608 aDrw->SetDrawable( false );
609 disp->EraseWithChildren(IObject);
610 // hide references if any
611 std::vector< _PTR(SObject) > vso = aStudy->FindDependances(obj);
612 for ( int i = 0; i < vso.size(); i++ ) {
613 _PTR(SObject) refObj = vso[i];
614 aDrw = B->FindOrCreateAttribute( refObj, "AttributeDrawable" );
615 aDrw->SetDrawable( false );
619 disp->SetUpdateColorScale( true ); // IPAL54049
620 aSelMgr->clearSelected();
623 app->updateObjectBrowser( false );
624 app->updateActions();
629 void GEOMToolsGUI::OnPublishObject() {
630 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
634 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
638 _PTR(Study) aStudy = appStudy->studyDS();
643 //Check lock of the study
644 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
646 SUIT_MessageBox::warning( app->desktop(),
647 QObject::tr( "WRN_WARNING" ),
648 QObject::tr( "WRN_STUDY_LOCKED" ) );
652 GEOMToolsGUI_PublishDlg* publishDlg =
653 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
658 void GEOMToolsGUI::OnEdgeWidth()
660 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
663 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
664 if ( !appStudy ) return;
666 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
667 if ( !aSelMgr ) return;
669 SALOME_ListIO selected;
670 aSelMgr->selectedObjects( selected );
671 if ( selected.IsEmpty() ) return;
673 GEOM_Displayer displayer;
675 SALOME_View* window = displayer.GetActiveView();
676 if ( !window ) return;
678 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
680 GEOMToolsGUI_LineWidthDlg* Dlg =
681 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
683 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
684 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
686 Dlg->setTheLW( aWidth );
688 SUIT_OverrideCursor wc;
689 aWidth = Dlg->getTheLW();
691 return; //Cancel case
692 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
693 Handle( SALOME_InteractiveObject ) io = It.Value();
694 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
695 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
697 displayer.UpdateViewer();
698 GeometryGUI::Modified();
702 void GEOMToolsGUI::OnIsosWidth() {
703 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
706 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
707 if ( !appStudy ) return;
709 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
710 if ( !aSelMgr ) return;
712 SALOME_ListIO selected;
713 aSelMgr->selectedObjects( selected );
714 if ( selected.IsEmpty() ) return;
716 GEOM_Displayer displayer;
718 SALOME_View* window = displayer.GetActiveView();
719 if ( !window ) return;
721 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
723 GEOMToolsGUI_LineWidthDlg* Dlg =
724 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
726 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
727 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
729 Dlg->setTheLW( aWidth );
731 SUIT_OverrideCursor wc;
732 aWidth = Dlg->getTheLW();
734 return; //Cancel case
735 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
736 Handle( SALOME_InteractiveObject ) io = It.Value();
737 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
738 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
740 displayer.UpdateViewer();
741 GeometryGUI::Modified();
744 void GEOMToolsGUI::OnBringToFront() {
745 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
748 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());
749 if (!appStudy) return;
751 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
752 if ( !aSelMgr ) return;
754 SALOME_ListIO selected;
755 aSelMgr->selectedObjects( selected );
756 if ( selected.IsEmpty() ) return;
758 GEOM_Displayer displayer;
760 SALOME_View* window = displayer.GetActiveView();
761 if ( !window ) return;
763 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
765 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
766 bool checked = a->isChecked();
768 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
769 Handle( SALOME_InteractiveObject ) io = It.Value();
770 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
771 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
773 displayer.UpdateViewer();
774 GeometryGUI::Modified();
777 void GEOMToolsGUI::OnClsBringToFront() {
778 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
781 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
782 if ( !appStudy ) return;
784 GEOM_Displayer displayer;
786 SALOME_View* window = displayer.GetActiveView();
787 if ( !window ) return;
789 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
791 SALOME_ListIO anIOlst;
792 window->GetVisible( anIOlst );
794 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
795 Handle( SALOME_InteractiveObject ) io = It.Value();
796 appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
797 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
799 displayer.Redisplay( anIOlst );
800 displayer.UpdateViewer();
801 GeometryGUI::Modified();
804 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
806 if ( !theParam.canConvert<QString>() ) return;
808 QString theName = theParam.toString();
810 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
813 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
814 if ( !study ) return;
816 LightApp_SelectionMgr* selMgr = app->selectionMgr();
818 SALOME_ListIO selected;
819 selMgr->selectedObjects( selected );
821 if ( selected.IsEmpty() ) return;
823 GEOM_Displayer displayer;
825 SALOME_View* window = displayer.GetActiveView();
826 if ( !window ) return;
828 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
830 Material_Model aModel;
831 aModel.fromResources( theName );
832 QString prop = aModel.toProperties();
834 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
835 Handle(SALOME_InteractiveObject) io = It.Value();
836 study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
837 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
839 displayer.UpdateViewer();
842 void GEOMToolsGUI::OnCreateFolder()
844 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
847 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
848 if ( !appStudy ) return;
850 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
851 if ( !aSelMgr ) return;
853 SALOME_ListIO selected;
854 aSelMgr->selectedObjects( selected );
855 if ( selected.IsEmpty() ) return;
857 Handle(SALOME_InteractiveObject) anIObject = selected.First();
859 _PTR(Study) aStudy = appStudy->studyDS();
860 if( !aStudy ) return;
861 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
862 if ( !aFatherSO ) return;
864 GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(),
865 _CAST(SObject, aFatherSO)->GetSObject() );
866 app->updateObjectBrowser( false );
869 void GEOMToolsGUI::OnSortChildren()
871 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
874 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
875 if ( !appStudy ) return;
877 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
878 if ( !aSelMgr ) return;
880 SALOME_ListIO selected;
881 aSelMgr->selectedObjects( selected );
882 if ( selected.IsEmpty() ) return;
884 Handle(SALOME_InteractiveObject) anIObject = selected.First();
886 _PTR(Study) aStudy = appStudy->studyDS();
887 if( !aStudy ) return;
888 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
889 if ( !aFatherSO ) return;
891 aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
893 app->updateObjectBrowser( true );
896 #ifndef DISABLE_GRAPHICSVIEW
897 void GEOMToolsGUI::OnShowDependencyTree()
899 //SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
901 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
904 #ifdef LAYOUT_DEPVIEW
905 SUIT_ViewManager* occVm = app->getViewManager( OCCViewer_Viewer::Type(), true );
906 SUIT_ViewWindow* occVw = occVm->getActiveView();
908 SUIT_ViewManager* depVm = app->getViewManager( GraphicsView_Viewer::Type(), false );
909 SUIT_ViewWindow* depVw = 0;
912 DependencyTree_View* view = new DependencyTree_View();
913 DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
914 depVm = app->createViewManager( viewModel );
916 LightApp_SelectionMgr* selMgr = app->selectionMgr();
917 new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
919 depVw = depVm->getActiveView();
920 GraphicsView_ViewFrame* aViewFrame = 0;
921 if ( !depVw ) depVw = depVm->createViewWindow();
922 if ( depVw ) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( depVw );
924 view->init( aViewFrame );
925 depVm->setTitle( view->getViewName() );
927 else if ( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( depVm->getViewModel() ) ) {
928 if ( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
929 depVw = depVm->getActiveView();
934 #ifdef LAYOUT_DEPVIEW
935 // layout views properly
936 STD_TabDesktop* d = dynamic_cast<STD_TabDesktop*>( app->desktop() );
937 if ( d && depVw && occVw ) {
938 QtxWorkstack* ws = d->workstack();
940 QApplication::instance()->processEvents();
941 ws->Split( depVw, Qt::Horizontal, QtxWorkstack::SplitMove );
949 void GEOMToolsGUI::OnReduceStudy()
951 QDialog* dlg = new GEOMToolsGUI_ReduceStudyDlg( SUIT_Session::session()->activeApplication()->desktop() );