summaryrefslogtreecommitdiffstats
path: root/Project/ImportForm.h
blob: 8224d3aea825fbcdc422e236b93f993ae74b9692 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef IMPORTFORM_H
#define IMPORTFORM_H

#include "base/PropertiesFormBase.h"

#include <wx/geometry.h>
#include <wx/msgdlg.h>
#include <wx/textfile.h>
#include <bitset>

class Workspace;
class Bus;
class SyncGenerator;
class Load;
class Capacitor;
class Inductor;
class IndMotor;
class Transformer;
class Line;

/**
 * @class ImportForm
 * @author Thales Lima Oliveira <thales@ufu.br>
 * @date 27/03/2018
 * @brief Form to import other programs files to PSP
 * @file ImportForm.h
 */
class ImportForm : public ImportFormBase
{
   public:
    ImportForm(wxWindow* parent, Workspace* workspace);
    virtual ~ImportForm();

    Workspace* GetWorkspace() { return m_workspace; }

   protected:
    virtual void OnButtonCancelClick(wxCommandEvent& event);
    virtual void OnButtonOKClick(wxCommandEvent& event);
    bool ImportSelectedFiles();
    Bus* GetBusFromID(std::vector<Bus*> busList, int id);

    Workspace* m_workspace = NULL;
    wxWindow* m_parent;
};

/**
 * @enum ElementType
 * @brief ID of ANAREDE's elements.
 */
enum ElementTypeAnarede {
    ANA_BUS = 1,            /**< Bus */
    ANA_GENERATOR = 4,      /**< Generator */
    ANA_LOAD = 5,           /**< Load */
    ANA_SHUNT = 6,          /**< Shunt element */
    ANA_MIT = 7,            /**< Induction motor */
    ANA_TRANSFORMER = 9,    /**< Transformer */
    ANA_LINE = 14,          /**< Power line */
    ANA_IND_LOAD = 22,      /**< Independent load */
    ANA_IND_SHUNT = 23,     /**< Independent shunt element */
    ANA_IND_GENERATOR = 24, /**< Independent generator */
};

/**
 * @class ParseAnarede
 * @author Thales Lima Oliveira <thales@ufu.br>
 * @date 27/03/2018
 * @brief Class responsible to parse ANAREDE files to import data to PSP.
 * @file ImportForm.h
 */
class ParseAnarede
{
   public:
    // Graphic files data structs
    struct Component {
        int id = 0;                        /**< Graphical ID */
        ElementTypeAnarede type = ANA_BUS; /**< Element type */
        double length = 0.0;               /**< Element lenght (only buses) */
        int rotationID = 0;                /**< Rotation ID (0, 1, 2 or 4) */
        wxPoint2DDouble position;          /**< X and Y coordinates */
        int electricalID = 0;              /**< Bus, Branch or Group electrical IDs */
        std::pair<int, int> busConnectionID[2] = {
            std::make_pair(0, 0), std::make_pair(0, 0)}; /**< In the form <graphicalBusID,electricBusID> */
        std::pair<int, int> busConnectionNode[2] = {std::make_pair(0, 0),
                                                    std::make_pair(0, 0)}; /**< In the form <graphicalBusID,nodeID> */
    };
    struct PowerLine {
        int id = 0;                         /**< Graphical ID */
        ElementTypeAnarede type = ANA_LINE; /**< Element type */
        int electricalID = 0;               /**< Bus, Branch or Group electrical IDs */
        std::pair<int, int> busConnectionID[2] = {
            std::make_pair(0, 0), std::make_pair(0, 0)}; /**< In the form <graphicalBusID,electricBusID> */
        std::pair<int, int> busConnectionNode[2] = {std::make_pair(0, 0),
                                                    std::make_pair(0, 0)}; /**< In the form <graphicalBusID,nodeID> */
        std::vector<wxPoint2DDouble> nodesPosition; /**< Coordinates of the line breaks, if any */
    };

    ParseAnarede(wxFileName lstFile, wxFileName pwfFile);
    ~ParseAnarede() {}
    bool Parse();
    std::vector<Component> GetComponents() const { return m_components; }
    std::vector<PowerLine> GetLines() const { return m_lines; }
    wxPoint2DDouble GetNodePositionFromID(Bus* bus, double scale, int nodeID);

   protected:
    bool GetLenghtAndRotationFromBusCode(wxString code, double& lenght, int& rotationID);
    wxString GetLSTLineNextValue(wxString line, int& currentPos);
    bool StrToElementType(wxString strType, ElementTypeAnarede& type);

    wxFileName m_lstFile;
    wxFileName m_pwfFile;

    std::vector<Component> m_components;
    std::vector<PowerLine> m_lines;
};

#endif  // IMPORTFORM_H