1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOMToolsGUI_1.cxx
25 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
27 #include <PyConsole_Console.h>
29 #include "GEOMToolsGUI.h"
30 #include "GEOMToolsGUI_TransparencyDlg.h"
31 #include "GEOMToolsGUI_NbIsosDlg.h"
32 #include "GEOMToolsGUI_DeflectionDlg.h"
33 #include "GEOMToolsGUI_MarkerDlg.h"
34 #include "GEOMToolsGUI_PublishDlg.h"
35 #include "GEOMToolsGUI_MaterialPropertiesDlg.h"
36 #include "GEOMToolsGUI_LineWidthDlg.h"
37 #include "GEOMToolsGUI_ReduceStudyDlg.h"
38 #include <Material_Model.h>
40 #include <GEOM_VTKPropertyMaterial.hxx>
42 #include <GeometryGUI.h>
43 #include <GeometryGUI_Operations.h>
44 #include <GEOM_Constants.h>
45 #include <GEOM_Displayer.h>
48 #include <GEOM_Actor.h>
50 #include <DependencyTree_ViewModel.h>
51 #include <DependencyTree_View.h>
52 #include <DependencyTree_Selector.h>
54 #include <Basics_OCCTVersion.hxx>
56 #include <SALOME_ListIO.hxx>
58 #include <SALOMEDS_SObject.hxx>
63 #include <SVTK_ViewModel.h>
64 #include <SVTK_ViewWindow.h>
65 #include <SVTK_View.h>
67 #include <OCCViewer_ViewModel.h>
69 #include <SUIT_ViewManager.h>
70 #include <SUIT_Desktop.h>
71 #include <SUIT_ResourceMgr.h>
72 #include <SUIT_Session.h>
73 #include <SUIT_OverrideCursor.h>
74 #include <SUIT_MessageBox.h>
75 #include <SUIT_Tools.h>
77 #include <STD_TabDesktop.h>
79 #include <QtxWorkstack.h>
81 #include <SalomeApp_Application.h>
82 #include <SalomeApp_Study.h>
83 #include <SalomeApp_Module.h>
85 #include <LightApp_SelectionMgr.h>
86 #include <LightApp_NameDlg.h>
88 #include <GEOMImpl_Types.hxx>
90 #include "utilities.h"
93 #include <AIS_Drawer.hxx>
94 #include <Prs3d_IsoAspect.hxx>
95 #include <Prs3d_PointAspect.hxx>
96 #include <Graphic3d_AspectMarker3d.hxx>
97 #include <Graphic3d_AspectLine3d.hxx>
98 #include <AIS_ListIteratorOfListOfInteractive.hxx>
99 #include <AIS_ListOfInteractive.hxx>
101 #include <TColStd_HArray1OfByte.hxx>
105 #include <QApplication>
106 #include <QColorDialog>
107 #include <QInputDialog>
108 #include <QFileDialog>
111 #include <QGridLayout>
114 #include <QPushButton>
118 #include <vtkRenderer.h>
120 // If the next macro is defined, autocolor feature works for all sub-shapes;
121 // if it is undefined, autocolor feature works for groups only
122 #define GENERAL_AUTOCOLOR
123 // Below macro, when uncommented, switches on simplified (more performant) algorithm
124 // of auto-color picking up
125 #define SIMPLE_AUTOCOLOR
126 // Below macro, when defined, switches on automatic layouting of OCC and Dependecy views
127 // on Show Dependencies operation
128 #define LAYOUT_DEPVIEW
130 void GEOMToolsGUI::OnCheckGeometry()
132 SalomeApp_Application* app =
133 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
134 PyConsole_Console* pyConsole = app->pythonConsole();
137 pyConsole->exec("from GEOM_usinggeom import *");
140 void GEOMToolsGUI::OnAutoColor()
142 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
145 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
146 if ( !appStudy ) return;
148 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
149 if ( !aSelMgr ) return;
151 SALOME_ListIO selected;
152 aSelMgr->selectedObjects( selected );
153 if ( selected.IsEmpty() ) return;
155 Handle(SALOME_InteractiveObject) anIObject = selected.First();
157 _PTR(Study) aStudy = appStudy->studyDS();
158 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
159 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
160 if (CORBA::is_nil(aMainObject)) return;
162 aMainObject->SetAutoColor( true );
164 QList<SALOMEDS::Color> aReservedColors;
166 GEOM_Displayer displayer ( appStudy );
168 SALOME_View* window = displayer.GetActiveView();
169 if ( !window ) return;
171 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
173 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
175 _PTR(SObject) aChildSObject( it->Value() );
176 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
177 if( CORBA::is_nil( aChildObject ) )
180 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
181 if( aChildObject->GetType() != GEOM_GROUP )
183 #endif // GENERAL_AUTOCOLOR
185 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
186 SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
187 #else // old algorithm for auto-colors
188 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
189 aReservedColors.append( aColor );
190 #endif // SIMPLE_AUTOCOLOR
191 aChildObject->SetColor( aColor );
193 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
195 SUIT_OverrideCursor();
197 appStudy->setObjectProperty( aMgrId, aChildObject->GetStudyEntry(), GEOM::propertyName( GEOM::Color ), c );
198 Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject( aChildObject->GetStudyEntry(), "GEOM", "" );
199 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
201 displayer.UpdateViewer();
204 appStudy->Modified();
205 app->updateActions(); //SRN: To update a Save button in the toolbar
208 void GEOMToolsGUI::OnDisableAutoColor()
210 SALOME_ListIO selected;
211 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
215 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
216 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
217 if( !aSelMgr || !appStudy )
220 aSelMgr->selectedObjects( selected );
221 if( selected.IsEmpty() )
224 Handle(SALOME_InteractiveObject) anIObject = selected.First();
226 _PTR(Study) aStudy = appStudy->studyDS();
227 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
228 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
229 if( CORBA::is_nil( aMainObject ) )
232 aMainObject->SetAutoColor( false );
235 void GEOMToolsGUI::OnColor()
237 // get active application
238 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
242 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
243 if ( !appStudy ) return;
245 // get selection manager
246 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
247 if ( !aSelMgr ) return;
250 SALOME_ListIO selected;
251 aSelMgr->selectedObjects( selected );
252 if ( selected.IsEmpty() ) return;
254 GEOM_Displayer displayer( appStudy );
257 SALOME_View* window = displayer.GetActiveView();
258 if ( !window ) return;
261 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
264 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
266 // show Choose Color dialog box
267 color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
268 if ( !color.isValid() ) return;
270 SALOMEDS::Color aSColor;
271 aSColor.R = (double)color.red() / 255.0;
272 aSColor.G = (double)color.green() / 255.0;
273 aSColor.B = (double)color.blue() / 255.0;
275 // iterate through list of objects and assign new color
276 SUIT_OverrideCursor();
277 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
278 Handle( SALOME_InteractiveObject ) io = It.Value();
279 GEOM::GEOM_Object_var aObject = GEOMBase::ConvertIOinGEOMObject( io );
280 if ( !CORBA::is_nil( aObject ) ) aObject->SetColor( aSColor );
281 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Color ), color );
282 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
284 displayer.UpdateViewer();
285 GeometryGUI::Modified();
288 app->updateActions(); //SRN: To update a Save button in the toolbar
291 void GEOMToolsGUI::OnTexture()
293 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
296 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
297 if ( !appStudy ) return;
299 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
300 if ( !aSelMgr ) return;
302 SALOME_ListIO selected;
303 aSelMgr->selectedObjects( selected );
304 if ( selected.IsEmpty() ) return;
306 GEOM_Displayer displayer( appStudy );
307 SALOME_View* window = displayer.GetActiveView();
308 if ( !window ) return;
310 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
312 QString aTexture = QFileDialog::getOpenFileName( dynamic_cast< SUIT_ViewWindow* >( window ),tr("GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
313 if( !aTexture.isEmpty() ) {
314 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
315 Handle( SALOME_InteractiveObject ) io = It.Value();
316 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Texture ), aTexture );
317 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), 3 );
318 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
321 displayer.UpdateViewer();
322 GeometryGUI::Modified();
325 app->updateActions(); //SRN: To update a Save button in the toolbar
328 void GEOMToolsGUI::OnTransparency()
330 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
334 void GEOMToolsGUI::OnChangeTransparency( bool increase )
336 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
339 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
340 if( !appStudy) return;
342 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
343 if ( !aSelMgr ) return;
345 SALOME_ListIO selected;
346 aSelMgr->selectedObjects( selected );
347 if ( selected.IsEmpty() ) return;
349 GEOM_Displayer displayer( appStudy );
350 SALOME_View* window = displayer.GetActiveView();
351 if ( !window ) return;
353 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
356 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
360 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Transparency ), QVariant() );
361 float transp = v.isValid() ? v.toFloat() : 1;
363 // Compute new transparency value
364 transp = transp + delta;
367 else if ( transp > 1 )
370 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
371 Handle( SALOME_InteractiveObject ) io = It.Value();
372 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::Transparency ), transp );
373 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
375 displayer.UpdateViewer();
376 GeometryGUI::Modified();
379 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
381 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
384 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
385 if ( !appStudy ) return;
387 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
388 if ( !aSelMgr ) return;
390 SALOME_ListIO selected;
391 aSelMgr->selectedObjects( selected );
392 if ( selected.IsEmpty() ) return;
394 GEOM_Displayer displayer( appStudy );
395 SALOME_View* window = displayer.GetActiveView();
396 if ( !window ) return;
398 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
400 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::NbIsos ) , QVariant() );
401 QString aStr = v.toString();
402 QStringList aStrList = aStr.split( GEOM::subSectionSeparator() );
403 int UIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_u", 1 );
404 int VIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_v", 1 );
405 if ( aStrList.count() == 2 ) {
406 if ( !aStrList[0].isEmpty() ) UIso = aStrList[0].toInt();
407 if ( !aStrList[1].isEmpty() ) VIso = aStrList[1].toInt();
413 if ( actionType == SHOWDLG ) {
414 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
415 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
417 NbIsosDlg->setU( UIso );
418 NbIsosDlg->setV( VIso );
420 if ( NbIsosDlg->exec() ) {
421 SUIT_OverrideCursor();
422 newNbUIso = NbIsosDlg->getU();
423 newNbVIso = NbIsosDlg->getV();
427 else if ( actionType == INCR || actionType == DECR ) {
429 if (actionType == DECR)
432 newNbUIso = UIso + delta;
433 newNbVIso = VIso + delta;
435 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
439 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
440 Handle( SALOME_InteractiveObject ) io = It.Value();
441 QString anIsos = QString( "%1%2%3" ).arg( newNbUIso ).arg( GEOM::subSectionSeparator() ).arg( newNbVIso );
442 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos );
443 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
445 displayer.UpdateViewer();
446 GeometryGUI::Modified();
449 void GEOMToolsGUI::OnDeflection()
451 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
454 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
455 if ( !appStudy ) return;
457 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
458 if ( !aSelMgr ) return;
460 SALOME_ListIO selected;
461 aSelMgr->selectedObjects( selected );
462 if ( selected.IsEmpty() ) return;
464 GEOM_Displayer displayer( appStudy );
465 SALOME_View* window = displayer.GetActiveView();
466 if ( !window ) return;
468 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
470 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
471 double aDC = v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
473 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
474 ( SUIT_Session::session()->activeApplication()->desktop() );
475 DeflectionDlg->setTheDC( aDC );
476 if ( DeflectionDlg->exec() ) {
477 SUIT_OverrideCursor();
478 aDC = DeflectionDlg->getTheDC();
480 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
481 Handle( SALOME_InteractiveObject ) io = It.Value();
482 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC );
483 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
486 displayer.UpdateViewer();
487 GeometryGUI::Modified();
490 void GEOMToolsGUI::OnSelectOnly(int mode)
492 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
494 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
495 GEOM_Displayer aDisp (appStudy);
496 aDisp.GlobalSelection(mode);
497 getGeometryGUI()->setLocalSelectionMode(mode);
501 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
503 SALOME_ListIO selected;
504 SalomeApp_Application* app =
505 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
507 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
509 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
512 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
513 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
514 if ( aSelMgr && appStudy ) {
515 aSelMgr->selectedObjects( selected );
516 if ( !selected.IsEmpty() ) {
517 _PTR(Study) aStudy = appStudy->studyDS();
518 _PTR(StudyBuilder) B = aStudy->NewBuilder();
520 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
522 SUIT_MessageBox::warning( app->desktop(),
523 QObject::tr( "WRN_WARNING" ),
524 QObject::tr( "WRN_STUDY_LOCKED" ) );
528 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
529 Handle(SALOME_InteractiveObject) IObject = It.Value();
531 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
532 _PTR(GenericAttribute) anAttr;
534 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
535 aExp->SetExpandable( show );
537 disp->EraseWithChildren(IObject,true);
542 app->updateObjectBrowser( false );
543 app->updateActions();
547 void GEOMToolsGUI::OnPointMarker()
549 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
553 void GEOMToolsGUI::OnMaterialProperties()
555 GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
559 void GEOMToolsGUI::OnMaterialsLibrary()
561 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
562 dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
566 void GEOMToolsGUI::OnUnpublishObject() {
567 SALOME_ListIO selected;
568 SalomeApp_Application* app =
569 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
571 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
573 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
576 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
577 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
578 if ( aSelMgr && appStudy ) {
579 aSelMgr->selectedObjects( selected );
580 if ( !selected.IsEmpty() ) {
581 _PTR(Study) aStudy = appStudy->studyDS();
582 _PTR(StudyBuilder) B = aStudy->NewBuilder();
584 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
586 SUIT_MessageBox::warning( app->desktop(),
587 QObject::tr( "WRN_WARNING" ),
588 QObject::tr( "WRN_STUDY_LOCKED" ) );
592 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
593 Handle(SALOME_InteractiveObject) IObject = It.Value();
595 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
596 _PTR(GenericAttribute) anAttr;
598 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
599 aDrw->SetDrawable( false );
600 disp->EraseWithChildren(IObject);
601 // hide references if any
602 std::vector< _PTR(SObject) > vso = aStudy->FindDependances(obj);
603 for ( int i = 0; i < vso.size(); i++ ) {
604 _PTR(SObject) refObj = vso[i];
605 aDrw = B->FindOrCreateAttribute( refObj, "AttributeDrawable" );
606 aDrw->SetDrawable( false );
610 aSelMgr->clearSelected();
613 app->updateObjectBrowser( false );
614 app->updateActions();
619 void GEOMToolsGUI::OnPublishObject() {
620 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
624 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
628 _PTR(Study) aStudy = appStudy->studyDS();
633 //Check lock of the study
634 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
636 SUIT_MessageBox::warning( app->desktop(),
637 QObject::tr( "WRN_WARNING" ),
638 QObject::tr( "WRN_STUDY_LOCKED" ) );
642 GEOMToolsGUI_PublishDlg* publishDlg =
643 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
648 void GEOMToolsGUI::OnEdgeWidth()
650 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
653 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
654 if ( !appStudy ) return;
656 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
657 if ( !aSelMgr ) return;
659 SALOME_ListIO selected;
660 aSelMgr->selectedObjects( selected );
661 if ( selected.IsEmpty() ) return;
663 GEOM_Displayer displayer( appStudy );
665 SALOME_View* window = displayer.GetActiveView();
666 if ( !window ) return;
668 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
670 GEOMToolsGUI_LineWidthDlg* Dlg =
671 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
673 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
674 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
676 Dlg->setTheLW( aWidth );
678 SUIT_OverrideCursor();
679 aWidth = Dlg->getTheLW();
681 return; //Cancel case
682 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
683 Handle( SALOME_InteractiveObject ) io = It.Value();
684 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
685 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
687 displayer.UpdateViewer();
688 GeometryGUI::Modified();
692 void GEOMToolsGUI::OnIsosWidth() {
693 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
696 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
697 if ( !appStudy ) return;
699 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
700 if ( !aSelMgr ) return;
702 SALOME_ListIO selected;
703 aSelMgr->selectedObjects( selected );
704 if ( selected.IsEmpty() ) return;
706 GEOM_Displayer displayer( appStudy );
708 SALOME_View* window = displayer.GetActiveView();
709 if ( !window ) return;
711 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
713 GEOMToolsGUI_LineWidthDlg* Dlg =
714 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
716 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
717 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
719 Dlg->setTheLW( aWidth );
721 SUIT_OverrideCursor();
722 aWidth = Dlg->getTheLW();
724 return; //Cancel case
725 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
726 Handle( SALOME_InteractiveObject ) io = It.Value();
727 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
728 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
730 displayer.UpdateViewer();
731 GeometryGUI::Modified();
734 void GEOMToolsGUI::OnBringToFront() {
735 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
738 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());
739 if (!appStudy) return;
741 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
742 if ( !aSelMgr ) return;
744 SALOME_ListIO selected;
745 aSelMgr->selectedObjects( selected );
746 if ( selected.IsEmpty() ) return;
748 GEOM_Displayer displayer( appStudy );
750 SALOME_View* window = displayer.GetActiveView();
751 if ( !window ) return;
753 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
755 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
756 bool checked = a->isChecked();
758 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
759 Handle( SALOME_InteractiveObject ) io = It.Value();
760 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
761 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
763 displayer.UpdateViewer();
764 GeometryGUI::Modified();
767 void GEOMToolsGUI::OnClsBringToFront() {
768 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
771 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
772 if ( !appStudy ) return;
774 GEOM_Displayer displayer( appStudy );
776 SALOME_View* window = displayer.GetActiveView();
777 if ( !window ) return;
779 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
781 SALOME_ListIO anIOlst;
782 window->GetVisible( anIOlst );
784 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
785 Handle( SALOME_InteractiveObject ) io = It.Value();
786 appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
787 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
789 displayer.Redisplay( anIOlst );
790 displayer.UpdateViewer();
791 GeometryGUI::Modified();
794 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
796 if ( !theParam.canConvert<QString>() ) return;
798 QString theName = theParam.toString();
800 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
803 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
804 if ( !study ) return;
806 LightApp_SelectionMgr* selMgr = app->selectionMgr();
808 SALOME_ListIO selected;
809 selMgr->selectedObjects( selected );
811 if ( selected.IsEmpty() ) return;
813 GEOM_Displayer displayer( study );
815 SALOME_View* window = displayer.GetActiveView();
816 if ( !window ) return;
818 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
820 Material_Model aModel;
821 aModel.fromResources( theName );
822 QString prop = aModel.toProperties();
824 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
825 Handle(SALOME_InteractiveObject) io = It.Value();
826 study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
827 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
829 displayer.UpdateViewer();
832 void GEOMToolsGUI::OnCreateFolder()
834 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
837 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
838 if ( !appStudy ) return;
840 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
841 if ( !aSelMgr ) return;
843 SALOME_ListIO selected;
844 aSelMgr->selectedObjects( selected );
845 if ( selected.IsEmpty() ) return;
847 Handle(SALOME_InteractiveObject) anIObject = selected.First();
849 _PTR(Study) aStudy = appStudy->studyDS();
850 if( !aStudy ) return;
851 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
852 if ( !aFatherSO ) return;
854 GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(),
855 _CAST(SObject, aFatherSO)->GetSObject() );
856 app->updateObjectBrowser( false );
859 void GEOMToolsGUI::OnSortChildren()
861 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
864 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
865 if ( !appStudy ) return;
867 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
868 if ( !aSelMgr ) return;
870 SALOME_ListIO selected;
871 aSelMgr->selectedObjects( selected );
872 if ( selected.IsEmpty() ) return;
874 Handle(SALOME_InteractiveObject) anIObject = selected.First();
876 _PTR(Study) aStudy = appStudy->studyDS();
877 if( !aStudy ) return;
878 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
879 if ( !aFatherSO ) return;
881 aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
883 app->updateObjectBrowser( true );
886 void GEOMToolsGUI::OnShowDependencyTree()
888 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
890 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
893 #ifdef LAYOUT_DEPVIEW
894 SUIT_ViewManager* occVm = app->getViewManager( OCCViewer_Viewer::Type(), true );
895 SUIT_ViewWindow* occVw = occVm->getActiveView();
897 SUIT_ViewManager* depVm = app->getViewManager( GraphicsView_Viewer::Type(), false );
898 SUIT_ViewWindow* depVw = 0;
901 DependencyTree_View* view = new DependencyTree_View();
902 DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
903 depVm = app->createViewManager( viewModel );
905 LightApp_SelectionMgr* selMgr = app->selectionMgr();
906 new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
908 depVw = depVm->getActiveView();
909 GraphicsView_ViewFrame* aViewFrame = 0;
910 if ( !depVw ) depVw = depVm->createViewWindow();
911 if ( depVw ) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( depVw );
913 view->init( aViewFrame );
914 depVm->setTitle( view->getViewName() );
916 else if ( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( depVm->getViewModel() ) ) {
917 if ( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
918 depVw = depVm->getActiveView();
923 #ifdef LAYOUT_DEPVIEW
924 // layout views properly
925 STD_TabDesktop* d = dynamic_cast<STD_TabDesktop*>( app->desktop() );
926 if ( d && depVw && occVw ) {
927 QtxWorkstack* ws = d->workstack();
929 QApplication::instance()->processEvents();
930 ws->Split( depVw, Qt::Horizontal, QtxWorkstack::SplitMove );
937 void GEOMToolsGUI::OnReduceStudy()
939 QDialog* dlg = new GEOMToolsGUI_ReduceStudyDlg( SUIT_Session::session()->activeApplication()->desktop() );