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)::DownCast( io )->SetShadingColor( aColor );
346 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(), COLOR_PROP, c);
348 io->Redisplay( Standard_True );
350 // store color to GEOM_Object
351 _PTR(Study) aStudy = appStudy->studyDS();
352 _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
353 GEOM::GEOM_Object_var anObject =
354 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
357 SALOMEDS::Color aSColor;
358 aSColor.R = (double)c.red() / 255.0;
359 aSColor.G = (double)c.green() / 255.0;
360 aSColor.B = (double)c.blue() / 255.0;
361 anObject->SetColor( aSColor );
362 anObject->SetAutoColor( false );
365 ic->UpdateCurrentViewer();
366 GeometryGUI::Modified();
368 } // first IO is not null
370 } // if ( selection not empty )
374 app->updateActions(); //SRN: To update a Save button in the toolbar
377 void GEOMToolsGUI::OnTexture()
379 SALOME_ListIO selected;
380 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
381 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
382 if ( app && appStudy ) {
383 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
385 aSelMgr->selectedObjects( selected );
386 if ( !selected.IsEmpty() ) {
387 SUIT_ViewWindow* window = app->desktop()->activeWindow();
388 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
389 int mgrId = window->getViewManager()->getGlobalId();
391 QString aTexture = QFileDialog::getOpenFileName(window,tr( "GEOM_SELECT_IMAGE"),QString(), tr("OCC_IMAGE_FILES"));
392 if( !aTexture.isEmpty() )
394 SUIT_OverrideCursor();
395 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
396 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
397 Handle(AIS_InteractiveObject) io ;
398 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
399 io = GEOMBase::GetAIS( It.Value(), true );
400 if ( !io.IsNull() ) {
401 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
402 Handle(GEOM_AISShape)::DownCast( io )->SetTextureFileName(TCollection_AsciiString(aTexture.toStdString().c_str()));
403 io->Redisplay( Standard_True );
404 } // if ( !io.IsNull() )
406 ic->UpdateCurrentViewer();
407 GeometryGUI::Modified();
408 GeometryGUI* myGeomGUI = getGeometryGUI();
409 myGeomGUI->OnGUIEvent(GEOMOp::OpTexture);
410 } // if ( !selFile.isEmpty() )
412 } // if ( selection not empty )
416 app->updateActions(); //SRN: To update a Save button in the toolbar
419 void GEOMToolsGUI::OnTransparency()
421 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
425 void GEOMToolsGUI::OnChangeTransparency( bool increase )
427 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
430 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
433 SALOME_ListIO selected;
434 aSelMgr->selectedObjects( selected );
435 if ( selected.IsEmpty() )
438 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
439 if ( FirstIOS.IsNull() )
443 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
447 SUIT_ViewWindow* window = app->desktop()->activeWindow();
448 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
449 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
452 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
455 SVTK_View* aView = vtkVW->getView();
457 float transp = aView->GetTransparency(FirstIOS);
459 // Compute new transparency value
460 transp = transp + delta;
463 else if ( transp > 1 )
466 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
467 aView->SetTransparency( It.Value(), transp );
470 GeometryGUI::Modified();
474 GEOMBase* gb = new GEOMBase();
475 Handle(GEOM_AISShape) aisShape;
477 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
478 if( aisShape.IsNull() )
480 float transp = aisShape->Transparency();
482 // Compute new transparency value
483 transp = transp + delta;
486 else if ( transp > 1 )
489 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
492 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
493 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
494 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
495 if ( !aisShape.IsNull() ) {
496 ic->SetTransparency( aisShape, transp, false );
497 ic->Redisplay( aisShape, Standard_False, Standard_True );
500 ic->UpdateCurrentViewer();
501 GeometryGUI::Modified();
505 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
507 SalomeApp_Application* app =
508 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
509 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
510 SUIT_ViewWindow* window = app->desktop()->activeWindow();
512 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
513 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
515 if(isOCC){ // if is OCCViewer
517 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
518 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
521 if ( ic->MoreCurrent() ) {
522 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
523 CurObject->restoreIsoNumbers();
524 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
526 int UIso = CurDrawer->UIsoAspect()->Number();
527 int VIso = CurDrawer->VIsoAspect()->Number();
532 if ( actionType == SHOWDLG ) {
533 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
534 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
536 NbIsosDlg->setU( UIso );
537 NbIsosDlg->setV( VIso );
539 if ( NbIsosDlg->exec() ) {
540 SUIT_OverrideCursor();
542 newNbUIso = NbIsosDlg->getU();
543 newNbVIso = NbIsosDlg->getV();
547 else if ( actionType == INCR || actionType == DECR ) {
549 if (actionType == DECR)
552 newNbUIso = UIso + delta;
553 newNbVIso = VIso + delta;
555 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
559 for(; ic->MoreCurrent(); ic->NextCurrent()) {
560 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
562 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
564 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbUIso) );
565 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbVIso) );
567 CurObject->storeIsoNumbers();
569 ic->SetLocalAttributes(CurObject, CurDrawer);
570 ic->Redisplay(CurObject);
572 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
573 int aMgrId = window->getViewManager()->getGlobalId();
574 aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_PROP, anIsos);
577 GeometryGUI::Modified();
579 else if(isVTK){ // if is VTKViewer
581 // Warning. It's works incorrect. must be recheked.
583 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
584 ( SUIT_Session::session()->activeApplication() );
587 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
590 SALOME_ListIO selected;
591 aSelMgr->selectedObjects( selected );
592 if ( selected.IsEmpty() )
595 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
599 SALOME_View* view = GEOM_Displayer::GetActiveView();
601 vtkActorCollection* aCollection = vtkActorCollection::New();
603 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
604 Handle(SALOME_InteractiveObject) anIObject = It.Value();
605 SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
606 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
608 vtkActorCollection* anActors = vtkPrs->GetObjects();
609 anActors->InitTraversal();
610 vtkActor* anAct = anActors->GetNextActor();
611 aCollection->AddItem(anAct);
616 aCollection->InitTraversal();
623 vtkActor* anAct = aCollection->GetNextActor();
624 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
625 anActor->RestoreIsoNumbers();
626 anActor->GetNbIsos(UIso,VIso);
634 if ( actionType == SHOWDLG ) {
635 GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
636 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
638 NbIsosDlg->setU( UIso );
639 NbIsosDlg->setV( VIso );
641 if ( NbIsosDlg->exec() ) {
642 SUIT_OverrideCursor();
644 newNbUIso = NbIsosDlg->getU();
645 newNbVIso = NbIsosDlg->getV();
647 return; //Cancel case
649 else if ( actionType == INCR || actionType == DECR ) {
651 if (actionType == DECR)
654 newNbUIso = UIso + delta;
655 newNbVIso = VIso + delta;
657 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
661 while( anAct!=NULL ) {
662 if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
663 // There are no casting to needed actor.
664 int aIsos[2]={newNbUIso,newNbVIso};
665 anActor->SetNbIsos(aIsos);
666 anActor->StoreIsoNumbers();
668 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
669 int aMgrId = window->getViewManager()->getGlobalId();
670 aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos);
672 anAct = aCollection->GetNextActor();
675 GeometryGUI::Modified();
679 void GEOMToolsGUI::OnDeflection()
681 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
682 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
685 bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
686 bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
687 int mgrId = window->getViewManager()->getGlobalId();
689 if (isOCC) { // if is OCCViewer
690 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
691 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
694 if (ic->MoreCurrent()) {
695 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
697 Standard_Real aDC, aPrevDC;
698 Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
700 aDC = ic->DeviationCoefficient();
702 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
703 (SUIT_Session::session()->activeApplication()->desktop());
704 DeflectionDlg->setTheDC(aDC);
708 if (DeflectionDlg->exec()) {
709 SUIT_OverrideCursor();
710 aNewDC = DeflectionDlg->getTheDC();
711 ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
713 for (; ic->MoreCurrent(); ic->NextCurrent()) {
714 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
715 ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
716 ic->Redisplay(CurObject);
717 appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC);
726 GeometryGUI::Modified();
728 else if (isVTK) { // if is VTKViewer
729 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
730 (SUIT_Session::session()->activeApplication());
734 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
738 SALOME_ListIO selected;
739 aSelMgr->selectedObjects(selected);
740 if (selected.IsEmpty())
743 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
747 SALOME_View* view = GEOM_Displayer::GetActiveView();
749 vtkActorCollection* aCollection = vtkActorCollection::New();
751 for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
752 Handle(SALOME_InteractiveObject) anIObject = It.Value();
753 SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
754 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
756 vtkActorCollection* anActors = vtkPrs->GetObjects();
757 anActors->InitTraversal();
758 vtkActor* anAct = anActors->GetNextActor();
759 aCollection->AddItem(anAct);
764 aCollection->InitTraversal();
770 vtkActor* anAct = aCollection->GetNextActor();
771 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
772 aDC = anActor->GetDeflection();
776 GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
777 (SUIT_Session::session()->activeApplication()->desktop());
778 DeflectionDlg->setTheDC(aDC);
779 if (DeflectionDlg->exec()) {
780 SUIT_OverrideCursor();
781 aDC = DeflectionDlg->getTheDC();
782 while (anAct != NULL) {
783 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
784 // There are no casting to needed actor.
785 anActor->SetDeflection(aDC);
786 appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC);
788 anAct = aCollection->GetNextActor();
791 GeometryGUI::Modified();
795 void GEOMToolsGUI::OnSelectOnly(int mode)
797 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
799 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
800 GEOM_Displayer aDisp (appStudy);
801 aDisp.GlobalSelection(mode);
802 getGeometryGUI()->setLocalSelectionMode(mode);
806 void GEOMToolsGUI::OnShowHideChildren( bool show )
808 SALOME_ListIO selected;
809 SalomeApp_Application* app =
810 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
812 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
814 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
817 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
818 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
819 if ( aSelMgr && appStudy ) {
820 aSelMgr->selectedObjects( selected );
821 if ( !selected.IsEmpty() ) {
822 _PTR(Study) aStudy = appStudy->studyDS();
823 _PTR(StudyBuilder) B = aStudy->NewBuilder();
825 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
827 SUIT_MessageBox::warning( app->desktop(),
828 QObject::tr( "WRN_WARNING" ),
829 QObject::tr( "WRN_STUDY_LOCKED" ) );
833 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
834 Handle(SALOME_InteractiveObject) IObject = It.Value();
836 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
837 _PTR(GenericAttribute) anAttr;
839 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
840 aExp->SetExpandable( show );
842 disp->EraseWithChildren(IObject,true);
847 app->updateObjectBrowser( false );
848 app->updateActions();
852 void GEOMToolsGUI::OnPointMarker()
854 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
858 void GEOMToolsGUI::OnMaterialProperties()
860 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
864 void GEOMToolsGUI::OnUnpublishObject() {
865 SALOME_ListIO selected;
866 SalomeApp_Application* app =
867 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
869 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
871 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
874 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
875 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
876 if ( aSelMgr && appStudy ) {
877 aSelMgr->selectedObjects( selected );
878 if ( !selected.IsEmpty() ) {
879 _PTR(Study) aStudy = appStudy->studyDS();
880 _PTR(StudyBuilder) B = aStudy->NewBuilder();
882 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
884 SUIT_MessageBox::warning( app->desktop(),
885 QObject::tr( "WRN_WARNING" ),
886 QObject::tr( "WRN_STUDY_LOCKED" ) );
890 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
891 Handle(SALOME_InteractiveObject) IObject = It.Value();
893 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
894 _PTR(GenericAttribute) anAttr;
896 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
897 aDrw->SetDrawable( false );
898 disp->EraseWithChildren(IObject);
901 aSelMgr->clearSelected();
904 app->updateObjectBrowser( false );
905 app->updateActions();
910 void GEOMToolsGUI::OnPublishObject() {
911 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
915 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
919 _PTR(Study) aStudy = appStudy->studyDS();
924 //Check lock of the study
925 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
927 SUIT_MessageBox::warning( app->desktop(),
928 QObject::tr( "WRN_WARNING" ),
929 QObject::tr( "WRN_STUDY_LOCKED" ) );
933 GEOMToolsGUI_PublishDlg * publishDlg =
934 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );