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;
59void Constant::DrawDC(wxPoint2DDouble translation,
double scale, wxGraphicsContext* gc)
const
64 gc->SetPen(*wxTRANSPARENT_PEN);
65 gc->SetBrush(wxBrush(wxColour(m_selectionColour)));
66 double borderSize = (m_borderSize * 2.0 + 1.0) / scale;
67 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);
69 gc->SetPen(wxPen(wxColour(0, 0, 0, 255), 1));
70 gc->SetBrush(wxBrush(wxColour(255, 255, 255, 255)));
72 gc->DrawRectangle(m_position.m_x - m_width / 2, m_position.m_y - m_height / 2, m_width, m_height);
75 m_gcText->
Draw(m_position + wxPoint2DDouble(-m_gcText->GetWidth() / 2, -m_gcText->GetHeight() / 2), gc);
77 gc->SetPen(*wxTRANSPARENT_PEN);
78 gc->SetBrush(wxBrush(wxColour(0, 0, 0, 255)));
85 form.CenterOnParent();
86 if(form.ShowModal() == wxID_OK) {
105 for(
auto it = m_nodeList.begin(), itEnd = m_nodeList.end(); it != itEnd; ++it) {
107 node->Rotate(clockwise);
111void Constant::UpdatePoints()
113 if(m_nodeList.size() != 0) {
115 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 0));
116 }
else if(m_angle == 90.0) {
117 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(0, -m_height / 2));
118 }
else if(m_angle == 180.0) {
119 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(m_width / 2, 0));
120 }
else if(m_angle == 270.0) {
121 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(0, m_height / 2));
126void Constant::SetValue(
double value)
134 m_gcText =
new GCText(text);
136 m_width = m_gcText->GetWidth() + 6 + 2 * m_borderSize;
137 m_height = m_gcText->GetHeight() + 6 + 2 * m_borderSize;
145 copy->m_gcText = m_gcText ? m_gcText->
GetCopy() :
nullptr;
156rapidxml::xml_node<>* Constant::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
158 auto elementNode = XMLParser::AppendNode(doc, elementListNode,
"Constant");
159 XMLParser::SetNodeAttribute(doc, elementNode,
"ID", m_elementID);
161 SaveCADProperties(doc, elementNode);
162 SaveControlNodes(doc, elementNode);
165 auto value = XMLParser::AppendNode(doc, elementNode,
"Value");
166 XMLParser::SetNodeValue(doc, value, m_value);
171bool Constant::OpenElement(rapidxml::xml_node<>* elementNode)
173 if(!OpenCADProperties(elementNode))
return false;
174 if(!OpenControlNodes(elementNode))
return false;
177 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(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...