1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: CurveCreator_EditPntsWidget.cxx
24 // Created: Fri Jul 05 16:30:11 2013
25 // Author: Sergey KHROMOV
29 #include <CurveCreator_EditPntsWidget.h>
30 #include <CurveCreator_EditPntsDlg.h>
31 #include <CurveCreator_PointItem.h>
33 #include <QHBoxLayout>
36 #include <QListWidget>
37 #include <QPushButton>
40 //=======================================================================
41 // function: Constructor
43 //=======================================================================
44 CurveCreator_EditPntsWidget::CurveCreator_EditPntsWidget
47 const CurveCreator::Dimension theDimension)
49 myDimension (theDimension),
55 QGroupBox *aMainGrp = new QGroupBox;
56 QHBoxLayout *aMainLO = new QHBoxLayout(aMainGrp);
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);
69 //=======================================================================
70 // function: Destructor
72 //=======================================================================
73 CurveCreator_EditPntsWidget::~CurveCreator_EditPntsWidget()
77 //=======================================================================
78 // function: setPoints
80 //=======================================================================
81 void CurveCreator_EditPntsWidget::setPoints
82 (const CurveCreator::Coordinates &thePoints)
88 //=======================================================================
89 // function: getPoints
91 //=======================================================================
92 const CurveCreator::Coordinates &CurveCreator_EditPntsWidget::getPoints() const
97 //=======================================================================
98 // function : setPointsList
100 //=======================================================================
101 void CurveCreator_EditPntsWidget::setPointsList(QListWidget *thePntsList)
103 myPntsList = thePntsList;
106 //=======================================================================
109 //=======================================================================
110 void CurveCreator_EditPntsWidget::clear()
113 myPntsEdit->setText("");
116 //=======================================================================
117 // function : getPointsEdit
119 //=======================================================================
120 QLineEdit *CurveCreator_EditPntsWidget::getPointsEdit() const
125 //=======================================================================
126 // function : getPointsButton
128 //=======================================================================
129 QPushButton *CurveCreator_EditPntsWidget::getPointsButton() const
134 //=======================================================================
137 //=======================================================================
138 void CurveCreator_EditPntsWidget::init()
140 connect(myPntsBtn, SIGNAL(clicked()), this, SLOT(editPoints()));
142 myPntsEdit->setReadOnly(true);
146 QWidget::setTabOrder(myPntsEdit, myPntsBtn);
149 //=======================================================================
150 // function : editPoints
152 //=======================================================================
153 void CurveCreator_EditPntsWidget::editPoints()
155 if (myPntsEditDlg == NULL) {
156 // Create the dialog.
157 myPntsEditDlg = new CurveCreator_EditPntsDlg(this, myDimension);
160 // Set points to dialog.
163 const int aResult = myPntsEditDlg->exec();
165 if (aResult == QDialog::Accepted) {
166 // Update the list of points and myPntsEdit.
167 const CurveCreator::Coordinates &aNewPoints = myPntsEditDlg->getPoints();
170 myPoints.insert(myPoints.end(), aNewPoints.begin(), aNewPoints.end());
175 //=======================================================================
176 // function : updateEditLine
178 //=======================================================================
179 void CurveCreator_EditPntsWidget::updateEditLine()
181 const int aNbPnts = myPoints.size();
183 if ( aNbPnts == 0 ) {
184 myPntsEdit->setText("");
185 } else if ( aNbPnts == myDimension ) {
189 if (myDimension == CurveCreator::Dim3d) {
190 aText = CurveCreator_PointItem::getText
191 (myPoints[0], myPoints[1], myPoints[2]);
193 aText = CurveCreator_PointItem::getText(myPoints[0], myPoints[1]);
196 myPntsEdit->setText(aText);
197 } else if ( aNbPnts > 0 ) {
198 myPntsEdit->setText(tr("CC_POINTS_NUMBER").arg(aNbPnts/myDimension));
202 //=======================================================================
203 // function : setPointsToDialog
205 //=======================================================================
206 void CurveCreator_EditPntsWidget::setPointsToDialog()
208 bool isPntsFromWidget = false;
210 if (myPntsList != NULL) {
211 QList<QListWidgetItem *> aListItems = myPntsList->selectedItems();
213 if (aListItems.size() > 0) {
214 CurveCreator::Coordinates aPoints;
216 foreach (QListWidgetItem *anItem, aListItems) {
217 const CurveCreator_PointItem *aPntItem =
218 (const CurveCreator_PointItem *)anItem;
220 aPoints.push_back(aPntItem->getX());
221 aPoints.push_back(aPntItem->getY());
223 if (myDimension == CurveCreator::Dim3d) {
224 aPoints.push_back(aPntItem->getZ());
228 myPntsEditDlg->setPoints(aPoints);
229 isPntsFromWidget = true;
233 if (!isPntsFromWidget) {
234 myPntsEditDlg->setPoints(myPoints);