19#include "../../forms/ConstantForm.h"
25 Node* nodeOut =
new Node(m_position + wxPoint2DDouble(m_width / 2, 0), Node::NodeType::NODE_OUT, m_borderSize);
26 nodeOut->SetAngle(180.0);
27 nodeOut->StartMove(m_position);
28 m_nodeList.push_back(nodeOut);
34 if (m_gcText)
delete m_gcText;
35 for (
auto& node : m_nodeList) if (node) delete node;
42 gc->SetPen(*wxTRANSPARENT_PEN);
43 gc->SetBrush(guiColour->selection);
44 double borderSize = (m_borderSize * 2.0 + 1.0) / scale;
45 gc->DrawRectangle(m_position.m_x - m_width / 2 - borderSize / 2, m_position.m_y - m_height / 2 - borderSize / 2, m_width + borderSize, m_height + borderSize);
47 gc->SetPen(wxPen(guiColour->enabled, 1));
48 gc->SetBrush(guiColour->background);
50 gc->DrawRectangle(m_position.m_x - m_width / 2, m_position.m_y - m_height / 2, m_width, m_height);
53 m_gcText->
Draw(m_position + wxPoint2DDouble(-m_gcText->GetWidth() / 2, -m_gcText->GetHeight() / 2), gc, 0, guiColour->text);
55 gc->SetPen(*wxTRANSPARENT_PEN);
56 gc->SetBrush(guiColour->enabled);
63 form.CenterOnParent();
64 if (form.ShowModal() == wxID_OK) {
83 for (
auto it = m_nodeList.begin(), itEnd = m_nodeList.end(); it != itEnd; ++it) {
85 node->Rotate(clockwise);
89void Constant::SetFont(wxFont& font)
91 if (m_gcText) m_gcText->SetFont(font);
95void Constant::UpdatePoints()
97 if (m_nodeList.size() != 0) {
99 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 0));
101 else if (m_angle == 90.0) {
102 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(0, -m_height / 2));
104 else if (m_angle == 180.0) {
105 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(m_width / 2, 0));
107 else if (m_angle == 270.0) {
108 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(0, m_height / 2));
113void Constant::SetValue(
double value)
121 m_gcText =
new GCText(text);
123 m_width = m_gcText->GetWidth() + 6 + 2 * m_borderSize;
124 m_height = m_gcText->GetHeight() + 6 + 2 * m_borderSize;
132 copy->m_gcText = m_gcText ? m_gcText->
GetCopy() :
nullptr;
143rapidxml::xml_node<>* Constant::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
145 auto elementNode = XMLParser::AppendNode(doc, elementListNode,
"Constant");
146 XMLParser::SetNodeAttribute(doc, elementNode,
"ID", m_elementID);
148 SaveCADProperties(doc, elementNode);
149 SaveControlNodes(doc, elementNode);
152 auto value = XMLParser::AppendNode(doc, elementNode,
"Value");
153 XMLParser::SetNodeValue(doc, value, m_value);
158bool Constant::OpenElement(rapidxml::xml_node<>* elementNode)
160 if (!OpenCADProperties(elementNode))
return false;
161 if (!OpenControlNodes(elementNode))
return false;
164 double value = XMLParser::GetNodeValueDouble(elementNode,
"Value");
A control element that provides a constant value.
virtual bool ShowForm(wxWindow *parent, Element *element, wxWindow *workspace=nullptr)
Show element data form.
virtual bool UpdateText()
Update the OpenGL text in the element (if present).
virtual void Rotate(bool clockwise=true)
Rotate the element.
virtual void DrawDC(GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
Draw the element using GDI+.
virtual Element * GetCopy()
Get a the element copy.
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
void SetPosition(const wxPoint2DDouble position)
Set the element position and update the rectangle.
static wxString StringFromDouble(double value, int minDecimal=1, int maxDecimals=13)
Convert a double value to string.
Class to draw text on Graphics Context using wxWidgets.
virtual GCText * GetCopy()
Get a deep text copy.
virtual void Draw(wxPoint2DDouble position, wxGraphicsContext *gc, double angle=0.0, wxColour colour= *wxBLACK) const
Draw the text in wxGraphicsContext.
virtual void SetText(wxString text)
Set correctly a new text string.
Node of a control element. This class manages the user interaction with the connection and control el...