From e723b1627b3e0e2fae9909c5f815afc834fbffd8 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 20 Jan 2023 23:52:31 +0800 Subject: [PATCH] feat: single case graph render --- src/graph/graph.cc | 98 +++++++++++++++++++++++++++++++++++++++----- src/graph/graph.h | 38 ++++++++++++----- src/graph/svg/svg.cc | 4 +- src/graph/svg/svg.h | 13 ++++-- 4 files changed, 127 insertions(+), 26 deletions(-) diff --git a/src/graph/graph.cc b/src/graph/graph.cc index 8b93a61..36a6ca0 100644 --- a/src/graph/graph.cc +++ b/src/graph/graph.cc @@ -31,6 +31,22 @@ void Graph::svg_demo(Analyse::track_data_t track_data) { // // } + + auto p = Point{100, 200}; + auto rc = RawCode::unsafe_create(0x0603EDF5CAFFF5E2); + auto gc = GraphCase(p, rc, BLOCK_GAP, BLOCK_LENGTH); + + auto skin = CaseSkin(); + + auto svg = SvgGraph(2000, 2000); + + gc.render(svg, skin); + + std::cout << svg.dump() << std::endl; + + return; + + struct inner_t { uint64_t code; uint32_t layer_num; @@ -69,16 +85,6 @@ void Graph::svg_demo(Analyse::track_data_t track_data) { // std::cout << "MAIN_WIDTH = " << MAIN_WIDTH << std::endl; // std::cout << "MAIN_HEIGHT = " << MAIN_HEIGHT << std::endl; - printf(R"()", MAIN_WIDTH, MAIN_HEIGHT); - printf("\n"); - -// SvgCase test = SvgCase(); -// test.width = BLOCK_LENGTH; -// test.gap = BLOCK_GAP; -// test.left = 50; -// test.top = 100; -// test.code = layer_data[0][0].code; -// test.render(); for (uint32_t i = 0; i < layer_data.size(); ++i) { @@ -187,3 +193,75 @@ void Graph::svg_demo(Analyse::track_data_t track_data) { // } // //} + + +void GraphCase::render(SvgGraph &svg, const CaseSkin &skin) const { +// std::cout << "render begin" << std::endl; + + auto raw_code = (uint64_t)code; + + uint32_t case_width = block_width * 4 + block_gap * 5; + uint32_t case_height = block_width * 5 + block_gap * 6; + + auto skeleton = new SvgRect {start, case_width, case_height}; + skeleton->color = "pink"; + svg.insert(skeleton); + + for (int addr = 0; raw_code; ++addr, raw_code >>= 3) { + uint32_t block_x = addr % 4; + uint32_t block_y = (addr - block_x) / 4; + + // TODO: same start point + + switch (raw_code & 0b111) { + case B_1x1: + + svg.insert(new SvgRect { + { + start.x + block_x * block_width + (block_x + 1) * block_gap, + start.y + block_y * block_width + (block_y + 1) * block_gap, + }, + block_width, block_width, + }); + + break; + case B_1x2: + + svg.insert(new SvgRect { + { + start.x + block_x * block_width + (block_x + 1) * block_gap, + start.y + block_y * block_width + (block_y + 1) * block_gap, + }, + block_width * 2 + block_gap, block_width, + }); + + break; + case B_2x1: + + svg.insert(new SvgRect { + { + start.x + block_x * block_width + (block_x + 1) * block_gap, + start.y + block_y * block_width + (block_y + 1) * block_gap, + }, + block_width, block_width * 2 + block_gap, + }); + + break; + case B_2x2: + + svg.insert(new SvgRect { + { + start.x + block_x * block_width + (block_x + 1) * block_gap, + start.y + block_y * block_width + (block_y + 1) * block_gap, + }, + block_width * 2 + block_gap, block_width * 2 + block_gap, + }); + + break; + default: + continue; + } + } + + +} diff --git a/src/graph/graph.h b/src/graph/graph.h index ea9d232..32ce5d9 100644 --- a/src/graph/graph.h +++ b/src/graph/graph.h @@ -1,20 +1,20 @@ #pragma once #include "analyse.h" +#include "svg/svg.h" -//class SvgRect { -//public: -// uint64_t top; -// uint64_t left; -// uint64_t width; -// uint64_t height; -// -// // TODO: color options -// -// void to_xml() const; -// +#include "raw_code.h" + +//struct BlockOpt { +// uint32_t gap; +// uint32_t width; //}; +class CaseSkin { +public: + std::string color = "pink"; +}; + //class SvgCase { //public: // @@ -30,6 +30,22 @@ // //}; +class GraphCase { +public: + Point start; + RawCode code; + uint32_t block_gap; + uint32_t block_width; + + GraphCase(Point p, RawCode c, uint32_t gap, uint32_t width) : start(p), code(c) { + block_gap = gap; + block_width = width; + } + + void render(SvgGraph &svg, const CaseSkin &skin) const; + +}; + class Graph { public: diff --git a/src/graph/svg/svg.cc b/src/graph/svg/svg.cc index 90acabb..0d8c450 100644 --- a/src/graph/svg/svg.cc +++ b/src/graph/svg/svg.cc @@ -23,8 +23,8 @@ std::string SvgLine::dump() const { std::string SvgRect::dump() const { /// basic attributes of svg-rect std::string xml = " #include +class Point { +public: + uint64_t x; + uint64_t y; +}; + class SvgObject { public: virtual ~SvgObject() = default; @@ -42,8 +48,9 @@ public: class SvgRect : public SvgObject { public: - uint64_t top; - uint64_t left; + Point start; +// uint64_t top; +// uint64_t left; uint64_t width; uint64_t height; @@ -58,5 +65,5 @@ public: ~SvgRect() override = default; std::string dump() const override; - SvgRect(uint64_t t, uint64_t l, uint64_t w, uint64_t h) : top(t), left(l), width(w), height(h) {} + SvgRect(Point p, uint64_t w, uint64_t h) : start(p), width(w), height(h) {} };