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"
35 #include "GEOMToolsGUI_LineWidthDlg.h"
37 #include <GeometryGUI.h>
38 #include <GeometryGUI_Operations.h>
39 #include <GEOM_Constants.h>
40 #include <GEOM_Displayer.h>
43 #include <GEOM_Actor.h>
45 #include <Basics_OCCTVersion.hxx>
47 #include <SALOME_ListIO.hxx>
48 #include <SALOME_ListIteratorOfListIO.hxx>
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SVTK_View.h>
57 #include <OCCViewer_ViewModel.h>
59 #include <SUIT_ViewManager.h>
60 #include <SUIT_Desktop.h>
61 #include <SUIT_ResourceMgr.h>
62 #include <SUIT_Session.h>
63 #include <SUIT_OverrideCursor.h>
64 #include <SUIT_MessageBox.h>
65 #include <SUIT_Tools.h>
67 #include <SalomeApp_Application.h>
68 #include <SalomeApp_Study.h>
69 #include <SalomeApp_Module.h>
71 #include <LightApp_SelectionMgr.h>
72 #include <LightApp_NameDlg.h>
74 #include <GEOMImpl_Types.hxx>
76 #include "utilities.h"
79 #include <AIS_Drawer.hxx>
80 #include <Prs3d_IsoAspect.hxx>
81 #include <Prs3d_PointAspect.hxx>
82 #include <Graphic3d_AspectMarker3d.hxx>
83 #include <Graphic3d_AspectLine3d.hxx>
85 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
86 #include <TColStd_HArray1OfByte.hxx>
88 #include <Graphic3d_HArray1OfBytes.hxx>
92 #include <QColorDialog>
93 #include <QInputDialog>
94 #include <QFileDialog>
97 #include <QGridLayout>
100 #include <QPushButton>
104 #include <vtkRenderer.h>
107 void GEOMToolsGUI::OnCheckGeometry()
109 SalomeApp_Application* app =
110 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
111 PyConsole_Console* pyConsole = app->pythonConsole();
114 pyConsole->exec("from GEOM_usinggeom import *");
117 void GEOMToolsGUI::OnAutoColor()
119 SALOME_ListIO selected;
120 SalomeApp_Application* app =
121 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
125 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
126 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
127 if (!aSelMgr || !appStudy)
130 aSelMgr->selectedObjects(selected);
131 if (selected.IsEmpty())
134 Handle(SALOME_InteractiveObject) anIObject = selected.First();
136 _PTR(Study) aStudy = appStudy->studyDS();
137 _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
138 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
139 if (CORBA::is_nil(aMainObject))
142 aMainObject->SetAutoColor( true );
144 QList<SALOMEDS::Color> aReservedColors;
146 GEOM_Displayer aDisp (appStudy);
148 SALOME_View* vf = aDisp.GetActiveView();
150 SUIT_ViewWindow* window = app->desktop()->activeWindow();
151 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
152 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
154 for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
156 _PTR(SObject) aChildSObject( it->Value() );
157 GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
158 if( CORBA::is_nil( aChildObject ) )
161 if( aChildObject->GetType() != GEOM_GROUP )
164 SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
165 aChildObject->SetColor( aColor );
166 aReservedColors.append( aColor );
168 QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
170 SALOME_Prs* aPrs = vf->CreatePrs( aChildSObject->GetID().c_str() );
174 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
177 SVTK_View* aView = vtkVW->getView();
178 SUIT_OverrideCursor();
179 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
180 aView->SetColor( It.Value(), c );
184 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
185 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
187 SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
191 AIS_ListOfInteractive aList;
192 anOCCPrs->GetObjects( aList );
193 if( !aList.Extent() )
196 Handle(AIS_InteractiveObject) io = aList.First();
200 Quantity_Color aQuanColor( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
202 // Set color for a point
203 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
204 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
205 Quantity_Color aCurColor;
206 Standard_Real aCurScale;
207 Aspect_TypeOfMarker aCurTypeOfMarker;
208 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
209 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
210 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
213 Standard_Integer aWidth, aHeight;
214 aCurPointAspect->GetTextureSize( aWidth, aHeight );
216 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
217 Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
219 Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
222 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aQuanColor, 1, aWidth, aHeight, aTexture ) );
224 ic->SetLocalAttributes( io, aCurDrawer );
226 io->SetColor( aQuanColor );
227 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) {
228 Handle(GEOM_AISShape) aGAISShape = Handle(GEOM_AISShape)::DownCast( io );
229 aGAISShape->SetShadingColor( aQuanColor );
230 aGAISShape->storeBoundaryColors();
233 io->Redisplay( Standard_True );
237 app->updateActions(); //SRN: To update a Save button in the toolbar
240 void GEOMToolsGUI::OnDisableAutoColor()
242 SALOME_ListIO selected;
243 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
247 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
248 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
249 if( !aSelMgr || !appStudy )
252 aSelMgr->selectedObjects( selected );
253 if( selected.IsEmpty() )
256 Handle(SALOME_InteractiveObject) anIObject = selected.First();
258 _PTR(Study) aStudy = appStudy->studyDS();
259 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
260 GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
261 if( CORBA::is_nil( aMainObject ) )
264 aMainObject->SetAutoColor( false );
268 void GEOMToolsGUI::OnColor()
270 SALOME_ListIO selected;
271 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
272 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
273 if ( app && appStudy ) {
274 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
276 aSelMgr->selectedObjects( selected );
277 if ( !selected.IsEmpty() ) {
278 SUIT_ViewWindow* window = app->desktop()->activeWindow();
279 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
280 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
281 int mgrId = window->getViewManager()->getGlobalId();
283 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
286 SVTK_View* aView = vtkVW->getView();
287 QColor initcolor = aView->GetColor( selected.First() );
288 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
290 SUIT_OverrideCursor();
291 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
292 aView->SetColor( It.Value(), c );
293 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c);
295 GeometryGUI::Modified();
299 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
300 if ( !io.IsNull() ) {
301 Quantity_Color aColor;
303 QColor initcolor ((int)( aColor.Red() * 255.0 ),
304 (int)( aColor.Green() * 255.0 ),
305 (int)( aColor.Blue() * 255.0 ));
306 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
308 SUIT_OverrideCursor();
309 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
310 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
311 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
312 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
313 io = GEOMBase::GetAIS( It.Value(), true );
314 if ( !io.IsNull() ) {
316 if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) {
317 TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape();
318 bool onlyVertex = (theShape.ShapeType() == TopAbs_VERTEX || GEOM_Displayer::isCompoundOfVertices( theShape ));
320 // Set color for a point
322 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
323 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
324 Quantity_Color aCurColor;
325 Standard_Real aCurScale;
326 Aspect_TypeOfMarker aCurTypeOfMarker;
327 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
328 if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
329 aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aCurTypeOfMarker, aColor, aCurScale));
332 Standard_Integer aWidth, aHeight;
333 aCurPointAspect->GetTextureSize( aWidth, aHeight );
335 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
336 Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
338 Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
341 aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aColor, 1, aWidth, aHeight, aTexture));
343 ic->SetLocalAttributes(io, aCurDrawer, Standard_False);
347 io->SetColor( aColor );
348 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) {
349 Handle(GEOM_AISShape) aGAISShape = Handle(GEOM_AISShape)::DownCast( io );
350 aGAISShape->SetShadingColor( aColor );
351 aGAISShape->storeBoundaryColors();
354 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(), COLOR_PROP, c);
356 io->Redisplay( Standard_True );
358 // store color to GEOM_Object
359 _PTR(Study) aStudy = appStudy->studyDS();
360 _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
361 GEOM::GEOM_Object_var anObject =
362 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
365 SALOMEDS::Color aSColor;
366 aSColor.R = (double)c.red() / 255.0;
367 aSColor.G = (double)c.green() / 255.0;
368 aSColor.B = (double)c.blue() / 255.0;
369 anObject->SetColor( aSColor );
370 anObject->SetAutoColor( false );
373 ic->UpdateCurrentViewer();
374 GeometryGUI::Modified();
376 } // first IO is not null
378 } // if ( selection not empty )
382 app->updateActions(); //SRN: To update a Save button in the toolbar
385 void GEOMToolsGUI::OnTexture()
387 SALOME_ListIO selected;
388 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
389 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
390 if ( app && appStudy ) {
391 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
393 aSelMgr->selectedObjects( selected );
394 if ( !selected.IsEmpty() ) {
395 SUIT_ViewWindow* window = app->desktop()->activeWindow();
396 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
398 QString aTexture = QFileDialog::getOpenFileName(window,tr( "GEOM_SELECT_IMAGE"),QString(), tr("OCC_IMAGE_FILES"));
399 if( !aTexture.isEmpty() )
401 SUIT_OverrideCursor();
402 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
403 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
404 Handle(AIS_InteractiveObject) io ;
405 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
406 io = GEOMBase::GetAIS( It.Value(), true );
407 if ( !io.IsNull() ) {
408 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
409 Handle(GEOM_AISShape)::DownCast( io )->SetTextureFileName(TCollection_AsciiString(aTexture.toStdString().c_str()));
410 io->Redisplay( Standard_True );
411 } // if ( !io.IsNull() )
413 ic->UpdateCurrentViewer();
414 GeometryGUI::Modified();
415 GeometryGUI* myGeomGUI = getGeometryGUI();
416 myGeomGUI->OnGUIEvent(GEOMOp::OpTexture);
417 } // if ( !selFile.isEmpty() )
419 } // if ( selection not empty )
423 app->updateActions(); //SRN: To update a Save button in the toolbar
426 void GEOMToolsGUI::OnTransparency()
428 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
432 void GEOMToolsGUI::OnChangeTransparency( bool increase )
434 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
437 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
440 SALOME_ListIO selected;
441 aSelMgr->selectedObjects( selected );
442 if ( selected.IsEmpty() )
445 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
446 if ( FirstIOS.IsNull() )
450 float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
454 SUIT_ViewWindow* window = app->desktop()->activeWindow();
455 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
456 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
459 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
462 SVTK_View* aView = vtkVW->getView();
464 float transp = aView->GetTransparency(FirstIOS);
466 // Compute new transparency value
467 transp = transp + delta;
470 else if ( transp > 1 )
473 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
474 aView->SetTransparency( It.Value(), transp );
477 GeometryGUI::Modified();
481 GEOMBase* gb = new GEOMBase();
482 Handle(GEOM_AISShape) aisShape;
484 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
485 if( aisShape.IsNull() )
487 float transp = aisShape->Transparency();
489 // Compute new transparency value
490 transp = transp + delta;
493 else if ( transp > 1 )
496 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
499 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
500 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
501 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
502 if ( !aisShape.IsNull() ) {
503 ic->SetTransparency( aisShape, transp, false );
504 ic->Redisplay( aisShape, Standard_False, Standard_True );
507 ic->UpdateCurrentViewer();
508 GeometryGUI::Modified();
512 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
514 SalomeApp_Application* app =
515 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
516 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
517 SUIT_ViewWindow* window = app->desktop()->activeWindow();
519 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
520 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
522 if(isOCC){ // if is OCCViewer
524 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
525 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
528 if ( ic->MoreCurrent() ) {
529 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
530 CurObject->restoreIsoNumbers();
531 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
533 int UIso = CurDrawer->UIsoAspect()->Number();
534 int VIso = CurDrawer->VIsoAspect()->Number();
539 if ( actionType == SHOWDLG ) {
540 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
541 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
543 NbIsosDlg->setU( UIso );
544 NbIsosDlg->setV( VIso );
546 if ( NbIsosDlg->exec() ) {
547 SUIT_OverrideCursor();
549 newNbUIso = NbIsosDlg->getU();
550 newNbVIso = NbIsosDlg->getV();
554 else if ( actionType == INCR || actionType == DECR ) {
556 if (actionType == DECR)
559 newNbUIso = UIso + delta;
560 newNbVIso = VIso + delta;
562 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
566 for(; ic->MoreCurrent(); ic->NextCurrent()) {
567 int aMgrId = window->getViewManager()->getGlobalId();
568 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
570 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
572 QVariant v = aStudy->getObjectProperty( aMgrId, CurObject->getIO()->getEntry(), EDGE_WIDTH_PROP , QVariant() );
574 int width = v.isValid() ? v.toInt() : 1;
576 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, width , newNbUIso) );
577 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, width , newNbVIso) );
579 CurObject->storeIsoNumbers();
581 ic->SetLocalAttributes(CurObject, CurDrawer);
582 ic->Redisplay(CurObject);
584 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
585 aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_WIDTH_PROP, anIsos);
588 GeometryGUI::Modified();
590 else if(isVTK){ // if is VTKViewer
592 // Warning. It's works incorrect. must be recheked.
594 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
595 ( SUIT_Session::session()->activeApplication() );
598 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
601 SALOME_ListIO selected;
602 aSelMgr->selectedObjects( selected );
603 if ( selected.IsEmpty() )
606 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
610 SALOME_View* view = GEOM_Displayer::GetActiveView();
612 vtkActorCollection* aCollection = vtkActorCollection::New();
614 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
615 Handle(SALOME_InteractiveObject) anIObject = It.Value();
616 SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
617 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
619 vtkActorCollection* anActors = vtkPrs->GetObjects();
620 anActors->InitTraversal();
621 vtkActor* anAct = anActors->GetNextActor();
622 aCollection->AddItem(anAct);
627 aCollection->InitTraversal();
634 vtkActor* anAct = aCollection->GetNextActor();
635 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
636 anActor->RestoreIsoNumbers();
637 anActor->GetNbIsos(UIso,VIso);
645 if ( actionType == SHOWDLG ) {
646 GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
647 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
649 NbIsosDlg->setU( UIso );
650 NbIsosDlg->setV( VIso );
652 if ( NbIsosDlg->exec() ) {
653 SUIT_OverrideCursor();
655 newNbUIso = NbIsosDlg->getU();
656 newNbVIso = NbIsosDlg->getV();
658 return; //Cancel case
660 else if ( actionType == INCR || actionType == DECR ) {
662 if (actionType == DECR)
665 newNbUIso = UIso + delta;
666 newNbVIso = VIso + delta;
668 if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
672 while( anAct!=NULL ) {
673 if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
674 // There are no casting to needed actor.
675 int aIsos[2]={newNbUIso,newNbVIso};
676 anActor->SetNbIsos(aIsos);
677 anActor->StoreIsoNumbers();
679 QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
680 int aMgrId = window->getViewManager()->getGlobalId();
681 aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos);
683 anAct = aCollection->GetNextActor();
686 GeometryGUI::Modified();
690 void GEOMToolsGUI::OnDeflection()
692 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
693 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
696 bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
697 bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
698 int mgrId = window->getViewManager()->getGlobalId();
700 if (isOCC) { // if is OCCViewer
701 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
702 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
705 if (ic->MoreCurrent()) {
706 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
708 Standard_Real aDC, aPrevDC;
709 Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
711 aDC = ic->DeviationCoefficient();
713 GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
714 (SUIT_Session::session()->activeApplication()->desktop());
715 DeflectionDlg->setTheDC(aDC);
719 if (DeflectionDlg->exec()) {
720 SUIT_OverrideCursor();
721 aNewDC = DeflectionDlg->getTheDC();
722 ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
724 for (; ic->MoreCurrent(); ic->NextCurrent()) {
725 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
726 ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
727 ic->Redisplay(CurObject);
728 appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC);
737 GeometryGUI::Modified();
739 else if (isVTK) { // if is VTKViewer
740 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
741 (SUIT_Session::session()->activeApplication());
745 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
749 SALOME_ListIO selected;
750 aSelMgr->selectedObjects(selected);
751 if (selected.IsEmpty())
754 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
758 SALOME_View* view = GEOM_Displayer::GetActiveView();
760 vtkActorCollection* aCollection = vtkActorCollection::New();
762 for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
763 Handle(SALOME_InteractiveObject) anIObject = It.Value();
764 SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
765 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
767 vtkActorCollection* anActors = vtkPrs->GetObjects();
768 anActors->InitTraversal();
769 vtkActor* anAct = anActors->GetNextActor();
770 aCollection->AddItem(anAct);
775 aCollection->InitTraversal();
781 vtkActor* anAct = aCollection->GetNextActor();
782 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
783 aDC = anActor->GetDeflection();
787 GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
788 (SUIT_Session::session()->activeApplication()->desktop());
789 DeflectionDlg->setTheDC(aDC);
790 if (DeflectionDlg->exec()) {
791 SUIT_OverrideCursor();
792 aDC = DeflectionDlg->getTheDC();
793 while (anAct != NULL) {
794 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
795 // There are no casting to needed actor.
796 anActor->SetDeflection(aDC);
797 appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC);
799 anAct = aCollection->GetNextActor();
802 GeometryGUI::Modified();
806 void GEOMToolsGUI::OnSelectOnly(int mode)
808 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
810 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
811 GEOM_Displayer aDisp (appStudy);
812 aDisp.GlobalSelection(mode);
813 getGeometryGUI()->setLocalSelectionMode(mode);
817 void GEOMToolsGUI::OnShowHideChildren( bool show )
819 SALOME_ListIO selected;
820 SalomeApp_Application* app =
821 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
823 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
825 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
828 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
829 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
830 if ( aSelMgr && appStudy ) {
831 aSelMgr->selectedObjects( selected );
832 if ( !selected.IsEmpty() ) {
833 _PTR(Study) aStudy = appStudy->studyDS();
834 _PTR(StudyBuilder) B = aStudy->NewBuilder();
836 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
838 SUIT_MessageBox::warning( app->desktop(),
839 QObject::tr( "WRN_WARNING" ),
840 QObject::tr( "WRN_STUDY_LOCKED" ) );
844 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
845 Handle(SALOME_InteractiveObject) IObject = It.Value();
847 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
848 _PTR(GenericAttribute) anAttr;
850 _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
851 aExp->SetExpandable( show );
853 disp->EraseWithChildren(IObject,true);
858 app->updateObjectBrowser( false );
859 app->updateActions();
863 void GEOMToolsGUI::OnPointMarker()
865 GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
869 void GEOMToolsGUI::OnMaterialProperties()
871 GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
875 void GEOMToolsGUI::OnUnpublishObject() {
876 SALOME_ListIO selected;
877 SalomeApp_Application* app =
878 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
880 SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
882 GEOM_Displayer* disp = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
885 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
886 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
887 if ( aSelMgr && appStudy ) {
888 aSelMgr->selectedObjects( selected );
889 if ( !selected.IsEmpty() ) {
890 _PTR(Study) aStudy = appStudy->studyDS();
891 _PTR(StudyBuilder) B = aStudy->NewBuilder();
893 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
895 SUIT_MessageBox::warning( app->desktop(),
896 QObject::tr( "WRN_WARNING" ),
897 QObject::tr( "WRN_STUDY_LOCKED" ) );
901 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
902 Handle(SALOME_InteractiveObject) IObject = It.Value();
904 _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
905 _PTR(GenericAttribute) anAttr;
907 _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
908 aDrw->SetDrawable( false );
909 disp->EraseWithChildren(IObject);
912 aSelMgr->clearSelected();
915 app->updateObjectBrowser( false );
916 app->updateActions();
921 void GEOMToolsGUI::OnPublishObject() {
922 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
926 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
930 _PTR(Study) aStudy = appStudy->studyDS();
935 //Check lock of the study
936 bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
938 SUIT_MessageBox::warning( app->desktop(),
939 QObject::tr( "WRN_WARNING" ),
940 QObject::tr( "WRN_STUDY_LOCKED" ) );
944 GEOMToolsGUI_PublishDlg * publishDlg =
945 new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
950 void GEOMToolsGUI::OnEdgeWidth()
952 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
953 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
956 bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
957 bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
958 int mgrId = window->getViewManager()->getGlobalId();
960 if (isOCC) { // if is OCCViewer
961 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
962 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
964 if (ic->MoreCurrent()) {
965 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
967 int aWidth = (int)CurObject->Width();
969 GEOMToolsGUI_LineWidthDlg * Dlg = new GEOMToolsGUI_LineWidthDlg
970 (SUIT_Session::session()->activeApplication()->desktop(),"EDGE_WIDTH_TLT");
971 Dlg->setTheLW(aWidth);
974 aNewWidth = Dlg->getTheLW();
975 bool ok = (aNewWidth != aWidth && aNewWidth != 0 );
977 for(; ic->MoreCurrent(); ic->NextCurrent()) {
978 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
979 CurObject->SetWidth(aNewWidth);
980 ic->Redisplay(CurObject);
981 appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), EDGE_WIDTH_PROP, aNewWidth);
989 GeometryGUI::Modified();
991 else if (isVTK) { // if is VTKViewer
992 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
993 (SUIT_Session::session()->activeApplication());
997 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1001 SALOME_ListIO selected;
1002 aSelMgr->selectedObjects(selected);
1003 if (selected.IsEmpty())
1006 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
1010 SALOME_View* view = GEOM_Displayer::GetActiveView();
1012 vtkActorCollection* aCollection = vtkActorCollection::New();
1014 for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
1015 Handle(SALOME_InteractiveObject) anIObject = It.Value();
1016 SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
1017 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
1019 vtkActorCollection* anActors = vtkPrs->GetObjects();
1020 anActors->InitTraversal();
1021 vtkActor* anAct = anActors->GetNextActor();
1022 aCollection->AddItem(anAct);
1027 aCollection->InitTraversal();
1033 vtkActor* anAct = aCollection->GetNextActor();
1034 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
1035 aWidth = anActor->GetWidth();
1039 GEOMToolsGUI_LineWidthDlg * Dlg = new GEOMToolsGUI_LineWidthDlg
1040 (SUIT_Session::session()->activeApplication()->desktop(),"EDGE_WIDTH_TLT");
1042 Dlg->setTheLW(aWidth);
1044 SUIT_OverrideCursor();
1045 aWidth = Dlg->getTheLW();
1046 while (anAct != NULL) {
1047 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
1048 // There are no casting to needed actor.
1049 anActor->SetWidth(aWidth);
1050 appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), EDGE_WIDTH_PROP, aWidth);
1052 anAct = aCollection->GetNextActor();
1055 GeometryGUI::Modified();
1060 void GEOMToolsGUI::OnIsosWidth() {
1061 SalomeApp_Application* app =
1062 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1063 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1064 SUIT_ViewWindow* window = app->desktop()->activeWindow();
1066 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1067 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
1069 if(isOCC){ // if is OCCViewer
1071 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
1072 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
1075 if ( ic->MoreCurrent() ) {
1076 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
1077 CurObject->restoreIsoNumbers();
1078 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
1080 Handle(Graphic3d_AspectLine3d) asp = CurDrawer->UIsoAspect()->Aspect();
1083 Aspect_TypeOfLine T;
1087 int aWidth = (int)W;
1089 GEOMToolsGUI_LineWidthDlg * Dlg =
1090 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(),"ISOS_WIDTH_TLT" );
1092 Dlg->setTheLW( aWidth );
1094 if ( Dlg->exec() ) {
1095 SUIT_OverrideCursor();
1096 aWidth = Dlg->getTheLW();
1097 } else //Cancel case
1100 for(; ic->MoreCurrent(); ic->NextCurrent()) {
1101 int aMgrId = window->getViewManager()->getGlobalId();
1102 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
1104 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
1106 CurObject->Attributes()->UIsoAspect()->SetWidth(aWidth);
1107 CurObject->Attributes()->VIsoAspect()->SetWidth(aWidth);
1109 ic->Redisplay(CurObject);
1111 aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_WIDTH_PROP, aWidth);
1113 GeometryGUI::Modified();
1116 else if(isVTK){ // if is VTKViewer
1118 // Warning. It's works incorrect. must be recheked.
1120 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
1121 ( SUIT_Session::session()->activeApplication() );
1124 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1127 SALOME_ListIO selected;
1128 aSelMgr->selectedObjects( selected );
1129 if ( selected.IsEmpty() )
1132 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
1136 SALOME_View* view = GEOM_Displayer::GetActiveView();
1138 vtkActorCollection* aCollection = vtkActorCollection::New();
1140 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
1141 Handle(SALOME_InteractiveObject) anIObject = It.Value();
1142 SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
1143 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
1145 vtkActorCollection* anActors = vtkPrs->GetObjects();
1146 anActors->InitTraversal();
1147 vtkActor* anAct = anActors->GetNextActor();
1148 aCollection->AddItem(anAct);
1153 aCollection->InitTraversal();
1159 vtkActor* anAct = aCollection->GetNextActor();
1160 if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
1161 aWidth = anActor->GetIsosWidth();
1166 GEOMToolsGUI_LineWidthDlg* Dlg =
1167 new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
1169 Dlg->setTheLW( aWidth );
1171 SUIT_OverrideCursor();
1172 aWidth = Dlg->getTheLW();
1174 return; //Cancel case
1176 while( anAct!= NULL ) {
1177 if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
1178 // There are no casting to needed actor.
1179 anActor->SetIsosWidth(aWidth);
1180 int aMgrId = window->getViewManager()->getGlobalId();
1181 aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_WIDTH_PROP, aWidth);
1183 anAct = aCollection->GetNextActor();
1187 GeometryGUI::Modified();