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_ViewModel.h>
50 #include <DependencyTree_View.h>
51 #include <DependencyTree_Selector.h>
53 #include <Basics_OCCTVersion.hxx>
55 #include <SALOME_ListIO.hxx>
56 #include <SALOME_ListIteratorOfListIO.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 <SalomeApp_Application.h>
78 #include <SalomeApp_Study.h>
79 #include <SalomeApp_Module.h>
81 #include <LightApp_SelectionMgr.h>
82 #include <LightApp_NameDlg.h>
84 #include <GEOMImpl_Types.hxx>
86 #include "utilities.h"
89 #include <AIS_Drawer.hxx>
90 #include <Prs3d_IsoAspect.hxx>
91 #include <Prs3d_PointAspect.hxx>
92 #include <Graphic3d_AspectMarker3d.hxx>
93 #include <Graphic3d_AspectLine3d.hxx>
94 #include <AIS_ListIteratorOfListOfInteractive.hxx>
95 #include <AIS_ListOfInteractive.hxx>
98 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
99 #include <TColStd_HArray1OfByte.hxx>
101 #include <Graphic3d_HArray1OfBytes.hxx>
106 #include <QColorDialog>
107 #include <QInputDialog>
108 #include <QFileDialog>
111 #include <QGridLayout>
114 #include <QPushButton>
118 #include <vtkRenderer.h>
121 // If the next macro is defined, autocolor feature works for all sub-shapes;
122 // if it is undefined, autocolor feature works for groups only
123 #define GENERAL_AUTOCOLOR
124 // Below macro, when uncommented, switches on simplified (more performant) algorithm
125 // of auto-color picking up
126 #define SIMPLE_AUTOCOLOR
128 void GEOMToolsGUI::OnCheckGeometry()
130 SalomeApp_Application* app =
131 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
132 PyConsole_Console* pyConsole = app->pythonConsole();
135 pyConsole->exec("from GEOM_usinggeom import *");
138 void GEOMToolsGUI::OnAutoColor()
140 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
143 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
144 if ( !appStudy ) return;
146 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
147 if ( !aSelMgr ) return;
149 SALOME_ListIO selected;
150 aSelMgr->selectedObjects( selected );
151 if ( selected.IsEmpty() ) return;
153 Handle(SALOME_InteractiveObject) anIObject = selected.First();
155 _PTR(Study) aStudy = appStudy->studyDS();
156 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
157 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
158 if (CORBA::is_nil(aMainObject)) return;
160 aMainObject->SetAutoColor( true );
162 QList<SALOMEDS::Color> aReservedColors;
164 GEOM_Displayer displayer ( appStudy );
166 SALOME_View* window = displayer.GetActiveView();
167 if ( !window ) return;
169 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
171 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
173 _PTR(SObject) aChildSObject( it->Value() );
174 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
175 if( CORBA::is_nil( aChildObject ) )
178 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
179 if( aChildObject->GetType() != GEOM_GROUP )
181 #endif // GENERAL_AUTOCOLOR
183 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
184 SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
185 #else // old algorithm for auto-colors
186 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
187 aReservedColors.append( aColor );
188 #endif // SIMPLE_AUTOCOLOR
189 aChildObject->SetColor( aColor );
191 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
193 SUIT_OverrideCursor();
195 appStudy->setObjectProperty( aMgrId, aChildObject->GetEntry(), GEOM::propertyName( GEOM::Color ), c );
196 Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject( aChildObject->GetStudyEntry(), "GEOM", "" );
197 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
199 displayer.UpdateViewer();
202 appStudy->Modified();
203 app->updateActions(); //SRN: To update a Save button in the toolbar
206 void GEOMToolsGUI::OnDisableAutoColor()
208 SALOME_ListIO selected;
209 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
213 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
214 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
215 if( !aSelMgr || !appStudy )
218 aSelMgr->selectedObjects( selected );
219 if( selected.IsEmpty() )
222 Handle(SALOME_InteractiveObject) anIObject = selected.First();
224 _PTR(Study) aStudy = appStudy->studyDS();
225 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
226 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
227 if( CORBA::is_nil( aMainObject ) )
230 aMainObject->SetAutoColor( false );
233 void GEOMToolsGUI::OnColor()
235 // get active application
236 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
240 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
241 if ( !appStudy ) return;
243 // get selection manager
244 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
245 if ( !aSelMgr ) return;
248 SALOME_ListIO selected;
249 aSelMgr->selectedObjects( selected );
250 if ( selected.IsEmpty() ) return;
252 GEOM_Displayer displayer( appStudy );
255 SALOME_View* window = displayer.GetActiveView();
256 if ( !window ) return;
259 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
262 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
264 // show Choose Color dialog box
265 color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
266 if ( !color.isValid() ) return;
268 // iterate through list of objects and assign new color
269 SUIT_OverrideCursor();
270 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
271 Handle( SALOME_InteractiveObject ) io = It.Value();
272 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Color ), color );
273 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
275 displayer.UpdateViewer();
276 GeometryGUI::Modified();
279 app->updateActions(); //SRN: To update a Save button in the toolbar
282 void GEOMToolsGUI::OnTexture()
284 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
287 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
288 if ( !appStudy ) return;
290 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
291 if ( !aSelMgr ) return;
293 SALOME_ListIO selected;
294 aSelMgr->selectedObjects( selected );
295 if ( selected.IsEmpty() ) return;
297 GEOM_Displayer displayer( appStudy );
298 SALOME_View* window = displayer.GetActiveView();
299 if ( !window ) return;
301 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
303 QString aTexture = QFileDialog::getOpenFileName( dynamic_cast< SUIT_ViewWindow* >( window ),tr("GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
304 if( !aTexture.isEmpty() ) {
305 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
306 Handle( SALOME_InteractiveObject ) io = It.Value();
307 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Texture ), aTexture );
308 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), 3 );
309 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
312 displayer.UpdateViewer();
313 GeometryGUI::Modified();
316 app->updateActions(); //SRN: To update a Save button in the toolbar
319 void GEOMToolsGUI::OnTransparency()
321 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
325 void GEOMToolsGUI::OnChangeTransparency( bool increase )
327 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
330 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
331 if( !appStudy) return;
333 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
334 if ( !aSelMgr ) return;
336 SALOME_ListIO selected;
337 aSelMgr->selectedObjects( selected );
338 if ( selected.IsEmpty() ) return;
340 GEOM_Displayer displayer( appStudy );
341 SALOME_View* window = displayer.GetActiveView();
342 if ( !window ) return;
344 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
347 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
351 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Transparency ), QVariant() );
352 float transp = v.isValid() ? v.toFloat() : 1;
354 // Compute new transparency value
355 transp = transp + delta;
358 else if ( transp > 1 )
361 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
362 Handle( SALOME_InteractiveObject ) io = It.Value();
363 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::Transparency ), transp );
364 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
366 displayer.UpdateViewer();
367 GeometryGUI::Modified();
370 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
372 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
375 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
376 if ( !appStudy ) return;
378 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
379 if ( !aSelMgr ) return;
381 SALOME_ListIO selected;
382 aSelMgr->selectedObjects( selected );
383 if ( selected.IsEmpty() ) return;
385 GEOM_Displayer displayer( appStudy );
386 SALOME_View* window = displayer.GetActiveView();
387 if ( !window ) return;
389 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
391 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::NbIsos ) , QVariant() );
392 QString aStr = v.toString();
393 QStringList aStrList = aStr.split( GEOM::subSectionSeparator() );
394 int UIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_u", 1 );
395 int VIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_v", 1 );
396 if ( aStrList.count() == 2 ) {
397 if ( !aStrList[0].isEmpty() ) UIso = aStrList[0].toInt();
398 if ( !aStrList[1].isEmpty() ) VIso = aStrList[1].toInt();
404 if ( actionType == SHOWDLG ) {
405 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
406 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
408 NbIsosDlg->setU( UIso );
409 NbIsosDlg->setV( VIso );
411 if ( NbIsosDlg->exec() ) {
412 SUIT_OverrideCursor();
413 newNbUIso = NbIsosDlg->getU();
414 newNbVIso = NbIsosDlg->getV();
418 else if ( actionType == INCR || actionType == DECR ) {
420 if (actionType == DECR)
423 newNbUIso = UIso + delta;
424 newNbVIso = VIso + delta;
426 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
430 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
431 Handle( SALOME_InteractiveObject ) io = It.Value();
432 QString anIsos = QString( "%1%2%3" ).arg( newNbUIso ).arg( GEOM::subSectionSeparator() ).arg( newNbVIso );
433 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos );
434 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
436 displayer.UpdateViewer();
437 GeometryGUI::Modified();
440 void GEOMToolsGUI::OnDeflection()
442 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
445 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
446 if ( !appStudy ) return;
448 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
449 if ( !aSelMgr ) return;
451 SALOME_ListIO selected;
452 aSelMgr->selectedObjects( selected );
453 if ( selected.IsEmpty() ) return;
455 GEOM_Displayer displayer( appStudy );
456 SALOME_View* window = displayer.GetActiveView();
457 if ( !window ) return;
459 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
461 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
462 double aDC = v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
464 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
465 ( SUIT_Session::session()->activeApplication()->desktop() );
466 DeflectionDlg->setTheDC( aDC );
467 if ( DeflectionDlg->exec() ) {
468 SUIT_OverrideCursor();
469 aDC = DeflectionDlg->getTheDC();
471 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
472 Handle( SALOME_InteractiveObject ) io = It.Value();
473 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC );
474 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
477 displayer.UpdateViewer();
478 GeometryGUI::Modified();
481 void GEOMToolsGUI::OnSelectOnly(int mode)
483 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
485 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
486 GEOM_Displayer aDisp (appStudy);
487 aDisp.GlobalSelection(mode);
488 getGeometryGUI()->setLocalSelectionMode(mode);
492 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
494 SALOME_ListIO selected;
495 SalomeApp_Application* app =
496 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
498 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
500 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
503 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
504 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
505 if ( aSelMgr && appStudy ) {
506 aSelMgr->selectedObjects( selected );
507 if ( !selected.IsEmpty() ) {
508 _PTR(Study) aStudy = appStudy->studyDS();
509 _PTR(StudyBuilder) B = aStudy->NewBuilder();
511 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
513 SUIT_MessageBox::warning( app->desktop(),
514 QObject::tr( "WRN_WARNING" ),
515 QObject::tr( "WRN_STUDY_LOCKED" ) );
519 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
520 Handle(SALOME_InteractiveObject) IObject = It.Value();
522 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
523 _PTR(GenericAttribute) anAttr;
525 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
526 aExp->SetExpandable( show );
528 disp->EraseWithChildren(IObject,true);
533 app->updateObjectBrowser( false );
534 app->updateActions();
538 void GEOMToolsGUI::OnPointMarker()
540 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
544 void GEOMToolsGUI::OnMaterialProperties()
546 GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
550 void GEOMToolsGUI::OnMaterialsLibrary()
552 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
553 dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
557 void GEOMToolsGUI::OnUnpublishObject() {
558 SALOME_ListIO selected;
559 SalomeApp_Application* app =
560 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
562 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
564 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
567 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
568 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
569 if ( aSelMgr && appStudy ) {
570 aSelMgr->selectedObjects( selected );
571 if ( !selected.IsEmpty() ) {
572 _PTR(Study) aStudy = appStudy->studyDS();
573 _PTR(StudyBuilder) B = aStudy->NewBuilder();
575 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
577 SUIT_MessageBox::warning( app->desktop(),
578 QObject::tr( "WRN_WARNING" ),
579 QObject::tr( "WRN_STUDY_LOCKED" ) );
583 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
584 Handle(SALOME_InteractiveObject) IObject = It.Value();
586 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
587 _PTR(GenericAttribute) anAttr;
589 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
590 aDrw->SetDrawable( false );
591 disp->EraseWithChildren(IObject);
594 aSelMgr->clearSelected();
597 app->updateObjectBrowser( false );
598 app->updateActions();
603 void GEOMToolsGUI::OnPublishObject() {
604 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
608 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
612 _PTR(Study) aStudy = appStudy->studyDS();
617 //Check lock of the study
618 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
620 SUIT_MessageBox::warning( app->desktop(),
621 QObject::tr( "WRN_WARNING" ),
622 QObject::tr( "WRN_STUDY_LOCKED" ) );
626 GEOMToolsGUI_PublishDlg* publishDlg =
627 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
632 void GEOMToolsGUI::OnEdgeWidth()
634 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
637 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
638 if ( !appStudy ) return;
640 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
641 if ( !aSelMgr ) return;
643 SALOME_ListIO selected;
644 aSelMgr->selectedObjects( selected );
645 if ( selected.IsEmpty() ) return;
647 GEOM_Displayer displayer( appStudy );
649 SALOME_View* window = displayer.GetActiveView();
650 if ( !window ) return;
652 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
654 GEOMToolsGUI_LineWidthDlg* Dlg =
655 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
657 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
658 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
660 Dlg->setTheLW( aWidth );
662 SUIT_OverrideCursor();
663 aWidth = Dlg->getTheLW();
665 return; //Cancel case
666 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
667 Handle( SALOME_InteractiveObject ) io = It.Value();
668 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
669 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
671 displayer.UpdateViewer();
672 GeometryGUI::Modified();
676 void GEOMToolsGUI::OnIsosWidth() {
677 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
680 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
681 if ( !appStudy ) return;
683 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
684 if ( !aSelMgr ) return;
686 SALOME_ListIO selected;
687 aSelMgr->selectedObjects( selected );
688 if ( selected.IsEmpty() ) return;
690 GEOM_Displayer displayer( appStudy );
692 SALOME_View* window = displayer.GetActiveView();
693 if ( !window ) return;
695 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
697 GEOMToolsGUI_LineWidthDlg* Dlg =
698 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
700 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
701 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
703 Dlg->setTheLW( aWidth );
705 SUIT_OverrideCursor();
706 aWidth = Dlg->getTheLW();
708 return; //Cancel case
709 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
710 Handle( SALOME_InteractiveObject ) io = It.Value();
711 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
712 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
714 displayer.UpdateViewer();
715 GeometryGUI::Modified();
718 void GEOMToolsGUI::OnBringToFront() {
719 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
722 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());
723 if (!appStudy) return;
725 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
726 if ( !aSelMgr ) return;
728 SALOME_ListIO selected;
729 aSelMgr->selectedObjects( selected );
730 if ( selected.IsEmpty() ) return;
732 GEOM_Displayer displayer( appStudy );
734 SALOME_View* window = displayer.GetActiveView();
735 if ( !window ) return;
737 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
739 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
740 bool checked = a->isChecked();
742 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
743 Handle( SALOME_InteractiveObject ) io = It.Value();
744 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
745 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
747 displayer.UpdateViewer();
748 GeometryGUI::Modified();
751 void GEOMToolsGUI::OnClsBringToFront() {
752 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
755 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
756 if ( !appStudy ) return;
758 GEOM_Displayer displayer( appStudy );
760 SALOME_View* window = displayer.GetActiveView();
761 if ( !window ) return;
763 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
765 SALOME_ListIO anIOlst;
766 window->GetVisible( anIOlst );
768 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
769 Handle( SALOME_InteractiveObject ) io = It.Value();
770 appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
771 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
773 displayer.Redisplay( anIOlst );
774 displayer.UpdateViewer();
775 GeometryGUI::Modified();
778 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
780 if ( !theParam.canConvert<QString>() ) return;
782 QString theName = theParam.toString();
784 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
787 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
788 if ( !study ) return;
790 LightApp_SelectionMgr* selMgr = app->selectionMgr();
792 SALOME_ListIO selected;
793 selMgr->selectedObjects( selected );
795 if ( selected.IsEmpty() ) return;
797 GEOM_Displayer displayer( study );
799 SALOME_View* window = displayer.GetActiveView();
800 if ( !window ) return;
802 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
804 Material_Model aModel;
805 aModel.fromResources( theName );
806 QString prop = aModel.toProperties();
808 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
809 Handle(SALOME_InteractiveObject) io = It.Value();
810 study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
811 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
813 displayer.UpdateViewer();
816 void GEOMToolsGUI::OnCreateFolder()
818 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
821 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
822 if ( !appStudy ) return;
824 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
825 if ( !aSelMgr ) return;
827 SALOME_ListIO selected;
828 aSelMgr->selectedObjects( selected );
829 if ( selected.IsEmpty() ) return;
831 Handle(SALOME_InteractiveObject) anIObject = selected.First();
833 _PTR(Study) aStudy = appStudy->studyDS();
834 if( !aStudy ) return;
835 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
836 if ( !aFatherSO ) return;
838 GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(),
839 _CAST(SObject, aFatherSO)->GetSObject() );
840 app->updateObjectBrowser( false );
843 void GEOMToolsGUI::OnSortChildren()
845 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
848 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
849 if ( !appStudy ) return;
851 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
852 if ( !aSelMgr ) return;
854 SALOME_ListIO selected;
855 aSelMgr->selectedObjects( selected );
856 if ( selected.IsEmpty() ) return;
858 Handle(SALOME_InteractiveObject) anIObject = selected.First();
860 _PTR(Study) aStudy = appStudy->studyDS();
861 if( !aStudy ) return;
862 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
863 if ( !aFatherSO ) return;
865 aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
867 app->updateObjectBrowser( true );
870 void GEOMToolsGUI::OnShowDependencyTree()
872 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
874 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
877 SUIT_ViewManager *svm = app->getViewManager( GraphicsView_Viewer::Type(), false );
880 DependencyTree_View* view = new DependencyTree_View();
881 DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
882 SUIT_ViewManager *svm = app->createViewManager( viewModel );
884 LightApp_SelectionMgr* selMgr = app->selectionMgr();
885 new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
887 SUIT_ViewWindow* svw = svm->getActiveView();
888 GraphicsView_ViewFrame* aViewFrame = 0;
889 if (!svw) svw = svm->createViewWindow();
890 if (svw) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>(svw);
892 view->init( aViewFrame );
893 svm->setTitle( view->getViewName() );
896 if( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( svm->getViewModel() ) )
897 if( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
898 svm->getActiveView()->setFocus();