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 <GeometryGUI_Operations.h>
37 #include <GEOM_Displayer.h>
40 #include <GEOM_Actor.h>
42 #include <Basics_OCCTVersion.hxx>
44 #include <SALOME_ListIO.hxx>
45 #include <SALOME_ListIteratorOfListIO.hxx>
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
52 #include <SVTK_View.h>
54 #include <OCCViewer_ViewModel.h>
56 #include <SUIT_ViewManager.h>
57 #include <SUIT_Desktop.h>
58 #include <SUIT_ResourceMgr.h>
59 #include <SUIT_Session.h>
60 #include <SUIT_OverrideCursor.h>
61 #include <SUIT_MessageBox.h>
62 #include <SUIT_Tools.h>
64 #include <SalomeApp_Application.h>
65 #include <SalomeApp_Study.h>
66 #include <SalomeApp_Module.h>
68 #include <LightApp_SelectionMgr.h>
69 #include <LightApp_NameDlg.h>
71 #include <GEOMImpl_Types.hxx>
73 #include "utilities.h"
76 #include <AIS_Drawer.hxx>
77 #include <Prs3d_IsoAspect.hxx>
78 #include <Prs3d_PointAspect.hxx>
79 #include <Graphic3d_AspectMarker3d.hxx>
81 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
82 #include <TColStd_HArray1OfByte.hxx>
84 #include <Graphic3d_HArray1OfBytes.hxx>
88 #include <QColorDialog>
89 #include <QInputDialog>
90 #include <QFileDialog>
93 #include <QGridLayout>
96 #include <QPushButton>
100 #include <vtkRenderer.h>
103 void GEOMToolsGUI::OnCheckGeometry()
105 SalomeApp_Application* app =
106 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
107 PyConsole_Console* pyConsole = app->pythonConsole();
110 pyConsole->exec("from GEOM_usinggeom import *");
113 void GEOMToolsGUI::OnAutoColor()
115 SALOME_ListIO selected;
116 SalomeApp_Application* app =
117 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
121 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
122 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
123 if (!aSelMgr || !appStudy)
126 aSelMgr->selectedObjects(selected);
127 if (selected.IsEmpty())
130 Handle(SALOME_InteractiveObject) anIObject = selected.First();
132 _PTR(Study) aStudy = appStudy->studyDS();
133 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
134 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
135 if (CORBA::is_nil(aMainObject))
138 aMainObject->SetAutoColor( true );
140 QList<SALOMEDS::Color> aReservedColors;
142 GEOM_Displayer aDisp (appStudy);
144 SALOME_View* vf = aDisp.GetActiveView();
146 SUIT_ViewWindow* window = app->desktop()->activeWindow();
147 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
148 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
150 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
152 _PTR(SObject) aChildSObject( it->Value() );
153 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
154 if( CORBA::is_nil( aChildObject ) )
157 if( aChildObject->GetType() != GEOM_GROUP )
160 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
161 aChildObject->SetColor( aColor );
162 aReservedColors.append( aColor );
164 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
166 SALOME_Prs* aPrs = vf->CreatePrs( aChildSObject->GetID().c_str() );
170 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
173 SVTK_View* aView = vtkVW->getView();
174 SUIT_OverrideCursor();
175 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
176 aView->SetColor( It.Value(), c );
180 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
181 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
183 SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
187 AIS_ListOfInteractive aList;
188 anOCCPrs->GetObjects( aList );
189 if( !aList.Extent() )
192 Handle(AIS_InteractiveObject) io = aList.First();
196 Quantity_Color aQuanColor( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
198 // Set color for a point
199 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
200 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
201 Quantity_Color aCurColor;
202 Standard_Real aCurScale;
203 Aspect_TypeOfMarker aCurTypeOfMarker;
204 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
205 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
206 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
209 Standard_Integer aWidth, aHeight;
210 aCurPointAspect->GetTextureSize( aWidth, aHeight );
212 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
213 Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
215 Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
218 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aQuanColor, 1, aWidth, aHeight, aTexture ) );
220 ic->SetLocalAttributes( io, aCurDrawer );
222 io->SetColor( aQuanColor );
223 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
224 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aQuanColor );
226 io->Redisplay( Standard_True );
230 app->updateActions(); //SRN: To update a Save button in the toolbar
233 void GEOMToolsGUI::OnDisableAutoColor()
235 SALOME_ListIO selected;
236 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
240 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
241 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
242 if( !aSelMgr || !appStudy )
245 aSelMgr->selectedObjects( selected );
246 if( selected.IsEmpty() )
249 Handle(SALOME_InteractiveObject) anIObject = selected.First();
251 _PTR(Study) aStudy = appStudy->studyDS();
252 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
253 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
254 if( CORBA::is_nil( aMainObject ) )
257 aMainObject->SetAutoColor( false );
261 void GEOMToolsGUI::OnColor()
263 SALOME_ListIO selected;
264 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
265 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
266 if ( app && appStudy ) {
267 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
269 aSelMgr->selectedObjects( selected );
270 if ( !selected.IsEmpty() ) {
271 SUIT_ViewWindow* window = app->desktop()->activeWindow();
272 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
273 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
274 int mgrId = window->getViewManager()->getGlobalId();
276 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
279 SVTK_View* aView = vtkVW->getView();
280 QColor initcolor = aView->GetColor( selected.First() );
281 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
283 SUIT_OverrideCursor();
284 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
285 aView->SetColor( It.Value(), c );
286 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c);
288 GeometryGUI::Modified();
292 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
293 if ( !io.IsNull() ) {
294 Quantity_Color aColor;
296 QColor initcolor ((int)( aColor.Red() * 255.0 ),
297 (int)( aColor.Green() * 255.0 ),
298 (int)( aColor.Blue() * 255.0 ));
299 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
301 SUIT_OverrideCursor();
302 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
303 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
304 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
305 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
306 io = GEOMBase::GetAIS( It.Value(), true );
307 if ( !io.IsNull() ) {
309 if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) {
310 TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape();
311 bool onlyVertex = (theShape.ShapeType() == TopAbs_VERTEX || GEOM_Displayer::isCompoundOfVertices( theShape ));
313 // Set color for a point
315 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
316 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
317 Quantity_Color aCurColor;
318 Standard_Real aCurScale;
319 Aspect_TypeOfMarker aCurTypeOfMarker;
320 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
321 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
322 aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aCurTypeOfMarker, aColor, aCurScale));
325 Standard_Integer aWidth, aHeight;
326 aCurPointAspect->GetTextureSize( aWidth, aHeight );
328 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
329 Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
331 Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
334 aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aColor, 1, aWidth, aHeight, aTexture));
336 ic->SetLocalAttributes(io, aCurDrawer, Standard_False);
340 io->SetColor( aColor );
341 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
342 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
344 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(), COLOR_PROP, c);
346 io->Redisplay( Standard_True );
348 // store color to GEOM_Object
349 _PTR(Study) aStudy = appStudy->studyDS();
350 _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
351 GEOM::GEOM_Object_var anObject =
352 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
355 SALOMEDS::Color aSColor;
356 aSColor.R = (double)c.red() / 255.0;
357 aSColor.G = (double)c.green() / 255.0;
358 aSColor.B = (double)c.blue() / 255.0;
359 anObject->SetColor( aSColor );
360 anObject->SetAutoColor( false );
363 ic->UpdateCurrentViewer();
364 GeometryGUI::Modified();
366 } // first IO is not null
368 } // if ( selection not empty )
372 app->updateActions(); //SRN: To update a Save button in the toolbar
375 void GEOMToolsGUI::OnTexture()
377 SALOME_ListIO selected;
378 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
379 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
380 if ( app && appStudy ) {
381 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
383 aSelMgr->selectedObjects( selected );
384 if ( !selected.IsEmpty() ) {
385 SUIT_ViewWindow* window = app->desktop()->activeWindow();
386 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
387 int mgrId = window->getViewManager()->getGlobalId();
389 QString aTexture = QFileDialog::getOpenFileName(window,tr( "GEOM_SELECT_IMAGE"),QString(), tr("OCC_IMAGE_FILES"));
390 if( !aTexture.isEmpty() )
392 SUIT_OverrideCursor();
393 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
394 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
395 Handle(AIS_InteractiveObject) io ;
396 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
397 io = GEOMBase::GetAIS( It.Value(), true );
398 if ( !io.IsNull() ) {
399 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
400 Handle(GEOM_AISShape)::DownCast( io )->SetTextureFileName(TCollection_AsciiString(aTexture.toStdString().c_str()));
401 io->Redisplay( Standard_True );
402 } // if ( !io.IsNull() )
404 ic->UpdateCurrentViewer();
405 GeometryGUI::Modified();
406 GeometryGUI* myGeomGUI = getGeometryGUI();
407 myGeomGUI->OnGUIEvent(GEOMOp::OpTexture);
408 } // if ( !selFile.isEmpty() )
410 } // if ( selection not empty )
414 app->updateActions(); //SRN: To update a Save button in the toolbar
417 void GEOMToolsGUI::OnTransparency()
419 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
423 void GEOMToolsGUI::OnChangeTransparency( bool increase )
425 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
428 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
431 SALOME_ListIO selected;
432 aSelMgr->selectedObjects( selected );
433 if ( selected.IsEmpty() )
436 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
437 if ( FirstIOS.IsNull() )
441 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
445 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() );
450 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
453 SVTK_View* aView = vtkVW->getView();
455 float transp = aView->GetTransparency(FirstIOS);
457 // Compute new transparency value
458 transp = transp + delta;
461 else if ( transp > 1 )
464 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
465 aView->SetTransparency( It.Value(), transp );
468 GeometryGUI::Modified();
472 GEOMBase* gb = new GEOMBase();
473 Handle(GEOM_AISShape) aisShape;
475 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
476 if( aisShape.IsNull() )
478 float transp = aisShape->Transparency();
480 // Compute new transparency value
481 transp = transp + delta;
484 else if ( transp > 1 )
487 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
490 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
491 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
492 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
493 if ( !aisShape.IsNull() ) {
494 ic->SetTransparency( aisShape, transp, false );
495 ic->Redisplay( aisShape, Standard_False, Standard_True );
498 ic->UpdateCurrentViewer();
499 GeometryGUI::Modified();
503 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
505 SalomeApp_Application* app =
506 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
507 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
508 SUIT_ViewWindow* window = app->desktop()->activeWindow();
510 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
511 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
513 if(isOCC){ // if is OCCViewer
515 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
516 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
519 if ( ic->MoreCurrent() ) {
520 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
521 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
523 int UIso = CurDrawer->UIsoAspect()->Number();
524 int VIso = CurDrawer->VIsoAspect()->Number();
529 if ( actionType == SHOWDLG ) {
530 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
531 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
533 NbIsosDlg->setU( UIso );
534 NbIsosDlg->setV( VIso );
536 if ( NbIsosDlg->exec() ) {
537 SUIT_OverrideCursor();
539 newNbUIso = NbIsosDlg->getU();
540 newNbVIso = NbIsosDlg->getV();
544 else if ( actionType == INCR || actionType == DECR ) {
546 if (actionType == DECR)
549 newNbUIso = UIso + delta;
550 newNbVIso = VIso + delta;
552 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
556 for(; ic->MoreCurrent(); ic->NextCurrent()) {
557 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
559 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
561 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbUIso) );
562 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbVIso) );
564 ic->SetLocalAttributes(CurObject, CurDrawer);
565 ic->Redisplay(CurObject);
567 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
568 int aMgrId = window->getViewManager()->getGlobalId();
569 aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), "Isos", anIsos);
572 GeometryGUI::Modified();
574 else if(isVTK){ // if is VTKViewer
576 // Warning. It's works incorrect. must be recheked.
578 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
579 ( SUIT_Session::session()->activeApplication() );
582 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
585 SALOME_ListIO selected;
586 aSelMgr->selectedObjects( selected );
587 if ( selected.IsEmpty() )
590 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
594 SALOME_View* view = GEOM_Displayer::GetActiveView();
596 vtkActorCollection* aCollection = vtkActorCollection::New();
598 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
599 Handle(SALOME_InteractiveObject) anIObject = It.Value();
600 SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
601 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
603 vtkActorCollection* anActors = vtkPrs->GetObjects();
604 anActors->InitTraversal();
605 vtkActor* anAct = anActors->GetNextActor();
606 aCollection->AddItem(anAct);
611 aCollection->InitTraversal();
618 vtkActor* anAct = aCollection->GetNextActor();
619 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
620 anActor->GetNbIsos(UIso,VIso);
627 if ( actionType == SHOWDLG ) {
628 GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
629 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
631 NbIsosDlg->setU( UIso );
632 NbIsosDlg->setV( VIso );
634 if ( NbIsosDlg->exec() ) {
635 SUIT_OverrideCursor();
637 newNbUIso = NbIsosDlg->getU();
638 newNbVIso = NbIsosDlg->getV();
640 return; //Cancel case
642 else if ( actionType == INCR || actionType == DECR ) {
644 if (actionType == DECR)
647 newNbUIso = UIso + delta;
648 newNbVIso = VIso + delta;
650 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
654 while( anAct!=NULL ) {
655 if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
656 // There are no casting to needed actor.
657 int aIsos[2]={newNbUIso,newNbVIso};
658 anActor->SetNbIsos(aIsos);
660 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
661 int aMgrId = window->getViewManager()->getGlobalId();
662 aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos);
664 anAct = aCollection->GetNextActor();
667 GeometryGUI::Modified();
671 void GEOMToolsGUI::OnDeflection()
673 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
674 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
677 bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
678 bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
679 int mgrId = window->getViewManager()->getGlobalId();
681 if (isOCC) { // if is OCCViewer
682 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
683 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
686 if (ic->MoreCurrent()) {
687 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
689 Standard_Real aDC, aPrevDC;
690 Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
692 aDC = ic->DeviationCoefficient();
694 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
695 (SUIT_Session::session()->activeApplication()->desktop());
696 DeflectionDlg->setTheDC(aDC);
700 if (DeflectionDlg->exec()) {
701 SUIT_OverrideCursor();
702 aNewDC = DeflectionDlg->getTheDC();
703 ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
705 for (; ic->MoreCurrent(); ic->NextCurrent()) {
706 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
707 ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
708 ic->Redisplay(CurObject);
709 appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC);
718 GeometryGUI::Modified();
720 else if (isVTK) { // if is VTKViewer
721 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
722 (SUIT_Session::session()->activeApplication());
726 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
730 SALOME_ListIO selected;
731 aSelMgr->selectedObjects(selected);
732 if (selected.IsEmpty())
735 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
739 SALOME_View* view = GEOM_Displayer::GetActiveView();
741 vtkActorCollection* aCollection = vtkActorCollection::New();
743 for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
744 Handle(SALOME_InteractiveObject) anIObject = It.Value();
745 SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
746 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
748 vtkActorCollection* anActors = vtkPrs->GetObjects();
749 anActors->InitTraversal();
750 vtkActor* anAct = anActors->GetNextActor();
751 aCollection->AddItem(anAct);
756 aCollection->InitTraversal();
762 vtkActor* anAct = aCollection->GetNextActor();
763 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
764 aDC = anActor->GetDeflection();
768 GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
769 (SUIT_Session::session()->activeApplication()->desktop());
770 DeflectionDlg->setTheDC(aDC);
771 if (DeflectionDlg->exec()) {
772 SUIT_OverrideCursor();
773 aDC = DeflectionDlg->getTheDC();
774 while (anAct != NULL) {
775 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
776 // There are no casting to needed actor.
777 anActor->SetDeflection(aDC);
778 appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC);
780 anAct = aCollection->GetNextActor();
783 GeometryGUI::Modified();
787 void GEOMToolsGUI::OnSelectOnly(int mode)
789 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
791 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
792 GEOM_Displayer aDisp (appStudy);
793 aDisp.GlobalSelection(mode);
794 getGeometryGUI()->setLocalSelectionMode(mode);
798 void GEOMToolsGUI::OnShowHideChildren( bool show )
800 SALOME_ListIO selected;
801 SalomeApp_Application* app =
802 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
804 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
806 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
809 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
810 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
811 if ( aSelMgr && appStudy ) {
812 aSelMgr->selectedObjects( selected );
813 if ( !selected.IsEmpty() ) {
814 _PTR(Study) aStudy = appStudy->studyDS();
815 _PTR(StudyBuilder) B = aStudy->NewBuilder();
817 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
819 SUIT_MessageBox::warning( app->desktop(),
820 QObject::tr( "WRN_WARNING" ),
821 QObject::tr( "WRN_STUDY_LOCKED" ) );
825 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
826 Handle(SALOME_InteractiveObject) IObject = It.Value();
828 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
829 _PTR(GenericAttribute) anAttr;
831 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
832 aExp->SetExpandable( show );
834 disp->EraseWithChildren(IObject,true);
839 app->updateObjectBrowser( false );
840 app->updateActions();
844 void GEOMToolsGUI::OnPointMarker()
846 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
851 void GEOMToolsGUI::OnUnpublishObject() {
852 SALOME_ListIO selected;
853 SalomeApp_Application* app =
854 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
856 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
858 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
861 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
862 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
863 if ( aSelMgr && appStudy ) {
864 aSelMgr->selectedObjects( selected );
865 if ( !selected.IsEmpty() ) {
866 _PTR(Study) aStudy = appStudy->studyDS();
867 _PTR(StudyBuilder) B = aStudy->NewBuilder();
869 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
871 SUIT_MessageBox::warning( app->desktop(),
872 QObject::tr( "WRN_WARNING" ),
873 QObject::tr( "WRN_STUDY_LOCKED" ) );
877 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
878 Handle(SALOME_InteractiveObject) IObject = It.Value();
880 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
881 _PTR(GenericAttribute) anAttr;
883 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
884 aDrw->SetDrawable( false );
885 disp->EraseWithChildren(IObject);
888 aSelMgr->clearSelected();
891 app->updateObjectBrowser( false );
892 app->updateActions();
897 void GEOMToolsGUI::OnPublishObject() {
898 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
902 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
906 _PTR(Study) aStudy = appStudy->studyDS();
911 //Check lock of the study
912 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
914 SUIT_MessageBox::warning( app->desktop(),
915 QObject::tr( "WRN_WARNING" ),
916 QObject::tr( "WRN_STUDY_LOCKED" ) );
920 GEOMToolsGUI_PublishDlg * publishDlg =
921 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );