]> SALOME platform Git repositories - modules/geom.git/blob - src/CurveCreator/CurveCreator_EditPntsWidget.cxx
Salome HOME
Images neccessary for CurveEditor were added
[modules/geom.git] / src / CurveCreator / CurveCreator_EditPntsWidget.cxx
1 // Copyright (C) 2007-2013  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.
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 // File:        CurveCreator_EditPntsWidget.cxx
24 // Created:     Fri Jul  05 16:30:11 2013
25 // Author:      Sergey KHROMOV
26 //
27
28
29 #include <CurveCreator_EditPntsWidget.h>
30 #include <CurveCreator_EditPntsDlg.h>
31 #include <CurveCreator_PointItem.h>
32 #include <QGroupBox>
33 #include <QHBoxLayout>
34 #include <QLabel>
35 #include <QLineEdit>
36 #include <QListWidget>
37 #include <QPushButton>
38
39
40 //=======================================================================
41 // function: Constructor
42 // purpose:
43 //=======================================================================
44 CurveCreator_EditPntsWidget::CurveCreator_EditPntsWidget
45   (QWidget* parent,
46    const bool IsSection,
47    const CurveCreator::Dimension theDimension)
48   : QWidget       (parent),
49     myDimension   (theDimension),
50     myPntsEdit    (NULL),
51     myPntsBtn     (NULL),
52     myPntsEditDlg (NULL),
53     myPntsList    (NULL)
54 {
55   QGroupBox   *aMainGrp = new QGroupBox;
56   QHBoxLayout *aMainLO  = new QHBoxLayout(aMainGrp);
57
58   myPntsEdit = new QLineEdit(aMainGrp);
59   myPntsBtn  = new QPushButton
60     (IsSection? tr("CC_SECTION_POINTS_EDIT") : tr("CC_POINTS_EDIT"), aMainGrp);
61   aMainLO->addWidget(myPntsEdit);
62   aMainLO->addWidget(myPntsBtn);
63
64   setLayout(aMainLO);
65
66   init();
67 }
68
69 //=======================================================================
70 // function: Destructor
71 // purpose:
72 //=======================================================================
73 CurveCreator_EditPntsWidget::~CurveCreator_EditPntsWidget()
74 {
75 }
76
77 //=======================================================================
78 // function: setPoints
79 // purpose:
80 //=======================================================================
81 void CurveCreator_EditPntsWidget::setPoints
82                     (const CurveCreator::Coordinates &thePoints)
83 {
84   myPoints = thePoints;
85   updateEditLine();
86 }
87
88 //=======================================================================
89 // function: getPoints
90 // purpose:
91 //=======================================================================
92 const CurveCreator::Coordinates &CurveCreator_EditPntsWidget::getPoints() const
93 {
94   return myPoints;
95 }
96
97 //=======================================================================
98 // function : setPointsList
99 // purpose  :
100 //=======================================================================
101 void CurveCreator_EditPntsWidget::setPointsList(QListWidget *thePntsList)
102 {
103   myPntsList = thePntsList;
104 }
105
106 //=======================================================================
107 // function : clear
108 // purpose  :
109 //=======================================================================
110 void CurveCreator_EditPntsWidget::clear()
111 {
112   myPoints.clear();
113   myPntsEdit->setText("");
114 }
115
116 //=======================================================================
117 // function : getPointsEdit
118 // purpose  :
119 //=======================================================================
120 QLineEdit *CurveCreator_EditPntsWidget::getPointsEdit() const
121 {
122   return myPntsEdit;
123 }
124
125 //=======================================================================
126 // function : getPointsButton
127 // purpose  :
128 //=======================================================================
129 QPushButton *CurveCreator_EditPntsWidget::getPointsButton() const
130 {
131   return myPntsBtn;
132 }
133
134 //=======================================================================
135 // function : init
136 // purpose  :
137 //=======================================================================
138 void CurveCreator_EditPntsWidget::init()
139 {
140   connect(myPntsBtn, SIGNAL(clicked()), this, SLOT(editPoints()));
141
142   myPntsEdit->setReadOnly(true);
143   updateEditLine();
144
145   // Set tab order.
146   QWidget::setTabOrder(myPntsEdit, myPntsBtn);
147 }
148
149 //=======================================================================
150 // function : editPoints
151 // purpose  :
152 //=======================================================================
153 void CurveCreator_EditPntsWidget::editPoints()
154 {
155   if (myPntsEditDlg == NULL) {
156     // Create the dialog.
157     myPntsEditDlg = new CurveCreator_EditPntsDlg(this, myDimension);
158   }
159
160   // Set points to dialog.
161   setPointsToDialog();
162
163   const int aResult = myPntsEditDlg->exec();
164
165   if (aResult == QDialog::Accepted) {
166     // Update the list of points and myPntsEdit.
167     const CurveCreator::Coordinates &aNewPoints = myPntsEditDlg->getPoints();
168
169     myPoints.clear();
170     myPoints.insert(myPoints.end(), aNewPoints.begin(), aNewPoints.end());
171     updateEditLine();
172   }
173 }
174
175 //=======================================================================
176 // function : updateEditLine
177 // purpose  :
178 //=======================================================================
179 void CurveCreator_EditPntsWidget::updateEditLine()
180 {
181   const int aNbPnts = myPoints.size();
182
183   if ( aNbPnts == 0 ) {
184     myPntsEdit->setText("");
185   } else if ( aNbPnts == myDimension ) {
186     // One point.
187     QString aText;
188
189     if (myDimension == CurveCreator::Dim3d) {
190       aText = CurveCreator_PointItem::getText
191                   (myPoints[0], myPoints[1], myPoints[2]);
192     } else {
193       aText = CurveCreator_PointItem::getText(myPoints[0], myPoints[1]);
194     }
195
196     myPntsEdit->setText(aText);
197   } else if ( aNbPnts > 0 ) {
198     myPntsEdit->setText(tr("CC_POINTS_NUMBER").arg(aNbPnts/myDimension));
199   }
200 }
201
202 //=======================================================================
203 // function : setPointsToDialog
204 // purpose  :
205 //=======================================================================
206 void CurveCreator_EditPntsWidget::setPointsToDialog()
207 {
208   bool isPntsFromWidget = false;
209
210   if (myPntsList != NULL) {
211     QList<QListWidgetItem *> aListItems = myPntsList->selectedItems();
212
213     if (aListItems.size() > 0) {
214       CurveCreator::Coordinates aPoints;
215
216       foreach (QListWidgetItem *anItem, aListItems) {
217         const CurveCreator_PointItem *aPntItem =
218           (const CurveCreator_PointItem *)anItem;
219
220         aPoints.push_back(aPntItem->getX());
221         aPoints.push_back(aPntItem->getY());
222
223         if (myDimension == CurveCreator::Dim3d) {
224           aPoints.push_back(aPntItem->getZ());
225         }
226       }
227
228       myPntsEditDlg->setPoints(aPoints);
229       isPntsFromWidget = true;
230     }
231   }
232
233   if (!isPntsFromWidget) {
234     myPntsEditDlg->setPoints(myPoints);
235   }
236 }