1 // Copyright (C) 2007-2011 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"
36 #include <GeometryGUI.h>
37 #include <GEOM_Displayer.h>
40 #include <GEOM_Actor.h>
42 #include <SALOME_ListIO.hxx>
43 #include <SALOME_ListIteratorOfListIO.hxx>
48 #include <SVTK_ViewModel.h>
49 #include <SVTK_ViewWindow.h>
50 #include <SVTK_View.h>
52 #include <OCCViewer_ViewModel.h>
54 #include <SUIT_ViewManager.h>
55 #include <SUIT_Desktop.h>
56 #include <SUIT_ResourceMgr.h>
57 #include <SUIT_Session.h>
58 #include <SUIT_OverrideCursor.h>
59 #include <SUIT_MessageBox.h>
60 #include <SUIT_Tools.h>
62 #include <SalomeApp_Application.h>
63 #include <SalomeApp_Study.h>
64 #include <SalomeApp_Module.h>
66 #include <LightApp_SelectionMgr.h>
67 #include <LightApp_NameDlg.h>
69 #include <GEOMImpl_Types.hxx>
71 #include "utilities.h"
74 #include <AIS_Drawer.hxx>
75 #include <Prs3d_IsoAspect.hxx>
76 #include <Prs3d_PointAspect.hxx>
77 #include <Graphic3d_AspectMarker3d.hxx>
78 #include <Graphic3d_HArray1OfBytes.hxx>
81 #include <QColorDialog>
82 #include <QInputDialog>
85 #include <QGridLayout>
88 #include <QPushButton>
92 #include <vtkRenderer.h>
95 void GEOMToolsGUI::OnCheckGeometry()
97 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
98 PyConsole_Console* pyConsole = app->pythonConsole();
101 pyConsole->exec("from GEOM_usinggeom import *");
104 void GEOMToolsGUI::OnAutoColor()
106 SALOME_ListIO selected;
107 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
111 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
112 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
113 if( !aSelMgr || !appStudy )
116 aSelMgr->selectedObjects( selected );
117 if( selected.IsEmpty() )
120 Handle(SALOME_InteractiveObject) anIObject = selected.First();
122 _PTR(Study) aStudy = appStudy->studyDS();
123 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
124 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
125 if( CORBA::is_nil( aMainObject ) )
128 aMainObject->SetAutoColor( true );
130 QList<SALOMEDS::Color> aReservedColors;
132 GEOM_Displayer aDisp (appStudy);
134 SALOME_View* vf = aDisp.GetActiveView();
136 SUIT_ViewWindow* window = app->desktop()->activeWindow();
137 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
138 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
140 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
142 _PTR(SObject) aChildSObject( it->Value() );
143 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
144 if( CORBA::is_nil( aChildObject ) )
147 if( aChildObject->GetType() != GEOM_GROUP )
150 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
151 aChildObject->SetColor( aColor );
152 aReservedColors.append( aColor );
154 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
156 SALOME_Prs* aPrs = vf->CreatePrs( aChildSObject->GetID().c_str() );
160 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
163 SVTK_View* aView = vtkVW->getView();
164 SUIT_OverrideCursor();
165 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
166 aView->SetColor( It.Value(), c );
170 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
171 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
173 SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
177 AIS_ListOfInteractive aList;
178 anOCCPrs->GetObjects( aList );
179 if( !aList.Extent() )
182 Handle(AIS_InteractiveObject) io = aList.First();
186 Quantity_Color aQuanColor( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
188 // Set color for a point
189 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
190 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
191 Quantity_Color aCurColor;
192 Standard_Real aCurScale;
193 Aspect_TypeOfMarker aCurTypeOfMarker;
194 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
195 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
196 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
199 Standard_Integer aWidth, aHeight;
200 aCurPointAspect->GetTextureSize( aWidth, aHeight );
201 Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
202 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aQuanColor, 1, aWidth, aHeight, aTexture ) );
204 ic->SetLocalAttributes( io, aCurDrawer );
206 io->SetColor( aQuanColor );
207 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
208 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aQuanColor );
210 io->Redisplay( Standard_True );
214 app->updateActions(); //SRN: To update a Save button in the toolbar
217 void GEOMToolsGUI::OnDisableAutoColor()
219 SALOME_ListIO selected;
220 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
224 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
225 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
226 if( !aSelMgr || !appStudy )
229 aSelMgr->selectedObjects( selected );
230 if( selected.IsEmpty() )
233 Handle(SALOME_InteractiveObject) anIObject = selected.First();
235 _PTR(Study) aStudy = appStudy->studyDS();
236 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
237 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
238 if( CORBA::is_nil( aMainObject ) )
241 aMainObject->SetAutoColor( false );
245 void GEOMToolsGUI::OnColor()
247 SALOME_ListIO selected;
248 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
249 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
250 if ( app && appStudy ) {
251 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
253 aSelMgr->selectedObjects( selected );
254 if ( !selected.IsEmpty() ) {
255 SUIT_ViewWindow* window = app->desktop()->activeWindow();
256 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
257 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
258 int mgrId = window->getViewManager()->getGlobalId();
260 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
263 SVTK_View* aView = vtkVW->getView();
264 QColor initcolor = aView->GetColor( selected.First() );
265 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
267 SUIT_OverrideCursor();
268 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
269 aView->SetColor( It.Value(), c );
270 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c);
272 GeometryGUI::Modified();
276 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
277 if ( !io.IsNull() ) {
278 Quantity_Color aColor;
280 QColor initcolor ((int)( aColor.Red() * 255.0 ),
281 (int)( aColor.Green() * 255.0 ),
282 (int)( aColor.Blue() * 255.0 ));
283 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
285 SUIT_OverrideCursor();
286 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
287 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
288 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
289 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
290 io = GEOMBase::GetAIS( It.Value(), true );
291 if ( !io.IsNull() ) {
293 if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) {
294 TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape();
295 bool onlyVertex = (theShape.ShapeType() == TopAbs_VERTEX || GEOM_Displayer::isCompoundOfVertices( theShape ));
297 // Set color for a point
299 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
300 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
301 Quantity_Color aCurColor;
302 Standard_Real aCurScale;
303 Aspect_TypeOfMarker aCurTypeOfMarker;
304 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
305 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
306 aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aCurTypeOfMarker, aColor, aCurScale));
309 Standard_Integer aWidth, aHeight;
310 aCurPointAspect->GetTextureSize( aWidth, aHeight );
311 Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
312 aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aColor, 1, aWidth, aHeight, aTexture));
314 ic->SetLocalAttributes(io, aCurDrawer, Standard_False);
318 io->SetColor( aColor );
319 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
320 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
322 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(), COLOR_PROP, c);
324 io->Redisplay( Standard_True );
326 // store color to GEOM_Object
327 _PTR(Study) aStudy = appStudy->studyDS();
328 _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
329 GEOM::GEOM_Object_var anObject =
330 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
333 SALOMEDS::Color aSColor;
334 aSColor.R = (double)c.red() / 255.0;
335 aSColor.G = (double)c.green() / 255.0;
336 aSColor.B = (double)c.blue() / 255.0;
337 anObject->SetColor( aSColor );
338 anObject->SetAutoColor( false );
341 ic->UpdateCurrentViewer();
342 GeometryGUI::Modified();
344 } // first IO is not null
346 } // if ( selection not empty )
350 app->updateActions(); //SRN: To update a Save button in the toolbar
353 void GEOMToolsGUI::OnTransparency()
355 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
359 void GEOMToolsGUI::OnChangeTransparency( bool increase )
361 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
364 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
367 SALOME_ListIO selected;
368 aSelMgr->selectedObjects( selected );
369 if ( selected.IsEmpty() )
372 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
373 if ( FirstIOS.IsNull() )
377 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
381 SUIT_ViewWindow* window = app->desktop()->activeWindow();
382 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
383 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
386 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
389 SVTK_View* aView = vtkVW->getView();
391 float transp = aView->GetTransparency(FirstIOS);
393 // Compute new transparency value
394 transp = transp + delta;
397 else if ( transp > 1 )
400 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
401 aView->SetTransparency( It.Value(), transp );
404 GeometryGUI::Modified();
408 GEOMBase* gb = new GEOMBase();
409 Handle(GEOM_AISShape) aisShape;
411 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
412 if( aisShape.IsNull() )
414 float transp = aisShape->Transparency();
416 // Compute new transparency value
417 transp = transp + delta;
420 else if ( transp > 1 )
423 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
426 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
427 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
428 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
429 if ( !aisShape.IsNull() ) {
430 ic->SetTransparency( aisShape, transp, false );
431 ic->Redisplay( aisShape, Standard_False, Standard_True );
434 ic->UpdateCurrentViewer();
435 GeometryGUI::Modified();
439 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
441 SalomeApp_Application* app =
442 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
443 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
444 SUIT_ViewWindow* window = app->desktop()->activeWindow();
446 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
447 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
449 if(isOCC){ // if is OCCViewer
451 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
452 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
455 if ( ic->MoreCurrent() ) {
456 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
457 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
459 int UIso = CurDrawer->UIsoAspect()->Number();
460 int VIso = CurDrawer->VIsoAspect()->Number();
465 if ( actionType == SHOWDLG ) {
466 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
467 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
469 NbIsosDlg->setU( UIso );
470 NbIsosDlg->setV( VIso );
472 if ( NbIsosDlg->exec() ) {
473 SUIT_OverrideCursor();
475 newNbUIso = NbIsosDlg->getU();
476 newNbVIso = NbIsosDlg->getV();
480 else if ( actionType == INCR || actionType == DECR ) {
482 if (actionType == DECR)
485 newNbUIso = UIso + delta;
486 newNbVIso = VIso + delta;
488 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
492 for(; ic->MoreCurrent(); ic->NextCurrent()) {
493 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
497 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
499 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbUIso) );
500 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbVIso) );
502 ic->SetLocalAttributes(CurObject, CurDrawer);
503 ic->Redisplay(CurObject);
505 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
506 int aMgrId = window->getViewManager()->getGlobalId();
507 aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), "Isos", anIsos);
510 GeometryGUI::Modified();
512 else if(isVTK){ // if is VTKViewer
514 // Warning. It's works incorrect. must be recheked.
516 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
517 ( SUIT_Session::session()->activeApplication() );
520 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
523 SALOME_ListIO selected;
524 aSelMgr->selectedObjects( selected );
525 if ( selected.IsEmpty() )
528 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
532 SALOME_View* view = GEOM_Displayer::GetActiveView();
534 vtkActorCollection* aCollection = vtkActorCollection::New();
536 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
537 Handle(SALOME_InteractiveObject) anIObject = It.Value();
538 SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
539 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
541 vtkActorCollection* anActors = vtkPrs->GetObjects();
542 anActors->InitTraversal();
543 vtkActor* anAct = anActors->GetNextActor();
544 aCollection->AddItem(anAct);
549 aCollection->InitTraversal();
556 vtkActor* anAct = aCollection->GetNextActor();
557 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
558 anActor->GetNbIsos(UIso,VIso);
565 if ( actionType == SHOWDLG ) {
566 GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
567 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
569 NbIsosDlg->setU( UIso );
570 NbIsosDlg->setV( VIso );
572 if ( NbIsosDlg->exec() ) {
573 SUIT_OverrideCursor();
575 newNbUIso = NbIsosDlg->getU();
576 newNbVIso = NbIsosDlg->getV();
578 return; //Cancel case
580 else if ( actionType == INCR || actionType == DECR ) {
582 if (actionType == DECR)
585 newNbUIso = UIso + delta;
586 newNbVIso = VIso + delta;
588 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
592 while( anAct!=NULL ) {
593 if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
594 // There are no casting to needed actor.
595 int aIsos[2]={newNbUIso,newNbVIso};
596 anActor->SetNbIsos(aIsos);
598 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
599 int aMgrId = window->getViewManager()->getGlobalId();
600 aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos);
602 anAct = aCollection->GetNextActor();
605 GeometryGUI::Modified();
609 void GEOMToolsGUI::OnDeflection()
611 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
612 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
615 bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
616 bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
617 int mgrId = window->getViewManager()->getGlobalId();
619 if (isOCC) { // if is OCCViewer
620 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
621 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
624 if (ic->MoreCurrent()) {
625 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
627 Standard_Real aDC, aPrevDC;
628 Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
630 aDC = ic->DeviationCoefficient();
632 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
633 (SUIT_Session::session()->activeApplication()->desktop());
634 DeflectionDlg->setTheDC(aDC);
638 if (DeflectionDlg->exec()) {
639 SUIT_OverrideCursor();
640 aNewDC = DeflectionDlg->getTheDC();
641 ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
643 for (; ic->MoreCurrent(); ic->NextCurrent()) {
644 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
645 ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
646 ic->Redisplay(CurObject);
647 appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC);
656 GeometryGUI::Modified();
658 else if (isVTK) { // if is VTKViewer
659 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
660 (SUIT_Session::session()->activeApplication());
664 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
668 SALOME_ListIO selected;
669 aSelMgr->selectedObjects(selected);
670 if (selected.IsEmpty())
673 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
677 SALOME_View* view = GEOM_Displayer::GetActiveView();
679 vtkActorCollection* aCollection = vtkActorCollection::New();
681 for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
682 Handle(SALOME_InteractiveObject) anIObject = It.Value();
683 SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
684 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
686 vtkActorCollection* anActors = vtkPrs->GetObjects();
687 anActors->InitTraversal();
688 vtkActor* anAct = anActors->GetNextActor();
689 aCollection->AddItem(anAct);
694 aCollection->InitTraversal();
700 vtkActor* anAct = aCollection->GetNextActor();
701 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
702 aDC = anActor->GetDeflection();
706 GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
707 (SUIT_Session::session()->activeApplication()->desktop());
708 DeflectionDlg->setTheDC(aDC);
709 if (DeflectionDlg->exec()) {
710 SUIT_OverrideCursor();
711 aDC = DeflectionDlg->getTheDC();
712 while (anAct != NULL) {
713 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
714 // There are no casting to needed actor.
715 anActor->SetDeflection(aDC);
716 appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC);
718 anAct = aCollection->GetNextActor();
721 GeometryGUI::Modified();
725 void GEOMToolsGUI::OnSelectOnly(int mode)
727 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
729 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
730 GEOM_Displayer aDisp (appStudy);
731 aDisp.GlobalSelection(mode);
732 getGeometryGUI()->setLocalSelectionMode(mode);
736 void GEOMToolsGUI::OnShowHideChildren( bool show )
738 SALOME_ListIO selected;
739 SalomeApp_Application* app =
740 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
742 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
744 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
747 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
748 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
749 if ( aSelMgr && appStudy ) {
750 aSelMgr->selectedObjects( selected );
751 if ( !selected.IsEmpty() ) {
752 _PTR(Study) aStudy = appStudy->studyDS();
753 _PTR(StudyBuilder) B = aStudy->NewBuilder();
755 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
757 SUIT_MessageBox::warning( app->desktop(),
758 QObject::tr( "WRN_WARNING" ),
759 QObject::tr( "WRN_STUDY_LOCKED" ) );
763 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
764 Handle(SALOME_InteractiveObject) IObject = It.Value();
766 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
767 _PTR(GenericAttribute) anAttr;
769 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
770 aExp->SetExpandable( show );
772 disp->EraseWithChildren(IObject,true);
777 app->updateObjectBrowser( false );
778 app->updateActions();
782 void GEOMToolsGUI::OnPointMarker()
784 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
789 void GEOMToolsGUI::OnUnpublishObject() {
790 SALOME_ListIO selected;
791 SalomeApp_Application* app =
792 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
794 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
796 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
799 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
800 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
801 if ( aSelMgr && appStudy ) {
802 aSelMgr->selectedObjects( selected );
803 if ( !selected.IsEmpty() ) {
804 _PTR(Study) aStudy = appStudy->studyDS();
805 _PTR(StudyBuilder) B = aStudy->NewBuilder();
807 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
809 SUIT_MessageBox::warning( app->desktop(),
810 QObject::tr( "WRN_WARNING" ),
811 QObject::tr( "WRN_STUDY_LOCKED" ) );
815 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
816 Handle(SALOME_InteractiveObject) IObject = It.Value();
818 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
819 _PTR(GenericAttribute) anAttr;
821 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
822 aDrw->SetDrawable( false );
823 disp->EraseWithChildren(IObject);
826 aSelMgr->clearSelected();
829 app->updateObjectBrowser( false );
830 app->updateActions();
835 void GEOMToolsGUI::OnPublishObject() {
836 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
840 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
844 _PTR(Study) aStudy = appStudy->studyDS();
849 //Check lock of the study
850 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
852 SUIT_MessageBox::warning( app->desktop(),
853 QObject::tr( "WRN_WARNING" ),
854 QObject::tr( "WRN_STUDY_LOCKED" ) );
858 GEOMToolsGUI_PublishDlg * publishDlg =
859 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );