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 bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
44 QFormLayout* aMainlayout = new QFormLayout(this);
45 ModuleBase_Tools::adjustMargins(aMainlayout);
47 myXSpin = new ModuleBase_ParamSpinBox(this);
48 myXSpin->setAcceptVariables(aAcceptVariables);
49 myXSpin->setToolTip("X coordinate");
51 QLabel* aXLbl = new QLabel(this);
52 aXLbl->setPixmap(QPixmap(":pictures/x_size.png"));
53 aMainlayout->addRow(aXLbl, myXSpin);
55 myYSpin = new ModuleBase_ParamSpinBox(this);
56 myYSpin->setAcceptVariables(aAcceptVariables);
57 myYSpin->setToolTip("Y coordinate");
59 QLabel* aYLbl = new QLabel(this);
60 aYLbl->setPixmap(QPixmap(":pictures/y_size.png"));
61 aMainlayout->addRow(aYLbl, myYSpin);
63 myZSpin = new ModuleBase_ParamSpinBox(this);
64 myZSpin->setAcceptVariables(aAcceptVariables);
65 myZSpin->setToolTip("Z coordinate");
67 QLabel* aZLbl = new QLabel(this);
68 aZLbl->setPixmap(QPixmap(":pictures/z_size.png"));
69 aMainlayout->addRow(aZLbl, myZSpin);
72 ModuleBase_WidgetPointInput::~ModuleBase_WidgetPointInput()
78 //********************************************************************
79 QList<QWidget*> ModuleBase_WidgetPointInput::getControls() const
81 QList<QWidget*> aList;
82 aList.append(myXSpin);
83 aList.append(myYSpin);
84 aList.append(myZSpin);
88 //********************************************************************
89 bool ModuleBase_WidgetPointInput::storeValueCustom()
91 AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
93 if (myXSpin->hasVariable() || myYSpin->hasVariable() || myZSpin->hasVariable()) {
94 aAttr->setText(myXSpin->text().toStdString(),
95 myYSpin->text().toStdString(), myZSpin->text().toStdString());
97 aAttr->setValue(myXSpin->value(), myYSpin->value(), myZSpin->value());
104 //********************************************************************
105 bool ModuleBase_WidgetPointInput::restoreValueCustom()
107 AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
109 std::string aXText = aAttr->textX();
110 if (aXText.empty()) {
111 myXSpin->setValue(aAttr->x());
113 myXSpin->setText(aXText.c_str());
115 std::string aYText = aAttr->textY();
116 if (aYText.empty()) {
117 myYSpin->setValue(aAttr->y());
119 myYSpin->setText(aYText.c_str());
121 std::string aZText = aAttr->textZ();
122 if (aZText.empty()) {
123 myZSpin->setValue(aAttr->z());
125 myZSpin->setText(aZText.c_str());
132 //********************************************************************
133 void ModuleBase_WidgetPointInput::selectionModes(int& theModuleSelectionModes, QIntList& theModes)
135 theModuleSelectionModes = -1;
136 theModes << TopAbs_VERTEX;
139 //********************************************************************
140 QIntList ModuleBase_WidgetPointInput::shapeTypes() const
143 aList << TopAbs_VERTEX;
147 //********************************************************************
148 bool ModuleBase_WidgetPointInput
149 ::setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
151 GeomShapePtr aShape = thePrs->shape();
152 if (aShape->isVertex()) {
153 GeomVertexPtr aVertex(new GeomAPI_Vertex(aShape));
154 GeomPointPtr aPnt = aVertex->point();
155 myXSpin->setValue(aPnt->x());
156 myYSpin->setValue(aPnt->y());
157 myZSpin->setValue(aPnt->z());