1 // Copyright (C) 2007-2013 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 #include "HYDROGUI_ProfileDlg.h"
25 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_Tool.h"
28 #include <CurveCreator_Widget.h>
29 #include <CurveCreator_ICurve.hxx>
30 #include <CurveCreator_Utils.h>
32 #include <OCCViewer_ViewPort3d.h>
33 #include <OCCViewer_Utilities.h>
34 #include <OCCViewer_ViewManager.h>
35 #include <OCCViewer_ViewFrame.h>
36 #include <LightApp_Application.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_ResourceMgr.h>
42 #include <QHBoxLayout>
45 #include <QMouseEvent>
47 HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QString& theTitle )
48 : HYDROGUI_InputPanel( theModule, theTitle ), myName(NULL)
50 QHBoxLayout* aNameLayout = new QHBoxLayout();
51 QLabel* aNameLabel = new QLabel(tr("PROFILE_NAME_TLT"), this);
52 aNameLayout->addWidget(aNameLabel);
53 myName = new QLineEdit(this);
54 aNameLayout->addWidget(myName);
56 addLayout(aNameLayout);
59 CurveCreator_Widget::DisableNewSection | CurveCreator_Widget::DisableDetectionMode |
60 CurveCreator_Widget::DisableClosedSection;
61 myEditorWidget = new CurveCreator_Widget( this, NULL, anActionFlags );
62 addWidget( myEditorWidget, 3 );
64 myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), this );
65 addWidget( myAddElementBox, 2 );
67 QBoxLayout* anAddElementLayout = new QVBoxLayout( myAddElementBox );
68 anAddElementLayout->setMargin( 0 );
69 anAddElementLayout->setSpacing( 5 );
71 myViewManager = new OCCViewer_ViewManager( theModule->getApp()->activeStudy(), 0 );
72 OCCViewer_Viewer* aViewer = new OCCViewer_Viewer( false /*erase trihedron*/);
74 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
75 aViewer->setBackground( OCCViewer_ViewFrame::TOP_LEFT,
76 aResMgr->backgroundValue( "OCCViewer", "xz_background", aViewer->background(OCCViewer_ViewFrame::TOP_LEFT) ) );
77 aViewer->setBackground( OCCViewer_ViewFrame::TOP_RIGHT,
78 aResMgr->backgroundValue( "OCCViewer", "yz_background", aViewer->background(OCCViewer_ViewFrame::TOP_RIGHT) ) );
79 aViewer->setBackground( OCCViewer_ViewFrame::BOTTOM_LEFT,
80 aResMgr->backgroundValue( "OCCViewer", "xy_background", aViewer->background(OCCViewer_ViewFrame::BOTTOM_LEFT) ) );
81 aViewer->setBackground( OCCViewer_ViewFrame::BOTTOM_RIGHT,
82 aResMgr->backgroundValue( "OCCViewer", "background", aViewer->background(OCCViewer_ViewFrame::MAIN_VIEW) ) );
84 aViewer->setTrihedronSize( aResMgr->doubleValue( "3DViewer", "trihedron_size", aViewer->trihedronSize() ),
85 aResMgr->booleanValue( "3DViewer", "relative_size", aViewer->trihedronRelative() ));
86 aViewer->setInteractionStyle( aResMgr->integerValue( "3DViewer", "navigation_mode", aViewer->interactionStyle() ) );
87 aViewer->setZoomingStyle( aResMgr->integerValue( "3DViewer", "zooming_mode", aViewer->zoomingStyle() ) );
88 aViewer->enablePreselection( aResMgr->booleanValue( "OCCViewer", "enable_preselection", aViewer->isPreselectionEnabled() ) );
89 aViewer->enableSelection( aResMgr->booleanValue( "OCCViewer", "enable_selection", aViewer->isSelectionEnabled() ) );
91 myViewManager->setViewModel( aViewer );// custom view model, which extends SALOME_View interface
92 SUIT_ViewWindow* aViewWin = myViewManager->createViewWindow();
93 aViewer->setStaticTrihedronDisplayed( false );
94 addWidget( aViewWin, 4 );
95 myEditorWidget->setOCCViewer( aViewer );
97 connect( myEditorWidget, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
98 connect( myEditorWidget, SIGNAL( subOperationStarted(QWidget*, bool) ), this, SLOT( processStartedSubOperation(QWidget*, bool) ) );
99 connect( myEditorWidget, SIGNAL( subOperationFinished(QWidget*) ), this, SLOT( processFinishedSubOperation(QWidget*) ) );
101 myAddElementBox->hide();
104 connect( myViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
105 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
107 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWin );
108 if ( aViewFrame && aViewFrame->getViewPort() ) {
109 aViewFrame->getViewPort()->installEventFilter( this );
113 myCoordLabel = new QLabel( this );
114 QHBoxLayout* aCoordLayout = new QHBoxLayout();
115 aCoordLayout->addWidget( myCoordLabel );
116 aCoordLayout->addStretch();
118 addLayout( aCoordLayout );
121 HYDROGUI_ProfileDlg::~HYDROGUI_ProfileDlg()
123 delete myViewManager;
126 void HYDROGUI_ProfileDlg::reset()
128 myEditorWidget->reset();
129 myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
132 Handle(AIS_InteractiveContext) HYDROGUI_ProfileDlg::getAISContext()
134 OCCViewer_Viewer* aViewer = (OCCViewer_Viewer*)myViewManager->getViewModel();
135 return aViewer ? aViewer->getAISContext() : 0;
138 void HYDROGUI_ProfileDlg::setProfileName( const QString& theName )
140 myName->setText(theName);
143 QString HYDROGUI_ProfileDlg::getProfileName() const
145 return myName->text();
148 void HYDROGUI_ProfileDlg::setProfile( CurveCreator_ICurve* theProfile )
150 myEditorWidget->setCurve( theProfile );
152 // select the single section by default
153 QList<int> aSections;
155 myEditorWidget->setSelectedSections( aSections );
158 QList<int> HYDROGUI_ProfileDlg::getSelectedSections()
160 return myEditorWidget->getSelectedSections();
164 * Redirect the delete action to editor widget
166 void HYDROGUI_ProfileDlg::deleteSelected()
168 myEditorWidget->removeSelected();
172 * Checks whether there are some to delete
174 bool HYDROGUI_ProfileDlg::deleteEnabled()
176 return myEditorWidget->removeEnabled();
179 void HYDROGUI_ProfileDlg::processStartedSubOperation( QWidget* theWidget, bool theIsEdit )
181 myEditorWidget->setEnabled( false );
183 myAddElementBox->setTitle( theIsEdit ? tr( "EDIT_ELEMENT" ) : tr( "ADD_ELEMENT" ) );
184 QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
185 anAddElementLayout->addWidget( theWidget );
188 myAddElementBox->show();
191 void HYDROGUI_ProfileDlg::processFinishedSubOperation( QWidget* theWidget )
193 myEditorWidget->setEnabled( true );
195 QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
196 anAddElementLayout->removeWidget( theWidget );
199 myAddElementBox->hide();
202 void HYDROGUI_ProfileDlg::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
204 OCCViewer_ViewWindow* anOCCViewWindow =
205 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
206 if ( anOCCViewWindow && anOCCViewWindow->getViewPort() ) {
207 gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint(
208 theEvent->x(), theEvent->y(), anOCCViewWindow->getViewPort()->getView() );
210 // Show the coordinates
211 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
212 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
213 myCoordLabel->setText( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );
217 bool HYDROGUI_ProfileDlg::eventFilter( QObject* theObj, QEvent* theEvent )
219 if ( theObj->inherits( "OCCViewer_ViewPort" ) )
221 if ( theEvent->type() == QEvent::Leave )
222 myCoordLabel->clear();
227 return HYDROGUI_InputPanel::eventFilter( theObj, theEvent );