diff options
author | Thales Lima Oliveira <thaleslima.ufu@gmail.com> | 2017-04-17 20:25:10 -0300 |
---|---|---|
committer | Thales Lima Oliveira <thaleslima.ufu@gmail.com> | 2017-04-17 20:25:10 -0300 |
commit | 0ec05e0cb396a9ef153d29f605d4a0bbeb0dc7c1 (patch) | |
tree | 35f1727f8eb959cf1c55798f7e6a2ef1d83db897 | |
parent | 52931022eb25080e33f2362c3b0bd4361f0cdb0b (diff) | |
download | PSP.git-0ec05e0cb396a9ef153d29f605d4a0bbeb0dc7c1.tar.gz PSP.git-0ec05e0cb396a9ef153d29f605d4a0bbeb0dc7c1.tar.xz PSP.git-0ec05e0cb396a9ef153d29f605d4a0bbeb0dc7c1.zip |
Connection line import under implementation
Parent line not implemented yet
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | PSP.workspace | 4 | ||||
-rw-r--r-- | Project/ConnectionLine.cpp | 4 | ||||
-rw-r--r-- | Project/ConnectionLine.h | 2 | ||||
-rw-r--r-- | Project/ControlEditor.cpp | 16 | ||||
-rw-r--r-- | Project/ControlEditor.h | 2 | ||||
-rw-r--r-- | Project/ControlElement.h | 5 | ||||
-rw-r--r-- | Project/FileHanding.cpp | 89 | ||||
-rw-r--r-- | Project/FileHanding.h | 3 | ||||
-rw-r--r-- | Project/Project.mk | 20 | ||||
-rw-r--r-- | Project/Project.txt | 2 |
11 files changed, 96 insertions, 55 deletions
@@ -1,8 +1,8 @@ .PHONY: clean All All: - @echo "----------Building project:[ Project - Debug ]----------" + @echo "----------Building project:[ Project - Release ]----------" @cd "Project" && "$(MAKE)" -f "Project.mk" clean: - @echo "----------Cleaning project:[ Project - Debug ]----------" + @echo "----------Cleaning project:[ Project - Release ]----------" @cd "Project" && "$(MAKE)" -f "Project.mk" clean diff --git a/PSP.workspace b/PSP.workspace index d5d4c55..8132425 100644 --- a/PSP.workspace +++ b/PSP.workspace @@ -2,11 +2,11 @@ <CodeLite_Workspace Name="PSP" Database="" Version="10.0.0"> <Project Name="Project" Path="Project/Project.project" Active="Yes"/> <BuildMatrix> - <WorkspaceConfiguration Name="Debug" Selected="yes"> + <WorkspaceConfiguration Name="Debug" Selected="no"> <Environment/> <Project Name="Project" ConfigName="Debug"/> </WorkspaceConfiguration> - <WorkspaceConfiguration Name="Release" Selected="no"> + <WorkspaceConfiguration Name="Release" Selected="yes"> <Environment/> <Project Name="Project" ConfigName="Release"/> </WorkspaceConfiguration> diff --git a/Project/ConnectionLine.cpp b/Project/ConnectionLine.cpp index 9b7ce40..ea04e5e 100644 --- a/Project/ConnectionLine.cpp +++ b/Project/ConnectionLine.cpp @@ -1,5 +1,9 @@ #include "ConnectionLine.h" +ConnectionLine::ConnectionLine() : ControlElement(-1) +{ +} + ConnectionLine::ConnectionLine(Node* firstNode, int id) : ControlElement(id) { diff --git a/Project/ConnectionLine.h b/Project/ConnectionLine.h index 30e0d6a..e9d238a 100644 --- a/Project/ConnectionLine.h +++ b/Project/ConnectionLine.h @@ -7,6 +7,7 @@ class ConnectionLine : public ControlElement { public: enum ConnectionLineType { ELEMENT_ELEMENT = 0, ELEMENT_LINE }; + ConnectionLine(); ConnectionLine(Node* firstNode, int id); ~ConnectionLine(); @@ -21,6 +22,7 @@ class ConnectionLine : public ControlElement virtual void SetTemporarySecondPoint(wxPoint2DDouble point) { m_tmpSndPt = point; } virtual wxPoint2DDouble GetMidPoint() const; virtual double GetOffset() const { return m_lineOffset; } + virtual void SetOffset(double offset) { m_lineOffset = offset; } virtual ConnectionLineType GetType() const { return m_type; } virtual void SetType(ConnectionLineType newType) { m_type = newType; } virtual ConnectionLine* GetParentLine() const { return m_parentLine; } diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index cb0edf3..5d64c5c 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -717,6 +717,7 @@ void ControlEditor::OnExportClick(wxCommandEvent& event) fileHandling.SaveControl(saveFileDialog.GetPath()); wxFileName fileName(saveFileDialog.GetPath()); + event.Skip(); } void ControlEditor::OnImportClick(wxCommandEvent& event) @@ -728,9 +729,20 @@ void ControlEditor::OnImportClick(wxCommandEvent& event) wxFileName fileName(openFileDialog.GetPath()); FileHanding fileHandling(this); - if(!fileHandling.OpenControl(fileName)) { + if(!fileHandling.OpenControl(fileName, m_elementList, m_connectionList)) { wxMessageDialog msgDialog(this, _("It was not possible to open the selected file."), _("Error"), wxOK | wxCENTRE | wxICON_ERROR); msgDialog.ShowModal(); } -}
\ No newline at end of file + Redraw(); + event.Skip(); +} + +/*void ControlEditor::SetElementsList(std::vector<ControlElement*> elementList) +{ + m_elementList.clear(); + for(auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) { + ControlElement* element = *it; + m_elementList.push_back(element); + } +}*/ diff --git a/Project/ControlEditor.h b/Project/ControlEditor.h index 2dd4051..eb1bc4f 100644 --- a/Project/ControlEditor.h +++ b/Project/ControlEditor.h @@ -83,8 +83,8 @@ class ControlEditor : public ControlEditorBase virtual void CheckConnections(); virtual std::vector<ConnectionLine*> GetConnectionLineList() const { return m_connectionList; } virtual std::vector<ControlElement*> GetControlElementList() const { return m_elementList; } - virtual void SetConnectionsList(std::vector<ConnectionLine*> connectionList) { m_connectionList = connectionList; } virtual void SetElementsList(std::vector<ControlElement*> elementList) { m_elementList = elementList; } + virtual void SetConnectionsList(std::vector<ConnectionLine*> connectionList) { m_connectionList = connectionList; } protected: virtual void OnImportClick(wxCommandEvent& event); diff --git a/Project/ControlElement.h b/Project/ControlElement.h index 880dd98..1cf4e0b 100644 --- a/Project/ControlElement.h +++ b/Project/ControlElement.h @@ -36,8 +36,13 @@ public: bool IsConnected() const { return m_connected; } void SetConnected(bool connected = true) { m_connected = connected; } + + int GetID() const { return m_id; } + void SetID(int id) { m_id = id; } protected: + int m_id = -1; + wxRect2DDouble m_rect; NodeType m_nodeType; diff --git a/Project/FileHanding.cpp b/Project/FileHanding.cpp index 4b87f2e..15a0dcf 100644 --- a/Project/FileHanding.cpp +++ b/Project/FileHanding.cpp @@ -1722,7 +1722,7 @@ void FileHanding::SaveControl(wxFileName path) writeXML.close(); } -bool FileHanding::OpenControl(wxFileName path) +bool FileHanding::OpenControl(wxFileName path, std::vector<ControlElement*>& ctrlElementList, std::vector<ConnectionLine*>& ctrlConnectionList) { rapidxml::xml_document<> doc; rapidxml::file<> xmlFile(path.GetFullPath()); @@ -1775,22 +1775,60 @@ bool FileHanding::OpenControl(wxFileName path) double nodePosX = GetNodeValueDouble(nodePosition, "X"); double nodePosY = GetNodeValueDouble(nodePosition, "Y"); double nodeAngle = GetNodeValueDouble(nodeN, "Angle"); - bool isConnected = (bool)GetNodeValueInt(nodeN, "IsConnected"); Node::NodeType nodeType = (Node::NodeType)GetNodeValueInt(nodeN, "Type"); Node* node = new Node(wxPoint2DDouble(nodePosX, nodePosY), nodeType, 2.0); node->SetAngle(nodeAngle); - node->SetConnected(isConnected); nodeVector.push_back(node); nodeN = nodeN->next_sibling("Node"); } exponential->SetNodeList(nodeVector); + exponential->UpdatePoints(); elementList.push_back(exponential); - + expNode = expNode->next_sibling("Exponential"); } - m_controlEditor->SetElementsList(elementList); - m_controlEditor->Redraw(); + //Connection line + auto connectionListNode = elementsNode->first_node("ConnectionList"); + if(!connectionListNode) return false; + auto connNode = connectionListNode->first_node("Connection"); + while(connNode) { + ConnectionLine* cLine = NULL; + int id = GetAttributeValueInt(connNode, "ID"); + + auto cadPropNode = connNode->first_node("CADProperties"); + if(!cadPropNode) return false; + double offset = GetNodeValueDouble(cadPropNode, "Offset"); + + auto parentList = connNode->first_node("ParentList"); + if(!parentList) return false; + auto parentNode = parentList->first_node("Parent"); + bool firstNode = true; + while(parentNode) { + int elementID = GetNodeValueInt(parentNode, "ElementID"); + int nodeID = GetNodeValueInt(parentNode, "NodeID"); + + ControlElement* element = GetControlElementFromID(elementList, elementID); + Node* node = element->GetNodeList()[nodeID]; + + if(firstNode) + cLine = new ConnectionLine(node, id); + cLine->AddParent(element); + element->AddChild(cLine); + if(!firstNode) + cLine->AppendNode(node, element); + + if(firstNode) firstNode = false; + parentNode = parentNode->next_sibling("Parent"); + } + cLine->SetOffset(offset); + cLine->UpdatePoints(); + connectionList.push_back(cLine); + connNode = connectionListNode->next_sibling("Connection"); + } + + ctrlElementList = elementList; + ctrlConnectionList = connectionList; return true; } @@ -1904,35 +1942,21 @@ void FileHanding::SaveControlElements(rapidxml::xml_document<>& doc, rapidxml::x // CAD properties auto cadProp = AppendNode(doc, cLineNode, "CADProperties"); - auto position1 = AppendNode(doc, cadProp, "Position1"); - auto posX1 = AppendNode(doc, position1, "X"); - SetNodeValue(doc, posX1, cLine->GetPointList()[0].m_x); - auto posY1 = AppendNode(doc, position1, "Y"); - SetNodeValue(doc, posY1, cLine->GetPointList()[0].m_y); - auto position2 = AppendNode(doc, cadProp, "Position2"); - auto posX2 = AppendNode(doc, position2, "X"); - SetNodeValue(doc, posX2, cLine->GetPointList()[5].m_x); - auto posY2 = AppendNode(doc, position2, "Y"); - SetNodeValue(doc, posY2, cLine->GetPointList()[5].m_y); auto offset = AppendNode(doc, cadProp, "Offset"); SetNodeValue(doc, offset, cLine->GetOffset()); - // Child list - auto childsNode = AppendNode(doc, cLineNode, "ChildList"); - auto childList = cLine->GetLineChildList(); - for(auto itC = childList.begin(), itCEnd = childList.end(); itC != itCEnd; ++itC) { - ConnectionLine* childLine = *itC; - auto childNode = AppendNode(doc, childsNode, "Child"); - SetNodeAttribute(doc, childNode, "ID", childLine->GetID()); - } - // Parent list auto parentsNode = AppendNode(doc, cLineNode, "ParentList"); auto parentList = cLine->GetParentList(); + int nodeIndex = 0; for(auto itP = parentList.begin(), itPEnd = parentList.end(); itP != itPEnd; ++itP) { Element* parent = *itP; auto parentNode = AppendNode(doc, parentsNode, "Parent"); - SetNodeAttribute(doc, parentNode, "ID", parent->GetID()); + auto elementID = AppendNode(doc, parentNode, "ElementID"); + SetNodeValue(doc, elementID, parent->GetID()); + auto nodeID = AppendNode(doc, parentNode, "NodeID"); + SetNodeValue(doc, nodeID, cLine->GetNodeList()[nodeIndex]->GetID()); + nodeIndex++; } auto parentLine = AppendNode(doc, cLineNode, "ParentLine"); @@ -1949,9 +1973,12 @@ void FileHanding::SaveControlNodes(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* nodesN, std::vector<Node*> nodeList) { + int id = 0; for(auto it = nodeList.begin(), itEnd = nodeList.end(); it != itEnd; ++it) { Node* node = *it; + node->SetID(id); auto nodeN = AppendNode(doc, nodesN, "Node"); + SetNodeAttribute(doc, nodeN, "ID", id); auto nodePosition = AppendNode(doc, nodeN, "Position"); auto posNodeX = AppendNode(doc, nodePosition, "X"); SetNodeValue(doc, posNodeX, node->GetPosition().m_x); @@ -1959,20 +1986,12 @@ void FileHanding::SaveControlNodes(rapidxml::xml_document<>& doc, SetNodeValue(doc, posNodeY, node->GetPosition().m_y); auto angle = AppendNode(doc, nodeN, "Angle"); SetNodeValue(doc, angle, node->GetAngle()); - auto isConnected = AppendNode(doc, nodeN, "IsConnected"); - SetNodeValue(doc, isConnected, node->IsConnected()); auto nodeType = AppendNode(doc, nodeN, "Type"); SetNodeValue(doc, nodeType, node->GetNodeType()); + id++; } } -// void FileHanding::SaveControlChildren(rapidxml::xml_document<>& doc, -// rapidxml::xml_node<>* childrenNode, -// std::vector<Node*> childList) -//{ -// -//} - ControlElement* FileHanding::GetControlElementFromID(std::vector<ControlElement*> elementList, int id) { for(auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) { diff --git a/Project/FileHanding.h b/Project/FileHanding.h index 8783070..28efa83 100644 --- a/Project/FileHanding.h +++ b/Project/FileHanding.h @@ -31,7 +31,7 @@ public: bool OpenProject(wxFileName path); void SaveControl(wxFileName path); - bool OpenControl(wxFileName path); + bool OpenControl(wxFileName path, std::vector<ControlElement*>& ctrlElementList, std::vector<ConnectionLine*>& ctrlConnectionList); protected: Workspace* m_workspace = NULL; @@ -54,7 +54,6 @@ protected: void SaveControlElements(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementsNode); void SaveControlNodes(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* nodesN, std::vector<Node*> nodeList); - //void SaveControlChildren(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* childrenNode, std::vector<Node*> childList); ControlElement* GetControlElementFromID(std::vector<ControlElement*> elementList, int id); }; diff --git a/Project/Project.mk b/Project/Project.mk index 117bc4c..b26a453 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -2,18 +2,18 @@ ## Auto Generated makefile by CodeLite IDE ## any manual changes will be erased ## -## Debug +## Release ProjectName :=Project -ConfigurationName :=Debug +ConfigurationName :=Release WorkspacePath :=C:/Users/NDSE-69/Documents/GitHub/PSP ProjectPath :=C:/Users/NDSE-69/Documents/GitHub/PSP/Project -IntermediateDirectory :=./Debug +IntermediateDirectory :=./Release OutDir := $(IntermediateDirectory) CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=NDSE-69 -Date :=12/04/2017 +Date :=17/04/2017 CodeLitePath :="C:/Program Files/CodeLite" LinkerName :=C:/TDM-GCC-64/bin/g++.exe SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC @@ -28,7 +28,7 @@ LibraryPathSwitch :=-L PreprocessorSwitch :=-D SourceSwitch :=-c OutputFile :=$(IntermediateDirectory)/pspufu -Preprocessors :=$(PreprocessorSwitch)UNICODE +Preprocessors :=$(PreprocessorSwitch)NDEBUG $(PreprocessorSwitch)UNICODE ObjectSwitch :=-o ArchiveOutputSwitch := PreprocessOnlySwitch :=-E @@ -52,8 +52,8 @@ LibPath := $(LibraryPathSwitch). AR := C:/TDM-GCC-64/bin/ar.exe rcu CXX := C:/TDM-GCC-64/bin/g++.exe CC := C:/TDM-GCC-64/bin/gcc.exe -CXXFLAGS := -g -O0 -Wall $(shell wx-config --cflags) $(Preprocessors) -CFLAGS := -g -O0 -Wall $(Preprocessors) +CXXFLAGS := -O2 -Wall $(shell wx-config --cflags) $(Preprocessors) +CFLAGS := -O2 -Wall $(Preprocessors) ASFLAGS := AS := C:/TDM-GCC-64/bin/as.exe @@ -89,11 +89,11 @@ $(OutputFile): $(IntermediateDirectory)/.d $(Objects) $(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions) MakeIntermediateDirs: - @$(MakeDirCommand) "./Debug" + @$(MakeDirCommand) "./Release" $(IntermediateDirectory)/.d: - @$(MakeDirCommand) "./Debug" + @$(MakeDirCommand) "./Release" PreBuild: @@ -645,6 +645,6 @@ $(IntermediateDirectory)/IOControlForm.cpp$(PreprocessSuffix): IOControlForm.cpp ## Clean ## clean: - $(RM) -r ./Debug/ + $(RM) -r ./Release/ diff --git a/Project/Project.txt b/Project/Project.txt index 70535ac..e29b621 100644 --- a/Project/Project.txt +++ b/Project/Project.txt @@ -1 +1 @@ -./Debug/main.cpp.o ./Debug/win_resources.rc.o ./Debug/ElementDataObject.cpp.o ./Debug/Element.cpp.o ./Debug/ArtMetro.cpp.o ./Debug/wxGLString.cpp.o ./Debug/MainFrame.cpp.o ./Debug/Workspace.cpp.o ./Debug/FileHanding.cpp.o ./Debug/ControlEditor.cpp.o ./Debug/Camera.cpp.o ./Debug/MainFrameBitmaps.cpp.o ./Debug/WorkspaceBitmaps.cpp.o ./Debug/BusFormBitmaps.cpp.o ./Debug/ElementFormBitmaps.cpp.o ./Debug/ControlEditorBitmaps.cpp.o ./Debug/MainFrameBase.cpp.o ./Debug/WorkspaceBase.cpp.o ./Debug/ElementForm.cpp.o ./Debug/ControlEditorBase.cpp.o ./Debug/Bus.cpp.o ./Debug/Line.cpp.o ./Debug/Transformer.cpp.o ./Debug/Machines.cpp.o ./Debug/SyncGenerator.cpp.o ./Debug/IndMotor.cpp.o ./Debug/Branch.cpp.o ./Debug/SyncMotor.cpp.o ./Debug/Shunt.cpp.o ./Debug/Load.cpp.o ./Debug/Inductor.cpp.o ./Debug/Capacitor.cpp.o ./Debug/PowerElement.cpp.o ./Debug/ElectricCalculation.cpp.o ./Debug/PowerFlow.cpp.o ./Debug/Fault.cpp.o ./Debug/Text.cpp.o ./Debug/GraphicalElement.cpp.o ./Debug/ControlElement.cpp.o ./Debug/TransferFunction.cpp.o ./Debug/ConnectionLine.cpp.o ./Debug/Sum.cpp.o ./Debug/Multiplier.cpp.o ./Debug/Limiter.cpp.o ./Debug/RateLimiter.cpp.o ./Debug/Exponential.cpp.o ./Debug/Constant.cpp.o ./Debug/Gain.cpp.o ./Debug/IOControl.cpp.o ./Debug/ControlElementContainer.cpp.o ./Debug/BusForm.cpp.o ./Debug/GeneratorStabForm.cpp.o ./Debug/LineForm.cpp.o ./Debug/SwitchingForm.cpp.o ./Debug/TransformerForm.cpp.o ./Debug/LoadForm.cpp.o ./Debug/ReactiveShuntElementForm.cpp.o ./Debug/IndMotorForm.cpp.o ./Debug/SyncMachineForm.cpp.o ./Debug/TextForm.cpp.o ./Debug/TransferFunctionForm.cpp.o ./Debug/SumForm.cpp.o ./Debug/LimiterForm.cpp.o ./Debug/RateLimiterForm.cpp.o ./Debug/ExponentialForm.cpp.o ./Debug/ConstantForm.cpp.o ./Debug/GainForm.cpp.o ./Debug/IOControlForm.cpp.o +./Release/main.cpp.o ./Release/win_resources.rc.o ./Release/ElementDataObject.cpp.o ./Release/Element.cpp.o ./Release/ArtMetro.cpp.o ./Release/wxGLString.cpp.o ./Release/MainFrame.cpp.o ./Release/Workspace.cpp.o ./Release/FileHanding.cpp.o ./Release/ControlEditor.cpp.o ./Release/Camera.cpp.o ./Release/MainFrameBitmaps.cpp.o ./Release/WorkspaceBitmaps.cpp.o ./Release/BusFormBitmaps.cpp.o ./Release/ElementFormBitmaps.cpp.o ./Release/ControlEditorBitmaps.cpp.o ./Release/MainFrameBase.cpp.o ./Release/WorkspaceBase.cpp.o ./Release/ElementForm.cpp.o ./Release/ControlEditorBase.cpp.o ./Release/Bus.cpp.o ./Release/Line.cpp.o ./Release/Transformer.cpp.o ./Release/Machines.cpp.o ./Release/SyncGenerator.cpp.o ./Release/IndMotor.cpp.o ./Release/Branch.cpp.o ./Release/SyncMotor.cpp.o ./Release/Shunt.cpp.o ./Release/Load.cpp.o ./Release/Inductor.cpp.o ./Release/Capacitor.cpp.o ./Release/PowerElement.cpp.o ./Release/ElectricCalculation.cpp.o ./Release/PowerFlow.cpp.o ./Release/Fault.cpp.o ./Release/Text.cpp.o ./Release/GraphicalElement.cpp.o ./Release/ControlElement.cpp.o ./Release/TransferFunction.cpp.o ./Release/ConnectionLine.cpp.o ./Release/Sum.cpp.o ./Release/Multiplier.cpp.o ./Release/Limiter.cpp.o ./Release/RateLimiter.cpp.o ./Release/Exponential.cpp.o ./Release/Constant.cpp.o ./Release/Gain.cpp.o ./Release/IOControl.cpp.o ./Release/ControlElementContainer.cpp.o ./Release/BusForm.cpp.o ./Release/GeneratorStabForm.cpp.o ./Release/LineForm.cpp.o ./Release/SwitchingForm.cpp.o ./Release/TransformerForm.cpp.o ./Release/LoadForm.cpp.o ./Release/ReactiveShuntElementForm.cpp.o ./Release/IndMotorForm.cpp.o ./Release/SyncMachineForm.cpp.o ./Release/TextForm.cpp.o ./Release/TransferFunctionForm.cpp.o ./Release/SumForm.cpp.o ./Release/LimiterForm.cpp.o ./Release/RateLimiterForm.cpp.o ./Release/ExponentialForm.cpp.o ./Release/ConstantForm.cpp.o ./Release/GainForm.cpp.o ./Release/IOControlForm.cpp.o |