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"
34 #include "GEOMToolsGUI_MaterialPropertiesDlg.h"
36 #include <GeometryGUI.h>
37 #include <GeometryGUI_Operations.h>
38 #include <GEOM_Constants.h>
39 #include <GEOM_Displayer.h>
42 #include <GEOM_Actor.h>
44 #include <Basics_OCCTVersion.hxx>
46 #include <SALOME_ListIO.hxx>
47 #include <SALOME_ListIteratorOfListIO.hxx>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SVTK_View.h>
56 #include <OCCViewer_ViewModel.h>
58 #include <SUIT_ViewManager.h>
59 #include <SUIT_Desktop.h>
60 #include <SUIT_ResourceMgr.h>
61 #include <SUIT_Session.h>
62 #include <SUIT_OverrideCursor.h>
63 #include <SUIT_MessageBox.h>
64 #include <SUIT_Tools.h>
66 #include <SalomeApp_Application.h>
67 #include <SalomeApp_Study.h>
68 #include <SalomeApp_Module.h>
70 #include <LightApp_SelectionMgr.h>
71 #include <LightApp_NameDlg.h>
73 #include <GEOMImpl_Types.hxx>
75 #include "utilities.h"
78 #include <AIS_Drawer.hxx>
79 #include <Prs3d_IsoAspect.hxx>
80 #include <Prs3d_PointAspect.hxx>
81 #include <Graphic3d_AspectMarker3d.hxx>
83 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
84 #include <TColStd_HArray1OfByte.hxx>
86 #include <Graphic3d_HArray1OfBytes.hxx>
90 #include <QColorDialog>
91 #include <QInputDialog>
92 #include <QFileDialog>
95 #include <QGridLayout>
98 #include <QPushButton>
102 #include <vtkRenderer.h>
105 void GEOMToolsGUI::OnCheckGeometry()
107 SalomeApp_Application* app =
108 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
109 PyConsole_Console* pyConsole = app->pythonConsole();
112 pyConsole->exec("from GEOM_usinggeom import *");
115 void GEOMToolsGUI::OnAutoColor()
117 SALOME_ListIO selected;
118 SalomeApp_Application* app =
119 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
123 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
124 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
125 if (!aSelMgr || !appStudy)
128 aSelMgr->selectedObjects(selected);
129 if (selected.IsEmpty())
132 Handle(SALOME_InteractiveObject) anIObject = selected.First();
134 _PTR(Study) aStudy = appStudy->studyDS();
135 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
136 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
137 if (CORBA::is_nil(aMainObject))
140 aMainObject->SetAutoColor( true );
142 QList<SALOMEDS::Color> aReservedColors;
144 GEOM_Displayer aDisp (appStudy);
146 SALOME_View* vf = aDisp.GetActiveView();
148 SUIT_ViewWindow* window = app->desktop()->activeWindow();
149 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
150 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
152 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
154 _PTR(SObject) aChildSObject( it->Value() );
155 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
156 if( CORBA::is_nil( aChildObject ) )
159 if( aChildObject->GetType() != GEOM_GROUP )
162 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
163 aChildObject->SetColor( aColor );
164 aReservedColors.append( aColor );
166 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
168 SALOME_Prs* aPrs = vf->CreatePrs( aChildSObject->GetID().c_str() );
172 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
175 SVTK_View* aView = vtkVW->getView();
176 SUIT_OverrideCursor();
177 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
178 aView->SetColor( It.Value(), c );
182 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
183 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
185 SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
189 AIS_ListOfInteractive aList;
190 anOCCPrs->GetObjects( aList );
191 if( !aList.Extent() )
194 Handle(AIS_InteractiveObject) io = aList.First();
198 Quantity_Color aQuanColor( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
200 // Set color for a point
201 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
202 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
203 Quantity_Color aCurColor;
204 Standard_Real aCurScale;
205 Aspect_TypeOfMarker aCurTypeOfMarker;
206 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
207 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
208 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
211 Standard_Integer aWidth, aHeight;
212 aCurPointAspect->GetTextureSize( aWidth, aHeight );
214 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
215 Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
217 Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
220 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aQuanColor, 1, aWidth, aHeight, aTexture ) );
222 ic->SetLocalAttributes( io, aCurDrawer );
224 io->SetColor( aQuanColor );
225 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
226 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aQuanColor );
228 io->Redisplay( Standard_True );
232 app->updateActions(); //SRN: To update a Save button in the toolbar
235 void GEOMToolsGUI::OnDisableAutoColor()
237 SALOME_ListIO selected;
238 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
242 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
243 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
244 if( !aSelMgr || !appStudy )
247 aSelMgr->selectedObjects( selected );
248 if( selected.IsEmpty() )
251 Handle(SALOME_InteractiveObject) anIObject = selected.First();
253 _PTR(Study) aStudy = appStudy->studyDS();
254 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
255 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
256 if( CORBA::is_nil( aMainObject ) )
259 aMainObject->SetAutoColor( false );
263 void GEOMToolsGUI::OnColor()
265 SALOME_ListIO selected;
266 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
267 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
268 if ( app && appStudy ) {
269 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
271 aSelMgr->selectedObjects( selected );
272 if ( !selected.IsEmpty() ) {
273 SUIT_ViewWindow* window = app->desktop()->activeWindow();
274 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
275 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
276 int mgrId = window->getViewManager()->getGlobalId();
278 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
281 SVTK_View* aView = vtkVW->getView();
282 QColor initcolor = aView->GetColor( selected.First() );
283 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
285 SUIT_OverrideCursor();
286 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
287 aView->SetColor( It.Value(), c );
288 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c);
290 GeometryGUI::Modified();
294 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
295 if ( !io.IsNull() ) {
296 Quantity_Color aColor;
298 QColor initcolor ((int)( aColor.Red() * 255.0 ),
299 (int)( aColor.Green() * 255.0 ),
300 (int)( aColor.Blue() * 255.0 ));
301 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
303 SUIT_OverrideCursor();
304 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
305 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
306 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
307 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
308 io = GEOMBase::GetAIS( It.Value(), true );
309 if ( !io.IsNull() ) {
311 if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) {
312 TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape();
313 bool onlyVertex = (theShape.ShapeType() == TopAbs_VERTEX || GEOM_Displayer::isCompoundOfVertices( theShape ));
315 // Set color for a point
317 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
318 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
319 Quantity_Color aCurColor;
320 Standard_Real aCurScale;
321 Aspect_TypeOfMarker aCurTypeOfMarker;
322 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
323 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
324 aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aCurTypeOfMarker, aColor, aCurScale));
327 Standard_Integer aWidth, aHeight;
328 aCurPointAspect->GetTextureSize( aWidth, aHeight );
330 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
331 Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
333 Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
336 aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aColor, 1, aWidth, aHeight, aTexture));
338 ic->SetLocalAttributes(io, aCurDrawer, Standard_False);
342 io->SetColor( aColor );
343 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) {
344 Handle(GEOM_AISShape) aGAISShape = Handle(GEOM_AISShape)::DownCast( io );
345 aGAISShape->SetShadingColor( aColor );
346 aGAISShape->storeBoundaryColors();
349 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(), COLOR_PROP, c);
351 io->Redisplay( Standard_True );
353 // store color to GEOM_Object
354 _PTR(Study) aStudy = appStudy->studyDS();
355 _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
356 GEOM::GEOM_Object_var anObject =
357 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
360 SALOMEDS::Color aSColor;
361 aSColor.R = (double)c.red() / 255.0;
362 aSColor.G = (double)c.green() / 255.0;
363 aSColor.B = (double)c.blue() / 255.0;
364 anObject->SetColor( aSColor );
365 anObject->SetAutoColor( false );
368 ic->UpdateCurrentViewer();
369 GeometryGUI::Modified();
371 } // first IO is not null
373 } // if ( selection not empty )
377 app->updateActions(); //SRN: To update a Save button in the toolbar
380 void GEOMToolsGUI::OnTexture()
382 SALOME_ListIO selected;
383 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
384 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
385 if ( app && appStudy ) {
386 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
388 aSelMgr->selectedObjects( selected );
389 if ( !selected.IsEmpty() ) {
390 SUIT_ViewWindow* window = app->desktop()->activeWindow();
391 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
392 int mgrId = window->getViewManager()->getGlobalId();
394 QString aTexture = QFileDialog::getOpenFileName(window,tr( "GEOM_SELECT_IMAGE"),QString(), tr("OCC_IMAGE_FILES"));
395 if( !aTexture.isEmpty() )
397 SUIT_OverrideCursor();
398 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
399 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
400 Handle(AIS_InteractiveObject) io ;
401 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
402 io = GEOMBase::GetAIS( It.Value(), true );
403 if ( !io.IsNull() ) {
404 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
405 Handle(GEOM_AISShape)::DownCast( io )->SetTextureFileName(TCollection_AsciiString(aTexture.toStdString().c_str()));
406 io->Redisplay( Standard_True );
407 } // if ( !io.IsNull() )
409 ic->UpdateCurrentViewer();
410 GeometryGUI::Modified();
411 GeometryGUI* myGeomGUI = getGeometryGUI();
412 myGeomGUI->OnGUIEvent(GEOMOp::OpTexture);
413 } // if ( !selFile.isEmpty() )
415 } // if ( selection not empty )
419 app->updateActions(); //SRN: To update a Save button in the toolbar
422 void GEOMToolsGUI::OnTransparency()
424 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
428 void GEOMToolsGUI::OnChangeTransparency( bool increase )
430 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
433 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
436 SALOME_ListIO selected;
437 aSelMgr->selectedObjects( selected );
438 if ( selected.IsEmpty() )
441 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
442 if ( FirstIOS.IsNull() )
446 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
450 SUIT_ViewWindow* window = app->desktop()->activeWindow();
451 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
452 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
455 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
458 SVTK_View* aView = vtkVW->getView();
460 float transp = aView->GetTransparency(FirstIOS);
462 // Compute new transparency value
463 transp = transp + delta;
466 else if ( transp > 1 )
469 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
470 aView->SetTransparency( It.Value(), transp );
473 GeometryGUI::Modified();
477 GEOMBase* gb = new GEOMBase();
478 Handle(GEOM_AISShape) aisShape;
480 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
481 if( aisShape.IsNull() )
483 float transp = aisShape->Transparency();
485 // Compute new transparency value
486 transp = transp + delta;
489 else if ( transp > 1 )
492 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
495 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
496 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
497 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
498 if ( !aisShape.IsNull() ) {
499 ic->SetTransparency( aisShape, transp, false );
500 ic->Redisplay( aisShape, Standard_False, Standard_True );
503 ic->UpdateCurrentViewer();
504 GeometryGUI::Modified();
508 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
510 SalomeApp_Application* app =
511 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
512 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
513 SUIT_ViewWindow* window = app->desktop()->activeWindow();
515 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
516 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
518 if(isOCC){ // if is OCCViewer
520 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
521 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
524 if ( ic->MoreCurrent() ) {
525 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
526 CurObject->restoreIsoNumbers();
527 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
529 int UIso = CurDrawer->UIsoAspect()->Number();
530 int VIso = CurDrawer->VIsoAspect()->Number();
535 if ( actionType == SHOWDLG ) {
536 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
537 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
539 NbIsosDlg->setU( UIso );
540 NbIsosDlg->setV( VIso );
542 if ( NbIsosDlg->exec() ) {
543 SUIT_OverrideCursor();
545 newNbUIso = NbIsosDlg->getU();
546 newNbVIso = NbIsosDlg->getV();
550 else if ( actionType == INCR || actionType == DECR ) {
552 if (actionType == DECR)
555 newNbUIso = UIso + delta;
556 newNbVIso = VIso + delta;
558 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
562 for(; ic->MoreCurrent(); ic->NextCurrent()) {
563 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
565 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
567 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbUIso) );
568 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbVIso) );
570 CurObject->storeIsoNumbers();
572 ic->SetLocalAttributes(CurObject, CurDrawer);
573 ic->Redisplay(CurObject);
575 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
576 int aMgrId = window->getViewManager()->getGlobalId();
577 aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_PROP, anIsos);
580 GeometryGUI::Modified();
582 else if(isVTK){ // if is VTKViewer
584 // Warning. It's works incorrect. must be recheked.
586 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
587 ( SUIT_Session::session()->activeApplication() );
590 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
593 SALOME_ListIO selected;
594 aSelMgr->selectedObjects( selected );
595 if ( selected.IsEmpty() )
598 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
602 SALOME_View* view = GEOM_Displayer::GetActiveView();
604 vtkActorCollection* aCollection = vtkActorCollection::New();
606 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
607 Handle(SALOME_InteractiveObject) anIObject = It.Value();
608 SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
609 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
611 vtkActorCollection* anActors = vtkPrs->GetObjects();
612 anActors->InitTraversal();
613 vtkActor* anAct = anActors->GetNextActor();
614 aCollection->AddItem(anAct);
619 aCollection->InitTraversal();
626 vtkActor* anAct = aCollection->GetNextActor();
627 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
628 anActor->RestoreIsoNumbers();
629 anActor->GetNbIsos(UIso,VIso);
637 if ( actionType == SHOWDLG ) {
638 GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
639 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
641 NbIsosDlg->setU( UIso );
642 NbIsosDlg->setV( VIso );
644 if ( NbIsosDlg->exec() ) {
645 SUIT_OverrideCursor();
647 newNbUIso = NbIsosDlg->getU();
648 newNbVIso = NbIsosDlg->getV();
650 return; //Cancel case
652 else if ( actionType == INCR || actionType == DECR ) {
654 if (actionType == DECR)
657 newNbUIso = UIso + delta;
658 newNbVIso = VIso + delta;
660 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
664 while( anAct!=NULL ) {
665 if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
666 // There are no casting to needed actor.
667 int aIsos[2]={newNbUIso,newNbVIso};
668 anActor->SetNbIsos(aIsos);
669 anActor->StoreIsoNumbers();
671 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
672 int aMgrId = window->getViewManager()->getGlobalId();
673 aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos);
675 anAct = aCollection->GetNextActor();
678 GeometryGUI::Modified();
682 void GEOMToolsGUI::OnDeflection()
684 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
685 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
688 bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
689 bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
690 int mgrId = window->getViewManager()->getGlobalId();
692 if (isOCC) { // if is OCCViewer
693 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
694 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
697 if (ic->MoreCurrent()) {
698 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
700 Standard_Real aDC, aPrevDC;
701 Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
703 aDC = ic->DeviationCoefficient();
705 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
706 (SUIT_Session::session()->activeApplication()->desktop());
707 DeflectionDlg->setTheDC(aDC);
711 if (DeflectionDlg->exec()) {
712 SUIT_OverrideCursor();
713 aNewDC = DeflectionDlg->getTheDC();
714 ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
716 for (; ic->MoreCurrent(); ic->NextCurrent()) {
717 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
718 ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
719 ic->Redisplay(CurObject);
720 appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC);
729 GeometryGUI::Modified();
731 else if (isVTK) { // if is VTKViewer
732 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
733 (SUIT_Session::session()->activeApplication());
737 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
741 SALOME_ListIO selected;
742 aSelMgr->selectedObjects(selected);
743 if (selected.IsEmpty())
746 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
750 SALOME_View* view = GEOM_Displayer::GetActiveView();
752 vtkActorCollection* aCollection = vtkActorCollection::New();
754 for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
755 Handle(SALOME_InteractiveObject) anIObject = It.Value();
756 SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
757 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
759 vtkActorCollection* anActors = vtkPrs->GetObjects();
760 anActors->InitTraversal();
761 vtkActor* anAct = anActors->GetNextActor();
762 aCollection->AddItem(anAct);
767 aCollection->InitTraversal();
773 vtkActor* anAct = aCollection->GetNextActor();
774 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
775 aDC = anActor->GetDeflection();
779 GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
780 (SUIT_Session::session()->activeApplication()->desktop());
781 DeflectionDlg->setTheDC(aDC);
782 if (DeflectionDlg->exec()) {
783 SUIT_OverrideCursor();
784 aDC = DeflectionDlg->getTheDC();
785 while (anAct != NULL) {
786 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
787 // There are no casting to needed actor.
788 anActor->SetDeflection(aDC);
789 appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC);
791 anAct = aCollection->GetNextActor();
794 GeometryGUI::Modified();
798 void GEOMToolsGUI::OnSelectOnly(int mode)
800 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
802 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
803 GEOM_Displayer aDisp (appStudy);
804 aDisp.GlobalSelection(mode);
805 getGeometryGUI()->setLocalSelectionMode(mode);
809 void GEOMToolsGUI::OnShowHideChildren( bool show )
811 SALOME_ListIO selected;
812 SalomeApp_Application* app =
813 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
815 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
817 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
820 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
821 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
822 if ( aSelMgr && appStudy ) {
823 aSelMgr->selectedObjects( selected );
824 if ( !selected.IsEmpty() ) {
825 _PTR(Study) aStudy = appStudy->studyDS();
826 _PTR(StudyBuilder) B = aStudy->NewBuilder();
828 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
830 SUIT_MessageBox::warning( app->desktop(),
831 QObject::tr( "WRN_WARNING" ),
832 QObject::tr( "WRN_STUDY_LOCKED" ) );
836 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
837 Handle(SALOME_InteractiveObject) IObject = It.Value();
839 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
840 _PTR(GenericAttribute) anAttr;
842 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
843 aExp->SetExpandable( show );
845 disp->EraseWithChildren(IObject,true);
850 app->updateObjectBrowser( false );
851 app->updateActions();
855 void GEOMToolsGUI::OnPointMarker()
857 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
861 void GEOMToolsGUI::OnMaterialProperties()
863 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
867 void GEOMToolsGUI::OnUnpublishObject() {
868 SALOME_ListIO selected;
869 SalomeApp_Application* app =
870 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
872 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
874 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
877 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
878 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
879 if ( aSelMgr && appStudy ) {
880 aSelMgr->selectedObjects( selected );
881 if ( !selected.IsEmpty() ) {
882 _PTR(Study) aStudy = appStudy->studyDS();
883 _PTR(StudyBuilder) B = aStudy->NewBuilder();
885 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
887 SUIT_MessageBox::warning( app->desktop(),
888 QObject::tr( "WRN_WARNING" ),
889 QObject::tr( "WRN_STUDY_LOCKED" ) );
893 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
894 Handle(SALOME_InteractiveObject) IObject = It.Value();
896 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
897 _PTR(GenericAttribute) anAttr;
899 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
900 aDrw->SetDrawable( false );
901 disp->EraseWithChildren(IObject);
904 aSelMgr->clearSelected();
907 app->updateObjectBrowser( false );
908 app->updateActions();
913 void GEOMToolsGUI::OnPublishObject() {
914 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
918 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
922 _PTR(Study) aStudy = appStudy->studyDS();
927 //Check lock of the study
928 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
930 SUIT_MessageBox::warning( app->desktop(),
931 QObject::tr( "WRN_WARNING" ),
932 QObject::tr( "WRN_STUDY_LOCKED" ) );
936 GEOMToolsGUI_PublishDlg * publishDlg =
937 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );