summaryrefslogtreecommitdiffstats
path: root/Project/GraphAutoLayout.h
blob: 4d427520ca7de674028c2dbd7636b60b0f0e7aab (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
// Code based in: "Weighted graphs: generate a layout in C++"
// https://rodic.fr/blog/c-weighted-graph-layout-fruchterman-reingold/

#ifndef GRAPHAUTOLAYOUT_H
#define GRAPHAUTOLAYOUT_H

#include <cmath>
//#include <vector>
#include <wx/gdicmn.h>
#include <wx/progdlg.h>

// class ParseMatpower;
#include "ImportForm.h"

class GraphAutoLayout
{
   public:
    struct GraphLayoutNode {
        wxRealPoint position;
        wxRealPoint displacement;
    };

    struct GraphLayoutEdge {
        GraphLayoutNode &node1;
        GraphLayoutNode &node2;
        float weight;
    };

    GraphAutoLayout();
    GraphAutoLayout(std::vector<ParseMatpower::BusData*> busData, std::vector<ParseMatpower::BranchData*> branchData);
    ~GraphAutoLayout();
    
    void CalculatePositions(int iterations, double scale);

   protected:
    void AddLink(size_t index1, size_t index2, float weight = 1.f);
    void Compute(size_t iterations);

    std::vector<GraphLayoutNode> m_nodes;
    std::vector<GraphLayoutEdge> m_edges;

    std::vector<ParseMatpower::BusData*> m_busData;
    std::vector<ParseMatpower::BranchData*> m_branchData;
};

#endif  // GRAPHAUTOLAYOUT_H