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>
57 #include <SVTK_ViewModel.h>
58 #include <SVTK_ViewWindow.h>
59 #include <SVTK_View.h>
61 #include <OCCViewer_ViewModel.h>
63 #include <SUIT_ViewManager.h>
64 #include <SUIT_Desktop.h>
65 #include <SUIT_ResourceMgr.h>
66 #include <SUIT_Session.h>
67 #include <SUIT_OverrideCursor.h>
68 #include <SUIT_MessageBox.h>
69 #include <SUIT_Tools.h>
71 #include <SalomeApp_Application.h>
72 #include <SalomeApp_Study.h>
73 #include <SalomeApp_Module.h>
75 #include <LightApp_SelectionMgr.h>
76 #include <LightApp_NameDlg.h>
78 #include <GEOMImpl_Types.hxx>
80 #include "utilities.h"
83 #include <AIS_Drawer.hxx>
84 #include <Prs3d_IsoAspect.hxx>
85 #include <Prs3d_PointAspect.hxx>
86 #include <Graphic3d_AspectMarker3d.hxx>
87 #include <Graphic3d_AspectLine3d.hxx>
88 #include <AIS_ListIteratorOfListOfInteractive.hxx>
89 #include <AIS_ListOfInteractive.hxx>
92 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
93 #include <TColStd_HArray1OfByte.hxx>
95 #include <Graphic3d_HArray1OfBytes.hxx>
100 #include <QColorDialog>
101 #include <QInputDialog>
102 #include <QFileDialog>
105 #include <QGridLayout>
108 #include <QPushButton>
112 #include <vtkRenderer.h>
115 // If the next macro is defined, autocolor feature works for all sub-shapes;
116 // if it is undefined, autocolor feature works for groups only
117 #define GENERAL_AUTOCOLOR
118 // Below macro, when uncommented, switches on simplified (more performant) algorithm
119 // of auto-color picking up
120 #define SIMPLE_AUTOCOLOR
122 void GEOMToolsGUI::OnCheckGeometry()
124 SalomeApp_Application* app =
125 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
126 PyConsole_Console* pyConsole = app->pythonConsole();
129 pyConsole->exec("from GEOM_usinggeom import *");
132 void GEOMToolsGUI::OnAutoColor()
134 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
137 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
138 if ( !appStudy ) return;
140 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
141 if ( !aSelMgr ) return;
143 SALOME_ListIO selected;
144 aSelMgr->selectedObjects( selected );
145 if ( selected.IsEmpty() ) return;
147 Handle(SALOME_InteractiveObject) anIObject = selected.First();
149 _PTR(Study) aStudy = appStudy->studyDS();
150 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
151 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
152 if (CORBA::is_nil(aMainObject)) return;
154 aMainObject->SetAutoColor( true );
156 QList<SALOMEDS::Color> aReservedColors;
158 GEOM_Displayer displayer ( appStudy );
160 SALOME_View* window = displayer.GetActiveView();
161 if ( !window ) return;
163 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
165 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
167 _PTR(SObject) aChildSObject( it->Value() );
168 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
169 if( CORBA::is_nil( aChildObject ) )
172 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
173 if( aChildObject->GetType() != GEOM_GROUP )
175 #endif // GENERAL_AUTOCOLOR
177 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
178 SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
179 #else // old algorithm for auto-colors
180 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
181 aReservedColors.append( aColor );
182 #endif // SIMPLE_AUTOCOLOR
183 aChildObject->SetColor( aColor );
185 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
187 SUIT_OverrideCursor();
189 appStudy->setObjectProperty( aMgrId, aChildObject->GetEntry(), GEOM::propertyName( GEOM::Color ), c );
190 Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject( aChildObject->GetEntry(), "GEOM", "" );
191 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
193 displayer.UpdateViewer();
196 appStudy->Modified();
197 app->updateActions(); //SRN: To update a Save button in the toolbar
200 void GEOMToolsGUI::OnDisableAutoColor()
202 SALOME_ListIO selected;
203 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
207 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
208 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
209 if( !aSelMgr || !appStudy )
212 aSelMgr->selectedObjects( selected );
213 if( selected.IsEmpty() )
216 Handle(SALOME_InteractiveObject) anIObject = selected.First();
218 _PTR(Study) aStudy = appStudy->studyDS();
219 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
220 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
221 if( CORBA::is_nil( aMainObject ) )
224 aMainObject->SetAutoColor( false );
227 void GEOMToolsGUI::OnColor()
229 // get active application
230 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
234 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
235 if ( !appStudy ) return;
237 // get selection manager
238 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
239 if ( !aSelMgr ) return;
242 SALOME_ListIO selected;
243 aSelMgr->selectedObjects( selected );
244 if ( selected.IsEmpty() ) return;
246 GEOM_Displayer displayer( appStudy );
249 SALOME_View* window = displayer.GetActiveView();
250 if ( !window ) return;
253 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
256 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
258 // show Choose Color dialog box
259 color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
260 if ( !color.isValid() ) return;
262 // iterate through list of objects and assign new color
263 SUIT_OverrideCursor();
264 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
265 Handle( SALOME_InteractiveObject ) io = It.Value();
266 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Color ), color );
267 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
269 displayer.UpdateViewer();
270 GeometryGUI::Modified();
273 app->updateActions(); //SRN: To update a Save button in the toolbar
276 void GEOMToolsGUI::OnTexture()
278 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
281 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
282 if ( !appStudy ) return;
284 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
285 if ( !aSelMgr ) return;
287 SALOME_ListIO selected;
288 aSelMgr->selectedObjects( selected );
289 if ( selected.IsEmpty() ) return;
291 GEOM_Displayer displayer( appStudy );
292 SALOME_View* window = displayer.GetActiveView();
293 if ( !window ) return;
295 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
297 QString aTexture = QFileDialog::getOpenFileName( dynamic_cast< SUIT_ViewWindow* >( window ),tr("GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
298 if( !aTexture.isEmpty() ) {
299 displayer.SetTexture( aTexture.toStdString() );
300 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
301 Handle( SALOME_InteractiveObject ) io = It.Value();
302 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), 3 );
303 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
306 displayer.UpdateViewer();
307 GeometryGUI::Modified();
310 app->updateActions(); //SRN: To update a Save button in the toolbar
313 void GEOMToolsGUI::OnTransparency()
315 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
319 void GEOMToolsGUI::OnChangeTransparency( bool increase )
321 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
324 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
325 if( !appStudy) return;
327 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
328 if ( !aSelMgr ) return;
330 SALOME_ListIO selected;
331 aSelMgr->selectedObjects( selected );
332 if ( selected.IsEmpty() ) return;
334 GEOM_Displayer displayer( appStudy );
335 SALOME_View* window = displayer.GetActiveView();
336 if ( !window ) return;
338 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
341 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
345 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Transparency ), QVariant() );
346 float transp = v.isValid() ? v.toFloat() : 1;
348 // Compute new transparency value
349 transp = transp + delta;
352 else if ( transp > 1 )
355 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
356 Handle( SALOME_InteractiveObject ) io = It.Value();
357 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::Transparency ), transp );
358 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
360 displayer.UpdateViewer();
361 GeometryGUI::Modified();
364 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
366 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
369 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
370 if ( !appStudy ) return;
372 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
373 if ( !aSelMgr ) return;
375 SALOME_ListIO selected;
376 aSelMgr->selectedObjects( selected );
377 if ( selected.IsEmpty() ) return;
379 GEOM_Displayer displayer( appStudy );
380 SALOME_View* window = displayer.GetActiveView();
381 if ( !window ) return;
383 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
385 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::NbIsos ) , QVariant() );
386 QString aStr = v.toString();
387 QStringList aStrList = aStr.split( GEOM::subSectionSeparator() );
388 int UIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_u", 1 );
389 int VIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_v", 1 );
390 if ( aStrList.count() == 2 ) {
391 if ( !aStrList[0].isEmpty() ) UIso = aStrList[0].toInt();
392 if ( !aStrList[1].isEmpty() ) VIso = aStrList[1].toInt();
398 if ( actionType == SHOWDLG ) {
399 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
400 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
402 NbIsosDlg->setU( UIso );
403 NbIsosDlg->setV( VIso );
405 if ( NbIsosDlg->exec() ) {
406 SUIT_OverrideCursor();
407 newNbUIso = NbIsosDlg->getU();
408 newNbVIso = NbIsosDlg->getV();
412 else if ( actionType == INCR || actionType == DECR ) {
414 if (actionType == DECR)
417 newNbUIso = UIso + delta;
418 newNbVIso = VIso + delta;
420 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
424 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
425 Handle( SALOME_InteractiveObject ) io = It.Value();
426 QString anIsos = QString( "%1%2%3" ).arg( newNbUIso ).arg( GEOM::subSectionSeparator() ).arg( newNbVIso );
427 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos );
428 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
430 displayer.UpdateViewer();
431 GeometryGUI::Modified();
434 void GEOMToolsGUI::OnDeflection()
436 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
439 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
440 if ( !appStudy ) return;
442 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
443 if ( !aSelMgr ) return;
445 SALOME_ListIO selected;
446 aSelMgr->selectedObjects( selected );
447 if ( selected.IsEmpty() ) return;
449 GEOM_Displayer displayer( appStudy );
450 SALOME_View* window = displayer.GetActiveView();
451 if ( !window ) return;
453 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
455 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
456 double aDC = v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
458 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
459 ( SUIT_Session::session()->activeApplication()->desktop() );
460 DeflectionDlg->setTheDC( aDC );
461 if ( DeflectionDlg->exec() ) {
462 SUIT_OverrideCursor();
463 aDC = DeflectionDlg->getTheDC();
465 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
466 Handle( SALOME_InteractiveObject ) io = It.Value();
467 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC );
468 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
471 displayer.UpdateViewer();
472 GeometryGUI::Modified();
475 void GEOMToolsGUI::OnSelectOnly(int mode)
477 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
479 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
480 GEOM_Displayer aDisp (appStudy);
481 aDisp.GlobalSelection(mode);
482 getGeometryGUI()->setLocalSelectionMode(mode);
486 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
488 SALOME_ListIO selected;
489 SalomeApp_Application* app =
490 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
492 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
494 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
497 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
498 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
499 if ( aSelMgr && appStudy ) {
500 aSelMgr->selectedObjects( selected );
501 if ( !selected.IsEmpty() ) {
502 _PTR(Study) aStudy = appStudy->studyDS();
503 _PTR(StudyBuilder) B = aStudy->NewBuilder();
505 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
507 SUIT_MessageBox::warning( app->desktop(),
508 QObject::tr( "WRN_WARNING" ),
509 QObject::tr( "WRN_STUDY_LOCKED" ) );
513 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
514 Handle(SALOME_InteractiveObject) IObject = It.Value();
516 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
517 _PTR(GenericAttribute) anAttr;
519 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
520 aExp->SetExpandable( show );
522 disp->EraseWithChildren(IObject,true);
527 app->updateObjectBrowser( false );
528 app->updateActions();
532 void GEOMToolsGUI::OnPointMarker()
534 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
538 void GEOMToolsGUI::OnMaterialProperties()
540 GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
544 void GEOMToolsGUI::OnMaterialsLibrary()
546 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
547 dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
551 void GEOMToolsGUI::OnUnpublishObject() {
552 SALOME_ListIO selected;
553 SalomeApp_Application* app =
554 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
556 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
558 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
561 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
562 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
563 if ( aSelMgr && appStudy ) {
564 aSelMgr->selectedObjects( selected );
565 if ( !selected.IsEmpty() ) {
566 _PTR(Study) aStudy = appStudy->studyDS();
567 _PTR(StudyBuilder) B = aStudy->NewBuilder();
569 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
571 SUIT_MessageBox::warning( app->desktop(),
572 QObject::tr( "WRN_WARNING" ),
573 QObject::tr( "WRN_STUDY_LOCKED" ) );
577 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
578 Handle(SALOME_InteractiveObject) IObject = It.Value();
580 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
581 _PTR(GenericAttribute) anAttr;
583 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
584 aDrw->SetDrawable( false );
585 disp->EraseWithChildren(IObject);
588 aSelMgr->clearSelected();
591 app->updateObjectBrowser( false );
592 app->updateActions();
597 void GEOMToolsGUI::OnPublishObject() {
598 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
602 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
606 _PTR(Study) aStudy = appStudy->studyDS();
611 //Check lock of the study
612 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
614 SUIT_MessageBox::warning( app->desktop(),
615 QObject::tr( "WRN_WARNING" ),
616 QObject::tr( "WRN_STUDY_LOCKED" ) );
620 GEOMToolsGUI_PublishDlg * publishDlg =
621 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
626 void GEOMToolsGUI::OnEdgeWidth()
628 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
631 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
632 if ( !appStudy ) return;
634 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
635 if ( !aSelMgr ) return;
637 SALOME_ListIO selected;
638 aSelMgr->selectedObjects( selected );
639 if ( selected.IsEmpty() ) return;
641 GEOM_Displayer displayer( appStudy );
643 SALOME_View* window = displayer.GetActiveView();
644 if ( !window ) return;
646 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
648 GEOMToolsGUI_LineWidthDlg* Dlg =
649 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
651 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
652 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
654 Dlg->setTheLW( aWidth );
656 SUIT_OverrideCursor();
657 aWidth = Dlg->getTheLW();
659 return; //Cancel case
660 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
661 Handle( SALOME_InteractiveObject ) io = It.Value();
662 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
663 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
665 displayer.UpdateViewer();
666 GeometryGUI::Modified();
670 void GEOMToolsGUI::OnIsosWidth() {
671 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
674 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
675 if ( !appStudy ) return;
677 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
678 if ( !aSelMgr ) return;
680 SALOME_ListIO selected;
681 aSelMgr->selectedObjects( selected );
682 if ( selected.IsEmpty() ) return;
684 GEOM_Displayer displayer( appStudy );
686 SALOME_View* window = displayer.GetActiveView();
687 if ( !window ) return;
689 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
691 GEOMToolsGUI_LineWidthDlg* Dlg =
692 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
694 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
695 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
697 Dlg->setTheLW( aWidth );
699 SUIT_OverrideCursor();
700 aWidth = Dlg->getTheLW();
702 return; //Cancel case
703 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
704 Handle( SALOME_InteractiveObject ) io = It.Value();
705 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
706 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
708 displayer.UpdateViewer();
709 GeometryGUI::Modified();
712 void GEOMToolsGUI::OnBringToFront() {
713 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
716 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());
717 if (!appStudy) return;
719 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
720 if ( !aSelMgr ) return;
722 SALOME_ListIO selected;
723 aSelMgr->selectedObjects( selected );
724 if ( selected.IsEmpty() ) return;
726 GEOM_Displayer displayer( appStudy );
728 SALOME_View* window = displayer.GetActiveView();
729 if ( !window ) return;
731 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
733 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
734 bool checked = a->isChecked();
736 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
737 Handle( SALOME_InteractiveObject ) io = It.Value();
738 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
739 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
741 displayer.UpdateViewer();
742 GeometryGUI::Modified();
745 void GEOMToolsGUI::OnClsBringToFront() {
746 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
749 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
750 if ( !appStudy ) return;
752 GEOM_Displayer displayer( appStudy );
754 SALOME_View* window = displayer.GetActiveView();
755 if ( !window ) return;
757 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
759 SALOME_ListIO anIOlst;
760 window->GetVisible( anIOlst );
762 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
763 Handle( SALOME_InteractiveObject ) io = It.Value();
764 appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
765 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
767 displayer.Redisplay( anIOlst );
768 displayer.UpdateViewer();
769 GeometryGUI::Modified();
772 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
774 if ( !theParam.canConvert<QString>() ) return;
776 QString theName = theParam.toString();
778 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
781 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
782 if ( !study ) return;
784 LightApp_SelectionMgr* selMgr = app->selectionMgr();
786 SALOME_ListIO selected;
787 selMgr->selectedObjects( selected );
789 if ( selected.IsEmpty() ) return;
791 GEOM_Displayer displayer( study );
793 SALOME_View* window = displayer.GetActiveView();
794 if ( !window ) return;
796 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
798 Material_Model aModel;
799 aModel.fromResources( theName );
800 QString prop = aModel.toProperties();
802 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
803 Handle(SALOME_InteractiveObject) io = It.Value();
804 study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
805 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
807 displayer.UpdateViewer();