diff options
author | Thales1330 <thaleslima.ufu@gmail.com> | 2016-12-13 21:38:03 -0200 |
---|---|---|
committer | Thales1330 <thaleslima.ufu@gmail.com> | 2016-12-13 21:38:03 -0200 |
commit | e86a20525e9838f4b3962eb267ea51dce7e8fb77 (patch) | |
tree | 0d54cff51a103800e9d416a553bbb6632d894e19 | |
parent | a235ce69803fb9b276ab682f9f15ddf30849372a (diff) | |
download | PSP.git-e86a20525e9838f4b3962eb267ea51dce7e8fb77.tar.gz PSP.git-e86a20525e9838f4b3962eb267ea51dce7e8fb77.tar.xz PSP.git-e86a20525e9838f4b3962eb267ea51dce7e8fb77.zip |
Bus open implemented, capacitor buggy
-rw-r--r-- | .codelite/PSP.tags | bin | 72197120 -> 72201216 bytes | |||
-rw-r--r-- | .codelite/compilation.db | bin | 63488 -> 63488 bytes | |||
-rw-r--r-- | Buglist.txt | 7 | ||||
-rw-r--r-- | Project/Element.h | 1 | ||||
-rw-r--r-- | Project/FileHanding.cpp | 177 | ||||
-rw-r--r-- | Project/FileHanding.h | 5 | ||||
-rw-r--r-- | Project/MainFrame.cpp | 31 | ||||
-rw-r--r-- | Project/Release/FileHanding.cpp.o | bin | 122878 -> 138603 bytes | |||
-rw-r--r-- | Project/Release/MainFrame.cpp.o | bin | 154563 -> 156024 bytes | |||
-rw-r--r-- | Project/Release/PSP-UFU.exe | bin | 4371786 -> 4382049 bytes |
10 files changed, 215 insertions, 6 deletions
diff --git a/.codelite/PSP.tags b/.codelite/PSP.tags Binary files differindex 35fb7b1..a1fd681 100644 --- a/.codelite/PSP.tags +++ b/.codelite/PSP.tags diff --git a/.codelite/compilation.db b/.codelite/compilation.db Binary files differindex 5ef7953..8135f2b 100644 --- a/.codelite/compilation.db +++ b/.codelite/compilation.db diff --git a/Buglist.txt b/Buglist.txt index 68cc739..5433fb1 100644 --- a/Buglist.txt +++ b/Buglist.txt @@ -1,15 +1,18 @@ BUG LIST [pt-br] PRIORIDADE 1: - +-> Capacitor salvo sem parent é aberto com erro na posição do nó. PRIORIDADE 2: +-> 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; -> 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. +-> 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. TODO LIST: -> Implementar dados em relação à base de potência do elemento (e não somente do sistema). diff --git a/Project/Element.h b/Project/Element.h index 27933a9..cdad147 100644 --- a/Project/Element.h +++ b/Project/Element.h @@ -106,6 +106,7 @@ public: bool IsSelected() const { return m_selected; } double GetWidth() const { return m_width; } double GetAngle() const { return m_angle; } + double GetRotationAngle() const { return m_rotationAngle; } bool IsPickboxShown() const { return m_showPickbox; } bool IsOnline() const { return m_online; } virtual std::vector<wxPoint2DDouble> GetPointList() const { return m_pointList; } diff --git a/Project/FileHanding.cpp b/Project/FileHanding.cpp index 4071d4d..1586aa6 100644 --- a/Project/FileHanding.cpp +++ b/Project/FileHanding.cpp @@ -121,6 +121,11 @@ void FileHanding::SaveProject(wxFileName path) SetNodeValue(doc, height, capacitor->GetHeight()); auto angle = AppendNode(doc, cadProp, "Angle"); SetNodeValue(doc, angle, capacitor->GetAngle()); + auto nodePos = AppendNode(doc, cadProp, "NodePosition"); + auto nodePosX = AppendNode(doc, nodePos, "X"); + SetNodeValue(doc, nodePosX, capacitor->GetPointList()[0].m_x); + auto nodePosY = AppendNode(doc, nodePos, "Y"); + SetNodeValue(doc, nodePosY, capacitor->GetPointList()[0].m_y); auto parentID = AppendNode(doc, cadProp, "ParentID"); Bus* parent = (Bus*)capacitor->GetParentList()[0]; if(parent) SetNodeValue(doc, parentID, parent->GetEletricalData().number); @@ -167,6 +172,11 @@ void FileHanding::SaveProject(wxFileName path) SetNodeValue(doc, height, indMotor->GetHeight()); auto angle = AppendNode(doc, cadProp, "Angle"); SetNodeValue(doc, angle, indMotor->GetAngle()); + auto nodePos = AppendNode(doc, cadProp, "NodePosition"); + auto nodePosX = AppendNode(doc, nodePos, "X"); + SetNodeValue(doc, nodePosX, indMotor->GetPointList()[0].m_x); + auto nodePosY = AppendNode(doc, nodePos, "Y"); + SetNodeValue(doc, nodePosY, indMotor->GetPointList()[0].m_y); auto parentID = AppendNode(doc, cadProp, "ParentID"); SetNodeValue(doc, parentID, ((Bus*)indMotor->GetParentList()[0])->GetEletricalData().number); @@ -720,7 +730,7 @@ void FileHanding::SaveProject(wxFileName path) SetNodeValue(doc, swTime, swData.swTime[j]); } } //} - + //{ Text auto textsNode = AppendNode(doc, elementsNode, "TextList"); auto textList = m_workspace->GetTextList(); @@ -762,7 +772,137 @@ void FileHanding::SaveProject(wxFileName path) writeXML.close(); } -void FileHanding::OpenProject(wxFileName path) {} +bool FileHanding::OpenProject(wxFileName path) +{ + rapidxml::xml_document<> doc; + rapidxml::file<> xmlFile(path.GetFullPath()); + + doc.parse<0>(xmlFile.data()); + + auto projectNode = doc.first_node("Project"); + if(!projectNode) return false; + auto nameNode = projectNode->first_node("Name"); + if(!nameNode) return false; + m_workspace->SetName(nameNode->value()); + + // Open elements + auto elementsNode = projectNode->first_node("Elements"); + if(!elementsNode) return false; + std::vector<Element*> elementList; + std::vector<Bus*> busList; // To fill parents. + + //{ Bus + auto busListNode = elementsNode->first_node("BusList"); + if(!busListNode) return false; + auto busNode = busListNode->first_node("Bus"); + while(busNode) { + auto cadPropNode = busNode->first_node("CADProperties"); + if(!cadPropNode) return false; + + auto position = cadPropNode->first_node("Position"); + double posX = GetNodeValueDouble(position, "X"); + double posY = GetNodeValueDouble(position, "Y"); + Bus* bus = new Bus(wxPoint2DDouble(posX, posY)); + + auto size = cadPropNode->first_node("Size"); + double width = GetNodeValueDouble(size, "Width"); + double height = GetNodeValueDouble(size, "Height"); + double angle = GetNodeValueDouble(cadPropNode, "Angle"); + bus->SetWidth(width); + bus->SetHeight(height); + bus->SetPosition(bus->GetPosition()); // Update bus rectangle. + int numRot = angle / bus->GetRotationAngle(); + bool clockwise = true; + if(numRot < 0) { + numRot = std::abs(numRot); + clockwise = false; + } + for(int i = 0; i < numRot; i++) bus->Rotate(clockwise); + + BusElectricalData data = bus->GetEletricalData(); + auto electricalProp = busNode->first_node("ElectricalProperties"); + if(!electricalProp) return false; + + data.name = electricalProp->first_node("Name")->value(); + data.nominalVoltage = GetNodeValueDouble(electricalProp, "NominalVoltage"); + data.nominalVoltageUnit = (ElectricalUnit)GetAttributeValueInt(electricalProp, "NominalVoltage", "UnitID"); + data.isVoltageControlled = GetNodeValueInt(electricalProp, "IsVoltageControlled"); + data.controlledVoltage = GetNodeValueDouble(electricalProp, "ControlledVoltage"); + data.controlledVoltageUnitChoice = GetAttributeValueInt(electricalProp, "ControlledVoltage", "Choice"); + data.slackBus = GetNodeValueInt(electricalProp, "SlackBus"); + auto fault = electricalProp->first_node("Fault"); + data.hasFault = GetNodeValueInt(fault, "HasFault"); + data.faultType = (FaultData)GetNodeValueInt(fault, "Type"); + data.faultLocation = (FaultData)GetNodeValueInt(fault, "Location"); + data.faultResistance = GetNodeValueDouble(fault, "Resistance"); + data.faultReactance = GetNodeValueDouble(fault, "Reactance"); + auto stability = electricalProp->first_node("Stability"); + data.plotBus = GetNodeValueInt(stability, "Plot"); + data.stabHasFault = GetNodeValueInt(stability, "HasFault"); + data.stabFaultTime = GetNodeValueDouble(stability, "FaultTime"); + data.stabFaultLength = GetNodeValueDouble(stability, "FaultLength"); + data.stabFaultResistance = GetNodeValueDouble(stability, "FaultResistance"); + data.stabFaultReactance = GetNodeValueDouble(stability, "FaultReactance"); + + bus->SetElectricalData(data); + elementList.push_back(bus); + busList.push_back(bus); + busNode = busNode->next_sibling("Bus"); + } //} + + //{ Capacitor + auto capacitorListNode = elementsNode->first_node("CapacitorList"); + if(!capacitorListNode) return false; + auto capacitorNode = capacitorListNode->first_node("Capacitor"); + while(capacitorNode) { + Capacitor* capacitor = new Capacitor(); + + auto cadPropNode = capacitorNode->first_node("CADProperties"); + if(!cadPropNode) return false; + + auto position = cadPropNode->first_node("Position"); + double posX = GetNodeValueDouble(position, "X"); + double posY = GetNodeValueDouble(position, "Y"); + auto size = cadPropNode->first_node("Size"); + double width = GetNodeValueDouble(size, "Width"); + double height = GetNodeValueDouble(size, "Height"); + double angle = GetNodeValueDouble(cadPropNode, "Angle"); + auto nodePosition = cadPropNode->first_node("NodePosition"); + double nodePosX = GetNodeValueDouble(nodePosition, "X"); + double nodePosY = GetNodeValueDouble(nodePosition, "Y"); + int parentID = GetNodeValueInt(cadPropNode, "ParentID"); + if(parentID == -1) { + //WRONG!!!!! + Bus* parent = new Bus(); + capacitor->AddParent(parent, wxPoint2DDouble(nodePosX, nodePosY)); + capacitor->StartMove(capacitor->GetPosition()); + capacitor->Move(wxPoint2DDouble(posX, posY)); + capacitor->RemoveParent(parent); + delete parent; + } else { + Bus* parent = busList[parentID]; + capacitor->AddParent(parent, wxPoint2DDouble(nodePosX, nodePosY)); + capacitor->StartMove(capacitor->GetPosition()); + capacitor->Move(wxPoint2DDouble(posX, posY)); + } + capacitor->SetWidth(width); + capacitor->SetHeight(height); + + int numRot = angle / capacitor->GetRotationAngle(); + bool clockwise = true; + if(numRot < 0) { + numRot = std::abs(numRot); + clockwise = false; + } + for(int i = 0; i < numRot; i++) capacitor->Rotate(clockwise); + + elementList.push_back(capacitor); + capacitorNode = capacitorNode->next_sibling("Capacitor"); + } + + m_workspace->SetElementList(elementList); + return true; +} rapidxml::xml_node<>* FileHanding::AppendNode(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* parentNode, @@ -813,3 +953,36 @@ void FileHanding::SetNodeAttribute(rapidxml::xml_document<>& doc, node->append_attribute( doc.allocate_attribute(atrName, doc.allocate_string(wxString::FromCDouble(value, 13).mb_str()))); } + +double FileHanding::GetNodeValueDouble(rapidxml::xml_node<>* parent, const char* nodeName) +{ + double dValue = 0.0; + if(parent) { + auto node = parent->first_node(nodeName); + if(node) wxString(node->value()).ToCDouble(&dValue); + } + return dValue; +} + +int FileHanding::GetNodeValueInt(rapidxml::xml_node<>* parent, const char* nodeName) +{ + long iValue = -1; + if(parent) { + auto node = parent->first_node(nodeName); + if(node) wxString(node->value()).ToCLong(&iValue); + } + return (int)iValue; +} + +int FileHanding::GetAttributeValueInt(rapidxml::xml_node<>* parent, const char* nodeName, const char* atrName) +{ + long iValue = -1; + if(parent) { + auto node = parent->first_node(nodeName); + if(node){ + auto atr = node->first_attribute(atrName); + if(atr) wxString(atr->value()).ToCLong(&iValue); + } + } + return (int)iValue; +} diff --git a/Project/FileHanding.h b/Project/FileHanding.h index 5e06c3e..ba95177 100644 --- a/Project/FileHanding.h +++ b/Project/FileHanding.h @@ -24,7 +24,7 @@ public: void SetWorkspace(Workspace* workspace) { m_workspace = workspace; } void SaveProject(wxFileName path); - void OpenProject(wxFileName path); + bool OpenProject(wxFileName path); protected: Workspace* m_workspace; @@ -39,6 +39,9 @@ protected: void SetNodeAttribute(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* node, const char* atrName, wxString value); void SetNodeAttribute(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* node, const char* atrName, int value); void SetNodeAttribute(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* node, const char* atrName, double value); + double GetNodeValueDouble(rapidxml::xml_node<>* parent, const char* nodeName); + int GetNodeValueInt(rapidxml::xml_node<>* parent, const char* nodeName); + int GetAttributeValueInt(rapidxml::xml_node<>* parent, const char* nodeName, const char* atrName); }; #endif // FILEHANDING_H diff --git a/Project/MainFrame.cpp b/Project/MainFrame.cpp index 3184b8c..78b4fcd 100644 --- a/Project/MainFrame.cpp +++ b/Project/MainFrame.cpp @@ -193,7 +193,36 @@ void MainFrame::OnMoveClick(wxRibbonButtonBarEvent& event) workspace->SetWorkspaceMode(MODE_MOVE_ELEMENT); } } -void MainFrame::OnOpenClick(wxRibbonButtonBarEvent& event) {} +void MainFrame::OnOpenClick(wxRibbonButtonBarEvent& event) +{ + wxFileDialog openFileDialog( + this, _("Open PSP file"), "", "", "PSP files (*.psp)|*.psp", wxFD_OPEN | wxFD_FILE_MUST_EXIST); + if(openFileDialog.ShowModal() == wxID_CANCEL) return; + + wxFileName fileName(openFileDialog.GetPath()); + + EnableCurrentProjectRibbon(); + Workspace* newWorkspace = new Workspace(this, _("Open project"), this->GetStatusBar()); + + FileHanding fileHandling(newWorkspace); + if(fileHandling.OpenProject(fileName)) { + newWorkspace->SetSavedPath(fileName); + + m_workspaceList.push_back(newWorkspace); + + m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, true); + m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL, false); + + m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(), true); + newWorkspace->Layout(); + newWorkspace->Redraw(); + m_projectNumber++; + } else { + // TODO: fail message. + delete newWorkspace; + } +} + void MainFrame::OnPSPGuideClick(wxRibbonButtonBarEvent& event) {} void MainFrame::OnPasteClick(wxRibbonButtonBarEvent& event) {} void MainFrame::OnPowerFlowClick(wxRibbonButtonBarEvent& event) diff --git a/Project/Release/FileHanding.cpp.o b/Project/Release/FileHanding.cpp.o Binary files differindex a0665f0..d011e30 100644 --- a/Project/Release/FileHanding.cpp.o +++ b/Project/Release/FileHanding.cpp.o diff --git a/Project/Release/MainFrame.cpp.o b/Project/Release/MainFrame.cpp.o Binary files differindex 0ab62ae..e5afc1a 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 b6445c3..5133fad 100644 --- a/Project/Release/PSP-UFU.exe +++ b/Project/Release/PSP-UFU.exe |