1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "ModuleBase_WidgetPointInput.h"
22 #include "ModuleBase_Tools.h"
23 #include "ModuleBase_ParamSpinBox.h"
24 #include "ModuleBase_ViewerPrs.h"
26 #include <GeomAPI_Vertex.h>
27 #include <GeomAPI_Pnt.h>
29 #include <GeomDataAPI_Point.h>
31 #include <Config_WidgetAPI.h>
32 #include <Config_Keywords.h>
34 #include <QFormLayout>
37 ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent,
38 ModuleBase_IWorkshop* theWorkshop,
39 const Config_WidgetAPI* theData)
40 : ModuleBase_WidgetSelector(theParent, theWorkshop, theData)
42 myDefaultValue[0] = 0;
43 myDefaultValue[1] = 0;
44 myDefaultValue[2] = 0;
45 bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
47 std::string aDefValuesStr = theData->getProperty(ATTR_DEFAULT);
48 if (!aDefValuesStr.empty()) {
49 QString aDefVal(aDefValuesStr.c_str());
50 QStringList aStrArray = aDefVal.split(';', QString::SkipEmptyParts);
51 if (aStrArray.length() == 3) {
52 for (int i = 0; i < 3; i++)
53 myDefaultValue[i] = aStrArray.at(i).toDouble();
56 QFormLayout* aMainlayout = new QFormLayout(this);
57 ModuleBase_Tools::adjustMargins(aMainlayout);
59 myXSpin = new ModuleBase_ParamSpinBox(this);
60 myXSpin->setAcceptVariables(aAcceptVariables);
61 myXSpin->setToolTip("X coordinate");
62 myXSpin->setValue(myDefaultValue[0]);
63 QLabel* aXLbl = new QLabel(this);
64 aXLbl->setPixmap(QPixmap(":pictures/x_size.png"));
65 aMainlayout->addRow(aXLbl, myXSpin);
67 myYSpin = new ModuleBase_ParamSpinBox(this);
68 myYSpin->setAcceptVariables(aAcceptVariables);
69 myYSpin->setToolTip("Y coordinate");
70 myYSpin->setValue(myDefaultValue[1]);
71 QLabel* aYLbl = new QLabel(this);
72 aYLbl->setPixmap(QPixmap(":pictures/y_size.png"));
73 aMainlayout->addRow(aYLbl, myYSpin);
75 myZSpin = new ModuleBase_ParamSpinBox(this);
76 myZSpin->setAcceptVariables(aAcceptVariables);
77 myZSpin->setToolTip("Z coordinate");
78 myZSpin->setValue(myDefaultValue[2]);
79 QLabel* aZLbl = new QLabel(this);
80 aZLbl->setPixmap(QPixmap(":pictures/z_size.png"));
81 aMainlayout->addRow(aZLbl, myZSpin);
83 connect(myXSpin, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesModified()));
84 connect(myYSpin, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesModified()));
85 connect(myZSpin, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesModified()));
88 ModuleBase_WidgetPointInput::~ModuleBase_WidgetPointInput()
94 //********************************************************************
95 QList<QWidget*> ModuleBase_WidgetPointInput::getControls() const
97 QList<QWidget*> aList;
98 aList.append(myXSpin);
99 aList.append(myYSpin);
100 aList.append(myZSpin);
104 //********************************************************************
105 bool ModuleBase_WidgetPointInput::storeValueCustom()
107 AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
109 if (aAttr->isInitialized()) {
110 if (myXSpin->hasVariable() || myYSpin->hasVariable() || myZSpin->hasVariable()) {
111 aAttr->setText(myXSpin->text().toStdString(),
112 myYSpin->text().toStdString(), myZSpin->text().toStdString());
114 aAttr->setValue(myXSpin->value(), myYSpin->value(), myZSpin->value());
117 aAttr->setValue(myDefaultValue[0], myDefaultValue[1], myDefaultValue[2]);
119 updateObject(myFeature);
125 //********************************************************************
126 bool ModuleBase_WidgetPointInput::restoreValueCustom()
128 AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
130 if (aAttr->isInitialized()) {
131 std::string aXText = aAttr->textX();
132 if (aXText.empty()) {
133 myXSpin->setValue(aAttr->x());
136 myXSpin->setText(aXText.c_str());
138 std::string aYText = aAttr->textY();
139 if (aYText.empty()) {
140 myYSpin->setValue(aAttr->y());
143 myYSpin->setText(aYText.c_str());
145 std::string aZText = aAttr->textZ();
146 if (aZText.empty()) {
147 myZSpin->setValue(aAttr->z());
150 myZSpin->setText(aZText.c_str());
154 aAttr->setValue(myDefaultValue[0], myDefaultValue[1], myDefaultValue[2]);
155 myXSpin->setValue(myDefaultValue[0]);
156 myYSpin->setValue(myDefaultValue[1]);
157 myZSpin->setValue(myDefaultValue[2]);
164 //********************************************************************
165 void ModuleBase_WidgetPointInput::selectionModes(int& theModuleSelectionModes, QIntList& theModes)
167 theModuleSelectionModes = -1;
168 theModes << TopAbs_VERTEX;
171 //********************************************************************
172 QIntList ModuleBase_WidgetPointInput::shapeTypes() const
175 aList << TopAbs_VERTEX;
179 //********************************************************************
180 bool ModuleBase_WidgetPointInput
181 ::setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
183 GeomShapePtr aShape = thePrs->shape();
184 if (aShape->isVertex()) {
185 GeomVertexPtr aVertex(new GeomAPI_Vertex(aShape));
186 GeomPointPtr aPnt = aVertex->point();
187 myXSpin->setValue(aPnt->x());
188 myYSpin->setValue(aPnt->y());
189 myZSpin->setValue(aPnt->z());
195 //********************************************************************
196 bool ModuleBase_WidgetPointInput::processEnter()
198 bool isModified = getValueState() == ModifiedInPP;
200 emit valuesChanged();