|
|
@ -1,4 +1,5 @@ |
|
|
|
#include "graph.h" |
|
|
|
#include "common.h" |
|
|
|
|
|
|
|
#include <list> |
|
|
|
#include <iostream> |
|
|
@ -69,6 +70,14 @@ void Graph::svg_demo(Analyse::track_data_t track_data) { |
|
|
|
printf(R"(<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="%ld" height="%ld">)", 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) { |
|
|
|
|
|
|
|
uint64_t CASE_Y = CASE_GAP_Y * (i + 1) + CASE_HEIGHT * i; |
|
|
@ -81,8 +90,16 @@ void Graph::svg_demo(Analyse::track_data_t track_data) { |
|
|
|
uint64_t CASE_X = CASE_GAP_X * (j + 1) + CASE_WIDTH * j + left_offset; |
|
|
|
// printf("(%ld, %ld, %ld, %ld)\n", CASE_Y, CASE_X, CASE_WIDTH, CASE_HEIGHT);
|
|
|
|
|
|
|
|
printf(R"( <rect x="%ld" y="%ld" width="%ld" height="%ld" style="fill:pink;stroke-width:1;stroke:blue"/>)", CASE_X, CASE_Y, CASE_WIDTH, CASE_HEIGHT); |
|
|
|
printf("\n"); |
|
|
|
// printf(R"( <rect x="%ld" y="%ld" width="%ld" height="%ld" style="fill:pink;stroke-width:1;stroke:blue"/>)", CASE_X, CASE_Y, CASE_WIDTH, CASE_HEIGHT);
|
|
|
|
// printf("\n");
|
|
|
|
|
|
|
|
SvgCase tmp = SvgCase(); |
|
|
|
tmp.width = BLOCK_LENGTH; |
|
|
|
tmp.gap = BLOCK_GAP; |
|
|
|
tmp.left = CASE_X; |
|
|
|
tmp.top = CASE_Y; |
|
|
|
tmp.code = layer_data[i][j].code; |
|
|
|
tmp.render(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -92,3 +109,79 @@ void Graph::svg_demo(Analyse::track_data_t track_data) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void SvgRect::to_xml() const { |
|
|
|
// TODO: return std::string
|
|
|
|
printf(R"(<rect x="%ld" y="%ld" width="%ld" height="%ld" style="fill:pink;stroke-width:1;stroke:blue"/>)", left, top, width, height); |
|
|
|
printf("\n"); |
|
|
|
} |
|
|
|
|
|
|
|
void SvgCase::render() const { |
|
|
|
|
|
|
|
std::string result; |
|
|
|
|
|
|
|
uint64_t raw_code = code; |
|
|
|
|
|
|
|
// std::cout << "start rander" << std::endl;
|
|
|
|
|
|
|
|
auto tmp = SvgRect(); |
|
|
|
|
|
|
|
tmp.left = left; |
|
|
|
tmp.top = top; |
|
|
|
tmp.width = width * 4 + gap * 5; |
|
|
|
tmp.height = width * 5 + gap * 6; |
|
|
|
// std::cout << "main" << std::endl;
|
|
|
|
tmp.to_xml(); |
|
|
|
|
|
|
|
for (int addr = 0; raw_code; ++addr, raw_code >>= 3) { |
|
|
|
|
|
|
|
uint32_t block_x = addr % 4; |
|
|
|
uint32_t block_y = (addr - block_x) / 4; |
|
|
|
|
|
|
|
switch (raw_code & 0b111) { |
|
|
|
case B_1x1: |
|
|
|
|
|
|
|
tmp.top = width * block_y + gap * (block_y + 1) + top; |
|
|
|
tmp.left = width * block_x + gap * (block_x + 1) + left; |
|
|
|
tmp.height = width; |
|
|
|
tmp.width = width; |
|
|
|
// std::cout << "1x1" << std::endl;
|
|
|
|
tmp.to_xml(); |
|
|
|
|
|
|
|
break; |
|
|
|
case B_1x2: |
|
|
|
|
|
|
|
tmp.top = width * block_y + gap * (block_y + 1) + top; |
|
|
|
tmp.left = width * block_x + gap * (block_x + 1) + left; |
|
|
|
tmp.height = width; |
|
|
|
tmp.width = width * 2 + gap; |
|
|
|
// std::cout << "1x2" << std::endl;
|
|
|
|
tmp.to_xml(); |
|
|
|
|
|
|
|
break; |
|
|
|
case B_2x1: |
|
|
|
|
|
|
|
tmp.top = width * block_y + gap * (block_y + 1) + top; |
|
|
|
tmp.left = width * block_x + gap * (block_x + 1) + left; |
|
|
|
tmp.height = width * 2 + gap; |
|
|
|
tmp.width = width; |
|
|
|
// std::cout << "2x1" << std::endl;
|
|
|
|
tmp.to_xml(); |
|
|
|
|
|
|
|
break; |
|
|
|
case B_2x2: |
|
|
|
|
|
|
|
tmp.top = width * block_y + gap * (block_y + 1) + top; |
|
|
|
tmp.left = width * block_x + gap * (block_x + 1) + left; |
|
|
|
tmp.height = width * 2 + gap; |
|
|
|
tmp.width = width * 2 + gap; |
|
|
|
// std::cout << "2x2" << std::endl;
|
|
|
|
tmp.to_xml(); |
|
|
|
|
|
|
|
break; |
|
|
|
default: |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|