Salome HOME
275a94625d3414f0e3b792312e363178e3afed7f
[modules/geom.git] / src / CurveCreator / CurveCreator_NewSectionDlg.cxx
1 // Copyright (C) 2013-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "CurveCreator_NewSectionDlg.h"
21 #include "CurveCreator_Curve.hxx"
22
23 #include <SUIT_Session.h>
24 #include <SUIT_ResourceMgr.h>
25
26 #include <QGridLayout>
27 #include <QLabel>
28 #include <QLineEdit>
29 #include <QComboBox>
30 #include <QCheckBox>
31 #include <QDialogButtonBox>
32 #include <QPushButton>
33
34 CurveCreator_NewSectionDlg::CurveCreator_NewSectionDlg( QWidget *parent ) :
35   QWidget(parent)
36 {
37   QFrame* aFrame = new QFrame( this );
38   QVBoxLayout* aLayout = new QVBoxLayout( aFrame );
39
40   QFrame* aCoordFrame = new QFrame( aFrame );
41   QGridLayout* aCoordLayout = new QGridLayout( aCoordFrame );
42
43   QLabel* aLbl = new QLabel(tr("NAME"), this);
44   myName = new QLineEdit(this);
45   aCoordLayout->addWidget(aLbl, 0, 0);
46   aCoordLayout->addWidget(myName, 0 , 1);
47
48   aLbl = new QLabel(tr("LINE_TYPE"));
49   myLineType = new QComboBox(this);
50
51   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
52   QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
53   QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
54
55 //  QPixmap aPolylinePixmap = QPixmap(tr(":images/ICON_POLYLINE"));
56 //  QPixmap aSplinePixmap = QPixmap(tr(":images/ICON_SPLINE"));
57   myLineType->addItem(aPolylinePixmap, tr("POLYLINE_TYPE"));
58   myLineType->addItem(aSplinePixmap, tr("SPLINE_TYPE"));
59   myLineType->setCurrentIndex(0);
60   aCoordLayout->addWidget(aLbl, 1, 0);
61   aCoordLayout->addWidget(myLineType, 1 , 1);
62
63   aLbl = new QLabel(tr("LINE_CLOSED"));
64   myIsClosed = new QCheckBox(this);
65   aCoordLayout->addWidget(aLbl, 2, 0);
66   aCoordLayout->addWidget(myIsClosed, 2, 1);
67
68   myBtnFrame = new QFrame( aFrame );
69   QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame );
70
71   myAddBtn = new QPushButton( tr( "ADD_BTN" ), myBtnFrame );
72   myCancelBtn = new QPushButton( tr( "CANCEL" ), myBtnFrame );
73
74   connect( myAddBtn,  SIGNAL( clicked() ), this, SIGNAL( addSection() ) );
75   connect( myCancelBtn, SIGNAL( clicked() ), this, SIGNAL( cancelSection() ) );
76
77   aBtnsLayout->addWidget( myAddBtn );
78   aBtnsLayout->addStretch( 1 );
79   aBtnsLayout->addWidget( myCancelBtn );
80
81   aLayout->addWidget( aCoordFrame, 0 );
82   aLayout->addWidget( myBtnFrame, 1 );
83 }
84
85 void CurveCreator_NewSectionDlg::setSectionParameters( const QString& theName, bool isClosed, CurveCreator::Type theType )
86 {
87   myName->setText(theName);
88   myIsClosed->setChecked(isClosed);
89   if( theType == CurveCreator::Polyline )
90     myLineType->setCurrentIndex(0);
91   else
92     myLineType->setCurrentIndex(1);
93 }
94
95 void CurveCreator_NewSectionDlg::clear()
96 {
97   myName->setText("");
98   myIsClosed->setChecked(true);
99   myLineType->setCurrentIndex(0);
100 }
101
102 void CurveCreator_NewSectionDlg::setEditMode( bool isEdit )
103 {
104   myIsEdit = isEdit;
105   if( myIsEdit ){
106     myAddBtn->setText(tr("OK"));
107     myAddBtn->disconnect( SIGNAL( clicked() ) );
108     connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( modifySection() ) );
109   }
110   else{
111     myAddBtn->setText(tr("ADD_BTN"));
112     myAddBtn->disconnect( SIGNAL( clicked() ) );
113     connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addSection() ) );
114   }
115   updateTitle();
116 }
117
118 QString CurveCreator_NewSectionDlg::getName() const
119 {
120   return myName->text();
121 }
122
123 bool CurveCreator_NewSectionDlg::isClosed() const
124 {
125   return myIsClosed->isChecked();
126 }
127
128 CurveCreator::Type CurveCreator_NewSectionDlg::getSectionType() const
129 {
130   if( myLineType->currentIndex() == 0 )
131     return CurveCreator::Polyline;
132   else
133     return CurveCreator::BSpline;
134 }
135
136 void CurveCreator_NewSectionDlg::updateTitle()
137 {
138   QString aTitle;
139   if( !myIsEdit )
140     aTitle = tr("ADD_NEW_SECTION");
141   else
142     aTitle = QString(tr("SET_SECTION_PARAMETERS"));
143   setWindowTitle(aTitle);
144 }
145
146 void CurveCreator_NewSectionDlg::setSectionName( const QString& theName )
147 {
148   myName->setText(theName);
149 }