From fb9de1b7935376897f1c93676ab1faeb1ea25f25 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Wed, 28 Dec 2016 20:06:41 -0200 Subject: Bus line and transformer copy/paste implemented Next step is try to generalize. Some graphical implementations in this commit. --- .codelite/.tern-port | 2 +- .codelite/PSP.session | 72 +++----- .codelite/PSP.tags | Bin 72230912 -> 72314880 bytes .codelite/compilation.db | Bin 63488 -> 63488 bytes .codelite/refactoring.db | Bin 2932736 -> 2956288 bytes Buglist.txt | 19 ++- Project/Bus.cpp | 2 +- Project/Capacitor.cpp | 10 +- Project/Element.cpp | 158 ++++++++++-------- Project/Element.h | 24 ++- Project/ElementDataObject.cpp | 71 +++++--- Project/ElementDataObject.h | 4 +- Project/Inductor.cpp | 10 +- Project/Line.cpp | 10 +- Project/Load.cpp | 10 +- Project/Machines.cpp | 11 +- Project/Project.mk | 2 +- Project/Release/Branch.cpp.o | Bin 35888 -> 35966 bytes Project/Release/Bus.cpp.o | Bin 44473 -> 44470 bytes Project/Release/BusForm.cpp.o | Bin 119004 -> 119004 bytes Project/Release/Capacitor.cpp.o | Bin 45966 -> 45989 bytes Project/Release/ElectricCalculation.cpp.o | Bin 74373 -> 74373 bytes Project/Release/Element.cpp.o | Bin 158555 -> 161886 bytes Project/Release/ElementDataObject.cpp.o | Bin 26894 -> 37405 bytes Project/Release/ElementDataObject.cpp.o.d | 8 +- Project/Release/FileHanding.cpp.o | Bin 197048 -> 197048 bytes Project/Release/GeneratorStabForm.cpp.o | Bin 104202 -> 104202 bytes Project/Release/IndMotor.cpp.o | Bin 38830 -> 38892 bytes Project/Release/IndMotorForm.cpp.o | Bin 87116 -> 87116 bytes Project/Release/Inductor.cpp.o | Bin 45871 -> 45878 bytes Project/Release/Line.cpp.o | Bin 164116 -> 164109 bytes Project/Release/LineForm.cpp.o | Bin 101112 -> 101112 bytes Project/Release/Load.cpp.o | Bin 44518 -> 44535 bytes Project/Release/LoadForm.cpp.o | Bin 86741 -> 86741 bytes Project/Release/Machines.cpp.o | Bin 40526 -> 40555 bytes Project/Release/MainFrame.cpp.o | Bin 156024 -> 155520 bytes Project/Release/PSP-UFU.exe | Bin 4431411 -> 4448474 bytes Project/Release/PowerFlow.cpp.o | Bin 43132 -> 43132 bytes Project/Release/ReactiveShuntElementForm.cpp.o | Bin 93115 -> 93115 bytes Project/Release/Shunt.cpp.o | Bin 36425 -> 36487 bytes Project/Release/SwitchingForm.cpp.o | Bin 107046 -> 107046 bytes Project/Release/SyncGenerator.cpp.o | Bin 43934 -> 44012 bytes Project/Release/SyncMachineForm.cpp.o | Bin 123729 -> 123729 bytes Project/Release/SyncMotor.cpp.o | Bin 40220 -> 40282 bytes Project/Release/Text.cpp.o | Bin 103098 -> 103176 bytes Project/Release/TextForm.cpp.o | Bin 165817 -> 165817 bytes Project/Release/Transformer.cpp.o | Bin 51523 -> 51530 bytes Project/Release/TransformerForm.cpp.o | Bin 108670 -> 108670 bytes Project/Release/Workspace.cpp.o | Bin 210774 -> 223120 bytes Project/Release/Workspace.cpp.o.d | 39 +++-- Project/Transformer.cpp | 12 +- Project/Workspace.cpp | 217 +++++++++++++++++++++---- Project/Workspace.h | 10 +- 53 files changed, 475 insertions(+), 216 deletions(-) diff --git a/.codelite/.tern-port b/.codelite/.tern-port index a6efc79..f9d7676 100644 --- a/.codelite/.tern-port +++ b/.codelite/.tern-port @@ -1 +1 @@ -49835 \ No newline at end of file +52743 \ No newline at end of file diff --git a/.codelite/PSP.session b/.codelite/PSP.session index 9d62b0b..59bfd16 100644 --- a/.codelite/PSP.session +++ b/.codelite/PSP.session @@ -1,19 +1,19 @@ - + - - + + - - + + @@ -32,70 +32,44 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + diff --git a/.codelite/PSP.tags b/.codelite/PSP.tags index 7f1ec15..bb08e8c 100644 Binary files a/.codelite/PSP.tags and b/.codelite/PSP.tags differ diff --git a/.codelite/compilation.db b/.codelite/compilation.db index 6517733..202d30b 100644 Binary files a/.codelite/compilation.db and b/.codelite/compilation.db differ diff --git a/.codelite/refactoring.db b/.codelite/refactoring.db index 451ce3e..43f6bab 100644 Binary files a/.codelite/refactoring.db and b/.codelite/refactoring.db differ diff --git a/Buglist.txt b/Buglist.txt index 6f88a40..0cdd293 100644 --- a/Buglist.txt +++ b/Buglist.txt @@ -1,31 +1,36 @@ -BUG LIST [pt-br] +BUG/TODO LIST [pt-br] PRIORIDADE 1: +-> Generalizar a classe ElementDataObject e o método Workspace::Paste (é possível?); +-> Elemento texto impactando bastante no desempenho gráfico (otimizar o algoritmo atual ou encontrar outra solução para desenhar textos no OpenGL?); +-> Texto de teste da solução do fluxo de carga sendo exibido desnecessariamente. PRIORIDADE 2: +-> Implementar uma visão rápida da solução (usar wxPopupTransientWindow ou wxPopupWindow); -> Abrir formulário pelo menu de contexto; -> Abrir o formulário do elemento após inserir o mesmo; -> Erro ao tentar inserir texto do tipo nome para elementos de ramo; -> Minimo de 1 casa decimal para os valores numéricos das barras; --> Calcular fit considerando os textos; -> Calcular posição média na opção de mover do menu ribbon considerando os textos; --> Número do nome do transformador preenchido errado; +-> Número do nome do transformador preenchido incorretamente; -> Potência reativa não está sendo distribuída apropriadamente em barras de tensão controlada caso tenha mais de uma máquina síncrona (com valores de reativos máximos/mínimos acionados); -> Dados de elementos desconectados/offline não estão sendo zerados/reiniciados; -> É necessário perguntar ao usuário se ele deseja trocar a tensão de todo o trecho conectado por linhas (quando é trocada a tensão de uma barra); -> Setas de fluxo de carga de linhas e transformadores não são atualizadas quando uma barra conectada é removida; -> Setas do fluxo de carga das máquinas elétricas não são atualizadas quando a barra conectada é rotacionada; --> Criar segurança caso um aquivo não possa ser escrito ou aberto. +-> Criar segurança caso um aquivo não possa ser escrito ou aberto; +-> Linhas dos transformadores desalinhadas quando abertos de um arquivo salvo; +-> Algoritmo de mover apresenta desempenho ruim quando possui elementos diferentes de barras (cálculos gráficos de atualização das posições dos pontos dos elementos sendo realizados desnecessariamente? Fazer um child list para evitar a busca desnecessária do parent?); +-> Remover a ferramenta Exportar/Importar. -TODO LIST: +PRIORIDADE 3: -> Inserir texto com nome da barra juntamente com barra; --> Elementos offline impressos em cinza; -> Implementar dados em relação à base de potência do elemento (e não somente do sistema); -> Implementar fluxo de carga pelo método numérico de Newton-Raphson; -> Textos vetorizados ou aumentar/diminuir a resolução das texturas de acordo com o zoom; -> Separar sistemas não conectados e resolvê-los separadamente (criar lista de barras de oscilação prioritárias). -OBJETIVOS: +OBJETIVOS GERAIS: -> Criar uma GUI amigável (wip); -> Cálculo de fluxo de carga (OK); -> Cálculo de faltas (curto simétrico e assimétrico / abertura de linhas); 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 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 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 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 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 triPts; triPts.push_back(arrowCenter + wxPoint2DDouble(5.0, 0.0)); @@ -434,8 +441,25 @@ void Element::CalculatePowerFlowPts(std::vector 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 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 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 m_switchRect; std::vector > 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 textList = workspace->GetTextList(); - - std::vector 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 elementsList = workspace->GetElementList(); + std::vector textList = workspace->GetTextList(); + + m_allElements.GetElementsFromList(elementsList); + + std::vector 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 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 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 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 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 index 0f29378..020c520 100644 Binary files a/Project/Release/Branch.cpp.o and b/Project/Release/Branch.cpp.o differ diff --git a/Project/Release/Bus.cpp.o b/Project/Release/Bus.cpp.o index 41a53aa..b6af0e2 100644 Binary files a/Project/Release/Bus.cpp.o and b/Project/Release/Bus.cpp.o differ diff --git a/Project/Release/BusForm.cpp.o b/Project/Release/BusForm.cpp.o index 917f8b4..673bcbb 100644 Binary files a/Project/Release/BusForm.cpp.o and b/Project/Release/BusForm.cpp.o differ diff --git a/Project/Release/Capacitor.cpp.o b/Project/Release/Capacitor.cpp.o index 80ab190..43d7dd5 100644 Binary files a/Project/Release/Capacitor.cpp.o and b/Project/Release/Capacitor.cpp.o differ diff --git a/Project/Release/ElectricCalculation.cpp.o b/Project/Release/ElectricCalculation.cpp.o index 3d144b8..00eba4a 100644 Binary files a/Project/Release/ElectricCalculation.cpp.o and b/Project/Release/ElectricCalculation.cpp.o differ diff --git a/Project/Release/Element.cpp.o b/Project/Release/Element.cpp.o index 3abe5a3..c809356 100644 Binary files a/Project/Release/Element.cpp.o and b/Project/Release/Element.cpp.o differ diff --git a/Project/Release/ElementDataObject.cpp.o b/Project/Release/ElementDataObject.cpp.o index f2ce58a..d4c97c2 100644 Binary files a/Project/Release/ElementDataObject.cpp.o and b/Project/Release/ElementDataObject.cpp.o differ 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 index ba53135..e221bbb 100644 Binary files a/Project/Release/FileHanding.cpp.o and b/Project/Release/FileHanding.cpp.o differ diff --git a/Project/Release/GeneratorStabForm.cpp.o b/Project/Release/GeneratorStabForm.cpp.o index 64bbc6c..d7ed1ff 100644 Binary files a/Project/Release/GeneratorStabForm.cpp.o and b/Project/Release/GeneratorStabForm.cpp.o differ diff --git a/Project/Release/IndMotor.cpp.o b/Project/Release/IndMotor.cpp.o index 8afaa98..b59825f 100644 Binary files a/Project/Release/IndMotor.cpp.o and b/Project/Release/IndMotor.cpp.o differ diff --git a/Project/Release/IndMotorForm.cpp.o b/Project/Release/IndMotorForm.cpp.o index 1a91d40..91ac5b7 100644 Binary files a/Project/Release/IndMotorForm.cpp.o and b/Project/Release/IndMotorForm.cpp.o differ diff --git a/Project/Release/Inductor.cpp.o b/Project/Release/Inductor.cpp.o index 36cb0b0..b727883 100644 Binary files a/Project/Release/Inductor.cpp.o and b/Project/Release/Inductor.cpp.o differ diff --git a/Project/Release/Line.cpp.o b/Project/Release/Line.cpp.o index 53728d5..30a5673 100644 Binary files a/Project/Release/Line.cpp.o and b/Project/Release/Line.cpp.o differ diff --git a/Project/Release/LineForm.cpp.o b/Project/Release/LineForm.cpp.o index 3f0094a..81b3aac 100644 Binary files a/Project/Release/LineForm.cpp.o and b/Project/Release/LineForm.cpp.o differ diff --git a/Project/Release/Load.cpp.o b/Project/Release/Load.cpp.o index 8d03c53..01a0de8 100644 Binary files a/Project/Release/Load.cpp.o and b/Project/Release/Load.cpp.o differ diff --git a/Project/Release/LoadForm.cpp.o b/Project/Release/LoadForm.cpp.o index ed59b46..13ac9f0 100644 Binary files a/Project/Release/LoadForm.cpp.o and b/Project/Release/LoadForm.cpp.o differ diff --git a/Project/Release/Machines.cpp.o b/Project/Release/Machines.cpp.o index 68a1fc6..7c9984e 100644 Binary files a/Project/Release/Machines.cpp.o and b/Project/Release/Machines.cpp.o differ diff --git a/Project/Release/MainFrame.cpp.o b/Project/Release/MainFrame.cpp.o index 8db3bdb..87dd6dd 100644 Binary files a/Project/Release/MainFrame.cpp.o and b/Project/Release/MainFrame.cpp.o differ diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe index 0006acb..5ba2374 100644 Binary files a/Project/Release/PSP-UFU.exe and b/Project/Release/PSP-UFU.exe differ diff --git a/Project/Release/PowerFlow.cpp.o b/Project/Release/PowerFlow.cpp.o index 1da8b90..1f23463 100644 Binary files a/Project/Release/PowerFlow.cpp.o and b/Project/Release/PowerFlow.cpp.o differ diff --git a/Project/Release/ReactiveShuntElementForm.cpp.o b/Project/Release/ReactiveShuntElementForm.cpp.o index 58f30f9..afb73b1 100644 Binary files a/Project/Release/ReactiveShuntElementForm.cpp.o and b/Project/Release/ReactiveShuntElementForm.cpp.o differ diff --git a/Project/Release/Shunt.cpp.o b/Project/Release/Shunt.cpp.o index 4ad87ec..4b51734 100644 Binary files a/Project/Release/Shunt.cpp.o and b/Project/Release/Shunt.cpp.o differ diff --git a/Project/Release/SwitchingForm.cpp.o b/Project/Release/SwitchingForm.cpp.o index c5b64f5..627da1b 100644 Binary files a/Project/Release/SwitchingForm.cpp.o and b/Project/Release/SwitchingForm.cpp.o differ diff --git a/Project/Release/SyncGenerator.cpp.o b/Project/Release/SyncGenerator.cpp.o index 1c75992..cc55904 100644 Binary files a/Project/Release/SyncGenerator.cpp.o and b/Project/Release/SyncGenerator.cpp.o differ diff --git a/Project/Release/SyncMachineForm.cpp.o b/Project/Release/SyncMachineForm.cpp.o index 0c315ad..82245a5 100644 Binary files a/Project/Release/SyncMachineForm.cpp.o and b/Project/Release/SyncMachineForm.cpp.o differ diff --git a/Project/Release/SyncMotor.cpp.o b/Project/Release/SyncMotor.cpp.o index 7d9b66b..5414ed7 100644 Binary files a/Project/Release/SyncMotor.cpp.o and b/Project/Release/SyncMotor.cpp.o differ diff --git a/Project/Release/Text.cpp.o b/Project/Release/Text.cpp.o index cd86899..8740298 100644 Binary files a/Project/Release/Text.cpp.o and b/Project/Release/Text.cpp.o differ diff --git a/Project/Release/TextForm.cpp.o b/Project/Release/TextForm.cpp.o index 7d9de3f..7e6ca32 100644 Binary files a/Project/Release/TextForm.cpp.o and b/Project/Release/TextForm.cpp.o differ diff --git a/Project/Release/Transformer.cpp.o b/Project/Release/Transformer.cpp.o index bca1767..fc03fb8 100644 Binary files a/Project/Release/Transformer.cpp.o and b/Project/Release/Transformer.cpp.o differ diff --git a/Project/Release/TransformerForm.cpp.o b/Project/Release/TransformerForm.cpp.o index 1cff932..58d9bdb 100644 Binary files a/Project/Release/TransformerForm.cpp.o and b/Project/Release/TransformerForm.cpp.o differ diff --git a/Project/Release/Workspace.cpp.o b/Project/Release/Workspace.cpp.o index 9c5c5b2..4eaf28b 100644 Binary files a/Project/Release/Workspace.cpp.o and b/Project/Release/Workspace.cpp.o differ 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 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 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 pastedElements; + ElementsLists* elementsLists = dataObject.GetElementsLists(); + + // Paste buses. + auto busList = elementsLists->busList; + std::vector 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 #include #include +#include #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 elementList); void Fit(); + void UnselectAll(); void ValidateBusesVoltages(Element* initialBus); void ValidateElementsVoltages(); -- cgit