1 // Copyright (C) 2007-2015 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 <Prs3d_IsoAspect.hxx>
94 #include <Prs3d_PointAspect.hxx>
95 #include <Graphic3d_AspectMarker3d.hxx>
96 #include <Graphic3d_AspectLine3d.hxx>
97 #include <AIS_ListIteratorOfListOfInteractive.hxx>
98 #include <AIS_ListOfInteractive.hxx>
100 #include <TColStd_HArray1OfByte.hxx>
104 #include <QApplication>
105 #include <QColorDialog>
106 #include <QInputDialog>
107 #include <QFileDialog>
110 #include <QGridLayout>
113 #include <QPushButton>
117 #include <vtkRenderer.h>
119 // If the next macro is defined, autocolor feature works for all sub-shapes;
120 // if it is undefined, autocolor feature works for groups only
121 #define GENERAL_AUTOCOLOR
122 // Below macro, when uncommented, switches on simplified (more performant) algorithm
123 // of auto-color picking up
124 #define SIMPLE_AUTOCOLOR
125 // Below macro, when defined, switches on automatic layouting of OCC and Dependecy views
126 // on Show Dependencies operation
127 #define LAYOUT_DEPVIEW
129 void GEOMToolsGUI::OnCheckGeometry()
131 SalomeApp_Application* app =
132 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
133 PyConsole_Console* pyConsole = app->pythonConsole();
136 pyConsole->exec("from GEOM_usinggeom import *");
139 void GEOMToolsGUI::OnAutoColor()
141 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
144 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
145 if ( !appStudy ) return;
147 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
148 if ( !aSelMgr ) return;
150 SALOME_ListIO selected;
151 aSelMgr->selectedObjects( selected );
152 if ( selected.IsEmpty() ) return;
154 Handle(SALOME_InteractiveObject) anIObject = selected.First();
156 _PTR(Study) aStudy = appStudy->studyDS();
157 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
158 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
159 if (CORBA::is_nil(aMainObject)) return;
161 aMainObject->SetAutoColor( true );
163 QList<SALOMEDS::Color> aReservedColors;
165 GEOM_Displayer displayer ( appStudy );
167 SALOME_View* window = displayer.GetActiveView();
168 if ( !window ) return;
170 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
172 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
174 _PTR(SObject) aChildSObject( it->Value() );
175 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
176 if( CORBA::is_nil( aChildObject ) )
179 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
180 if( aChildObject->GetType() != GEOM_GROUP )
182 #endif // GENERAL_AUTOCOLOR
184 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
185 SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
186 #else // old algorithm for auto-colors
187 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
188 aReservedColors.append( aColor );
189 #endif // SIMPLE_AUTOCOLOR
190 aChildObject->SetColor( aColor );
192 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
194 SUIT_OverrideCursor();
196 appStudy->setObjectProperty( aMgrId, aChildObject->GetStudyEntry(), GEOM::propertyName( GEOM::Color ), c );
197 Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject( aChildObject->GetStudyEntry(), "GEOM", "" );
198 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
200 displayer.UpdateViewer();
203 appStudy->Modified();
204 app->updateActions(); //SRN: To update a Save button in the toolbar
207 void GEOMToolsGUI::OnDisableAutoColor()
209 SALOME_ListIO selected;
210 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
214 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
215 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
216 if( !aSelMgr || !appStudy )
219 aSelMgr->selectedObjects( selected );
220 if( selected.IsEmpty() )
223 Handle(SALOME_InteractiveObject) anIObject = selected.First();
225 _PTR(Study) aStudy = appStudy->studyDS();
226 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
227 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
228 if( CORBA::is_nil( aMainObject ) )
231 aMainObject->SetAutoColor( false );
234 void GEOMToolsGUI::OnColor()
236 // get active application
237 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
241 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
242 if ( !appStudy ) return;
244 // get selection manager
245 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
246 if ( !aSelMgr ) return;
249 SALOME_ListIO selected;
250 aSelMgr->selectedObjects( selected );
251 if ( selected.IsEmpty() ) return;
253 GEOM_Displayer displayer( appStudy );
256 SALOME_View* window = displayer.GetActiveView();
257 if ( !window ) return;
260 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
263 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
265 // show Choose Color dialog box
266 color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
267 if ( !color.isValid() ) return;
269 SALOMEDS::Color aSColor;
270 aSColor.R = (double)color.red() / 255.0;
271 aSColor.G = (double)color.green() / 255.0;
272 aSColor.B = (double)color.blue() / 255.0;
274 // iterate through list of objects and assign new color
275 SUIT_OverrideCursor();
276 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
277 Handle( SALOME_InteractiveObject ) io = It.Value();
278 GEOM::GEOM_Object_var aObject = GEOMBase::ConvertIOinGEOMObject( io );
279 if ( !CORBA::is_nil( aObject ) ) aObject->SetColor( aSColor );
280 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Color ), color );
281 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
283 displayer.UpdateViewer();
284 GeometryGUI::Modified();
287 app->updateActions(); //SRN: To update a Save button in the toolbar
290 void GEOMToolsGUI::OnTexture()
292 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
295 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
296 if ( !appStudy ) return;
298 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
299 if ( !aSelMgr ) return;
301 SALOME_ListIO selected;
302 aSelMgr->selectedObjects( selected );
303 if ( selected.IsEmpty() ) return;
305 GEOM_Displayer displayer( appStudy );
306 SALOME_View* window = displayer.GetActiveView();
307 if ( !window ) return;
309 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
311 QString aTexture = QFileDialog::getOpenFileName( dynamic_cast< SUIT_ViewWindow* >( window ),tr("GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
312 if( !aTexture.isEmpty() ) {
313 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
314 Handle( SALOME_InteractiveObject ) io = It.Value();
315 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Texture ), aTexture );
316 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), 3 );
317 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
320 displayer.UpdateViewer();
321 GeometryGUI::Modified();
324 app->updateActions(); //SRN: To update a Save button in the toolbar
327 void GEOMToolsGUI::OnTransparency()
329 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
333 void GEOMToolsGUI::OnChangeTransparency( bool increase )
335 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
338 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
339 if( !appStudy) return;
341 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
342 if ( !aSelMgr ) return;
344 SALOME_ListIO selected;
345 aSelMgr->selectedObjects( selected );
346 if ( selected.IsEmpty() ) return;
348 GEOM_Displayer displayer( appStudy );
349 SALOME_View* window = displayer.GetActiveView();
350 if ( !window ) return;
352 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
355 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
359 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Transparency ), QVariant() );
360 float transp = v.isValid() ? v.toFloat() : 1;
362 // Compute new transparency value
363 transp = transp + delta;
366 else if ( transp > 1 )
369 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
370 Handle( SALOME_InteractiveObject ) io = It.Value();
371 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::Transparency ), transp );
372 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
374 displayer.UpdateViewer();
375 GeometryGUI::Modified();
378 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
380 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
383 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
384 if ( !appStudy ) return;
386 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
387 if ( !aSelMgr ) return;
389 SALOME_ListIO selected;
390 aSelMgr->selectedObjects( selected );
391 if ( selected.IsEmpty() ) return;
393 GEOM_Displayer displayer( appStudy );
394 SALOME_View* window = displayer.GetActiveView();
395 if ( !window ) return;
397 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
399 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::NbIsos ) , QVariant() );
400 QString aStr = v.toString();
401 QStringList aStrList = aStr.split( GEOM::subSectionSeparator() );
402 int UIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_u", 1 );
403 int VIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_v", 1 );
404 if ( aStrList.count() == 2 ) {
405 if ( !aStrList[0].isEmpty() ) UIso = aStrList[0].toInt();
406 if ( !aStrList[1].isEmpty() ) VIso = aStrList[1].toInt();
412 if ( actionType == SHOWDLG ) {
413 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
414 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
416 NbIsosDlg->setU( UIso );
417 NbIsosDlg->setV( VIso );
419 if ( NbIsosDlg->exec() ) {
420 SUIT_OverrideCursor();
421 newNbUIso = NbIsosDlg->getU();
422 newNbVIso = NbIsosDlg->getV();
426 else if ( actionType == INCR || actionType == DECR ) {
428 if (actionType == DECR)
431 newNbUIso = UIso + delta;
432 newNbVIso = VIso + delta;
434 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
438 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
439 Handle( SALOME_InteractiveObject ) io = It.Value();
440 QString anIsos = QString( "%1%2%3" ).arg( newNbUIso ).arg( GEOM::subSectionSeparator() ).arg( newNbVIso );
441 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos );
442 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
444 displayer.UpdateViewer();
445 GeometryGUI::Modified();
448 void GEOMToolsGUI::OnDeflection()
450 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
453 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
454 if ( !appStudy ) return;
456 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
457 if ( !aSelMgr ) return;
459 SALOME_ListIO selected;
460 aSelMgr->selectedObjects( selected );
461 if ( selected.IsEmpty() ) return;
463 GEOM_Displayer displayer( appStudy );
464 SALOME_View* window = displayer.GetActiveView();
465 if ( !window ) return;
467 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
469 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
470 double aDC = v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
472 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
473 ( SUIT_Session::session()->activeApplication()->desktop() );
474 DeflectionDlg->setTheDC( aDC );
475 if ( DeflectionDlg->exec() ) {
476 SUIT_OverrideCursor();
477 aDC = DeflectionDlg->getTheDC();
479 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
480 Handle( SALOME_InteractiveObject ) io = It.Value();
481 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC );
482 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
485 displayer.UpdateViewer();
486 GeometryGUI::Modified();
489 void GEOMToolsGUI::OnSelectOnly(int mode)
491 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
493 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
494 GEOM_Displayer aDisp (appStudy);
495 aDisp.GlobalSelection(mode);
496 getGeometryGUI()->setLocalSelectionMode(mode);
500 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
502 SALOME_ListIO selected;
503 SalomeApp_Application* app =
504 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
506 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
508 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
511 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
512 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
513 if ( aSelMgr && appStudy ) {
514 aSelMgr->selectedObjects( selected );
515 if ( !selected.IsEmpty() ) {
516 _PTR(Study) aStudy = appStudy->studyDS();
517 _PTR(StudyBuilder) B = aStudy->NewBuilder();
519 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
521 SUIT_MessageBox::warning( app->desktop(),
522 QObject::tr( "WRN_WARNING" ),
523 QObject::tr( "WRN_STUDY_LOCKED" ) );
527 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
528 Handle(SALOME_InteractiveObject) IObject = It.Value();
530 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
531 _PTR(GenericAttribute) anAttr;
533 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
534 aExp->SetExpandable( show );
536 disp->EraseWithChildren(IObject,true);
541 app->updateObjectBrowser( false );
542 app->updateActions();
546 void GEOMToolsGUI::OnPointMarker()
548 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
552 void GEOMToolsGUI::OnMaterialProperties()
554 GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
558 void GEOMToolsGUI::OnMaterialsLibrary()
560 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
561 dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
565 void GEOMToolsGUI::OnUnpublishObject() {
566 SALOME_ListIO selected;
567 SalomeApp_Application* app =
568 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
570 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
572 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
575 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
576 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
577 if ( aSelMgr && appStudy ) {
578 aSelMgr->selectedObjects( selected );
579 if ( !selected.IsEmpty() ) {
580 _PTR(Study) aStudy = appStudy->studyDS();
581 _PTR(StudyBuilder) B = aStudy->NewBuilder();
583 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
585 SUIT_MessageBox::warning( app->desktop(),
586 QObject::tr( "WRN_WARNING" ),
587 QObject::tr( "WRN_STUDY_LOCKED" ) );
591 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
592 Handle(SALOME_InteractiveObject) IObject = It.Value();
594 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
595 _PTR(GenericAttribute) anAttr;
597 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
598 aDrw->SetDrawable( false );
599 disp->EraseWithChildren(IObject);
600 // hide references if any
601 std::vector< _PTR(SObject) > vso = aStudy->FindDependances(obj);
602 for ( int i = 0; i < vso.size(); i++ ) {
603 _PTR(SObject) refObj = vso[i];
604 aDrw = B->FindOrCreateAttribute( refObj, "AttributeDrawable" );
605 aDrw->SetDrawable( false );
609 aSelMgr->clearSelected();
612 app->updateObjectBrowser( false );
613 app->updateActions();
618 void GEOMToolsGUI::OnPublishObject() {
619 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
623 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
627 _PTR(Study) aStudy = appStudy->studyDS();
632 //Check lock of the study
633 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
635 SUIT_MessageBox::warning( app->desktop(),
636 QObject::tr( "WRN_WARNING" ),
637 QObject::tr( "WRN_STUDY_LOCKED" ) );
641 GEOMToolsGUI_PublishDlg* publishDlg =
642 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
647 void GEOMToolsGUI::OnEdgeWidth()
649 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
652 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
653 if ( !appStudy ) return;
655 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
656 if ( !aSelMgr ) return;
658 SALOME_ListIO selected;
659 aSelMgr->selectedObjects( selected );
660 if ( selected.IsEmpty() ) return;
662 GEOM_Displayer displayer( appStudy );
664 SALOME_View* window = displayer.GetActiveView();
665 if ( !window ) return;
667 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
669 GEOMToolsGUI_LineWidthDlg* Dlg =
670 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
672 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
673 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
675 Dlg->setTheLW( aWidth );
677 SUIT_OverrideCursor();
678 aWidth = Dlg->getTheLW();
680 return; //Cancel case
681 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
682 Handle( SALOME_InteractiveObject ) io = It.Value();
683 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
684 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
686 displayer.UpdateViewer();
687 GeometryGUI::Modified();
691 void GEOMToolsGUI::OnIsosWidth() {
692 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
695 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
696 if ( !appStudy ) return;
698 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
699 if ( !aSelMgr ) return;
701 SALOME_ListIO selected;
702 aSelMgr->selectedObjects( selected );
703 if ( selected.IsEmpty() ) return;
705 GEOM_Displayer displayer( appStudy );
707 SALOME_View* window = displayer.GetActiveView();
708 if ( !window ) return;
710 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
712 GEOMToolsGUI_LineWidthDlg* Dlg =
713 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
715 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
716 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
718 Dlg->setTheLW( aWidth );
720 SUIT_OverrideCursor();
721 aWidth = Dlg->getTheLW();
723 return; //Cancel case
724 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
725 Handle( SALOME_InteractiveObject ) io = It.Value();
726 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
727 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
729 displayer.UpdateViewer();
730 GeometryGUI::Modified();
733 void GEOMToolsGUI::OnBringToFront() {
734 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
737 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());
738 if (!appStudy) return;
740 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
741 if ( !aSelMgr ) return;
743 SALOME_ListIO selected;
744 aSelMgr->selectedObjects( selected );
745 if ( selected.IsEmpty() ) return;
747 GEOM_Displayer displayer( appStudy );
749 SALOME_View* window = displayer.GetActiveView();
750 if ( !window ) return;
752 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
754 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
755 bool checked = a->isChecked();
757 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
758 Handle( SALOME_InteractiveObject ) io = It.Value();
759 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
760 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
762 displayer.UpdateViewer();
763 GeometryGUI::Modified();
766 void GEOMToolsGUI::OnClsBringToFront() {
767 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
770 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
771 if ( !appStudy ) return;
773 GEOM_Displayer displayer( appStudy );
775 SALOME_View* window = displayer.GetActiveView();
776 if ( !window ) return;
778 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
780 SALOME_ListIO anIOlst;
781 window->GetVisible( anIOlst );
783 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
784 Handle( SALOME_InteractiveObject ) io = It.Value();
785 appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
786 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
788 displayer.Redisplay( anIOlst );
789 displayer.UpdateViewer();
790 GeometryGUI::Modified();
793 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
795 if ( !theParam.canConvert<QString>() ) return;
797 QString theName = theParam.toString();
799 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
802 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
803 if ( !study ) return;
805 LightApp_SelectionMgr* selMgr = app->selectionMgr();
807 SALOME_ListIO selected;
808 selMgr->selectedObjects( selected );
810 if ( selected.IsEmpty() ) return;
812 GEOM_Displayer displayer( study );
814 SALOME_View* window = displayer.GetActiveView();
815 if ( !window ) return;
817 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
819 Material_Model aModel;
820 aModel.fromResources( theName );
821 QString prop = aModel.toProperties();
823 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
824 Handle(SALOME_InteractiveObject) io = It.Value();
825 study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
826 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
828 displayer.UpdateViewer();
831 void GEOMToolsGUI::OnCreateFolder()
833 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
836 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
837 if ( !appStudy ) return;
839 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
840 if ( !aSelMgr ) return;
842 SALOME_ListIO selected;
843 aSelMgr->selectedObjects( selected );
844 if ( selected.IsEmpty() ) return;
846 Handle(SALOME_InteractiveObject) anIObject = selected.First();
848 _PTR(Study) aStudy = appStudy->studyDS();
849 if( !aStudy ) return;
850 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
851 if ( !aFatherSO ) return;
853 GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(),
854 _CAST(SObject, aFatherSO)->GetSObject() );
855 app->updateObjectBrowser( false );
858 void GEOMToolsGUI::OnSortChildren()
860 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
863 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
864 if ( !appStudy ) return;
866 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
867 if ( !aSelMgr ) return;
869 SALOME_ListIO selected;
870 aSelMgr->selectedObjects( selected );
871 if ( selected.IsEmpty() ) return;
873 Handle(SALOME_InteractiveObject) anIObject = selected.First();
875 _PTR(Study) aStudy = appStudy->studyDS();
876 if( !aStudy ) return;
877 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
878 if ( !aFatherSO ) return;
880 aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
882 app->updateObjectBrowser( true );
885 void GEOMToolsGUI::OnShowDependencyTree()
887 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
889 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
892 #ifdef LAYOUT_DEPVIEW
893 SUIT_ViewManager* occVm = app->getViewManager( OCCViewer_Viewer::Type(), true );
894 SUIT_ViewWindow* occVw = occVm->getActiveView();
896 SUIT_ViewManager* depVm = app->getViewManager( GraphicsView_Viewer::Type(), false );
897 SUIT_ViewWindow* depVw = 0;
900 DependencyTree_View* view = new DependencyTree_View();
901 DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
902 depVm = app->createViewManager( viewModel );
904 LightApp_SelectionMgr* selMgr = app->selectionMgr();
905 new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
907 depVw = depVm->getActiveView();
908 GraphicsView_ViewFrame* aViewFrame = 0;
909 if ( !depVw ) depVw = depVm->createViewWindow();
910 if ( depVw ) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( depVw );
912 view->init( aViewFrame );
913 depVm->setTitle( view->getViewName() );
915 else if ( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( depVm->getViewModel() ) ) {
916 if ( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
917 depVw = depVm->getActiveView();
922 #ifdef LAYOUT_DEPVIEW
923 // layout views properly
924 STD_TabDesktop* d = dynamic_cast<STD_TabDesktop*>( app->desktop() );
925 if ( d && depVw && occVw ) {
926 QtxWorkstack* ws = d->workstack();
928 QApplication::instance()->processEvents();
929 ws->Split( depVw, Qt::Horizontal, QtxWorkstack::SplitMove );
936 void GEOMToolsGUI::OnReduceStudy()
938 QDialog* dlg = new GEOMToolsGUI_ReduceStudyDlg( SUIT_Session::session()->activeApplication()->desktop() );