]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetPointInput.cpp
Salome HOME
Code standard issues
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetPointInput.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "ModuleBase_WidgetPointInput.h"
22 #include "ModuleBase_Tools.h"
23 #include "ModuleBase_ParamSpinBox.h"
24 #include "ModuleBase_ViewerPrs.h"
25
26 #include <GeomAPI_Vertex.h>
27 #include <GeomAPI_Pnt.h>
28
29 #include <GeomDataAPI_Point.h>
30
31 #include <Config_WidgetAPI.h>
32 #include <Config_Keywords.h>
33
34 #include <QFormLayout>
35 #include <QLabel>
36
37 ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent,
38   ModuleBase_IWorkshop* theWorkshop,
39   const Config_WidgetAPI* theData)
40   : ModuleBase_WidgetSelector(theParent, theWorkshop, theData)
41 {
42   bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
43
44   QFormLayout* aMainlayout = new QFormLayout(this);
45   ModuleBase_Tools::adjustMargins(aMainlayout);
46
47   myXSpin = new ModuleBase_ParamSpinBox(this);
48   myXSpin->setAcceptVariables(aAcceptVariables);
49   myXSpin->setToolTip("X coordinate");
50   myXSpin->setValue(0);
51   QLabel* aXLbl = new QLabel(this);
52   aXLbl->setPixmap(QPixmap(":pictures/x_size.png"));
53   aMainlayout->addRow(aXLbl, myXSpin);
54
55   myYSpin = new ModuleBase_ParamSpinBox(this);
56   myYSpin->setAcceptVariables(aAcceptVariables);
57   myYSpin->setToolTip("Y coordinate");
58   myYSpin->setValue(0);
59   QLabel* aYLbl = new QLabel(this);
60   aYLbl->setPixmap(QPixmap(":pictures/y_size.png"));
61   aMainlayout->addRow(aYLbl, myYSpin);
62
63   myZSpin = new ModuleBase_ParamSpinBox(this);
64   myZSpin->setAcceptVariables(aAcceptVariables);
65   myZSpin->setToolTip("Z coordinate");
66   myZSpin->setValue(0);
67   QLabel* aZLbl = new QLabel(this);
68   aZLbl->setPixmap(QPixmap(":pictures/z_size.png"));
69   aMainlayout->addRow(aZLbl, myZSpin);
70 }
71
72 ModuleBase_WidgetPointInput::~ModuleBase_WidgetPointInput()
73 {
74
75 }
76
77
78 //********************************************************************
79 QList<QWidget*> ModuleBase_WidgetPointInput::getControls() const
80 {
81   QList<QWidget*> aList;
82   aList.append(myXSpin);
83   aList.append(myYSpin);
84   aList.append(myZSpin);
85   return aList;
86 }
87
88 //********************************************************************
89 bool ModuleBase_WidgetPointInput::storeValueCustom()
90 {
91   AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
92   if (aAttr.get()) {
93     if (myXSpin->hasVariable() || myYSpin->hasVariable() || myZSpin->hasVariable()) {
94       aAttr->setText(myXSpin->text().toStdString(),
95         myYSpin->text().toStdString(), myZSpin->text().toStdString());
96     } else {
97       aAttr->setValue(myXSpin->value(), myYSpin->value(), myZSpin->value());
98     }
99     return true;
100   }
101   return false;
102 }
103
104 //********************************************************************
105 bool ModuleBase_WidgetPointInput::restoreValueCustom()
106 {
107   AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
108   if (aAttr.get()) {
109     std::string aXText = aAttr->textX();
110     if (aXText.empty()) {
111       myXSpin->setValue(aAttr->x());
112     } else {
113       myXSpin->setText(aXText.c_str());
114     }
115     std::string aYText = aAttr->textY();
116     if (aYText.empty()) {
117       myYSpin->setValue(aAttr->y());
118     } else {
119       myYSpin->setText(aYText.c_str());
120     }
121     std::string aZText = aAttr->textZ();
122     if (aZText.empty()) {
123       myZSpin->setValue(aAttr->z());
124     } else {
125       myZSpin->setText(aZText.c_str());
126     }
127     return true;
128   }
129   return false;
130 }
131
132 //********************************************************************
133 void ModuleBase_WidgetPointInput::selectionModes(int& theModuleSelectionModes, QIntList& theModes)
134 {
135   theModuleSelectionModes = -1;
136   theModes << TopAbs_VERTEX;
137 }
138
139 //********************************************************************
140 QIntList ModuleBase_WidgetPointInput::shapeTypes() const
141 {
142   QIntList aList;
143   aList << TopAbs_VERTEX;
144   return aList;
145 }
146
147 //********************************************************************
148 bool ModuleBase_WidgetPointInput
149 ::setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
150 {
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());
158     return true;
159   }
160   return false;
161 }