1 // Copyright (C) 2007-2013 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.
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 <Basics_OCCTVersion.hxx>
51 #include <SALOME_ListIO.hxx>
52 #include <SALOME_ListIteratorOfListIO.hxx>
54 #include <SALOMEDS_SObject.hxx>
59 #include <SVTK_ViewModel.h>
60 #include <SVTK_ViewWindow.h>
61 #include <SVTK_View.h>
63 #include <OCCViewer_ViewModel.h>
65 #include <SUIT_ViewManager.h>
66 #include <SUIT_Desktop.h>
67 #include <SUIT_ResourceMgr.h>
68 #include <SUIT_Session.h>
69 #include <SUIT_OverrideCursor.h>
70 #include <SUIT_MessageBox.h>
71 #include <SUIT_Tools.h>
73 #include <SalomeApp_Application.h>
74 #include <SalomeApp_Study.h>
75 #include <SalomeApp_Module.h>
77 #include <LightApp_SelectionMgr.h>
78 #include <LightApp_NameDlg.h>
80 #include <GEOMImpl_Types.hxx>
82 #include "utilities.h"
85 #include <AIS_Drawer.hxx>
86 #include <Prs3d_IsoAspect.hxx>
87 #include <Prs3d_PointAspect.hxx>
88 #include <Graphic3d_AspectMarker3d.hxx>
89 #include <Graphic3d_AspectLine3d.hxx>
90 #include <AIS_ListIteratorOfListOfInteractive.hxx>
91 #include <AIS_ListOfInteractive.hxx>
94 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
95 #include <TColStd_HArray1OfByte.hxx>
97 #include <Graphic3d_HArray1OfBytes.hxx>
102 #include <QColorDialog>
103 #include <QInputDialog>
104 #include <QFileDialog>
107 #include <QGridLayout>
110 #include <QPushButton>
114 #include <vtkRenderer.h>
117 // If the next macro is defined, autocolor feature works for all sub-shapes;
118 // if it is undefined, autocolor feature works for groups only
119 #define GENERAL_AUTOCOLOR
120 // Below macro, when uncommented, switches on simplified (more performant) algorithm
121 // of auto-color picking up
122 #define SIMPLE_AUTOCOLOR
124 void GEOMToolsGUI::OnCheckGeometry()
126 SalomeApp_Application* app =
127 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
128 PyConsole_Console* pyConsole = app->pythonConsole();
131 pyConsole->exec("from GEOM_usinggeom import *");
134 void GEOMToolsGUI::OnAutoColor()
136 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
139 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
140 if ( !appStudy ) return;
142 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
143 if ( !aSelMgr ) return;
145 SALOME_ListIO selected;
146 aSelMgr->selectedObjects( selected );
147 if ( selected.IsEmpty() ) return;
149 Handle(SALOME_InteractiveObject) anIObject = selected.First();
151 _PTR(Study) aStudy = appStudy->studyDS();
152 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
153 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
154 if (CORBA::is_nil(aMainObject)) return;
156 aMainObject->SetAutoColor( true );
158 QList<SALOMEDS::Color> aReservedColors;
160 GEOM_Displayer displayer ( appStudy );
162 SALOME_View* window = displayer.GetActiveView();
163 if ( !window ) return;
165 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
167 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
169 _PTR(SObject) aChildSObject( it->Value() );
170 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
171 if( CORBA::is_nil( aChildObject ) )
174 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
175 if( aChildObject->GetType() != GEOM_GROUP )
177 #endif // GENERAL_AUTOCOLOR
179 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
180 SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
181 #else // old algorithm for auto-colors
182 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
183 aReservedColors.append( aColor );
184 #endif // SIMPLE_AUTOCOLOR
185 aChildObject->SetColor( aColor );
187 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
189 SUIT_OverrideCursor();
191 appStudy->setObjectProperty( aMgrId, aChildObject->GetEntry(), GEOM::propertyName( GEOM::Color ), c );
192 Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject( aChildObject->GetStudyEntry(), "GEOM", "" );
193 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
195 displayer.UpdateViewer();
198 appStudy->Modified();
199 app->updateActions(); //SRN: To update a Save button in the toolbar
202 void GEOMToolsGUI::OnDisableAutoColor()
204 SALOME_ListIO selected;
205 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
209 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
210 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
211 if( !aSelMgr || !appStudy )
214 aSelMgr->selectedObjects( selected );
215 if( selected.IsEmpty() )
218 Handle(SALOME_InteractiveObject) anIObject = selected.First();
220 _PTR(Study) aStudy = appStudy->studyDS();
221 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
222 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
223 if( CORBA::is_nil( aMainObject ) )
226 aMainObject->SetAutoColor( false );
229 void GEOMToolsGUI::OnColor()
231 // get active application
232 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
236 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
237 if ( !appStudy ) return;
239 // get selection manager
240 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
241 if ( !aSelMgr ) return;
244 SALOME_ListIO selected;
245 aSelMgr->selectedObjects( selected );
246 if ( selected.IsEmpty() ) return;
248 GEOM_Displayer displayer( appStudy );
251 SALOME_View* window = displayer.GetActiveView();
252 if ( !window ) return;
255 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
258 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
260 // show Choose Color dialog box
261 color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
262 if ( !color.isValid() ) return;
264 // iterate through list of objects and assign new color
265 SUIT_OverrideCursor();
266 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
267 Handle( SALOME_InteractiveObject ) io = It.Value();
268 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Color ), color );
269 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
271 displayer.UpdateViewer();
272 GeometryGUI::Modified();
275 app->updateActions(); //SRN: To update a Save button in the toolbar
278 void GEOMToolsGUI::OnTexture()
280 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
283 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
284 if ( !appStudy ) return;
286 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
287 if ( !aSelMgr ) return;
289 SALOME_ListIO selected;
290 aSelMgr->selectedObjects( selected );
291 if ( selected.IsEmpty() ) return;
293 GEOM_Displayer displayer( appStudy );
294 SALOME_View* window = displayer.GetActiveView();
295 if ( !window ) return;
297 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
299 QString aTexture = QFileDialog::getOpenFileName( dynamic_cast< SUIT_ViewWindow* >( window ),tr("GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
300 if( !aTexture.isEmpty() ) {
301 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
302 Handle( SALOME_InteractiveObject ) io = It.Value();
303 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Texture ), aTexture );
304 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), 3 );
305 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
308 displayer.UpdateViewer();
309 GeometryGUI::Modified();
312 app->updateActions(); //SRN: To update a Save button in the toolbar
315 void GEOMToolsGUI::OnTransparency()
317 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
321 void GEOMToolsGUI::OnChangeTransparency( bool increase )
323 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
326 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
327 if( !appStudy) return;
329 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
330 if ( !aSelMgr ) return;
332 SALOME_ListIO selected;
333 aSelMgr->selectedObjects( selected );
334 if ( selected.IsEmpty() ) return;
336 GEOM_Displayer displayer( appStudy );
337 SALOME_View* window = displayer.GetActiveView();
338 if ( !window ) return;
340 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
343 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
347 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Transparency ), QVariant() );
348 float transp = v.isValid() ? v.toFloat() : 1;
350 // Compute new transparency value
351 transp = transp + delta;
354 else if ( transp > 1 )
357 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
358 Handle( SALOME_InteractiveObject ) io = It.Value();
359 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::Transparency ), transp );
360 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
362 displayer.UpdateViewer();
363 GeometryGUI::Modified();
366 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
368 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
371 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
372 if ( !appStudy ) return;
374 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
375 if ( !aSelMgr ) return;
377 SALOME_ListIO selected;
378 aSelMgr->selectedObjects( selected );
379 if ( selected.IsEmpty() ) return;
381 GEOM_Displayer displayer( appStudy );
382 SALOME_View* window = displayer.GetActiveView();
383 if ( !window ) return;
385 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
387 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::NbIsos ) , QVariant() );
388 QString aStr = v.toString();
389 QStringList aStrList = aStr.split( GEOM::subSectionSeparator() );
390 int UIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_u", 1 );
391 int VIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_v", 1 );
392 if ( aStrList.count() == 2 ) {
393 if ( !aStrList[0].isEmpty() ) UIso = aStrList[0].toInt();
394 if ( !aStrList[1].isEmpty() ) VIso = aStrList[1].toInt();
400 if ( actionType == SHOWDLG ) {
401 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
402 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
404 NbIsosDlg->setU( UIso );
405 NbIsosDlg->setV( VIso );
407 if ( NbIsosDlg->exec() ) {
408 SUIT_OverrideCursor();
409 newNbUIso = NbIsosDlg->getU();
410 newNbVIso = NbIsosDlg->getV();
414 else if ( actionType == INCR || actionType == DECR ) {
416 if (actionType == DECR)
419 newNbUIso = UIso + delta;
420 newNbVIso = VIso + delta;
422 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
426 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
427 Handle( SALOME_InteractiveObject ) io = It.Value();
428 QString anIsos = QString( "%1%2%3" ).arg( newNbUIso ).arg( GEOM::subSectionSeparator() ).arg( newNbVIso );
429 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos );
430 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
432 displayer.UpdateViewer();
433 GeometryGUI::Modified();
436 void GEOMToolsGUI::OnDeflection()
438 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
441 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
442 if ( !appStudy ) return;
444 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
445 if ( !aSelMgr ) return;
447 SALOME_ListIO selected;
448 aSelMgr->selectedObjects( selected );
449 if ( selected.IsEmpty() ) return;
451 GEOM_Displayer displayer( appStudy );
452 SALOME_View* window = displayer.GetActiveView();
453 if ( !window ) return;
455 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
457 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
458 double aDC = v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
460 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
461 ( SUIT_Session::session()->activeApplication()->desktop() );
462 DeflectionDlg->setTheDC( aDC );
463 if ( DeflectionDlg->exec() ) {
464 SUIT_OverrideCursor();
465 aDC = DeflectionDlg->getTheDC();
467 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
468 Handle( SALOME_InteractiveObject ) io = It.Value();
469 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC );
470 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
473 displayer.UpdateViewer();
474 GeometryGUI::Modified();
477 void GEOMToolsGUI::OnSelectOnly(int mode)
479 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
481 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
482 GEOM_Displayer aDisp (appStudy);
483 aDisp.GlobalSelection(mode);
484 getGeometryGUI()->setLocalSelectionMode(mode);
488 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
490 SALOME_ListIO selected;
491 SalomeApp_Application* app =
492 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
494 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
496 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
499 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
500 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
501 if ( aSelMgr && appStudy ) {
502 aSelMgr->selectedObjects( selected );
503 if ( !selected.IsEmpty() ) {
504 _PTR(Study) aStudy = appStudy->studyDS();
505 _PTR(StudyBuilder) B = aStudy->NewBuilder();
507 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
509 SUIT_MessageBox::warning( app->desktop(),
510 QObject::tr( "WRN_WARNING" ),
511 QObject::tr( "WRN_STUDY_LOCKED" ) );
515 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
516 Handle(SALOME_InteractiveObject) IObject = It.Value();
518 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
519 _PTR(GenericAttribute) anAttr;
521 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
522 aExp->SetExpandable( show );
524 disp->EraseWithChildren(IObject,true);
529 app->updateObjectBrowser( false );
530 app->updateActions();
534 void GEOMToolsGUI::OnPointMarker()
536 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
540 void GEOMToolsGUI::OnMaterialProperties()
542 GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
546 void GEOMToolsGUI::OnMaterialsLibrary()
548 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
549 dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
553 void GEOMToolsGUI::OnUnpublishObject() {
554 SALOME_ListIO selected;
555 SalomeApp_Application* app =
556 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
558 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
560 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
563 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
564 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
565 if ( aSelMgr && appStudy ) {
566 aSelMgr->selectedObjects( selected );
567 if ( !selected.IsEmpty() ) {
568 _PTR(Study) aStudy = appStudy->studyDS();
569 _PTR(StudyBuilder) B = aStudy->NewBuilder();
571 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
573 SUIT_MessageBox::warning( app->desktop(),
574 QObject::tr( "WRN_WARNING" ),
575 QObject::tr( "WRN_STUDY_LOCKED" ) );
579 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
580 Handle(SALOME_InteractiveObject) IObject = It.Value();
582 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
583 _PTR(GenericAttribute) anAttr;
585 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
586 aDrw->SetDrawable( false );
587 disp->EraseWithChildren(IObject);
590 aSelMgr->clearSelected();
593 app->updateObjectBrowser( false );
594 app->updateActions();
599 void GEOMToolsGUI::OnPublishObject() {
600 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
604 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
608 _PTR(Study) aStudy = appStudy->studyDS();
613 //Check lock of the study
614 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
616 SUIT_MessageBox::warning( app->desktop(),
617 QObject::tr( "WRN_WARNING" ),
618 QObject::tr( "WRN_STUDY_LOCKED" ) );
622 GEOMToolsGUI_PublishDlg* publishDlg =
623 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
628 void GEOMToolsGUI::OnEdgeWidth()
630 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
633 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
634 if ( !appStudy ) return;
636 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
637 if ( !aSelMgr ) return;
639 SALOME_ListIO selected;
640 aSelMgr->selectedObjects( selected );
641 if ( selected.IsEmpty() ) return;
643 GEOM_Displayer displayer( appStudy );
645 SALOME_View* window = displayer.GetActiveView();
646 if ( !window ) return;
648 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
650 GEOMToolsGUI_LineWidthDlg* Dlg =
651 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
653 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
654 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
656 Dlg->setTheLW( aWidth );
658 SUIT_OverrideCursor();
659 aWidth = Dlg->getTheLW();
661 return; //Cancel case
662 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
663 Handle( SALOME_InteractiveObject ) io = It.Value();
664 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
665 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
667 displayer.UpdateViewer();
668 GeometryGUI::Modified();
672 void GEOMToolsGUI::OnIsosWidth() {
673 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
676 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
677 if ( !appStudy ) return;
679 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
680 if ( !aSelMgr ) return;
682 SALOME_ListIO selected;
683 aSelMgr->selectedObjects( selected );
684 if ( selected.IsEmpty() ) return;
686 GEOM_Displayer displayer( appStudy );
688 SALOME_View* window = displayer.GetActiveView();
689 if ( !window ) return;
691 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
693 GEOMToolsGUI_LineWidthDlg* Dlg =
694 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
696 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
697 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
699 Dlg->setTheLW( aWidth );
701 SUIT_OverrideCursor();
702 aWidth = Dlg->getTheLW();
704 return; //Cancel case
705 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
706 Handle( SALOME_InteractiveObject ) io = It.Value();
707 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
708 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
710 displayer.UpdateViewer();
711 GeometryGUI::Modified();
714 void GEOMToolsGUI::OnBringToFront() {
715 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
718 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());
719 if (!appStudy) return;
721 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
722 if ( !aSelMgr ) return;
724 SALOME_ListIO selected;
725 aSelMgr->selectedObjects( selected );
726 if ( selected.IsEmpty() ) return;
728 GEOM_Displayer displayer( appStudy );
730 SALOME_View* window = displayer.GetActiveView();
731 if ( !window ) return;
733 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
735 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
736 bool checked = a->isChecked();
738 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
739 Handle( SALOME_InteractiveObject ) io = It.Value();
740 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
741 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
743 displayer.UpdateViewer();
744 GeometryGUI::Modified();
747 void GEOMToolsGUI::OnClsBringToFront() {
748 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
751 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
752 if ( !appStudy ) return;
754 GEOM_Displayer displayer( appStudy );
756 SALOME_View* window = displayer.GetActiveView();
757 if ( !window ) return;
759 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
761 SALOME_ListIO anIOlst;
762 window->GetVisible( anIOlst );
764 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
765 Handle( SALOME_InteractiveObject ) io = It.Value();
766 appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
767 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
769 displayer.Redisplay( anIOlst );
770 displayer.UpdateViewer();
771 GeometryGUI::Modified();
774 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
776 if ( !theParam.canConvert<QString>() ) return;
778 QString theName = theParam.toString();
780 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
783 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
784 if ( !study ) return;
786 LightApp_SelectionMgr* selMgr = app->selectionMgr();
788 SALOME_ListIO selected;
789 selMgr->selectedObjects( selected );
791 if ( selected.IsEmpty() ) return;
793 GEOM_Displayer displayer( study );
795 SALOME_View* window = displayer.GetActiveView();
796 if ( !window ) return;
798 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
800 Material_Model aModel;
801 aModel.fromResources( theName );
802 QString prop = aModel.toProperties();
804 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
805 Handle(SALOME_InteractiveObject) io = It.Value();
806 study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
807 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
809 displayer.UpdateViewer();
812 void GEOMToolsGUI::OnCreateFolder()
814 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
817 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
818 if ( !appStudy ) return;
820 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
821 if ( !aSelMgr ) return;
823 SALOME_ListIO selected;
824 aSelMgr->selectedObjects( selected );
825 if ( selected.IsEmpty() ) return;
827 Handle(SALOME_InteractiveObject) anIObject = selected.First();
829 _PTR(Study) aStudy = appStudy->studyDS();
830 if( !aStudy ) return;
831 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
832 if ( !aFatherSO ) return;
834 GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(),
835 _CAST(SObject, aFatherSO)->GetSObject() );
836 app->updateObjectBrowser( false );
839 void GEOMToolsGUI::OnSortChildren()
841 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
844 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
845 if ( !appStudy ) return;
847 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
848 if ( !aSelMgr ) return;
850 SALOME_ListIO selected;
851 aSelMgr->selectedObjects( selected );
852 if ( selected.IsEmpty() ) return;
854 Handle(SALOME_InteractiveObject) anIObject = selected.First();
856 _PTR(Study) aStudy = appStudy->studyDS();
857 if( !aStudy ) return;
858 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
859 if ( !aFatherSO ) return;
861 aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
863 app->updateObjectBrowser( true );