Salome HOME
Merge remote-tracking branch 'origin/BR_1332' into BR_1331
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ProfileDlg.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_ProfileDlg.h"
20
21 #include "HYDROGUI_Module.h"
22 #include "HYDROGUI_Tool.h"
23 #include "HYDROGUI_AISTrihedron.h"
24
25 #include <CurveCreator_Widget.h>
26 #include <CurveCreator_ICurve.hxx>
27 #include <CurveCreator_Utils.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 #include <QMouseEvent>
43 #include <QSplitter>
44 #include <QSettings>
45
46 const QString splitter_key = "HYDROGUI_ProfileDlg::splitter";
47
48 HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QString& theTitle )
49 : HYDROGUI_ViewerDlg( theModule, theTitle, true ),
50   myName( NULL )
51 {
52   QFrame* name_frame = new QFrame( mainFrame() );
53   QHBoxLayout* name_layout = new QHBoxLayout( name_frame );
54   name_layout->setMargin( 0 );
55   QLabel* aNameLabel = new QLabel(tr("PROFILE_NAME_TLT"), this);
56   name_layout->addWidget(aNameLabel);
57   myName = new QLineEdit(this);
58   name_layout->addWidget(myName);
59
60   insertWidget( name_frame, 0, 0 );
61
62   int anActionFlags = 
63     CurveCreator_Widget::DisableNewSection | CurveCreator_Widget::DisableDetectionMode |
64     CurveCreator_Widget::DisableClosedSection;
65   QStringList aCoordTitles;
66   aCoordTitles << tr( "U_TITLE" ) << tr( "Z_TITLE" );
67   myEditorWidget = new CurveCreator_Widget( this, NULL, anActionFlags, aCoordTitles );
68   insertWidget( myEditorWidget, 1, 1 );
69
70   myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), this );
71   insertWidget( myAddElementBox, 2, 1 );
72
73   QBoxLayout* anAddElementLayout = new QVBoxLayout( myAddElementBox );
74   anAddElementLayout->setMargin( 0 );
75   anAddElementLayout->setSpacing( 5 );
76
77   myEditorWidget->setOCCViewer( viewer() );
78
79   connect( myEditorWidget, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
80   connect( myEditorWidget, SIGNAL( subOperationStarted(QWidget*, bool) ), this, SLOT( processStartedSubOperation(QWidget*, bool) ) );
81   connect( myEditorWidget, SIGNAL( subOperationFinished(QWidget*) ), this, SLOT( processFinishedSubOperation(QWidget*) ) );
82
83   myAddElementBox->hide();
84
85   QList<int> sizes;
86   sizes.append( 25 );
87   sizes.append( 100 );
88   sizes.append( 100 );
89   sizes.append( 200 );
90   sizes.append( 25 );
91   splitter()->setSizes( sizes );
92
93 #ifndef TEST_MODE
94   QSettings settings;
95   splitter()->restoreState( settings.value( splitter_key ).toByteArray() );
96 #endif
97 }
98
99 HYDROGUI_ProfileDlg::~HYDROGUI_ProfileDlg()
100 {
101 #ifndef TEST_MODE
102   QSettings settings;
103   settings.setValue( splitter_key, splitter()->saveState() );
104 #endif
105 }
106
107 void HYDROGUI_ProfileDlg::reset()
108 {
109   myEditorWidget->reset();
110   myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
111   viewer()->setTrihedronShown( false ); // Issue #548
112 }
113
114 void HYDROGUI_ProfileDlg::setProfileName( const QString& theName )
115 {
116   myName->setText(theName);
117 }
118
119 QString HYDROGUI_ProfileDlg::getProfileName() const
120 {
121   return myName->text();
122 }
123
124 void HYDROGUI_ProfileDlg::setProfile( CurveCreator_ICurve* theProfile )
125 {
126   myEditorWidget->setCurve( theProfile );
127
128   // select the single section by default
129   QList<int> aSections;
130   aSections << 0;
131   myEditorWidget->setSelectedSections( aSections );
132 }
133
134 QList<int> HYDROGUI_ProfileDlg::getSelectedSections()
135 {
136   return myEditorWidget->getSelectedSections();
137 }
138
139 /**
140  * Redirect the delete action to editor widget
141  */
142 void HYDROGUI_ProfileDlg::deleteSelected()
143 {
144   myEditorWidget->removeSelected();
145 }
146
147 /**
148  * Checks whether there are some to delete
149  */
150 bool HYDROGUI_ProfileDlg::deleteEnabled()
151 {
152   return myEditorWidget->removeEnabled();
153 }
154
155 void HYDROGUI_ProfileDlg::processStartedSubOperation( QWidget* theWidget, bool theIsEdit )
156 {
157   myEditorWidget->setEnabled( false );
158
159   myAddElementBox->setTitle( theIsEdit ? tr( "EDIT_ELEMENT" ) : tr( "ADD_ELEMENT" ) );
160   QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
161   anAddElementLayout->addWidget( theWidget );
162
163   theWidget->show();
164   myAddElementBox->show();
165 }
166
167 void HYDROGUI_ProfileDlg::processFinishedSubOperation( QWidget* theWidget )
168 {
169   myEditorWidget->setEnabled( true );
170
171   QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
172   anAddElementLayout->removeWidget( theWidget );
173
174   theWidget->hide();
175   myAddElementBox->hide();
176 }
177
178 Handle(AIS_Trihedron) HYDROGUI_ProfileDlg::trihedron()
179 {
180     SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
181     Handle(AIS_Trihedron) aTrihedron =
182         HYDROGUI_AISTrihedron::createTrihedron( aResMgr->doubleValue( "3DViewer", "trihedron_size", viewer()->trihedronSize() ) );
183     return aTrihedron;
184 }