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 <Material_Model.h>
39 #include <GEOM_VTKPropertyMaterial.hxx>
41 #include <GeometryGUI.h>
42 #include <GeometryGUI_Operations.h>
43 #include <GEOM_Constants.h>
44 #include <GEOM_Displayer.h>
47 #include <GEOM_Actor.h>
49 #include <DependencyTree.h>
51 #include <Basics_OCCTVersion.hxx>
53 #include <SALOME_ListIO.hxx>
54 #include <SALOME_ListIteratorOfListIO.hxx>
56 #include <SALOMEDS_SObject.hxx>
61 #include <SVTK_ViewModel.h>
62 #include <SVTK_ViewWindow.h>
63 #include <SVTK_View.h>
65 #include <OCCViewer_ViewModel.h>
67 #include <SUIT_ViewManager.h>
68 #include <SUIT_Desktop.h>
69 #include <SUIT_ResourceMgr.h>
70 #include <SUIT_Session.h>
71 #include <SUIT_OverrideCursor.h>
72 #include <SUIT_MessageBox.h>
73 #include <SUIT_Tools.h>
75 #include <SalomeApp_Application.h>
76 #include <SalomeApp_Study.h>
77 #include <SalomeApp_Module.h>
79 #include <LightApp_SelectionMgr.h>
80 #include <LightApp_NameDlg.h>
82 #include <GEOMImpl_Types.hxx>
84 #include "utilities.h"
87 #include <AIS_Drawer.hxx>
88 #include <Prs3d_IsoAspect.hxx>
89 #include <Prs3d_PointAspect.hxx>
90 #include <Graphic3d_AspectMarker3d.hxx>
91 #include <Graphic3d_AspectLine3d.hxx>
92 #include <AIS_ListIteratorOfListOfInteractive.hxx>
93 #include <AIS_ListOfInteractive.hxx>
96 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
97 #include <TColStd_HArray1OfByte.hxx>
99 #include <Graphic3d_HArray1OfBytes.hxx>
104 #include <QColorDialog>
105 #include <QInputDialog>
106 #include <QFileDialog>
109 #include <QGridLayout>
112 #include <QPushButton>
116 #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
126 void GEOMToolsGUI::OnCheckGeometry()
128 SalomeApp_Application* app =
129 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
130 PyConsole_Console* pyConsole = app->pythonConsole();
133 pyConsole->exec("from GEOM_usinggeom import *");
136 void GEOMToolsGUI::OnAutoColor()
138 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
141 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
142 if ( !appStudy ) return;
144 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
145 if ( !aSelMgr ) return;
147 SALOME_ListIO selected;
148 aSelMgr->selectedObjects( selected );
149 if ( selected.IsEmpty() ) return;
151 Handle(SALOME_InteractiveObject) anIObject = selected.First();
153 _PTR(Study) aStudy = appStudy->studyDS();
154 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
155 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
156 if (CORBA::is_nil(aMainObject)) return;
158 aMainObject->SetAutoColor( true );
160 QList<SALOMEDS::Color> aReservedColors;
162 GEOM_Displayer displayer ( appStudy );
164 SALOME_View* window = displayer.GetActiveView();
165 if ( !window ) return;
167 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
169 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
171 _PTR(SObject) aChildSObject( it->Value() );
172 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
173 if( CORBA::is_nil( aChildObject ) )
176 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
177 if( aChildObject->GetType() != GEOM_GROUP )
179 #endif // GENERAL_AUTOCOLOR
181 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
182 SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
183 #else // old algorithm for auto-colors
184 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
185 aReservedColors.append( aColor );
186 #endif // SIMPLE_AUTOCOLOR
187 aChildObject->SetColor( aColor );
189 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
191 SUIT_OverrideCursor();
193 appStudy->setObjectProperty( aMgrId, aChildObject->GetEntry(), GEOM::propertyName( GEOM::Color ), c );
194 Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject( aChildObject->GetStudyEntry(), "GEOM", "" );
195 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
197 displayer.UpdateViewer();
200 appStudy->Modified();
201 app->updateActions(); //SRN: To update a Save button in the toolbar
204 void GEOMToolsGUI::OnDisableAutoColor()
206 SALOME_ListIO selected;
207 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
211 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
212 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
213 if( !aSelMgr || !appStudy )
216 aSelMgr->selectedObjects( selected );
217 if( selected.IsEmpty() )
220 Handle(SALOME_InteractiveObject) anIObject = selected.First();
222 _PTR(Study) aStudy = appStudy->studyDS();
223 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
224 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
225 if( CORBA::is_nil( aMainObject ) )
228 aMainObject->SetAutoColor( false );
231 void GEOMToolsGUI::OnColor()
233 // get active application
234 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
238 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
239 if ( !appStudy ) return;
241 // get selection manager
242 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
243 if ( !aSelMgr ) return;
246 SALOME_ListIO selected;
247 aSelMgr->selectedObjects( selected );
248 if ( selected.IsEmpty() ) return;
250 GEOM_Displayer displayer( appStudy );
253 SALOME_View* window = displayer.GetActiveView();
254 if ( !window ) return;
257 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
260 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
262 // show Choose Color dialog box
263 color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
264 if ( !color.isValid() ) return;
266 // iterate through list of objects and assign new color
267 SUIT_OverrideCursor();
268 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
269 Handle( SALOME_InteractiveObject ) io = It.Value();
270 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Color ), color );
271 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
273 displayer.UpdateViewer();
274 GeometryGUI::Modified();
277 app->updateActions(); //SRN: To update a Save button in the toolbar
280 void GEOMToolsGUI::OnTexture()
282 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
285 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
286 if ( !appStudy ) return;
288 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
289 if ( !aSelMgr ) return;
291 SALOME_ListIO selected;
292 aSelMgr->selectedObjects( selected );
293 if ( selected.IsEmpty() ) return;
295 GEOM_Displayer displayer( appStudy );
296 SALOME_View* window = displayer.GetActiveView();
297 if ( !window ) return;
299 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
301 QString aTexture = QFileDialog::getOpenFileName( dynamic_cast< SUIT_ViewWindow* >( window ),tr("GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
302 if( !aTexture.isEmpty() ) {
303 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
304 Handle( SALOME_InteractiveObject ) io = It.Value();
305 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Texture ), aTexture );
306 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), 3 );
307 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
310 displayer.UpdateViewer();
311 GeometryGUI::Modified();
314 app->updateActions(); //SRN: To update a Save button in the toolbar
317 void GEOMToolsGUI::OnTransparency()
319 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
323 void GEOMToolsGUI::OnChangeTransparency( bool increase )
325 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
328 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
329 if( !appStudy) return;
331 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
332 if ( !aSelMgr ) return;
334 SALOME_ListIO selected;
335 aSelMgr->selectedObjects( selected );
336 if ( selected.IsEmpty() ) return;
338 GEOM_Displayer displayer( appStudy );
339 SALOME_View* window = displayer.GetActiveView();
340 if ( !window ) return;
342 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
345 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
349 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Transparency ), QVariant() );
350 float transp = v.isValid() ? v.toFloat() : 1;
352 // Compute new transparency value
353 transp = transp + delta;
356 else if ( transp > 1 )
359 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
360 Handle( SALOME_InteractiveObject ) io = It.Value();
361 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::Transparency ), transp );
362 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
364 displayer.UpdateViewer();
365 GeometryGUI::Modified();
368 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
370 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
373 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
374 if ( !appStudy ) return;
376 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
377 if ( !aSelMgr ) return;
379 SALOME_ListIO selected;
380 aSelMgr->selectedObjects( selected );
381 if ( selected.IsEmpty() ) return;
383 GEOM_Displayer displayer( appStudy );
384 SALOME_View* window = displayer.GetActiveView();
385 if ( !window ) return;
387 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
389 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::NbIsos ) , QVariant() );
390 QString aStr = v.toString();
391 QStringList aStrList = aStr.split( GEOM::subSectionSeparator() );
392 int UIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_u", 1 );
393 int VIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_v", 1 );
394 if ( aStrList.count() == 2 ) {
395 if ( !aStrList[0].isEmpty() ) UIso = aStrList[0].toInt();
396 if ( !aStrList[1].isEmpty() ) VIso = aStrList[1].toInt();
402 if ( actionType == SHOWDLG ) {
403 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
404 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
406 NbIsosDlg->setU( UIso );
407 NbIsosDlg->setV( VIso );
409 if ( NbIsosDlg->exec() ) {
410 SUIT_OverrideCursor();
411 newNbUIso = NbIsosDlg->getU();
412 newNbVIso = NbIsosDlg->getV();
416 else if ( actionType == INCR || actionType == DECR ) {
418 if (actionType == DECR)
421 newNbUIso = UIso + delta;
422 newNbVIso = VIso + delta;
424 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
428 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
429 Handle( SALOME_InteractiveObject ) io = It.Value();
430 QString anIsos = QString( "%1%2%3" ).arg( newNbUIso ).arg( GEOM::subSectionSeparator() ).arg( newNbVIso );
431 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos );
432 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
434 displayer.UpdateViewer();
435 GeometryGUI::Modified();
438 void GEOMToolsGUI::OnDeflection()
440 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
443 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
444 if ( !appStudy ) return;
446 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
447 if ( !aSelMgr ) return;
449 SALOME_ListIO selected;
450 aSelMgr->selectedObjects( selected );
451 if ( selected.IsEmpty() ) return;
453 GEOM_Displayer displayer( appStudy );
454 SALOME_View* window = displayer.GetActiveView();
455 if ( !window ) return;
457 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
459 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
460 double aDC = v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
462 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
463 ( SUIT_Session::session()->activeApplication()->desktop() );
464 DeflectionDlg->setTheDC( aDC );
465 if ( DeflectionDlg->exec() ) {
466 SUIT_OverrideCursor();
467 aDC = DeflectionDlg->getTheDC();
469 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
470 Handle( SALOME_InteractiveObject ) io = It.Value();
471 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC );
472 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
475 displayer.UpdateViewer();
476 GeometryGUI::Modified();
479 void GEOMToolsGUI::OnSelectOnly(int mode)
481 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
483 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
484 GEOM_Displayer aDisp (appStudy);
485 aDisp.GlobalSelection(mode);
486 getGeometryGUI()->setLocalSelectionMode(mode);
490 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
492 SALOME_ListIO selected;
493 SalomeApp_Application* app =
494 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
496 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
498 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
501 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
502 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
503 if ( aSelMgr && appStudy ) {
504 aSelMgr->selectedObjects( selected );
505 if ( !selected.IsEmpty() ) {
506 _PTR(Study) aStudy = appStudy->studyDS();
507 _PTR(StudyBuilder) B = aStudy->NewBuilder();
509 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
511 SUIT_MessageBox::warning( app->desktop(),
512 QObject::tr( "WRN_WARNING" ),
513 QObject::tr( "WRN_STUDY_LOCKED" ) );
517 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
518 Handle(SALOME_InteractiveObject) IObject = It.Value();
520 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
521 _PTR(GenericAttribute) anAttr;
523 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
524 aExp->SetExpandable( show );
526 disp->EraseWithChildren(IObject,true);
531 app->updateObjectBrowser( false );
532 app->updateActions();
536 void GEOMToolsGUI::OnPointMarker()
538 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
542 void GEOMToolsGUI::OnMaterialProperties()
544 GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
548 void GEOMToolsGUI::OnMaterialsLibrary()
550 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
551 dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
555 void GEOMToolsGUI::OnUnpublishObject() {
556 SALOME_ListIO selected;
557 SalomeApp_Application* app =
558 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
560 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
562 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
565 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
566 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
567 if ( aSelMgr && appStudy ) {
568 aSelMgr->selectedObjects( selected );
569 if ( !selected.IsEmpty() ) {
570 _PTR(Study) aStudy = appStudy->studyDS();
571 _PTR(StudyBuilder) B = aStudy->NewBuilder();
573 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
575 SUIT_MessageBox::warning( app->desktop(),
576 QObject::tr( "WRN_WARNING" ),
577 QObject::tr( "WRN_STUDY_LOCKED" ) );
581 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
582 Handle(SALOME_InteractiveObject) IObject = It.Value();
584 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
585 _PTR(GenericAttribute) anAttr;
587 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
588 aDrw->SetDrawable( false );
589 disp->EraseWithChildren(IObject);
592 aSelMgr->clearSelected();
595 app->updateObjectBrowser( false );
596 app->updateActions();
601 void GEOMToolsGUI::OnPublishObject() {
602 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
606 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
610 _PTR(Study) aStudy = appStudy->studyDS();
615 //Check lock of the study
616 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
618 SUIT_MessageBox::warning( app->desktop(),
619 QObject::tr( "WRN_WARNING" ),
620 QObject::tr( "WRN_STUDY_LOCKED" ) );
624 GEOMToolsGUI_PublishDlg* publishDlg =
625 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
630 void GEOMToolsGUI::OnEdgeWidth()
632 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
635 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
636 if ( !appStudy ) return;
638 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
639 if ( !aSelMgr ) return;
641 SALOME_ListIO selected;
642 aSelMgr->selectedObjects( selected );
643 if ( selected.IsEmpty() ) return;
645 GEOM_Displayer displayer( appStudy );
647 SALOME_View* window = displayer.GetActiveView();
648 if ( !window ) return;
650 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
652 GEOMToolsGUI_LineWidthDlg* Dlg =
653 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
655 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
656 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
658 Dlg->setTheLW( aWidth );
660 SUIT_OverrideCursor();
661 aWidth = Dlg->getTheLW();
663 return; //Cancel case
664 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
665 Handle( SALOME_InteractiveObject ) io = It.Value();
666 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
667 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
669 displayer.UpdateViewer();
670 GeometryGUI::Modified();
674 void GEOMToolsGUI::OnIsosWidth() {
675 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
678 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
679 if ( !appStudy ) return;
681 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
682 if ( !aSelMgr ) return;
684 SALOME_ListIO selected;
685 aSelMgr->selectedObjects( selected );
686 if ( selected.IsEmpty() ) return;
688 GEOM_Displayer displayer( appStudy );
690 SALOME_View* window = displayer.GetActiveView();
691 if ( !window ) return;
693 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
695 GEOMToolsGUI_LineWidthDlg* Dlg =
696 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
698 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
699 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
701 Dlg->setTheLW( aWidth );
703 SUIT_OverrideCursor();
704 aWidth = Dlg->getTheLW();
706 return; //Cancel case
707 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
708 Handle( SALOME_InteractiveObject ) io = It.Value();
709 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
710 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
712 displayer.UpdateViewer();
713 GeometryGUI::Modified();
716 void GEOMToolsGUI::OnBringToFront() {
717 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
720 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());
721 if (!appStudy) return;
723 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
724 if ( !aSelMgr ) return;
726 SALOME_ListIO selected;
727 aSelMgr->selectedObjects( selected );
728 if ( selected.IsEmpty() ) return;
730 GEOM_Displayer displayer( appStudy );
732 SALOME_View* window = displayer.GetActiveView();
733 if ( !window ) return;
735 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
737 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
738 bool checked = a->isChecked();
740 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
741 Handle( SALOME_InteractiveObject ) io = It.Value();
742 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
743 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
745 displayer.UpdateViewer();
746 GeometryGUI::Modified();
749 void GEOMToolsGUI::OnClsBringToFront() {
750 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
753 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
754 if ( !appStudy ) return;
756 GEOM_Displayer displayer( appStudy );
758 SALOME_View* window = displayer.GetActiveView();
759 if ( !window ) return;
761 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
763 SALOME_ListIO anIOlst;
764 window->GetVisible( anIOlst );
766 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
767 Handle( SALOME_InteractiveObject ) io = It.Value();
768 appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
769 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
771 displayer.Redisplay( anIOlst );
772 displayer.UpdateViewer();
773 GeometryGUI::Modified();
776 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
778 if ( !theParam.canConvert<QString>() ) return;
780 QString theName = theParam.toString();
782 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
785 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
786 if ( !study ) return;
788 LightApp_SelectionMgr* selMgr = app->selectionMgr();
790 SALOME_ListIO selected;
791 selMgr->selectedObjects( selected );
793 if ( selected.IsEmpty() ) return;
795 GEOM_Displayer displayer( study );
797 SALOME_View* window = displayer.GetActiveView();
798 if ( !window ) return;
800 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
802 Material_Model aModel;
803 aModel.fromResources( theName );
804 QString prop = aModel.toProperties();
806 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
807 Handle(SALOME_InteractiveObject) io = It.Value();
808 study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
809 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
811 displayer.UpdateViewer();
814 void GEOMToolsGUI::OnCreateFolder()
816 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
819 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
820 if ( !appStudy ) return;
822 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
823 if ( !aSelMgr ) return;
825 SALOME_ListIO selected;
826 aSelMgr->selectedObjects( selected );
827 if ( selected.IsEmpty() ) return;
829 Handle(SALOME_InteractiveObject) anIObject = selected.First();
831 _PTR(Study) aStudy = appStudy->studyDS();
832 if( !aStudy ) return;
833 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
834 if ( !aFatherSO ) return;
836 GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(),
837 _CAST(SObject, aFatherSO)->GetSObject() );
838 app->updateObjectBrowser( false );
841 void GEOMToolsGUI::OnSortChildren()
843 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
846 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
847 if ( !appStudy ) return;
849 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
850 if ( !aSelMgr ) return;
852 SALOME_ListIO selected;
853 aSelMgr->selectedObjects( selected );
854 if ( selected.IsEmpty() ) return;
856 Handle(SALOME_InteractiveObject) anIObject = selected.First();
858 _PTR(Study) aStudy = appStudy->studyDS();
859 if( !aStudy ) return;
860 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
861 if ( !aFatherSO ) return;
863 aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
865 app->updateObjectBrowser( true );
868 void GEOMToolsGUI::OnShowDependencyTree()