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) aGAISShape = Handle(GEOM_AISShape)::DownCast( io );
227 aGAISShape->SetShadingColor( aQuanColor );
228 aGAISShape->storeBoundaryColors();
231 io->Redisplay( Standard_True );
235 app->updateActions(); //SRN: To update a Save button in the toolbar
238 void GEOMToolsGUI::OnDisableAutoColor()
240 SALOME_ListIO selected;
241 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
245 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
246 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
247 if( !aSelMgr || !appStudy )
250 aSelMgr->selectedObjects( selected );
251 if( selected.IsEmpty() )
254 Handle(SALOME_InteractiveObject) anIObject = selected.First();
256 _PTR(Study) aStudy = appStudy->studyDS();
257 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
258 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
259 if( CORBA::is_nil( aMainObject ) )
262 aMainObject->SetAutoColor( false );
266 void GEOMToolsGUI::OnColor()
268 SALOME_ListIO selected;
269 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
270 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
271 if ( app && appStudy ) {
272 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
274 aSelMgr->selectedObjects( selected );
275 if ( !selected.IsEmpty() ) {
276 SUIT_ViewWindow* window = app->desktop()->activeWindow();
277 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
278 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
279 int mgrId = window->getViewManager()->getGlobalId();
281 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
284 SVTK_View* aView = vtkVW->getView();
285 QColor initcolor = aView->GetColor( selected.First() );
286 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
288 SUIT_OverrideCursor();
289 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
290 aView->SetColor( It.Value(), c );
291 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c);
293 GeometryGUI::Modified();
297 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
298 if ( !io.IsNull() ) {
299 Quantity_Color aColor;
301 QColor initcolor ((int)( aColor.Red() * 255.0 ),
302 (int)( aColor.Green() * 255.0 ),
303 (int)( aColor.Blue() * 255.0 ));
304 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
306 SUIT_OverrideCursor();
307 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
308 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
309 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
310 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
311 io = GEOMBase::GetAIS( It.Value(), true );
312 if ( !io.IsNull() ) {
314 if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) {
315 TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape();
316 bool onlyVertex = (theShape.ShapeType() == TopAbs_VERTEX || GEOM_Displayer::isCompoundOfVertices( theShape ));
318 // Set color for a point
320 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
321 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
322 Quantity_Color aCurColor;
323 Standard_Real aCurScale;
324 Aspect_TypeOfMarker aCurTypeOfMarker;
325 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
326 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
327 aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aCurTypeOfMarker, aColor, aCurScale));
330 Standard_Integer aWidth, aHeight;
331 aCurPointAspect->GetTextureSize( aWidth, aHeight );
333 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
334 Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
336 Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
339 aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aColor, 1, aWidth, aHeight, aTexture));
341 ic->SetLocalAttributes(io, aCurDrawer, Standard_False);
345 io->SetColor( aColor );
346 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) {
347 Handle(GEOM_AISShape) aGAISShape = Handle(GEOM_AISShape)::DownCast( io );
348 aGAISShape->SetShadingColor( aColor );
349 aGAISShape->storeBoundaryColors();
352 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(), COLOR_PROP, c);
354 io->Redisplay( Standard_True );
356 // store color to GEOM_Object
357 _PTR(Study) aStudy = appStudy->studyDS();
358 _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
359 GEOM::GEOM_Object_var anObject =
360 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
363 SALOMEDS::Color aSColor;
364 aSColor.R = (double)c.red() / 255.0;
365 aSColor.G = (double)c.green() / 255.0;
366 aSColor.B = (double)c.blue() / 255.0;
367 anObject->SetColor( aSColor );
368 anObject->SetAutoColor( false );
371 ic->UpdateCurrentViewer();
372 GeometryGUI::Modified();
374 } // first IO is not null
376 } // if ( selection not empty )
380 app->updateActions(); //SRN: To update a Save button in the toolbar
383 void GEOMToolsGUI::OnTexture()
385 SALOME_ListIO selected;
386 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
387 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
388 if ( app && appStudy ) {
389 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
391 aSelMgr->selectedObjects( selected );
392 if ( !selected.IsEmpty() ) {
393 SUIT_ViewWindow* window = app->desktop()->activeWindow();
394 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
395 int mgrId = window->getViewManager()->getGlobalId();
397 QString aTexture = QFileDialog::getOpenFileName(window,tr( "GEOM_SELECT_IMAGE"),QString(), tr("OCC_IMAGE_FILES"));
398 if( !aTexture.isEmpty() )
400 SUIT_OverrideCursor();
401 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
402 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
403 Handle(AIS_InteractiveObject) io ;
404 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
405 io = GEOMBase::GetAIS( It.Value(), true );
406 if ( !io.IsNull() ) {
407 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
408 Handle(GEOM_AISShape)::DownCast( io )->SetTextureFileName(TCollection_AsciiString(aTexture.toStdString().c_str()));
409 io->Redisplay( Standard_True );
410 } // if ( !io.IsNull() )
412 ic->UpdateCurrentViewer();
413 GeometryGUI::Modified();
414 GeometryGUI* myGeomGUI = getGeometryGUI();
415 myGeomGUI->OnGUIEvent(GEOMOp::OpTexture);
416 } // if ( !selFile.isEmpty() )
418 } // if ( selection not empty )
422 app->updateActions(); //SRN: To update a Save button in the toolbar
425 void GEOMToolsGUI::OnTransparency()
427 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
431 void GEOMToolsGUI::OnChangeTransparency( bool increase )
433 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
436 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
439 SALOME_ListIO selected;
440 aSelMgr->selectedObjects( selected );
441 if ( selected.IsEmpty() )
444 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
445 if ( FirstIOS.IsNull() )
449 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
453 SUIT_ViewWindow* window = app->desktop()->activeWindow();
454 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
455 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
458 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
461 SVTK_View* aView = vtkVW->getView();
463 float transp = aView->GetTransparency(FirstIOS);
465 // Compute new transparency value
466 transp = transp + delta;
469 else if ( transp > 1 )
472 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
473 aView->SetTransparency( It.Value(), transp );
476 GeometryGUI::Modified();
480 GEOMBase* gb = new GEOMBase();
481 Handle(GEOM_AISShape) aisShape;
483 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
484 if( aisShape.IsNull() )
486 float transp = aisShape->Transparency();
488 // Compute new transparency value
489 transp = transp + delta;
492 else if ( transp > 1 )
495 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
498 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
499 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
500 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
501 if ( !aisShape.IsNull() ) {
502 ic->SetTransparency( aisShape, transp, false );
503 ic->Redisplay( aisShape, Standard_False, Standard_True );
506 ic->UpdateCurrentViewer();
507 GeometryGUI::Modified();
511 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
513 SalomeApp_Application* app =
514 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
515 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
516 SUIT_ViewWindow* window = app->desktop()->activeWindow();
518 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
519 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
521 if(isOCC){ // if is OCCViewer
523 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
524 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
527 if ( ic->MoreCurrent() ) {
528 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
529 CurObject->restoreIsoNumbers();
530 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
532 int UIso = CurDrawer->UIsoAspect()->Number();
533 int VIso = CurDrawer->VIsoAspect()->Number();
538 if ( actionType == SHOWDLG ) {
539 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
540 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
542 NbIsosDlg->setU( UIso );
543 NbIsosDlg->setV( VIso );
545 if ( NbIsosDlg->exec() ) {
546 SUIT_OverrideCursor();
548 newNbUIso = NbIsosDlg->getU();
549 newNbVIso = NbIsosDlg->getV();
553 else if ( actionType == INCR || actionType == DECR ) {
555 if (actionType == DECR)
558 newNbUIso = UIso + delta;
559 newNbVIso = VIso + delta;
561 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
565 for(; ic->MoreCurrent(); ic->NextCurrent()) {
566 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
568 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
570 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbUIso) );
571 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbVIso) );
573 CurObject->storeIsoNumbers();
575 ic->SetLocalAttributes(CurObject, CurDrawer);
576 ic->Redisplay(CurObject);
578 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
579 int aMgrId = window->getViewManager()->getGlobalId();
580 aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_PROP, anIsos);
583 GeometryGUI::Modified();
585 else if(isVTK){ // if is VTKViewer
587 // Warning. It's works incorrect. must be recheked.
589 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
590 ( SUIT_Session::session()->activeApplication() );
593 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
596 SALOME_ListIO selected;
597 aSelMgr->selectedObjects( selected );
598 if ( selected.IsEmpty() )
601 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
605 SALOME_View* view = GEOM_Displayer::GetActiveView();
607 vtkActorCollection* aCollection = vtkActorCollection::New();
609 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
610 Handle(SALOME_InteractiveObject) anIObject = It.Value();
611 SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
612 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
614 vtkActorCollection* anActors = vtkPrs->GetObjects();
615 anActors->InitTraversal();
616 vtkActor* anAct = anActors->GetNextActor();
617 aCollection->AddItem(anAct);
622 aCollection->InitTraversal();
629 vtkActor* anAct = aCollection->GetNextActor();
630 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
631 anActor->RestoreIsoNumbers();
632 anActor->GetNbIsos(UIso,VIso);
640 if ( actionType == SHOWDLG ) {
641 GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
642 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
644 NbIsosDlg->setU( UIso );
645 NbIsosDlg->setV( VIso );
647 if ( NbIsosDlg->exec() ) {
648 SUIT_OverrideCursor();
650 newNbUIso = NbIsosDlg->getU();
651 newNbVIso = NbIsosDlg->getV();
653 return; //Cancel case
655 else if ( actionType == INCR || actionType == DECR ) {
657 if (actionType == DECR)
660 newNbUIso = UIso + delta;
661 newNbVIso = VIso + delta;
663 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
667 while( anAct!=NULL ) {
668 if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
669 // There are no casting to needed actor.
670 int aIsos[2]={newNbUIso,newNbVIso};
671 anActor->SetNbIsos(aIsos);
672 anActor->StoreIsoNumbers();
674 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
675 int aMgrId = window->getViewManager()->getGlobalId();
676 aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos);
678 anAct = aCollection->GetNextActor();
681 GeometryGUI::Modified();
685 void GEOMToolsGUI::OnDeflection()
687 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
688 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
691 bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
692 bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
693 int mgrId = window->getViewManager()->getGlobalId();
695 if (isOCC) { // if is OCCViewer
696 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
697 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
700 if (ic->MoreCurrent()) {
701 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
703 Standard_Real aDC, aPrevDC;
704 Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
706 aDC = ic->DeviationCoefficient();
708 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
709 (SUIT_Session::session()->activeApplication()->desktop());
710 DeflectionDlg->setTheDC(aDC);
714 if (DeflectionDlg->exec()) {
715 SUIT_OverrideCursor();
716 aNewDC = DeflectionDlg->getTheDC();
717 ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
719 for (; ic->MoreCurrent(); ic->NextCurrent()) {
720 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
721 ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
722 ic->Redisplay(CurObject);
723 appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC);
732 GeometryGUI::Modified();
734 else if (isVTK) { // if is VTKViewer
735 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
736 (SUIT_Session::session()->activeApplication());
740 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
744 SALOME_ListIO selected;
745 aSelMgr->selectedObjects(selected);
746 if (selected.IsEmpty())
749 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
753 SALOME_View* view = GEOM_Displayer::GetActiveView();
755 vtkActorCollection* aCollection = vtkActorCollection::New();
757 for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
758 Handle(SALOME_InteractiveObject) anIObject = It.Value();
759 SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
760 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
762 vtkActorCollection* anActors = vtkPrs->GetObjects();
763 anActors->InitTraversal();
764 vtkActor* anAct = anActors->GetNextActor();
765 aCollection->AddItem(anAct);
770 aCollection->InitTraversal();
776 vtkActor* anAct = aCollection->GetNextActor();
777 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
778 aDC = anActor->GetDeflection();
782 GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
783 (SUIT_Session::session()->activeApplication()->desktop());
784 DeflectionDlg->setTheDC(aDC);
785 if (DeflectionDlg->exec()) {
786 SUIT_OverrideCursor();
787 aDC = DeflectionDlg->getTheDC();
788 while (anAct != NULL) {
789 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
790 // There are no casting to needed actor.
791 anActor->SetDeflection(aDC);
792 appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC);
794 anAct = aCollection->GetNextActor();
797 GeometryGUI::Modified();
801 void GEOMToolsGUI::OnSelectOnly(int mode)
803 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
805 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
806 GEOM_Displayer aDisp (appStudy);
807 aDisp.GlobalSelection(mode);
808 getGeometryGUI()->setLocalSelectionMode(mode);
812 void GEOMToolsGUI::OnShowHideChildren( bool show )
814 SALOME_ListIO selected;
815 SalomeApp_Application* app =
816 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
818 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
820 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
823 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
824 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
825 if ( aSelMgr && appStudy ) {
826 aSelMgr->selectedObjects( selected );
827 if ( !selected.IsEmpty() ) {
828 _PTR(Study) aStudy = appStudy->studyDS();
829 _PTR(StudyBuilder) B = aStudy->NewBuilder();
831 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
833 SUIT_MessageBox::warning( app->desktop(),
834 QObject::tr( "WRN_WARNING" ),
835 QObject::tr( "WRN_STUDY_LOCKED" ) );
839 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
840 Handle(SALOME_InteractiveObject) IObject = It.Value();
842 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
843 _PTR(GenericAttribute) anAttr;
845 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
846 aExp->SetExpandable( show );
848 disp->EraseWithChildren(IObject,true);
853 app->updateObjectBrowser( false );
854 app->updateActions();
858 void GEOMToolsGUI::OnPointMarker()
860 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
864 void GEOMToolsGUI::OnMaterialProperties()
866 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
870 void GEOMToolsGUI::OnUnpublishObject() {
871 SALOME_ListIO selected;
872 SalomeApp_Application* app =
873 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
875 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
877 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
880 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
881 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
882 if ( aSelMgr && appStudy ) {
883 aSelMgr->selectedObjects( selected );
884 if ( !selected.IsEmpty() ) {
885 _PTR(Study) aStudy = appStudy->studyDS();
886 _PTR(StudyBuilder) B = aStudy->NewBuilder();
888 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
890 SUIT_MessageBox::warning( app->desktop(),
891 QObject::tr( "WRN_WARNING" ),
892 QObject::tr( "WRN_STUDY_LOCKED" ) );
896 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
897 Handle(SALOME_InteractiveObject) IObject = It.Value();
899 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
900 _PTR(GenericAttribute) anAttr;
902 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
903 aDrw->SetDrawable( false );
904 disp->EraseWithChildren(IObject);
907 aSelMgr->clearSelected();
910 app->updateObjectBrowser( false );
911 app->updateActions();
916 void GEOMToolsGUI::OnPublishObject() {
917 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
921 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
925 _PTR(Study) aStudy = appStudy->studyDS();
930 //Check lock of the study
931 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
933 SUIT_MessageBox::warning( app->desktop(),
934 QObject::tr( "WRN_WARNING" ),
935 QObject::tr( "WRN_STUDY_LOCKED" ) );
939 GEOMToolsGUI_PublishDlg * publishDlg =
940 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );