diff options
Diffstat (limited to 'Project')
47 files changed, 439 insertions, 159 deletions
diff --git a/Project/Bus.cpp b/Project/Bus.cpp index f41b0d1..72d6412 100644 --- a/Project/Bus.cpp +++ b/Project/Bus.cpp @@ -53,7 +53,7 @@ void Bus::Draw(wxPoint2DDouble translation, double scale) const glRotated(m_angle, 0.0, 0.0, 1.0); glTranslated(-m_position.m_x, -m_position.m_y, 0.0); - glColor4d(0.0, 0.3, 1.0, 1.0); + glColor4dv(m_busColour->GetRGBA()); DrawRectangle(m_position, m_width, m_height); // Pop the old matrix back. glPopMatrix(); diff --git a/Project/Capacitor.cpp b/Project/Capacitor.cpp index 332582d..31fecc7 100644 --- a/Project/Capacitor.cpp +++ b/Project/Capacitor.cpp @@ -36,6 +36,10 @@ bool Capacitor::AddParent(Element* parent, wxPoint2DDouble position) void Capacitor::Draw(wxPoint2DDouble translation, double scale) const { + OpenGLColour* elementColour; + if(m_online) elementColour = m_onlineElementColour; + else elementColour = m_offlineElementColour; + if(m_inserted) { std::vector<wxPoint2DDouble> capPts; capPts.push_back(wxPoint2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0)); @@ -45,7 +49,7 @@ void Capacitor::Draw(wxPoint2DDouble translation, double scale) const if(m_selected) { glLineWidth(1.5 + m_borderSize * 2.0); - glColor4d(0.0, 0.5, 1.0, 0.5); + glColor4dv(m_selectionColour->GetRGBA()); DrawLine(m_pointList); @@ -65,7 +69,7 @@ void Capacitor::Draw(wxPoint2DDouble translation, double scale) const } // Draw Capacitor (layer 2). glLineWidth(1.5); - glColor4d(0.2, 0.2, 0.2, 1.0); + glColor4dv(elementColour->GetRGBA()); DrawCircle(m_pointList[0], 5.0, 10, GL_POLYGON); DrawLine(m_pointList); @@ -76,7 +80,7 @@ void Capacitor::Draw(wxPoint2DDouble translation, double scale) const glRotated(m_angle, 0.0, 0.0, 1.0); glTranslated(-m_position.m_x, -m_position.m_y, 0.0); - glColor4d(0.2, 0.2, 0.2, 1.0); + glColor4dv(elementColour->GetRGBA()); DrawLine(capPts, GL_LINES); DrawGround(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 10.0)); diff --git a/Project/Element.cpp b/Project/Element.cpp index 8ced79b..68563ca 100644 --- a/Project/Element.cpp +++ b/Project/Element.cpp @@ -1,13 +1,23 @@ #include "Element.h" -Element::Element() {} +Element::Element() +{ + m_busColour = new OpenGLColour(0.0, 0.3, 1.0, 1.0); + m_onlineElementColour = new OpenGLColour(0.2, 0.2, 0.2, 1.0); + m_offlineElementColour = new OpenGLColour(0.5, 0.5, 0.5, 1.0); + m_closedSwitchColour = new OpenGLColour(0.0, 0.4, 0.0, 1.0); + m_openedSwitchColour = new OpenGLColour(1.0, 0.1, 0.1, 1.0); + m_selectionColour = new OpenGLColour(0.0, 0.5, 1.0, 0.5); + m_powerFlowArrowColour = new OpenGLColour(1.0, 0.51, 0.0, 1.0); +} + Element::~Element() {} + void Element::SetPosition(const wxPoint2DDouble position) { m_position = position; - m_rect = - wxRect2DDouble(m_position.m_x - m_width / 2.0 - m_borderSize, m_position.m_y - m_height / 2.0 - m_borderSize, - m_width + 2.0 * m_borderSize, m_height + 2.0 * m_borderSize); + m_rect = wxRect2DDouble(m_position.m_x - m_width / 2.0 - m_borderSize, + m_position.m_y - m_height / 2.0 - m_borderSize, m_width + 2.0 * m_borderSize, m_height + 2.0 * m_borderSize); } void Element::DrawCircle(wxPoint2DDouble position, double radius, int numSegments, GLenum mode) const @@ -21,11 +31,11 @@ void Element::DrawCircle(wxPoint2DDouble position, double radius, int numSegment } void Element::DrawArc(wxPoint2DDouble position, - double radius, - double initAngle, - double finalAngle, - int numSegments, - GLenum mode) const + double radius, + double initAngle, + double finalAngle, + int numSegments, + GLenum mode) const { double initAngRad = wxDegToRad(initAngle); double finalAngRad = wxDegToRad(finalAngle); @@ -48,7 +58,7 @@ void Element::DrawTriangle(std::vector<wxPoint2DDouble> points, GLenum mode) con void Element::DrawRectangle(wxPoint2DDouble position, double width, double height, GLenum mode) const { - glBegin(mode); // TODO: GL_QUADS é obsoleto (OpenGL 3.0+), encontrar outra solução. + glBegin(mode); // TODO: GL_QUADS é obsoleto (OpenGL 3.0+), encontrar outra solução. glVertex2d(position.m_x - width / 2.0, position.m_y - height / 2.0); glVertex2d(position.m_x - width / 2.0, position.m_y + height / 2.0); glVertex2d(position.m_x + width / 2.0, position.m_y + height / 2.0); @@ -58,7 +68,7 @@ void Element::DrawRectangle(wxPoint2DDouble position, double width, double heigh void Element::DrawRectangle(wxPoint2DDouble* points, GLenum mode) const { - glBegin(mode); // TODO: GL_QUADS é obsoleto (OpenGL 3.0+), encontrar outra solução. + glBegin(mode); // TODO: GL_QUADS é obsoleto (OpenGL 3.0+), encontrar outra solução. glVertex2d(points[0].m_x, points[0].m_y); glVertex2d(points[1].m_x, points[1].m_y); glVertex2d(points[2].m_x, points[2].m_y); @@ -89,9 +99,9 @@ wxPoint2DDouble Element::RotateAtPosition(wxPoint2DDouble pointToRotate, double double radAngle = angle; if(degrees) radAngle = wxDegToRad(angle); return wxPoint2DDouble(std::cos(radAngle) * (pointToRotate.m_x - m_position.m_x) - - std::sin(radAngle) * (pointToRotate.m_y - m_position.m_y) + m_position.m_x, - std::sin(radAngle) * (pointToRotate.m_x - m_position.m_x) + - std::cos(radAngle) * (pointToRotate.m_y - m_position.m_y) + m_position.m_y); + std::sin(radAngle) * (pointToRotate.m_y - m_position.m_y) + m_position.m_x, + std::sin(radAngle) * (pointToRotate.m_x - m_position.m_x) + + std::cos(radAngle) * (pointToRotate.m_y - m_position.m_y) + m_position.m_y); } void Element::StartMove(wxPoint2DDouble position) @@ -109,31 +119,30 @@ wxPoint2DDouble Element::GetSwitchPoint(Element* parent, wxPoint2DDouble parentP // Rotate the second point (to compare). double angle = parent->GetAngle(); - secondPoint = - wxPoint2DDouble(std::cos(wxDegToRad(-angle)) * (secondPoint.m_x - parentPoint.m_x) - - std::sin(wxDegToRad(-angle)) * (secondPoint.m_y - parentPoint.m_y) + parentPoint.m_x, - std::sin(wxDegToRad(-angle)) * (secondPoint.m_x - parentPoint.m_x) + - std::cos(wxDegToRad(-angle)) * (secondPoint.m_y - parentPoint.m_y) + parentPoint.m_y); + secondPoint = wxPoint2DDouble(std::cos(wxDegToRad(-angle)) * (secondPoint.m_x - parentPoint.m_x) - + std::sin(wxDegToRad(-angle)) * (secondPoint.m_y - parentPoint.m_y) + parentPoint.m_x, + std::sin(wxDegToRad(-angle)) * (secondPoint.m_x - parentPoint.m_x) + + std::cos(wxDegToRad(-angle)) * (secondPoint.m_y - parentPoint.m_y) + parentPoint.m_y); // Rotate if(secondPoint.m_y > parentPoint.m_y) angle -= 180.0; return wxPoint2DDouble(std::cos(wxDegToRad(angle)) * (swPoint.m_x - parentPoint.m_x) - - std::sin(wxDegToRad(angle)) * (swPoint.m_y - parentPoint.m_y) + parentPoint.m_x, - std::sin(wxDegToRad(angle)) * (swPoint.m_x - parentPoint.m_x) + - std::cos(wxDegToRad(angle)) * (swPoint.m_y - parentPoint.m_y) + parentPoint.m_y); + std::sin(wxDegToRad(angle)) * (swPoint.m_y - parentPoint.m_y) + parentPoint.m_x, + std::sin(wxDegToRad(angle)) * (swPoint.m_x - parentPoint.m_x) + + std::cos(wxDegToRad(angle)) * (swPoint.m_y - parentPoint.m_y) + parentPoint.m_y); } wxPoint2DDouble Element::WorldToScreen(wxPoint2DDouble translation, double scale, double offsetX, double offsetY) const { return wxPoint2DDouble(m_position.m_x + offsetX + translation.m_x, m_position.m_y + offsetY + translation.m_y) * - scale; + scale; } wxPoint2DDouble Element::WorldToScreen(wxPoint2DDouble position, - wxPoint2DDouble translation, - double scale, - double offsetX, - double offsetY) const + wxPoint2DDouble translation, + double scale, + double offsetX, + double offsetY) const { return wxPoint2DDouble(position.m_x + offsetX + translation.m_x, position.m_y + offsetY + translation.m_y) * scale; } @@ -147,14 +156,14 @@ void Element::DrawPoint(wxPoint2DDouble position, double size) const } bool Element::RotatedRectanglesIntersects(wxRect2DDouble rect1, - wxRect2DDouble rect2, - double angle1, - double angle2) const + wxRect2DDouble rect2, + double angle1, + double angle2) const { - wxPoint2DDouble rect1Corners[4] = {rect1.GetLeftTop(), rect1.GetLeftBottom(), rect1.GetRightBottom(), - rect1.GetRightTop()}; - wxPoint2DDouble rect2Corners[4] = {rect2.GetLeftTop(), rect2.GetLeftBottom(), rect2.GetRightBottom(), - rect2.GetRightTop()}; + wxPoint2DDouble rect1Corners[4] = { rect1.GetLeftTop(), rect1.GetLeftBottom(), rect1.GetRightBottom(), + rect1.GetRightTop() }; + wxPoint2DDouble rect2Corners[4] = { rect2.GetLeftTop(), rect2.GetLeftBottom(), rect2.GetRightBottom(), + rect2.GetRightTop() }; wxPoint2DDouble rect1Center(rect1.m_x + rect1.m_width / 2.0, rect1.m_y + rect1.m_height / 2.0); wxPoint2DDouble rect2Center(rect2.m_x + rect2.m_width / 2.0, rect2.m_y + rect2.m_height / 2.0); @@ -163,28 +172,26 @@ bool Element::RotatedRectanglesIntersects(wxRect2DDouble rect1, double radAngle2 = wxDegToRad(angle2); for(int i = 0; i < 4; i++) { - rect1Corners[i] = - wxPoint2DDouble(std::cos(radAngle1) * (rect1Corners[i].m_x - rect1Center.m_x) - - std::sin(radAngle1) * (rect1Corners[i].m_y - rect1Center.m_y) + rect1Center.m_x, - std::sin(radAngle1) * (rect1Corners[i].m_x - rect1Center.m_x) + - std::cos(radAngle1) * (rect1Corners[i].m_y - rect1Center.m_y) + rect1Center.m_y); - - rect2Corners[i] = - wxPoint2DDouble(std::cos(radAngle2) * (rect2Corners[i].m_x - rect2Center.m_x) - - std::sin(radAngle2) * (rect2Corners[i].m_y - rect2Center.m_y) + rect2Center.m_x, - std::sin(radAngle2) * (rect2Corners[i].m_x - rect2Center.m_x) + - std::cos(radAngle2) * (rect2Corners[i].m_y - rect2Center.m_y) + rect2Center.m_y); + rect1Corners[i] = wxPoint2DDouble(std::cos(radAngle1) * (rect1Corners[i].m_x - rect1Center.m_x) - + std::sin(radAngle1) * (rect1Corners[i].m_y - rect1Center.m_y) + rect1Center.m_x, + std::sin(radAngle1) * (rect1Corners[i].m_x - rect1Center.m_x) + + std::cos(radAngle1) * (rect1Corners[i].m_y - rect1Center.m_y) + rect1Center.m_y); + + rect2Corners[i] = wxPoint2DDouble(std::cos(radAngle2) * (rect2Corners[i].m_x - rect2Center.m_x) - + std::sin(radAngle2) * (rect2Corners[i].m_y - rect2Center.m_y) + rect2Center.m_x, + std::sin(radAngle2) * (rect2Corners[i].m_x - rect2Center.m_x) + + std::cos(radAngle2) * (rect2Corners[i].m_y - rect2Center.m_y) + rect2Center.m_y); } //[Ref] http://www.gamedev.net/page/resources/_/technical/game-programming/2d-rotated-rectangle-collision-r2604 // Find the rectangles axis to project - wxPoint2DDouble axis[4] = {rect1Corners[3] - rect1Corners[0], rect1Corners[3] - rect1Corners[2], - rect2Corners[3] - rect2Corners[0], rect2Corners[3] - rect2Corners[2]}; + wxPoint2DDouble axis[4] = { rect1Corners[3] - rect1Corners[0], rect1Corners[3] - rect1Corners[2], + rect2Corners[3] - rect2Corners[0], rect2Corners[3] - rect2Corners[2] }; // Calculate the projected points to each axis - wxPoint2DDouble rect1ProjPts[4][4]; // [axis][corner] - wxPoint2DDouble rect2ProjPts[4][4]; // [axis][corner] + wxPoint2DDouble rect1ProjPts[4][4]; // [axis][corner] + wxPoint2DDouble rect2ProjPts[4][4]; // [axis][corner] for(int i = 0; i < 4; i++) { double den = axis[i].m_x * axis[i].m_x + axis[i].m_y * axis[i].m_y; for(int j = 0; j < 4; j++) { @@ -197,8 +204,8 @@ bool Element::RotatedRectanglesIntersects(wxRect2DDouble rect1, } // Calculate the scalar value to identify the max and min values on projections - double rect1Scalar[4][4]; //[axis][corner] - double rect2Scalar[4][4]; //[axis][corner] + double rect1Scalar[4][4]; //[axis][corner] + double rect2Scalar[4][4]; //[axis][corner] for(int i = 0; i < 4; i++) { for(int j = 0; j < 4; j++) { rect1Scalar[i][j] = rect1ProjPts[i][j].m_x * axis[i].m_x + rect1ProjPts[i][j].m_y * axis[i].m_y; @@ -237,10 +244,10 @@ bool Element::RotatedRectanglesIntersects(wxRect2DDouble rect1, void Element::UpdateSwitches() { // General method, to one switch only. - wxPoint2DDouble swCenter = wxPoint2DDouble((m_pointList[0].m_x + m_pointList[1].m_x) / 2.0, - (m_pointList[0].m_y + m_pointList[1].m_y) / 2.0); - m_switchRect[0] = wxRect2DDouble(swCenter.m_x - m_switchSize / 2.0, swCenter.m_y - m_switchSize / 2.0, m_switchSize, - m_switchSize); + wxPoint2DDouble swCenter = wxPoint2DDouble( + (m_pointList[0].m_x + m_pointList[1].m_x) / 2.0, (m_pointList[0].m_y + m_pointList[1].m_y) / 2.0); + m_switchRect[0] = wxRect2DDouble( + swCenter.m_x - m_switchSize / 2.0, swCenter.m_y - m_switchSize / 2.0, m_switchSize, m_switchSize); } void Element::DrawSwitches() const @@ -250,20 +257,20 @@ void Element::DrawSwitches() const Element* parent = *it; if(parent) { if(m_online) { - glColor4d(0.0, 0.4, 0.0, 1.0); // green + glColor4dv(m_closedSwitchColour->GetRGBA()); } else { - glColor4d(1.0, 0.1, 0.1, 1.0); // red + glColor4dv(m_openedSwitchColour->GetRGBA()); } glPushMatrix(); glTranslated(m_switchRect[i].GetPosition().m_x + m_switchSize / 2.0, - m_switchRect[i].GetPosition().m_y + m_switchSize / 2.0, 0.0); + m_switchRect[i].GetPosition().m_y + m_switchSize / 2.0, 0.0); glRotated(parent->GetAngle(), 0.0, 0.0, 1.0); glTranslated(-m_switchRect[i].GetPosition().m_x - m_switchSize / 2.0, - -m_switchRect[i].GetPosition().m_y - m_switchSize / 2.0, 0.0); + -m_switchRect[i].GetPosition().m_y - m_switchSize / 2.0, 0.0); DrawRectangle(m_switchRect[i].GetPosition() + wxPoint2DDouble(m_switchSize / 2.0, m_switchSize / 2.0), - m_switchSize, m_switchSize); + m_switchSize, m_switchSize); glPopMatrix(); } @@ -310,8 +317,8 @@ void Element::CalculateBoundaries(wxPoint2DDouble& leftUp, wxPoint2DDouble& righ // Check rect corners boundaries. // Get rectangle corners - wxPoint2DDouble rectCorner[4] = {m_rect.GetLeftTop(), m_rect.GetLeftBottom(), m_rect.GetRightBottom(), - m_rect.GetRightTop()}; + wxPoint2DDouble rectCorner[4] = { m_rect.GetLeftTop(), m_rect.GetLeftBottom(), m_rect.GetRightBottom(), + m_rect.GetRightTop() }; // Rotate corners. for(int i = 0; i < 4; ++i) { rectCorner[i] = RotateAtPosition(rectCorner[i], m_angle); @@ -390,7 +397,7 @@ wxString Element::StringFromDouble(double value, int minDecimal) void Element::CalculatePowerFlowPts(std::vector<wxPoint2DDouble> edges) { - double arrowRate = 100.0; // One arrow to each "arrowRate" distance in pixels. + double arrowRate = 100.0; // One arrow to each "arrowRate" distance in pixels. if(edges.size() < 2) return; @@ -413,7 +420,7 @@ void Element::CalculatePowerFlowPts(std::vector<wxPoint2DDouble> edges) for(int i = 0; i < numArrows; i++) { wxPoint2DDouble arrowCenter(pt1.m_x + ((rotPt2.m_x - pt1.m_x) / double(numArrows + 1)) * double(i + 1), - pt1.m_y + ((rotPt2.m_y - pt1.m_y) / double(numArrows + 1)) * double(i + 1)); + pt1.m_y + ((rotPt2.m_y - pt1.m_y) / double(numArrows + 1)) * double(i + 1)); std::vector<wxPoint2DDouble> triPts; triPts.push_back(arrowCenter + wxPoint2DDouble(5.0, 0.0)); @@ -434,8 +441,25 @@ void Element::CalculatePowerFlowPts(std::vector<wxPoint2DDouble> edges) void Element::DrawPowerFlowPts() const { - glColor4d(1.0, 0.51, 0.0, 1.0); - for(int i = 0; i < (int)m_powerFlowArrow.size(); i++) { - DrawTriangle(m_powerFlowArrow[i]); + if(m_online) { + glColor4dv(m_powerFlowArrowColour->GetRGBA()); + for(int i = 0; i < (int)m_powerFlowArrow.size(); i++) { + DrawTriangle(m_powerFlowArrow[i]); + } + } +} + +void Element::ReplaceParent(Element* oldParent, Element* newParent) +{ + for(int i = 0; i < (int)m_parentList.size(); i++) { + if(m_parentList[i] == oldParent) m_parentList[i] = newParent; } } + +void OpenGLColour::SetRGBA(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha) +{ + rgba[0] = red; + rgba[1] = green; + rgba[2] = blue; + rgba[3] = alpha; +} diff --git a/Project/Element.h b/Project/Element.h index 512fc8f..0dd7dea 100644 --- a/Project/Element.h +++ b/Project/Element.h @@ -82,6 +82,19 @@ struct SwitchingData { std::vector<double> swTime; }; +class OpenGLColour +{ +public: + OpenGLColour() {} + OpenGLColour(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha) { SetRGBA(red, green, blue, alpha); } + virtual ~OpenGLColour() {} + void SetRGBA(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha); + GLdouble* GetRGBA() const { return rgba; } + +protected: + GLdouble* rgba = new GLdouble(4); +}; + class Element { public: @@ -111,7 +124,7 @@ public: bool IsPickboxShown() const { return m_showPickbox; } bool IsOnline() const { return m_online; } virtual std::vector<wxPoint2DDouble> GetPointList() const { return m_pointList; } - + // Pure-virtuals methods virtual bool AddParent(Element* parent, wxPoint2DDouble position) = 0; virtual bool Contains(wxPoint2DDouble position) const = 0; @@ -129,6 +142,7 @@ public: virtual void UpdateNodes() {} virtual bool SetNodeParent(Element* parent) { return false; } virtual void RemoveParent(Element* parent) {} + virtual void ReplaceParent(Element* oldParent, Element* newParent); virtual void RotateNode(Element* parent, bool clockwise = true) {} virtual wxPoint2DDouble GetSwitchPoint(Element* parent, wxPoint2DDouble parentPoint, wxPoint2DDouble secondPoint) const; @@ -206,6 +220,14 @@ protected: double m_rotationAngle = 45.0; double m_switchSize = 10.0; + OpenGLColour* m_busColour; + OpenGLColour* m_onlineElementColour; + OpenGLColour* m_offlineElementColour; + OpenGLColour* m_closedSwitchColour; + OpenGLColour* m_openedSwitchColour; + OpenGLColour* m_selectionColour; + OpenGLColour* m_powerFlowArrowColour; + std::vector<wxRect2DDouble> m_switchRect; std::vector<std::vector<wxPoint2DDouble> > m_powerFlowArrow; diff --git a/Project/ElementDataObject.cpp b/Project/ElementDataObject.cpp index e4752ea..5df312c 100644 --- a/Project/ElementDataObject.cpp +++ b/Project/ElementDataObject.cpp @@ -1,39 +1,68 @@ #include "ElectricCalculation.h" #include "ElementDataObject.h" -ElementDataObject::ElementDataObject(Workspace* workspace) : wxDataObjectSimple(wxDataFormat("PSPCopy")) +ElementDataObject::ElementDataObject(Workspace* workspace) + : wxDataObjectSimple(wxDataFormat("PSPCopy")) { - m_allElements.GetElementsFromList(workspace->GetElementList()); - std::vector<Text*> textList = workspace->GetTextList(); - - std::vector<Bus*> busList = m_allElements.GetBusList(); - for(int i = 0; i<(int)busList.size(); i++) { - Bus* origBus = busList[i]; - if(origBus->IsSelected()) { - Bus* copyBus = new Bus(); - *copyBus = *origBus; - m_elementsLists->busList.push_back(copyBus); + if(workspace) { + m_elementsLists = new ElementsLists(); + + ElectricCalculation m_allElements; + std::vector<Element*> elementsList = workspace->GetElementList(); + std::vector<Text*> textList = workspace->GetTextList(); + + m_allElements.GetElementsFromList(elementsList); + + std::vector<Bus*> busList = m_allElements.GetBusList(); + for(int i = 0; i < (int)busList.size(); i++) { + Bus* origBus = busList[i]; + + // Set bus number. + auto data = origBus->GetEletricalData(); + data.number = i; + origBus->SetElectricalData(data); + + if(origBus->IsSelected()) { + Bus* copyBus = new Bus(); + *copyBus = *origBus; + m_elementsLists->busList.push_back(copyBus); + } + } + + std::vector<Line*> lineList = m_allElements.GetLineList(); + for(int i = 0; i < (int)lineList.size(); i++) { + Line* origLine = lineList[i]; + if(origLine->IsSelected()) { + Line* copyLine = new Line(); + *copyLine = *origLine; + m_elementsLists->lineList.push_back(copyLine); + } + } + + std::vector<Transformer*> transformerList = m_allElements.GetTransformerList(); + for(int i = 0; i < (int)transformerList.size(); i++) { + Transformer* origTransformer = transformerList[i]; + if(origTransformer->IsSelected()) { + Transformer* copyTransformer = new Transformer(); + *copyTransformer = *origTransformer; + m_elementsLists->transformerList.push_back(copyTransformer); + } } } } -ElementDataObject::~ElementDataObject() -{ -} +ElementDataObject::~ElementDataObject() {} -size_t ElementDataObject::GetDataSize() const -{ - return sizeof(void*); -} +size_t ElementDataObject::GetDataSize() const { return sizeof(void*); } bool ElementDataObject::GetDataHere(void* buf) const { - *(ElementsLists**)buf = m_elementsLists; - return true; + *(ElementsLists**)buf = m_elementsLists; + return true; } bool ElementDataObject::SetData(size_t len, const void* buf) { m_elementsLists = *(ElementsLists**)buf; - return true; + return true; } diff --git a/Project/ElementDataObject.h b/Project/ElementDataObject.h index 70aacc5..3f7155f 100644 --- a/Project/ElementDataObject.h +++ b/Project/ElementDataObject.h @@ -29,9 +29,11 @@ public: size_t GetDataSize() const override; bool GetDataHere(void* buf) const override; bool SetData(size_t len, const void* buf) override; + + ElementsLists* GetElementsLists() { return m_elementsLists; } +protected: ElementsLists* m_elementsLists; - ElectricCalculation m_allElements; }; #endif // ELEMENTDATAOBJECT_H diff --git a/Project/Inductor.cpp b/Project/Inductor.cpp index 9c13f15..4a6cf75 100644 --- a/Project/Inductor.cpp +++ b/Project/Inductor.cpp @@ -36,10 +36,14 @@ bool Inductor::AddParent(Element* parent, wxPoint2DDouble position) void Inductor::Draw(wxPoint2DDouble translation, double scale) const { + OpenGLColour* elementColour; + if(m_online) elementColour = m_onlineElementColour; + else elementColour = m_offlineElementColour; + if(m_inserted) { if(m_selected) { glLineWidth(1.5 + m_borderSize * 2.0); - glColor4d(0.0, 0.5, 1.0, 0.5); + glColor4dv(m_selectionColour->GetRGBA()); DrawLine(m_pointList); @@ -61,7 +65,7 @@ void Inductor::Draw(wxPoint2DDouble translation, double scale) const } // Draw Load (layer 2). glLineWidth(1.5); - glColor4d(0.2, 0.2, 0.2, 1.0); + glColor4dv(elementColour->GetRGBA()); DrawCircle(m_pointList[0], 5.0, 10, GL_POLYGON); DrawLine(m_pointList); @@ -72,7 +76,7 @@ void Inductor::Draw(wxPoint2DDouble translation, double scale) const glRotated(m_angle, 0.0, 0.0, 1.0); glTranslated(-m_position.m_x, -m_position.m_y, 0.0); - glColor4d(0.2, 0.2, 0.2, 1.0); + glColor4dv(elementColour->GetRGBA()); DrawArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 10.0), 10, 45, 270, 10, GL_LINE_STRIP); DrawArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 25.0), 10, 45, 315, 10, GL_LINE_STRIP); DrawArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 40.0), 10, 90, 315, 10, GL_LINE_STRIP); diff --git a/Project/Line.cpp b/Project/Line.cpp index 836ca3c..7f569fd 100644 --- a/Project/Line.cpp +++ b/Project/Line.cpp @@ -31,6 +31,10 @@ bool Line::Contains(wxPoint2DDouble position) const void Line::Draw(wxPoint2DDouble translation, double scale) const { + OpenGLColour* elementColour; + if(m_online) elementColour = m_onlineElementColour; + else elementColour = m_offlineElementColour; + std::vector<wxPoint2DDouble> pointList = m_pointList; if(!m_inserted && pointList.size() > 0) { wxPoint2DDouble secondPoint = m_position; @@ -44,7 +48,7 @@ void Line::Draw(wxPoint2DDouble translation, double scale) const // Line selected (Layer 1). if(m_selected) { glLineWidth(1.5 + m_borderSize * 2.0); - glColor4d(0.0, 0.5, 1.0, 0.5); + glColor4dv(m_selectionColour->GetRGBA()); DrawLine(pointList); // Draw nodes selection. @@ -58,7 +62,7 @@ void Line::Draw(wxPoint2DDouble translation, double scale) const // Draw line (Layer 2) glLineWidth(1.5); - glColor4d(0.2, 0.2, 0.2, 1.0); + glColor4dv(elementColour->GetRGBA()); DrawLine(pointList); if(m_inserted) { @@ -68,7 +72,7 @@ void Line::Draw(wxPoint2DDouble translation, double scale) const // Draw nodes. if(pointList.size() > 0) { - glColor4d(0.2, 0.2, 0.2, 1.0); + glColor4dv(elementColour->GetRGBA()); DrawCircle(pointList[0], 5.0, 10, GL_POLYGON); if(m_inserted) { DrawCircle(pointList[pointList.size() - 1], 5.0, 10, GL_POLYGON); diff --git a/Project/Load.cpp b/Project/Load.cpp index 9889215..d363b17 100644 --- a/Project/Load.cpp +++ b/Project/Load.cpp @@ -40,11 +40,15 @@ bool Load::AddParent(Element* parent, wxPoint2DDouble position) void Load::Draw(wxPoint2DDouble translation, double scale) const { + OpenGLColour* elementColour; + if(m_online) elementColour = m_onlineElementColour; + else elementColour = m_offlineElementColour; + if(m_inserted) { // Draw Selection (layer 1). if(m_selected) { glLineWidth(1.5 + m_borderSize * 2.0); - glColor4d(0.0, 0.5, 1.0, 0.5); + glColor4dv(m_selectionColour->GetRGBA()); std::vector<wxPoint2DDouble> selTriangPts; selTriangPts.push_back(m_triangPts[0] + m_position + wxPoint2DDouble(-m_borderSize / scale, -m_borderSize / scale)); @@ -69,7 +73,7 @@ void Load::Draw(wxPoint2DDouble translation, double scale) const glLineWidth(1.5); // Draw node. - glColor4d(0.2, 0.2, 0.2, 1.0); + glColor4dv(elementColour->GetRGBA()); DrawCircle(m_pointList[0], 5.0, 10, GL_POLYGON); DrawLine(m_pointList); @@ -85,7 +89,7 @@ void Load::Draw(wxPoint2DDouble translation, double scale) const glTranslated(m_position.m_x, m_position.m_y, 0.0); glRotated(m_angle, 0.0, 0.0, 1.0); glTranslated(-m_position.m_x, -m_position.m_y, 0.0); - glColor4d(0.2, 0.2, 0.2, 1.0); + glColor4dv(elementColour->GetRGBA()); DrawTriangle(triangPts); glPopMatrix(); } diff --git a/Project/Machines.cpp b/Project/Machines.cpp index c24deaf..c1970e6 100644 --- a/Project/Machines.cpp +++ b/Project/Machines.cpp @@ -35,12 +35,15 @@ bool Machines::AddParent(Element* parent, wxPoint2DDouble position) void Machines::Draw(wxPoint2DDouble translation, double scale) const { + OpenGLColour* elementColour; + if(m_online) elementColour = m_onlineElementColour; + else elementColour = m_offlineElementColour; + if(m_inserted) { - // Draw Selection (layer 1). if(m_selected) { glLineWidth(1.5 + m_borderSize * 2.0); - glColor4d(0.0, 0.5, 1.0, 0.5); + glColor4dv(m_selectionColour->GetRGBA()); DrawCircle(m_position, 25.0 + (m_borderSize + 1.5) / scale, 20, GL_POLYGON); DrawLine(m_pointList); @@ -52,7 +55,7 @@ void Machines::Draw(wxPoint2DDouble translation, double scale) const glLineWidth(1.5); // Draw node. - glColor4d(0.2, 0.2, 0.2, 1.0); + glColor4dv(elementColour->GetRGBA()); DrawCircle(m_pointList[0], 5.0, 10, GL_POLYGON); DrawLine(m_pointList); @@ -63,7 +66,7 @@ void Machines::Draw(wxPoint2DDouble translation, double scale) const glColor4d(1.0, 1.0, 1.0, 1.0); DrawCircle(m_position, 25.0, 20, GL_POLYGON); - glColor4d(0.2, 0.2, 0.2, 1.0); + glColor4dv(elementColour->GetRGBA()); DrawCircle(m_position, 25.0, 20); // Draw machine symbol. diff --git a/Project/Project.mk b/Project/Project.mk index e02536d..e9cbe10 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Thales -Date :=16/12/2016 +Date :=28/12/2016 CodeLitePath :="C:/Program Files/CodeLite" LinkerName :=C:/TDM-GCC-64/bin/g++.exe SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC diff --git a/Project/Release/Branch.cpp.o b/Project/Release/Branch.cpp.o Binary files differindex 0f29378..020c520 100644 --- a/Project/Release/Branch.cpp.o +++ b/Project/Release/Branch.cpp.o diff --git a/Project/Release/Bus.cpp.o b/Project/Release/Bus.cpp.o Binary files differindex 41a53aa..b6af0e2 100644 --- a/Project/Release/Bus.cpp.o +++ b/Project/Release/Bus.cpp.o diff --git a/Project/Release/BusForm.cpp.o b/Project/Release/BusForm.cpp.o Binary files differindex 917f8b4..673bcbb 100644 --- a/Project/Release/BusForm.cpp.o +++ b/Project/Release/BusForm.cpp.o diff --git a/Project/Release/Capacitor.cpp.o b/Project/Release/Capacitor.cpp.o Binary files differindex 80ab190..43d7dd5 100644 --- a/Project/Release/Capacitor.cpp.o +++ b/Project/Release/Capacitor.cpp.o diff --git a/Project/Release/ElectricCalculation.cpp.o b/Project/Release/ElectricCalculation.cpp.o Binary files differindex 3d144b8..00eba4a 100644 --- a/Project/Release/ElectricCalculation.cpp.o +++ b/Project/Release/ElectricCalculation.cpp.o diff --git a/Project/Release/Element.cpp.o b/Project/Release/Element.cpp.o Binary files differindex 3abe5a3..c809356 100644 --- a/Project/Release/Element.cpp.o +++ b/Project/Release/Element.cpp.o diff --git a/Project/Release/ElementDataObject.cpp.o b/Project/Release/ElementDataObject.cpp.o Binary files differindex f2ce58a..d4c97c2 100644 --- a/Project/Release/ElementDataObject.cpp.o +++ b/Project/Release/ElementDataObject.cpp.o diff --git a/Project/Release/ElementDataObject.cpp.o.d b/Project/Release/ElementDataObject.cpp.o.d index 3dbc853..cffe587 100644 --- a/Project/Release/ElementDataObject.cpp.o.d +++ b/Project/Release/ElementDataObject.cpp.o.d @@ -233,7 +233,9 @@ Release/ElementDataObject.cpp.o: ElementDataObject.cpp \ C:/wxWidgets-3.1.0/include/wx/msw/ole/dataobj.h \ C:/wxWidgets-3.1.0/include/wx/msw/ole/dataobj2.h Workspace.h \ C:/wxWidgets-3.1.0/include/wx/statusbr.h \ - C:/wxWidgets-3.1.0/include/wx/msw/statusbar.h WorkspaceBase.h \ + C:/wxWidgets-3.1.0/include/wx/msw/statusbar.h \ + C:/wxWidgets-3.1.0/include/wx/clipbrd.h \ + C:/wxWidgets-3.1.0/include/wx/msw/clipbrd.h WorkspaceBase.h \ C:/wxWidgets-3.1.0/include/wx/glcanvas.h \ C:/wxWidgets-3.1.0/include/wx/app.h \ C:/wxWidgets-3.1.0/include/wx/eventfilter.h \ @@ -754,6 +756,10 @@ C:/wxWidgets-3.1.0/include/wx/statusbr.h: C:/wxWidgets-3.1.0/include/wx/msw/statusbar.h: +C:/wxWidgets-3.1.0/include/wx/clipbrd.h: + +C:/wxWidgets-3.1.0/include/wx/msw/clipbrd.h: + WorkspaceBase.h: C:/wxWidgets-3.1.0/include/wx/glcanvas.h: diff --git a/Project/Release/FileHanding.cpp.o b/Project/Release/FileHanding.cpp.o Binary files differindex ba53135..e221bbb 100644 --- a/Project/Release/FileHanding.cpp.o +++ b/Project/Release/FileHanding.cpp.o diff --git a/Project/Release/GeneratorStabForm.cpp.o b/Project/Release/GeneratorStabForm.cpp.o Binary files differindex 64bbc6c..d7ed1ff 100644 --- a/Project/Release/GeneratorStabForm.cpp.o +++ b/Project/Release/GeneratorStabForm.cpp.o diff --git a/Project/Release/IndMotor.cpp.o b/Project/Release/IndMotor.cpp.o Binary files differindex 8afaa98..b59825f 100644 --- a/Project/Release/IndMotor.cpp.o +++ b/Project/Release/IndMotor.cpp.o diff --git a/Project/Release/IndMotorForm.cpp.o b/Project/Release/IndMotorForm.cpp.o Binary files differindex 1a91d40..91ac5b7 100644 --- a/Project/Release/IndMotorForm.cpp.o +++ b/Project/Release/IndMotorForm.cpp.o diff --git a/Project/Release/Inductor.cpp.o b/Project/Release/Inductor.cpp.o Binary files differindex 36cb0b0..b727883 100644 --- a/Project/Release/Inductor.cpp.o +++ b/Project/Release/Inductor.cpp.o diff --git a/Project/Release/Line.cpp.o b/Project/Release/Line.cpp.o Binary files differindex 53728d5..30a5673 100644 --- a/Project/Release/Line.cpp.o +++ b/Project/Release/Line.cpp.o diff --git a/Project/Release/LineForm.cpp.o b/Project/Release/LineForm.cpp.o Binary files differindex 3f0094a..81b3aac 100644 --- a/Project/Release/LineForm.cpp.o +++ b/Project/Release/LineForm.cpp.o diff --git a/Project/Release/Load.cpp.o b/Project/Release/Load.cpp.o Binary files differindex 8d03c53..01a0de8 100644 --- a/Project/Release/Load.cpp.o +++ b/Project/Release/Load.cpp.o diff --git a/Project/Release/LoadForm.cpp.o b/Project/Release/LoadForm.cpp.o Binary files differindex ed59b46..13ac9f0 100644 --- a/Project/Release/LoadForm.cpp.o +++ b/Project/Release/LoadForm.cpp.o diff --git a/Project/Release/Machines.cpp.o b/Project/Release/Machines.cpp.o Binary files differindex 68a1fc6..7c9984e 100644 --- a/Project/Release/Machines.cpp.o +++ b/Project/Release/Machines.cpp.o diff --git a/Project/Release/MainFrame.cpp.o b/Project/Release/MainFrame.cpp.o Binary files differindex 8db3bdb..87dd6dd 100644 --- a/Project/Release/MainFrame.cpp.o +++ b/Project/Release/MainFrame.cpp.o diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe Binary files differindex 0006acb..5ba2374 100644 --- a/Project/Release/PSP-UFU.exe +++ b/Project/Release/PSP-UFU.exe diff --git a/Project/Release/PowerFlow.cpp.o b/Project/Release/PowerFlow.cpp.o Binary files differindex 1da8b90..1f23463 100644 --- a/Project/Release/PowerFlow.cpp.o +++ b/Project/Release/PowerFlow.cpp.o diff --git a/Project/Release/ReactiveShuntElementForm.cpp.o b/Project/Release/ReactiveShuntElementForm.cpp.o Binary files differindex 58f30f9..afb73b1 100644 --- a/Project/Release/ReactiveShuntElementForm.cpp.o +++ b/Project/Release/ReactiveShuntElementForm.cpp.o diff --git a/Project/Release/Shunt.cpp.o b/Project/Release/Shunt.cpp.o Binary files differindex 4ad87ec..4b51734 100644 --- a/Project/Release/Shunt.cpp.o +++ b/Project/Release/Shunt.cpp.o diff --git a/Project/Release/SwitchingForm.cpp.o b/Project/Release/SwitchingForm.cpp.o Binary files differindex c5b64f5..627da1b 100644 --- a/Project/Release/SwitchingForm.cpp.o +++ b/Project/Release/SwitchingForm.cpp.o diff --git a/Project/Release/SyncGenerator.cpp.o b/Project/Release/SyncGenerator.cpp.o Binary files differindex 1c75992..cc55904 100644 --- a/Project/Release/SyncGenerator.cpp.o +++ b/Project/Release/SyncGenerator.cpp.o diff --git a/Project/Release/SyncMachineForm.cpp.o b/Project/Release/SyncMachineForm.cpp.o Binary files differindex 0c315ad..82245a5 100644 --- a/Project/Release/SyncMachineForm.cpp.o +++ b/Project/Release/SyncMachineForm.cpp.o diff --git a/Project/Release/SyncMotor.cpp.o b/Project/Release/SyncMotor.cpp.o Binary files differindex 7d9b66b..5414ed7 100644 --- a/Project/Release/SyncMotor.cpp.o +++ b/Project/Release/SyncMotor.cpp.o diff --git a/Project/Release/Text.cpp.o b/Project/Release/Text.cpp.o Binary files differindex cd86899..8740298 100644 --- a/Project/Release/Text.cpp.o +++ b/Project/Release/Text.cpp.o diff --git a/Project/Release/TextForm.cpp.o b/Project/Release/TextForm.cpp.o Binary files differindex 7d9de3f..7e6ca32 100644 --- a/Project/Release/TextForm.cpp.o +++ b/Project/Release/TextForm.cpp.o diff --git a/Project/Release/Transformer.cpp.o b/Project/Release/Transformer.cpp.o Binary files differindex bca1767..fc03fb8 100644 --- a/Project/Release/Transformer.cpp.o +++ b/Project/Release/Transformer.cpp.o diff --git a/Project/Release/TransformerForm.cpp.o b/Project/Release/TransformerForm.cpp.o Binary files differindex 1cff932..58d9bdb 100644 --- a/Project/Release/TransformerForm.cpp.o +++ b/Project/Release/TransformerForm.cpp.o diff --git a/Project/Release/Workspace.cpp.o b/Project/Release/Workspace.cpp.o Binary files differindex 9c5c5b2..4eaf28b 100644 --- a/Project/Release/Workspace.cpp.o +++ b/Project/Release/Workspace.cpp.o diff --git a/Project/Release/Workspace.cpp.o.d b/Project/Release/Workspace.cpp.o.d index 580e64d..f67b8e6 100644 --- a/Project/Release/Workspace.cpp.o.d +++ b/Project/Release/Workspace.cpp.o.d @@ -138,7 +138,13 @@ Release/Workspace.cpp.o: Workspace.cpp Workspace.h \ C:/wxWidgets-3.1.0/include/wx/msw/control.h \ C:/wxWidgets-3.1.0/include/wx/msw/statusbar.h \ C:/wxWidgets-3.1.0/include/wx/tooltip.h \ - C:/wxWidgets-3.1.0/include/wx/msw/tooltip.h WorkspaceBase.h \ + C:/wxWidgets-3.1.0/include/wx/msw/tooltip.h \ + C:/wxWidgets-3.1.0/include/wx/clipbrd.h \ + C:/wxWidgets-3.1.0/include/wx/dataobj.h \ + C:/wxWidgets-3.1.0/include/wx/msw/ole/dataform.h \ + C:/wxWidgets-3.1.0/include/wx/msw/ole/dataobj.h \ + C:/wxWidgets-3.1.0/include/wx/msw/ole/dataobj2.h \ + C:/wxWidgets-3.1.0/include/wx/msw/clipbrd.h WorkspaceBase.h \ C:/wxWidgets-3.1.0/include/wx/xrc/xmlres.h \ C:/wxWidgets-3.1.0/include/wx/filesys.h \ C:/wxWidgets-3.1.0/include/wx/filename.h \ @@ -239,8 +245,9 @@ Release/Workspace.cpp.o: Workspace.cpp Workspace.h \ C:/wxWidgets-3.1.0/include/wx/msw/ownerdrw.h \ C:/wxWidgets-3.1.0/include/wx/msw/menu.h Line.h LineForm.h Branch.h \ Transformer.h SyncGenerator.h Machines.h IndMotor.h SyncMotor.h Load.h \ - LoadForm.h Shunt.h Inductor.h Capacitor.h Text.h wxGLString.h \ - C:/wxWidgets-3.1.0/include/wx/wx.h C:/wxWidgets-3.1.0/include/wx/hash.h \ + LoadForm.h Shunt.h Inductor.h Capacitor.h ElementDataObject.h Text.h \ + wxGLString.h C:/wxWidgets-3.1.0/include/wx/wx.h \ + C:/wxWidgets-3.1.0/include/wx/hash.h \ C:/wxWidgets-3.1.0/include/wx/stopwatch.h \ C:/wxWidgets-3.1.0/include/wx/timer.h \ C:/wxWidgets-3.1.0/include/wx/module.h \ @@ -250,10 +257,6 @@ Release/Workspace.cpp.o: Workspace.cpp Workspace.h \ C:/wxWidgets-3.1.0/include/wx/dcmemory.h \ C:/wxWidgets-3.1.0/include/wx/dcprint.h \ C:/wxWidgets-3.1.0/include/wx/dcscreen.h \ - C:/wxWidgets-3.1.0/include/wx/dataobj.h \ - C:/wxWidgets-3.1.0/include/wx/msw/ole/dataform.h \ - C:/wxWidgets-3.1.0/include/wx/msw/ole/dataobj.h \ - C:/wxWidgets-3.1.0/include/wx/msw/ole/dataobj2.h \ C:/wxWidgets-3.1.0/include/wx/bmpbuttn.h \ C:/wxWidgets-3.1.0/include/wx/msw/bmpbuttn.h \ C:/wxWidgets-3.1.0/include/wx/checklst.h \ @@ -569,6 +572,18 @@ C:/wxWidgets-3.1.0/include/wx/tooltip.h: C:/wxWidgets-3.1.0/include/wx/msw/tooltip.h: +C:/wxWidgets-3.1.0/include/wx/clipbrd.h: + +C:/wxWidgets-3.1.0/include/wx/dataobj.h: + +C:/wxWidgets-3.1.0/include/wx/msw/ole/dataform.h: + +C:/wxWidgets-3.1.0/include/wx/msw/ole/dataobj.h: + +C:/wxWidgets-3.1.0/include/wx/msw/ole/dataobj2.h: + +C:/wxWidgets-3.1.0/include/wx/msw/clipbrd.h: + WorkspaceBase.h: C:/wxWidgets-3.1.0/include/wx/xrc/xmlres.h: @@ -803,6 +818,8 @@ Inductor.h: Capacitor.h: +ElementDataObject.h: + Text.h: wxGLString.h: @@ -829,14 +846,6 @@ C:/wxWidgets-3.1.0/include/wx/dcprint.h: C:/wxWidgets-3.1.0/include/wx/dcscreen.h: -C:/wxWidgets-3.1.0/include/wx/dataobj.h: - -C:/wxWidgets-3.1.0/include/wx/msw/ole/dataform.h: - -C:/wxWidgets-3.1.0/include/wx/msw/ole/dataobj.h: - -C:/wxWidgets-3.1.0/include/wx/msw/ole/dataobj2.h: - C:/wxWidgets-3.1.0/include/wx/bmpbuttn.h: C:/wxWidgets-3.1.0/include/wx/msw/bmpbuttn.h: diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index 42fffaf..4110317 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -92,12 +92,16 @@ bool Transformer::Contains(wxPoint2DDouble position) const void Transformer::Draw(wxPoint2DDouble translation, double scale) const { + OpenGLColour* elementColour; + if(m_online) elementColour = m_onlineElementColour; + else elementColour = m_offlineElementColour; + if(m_inserted) { // Draw selection (layer 1). if(m_selected) { // Push the current matrix on stack. glLineWidth(1.5 + m_borderSize * 2.0); - glColor4d(0.0, 0.5, 1.0, 0.5); + glColor4dv(m_selectionColour->GetRGBA()); DrawLine(m_pointList); glPushMatrix(); // Rotate the matrix around the object position. @@ -124,12 +128,12 @@ void Transformer::Draw(wxPoint2DDouble translation, double scale) const // Draw transformer (layer 2). // Transformer line glLineWidth(1.5); - glColor4d(0.2, 0.2, 0.2, 1.0); + glColor4dv(elementColour->GetRGBA()); DrawLine(m_pointList); // Draw nodes. if(m_pointList.size() > 0) { - glColor4d(0.2, 0.2, 0.2, 1.0); + glColor4dv(elementColour->GetRGBA()); DrawCircle(m_pointList[0], 5.0, 10, GL_POLYGON); if(m_inserted) { DrawCircle(m_pointList[m_pointList.size() - 1], 5.0, 10, GL_POLYGON); @@ -150,7 +154,7 @@ void Transformer::Draw(wxPoint2DDouble translation, double scale) const DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20, 20, GL_POLYGON); DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20, 20, GL_POLYGON); - glColor4d(0.2, 0.2, 0.2, 1.0); + glColor4dv(elementColour->GetRGBA()); DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20, 20); DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20, 20); diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp index bdb8211..93c846c 100644 --- a/Project/Workspace.cpp +++ b/Project/Workspace.cpp @@ -10,6 +10,7 @@ #include "Load.h" #include "Inductor.h" #include "Capacitor.h" +#include "ElementDataObject.h" #include "Text.h" @@ -158,7 +159,7 @@ void Workspace::SetViewport() void Workspace::OnLeftClickDown(wxMouseEvent& event) { bool foundElement = false; - if(m_mode == MODE_INSERT_TEXT) { + if(m_mode == MODE_INSERT_TEXT || m_mode == MODE_PASTE) { m_mode = MODE_EDIT; } else if(m_mode == MODE_INSERT || m_mode == MODE_DRAG_INSERT || m_mode == MODE_DRAG_INSERT_TEXT) { // Get the last element inserted on the list. @@ -534,7 +535,8 @@ void Workspace::OnMouseMotion(wxMouseEvent& event) } } break; - case MODE_MOVE_ELEMENT: { + case MODE_MOVE_ELEMENT: + case MODE_PASTE: { for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) { Element* element = *it; // Parent's element moving... @@ -769,6 +771,15 @@ void Workspace::OnKeyDown(wxKeyEvent& event) m_mode = MODE_INSERT; m_statusBar->SetStatusText(_("Insert Capacitor: Click on a buses, ESC to cancel.")); Redraw(); + } else if(event.GetModifiers() == wxMOD_CONTROL) { // Copy. + CopySelection(); + } + } + } break; + case 'V': { + if(!insertingElement) { + if(event.GetModifiers() == wxMOD_CONTROL) { + Paste(); } } } break; @@ -953,41 +964,53 @@ void Workspace::DeleteSelectedElements() Redraw(); } -void Workspace::Fit() +bool Workspace::GetElementsCorners(wxPoint2DDouble& leftUpCorner, + wxPoint2DDouble& rightDownCorner, + std::vector<Element*> elementList) { - if(m_elementList.size() > 0) { - wxPoint2DDouble leftUpCorner(0, 0); - wxPoint2DDouble rightDownCorner(0, 0); - m_elementList[0]->CalculateBoundaries(leftUpCorner, rightDownCorner); + if(elementList.size() == 0) return false; - for(auto it = m_elementList.begin() + 1; it != m_elementList.end(); it++) { - Element* element = *it; - wxPoint2DDouble leftUp; - wxPoint2DDouble rightDown; - element->CalculateBoundaries(leftUp, rightDown); - if(leftUp.m_x < leftUpCorner.m_x) leftUpCorner.m_x = leftUp.m_x; - if(leftUp.m_y < leftUpCorner.m_y) leftUpCorner.m_y = leftUp.m_y; - if(rightDown.m_x > rightDownCorner.m_x) rightDownCorner.m_x = rightDown.m_x; - if(rightDown.m_y > rightDownCorner.m_y) rightDownCorner.m_y = rightDown.m_y; - } + elementList[0]->CalculateBoundaries(leftUpCorner, rightDownCorner); + + for(auto it = elementList.begin() + 1, itEnd = elementList.end(); it != itEnd; it++) { + Element* element = *it; + wxPoint2DDouble leftUp; + wxPoint2DDouble rightDown; + element->CalculateBoundaries(leftUp, rightDown); + if(leftUp.m_x < leftUpCorner.m_x) leftUpCorner.m_x = leftUp.m_x; + if(leftUp.m_y < leftUpCorner.m_y) leftUpCorner.m_y = leftUp.m_y; + if(rightDown.m_x > rightDownCorner.m_x) rightDownCorner.m_x = rightDown.m_x; + if(rightDown.m_y > rightDownCorner.m_y) rightDownCorner.m_y = rightDown.m_y; + } + return true; +} + +void Workspace::Fit() +{ + wxPoint2DDouble leftUpCorner(0, 0); + wxPoint2DDouble rightDownCorner(0, 0); + std::vector<Element*> elementList = m_elementList; + for(auto it = m_textList.begin(), itEnd = m_textList.end(); it != itEnd; ++it) { + elementList.push_back(*it); + } - int width = 0.0; - int height = 0.0; - GetSize(&width, &height); + if(!GetElementsCorners(leftUpCorner, rightDownCorner, elementList)) return; + int width = 0.0; + int height = 0.0; + GetSize(&width, &height); - double scaleX = double(width) / (rightDownCorner.m_x - leftUpCorner.m_x); - double scaleY = double(height) / (rightDownCorner.m_y - leftUpCorner.m_y); + double scaleX = double(width) / (rightDownCorner.m_x - leftUpCorner.m_x); + double scaleY = double(height) / (rightDownCorner.m_y - leftUpCorner.m_y); - double scale = scaleX < scaleY ? scaleX : scaleY; - if(scale > m_camera->GetZoomMax()) scale = m_camera->GetZoomMax(); - if(scale < m_camera->GetZoomMin()) scale = m_camera->GetZoomMin(); + double scale = scaleX < scaleY ? scaleX : scaleY; + if(scale > m_camera->GetZoomMax()) scale = m_camera->GetZoomMax(); + if(scale < m_camera->GetZoomMin()) scale = m_camera->GetZoomMin(); - m_camera->SetScale(scale); + m_camera->SetScale(scale); - m_camera->StartTranslation(leftUpCorner); - m_camera->SetTranslation(wxPoint2DDouble(0, 0)); - Redraw(); - } + m_camera->StartTranslation(leftUpCorner); + m_camera->SetTranslation(wxPoint2DDouble(0, 0)); + Redraw(); } void Workspace::ValidateBusesVoltages(Element* initialBus) @@ -1062,3 +1085,137 @@ void Workspace::UpdateTextElements() text->UpdateText(100e6); } } + +void Workspace::CopySelection() +{ + ElementDataObject* dataObject = new ElementDataObject(this); + wxTheClipboard->SetData(dataObject); + wxTheClipboard->Close(); +} + +bool Workspace::Paste() +{ + if(wxTheClipboard->Open()) { + ElementDataObject dataObject(NULL); + + if(wxTheClipboard->IsSupported(wxDataFormat("PSPCopy"))) { + if(!wxTheClipboard->GetData(dataObject)) { + wxMessageDialog dialog(this, _("It was not possible to paste from clipboard."), _("Error"), + wxOK | wxCENTER | wxICON_ERROR, wxDefaultPosition); + dialog.ShowModal(); + wxTheClipboard->Close(); + return false; + } + } else { + wxTheClipboard->Close(); + return false; + } + wxTheClipboard->Close(); + + UnselectAll(); + + std::vector<Element*> pastedElements; + ElementsLists* elementsLists = dataObject.GetElementsLists(); + + // Paste buses. + auto busList = elementsLists->busList; + std::vector<Bus*> pastedBusList; // To set new parents; + for(auto it = busList.begin(), itEnd = busList.end(); it != itEnd; ++it) { + Bus* bus = *it; + Bus* copyBus = new Bus(); + *copyBus = *bus; + pastedElements.push_back(copyBus); + pastedBusList.push_back(copyBus); + m_elementList.push_back(copyBus); + } + + // Paste lines. + auto lineList = elementsLists->lineList; + for(auto it = lineList.begin(), itEnd = lineList.end(); it != itEnd; ++it) { + Line* line = *it; + Line* copyLine = new Line(); + *copyLine = *line; + + // Change the parent if copied, otherwise remove it. + for(int j = 0; j < (int)copyLine->GetParentList().size(); j++) { + Bus* currentParent = (Bus*)copyLine->GetParentList()[j]; + if(currentParent) { + int parentNumber = currentParent->GetEletricalData().number; + bool parentCopied = false; + for(int k = 0; k < (int)pastedBusList.size(); k++) { + Bus* newParent = pastedBusList[k]; + if(parentNumber == newParent->GetEletricalData().number) + copyLine->ReplaceParent(currentParent, newParent); + } + if(!parentCopied) copyLine->RemoveParent(currentParent); + } + } + + pastedElements.push_back(copyLine); + m_elementList.push_back(copyLine); + } + + // Paste transformers. + auto transformerList = elementsLists->transformerList; + for(auto it = transformerList.begin(), itEnd = transformerList.end(); it != itEnd; ++it) { + Transformer* transformer = *it; + Transformer* copyTransfomer = new Transformer(); + *copyTransfomer = *transformer; + + // Change the parent if copied, otherwise remove it. + for(int j = 0; j < (int)copyTransfomer->GetParentList().size(); j++) { + Bus* currentParent = (Bus*)copyTransfomer->GetParentList()[j]; + if(currentParent) { + int parentNumber = currentParent->GetEletricalData().number; + bool parentCopied = false; + for(int k = 0; k < (int)pastedBusList.size(); k++) { + Bus* newParent = pastedBusList[k]; + if(parentNumber == newParent->GetEletricalData().number) + copyTransfomer->ReplaceParent(currentParent, newParent); + } + if(!parentCopied) copyTransfomer->RemoveParent(currentParent); + } + } + + pastedElements.push_back(copyTransfomer); + m_elementList.push_back(copyTransfomer); + } + + // Move elements (and nodes) to the mouse position. + // The start position it's the center of the pasted objects. + wxPoint2DDouble leftUpCorner, rightDownCorner; + GetElementsCorners(leftUpCorner, rightDownCorner, pastedElements); + wxPoint2DDouble startPosition = (leftUpCorner + rightDownCorner) / 2.0; + for(auto it = pastedElements.begin(), itEnd = pastedElements.end(); it != itEnd; ++it) { + Element* element = *it; + element->StartMove(startPosition); + element->Move(m_camera->GetMousePosition()); + for(int i = 0; i < (int)element->GetParentList().size(); i++) { + Element* parent = element->GetParentList()[i]; + element->MoveNode(parent, m_camera->GetMousePosition()); + } + } + + } else { + wxMessageDialog dialog(this, _("It was not possible to paste from clipboard."), _("Error"), + wxOK | wxCENTER | wxICON_ERROR, wxDefaultPosition); + dialog.ShowModal(); + return false; + } + + Redraw(); + m_mode = MODE_PASTE; + return true; +} + +void Workspace::UnselectAll() +{ + for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; it++) { + Element* element = *it; + element->SetSelected(false); + } + for(auto it = m_textList.begin(), itEnd = m_textList.end(); it != itEnd; it++) { + Text* text = *it; + text->SetSelected(false); + } +} diff --git a/Project/Workspace.h b/Project/Workspace.h index d0ac2be..21a1a56 100644 --- a/Project/Workspace.h +++ b/Project/Workspace.h @@ -6,6 +6,7 @@ #include <wx/dcclient.h> #include <wx/msgdlg.h> #include <wx/statusbr.h> +#include <wx/clipbrd.h> #include "WorkspaceBase.h" #include "Bus.h" @@ -21,6 +22,7 @@ class SyncMotor; class Load; class Inductor; class Capacitor; +class ElementDataObject; class Text; @@ -36,7 +38,8 @@ enum WorkspaceMode { MODE_DRAG_INSERT_TEXT, MODE_INSERT, MODE_INSERT_TEXT, - MODE_SELECTION_RECT + MODE_SELECTION_RECT, + MODE_PASTE }; enum ElementID { @@ -67,6 +70,9 @@ public: WorkspaceMode GetWorkspaceMode() const { return m_mode; } Camera* GetCamera() const { return m_camera; } + void CopySelection(); + bool Paste(); + wxFileName GetSavedPath() const { return m_savedPath; } void SetName(wxString name) { m_name = name; } @@ -79,7 +85,9 @@ public: void Redraw() { m_glCanvas->Refresh(); } void RotateSelectedElements(bool clockwise = true); void DeleteSelectedElements(); + bool GetElementsCorners(wxPoint2DDouble& leftUpCorner, wxPoint2DDouble& rightDownCorner, std::vector<Element*> elementList); void Fit(); + void UnselectAll(); void ValidateBusesVoltages(Element* initialBus); void ValidateElementsVoltages(); |