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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GEOMToolsGUI_1.cxx
24 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26 #include <PyConsole_Console.h>
28 #include "GEOMToolsGUI.h"
29 #include "GEOMToolsGUI_TransparencyDlg.h"
30 #include "GEOMToolsGUI_NbIsosDlg.h"
31 #include "GEOMToolsGUI_DeflectionDlg.h"
32 #include "GEOMToolsGUI_MarkerDlg.h"
33 #include "GEOMToolsGUI_PublishDlg.h"
35 #include <GeometryGUI.h>
36 #include <GEOM_Displayer.h>
39 #include <GEOM_Actor.h>
41 #include <CASCatch_OCCTVersion.hxx>
43 #include <SALOME_ListIO.hxx>
44 #include <SALOME_ListIteratorOfListIO.hxx>
49 #include <SVTK_ViewModel.h>
50 #include <SVTK_ViewWindow.h>
51 #include <SVTK_View.h>
53 #include <OCCViewer_ViewModel.h>
55 #include <SUIT_ViewManager.h>
56 #include <SUIT_Desktop.h>
57 #include <SUIT_ResourceMgr.h>
58 #include <SUIT_Session.h>
59 #include <SUIT_OverrideCursor.h>
60 #include <SUIT_MessageBox.h>
61 #include <SUIT_Tools.h>
63 #include <SalomeApp_Application.h>
64 #include <SalomeApp_Study.h>
65 #include <SalomeApp_Module.h>
67 #include <LightApp_SelectionMgr.h>
68 #include <LightApp_NameDlg.h>
70 #include <GEOMImpl_Types.hxx>
72 #include "utilities.h"
75 #include <AIS_Drawer.hxx>
76 #include <Prs3d_IsoAspect.hxx>
77 #include <Prs3d_PointAspect.hxx>
78 #include <Graphic3d_AspectMarker3d.hxx>
80 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
81 #include <TColStd_HArray1OfByte.hxx>
83 #include <Graphic3d_HArray1OfBytes.hxx>
87 #include <QColorDialog>
88 #include <QInputDialog>
91 #include <QGridLayout>
94 #include <QPushButton>
98 #include <vtkRenderer.h>
101 void GEOMToolsGUI::OnCheckGeometry()
103 SalomeApp_Application* app =
104 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
105 PyConsole_Console* pyConsole = app->pythonConsole();
108 pyConsole->exec("from GEOM_usinggeom import *");
111 void GEOMToolsGUI::OnAutoColor()
113 SALOME_ListIO selected;
114 SalomeApp_Application* app =
115 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
119 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
120 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
121 if (!aSelMgr || !appStudy)
124 aSelMgr->selectedObjects(selected);
125 if (selected.IsEmpty())
128 Handle(SALOME_InteractiveObject) anIObject = selected.First();
130 _PTR(Study) aStudy = appStudy->studyDS();
131 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
132 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
133 if (CORBA::is_nil(aMainObject))
136 aMainObject->SetAutoColor( true );
138 QList<SALOMEDS::Color> aReservedColors;
140 GEOM_Displayer aDisp (appStudy);
142 SALOME_View* vf = aDisp.GetActiveView();
144 SUIT_ViewWindow* window = app->desktop()->activeWindow();
145 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
146 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
148 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
150 _PTR(SObject) aChildSObject( it->Value() );
151 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
152 if( CORBA::is_nil( aChildObject ) )
155 if( aChildObject->GetType() != GEOM_GROUP )
158 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
159 aChildObject->SetColor( aColor );
160 aReservedColors.append( aColor );
162 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
164 SALOME_Prs* aPrs = vf->CreatePrs( aChildSObject->GetID().c_str() );
168 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
171 SVTK_View* aView = vtkVW->getView();
172 SUIT_OverrideCursor();
173 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
174 aView->SetColor( It.Value(), c );
178 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
179 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
181 SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
185 AIS_ListOfInteractive aList;
186 anOCCPrs->GetObjects( aList );
187 if( !aList.Extent() )
190 Handle(AIS_InteractiveObject) io = aList.First();
194 Quantity_Color aQuanColor( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
196 // Set color for a point
197 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
198 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
199 Quantity_Color aCurColor;
200 Standard_Real aCurScale;
201 Aspect_TypeOfMarker aCurTypeOfMarker;
202 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
203 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
204 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
207 Standard_Integer aWidth, aHeight;
208 aCurPointAspect->GetTextureSize( aWidth, aHeight );
210 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
211 Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
213 Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
216 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aQuanColor, 1, aWidth, aHeight, aTexture ) );
218 ic->SetLocalAttributes( io, aCurDrawer );
220 io->SetColor( aQuanColor );
221 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
222 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aQuanColor );
224 io->Redisplay( Standard_True );
228 app->updateActions(); //SRN: To update a Save button in the toolbar
231 void GEOMToolsGUI::OnDisableAutoColor()
233 SALOME_ListIO selected;
234 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
238 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
239 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
240 if( !aSelMgr || !appStudy )
243 aSelMgr->selectedObjects( selected );
244 if( selected.IsEmpty() )
247 Handle(SALOME_InteractiveObject) anIObject = selected.First();
249 _PTR(Study) aStudy = appStudy->studyDS();
250 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
251 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
252 if( CORBA::is_nil( aMainObject ) )
255 aMainObject->SetAutoColor( false );
259 void GEOMToolsGUI::OnColor()
261 SALOME_ListIO selected;
262 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
263 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
264 if ( app && appStudy ) {
265 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
267 aSelMgr->selectedObjects( selected );
268 if ( !selected.IsEmpty() ) {
269 SUIT_ViewWindow* window = app->desktop()->activeWindow();
270 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
271 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
272 int mgrId = window->getViewManager()->getGlobalId();
274 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
277 SVTK_View* aView = vtkVW->getView();
278 QColor initcolor = aView->GetColor( selected.First() );
279 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
281 SUIT_OverrideCursor();
282 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
283 aView->SetColor( It.Value(), c );
284 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c);
286 GeometryGUI::Modified();
290 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
291 if ( !io.IsNull() ) {
292 Quantity_Color aColor;
294 QColor initcolor ((int)( aColor.Red() * 255.0 ),
295 (int)( aColor.Green() * 255.0 ),
296 (int)( aColor.Blue() * 255.0 ));
297 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
299 SUIT_OverrideCursor();
300 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
301 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
302 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
303 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
304 io = GEOMBase::GetAIS( It.Value(), true );
305 if ( !io.IsNull() ) {
307 if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) {
308 TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape();
309 bool onlyVertex = (theShape.ShapeType() == TopAbs_VERTEX || GEOM_Displayer::isCompoundOfVertices( theShape ));
311 // Set color for a point
313 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
314 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
315 Quantity_Color aCurColor;
316 Standard_Real aCurScale;
317 Aspect_TypeOfMarker aCurTypeOfMarker;
318 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
319 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
320 aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aCurTypeOfMarker, aColor, aCurScale));
323 Standard_Integer aWidth, aHeight;
324 aCurPointAspect->GetTextureSize( aWidth, aHeight );
326 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
327 Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
329 Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
332 aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aColor, 1, aWidth, aHeight, aTexture));
334 ic->SetLocalAttributes(io, aCurDrawer, Standard_False);
338 io->SetColor( aColor );
339 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
340 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
342 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(), COLOR_PROP, c);
344 io->Redisplay( Standard_True );
346 // store color to GEOM_Object
347 _PTR(Study) aStudy = appStudy->studyDS();
348 _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
349 GEOM::GEOM_Object_var anObject =
350 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
353 SALOMEDS::Color aSColor;
354 aSColor.R = (double)c.red() / 255.0;
355 aSColor.G = (double)c.green() / 255.0;
356 aSColor.B = (double)c.blue() / 255.0;
357 anObject->SetColor( aSColor );
358 anObject->SetAutoColor( false );
361 ic->UpdateCurrentViewer();
362 GeometryGUI::Modified();
364 } // first IO is not null
366 } // if ( selection not empty )
370 app->updateActions(); //SRN: To update a Save button in the toolbar
373 void GEOMToolsGUI::OnTransparency()
375 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
379 void GEOMToolsGUI::OnChangeTransparency( bool increase )
381 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
384 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
387 SALOME_ListIO selected;
388 aSelMgr->selectedObjects( selected );
389 if ( selected.IsEmpty() )
392 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
393 if ( FirstIOS.IsNull() )
397 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
401 SUIT_ViewWindow* window = app->desktop()->activeWindow();
402 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
403 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
406 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
409 SVTK_View* aView = vtkVW->getView();
411 float transp = aView->GetTransparency(FirstIOS);
413 // Compute new transparency value
414 transp = transp + delta;
417 else if ( transp > 1 )
420 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
421 aView->SetTransparency( It.Value(), transp );
424 GeometryGUI::Modified();
428 GEOMBase* gb = new GEOMBase();
429 Handle(GEOM_AISShape) aisShape;
431 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
432 if( aisShape.IsNull() )
434 float transp = aisShape->Transparency();
436 // Compute new transparency value
437 transp = transp + delta;
440 else if ( transp > 1 )
443 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
446 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
447 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
448 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
449 if ( !aisShape.IsNull() ) {
450 ic->SetTransparency( aisShape, transp, false );
451 ic->Redisplay( aisShape, Standard_False, Standard_True );
454 ic->UpdateCurrentViewer();
455 GeometryGUI::Modified();
459 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
461 SalomeApp_Application* app =
462 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
463 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
464 SUIT_ViewWindow* window = app->desktop()->activeWindow();
466 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
467 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
469 if(isOCC){ // if is OCCViewer
471 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
472 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
475 if ( ic->MoreCurrent() ) {
476 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
477 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
479 int UIso = CurDrawer->UIsoAspect()->Number();
480 int VIso = CurDrawer->VIsoAspect()->Number();
485 if ( actionType == SHOWDLG ) {
486 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
487 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
489 NbIsosDlg->setU( UIso );
490 NbIsosDlg->setV( VIso );
492 if ( NbIsosDlg->exec() ) {
493 SUIT_OverrideCursor();
495 newNbUIso = NbIsosDlg->getU();
496 newNbVIso = NbIsosDlg->getV();
500 else if ( actionType == INCR || actionType == DECR ) {
502 if (actionType == DECR)
505 newNbUIso = UIso + delta;
506 newNbVIso = VIso + delta;
508 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
512 for(; ic->MoreCurrent(); ic->NextCurrent()) {
513 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
515 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
517 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbUIso) );
518 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbVIso) );
520 ic->SetLocalAttributes(CurObject, CurDrawer);
521 ic->Redisplay(CurObject);
523 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
524 int aMgrId = window->getViewManager()->getGlobalId();
525 aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), "Isos", anIsos);
528 GeometryGUI::Modified();
530 else if(isVTK){ // if is VTKViewer
532 // Warning. It's works incorrect. must be recheked.
534 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
535 ( SUIT_Session::session()->activeApplication() );
538 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
541 SALOME_ListIO selected;
542 aSelMgr->selectedObjects( selected );
543 if ( selected.IsEmpty() )
546 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
550 SALOME_View* view = GEOM_Displayer::GetActiveView();
552 vtkActorCollection* aCollection = vtkActorCollection::New();
554 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
555 Handle(SALOME_InteractiveObject) anIObject = It.Value();
556 SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
557 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
559 vtkActorCollection* anActors = vtkPrs->GetObjects();
560 anActors->InitTraversal();
561 vtkActor* anAct = anActors->GetNextActor();
562 aCollection->AddItem(anAct);
567 aCollection->InitTraversal();
574 vtkActor* anAct = aCollection->GetNextActor();
575 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
576 anActor->GetNbIsos(UIso,VIso);
583 if ( actionType == SHOWDLG ) {
584 GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
585 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
587 NbIsosDlg->setU( UIso );
588 NbIsosDlg->setV( VIso );
590 if ( NbIsosDlg->exec() ) {
591 SUIT_OverrideCursor();
593 newNbUIso = NbIsosDlg->getU();
594 newNbVIso = NbIsosDlg->getV();
596 return; //Cancel case
598 else if ( actionType == INCR || actionType == DECR ) {
600 if (actionType == DECR)
603 newNbUIso = UIso + delta;
604 newNbVIso = VIso + delta;
606 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
610 while( anAct!=NULL ) {
611 if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
612 // There are no casting to needed actor.
613 int aIsos[2]={newNbUIso,newNbVIso};
614 anActor->SetNbIsos(aIsos);
616 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
617 int aMgrId = window->getViewManager()->getGlobalId();
618 aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos);
620 anAct = aCollection->GetNextActor();
623 GeometryGUI::Modified();
627 void GEOMToolsGUI::OnDeflection()
629 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
630 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
633 bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
634 bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
635 int mgrId = window->getViewManager()->getGlobalId();
637 if (isOCC) { // if is OCCViewer
638 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
639 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
642 if (ic->MoreCurrent()) {
643 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
645 Standard_Real aDC, aPrevDC;
646 Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
648 aDC = ic->DeviationCoefficient();
650 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
651 (SUIT_Session::session()->activeApplication()->desktop());
652 DeflectionDlg->setTheDC(aDC);
656 if (DeflectionDlg->exec()) {
657 SUIT_OverrideCursor();
658 aNewDC = DeflectionDlg->getTheDC();
659 ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
661 for (; ic->MoreCurrent(); ic->NextCurrent()) {
662 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
663 ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
664 ic->Redisplay(CurObject);
665 appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC);
674 GeometryGUI::Modified();
676 else if (isVTK) { // if is VTKViewer
677 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
678 (SUIT_Session::session()->activeApplication());
682 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
686 SALOME_ListIO selected;
687 aSelMgr->selectedObjects(selected);
688 if (selected.IsEmpty())
691 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
695 SALOME_View* view = GEOM_Displayer::GetActiveView();
697 vtkActorCollection* aCollection = vtkActorCollection::New();
699 for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
700 Handle(SALOME_InteractiveObject) anIObject = It.Value();
701 SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
702 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
704 vtkActorCollection* anActors = vtkPrs->GetObjects();
705 anActors->InitTraversal();
706 vtkActor* anAct = anActors->GetNextActor();
707 aCollection->AddItem(anAct);
712 aCollection->InitTraversal();
718 vtkActor* anAct = aCollection->GetNextActor();
719 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
720 aDC = anActor->GetDeflection();
724 GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
725 (SUIT_Session::session()->activeApplication()->desktop());
726 DeflectionDlg->setTheDC(aDC);
727 if (DeflectionDlg->exec()) {
728 SUIT_OverrideCursor();
729 aDC = DeflectionDlg->getTheDC();
730 while (anAct != NULL) {
731 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
732 // There are no casting to needed actor.
733 anActor->SetDeflection(aDC);
734 appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC);
736 anAct = aCollection->GetNextActor();
739 GeometryGUI::Modified();
743 void GEOMToolsGUI::OnSelectOnly(int mode)
745 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
747 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
748 GEOM_Displayer aDisp (appStudy);
749 aDisp.GlobalSelection(mode);
750 getGeometryGUI()->setLocalSelectionMode(mode);
754 void GEOMToolsGUI::OnShowHideChildren( bool show )
756 SALOME_ListIO selected;
757 SalomeApp_Application* app =
758 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
760 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
762 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
765 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
766 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
767 if ( aSelMgr && appStudy ) {
768 aSelMgr->selectedObjects( selected );
769 if ( !selected.IsEmpty() ) {
770 _PTR(Study) aStudy = appStudy->studyDS();
771 _PTR(StudyBuilder) B = aStudy->NewBuilder();
773 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
775 SUIT_MessageBox::warning( app->desktop(),
776 QObject::tr( "WRN_WARNING" ),
777 QObject::tr( "WRN_STUDY_LOCKED" ) );
781 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
782 Handle(SALOME_InteractiveObject) IObject = It.Value();
784 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
785 _PTR(GenericAttribute) anAttr;
787 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
788 aExp->SetExpandable( show );
790 disp->EraseWithChildren(IObject,true);
795 app->updateObjectBrowser( false );
796 app->updateActions();
800 void GEOMToolsGUI::OnPointMarker()
802 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
807 void GEOMToolsGUI::OnUnpublishObject() {
808 SALOME_ListIO selected;
809 SalomeApp_Application* app =
810 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
812 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
814 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
817 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
818 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
819 if ( aSelMgr && appStudy ) {
820 aSelMgr->selectedObjects( selected );
821 if ( !selected.IsEmpty() ) {
822 _PTR(Study) aStudy = appStudy->studyDS();
823 _PTR(StudyBuilder) B = aStudy->NewBuilder();
825 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
827 SUIT_MessageBox::warning( app->desktop(),
828 QObject::tr( "WRN_WARNING" ),
829 QObject::tr( "WRN_STUDY_LOCKED" ) );
833 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
834 Handle(SALOME_InteractiveObject) IObject = It.Value();
836 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
837 _PTR(GenericAttribute) anAttr;
839 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
840 aDrw->SetDrawable( false );
841 disp->EraseWithChildren(IObject);
844 aSelMgr->clearSelected();
847 app->updateObjectBrowser( false );
848 app->updateActions();
853 void GEOMToolsGUI::OnPublishObject() {
854 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
858 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
862 _PTR(Study) aStudy = appStudy->studyDS();
867 //Check lock of the study
868 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
870 SUIT_MessageBox::warning( app->desktop(),
871 QObject::tr( "WRN_WARNING" ),
872 QObject::tr( "WRN_STUDY_LOCKED" ) );
876 GEOMToolsGUI_PublishDlg * publishDlg =
877 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );