Salome HOME
a94b56417678d5637b03c82246a6ab277fe2d322
[modules/geom.git] / src / CurveCreator / CurveCreator_NewSectionDlg.cxx
1 // Copyright (C) 2013-2022  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, bool enableClosed ) :
35   QWidget(parent), myIsEnableClosed( enableClosed )
36 {
37   QVBoxLayout* aMainLayout = new QVBoxLayout( this );
38   aMainLayout->setMargin( 0 );
39
40   QFrame* aFrame = new QFrame( this );
41   aMainLayout->addWidget( aFrame );
42
43   QVBoxLayout* aLayout = new QVBoxLayout( aFrame );
44   aLayout->setMargin( 0 );
45
46   QFrame* aCoordFrame = new QFrame( aFrame );
47   QGridLayout* aCoordLayout = new QGridLayout( aCoordFrame );
48
49   QLabel* aLbl = new QLabel(tr("SECTION_NAME"), this);
50   myName = new QLineEdit(this);
51   aCoordLayout->addWidget(aLbl, 0, 0);
52   aCoordLayout->addWidget(myName, 0 , 1);
53
54   aLbl = new QLabel(tr("SECTION_LINE_TYPE"));
55   myLineType = new QComboBox(this);
56
57   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
58   QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
59   QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
60
61 //  QPixmap aPolylinePixmap = QPixmap(tr(":images/ICON_POLYLINE"));
62 //  QPixmap aSplinePixmap = QPixmap(tr(":images/ICON_SPLINE"));
63   myLineType->addItem(aPolylinePixmap, tr("SECTION_POLYLINE_TYPE"));
64   myLineType->addItem(aSplinePixmap, tr("SECTION_SPLINE_TYPE"));
65   myLineType->setCurrentIndex(0);
66   aCoordLayout->addWidget(aLbl, 1, 0);
67   aCoordLayout->addWidget(myLineType, 1 , 1);
68
69   aLbl = new QLabel(tr("SECTION_LINE_CLOSED"));
70   myIsClosed = new QCheckBox(this);
71   aCoordLayout->addWidget(aLbl, 2, 0);
72   aCoordLayout->addWidget(myIsClosed, 2, 1);
73   if ( !myIsEnableClosed ) {
74     aLbl->hide();
75     myIsClosed->hide();
76   }
77
78   myBtnFrame = new QFrame( aFrame );
79   QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame );
80
81   myAddBtn = new QPushButton( tr( "SECTION_ADD_BTN" ), myBtnFrame );
82   myCancelBtn = new QPushButton( tr( "SECTION_CANCEL_BTN" ), myBtnFrame );
83
84   connect( myAddBtn,  SIGNAL( clicked() ), this, SIGNAL( addSection() ) );
85   connect( myCancelBtn, SIGNAL( clicked() ), this, SIGNAL( cancelSection() ) );
86
87   aBtnsLayout->addWidget( myAddBtn );
88   aBtnsLayout->addStretch( 1 );
89   aBtnsLayout->addWidget( myCancelBtn );
90
91   aLayout->addWidget( aCoordFrame, 0 );
92   aLayout->addWidget( myBtnFrame, 1 );
93 }
94
95 void CurveCreator_NewSectionDlg::setSectionParameters( const QString& theName, bool isClosed, CurveCreator::SectionType theType )
96 {
97   myName->setText(theName);
98   myIsClosed->setChecked(isClosed);
99   if( theType == CurveCreator::Polyline )
100     myLineType->setCurrentIndex(0);
101   else
102     myLineType->setCurrentIndex(1);
103 }
104
105 void CurveCreator_NewSectionDlg::clear()
106 {
107   myName->setText("");
108   myIsClosed->setChecked(true);
109   myLineType->setCurrentIndex(0);
110 }
111
112 void CurveCreator_NewSectionDlg::setEditMode( bool isEdit )
113 {
114   myIsEdit = isEdit;
115   if( myIsEdit ){
116     myAddBtn->setText(tr("SECTION_OK_BTN"));
117     myAddBtn->disconnect( SIGNAL( clicked() ) );
118     connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( modifySection() ) );
119   }
120   else{
121     myAddBtn->setText(tr("SECTION_ADD_BTN"));
122     myAddBtn->disconnect( SIGNAL( clicked() ) );
123     connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addSection() ) );
124   }
125   updateTitle();
126 }
127
128 QString CurveCreator_NewSectionDlg::getName() const
129 {
130   return myName->text();
131 }
132
133 bool CurveCreator_NewSectionDlg::isClosed() const
134 {
135   return myIsClosed->isChecked();
136 }
137
138 CurveCreator::SectionType CurveCreator_NewSectionDlg::getSectionType() const
139 {
140   if( myLineType->currentIndex() == 0 )
141     return CurveCreator::Polyline;
142   else
143     return CurveCreator::Spline;
144 }
145
146 void CurveCreator_NewSectionDlg::updateTitle()
147 {
148   QString aTitle;
149   if( !myIsEdit )
150     aTitle = tr("ADD_NEW_SECTION");
151   else
152     aTitle = QString(tr("SET_SECTION_PARAMETERS"));
153   setWindowTitle(aTitle);
154 }
155
156 void CurveCreator_NewSectionDlg::setSectionName( const QString& theName )
157 {
158   myName->setText(theName);
159 }