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 "GEOMToolsGUI_ReduceStudyDlg.h"
38 #include <Material_Model.h>
40 #include <GEOM_VTKPropertyMaterial.hxx>
42 #include <GeometryGUI.h>
43 #include <GeometryGUI_Operations.h>
44 #include <GEOM_Constants.h>
45 #include <GEOM_Displayer.h>
48 #include <GEOM_Actor.h>
50 #include <DependencyTree_ViewModel.h>
51 #include <DependencyTree_View.h>
52 #include <DependencyTree_Selector.h>
54 #include <Basics_OCCTVersion.hxx>
56 #include <SALOME_ListIO.hxx>
58 #include <SALOMEDS_SObject.hxx>
63 #include <SVTK_ViewModel.h>
64 #include <SVTK_ViewWindow.h>
65 #include <SVTK_View.h>
67 #include <OCCViewer_ViewModel.h>
69 #include <SUIT_ViewManager.h>
70 #include <SUIT_Desktop.h>
71 #include <SUIT_ResourceMgr.h>
72 #include <SUIT_Session.h>
73 #include <SUIT_OverrideCursor.h>
74 #include <SUIT_MessageBox.h>
75 #include <SUIT_Tools.h>
77 #include <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>
97 #include <TColStd_HArray1OfByte.hxx>
101 #include <QColorDialog>
102 #include <QInputDialog>
103 #include <QFileDialog>
106 #include <QGridLayout>
109 #include <QPushButton>
113 #include <vtkRenderer.h>
116 // If the next macro is defined, autocolor feature works for all sub-shapes;
117 // if it is undefined, autocolor feature works for groups only
118 #define GENERAL_AUTOCOLOR
119 // Below macro, when uncommented, switches on simplified (more performant) algorithm
120 // of auto-color picking up
121 #define SIMPLE_AUTOCOLOR
123 void GEOMToolsGUI::OnCheckGeometry()
125 SalomeApp_Application* app =
126 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
127 PyConsole_Console* pyConsole = app->pythonConsole();
130 pyConsole->exec("from GEOM_usinggeom import *");
133 void GEOMToolsGUI::OnAutoColor()
135 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
138 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
139 if ( !appStudy ) return;
141 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
142 if ( !aSelMgr ) return;
144 SALOME_ListIO selected;
145 aSelMgr->selectedObjects( selected );
146 if ( selected.IsEmpty() ) return;
148 Handle(SALOME_InteractiveObject) anIObject = selected.First();
150 _PTR(Study) aStudy = appStudy->studyDS();
151 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
152 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
153 if (CORBA::is_nil(aMainObject)) return;
155 aMainObject->SetAutoColor( true );
157 QList<SALOMEDS::Color> aReservedColors;
159 GEOM_Displayer displayer ( appStudy );
161 SALOME_View* window = displayer.GetActiveView();
162 if ( !window ) return;
164 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
166 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
168 _PTR(SObject) aChildSObject( it->Value() );
169 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
170 if( CORBA::is_nil( aChildObject ) )
173 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
174 if( aChildObject->GetType() != GEOM_GROUP )
176 #endif // GENERAL_AUTOCOLOR
178 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
179 SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
180 #else // old algorithm for auto-colors
181 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
182 aReservedColors.append( aColor );
183 #endif // SIMPLE_AUTOCOLOR
184 aChildObject->SetColor( aColor );
186 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
188 SUIT_OverrideCursor();
190 appStudy->setObjectProperty( aMgrId, aChildObject->GetEntry(), GEOM::propertyName( GEOM::Color ), c );
191 Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject( aChildObject->GetStudyEntry(), "GEOM", "" );
192 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
194 displayer.UpdateViewer();
197 appStudy->Modified();
198 app->updateActions(); //SRN: To update a Save button in the toolbar
201 void GEOMToolsGUI::OnDisableAutoColor()
203 SALOME_ListIO selected;
204 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
208 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
209 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
210 if( !aSelMgr || !appStudy )
213 aSelMgr->selectedObjects( selected );
214 if( selected.IsEmpty() )
217 Handle(SALOME_InteractiveObject) anIObject = selected.First();
219 _PTR(Study) aStudy = appStudy->studyDS();
220 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
221 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
222 if( CORBA::is_nil( aMainObject ) )
225 aMainObject->SetAutoColor( false );
228 void GEOMToolsGUI::OnColor()
230 // get active application
231 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
235 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
236 if ( !appStudy ) return;
238 // get selection manager
239 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
240 if ( !aSelMgr ) return;
243 SALOME_ListIO selected;
244 aSelMgr->selectedObjects( selected );
245 if ( selected.IsEmpty() ) return;
247 GEOM_Displayer displayer( appStudy );
250 SALOME_View* window = displayer.GetActiveView();
251 if ( !window ) return;
254 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
257 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
259 // show Choose Color dialog box
260 color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
261 if ( !color.isValid() ) return;
263 // iterate through list of objects and assign new color
264 SUIT_OverrideCursor();
265 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
266 Handle( SALOME_InteractiveObject ) io = It.Value();
267 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Color ), color );
268 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
270 displayer.UpdateViewer();
271 GeometryGUI::Modified();
274 app->updateActions(); //SRN: To update a Save button in the toolbar
277 void GEOMToolsGUI::OnTexture()
279 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
282 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
283 if ( !appStudy ) return;
285 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
286 if ( !aSelMgr ) return;
288 SALOME_ListIO selected;
289 aSelMgr->selectedObjects( selected );
290 if ( selected.IsEmpty() ) return;
292 GEOM_Displayer displayer( appStudy );
293 SALOME_View* window = displayer.GetActiveView();
294 if ( !window ) return;
296 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
298 QString aTexture = QFileDialog::getOpenFileName( dynamic_cast< SUIT_ViewWindow* >( window ),tr("GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
299 if( !aTexture.isEmpty() ) {
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::Texture ), aTexture );
303 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), 3 );
304 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
307 displayer.UpdateViewer();
308 GeometryGUI::Modified();
311 app->updateActions(); //SRN: To update a Save button in the toolbar
314 void GEOMToolsGUI::OnTransparency()
316 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
320 void GEOMToolsGUI::OnChangeTransparency( bool increase )
322 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
325 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
326 if( !appStudy) return;
328 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
329 if ( !aSelMgr ) return;
331 SALOME_ListIO selected;
332 aSelMgr->selectedObjects( selected );
333 if ( selected.IsEmpty() ) return;
335 GEOM_Displayer displayer( appStudy );
336 SALOME_View* window = displayer.GetActiveView();
337 if ( !window ) return;
339 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
342 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
346 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Transparency ), QVariant() );
347 float transp = v.isValid() ? v.toFloat() : 1;
349 // Compute new transparency value
350 transp = transp + delta;
353 else if ( transp > 1 )
356 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
357 Handle( SALOME_InteractiveObject ) io = It.Value();
358 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::Transparency ), transp );
359 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
361 displayer.UpdateViewer();
362 GeometryGUI::Modified();
365 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
367 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
370 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
371 if ( !appStudy ) return;
373 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
374 if ( !aSelMgr ) return;
376 SALOME_ListIO selected;
377 aSelMgr->selectedObjects( selected );
378 if ( selected.IsEmpty() ) return;
380 GEOM_Displayer displayer( appStudy );
381 SALOME_View* window = displayer.GetActiveView();
382 if ( !window ) return;
384 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
386 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::NbIsos ) , QVariant() );
387 QString aStr = v.toString();
388 QStringList aStrList = aStr.split( GEOM::subSectionSeparator() );
389 int UIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_u", 1 );
390 int VIso = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "iso_number_v", 1 );
391 if ( aStrList.count() == 2 ) {
392 if ( !aStrList[0].isEmpty() ) UIso = aStrList[0].toInt();
393 if ( !aStrList[1].isEmpty() ) VIso = aStrList[1].toInt();
399 if ( actionType == SHOWDLG ) {
400 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
401 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
403 NbIsosDlg->setU( UIso );
404 NbIsosDlg->setV( VIso );
406 if ( NbIsosDlg->exec() ) {
407 SUIT_OverrideCursor();
408 newNbUIso = NbIsosDlg->getU();
409 newNbVIso = NbIsosDlg->getV();
413 else if ( actionType == INCR || actionType == DECR ) {
415 if (actionType == DECR)
418 newNbUIso = UIso + delta;
419 newNbVIso = VIso + delta;
421 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
425 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
426 Handle( SALOME_InteractiveObject ) io = It.Value();
427 QString anIsos = QString( "%1%2%3" ).arg( newNbUIso ).arg( GEOM::subSectionSeparator() ).arg( newNbVIso );
428 appStudy->setObjectProperty( aMgrId ,io->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos );
429 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
431 displayer.UpdateViewer();
432 GeometryGUI::Modified();
435 void GEOMToolsGUI::OnDeflection()
437 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
440 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
441 if ( !appStudy ) return;
443 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
444 if ( !aSelMgr ) return;
446 SALOME_ListIO selected;
447 aSelMgr->selectedObjects( selected );
448 if ( selected.IsEmpty() ) return;
450 GEOM_Displayer displayer( appStudy );
451 SALOME_View* window = displayer.GetActiveView();
452 if ( !window ) return;
454 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
456 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Deflection ), QVariant() );
457 double aDC = v.isValid() ? v.toDouble() : SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "deflection_coef", 0.001 );
459 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
460 ( SUIT_Session::session()->activeApplication()->desktop() );
461 DeflectionDlg->setTheDC( aDC );
462 if ( DeflectionDlg->exec() ) {
463 SUIT_OverrideCursor();
464 aDC = DeflectionDlg->getTheDC();
466 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
467 Handle( SALOME_InteractiveObject ) io = It.Value();
468 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC );
469 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
472 displayer.UpdateViewer();
473 GeometryGUI::Modified();
476 void GEOMToolsGUI::OnSelectOnly(int mode)
478 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
480 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
481 GEOM_Displayer aDisp (appStudy);
482 aDisp.GlobalSelection(mode);
483 getGeometryGUI()->setLocalSelectionMode(mode);
487 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
489 SALOME_ListIO selected;
490 SalomeApp_Application* app =
491 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
493 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
495 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
498 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
499 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
500 if ( aSelMgr && appStudy ) {
501 aSelMgr->selectedObjects( selected );
502 if ( !selected.IsEmpty() ) {
503 _PTR(Study) aStudy = appStudy->studyDS();
504 _PTR(StudyBuilder) B = aStudy->NewBuilder();
506 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
508 SUIT_MessageBox::warning( app->desktop(),
509 QObject::tr( "WRN_WARNING" ),
510 QObject::tr( "WRN_STUDY_LOCKED" ) );
514 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
515 Handle(SALOME_InteractiveObject) IObject = It.Value();
517 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
518 _PTR(GenericAttribute) anAttr;
520 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
521 aExp->SetExpandable( show );
523 disp->EraseWithChildren(IObject,true);
528 app->updateObjectBrowser( false );
529 app->updateActions();
533 void GEOMToolsGUI::OnPointMarker()
535 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
539 void GEOMToolsGUI::OnMaterialProperties()
541 GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
545 void GEOMToolsGUI::OnMaterialsLibrary()
547 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
548 dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
552 void GEOMToolsGUI::OnUnpublishObject() {
553 SALOME_ListIO selected;
554 SalomeApp_Application* app =
555 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
557 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
559 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
562 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
563 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
564 if ( aSelMgr && appStudy ) {
565 aSelMgr->selectedObjects( selected );
566 if ( !selected.IsEmpty() ) {
567 _PTR(Study) aStudy = appStudy->studyDS();
568 _PTR(StudyBuilder) B = aStudy->NewBuilder();
570 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
572 SUIT_MessageBox::warning( app->desktop(),
573 QObject::tr( "WRN_WARNING" ),
574 QObject::tr( "WRN_STUDY_LOCKED" ) );
578 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
579 Handle(SALOME_InteractiveObject) IObject = It.Value();
581 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
582 _PTR(GenericAttribute) anAttr;
584 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
585 aDrw->SetDrawable( false );
586 disp->EraseWithChildren(IObject);
587 // hide references if any
588 std::vector< _PTR(SObject) > vso = aStudy->FindDependances(obj);
589 for ( int i = 0; i < vso.size(); i++ ) {
590 _PTR(SObject) refObj = vso[i];
591 aDrw = B->FindOrCreateAttribute( refObj, "AttributeDrawable" );
592 aDrw->SetDrawable( false );
596 aSelMgr->clearSelected();
599 app->updateObjectBrowser( false );
600 app->updateActions();
605 void GEOMToolsGUI::OnPublishObject() {
606 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
610 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
614 _PTR(Study) aStudy = appStudy->studyDS();
619 //Check lock of the study
620 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
622 SUIT_MessageBox::warning( app->desktop(),
623 QObject::tr( "WRN_WARNING" ),
624 QObject::tr( "WRN_STUDY_LOCKED" ) );
628 GEOMToolsGUI_PublishDlg* publishDlg =
629 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
634 void GEOMToolsGUI::OnEdgeWidth()
636 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
639 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
640 if ( !appStudy ) return;
642 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
643 if ( !aSelMgr ) return;
645 SALOME_ListIO selected;
646 aSelMgr->selectedObjects( selected );
647 if ( selected.IsEmpty() ) return;
649 GEOM_Displayer displayer( appStudy );
651 SALOME_View* window = displayer.GetActiveView();
652 if ( !window ) return;
654 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
656 GEOMToolsGUI_LineWidthDlg* Dlg =
657 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "EDGE_WIDTH_TLT" );
659 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), QVariant() );
660 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "edge_width", 1 );
662 Dlg->setTheLW( aWidth );
664 SUIT_OverrideCursor();
665 aWidth = Dlg->getTheLW();
667 return; //Cancel case
668 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
669 Handle( SALOME_InteractiveObject ) io = It.Value();
670 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth );
671 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
673 displayer.UpdateViewer();
674 GeometryGUI::Modified();
678 void GEOMToolsGUI::OnIsosWidth() {
679 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
682 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
683 if ( !appStudy ) return;
685 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
686 if ( !aSelMgr ) return;
688 SALOME_ListIO selected;
689 aSelMgr->selectedObjects( selected );
690 if ( selected.IsEmpty() ) return;
692 GEOM_Displayer displayer( appStudy );
694 SALOME_View* window = displayer.GetActiveView();
695 if ( !window ) return;
697 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
699 GEOMToolsGUI_LineWidthDlg* Dlg =
700 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
702 QVariant v = appStudy->getObjectProperty( aMgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), QVariant() );
703 int aWidth = v.isValid() ? v.toInt() : SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "isolines_width", 1 );
705 Dlg->setTheLW( aWidth );
707 SUIT_OverrideCursor();
708 aWidth = Dlg->getTheLW();
710 return; //Cancel case
711 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
712 Handle( SALOME_InteractiveObject ) io = It.Value();
713 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth );
714 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
716 displayer.UpdateViewer();
717 GeometryGUI::Modified();
720 void GEOMToolsGUI::OnBringToFront() {
721 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
724 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy());
725 if (!appStudy) return;
727 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
728 if ( !aSelMgr ) return;
730 SALOME_ListIO selected;
731 aSelMgr->selectedObjects( selected );
732 if ( selected.IsEmpty() ) return;
734 GEOM_Displayer displayer( appStudy );
736 SALOME_View* window = displayer.GetActiveView();
737 if ( !window ) return;
739 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
741 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
742 bool checked = a->isChecked();
744 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
745 Handle( SALOME_InteractiveObject ) io = It.Value();
746 appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
747 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
749 displayer.UpdateViewer();
750 GeometryGUI::Modified();
753 void GEOMToolsGUI::OnClsBringToFront() {
754 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
757 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
758 if ( !appStudy ) return;
760 GEOM_Displayer displayer( appStudy );
762 SALOME_View* window = displayer.GetActiveView();
763 if ( !window ) return;
765 int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
767 SALOME_ListIO anIOlst;
768 window->GetVisible( anIOlst );
770 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
771 Handle( SALOME_InteractiveObject ) io = It.Value();
772 appStudy->setObjectProperty( aMgrId, QString( io->getEntry() ), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
773 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
775 displayer.Redisplay( anIOlst );
776 displayer.UpdateViewer();
777 GeometryGUI::Modified();
780 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
782 if ( !theParam.canConvert<QString>() ) return;
784 QString theName = theParam.toString();
786 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
789 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
790 if ( !study ) return;
792 LightApp_SelectionMgr* selMgr = app->selectionMgr();
794 SALOME_ListIO selected;
795 selMgr->selectedObjects( selected );
797 if ( selected.IsEmpty() ) return;
799 GEOM_Displayer displayer( study );
801 SALOME_View* window = displayer.GetActiveView();
802 if ( !window ) return;
804 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
806 Material_Model aModel;
807 aModel.fromResources( theName );
808 QString prop = aModel.toProperties();
810 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
811 Handle(SALOME_InteractiveObject) io = It.Value();
812 study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
813 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
815 displayer.UpdateViewer();
818 void GEOMToolsGUI::OnCreateFolder()
820 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
823 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
824 if ( !appStudy ) return;
826 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
827 if ( !aSelMgr ) return;
829 SALOME_ListIO selected;
830 aSelMgr->selectedObjects( selected );
831 if ( selected.IsEmpty() ) return;
833 Handle(SALOME_InteractiveObject) anIObject = selected.First();
835 _PTR(Study) aStudy = appStudy->studyDS();
836 if( !aStudy ) return;
837 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
838 if ( !aFatherSO ) return;
840 GeometryGUI::GetGeomGen()->CreateFolder( tr("NEW_FOLDER_NAME").toLatin1().constData(),
841 _CAST(SObject, aFatherSO)->GetSObject() );
842 app->updateObjectBrowser( false );
845 void GEOMToolsGUI::OnSortChildren()
847 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
850 SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
851 if ( !appStudy ) return;
853 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
854 if ( !aSelMgr ) return;
856 SALOME_ListIO selected;
857 aSelMgr->selectedObjects( selected );
858 if ( selected.IsEmpty() ) return;
860 Handle(SALOME_InteractiveObject) anIObject = selected.First();
862 _PTR(Study) aStudy = appStudy->studyDS();
863 if( !aStudy ) return;
864 _PTR(SObject) aFatherSO(aStudy->FindObjectID(anIObject->getEntry()));
865 if ( !aFatherSO ) return;
867 aStudy->GetUseCaseBuilder()->SortChildren( aFatherSO, true/*AscendingOrder*/ );
869 app->updateObjectBrowser( true );
872 void GEOMToolsGUI::OnShowDependencyTree()
874 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
876 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
879 SUIT_ViewManager *svm = app->getViewManager( GraphicsView_Viewer::Type(), false );
882 DependencyTree_View* view = new DependencyTree_View();
883 DependencyTree_ViewModel* viewModel = new DependencyTree_ViewModel( GraphicsView_Viewer::Type(), view );
884 SUIT_ViewManager *svm = app->createViewManager( viewModel );
886 LightApp_SelectionMgr* selMgr = app->selectionMgr();
887 new DependencyTree_Selector( viewModel, (SUIT_SelectionMgr*)selMgr );
889 SUIT_ViewWindow* svw = svm->getActiveView();
890 GraphicsView_ViewFrame* aViewFrame = 0;
891 if (!svw) svw = svm->createViewWindow();
892 if (svw) aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>(svw);
894 view->init( aViewFrame );
895 svm->setTitle( view->getViewName() );
898 if( DependencyTree_ViewModel* viewModel = dynamic_cast<DependencyTree_ViewModel*>( svm->getViewModel() ) )
899 if( DependencyTree_View* view = dynamic_cast<DependencyTree_View*>( viewModel->getActiveViewPort() ) ) {
900 svm->getActiveView()->setFocus();
905 void GEOMToolsGUI::OnReduceStudy()
907 QDialog* dlg = new GEOMToolsGUI_ReduceStudyDlg( SUIT_Session::session()->activeApplication()->desktop() );