1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 #include "HYDROGUI_ViewerDlg.h"
25 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_Tool.h"
27 #include "HYDROGUI_AISTrihedron.h"
29 #include <CurveCreator_Widget.h>
30 #include <CurveCreator_ICurve.hxx>
31 #include <CurveCreator_Utils.hxx>
33 #include <OCCViewer_ViewPort3d.h>
34 #include <OCCViewer_Utilities.h>
35 #include <OCCViewer_ViewManager.h>
36 #include <OCCViewer_ViewFrame.h>
38 #include <LightApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_ResourceMgr.h>
45 #include <QHBoxLayout>
48 #include <QMouseEvent>
50 HYDROGUI_ViewerDlg::HYDROGUI_ViewerDlg( HYDROGUI_Module* theModule, const QString& theTitle )
51 : HYDROGUI_InputPanel( theModule, theTitle )
53 QWidget* viewMain = new QWidget( mainFrame() );
54 QVBoxLayout* viewBase = new QVBoxLayout( viewMain );
55 viewBase->setMargin( 0 );
57 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
58 myViewManager = new OCCViewer_ViewManager( theModule->getApp()->activeStudy(), 0 );
59 OCCViewer_Viewer* aViewer = new OCCViewer_Viewer( true );
61 aViewer->setBackground( OCCViewer_ViewFrame::TOP_LEFT,
62 aResMgr->backgroundValue( "OCCViewer", "xz_background", aViewer->background(OCCViewer_ViewFrame::TOP_LEFT) ) );
63 aViewer->setBackground( OCCViewer_ViewFrame::TOP_RIGHT,
64 aResMgr->backgroundValue( "OCCViewer", "yz_background", aViewer->background(OCCViewer_ViewFrame::TOP_RIGHT) ) );
65 aViewer->setBackground( OCCViewer_ViewFrame::BOTTOM_LEFT,
66 aResMgr->backgroundValue( "OCCViewer", "xy_background", aViewer->background(OCCViewer_ViewFrame::BOTTOM_LEFT) ) );
67 aViewer->setBackground( OCCViewer_ViewFrame::BOTTOM_RIGHT,
68 aResMgr->backgroundValue( "OCCViewer", "background", aViewer->background(OCCViewer_ViewFrame::MAIN_VIEW) ) );
70 aViewer->setTrihedronSize( aResMgr->doubleValue( "3DViewer", "trihedron_size", aViewer->trihedronSize() ),
71 aResMgr->booleanValue( "3DViewer", "relative_size", aViewer->trihedronRelative() ));
72 aViewer->setInteractionStyle( aResMgr->integerValue( "3DViewer", "navigation_mode", aViewer->interactionStyle() ) );
73 aViewer->setZoomingStyle( aResMgr->integerValue( "3DViewer", "zooming_mode", aViewer->zoomingStyle() ) );
74 aViewer->enablePreselection( aResMgr->booleanValue( "OCCViewer", "enable_preselection", aViewer->isPreselectionEnabled() ) );
75 aViewer->enableSelection( aResMgr->booleanValue( "OCCViewer", "enable_selection", aViewer->isSelectionEnabled() ) );
77 myViewManager->setViewModel( aViewer );// custom view model, which extends SALOME_View interface
79 aViewer->enableMultiselection( false );
81 SUIT_ViewWindow* aViewWin = myViewManager->createViewWindow();
82 aViewer->setStaticTrihedronDisplayed( false );
84 Handle(AIS_Trihedron) aTrihedron =
85 HYDROGUI_AISTrihedron::createTrihedron( aResMgr->doubleValue( "3DViewer", "trihedron_size", aViewer->trihedronSize() ) );
86 Handle(AIS_InteractiveContext) anAISContext = aViewer->getAISContext();
87 if ( !anAISContext.IsNull() )
89 anAISContext->Display( aTrihedron );
90 anAISContext->Deactivate( aTrihedron );
93 viewBase->addWidget( aViewWin );
96 connect( myViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
97 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
101 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWin );
102 if ( aViewFrame && aViewFrame->getViewPort() )
103 aViewFrame->getViewPort()->installEventFilter( this );
106 myCoordLabel = new QLabel( viewMain );
107 viewBase->addWidget( myCoordLabel );
110 HYDROGUI_ViewerDlg::~HYDROGUI_ViewerDlg()
112 myViewManager->closeAllViews();
113 delete myViewManager;
116 bool HYDROGUI_ViewerDlg::event( QEvent* e )
118 if ( e->type() == QEvent::Polish )
120 addWidget( myCoordLabel->parentWidget(), 4 );
122 Handle(AIS_Trihedron) aTrihedron = trihedron();
123 Handle(AIS_InteractiveContext) anAISContext = getAISContext();
124 if ( !anAISContext.IsNull() && !aTrihedron.IsNull() )
126 viewer()->setTrihedronShown( false );
127 anAISContext->Display( aTrihedron );
128 anAISContext->Deactivate( aTrihedron );
132 return HYDROGUI_InputPanel::event( e );
135 Handle(AIS_InteractiveContext) HYDROGUI_ViewerDlg::getAISContext()
137 OCCViewer_Viewer* aViewer = (OCCViewer_Viewer*)myViewManager->getViewModel();
138 return aViewer ? aViewer->getAISContext() : 0;
141 OCCViewer_Viewer* HYDROGUI_ViewerDlg::viewer() const
143 return ::qobject_cast<OCCViewer_Viewer*>( myViewManager->getViewModel() );
146 OCCViewer_ViewManager* HYDROGUI_ViewerDlg::viewManager() const
148 return myViewManager;
151 SUIT_SelectionMgr* HYDROGUI_ViewerDlg::selectionMgr() const
153 SUIT_SelectionMgr* aSelMgr = 0;
156 LightApp_Application* app = module()->getApp();
158 aSelMgr = app->selectionMgr();
163 void HYDROGUI_ViewerDlg::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
165 OCCViewer_ViewWindow* anOCCViewWindow =
166 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
167 if ( anOCCViewWindow && anOCCViewWindow->getViewPort() )
169 gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(), anOCCViewWindow->getViewPort()->getView() );
171 // Show the coordinates
172 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X(), true );
173 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y(), true );
174 myCoordLabel->setText( tr("UZ_COORDINATES_INFO").arg( aX ).arg( anY ) );
178 bool HYDROGUI_ViewerDlg::eventFilter( QObject* theObj, QEvent* theEvent )
180 if ( theObj->inherits( "OCCViewer_ViewPort" ) )
182 if ( theEvent->type() == QEvent::Leave )
183 myCoordLabel->clear();
188 return HYDROGUI_InputPanel::eventFilter( theObj, theEvent );
191 Handle(AIS_Trihedron) HYDROGUI_ViewerDlg::trihedron()
193 return Handle(AIS_Trihedron)();