Salome HOME
Merge branch 'BR_v14_rc' into BR_quadtree
[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
44 HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QString& theTitle )
45 : HYDROGUI_ViewerDlg( theModule, theTitle ),
46   myName( NULL )
47 {
48   QHBoxLayout* aNameLayout = new QHBoxLayout();
49   QLabel* aNameLabel = new QLabel(tr("PROFILE_NAME_TLT"), this);
50   aNameLayout->addWidget(aNameLabel);
51   myName = new QLineEdit(this);
52   aNameLayout->addWidget(myName);
53
54   addLayout(aNameLayout);
55
56   int anActionFlags = 
57     CurveCreator_Widget::DisableNewSection | CurveCreator_Widget::DisableDetectionMode |
58     CurveCreator_Widget::DisableClosedSection;
59   QStringList aCoordTitles;
60   aCoordTitles << tr( "U_TITLE" ) << tr( "Z_TITLE" );
61   myEditorWidget = new CurveCreator_Widget( this, NULL, anActionFlags, aCoordTitles );
62   addWidget( myEditorWidget, 3 );
63
64   myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), this );
65   addWidget( myAddElementBox, 2 );
66
67   QBoxLayout* anAddElementLayout = new QVBoxLayout( myAddElementBox );
68   anAddElementLayout->setMargin( 0 );
69   anAddElementLayout->setSpacing( 5 );
70
71   myEditorWidget->setOCCViewer( viewer() );
72
73   connect( myEditorWidget, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
74   connect( myEditorWidget, SIGNAL( subOperationStarted(QWidget*, bool) ), this, SLOT( processStartedSubOperation(QWidget*, bool) ) );
75   connect( myEditorWidget, SIGNAL( subOperationFinished(QWidget*) ), this, SLOT( processFinishedSubOperation(QWidget*) ) );
76
77   myAddElementBox->hide();
78 }
79
80 HYDROGUI_ProfileDlg::~HYDROGUI_ProfileDlg()
81 {
82 }
83
84 void HYDROGUI_ProfileDlg::reset()
85 {
86   myEditorWidget->reset();
87   myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
88   viewer()->setTrihedronShown( false ); // Issue #548
89 }
90
91 void HYDROGUI_ProfileDlg::setProfileName( const QString& theName )
92 {
93   myName->setText(theName);
94 }
95
96 QString HYDROGUI_ProfileDlg::getProfileName() const
97 {
98   return myName->text();
99 }
100
101 void HYDROGUI_ProfileDlg::setProfile( CurveCreator_ICurve* theProfile )
102 {
103   myEditorWidget->setCurve( theProfile );
104
105   // select the single section by default
106   QList<int> aSections;
107   aSections << 0;
108   myEditorWidget->setSelectedSections( aSections );
109 }
110
111 QList<int> HYDROGUI_ProfileDlg::getSelectedSections()
112 {
113   return myEditorWidget->getSelectedSections();
114 }
115
116 /**
117  * Redirect the delete action to editor widget
118  */
119 void HYDROGUI_ProfileDlg::deleteSelected()
120 {
121   myEditorWidget->removeSelected();
122 }
123
124 /**
125  * Checks whether there are some to delete
126  */
127 bool HYDROGUI_ProfileDlg::deleteEnabled()
128 {
129   return myEditorWidget->removeEnabled();
130 }
131
132 void HYDROGUI_ProfileDlg::processStartedSubOperation( QWidget* theWidget, bool theIsEdit )
133 {
134   myEditorWidget->setEnabled( false );
135
136   myAddElementBox->setTitle( theIsEdit ? tr( "EDIT_ELEMENT" ) : tr( "ADD_ELEMENT" ) );
137   QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
138   anAddElementLayout->addWidget( theWidget );
139
140   theWidget->show();
141   myAddElementBox->show();
142 }
143
144 void HYDROGUI_ProfileDlg::processFinishedSubOperation( QWidget* theWidget )
145 {
146   myEditorWidget->setEnabled( true );
147
148   QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
149   anAddElementLayout->removeWidget( theWidget );
150
151   theWidget->hide();
152   myAddElementBox->hide();
153 }
154
155 Handle(AIS_Trihedron) HYDROGUI_ProfileDlg::trihedron()
156 {
157     SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
158     Handle(AIS_Trihedron) aTrihedron =
159         HYDROGUI_AISTrihedron::createTrihedron( aResMgr->doubleValue( "3DViewer", "trihedron_size", viewer()->trihedronSize() ) );
160     return aTrihedron;
161 }