Salome HOME
bug #155: create profile of splines
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ProfileDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_ProfileDlg.h"
24
25 #include "HYDROGUI_Module.h"
26 #include <CurveCreator_Widget.h>
27 #include <CurveCreator_ICurve.hxx>
28
29 #include <OCCViewer_ViewPort3d.h>
30 #include <OCCViewer_Utilities.h>
31 #include <OCCViewer_ViewManager.h>
32 #include <OCCViewer_ViewFrame.h>
33 #include <LightApp_Application.h>
34
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
37
38 #include <QGroupBox>
39 #include <QHBoxLayout>
40 #include <QLabel>
41 #include <QLineEdit>
42
43 HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QString& theTitle )
44 : HYDROGUI_InputPanel( theModule, theTitle ), myName(NULL)
45 {
46   QHBoxLayout* aNameLayout = new QHBoxLayout();
47   QLabel* aNameLabel = new QLabel(tr("PROFILE_NAME_TLT"), this);
48   aNameLayout->addWidget(aNameLabel);
49   myName = new QLineEdit(this);
50   aNameLayout->addWidget(myName);
51
52   addLayout(aNameLayout);
53
54   myEditorWidget = new CurveCreator_Widget( this, NULL );
55   addWidget( myEditorWidget, 3 );
56
57   myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), this );
58   addWidget( myAddElementBox, 2 );
59
60   QBoxLayout* anAddElementLayout = new QVBoxLayout( myAddElementBox );
61   anAddElementLayout->setMargin( 0 );
62   anAddElementLayout->setSpacing( 5 );
63
64
65   OCCViewer_ViewManager* aViewMgr = new OCCViewer_ViewManager( theModule->getApp()->activeStudy(), 0 );
66   myViewer = new OCCViewer_Viewer( true );
67
68   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
69   myViewer->setBackground( OCCViewer_ViewFrame::TOP_LEFT,
70                      aResMgr->backgroundValue( "OCCViewer", "xz_background", myViewer->background(OCCViewer_ViewFrame::TOP_LEFT) ) );
71   myViewer->setBackground( OCCViewer_ViewFrame::TOP_RIGHT,
72                      aResMgr->backgroundValue( "OCCViewer", "yz_background", myViewer->background(OCCViewer_ViewFrame::TOP_RIGHT) ) );
73   myViewer->setBackground( OCCViewer_ViewFrame::BOTTOM_LEFT,
74                      aResMgr->backgroundValue( "OCCViewer", "xy_background", myViewer->background(OCCViewer_ViewFrame::BOTTOM_LEFT) ) );
75   myViewer->setBackground( OCCViewer_ViewFrame::BOTTOM_RIGHT,
76                      aResMgr->backgroundValue( "OCCViewer", "background", myViewer->background(OCCViewer_ViewFrame::MAIN_VIEW) ) );
77
78   myViewer->setTrihedronSize( aResMgr->doubleValue( "3DViewer", "trihedron_size", myViewer->trihedronSize() ),
79                         aResMgr->booleanValue( "3DViewer", "relative_size", myViewer->trihedronRelative() ));
80   myViewer->setInteractionStyle( aResMgr->integerValue( "3DViewer", "navigation_mode", myViewer->interactionStyle() ) );
81   myViewer->setZoomingStyle( aResMgr->integerValue( "3DViewer", "zooming_mode", myViewer->zoomingStyle() ) );
82   myViewer->enablePreselection( aResMgr->booleanValue( "OCCViewer", "enable_preselection", myViewer->isPreselectionEnabled() ) );
83   myViewer->enableSelection( aResMgr->booleanValue( "OCCViewer", "enable_selection", myViewer->isSelectionEnabled() ) );
84
85   aViewMgr->setViewModel( myViewer );// custom view model, which extends SALOME_View interface
86   SUIT_ViewWindow* aViewWin = aViewMgr->createViewWindow();
87   addWidget( aViewWin, 4 );
88   myEditorWidget->setOCCViewer( myViewer );
89
90   connect( myEditorWidget, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
91   connect( myEditorWidget, SIGNAL( subOperationStarted(QWidget*) ), this, SLOT( processStartedSubOperation(QWidget*) ) );
92   connect( myEditorWidget, SIGNAL( subOperationFinished(QWidget*) ), this, SLOT( processFinishedSubOperation(QWidget*) ) );
93
94   myAddElementBox->hide();
95 }
96
97 HYDROGUI_ProfileDlg::~HYDROGUI_ProfileDlg()
98 {
99 }
100
101 void HYDROGUI_ProfileDlg::reset()
102 {
103   myEditorWidget->reset();
104 }
105
106 Handle(AIS_InteractiveContext) HYDROGUI_ProfileDlg::getAISContext()
107 {
108   return myViewer->getAISContext();
109 }
110
111 void HYDROGUI_ProfileDlg::setProfileName( const QString& theName )
112 {
113   myName->setText(theName);
114 }
115
116 QString HYDROGUI_ProfileDlg::getProfileName() const
117 {
118   return myName->text();
119 }
120
121 void HYDROGUI_ProfileDlg::setProfile( CurveCreator_ICurve* theProfile )
122 {
123   myEditorWidget->setCurve( theProfile );
124 }
125
126 QList<int> HYDROGUI_ProfileDlg::getSelectedSections()
127 {
128   return myEditorWidget->getSelectedSections();
129 }
130
131 QList< QPair< int, int > > HYDROGUI_ProfileDlg::getSelectedPoints()
132 {
133   return myEditorWidget->getSelectedPoints();
134 }
135
136 /**
137  * Redirect the delete action to editor widget
138  */
139 void HYDROGUI_ProfileDlg::deleteSelected()
140 {
141   myEditorWidget->removeSelected();
142 }
143
144 /**
145  * Checks whether there are some to delete
146  */
147 bool HYDROGUI_ProfileDlg::deleteEnabled()
148 {
149   return myEditorWidget->removeEnabled();
150 }
151
152 void HYDROGUI_ProfileDlg::processStartedSubOperation( QWidget* theWidget )
153 {
154   myEditorWidget->setEnabled( false );
155
156   QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
157   anAddElementLayout->addWidget( theWidget );
158
159   theWidget->show();
160   myAddElementBox->show();
161 }
162
163 void HYDROGUI_ProfileDlg::processFinishedSubOperation( QWidget* theWidget )
164 {
165   myEditorWidget->setEnabled( true );
166
167   QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
168   anAddElementLayout->removeWidget( theWidget );
169
170   theWidget->hide();
171   myAddElementBox->hide();
172 }