1 // Copyright (C) 2007-2012 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOMToolsGUI_1.cxx
25 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
27 #include <PyConsole_Console.h>
29 #include "GEOMToolsGUI.h"
30 #include "GEOMToolsGUI_TransparencyDlg.h"
31 #include "GEOMToolsGUI_NbIsosDlg.h"
32 #include "GEOMToolsGUI_DeflectionDlg.h"
33 #include "GEOMToolsGUI_MarkerDlg.h"
34 #include "GEOMToolsGUI_PublishDlg.h"
35 #include "GEOMToolsGUI_MaterialPropertiesDlg.h"
36 #include "GEOMToolsGUI_LineWidthDlg.h"
37 #include <Material_Model.h>
39 #include <GEOM_VTKPropertyMaterial.hxx>
41 #include <GeometryGUI.h>
42 #include <GeometryGUI_Operations.h>
43 #include <GEOM_Constants.h>
44 #include <GEOM_Displayer.h>
47 #include <GEOM_Actor.h>
49 #include <Basics_OCCTVersion.hxx>
51 #include <SALOME_ListIO.hxx>
52 #include <SALOME_ListIteratorOfListIO.hxx>
57 #include <SVTK_ViewModel.h>
58 #include <SVTK_ViewWindow.h>
59 #include <SVTK_View.h>
61 #include <OCCViewer_ViewModel.h>
63 #include <SUIT_ViewManager.h>
64 #include <SUIT_Desktop.h>
65 #include <SUIT_ResourceMgr.h>
66 #include <SUIT_Session.h>
67 #include <SUIT_OverrideCursor.h>
68 #include <SUIT_MessageBox.h>
69 #include <SUIT_Tools.h>
71 #include <SalomeApp_Application.h>
72 #include <SalomeApp_Study.h>
73 #include <SalomeApp_Module.h>
75 #include <LightApp_SelectionMgr.h>
76 #include <LightApp_NameDlg.h>
78 #include <GEOMImpl_Types.hxx>
80 #include "utilities.h"
83 #include <AIS_Drawer.hxx>
84 #include <Prs3d_IsoAspect.hxx>
85 #include <Prs3d_PointAspect.hxx>
86 #include <Graphic3d_AspectMarker3d.hxx>
87 #include <Graphic3d_AspectLine3d.hxx>
88 #include <AIS_ListIteratorOfListOfInteractive.hxx>
89 #include <AIS_ListOfInteractive.hxx>
92 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
93 #include <TColStd_HArray1OfByte.hxx>
95 #include <Graphic3d_HArray1OfBytes.hxx>
100 #include <QColorDialog>
101 #include <QInputDialog>
102 #include <QFileDialog>
105 #include <QGridLayout>
108 #include <QPushButton>
112 #include <vtkRenderer.h>
115 // If the next macro is defined, autocolor feature works for all sub-shapes;
116 // if it is undefined, autocolor feature works for groups only
117 #define GENERAL_AUTOCOLOR
118 // Below macro, when uncommented, switches on simplified (more performant) algorithm
119 // of auto-color picking up
120 #define SIMPLE_AUTOCOLOR
122 void GEOMToolsGUI::OnCheckGeometry()
124 SalomeApp_Application* app =
125 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
126 PyConsole_Console* pyConsole = app->pythonConsole();
129 pyConsole->exec("from GEOM_usinggeom import *");
132 void GEOMToolsGUI::OnAutoColor()
134 SALOME_ListIO selected;
135 SalomeApp_Application* app =
136 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
140 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
141 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
142 if (!aSelMgr || !appStudy)
145 aSelMgr->selectedObjects(selected);
146 if (selected.IsEmpty())
149 Handle(SALOME_InteractiveObject) anIObject = selected.First();
151 _PTR(Study) aStudy = appStudy->studyDS();
152 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
153 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
154 if (CORBA::is_nil(aMainObject))
157 aMainObject->SetAutoColor( true );
159 QList<SALOMEDS::Color> aReservedColors;
161 GEOM_Displayer aDisp (appStudy);
163 SALOME_View* vf = aDisp.GetActiveView();
165 SUIT_ViewWindow* window = app->desktop()->activeWindow();
166 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
167 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
169 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
171 _PTR(SObject) aChildSObject( it->Value() );
172 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
173 if( CORBA::is_nil( aChildObject ) )
176 #ifndef GENERAL_AUTOCOLOR // auto-color for groups only
177 if( aChildObject->GetType() != GEOM_GROUP )
179 #endif // GENERAL_AUTOCOLOR
181 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
182 SALOMEDS::Color aColor = GEOM_Displayer::getPredefinedUniqueColor();
183 #else // old algorithm for auto-colors
184 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
185 aReservedColors.append( aColor );
186 #endif // SIMPLE_AUTOCOLOR
187 aChildObject->SetColor( aColor );
189 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
191 SALOME_Prs* aPrs = vf->CreatePrs( aChildSObject->GetID().c_str() );
195 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
198 SVTK_View* aView = vtkVW->getView();
199 SUIT_OverrideCursor();
200 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
201 aView->SetColor( It.Value(), c );
205 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
206 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
208 SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
212 AIS_ListOfInteractive aList;
213 anOCCPrs->GetObjects( aList );
214 if( !aList.Extent() )
217 Handle(AIS_InteractiveObject) io = aList.First();
221 Quantity_Color aQuanColor( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
223 // Set color for a point
224 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
225 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
226 Quantity_Color aCurColor;
227 Standard_Real aCurScale;
228 Aspect_TypeOfMarker aCurTypeOfMarker;
229 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
230 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
231 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
234 Standard_Integer aWidth, aHeight;
235 aCurPointAspect->GetTextureSize( aWidth, aHeight );
237 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
238 Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
240 Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
243 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aQuanColor, 1, aWidth, aHeight, aTexture ) );
245 ic->SetLocalAttributes( io, aCurDrawer );
247 io->SetColor( aQuanColor );
248 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) {
249 Handle(GEOM_AISShape) aGAISShape = Handle(GEOM_AISShape)::DownCast( io );
250 aGAISShape->SetShadingColor( aQuanColor );
251 aGAISShape->storeBoundaryColors();
254 io->Redisplay( Standard_True );
258 app->updateActions(); //SRN: To update a Save button in the toolbar
261 void GEOMToolsGUI::OnDisableAutoColor()
263 SALOME_ListIO selected;
264 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
268 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
269 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
270 if( !aSelMgr || !appStudy )
273 aSelMgr->selectedObjects( selected );
274 if( selected.IsEmpty() )
277 Handle(SALOME_InteractiveObject) anIObject = selected.First();
279 _PTR(Study) aStudy = appStudy->studyDS();
280 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
281 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
282 if( CORBA::is_nil( aMainObject ) )
285 aMainObject->SetAutoColor( false );
288 void GEOMToolsGUI::SetColor( const QString& entry, const QColor& color, bool updateViewer )
290 if ( entry.isEmpty() || !color.isValid() ) return;
292 // get active application
293 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
297 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
298 if ( !appStudy ) return;
301 SUIT_ViewWindow* window = app->desktop()->activeWindow();
302 if ( !window ) return;
304 bool isOCC = window->getViewManager()->getType() == OCCViewer_Viewer::Type();
305 bool isVTK = window->getViewManager()->getType() == SVTK_Viewer::Type();
308 int mgrId = window->getViewManager()->getGlobalId();
310 Handle(SALOME_InteractiveObject) IO =
311 new SALOME_InteractiveObject( entry.toLatin1().data(), "GEOM", "");
314 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
315 if ( !vtkVW ) return;
316 SVTK_View* aView = vtkVW->getView();
318 GEOMToolsGUI::setVtkColor( appStudy, mgrId, aView, IO, color );
319 if ( updateViewer ) aView->Repaint();
322 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
323 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
324 GEOMToolsGUI::setOccColor( appStudy, mgrId, ic, IO, color );
325 if ( updateViewer ) ic->UpdateCurrentViewer();
328 // mark study as modified
329 GeometryGUI::Modified();
332 app->updateActions(); //SRN: To update a Save button in the toolbar
335 void GEOMToolsGUI::OnColor()
337 // get active application
338 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
342 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
343 if ( !appStudy ) return;
345 // get selection manager
346 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
347 if ( !aSelMgr ) return;
350 SALOME_ListIO selected;
351 aSelMgr->selectedObjects( selected );
352 if ( selected.IsEmpty() ) return;
355 SUIT_ViewWindow* window = app->desktop()->activeWindow();
356 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
357 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
360 int mgrId = window ? window->getViewManager()->getGlobalId() : -1;
363 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
364 if ( !vtkVW ) return;
366 // get initial color (use first object from selection)
367 SVTK_View* aView = vtkVW->getView();
368 QColor color = aView->GetColor( selected.First() );
369 QVariant v = appStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
371 // show Choose Color dialog box
372 color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
373 if ( !color.isValid() ) return;
375 // iterate through list of objects and assign new color
376 SUIT_OverrideCursor();
377 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
378 GEOMToolsGUI::setVtkColor( appStudy, mgrId, aView, It.Value(), color );
383 // find AIS interactive object (for first item in selection)
384 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
385 if ( io.IsNull() ) return;
387 // get initial color (use first object from selection)
388 Quantity_Color aColor;
390 QColor color = QColor((int)( aColor.Red() * 255.0 ),
391 (int)( aColor.Green() * 255.0 ),
392 (int)( aColor.Blue() * 255.0 ));
393 QVariant v = appStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
395 // show Choose Color dialog box
396 color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
397 if ( !color.isValid() ) return;
399 // iterate through list of objects and assign new color
400 SUIT_OverrideCursor();
401 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
402 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
403 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
404 GEOMToolsGUI::setOccColor( appStudy, mgrId, ic, It.Value(), color );
406 ic->UpdateCurrentViewer();
409 // mark study as modified
410 GeometryGUI::Modified();
413 app->updateActions(); //SRN: To update a Save button in the toolbar
417 void GEOMToolsGUI::setVtkColor( SalomeApp_Study* study, // study
418 int mgrId, // view window id
419 SVTK_View* view, // VTK view
420 const Handle(SALOME_InteractiveObject)& IO, // interactive object
421 const QColor& color ) // color
423 // get material property
425 matProp = study->getObjectProperty( mgrId, IO->getEntry(), GEOM::propertyName( GEOM::Material ), matProp ).toString();
426 Material_Model material;
427 material.fromProperties( matProp );
429 // change color only for shapes with not physical type of material
430 if ( !material.isPhysical() ) {
431 view->SetColor( IO, color );
432 study->setObjectProperty( mgrId, IO->getEntry(), GEOM::propertyName( GEOM::Color ), color );
435 // store color to GEOM_Object
436 _PTR(Study) aStudy = study->studyDS();
437 _PTR(SObject) aSObject( aStudy->FindObjectID( IO->getEntry() ) );
438 if ( !aSObject ) return;
440 GEOM::GEOM_Object_var anObject =
441 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
443 if ( CORBA::is_nil( anObject ) ) return;
445 SALOMEDS::Color aSColor;
446 aSColor.R = (double)color.red() / 255.0;
447 aSColor.G = (double)color.green() / 255.0;
448 aSColor.B = (double)color.blue() / 255.0;
449 anObject->SetColor( aSColor );
450 anObject->SetAutoColor( false );
453 void GEOMToolsGUI::setOccColor( SalomeApp_Study* study, // study
454 int mgrId, // view window id
455 const Handle(AIS_InteractiveContext)& ic, // OCC interactive context
456 const Handle(SALOME_InteractiveObject)& IO, // interactive object
457 const QColor& color ) // color
460 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( IO, true );
461 if ( io.IsNull() ) return;
463 // get material property
465 matProp = study->getObjectProperty( mgrId, IO->getEntry(), GEOM::propertyName( GEOM::Material ), matProp ).toString();
466 Material_Model material;
467 material.fromProperties( matProp );
469 Quantity_Color aColor = Quantity_Color( color.red() / 255., color.green() / 255., color.blue() / 255., Quantity_TOC_RGB );
471 // change color only for shapes with not physical type of material
472 if ( !material.isPhysical() ) {
473 if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) {
474 TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape();
475 bool onlyVertex = (theShape.ShapeType() == TopAbs_VERTEX || GEOM_Displayer::isCompoundOfVertices( theShape ));
477 // set color for a point
478 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
479 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
480 Quantity_Color aCurColor;
481 Standard_Real aCurScale;
482 Aspect_TypeOfMarker aCurTypeOfMarker;
483 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
484 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
485 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aColor, aCurScale ) );
488 Standard_Integer aWidth, aHeight;
489 aCurPointAspect->GetTextureSize( aWidth, aHeight );
490 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
491 Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
493 Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
495 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aColor, 1, aWidth, aHeight, aTexture ) );
497 ic->SetLocalAttributes( io, aCurDrawer, Standard_False );
501 io->SetColor( aColor );
502 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) {
503 Handle(GEOM_AISShape) aGAISShape = Handle(GEOM_AISShape)::DownCast( io );
504 aGAISShape->SetShadingColor( aColor );
505 aGAISShape->storeBoundaryColors();
508 io->Redisplay( Standard_True );
510 study->setObjectProperty( mgrId, IO->getEntry(), GEOM::propertyName( GEOM::Color ), color );
513 // store color to GEOM_Object
514 _PTR(Study) aStudy = study->studyDS();
515 _PTR(SObject) aSObject( aStudy->FindObjectID( IO->getEntry() ) );
516 GEOM::GEOM_Object_var anObject =
517 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
518 SALOMEDS::Color aSColor;
519 aSColor.R = (double)color.red() / 255.0;
520 aSColor.G = (double)color.green() / 255.0;
521 aSColor.B = (double)color.blue() / 255.0;
522 anObject->SetColor( aSColor );
523 anObject->SetAutoColor( false );
526 void GEOMToolsGUI::OnTexture()
528 SALOME_ListIO selected;
529 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
530 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
531 if ( app && appStudy ) {
532 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
534 aSelMgr->selectedObjects( selected );
535 if ( !selected.IsEmpty() ) {
536 SUIT_ViewWindow* window = app->desktop()->activeWindow();
537 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
539 QString aTexture = QFileDialog::getOpenFileName(window,tr( "GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
540 if( !aTexture.isEmpty() )
542 SUIT_OverrideCursor();
543 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
544 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
545 Handle(AIS_InteractiveObject) io ;
546 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
547 io = GEOMBase::GetAIS( It.Value(), true );
548 if ( !io.IsNull() ) {
549 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
550 Handle(GEOM_AISShape)::DownCast( io )->SetTextureFileName(TCollection_AsciiString(aTexture.toStdString().c_str()));
551 io->Redisplay( Standard_True );
552 } // if ( !io.IsNull() )
554 ic->UpdateCurrentViewer();
555 GeometryGUI::Modified();
556 GeometryGUI* myGeomGUI = getGeometryGUI();
557 myGeomGUI->OnGUIEvent(GEOMOp::OpTexture);
558 } // if ( !selFile.isEmpty() )
560 } // if ( selection not empty )
564 app->updateActions(); //SRN: To update a Save button in the toolbar
567 void GEOMToolsGUI::OnTransparency()
569 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
573 void GEOMToolsGUI::OnChangeTransparency( bool increase )
575 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
578 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
581 SALOME_ListIO selected;
582 aSelMgr->selectedObjects( selected );
583 if ( selected.IsEmpty() )
586 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
587 if ( FirstIOS.IsNull() )
591 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
595 SUIT_ViewWindow* window = app->desktop()->activeWindow();
596 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
597 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
600 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
603 SVTK_View* aView = vtkVW->getView();
605 float transp = aView->GetTransparency(FirstIOS);
607 // Compute new transparency value
608 transp = transp + delta;
611 else if ( transp > 1 )
614 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
615 aView->SetTransparency( It.Value(), transp );
618 GeometryGUI::Modified();
622 GEOMBase* gb = new GEOMBase();
623 Handle(GEOM_AISShape) aisShape;
625 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
626 if( aisShape.IsNull() )
628 float transp = aisShape->Transparency();
630 // Compute new transparency value
631 transp = transp + delta;
634 else if ( transp > 1 )
637 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
640 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
641 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
642 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
643 if ( !aisShape.IsNull() ) {
644 ic->SetTransparency( aisShape, transp, false );
645 ic->Redisplay( aisShape, Standard_False, Standard_True );
648 ic->UpdateCurrentViewer();
649 GeometryGUI::Modified();
653 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
655 SalomeApp_Application* app =
656 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
657 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
658 SUIT_ViewWindow* window = app->desktop()->activeWindow();
660 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
661 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
663 if(isOCC){ // if is OCCViewer
665 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
666 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
667 int aMgrId = window->getViewManager()->getGlobalId();
670 if ( ic->MoreCurrent() ) {
671 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
672 CurObject->restoreIsoNumbers();
673 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
675 int UIso = CurDrawer->UIsoAspect()->Number();
676 int VIso = CurDrawer->VIsoAspect()->Number();
681 if ( actionType == SHOWDLG ) {
682 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
683 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
685 NbIsosDlg->setU( UIso );
686 NbIsosDlg->setV( VIso );
688 if ( NbIsosDlg->exec() ) {
689 SUIT_OverrideCursor();
691 newNbUIso = NbIsosDlg->getU();
692 newNbVIso = NbIsosDlg->getV();
696 else if ( actionType == INCR || actionType == DECR ) {
698 if (actionType == DECR)
701 newNbUIso = UIso + delta;
702 newNbVIso = VIso + delta;
704 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
708 for(; ic->MoreCurrent(); ic->NextCurrent()) {
709 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
711 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
713 QVariant v = aStudy->getObjectProperty( aMgrId, CurObject->getIO()->getEntry(), GEOM::propertyName( GEOM::LineWidth ) , QVariant() );
715 int width = v.isValid() ? v.toInt() : 1;
717 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, width , newNbUIso) );
718 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, width , newNbVIso) );
720 CurObject->storeIsoNumbers();
722 ic->SetLocalAttributes(CurObject, CurDrawer);
723 ic->Redisplay(CurObject);
725 QString anIsos = QString("%1%2%3").arg(newNbUIso).arg(GEOM::subSectionSeparator()).arg(newNbVIso);
726 aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos);
729 GeometryGUI::Modified();
731 else if(isVTK){ // if is VTKViewer
733 // Warning. It's works incorrect. must be recheked.
735 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
736 ( SUIT_Session::session()->activeApplication() );
739 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
742 SALOME_ListIO selected;
743 aSelMgr->selectedObjects( selected );
744 if ( selected.IsEmpty() )
747 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
751 int aMgrId = window->getViewManager()->getGlobalId();
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();
777 vtkActor* anAct = aCollection->GetNextActor();
778 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
779 anActor->RestoreIsoNumbers();
780 anActor->GetNbIsos(UIso,VIso);
788 if ( actionType == SHOWDLG ) {
789 GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
790 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
792 NbIsosDlg->setU( UIso );
793 NbIsosDlg->setV( VIso );
795 if ( NbIsosDlg->exec() ) {
796 SUIT_OverrideCursor();
798 newNbUIso = NbIsosDlg->getU();
799 newNbVIso = NbIsosDlg->getV();
801 return; //Cancel case
803 else if ( actionType == INCR || actionType == DECR ) {
805 if (actionType == DECR)
808 newNbUIso = UIso + delta;
809 newNbVIso = VIso + delta;
811 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
815 while( anAct!=NULL ) {
816 if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
817 // There are no casting to needed actor.
818 int aIsos[2]={newNbUIso,newNbVIso};
819 anActor->SetNbIsos(aIsos);
820 anActor->StoreIsoNumbers();
822 QString anIsos = QString("%1%2%3").arg(newNbUIso).arg(GEOM::subSectionSeparator()).arg(newNbVIso);
823 aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos);
825 anAct = aCollection->GetNextActor();
828 GeometryGUI::Modified();
832 void GEOMToolsGUI::OnDeflection()
834 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
835 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
838 bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
839 bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
840 int mgrId = window ? window->getViewManager()->getGlobalId() : -1;
842 if (isOCC) { // if is OCCViewer
843 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
844 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
847 if (ic->MoreCurrent()) {
848 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
850 Standard_Real aDC, aPrevDC;
851 Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
853 aDC = ic->DeviationCoefficient();
855 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
856 (SUIT_Session::session()->activeApplication()->desktop());
857 DeflectionDlg->setTheDC(aDC);
861 if (DeflectionDlg->exec()) {
862 SUIT_OverrideCursor();
863 aNewDC = DeflectionDlg->getTheDC();
864 ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
866 for (; ic->MoreCurrent(); ic->NextCurrent()) {
867 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
868 ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
869 ic->Redisplay(CurObject);
870 appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), GEOM::propertyName( GEOM::Deflection ), aNewDC);
879 GeometryGUI::Modified();
881 else if (isVTK) { // if is VTKViewer
882 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
883 (SUIT_Session::session()->activeApplication());
887 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
891 SALOME_ListIO selected;
892 aSelMgr->selectedObjects(selected);
893 if (selected.IsEmpty())
896 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
900 SALOME_View* view = GEOM_Displayer::GetActiveView();
902 vtkActorCollection* aCollection = vtkActorCollection::New();
904 for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
905 Handle(SALOME_InteractiveObject) anIObject = It.Value();
906 SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
907 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
909 vtkActorCollection* anActors = vtkPrs->GetObjects();
910 anActors->InitTraversal();
911 vtkActor* anAct = anActors->GetNextActor();
912 aCollection->AddItem(anAct);
917 aCollection->InitTraversal();
923 vtkActor* anAct = aCollection->GetNextActor();
924 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
925 aDC = anActor->GetDeflection();
929 GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
930 (SUIT_Session::session()->activeApplication()->desktop());
931 DeflectionDlg->setTheDC(aDC);
932 if (DeflectionDlg->exec()) {
933 SUIT_OverrideCursor();
934 aDC = DeflectionDlg->getTheDC();
935 while (anAct != NULL) {
936 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
937 // There are no casting to needed actor.
938 anActor->SetDeflection(aDC);
939 appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC);
941 anAct = aCollection->GetNextActor();
944 GeometryGUI::Modified();
948 void GEOMToolsGUI::OnSelectOnly(int mode)
950 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
952 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
953 GEOM_Displayer aDisp (appStudy);
954 aDisp.GlobalSelection(mode);
955 getGeometryGUI()->setLocalSelectionMode(mode);
959 void GEOMToolsGUI::OnDiscloseConcealChildren( bool show )
961 SALOME_ListIO selected;
962 SalomeApp_Application* app =
963 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
965 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
967 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
970 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
971 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
972 if ( aSelMgr && appStudy ) {
973 aSelMgr->selectedObjects( selected );
974 if ( !selected.IsEmpty() ) {
975 _PTR(Study) aStudy = appStudy->studyDS();
976 _PTR(StudyBuilder) B = aStudy->NewBuilder();
978 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
980 SUIT_MessageBox::warning( app->desktop(),
981 QObject::tr( "WRN_WARNING" ),
982 QObject::tr( "WRN_STUDY_LOCKED" ) );
986 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
987 Handle(SALOME_InteractiveObject) IObject = It.Value();
989 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
990 _PTR(GenericAttribute) anAttr;
992 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
993 aExp->SetExpandable( show );
995 disp->EraseWithChildren(IObject,true);
1000 app->updateObjectBrowser( false );
1001 app->updateActions();
1005 void GEOMToolsGUI::OnPointMarker()
1007 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
1011 void GEOMToolsGUI::OnMaterialProperties()
1013 GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
1017 void GEOMToolsGUI::OnMaterialsLibrary()
1019 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
1020 dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
1024 void GEOMToolsGUI::OnUnpublishObject() {
1025 SALOME_ListIO selected;
1026 SalomeApp_Application* app =
1027 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1029 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
1031 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
1033 if ( app && disp ) {
1034 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1035 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1036 if ( aSelMgr && appStudy ) {
1037 aSelMgr->selectedObjects( selected );
1038 if ( !selected.IsEmpty() ) {
1039 _PTR(Study) aStudy = appStudy->studyDS();
1040 _PTR(StudyBuilder) B = aStudy->NewBuilder();
1042 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
1044 SUIT_MessageBox::warning( app->desktop(),
1045 QObject::tr( "WRN_WARNING" ),
1046 QObject::tr( "WRN_STUDY_LOCKED" ) );
1050 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
1051 Handle(SALOME_InteractiveObject) IObject = It.Value();
1053 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
1054 _PTR(GenericAttribute) anAttr;
1056 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
1057 aDrw->SetDrawable( false );
1058 disp->EraseWithChildren(IObject);
1061 aSelMgr->clearSelected();
1064 app->updateObjectBrowser( false );
1065 app->updateActions();
1070 void GEOMToolsGUI::OnPublishObject() {
1071 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1075 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1079 _PTR(Study) aStudy = appStudy->studyDS();
1084 //Check lock of the study
1085 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
1087 SUIT_MessageBox::warning( app->desktop(),
1088 QObject::tr( "WRN_WARNING" ),
1089 QObject::tr( "WRN_STUDY_LOCKED" ) );
1093 GEOMToolsGUI_PublishDlg * publishDlg =
1094 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
1099 void GEOMToolsGUI::OnEdgeWidth()
1101 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1102 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1105 bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
1106 bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
1107 int mgrId = window ? window->getViewManager()->getGlobalId() : -1;
1109 if (isOCC) { // if is OCCViewer
1110 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
1111 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
1112 SALOME_View* view = GEOM_Displayer::GetActiveView();
1114 if (ic->MoreCurrent()) {
1115 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
1117 int aWidth = (int)CurObject->Width();
1119 GEOMToolsGUI_LineWidthDlg * Dlg = new GEOMToolsGUI_LineWidthDlg
1120 (SUIT_Session::session()->activeApplication()->desktop(),"EDGE_WIDTH_TLT");
1121 Dlg->setTheLW(aWidth);
1124 aNewWidth = Dlg->getTheLW();
1125 bool ok = (aNewWidth != aWidth && aNewWidth != 0 );
1127 for(; ic->MoreCurrent(); ic->NextCurrent()) {
1128 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
1129 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>(view->CreatePrs(CurObject->getIO()->getEntry()));
1130 AIS_ListOfInteractive anAISObjects;
1131 aPrs->GetObjects( anAISObjects );
1132 AIS_ListIteratorOfListOfInteractive aIter( anAISObjects );
1133 for ( ; aIter.More(); aIter.Next() ) {
1134 Handle(SALOME_AISShape) cur = Handle(SALOME_AISShape)::DownCast(aIter.Value());
1135 if ( !cur.IsNull() ) {
1136 cur->SetWidth(aNewWidth);
1140 appStudy->setObjectProperty(mgrId, CurObject->getIO()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aNewWidth);
1148 GeometryGUI::Modified();
1150 else if (isVTK) { // if is VTKViewer
1151 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
1152 (SUIT_Session::session()->activeApplication());
1156 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1160 SALOME_ListIO selected;
1161 aSelMgr->selectedObjects(selected);
1162 if (selected.IsEmpty())
1165 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
1169 SALOME_View* view = GEOM_Displayer::GetActiveView();
1171 vtkActorCollection* aCollection = vtkActorCollection::New();
1173 for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
1174 Handle(SALOME_InteractiveObject) anIObject = It.Value();
1175 SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
1176 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
1178 vtkActorCollection* anActors = vtkPrs->GetObjects();
1179 anActors->InitTraversal();
1180 vtkActor* anAct = anActors->GetNextActor();
1181 aCollection->AddItem(anAct);
1186 aCollection->InitTraversal();
1192 vtkActor* anAct = aCollection->GetNextActor();
1193 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
1194 aWidth = anActor->GetWidth();
1198 GEOMToolsGUI_LineWidthDlg * Dlg = new GEOMToolsGUI_LineWidthDlg
1199 (SUIT_Session::session()->activeApplication()->desktop(),"EDGE_WIDTH_TLT");
1201 Dlg->setTheLW(aWidth);
1203 SUIT_OverrideCursor();
1204 aWidth = Dlg->getTheLW();
1205 while (anAct != NULL) {
1206 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
1207 // There are no casting to needed actor.
1208 anActor->SetWidth(aWidth);
1209 appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth);
1211 anAct = aCollection->GetNextActor();
1214 GeometryGUI::Modified();
1219 void GEOMToolsGUI::OnIsosWidth() {
1220 SalomeApp_Application* app =
1221 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1222 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1223 SUIT_ViewWindow* window = app->desktop()->activeWindow();
1225 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1226 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
1228 if(isOCC){ // if is OCCViewer
1230 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
1231 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
1232 int aMgrId = window->getViewManager()->getGlobalId();
1235 if ( ic->MoreCurrent() ) {
1236 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
1237 CurObject->restoreIsoNumbers();
1238 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
1240 Handle(Graphic3d_AspectLine3d) asp = CurDrawer->UIsoAspect()->Aspect();
1243 Aspect_TypeOfLine T;
1247 int aWidth = (int)W;
1249 GEOMToolsGUI_LineWidthDlg * Dlg =
1250 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(),"ISOS_WIDTH_TLT" );
1252 Dlg->setTheLW( aWidth );
1254 if ( Dlg->exec() ) {
1255 SUIT_OverrideCursor();
1256 aWidth = Dlg->getTheLW();
1257 } else //Cancel case
1260 for(; ic->MoreCurrent(); ic->NextCurrent()) {
1261 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
1263 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
1265 CurObject->Attributes()->UIsoAspect()->SetWidth(aWidth);
1266 CurObject->Attributes()->VIsoAspect()->SetWidth(aWidth);
1268 ic->Redisplay(CurObject);
1270 aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth);
1272 GeometryGUI::Modified();
1275 else if(isVTK){ // if is VTKViewer
1277 // Warning. It's works incorrect. must be recheked.
1279 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
1280 ( SUIT_Session::session()->activeApplication() );
1283 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1286 SALOME_ListIO selected;
1287 aSelMgr->selectedObjects( selected );
1288 if ( selected.IsEmpty() )
1291 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
1295 int aMgrId = window->getViewManager()->getGlobalId();
1297 SALOME_View* view = GEOM_Displayer::GetActiveView();
1299 vtkActorCollection* aCollection = vtkActorCollection::New();
1301 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
1302 Handle(SALOME_InteractiveObject) anIObject = It.Value();
1303 SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
1304 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
1306 vtkActorCollection* anActors = vtkPrs->GetObjects();
1307 anActors->InitTraversal();
1308 vtkActor* anAct = anActors->GetNextActor();
1309 aCollection->AddItem(anAct);
1314 aCollection->InitTraversal();
1320 vtkActor* anAct = aCollection->GetNextActor();
1321 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
1322 aWidth = anActor->GetIsosWidth();
1327 GEOMToolsGUI_LineWidthDlg* Dlg =
1328 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
1330 Dlg->setTheLW( aWidth );
1332 SUIT_OverrideCursor();
1333 aWidth = Dlg->getTheLW();
1335 return; //Cancel case
1337 while( anAct!= NULL ) {
1338 if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
1339 // There are no casting to needed actor.
1340 anActor->SetIsosWidth(aWidth);
1341 aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth);
1343 anAct = aCollection->GetNextActor();
1347 GeometryGUI::Modified();
1351 void GEOMToolsGUI::OnBringToFront() {
1352 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1356 SalomeApp_Module* mod = dynamic_cast<SalomeApp_Module*>(app->activeModule());
1360 GEOM_Displayer* disp = dynamic_cast<GEOM_Displayer*>(mod->displayer());
1365 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1369 SALOME_ListIO selected;
1370 aSelMgr->selectedObjects( selected );
1371 if ( selected.IsEmpty() )
1374 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1378 SUIT_ViewWindow* window = app->desktop()->activeWindow();
1380 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
1384 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1386 QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
1387 bool checked = a->isChecked();
1390 GEOMBase* gb = new GEOMBase();
1391 Handle(GEOM_AISShape) aisShape;
1392 int aMgrId = window->getViewManager()->getGlobalId();
1394 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
1395 SALOME_ListIO anIOlst;
1396 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
1397 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
1398 if ( !aisShape.IsNull() ) {
1399 appStudy->setObjectProperty( aMgrId, aisShape->getIO()->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
1400 aisShape->setTopLevel(checked);
1401 anIOlst.Append(aisShape->getIO());
1404 disp->Redisplay(anIOlst);
1405 GeometryGUI::Modified();
1409 void GEOMToolsGUI::OnClsBringToFront() {
1410 SalomeApp_Application* app =
1411 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1415 SalomeApp_Module* mod = dynamic_cast<SalomeApp_Module*>(app->activeModule());
1419 GEOM_Displayer* disp = dynamic_cast<GEOM_Displayer*>(mod->displayer());
1425 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1429 SUIT_ViewWindow* window = app->desktop()->activeWindow();
1431 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1433 if(isOCC){ // if is OCCViewer
1435 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
1436 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
1437 int aMgrId = window->getViewManager()->getGlobalId();
1439 SALOME_ListIO anIOlst;
1440 AIS_ListOfInteractive aList;
1441 ic->DisplayedObjects( aList );
1442 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() ) {
1444 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(it.Value());
1446 if(CurObject.IsNull())
1449 appStudy->setObjectProperty( aMgrId, QString(CurObject->getIO()->getEntry()), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
1450 CurObject->setTopLevel(Standard_False);
1451 anIOlst.Append(CurObject->getIO());
1453 disp->Redisplay(anIOlst);
1454 GeometryGUI::Modified();
1458 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
1460 if ( !theParam.canConvert<QString>() ) return;
1462 QString theName = theParam.toString();
1464 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1467 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1468 if ( !study ) return;
1470 LightApp_SelectionMgr* selMgr = app->selectionMgr();
1472 SALOME_ListIO selected;
1473 selMgr->selectedObjects( selected );
1475 if ( selected.IsEmpty() ) return;
1477 GEOM_Displayer displayer( study );
1479 SALOME_View* window = displayer.GetActiveView();
1480 if ( !window ) return;
1482 int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
1484 Material_Model aModel;
1485 aModel.fromResources( theName );
1486 QString prop = aModel.toProperties();
1488 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
1489 Handle(SALOME_InteractiveObject) io = It.Value();
1490 study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
1491 if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
1493 displayer.UpdateViewer();