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