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( "SELECT_IMAGE"),QString("/home"), 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()));
402 io->Redisplay( Standard_True );
405 ic->UpdateCurrentViewer();
406 GeometryGUI::Modified();
407 GeometryGUI* myGeomGUI = getGeometryGUI();
408 myGeomGUI->OnGUIEvent(GEOMOp::OpTexture);
409 } // if ( !selFile.isEmpty() )
411 } // if ( selection not empty )
415 app->updateActions(); //SRN: To update a Save button in the toolbar
418 void GEOMToolsGUI::OnTransparency()
420 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
424 void GEOMToolsGUI::OnChangeTransparency( bool increase )
426 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
429 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
432 SALOME_ListIO selected;
433 aSelMgr->selectedObjects( selected );
434 if ( selected.IsEmpty() )
437 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
438 if ( FirstIOS.IsNull() )
442 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
446 SUIT_ViewWindow* window = app->desktop()->activeWindow();
447 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
448 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
451 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
454 SVTK_View* aView = vtkVW->getView();
456 float transp = aView->GetTransparency(FirstIOS);
458 // Compute new transparency value
459 transp = transp + delta;
462 else if ( transp > 1 )
465 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
466 aView->SetTransparency( It.Value(), transp );
469 GeometryGUI::Modified();
473 GEOMBase* gb = new GEOMBase();
474 Handle(GEOM_AISShape) aisShape;
476 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
477 if( aisShape.IsNull() )
479 float transp = aisShape->Transparency();
481 // Compute new transparency value
482 transp = transp + delta;
485 else if ( transp > 1 )
488 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
491 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
492 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
493 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
494 if ( !aisShape.IsNull() ) {
495 ic->SetTransparency( aisShape, transp, false );
496 ic->Redisplay( aisShape, Standard_False, Standard_True );
499 ic->UpdateCurrentViewer();
500 GeometryGUI::Modified();
504 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
506 SalomeApp_Application* app =
507 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
508 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
509 SUIT_ViewWindow* window = app->desktop()->activeWindow();
511 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
512 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
514 if(isOCC){ // if is OCCViewer
516 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
517 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
520 if ( ic->MoreCurrent() ) {
521 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
522 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
524 int UIso = CurDrawer->UIsoAspect()->Number();
525 int VIso = CurDrawer->VIsoAspect()->Number();
530 if ( actionType == SHOWDLG ) {
531 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
532 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
534 NbIsosDlg->setU( UIso );
535 NbIsosDlg->setV( VIso );
537 if ( NbIsosDlg->exec() ) {
538 SUIT_OverrideCursor();
540 newNbUIso = NbIsosDlg->getU();
541 newNbVIso = NbIsosDlg->getV();
545 else if ( actionType == INCR || actionType == DECR ) {
547 if (actionType == DECR)
550 newNbUIso = UIso + delta;
551 newNbVIso = VIso + delta;
553 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
557 for(; ic->MoreCurrent(); ic->NextCurrent()) {
558 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
560 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
562 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbUIso) );
563 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbVIso) );
565 ic->SetLocalAttributes(CurObject, CurDrawer);
566 ic->Redisplay(CurObject);
568 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
569 int aMgrId = window->getViewManager()->getGlobalId();
570 aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), "Isos", anIsos);
573 GeometryGUI::Modified();
575 else if(isVTK){ // if is VTKViewer
577 // Warning. It's works incorrect. must be recheked.
579 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
580 ( SUIT_Session::session()->activeApplication() );
583 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
586 SALOME_ListIO selected;
587 aSelMgr->selectedObjects( selected );
588 if ( selected.IsEmpty() )
591 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
595 SALOME_View* view = GEOM_Displayer::GetActiveView();
597 vtkActorCollection* aCollection = vtkActorCollection::New();
599 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
600 Handle(SALOME_InteractiveObject) anIObject = It.Value();
601 SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
602 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
604 vtkActorCollection* anActors = vtkPrs->GetObjects();
605 anActors->InitTraversal();
606 vtkActor* anAct = anActors->GetNextActor();
607 aCollection->AddItem(anAct);
612 aCollection->InitTraversal();
619 vtkActor* anAct = aCollection->GetNextActor();
620 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
621 anActor->GetNbIsos(UIso,VIso);
628 if ( actionType == SHOWDLG ) {
629 GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
630 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
632 NbIsosDlg->setU( UIso );
633 NbIsosDlg->setV( VIso );
635 if ( NbIsosDlg->exec() ) {
636 SUIT_OverrideCursor();
638 newNbUIso = NbIsosDlg->getU();
639 newNbVIso = NbIsosDlg->getV();
641 return; //Cancel case
643 else if ( actionType == INCR || actionType == DECR ) {
645 if (actionType == DECR)
648 newNbUIso = UIso + delta;
649 newNbVIso = VIso + delta;
651 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
655 while( anAct!=NULL ) {
656 if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
657 // There are no casting to needed actor.
658 int aIsos[2]={newNbUIso,newNbVIso};
659 anActor->SetNbIsos(aIsos);
661 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
662 int aMgrId = window->getViewManager()->getGlobalId();
663 aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos);
665 anAct = aCollection->GetNextActor();
668 GeometryGUI::Modified();
672 void GEOMToolsGUI::OnDeflection()
674 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
675 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
678 bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
679 bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
680 int mgrId = window->getViewManager()->getGlobalId();
682 if (isOCC) { // if is OCCViewer
683 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
684 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
687 if (ic->MoreCurrent()) {
688 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
690 Standard_Real aDC, aPrevDC;
691 Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
693 aDC = ic->DeviationCoefficient();
695 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
696 (SUIT_Session::session()->activeApplication()->desktop());
697 DeflectionDlg->setTheDC(aDC);
701 if (DeflectionDlg->exec()) {
702 SUIT_OverrideCursor();
703 aNewDC = DeflectionDlg->getTheDC();
704 ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
706 for (; ic->MoreCurrent(); ic->NextCurrent()) {
707 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
708 ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
709 ic->Redisplay(CurObject);
710 appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC);
719 GeometryGUI::Modified();
721 else if (isVTK) { // if is VTKViewer
722 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
723 (SUIT_Session::session()->activeApplication());
727 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
731 SALOME_ListIO selected;
732 aSelMgr->selectedObjects(selected);
733 if (selected.IsEmpty())
736 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
740 SALOME_View* view = GEOM_Displayer::GetActiveView();
742 vtkActorCollection* aCollection = vtkActorCollection::New();
744 for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
745 Handle(SALOME_InteractiveObject) anIObject = It.Value();
746 SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
747 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
749 vtkActorCollection* anActors = vtkPrs->GetObjects();
750 anActors->InitTraversal();
751 vtkActor* anAct = anActors->GetNextActor();
752 aCollection->AddItem(anAct);
757 aCollection->InitTraversal();
763 vtkActor* anAct = aCollection->GetNextActor();
764 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
765 aDC = anActor->GetDeflection();
769 GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
770 (SUIT_Session::session()->activeApplication()->desktop());
771 DeflectionDlg->setTheDC(aDC);
772 if (DeflectionDlg->exec()) {
773 SUIT_OverrideCursor();
774 aDC = DeflectionDlg->getTheDC();
775 while (anAct != NULL) {
776 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
777 // There are no casting to needed actor.
778 anActor->SetDeflection(aDC);
779 appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC);
781 anAct = aCollection->GetNextActor();
784 GeometryGUI::Modified();
788 void GEOMToolsGUI::OnSelectOnly(int mode)
790 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
792 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
793 GEOM_Displayer aDisp (appStudy);
794 aDisp.GlobalSelection(mode);
795 getGeometryGUI()->setLocalSelectionMode(mode);
799 void GEOMToolsGUI::OnShowHideChildren( bool show )
801 SALOME_ListIO selected;
802 SalomeApp_Application* app =
803 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
805 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
807 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
810 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
811 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
812 if ( aSelMgr && appStudy ) {
813 aSelMgr->selectedObjects( selected );
814 if ( !selected.IsEmpty() ) {
815 _PTR(Study) aStudy = appStudy->studyDS();
816 _PTR(StudyBuilder) B = aStudy->NewBuilder();
818 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
820 SUIT_MessageBox::warning( app->desktop(),
821 QObject::tr( "WRN_WARNING" ),
822 QObject::tr( "WRN_STUDY_LOCKED" ) );
826 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
827 Handle(SALOME_InteractiveObject) IObject = It.Value();
829 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
830 _PTR(GenericAttribute) anAttr;
832 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
833 aExp->SetExpandable( show );
835 disp->EraseWithChildren(IObject,true);
840 app->updateObjectBrowser( false );
841 app->updateActions();
845 void GEOMToolsGUI::OnPointMarker()
847 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
852 void GEOMToolsGUI::OnUnpublishObject() {
853 SALOME_ListIO selected;
854 SalomeApp_Application* app =
855 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
857 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
859 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
862 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
863 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
864 if ( aSelMgr && appStudy ) {
865 aSelMgr->selectedObjects( selected );
866 if ( !selected.IsEmpty() ) {
867 _PTR(Study) aStudy = appStudy->studyDS();
868 _PTR(StudyBuilder) B = aStudy->NewBuilder();
870 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
872 SUIT_MessageBox::warning( app->desktop(),
873 QObject::tr( "WRN_WARNING" ),
874 QObject::tr( "WRN_STUDY_LOCKED" ) );
878 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
879 Handle(SALOME_InteractiveObject) IObject = It.Value();
881 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
882 _PTR(GenericAttribute) anAttr;
884 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
885 aDrw->SetDrawable( false );
886 disp->EraseWithChildren(IObject);
889 aSelMgr->clearSelected();
892 app->updateObjectBrowser( false );
893 app->updateActions();
898 void GEOMToolsGUI::OnPublishObject() {
899 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
903 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
907 _PTR(Study) aStudy = appStudy->studyDS();
912 //Check lock of the study
913 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
915 SUIT_MessageBox::warning( app->desktop(),
916 QObject::tr( "WRN_WARNING" ),
917 QObject::tr( "WRN_STUDY_LOCKED" ) );
921 GEOMToolsGUI_PublishDlg * publishDlg =
922 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );