Salome HOME
Draft version of "Find River Bottom", new viewer dialog base class, new component...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ProfileDlg.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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 "HYDROGUI_Tool.h"
27 #include "HYDROGUI_AISTrihedron.h"
28
29 #include <CurveCreator_Widget.h>
30 #include <CurveCreator_ICurve.hxx>
31 #include <CurveCreator_Utils.hxx>
32
33 #include <OCCViewer_ViewPort3d.h>
34 #include <OCCViewer_Utilities.h>
35 #include <OCCViewer_ViewManager.h>
36 #include <OCCViewer_ViewFrame.h>
37 #include <LightApp_Application.h>
38
39 #include <SUIT_Session.h>
40 #include <SUIT_ResourceMgr.h>
41
42 #include <QGroupBox>
43 #include <QHBoxLayout>
44 #include <QLabel>
45 #include <QLineEdit>
46 #include <QMouseEvent>
47
48 HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QString& theTitle )
49 : HYDROGUI_ViewerDlg( theModule, theTitle ),
50   myName( NULL )
51 {
52   QHBoxLayout* aNameLayout = new QHBoxLayout();
53   QLabel* aNameLabel = new QLabel(tr("PROFILE_NAME_TLT"), this);
54   aNameLayout->addWidget(aNameLabel);
55   myName = new QLineEdit(this);
56   aNameLayout->addWidget(myName);
57
58   addLayout(aNameLayout);
59
60   int anActionFlags = 
61     CurveCreator_Widget::DisableNewSection | CurveCreator_Widget::DisableDetectionMode |
62     CurveCreator_Widget::DisableClosedSection;
63   QStringList aCoordTitles;
64   aCoordTitles << tr( "U_TITLE" ) << tr( "Z_TITLE" );
65   myEditorWidget = new CurveCreator_Widget( this, NULL, anActionFlags, aCoordTitles );
66   addWidget( myEditorWidget, 3 );
67
68   myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), this );
69   addWidget( myAddElementBox, 2 );
70
71   QBoxLayout* anAddElementLayout = new QVBoxLayout( myAddElementBox );
72   anAddElementLayout->setMargin( 0 );
73   anAddElementLayout->setSpacing( 5 );
74
75   myEditorWidget->setOCCViewer( viewer() );
76
77   connect( myEditorWidget, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
78   connect( myEditorWidget, SIGNAL( subOperationStarted(QWidget*, bool) ), this, SLOT( processStartedSubOperation(QWidget*, bool) ) );
79   connect( myEditorWidget, SIGNAL( subOperationFinished(QWidget*) ), this, SLOT( processFinishedSubOperation(QWidget*) ) );
80
81   myAddElementBox->hide();
82 }
83
84 HYDROGUI_ProfileDlg::~HYDROGUI_ProfileDlg()
85 {
86 }
87
88 void HYDROGUI_ProfileDlg::reset()
89 {
90   myEditorWidget->reset();
91   myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
92 }
93
94 void HYDROGUI_ProfileDlg::setProfileName( const QString& theName )
95 {
96   myName->setText(theName);
97 }
98
99 QString HYDROGUI_ProfileDlg::getProfileName() const
100 {
101   return myName->text();
102 }
103
104 void HYDROGUI_ProfileDlg::setProfile( CurveCreator_ICurve* theProfile )
105 {
106   myEditorWidget->setCurve( theProfile );
107
108   // select the single section by default
109   QList<int> aSections;
110   aSections << 0;
111   myEditorWidget->setSelectedSections( aSections );
112 }
113
114 QList<int> HYDROGUI_ProfileDlg::getSelectedSections()
115 {
116   return myEditorWidget->getSelectedSections();
117 }
118
119 /**
120  * Redirect the delete action to editor widget
121  */
122 void HYDROGUI_ProfileDlg::deleteSelected()
123 {
124   myEditorWidget->removeSelected();
125 }
126
127 /**
128  * Checks whether there are some to delete
129  */
130 bool HYDROGUI_ProfileDlg::deleteEnabled()
131 {
132   return myEditorWidget->removeEnabled();
133 }
134
135 void HYDROGUI_ProfileDlg::processStartedSubOperation( QWidget* theWidget, bool theIsEdit )
136 {
137   myEditorWidget->setEnabled( false );
138
139   myAddElementBox->setTitle( theIsEdit ? tr( "EDIT_ELEMENT" ) : tr( "ADD_ELEMENT" ) );
140   QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
141   anAddElementLayout->addWidget( theWidget );
142
143   theWidget->show();
144   myAddElementBox->show();
145 }
146
147 void HYDROGUI_ProfileDlg::processFinishedSubOperation( QWidget* theWidget )
148 {
149   myEditorWidget->setEnabled( true );
150
151   QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
152   anAddElementLayout->removeWidget( theWidget );
153
154   theWidget->hide();
155   myAddElementBox->hide();
156 }