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, ModuleBase_IWorkshop* theWorkshop,
38 const Config_WidgetAPI* theData)
39 : ModuleBase_WidgetSelector(theParent, theWorkshop, theData)
41 bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
43 QFormLayout* aMainlayout = new QFormLayout(this);
44 ModuleBase_Tools::adjustMargins(aMainlayout);
46 myXSpin = new ModuleBase_ParamSpinBox(this);
47 myXSpin->setAcceptVariables(aAcceptVariables);
48 myXSpin->setToolTip("X coordinate");
50 QLabel* aXLbl = new QLabel(this);
51 aXLbl->setPixmap(QPixmap(":pictures/x_size.png"));
52 aMainlayout->addRow(aXLbl, myXSpin);
54 myYSpin = new ModuleBase_ParamSpinBox(this);
55 myYSpin->setAcceptVariables(aAcceptVariables);
56 myYSpin->setToolTip("Y coordinate");
58 QLabel* aYLbl = new QLabel(this);
59 aYLbl->setPixmap(QPixmap(":pictures/y_size.png"));
60 aMainlayout->addRow(aYLbl, myYSpin);
62 myZSpin = new ModuleBase_ParamSpinBox(this);
63 myZSpin->setAcceptVariables(aAcceptVariables);
64 myZSpin->setToolTip("Z coordinate");
66 QLabel* aZLbl = new QLabel(this);
67 aZLbl->setPixmap(QPixmap(":pictures/z_size.png"));
68 aMainlayout->addRow(aZLbl, myZSpin);
71 ModuleBase_WidgetPointInput::~ModuleBase_WidgetPointInput()
77 //********************************************************************
78 QList<QWidget*> ModuleBase_WidgetPointInput::getControls() const
80 QList<QWidget*> aList;
81 aList.append(myXSpin);
82 aList.append(myYSpin);
83 aList.append(myZSpin);
87 //********************************************************************
88 bool ModuleBase_WidgetPointInput::storeValueCustom()
90 AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
92 if (myXSpin->hasVariable() || myYSpin->hasVariable() || myZSpin->hasVariable()) {
93 aAttr->setText(myXSpin->text().toStdString(),
94 myYSpin->text().toStdString(), myZSpin->text().toStdString());
96 aAttr->setValue(myXSpin->value(), myYSpin->value(), myZSpin->value());
103 //********************************************************************
104 bool ModuleBase_WidgetPointInput::restoreValueCustom()
106 AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
108 std::string aXText = aAttr->textX();
109 if (aXText.empty()) {
110 myXSpin->setValue(aAttr->x());
112 myXSpin->setText(aXText.c_str());
114 std::string aYText = aAttr->textY();
115 if (aYText.empty()) {
116 myYSpin->setValue(aAttr->y());
118 myYSpin->setText(aYText.c_str());
120 std::string aZText = aAttr->textZ();
121 if (aZText.empty()) {
122 myZSpin->setValue(aAttr->z());
124 myZSpin->setText(aZText.c_str());
131 //********************************************************************
132 void ModuleBase_WidgetPointInput::selectionModes(int& theModuleSelectionModes, QIntList& theModes)
134 theModuleSelectionModes = -1;
135 theModes << TopAbs_VERTEX;
138 //********************************************************************
139 QIntList ModuleBase_WidgetPointInput::shapeTypes() const
142 aList << TopAbs_VERTEX;
146 //********************************************************************
147 bool ModuleBase_WidgetPointInput
148 ::setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
150 GeomShapePtr aShape = thePrs->shape();
151 if (aShape->isVertex()) {
152 GeomVertexPtr aVertex(new GeomAPI_Vertex(aShape));
153 GeomPointPtr aPnt = aVertex->point();
154 myXSpin->setValue(aPnt->x());
155 myYSpin->setValue(aPnt->y());
156 myZSpin->setValue(aPnt->z());