-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinearRing.cpp
158 lines (143 loc) · 3.04 KB
/
LinearRing.cpp
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* File: LinearRing.cpp
* Author: tomko
*
* Created on 4 czerwiec 2011, 00:21
*/
#include "LinearRing.h"
#include "node.h"
#include "Coordinates.h"
#include "PolyStyle.h"
#include "Placemark.h"
#include "LineStyle.h"
#include <cairo/cairo.h>
using namespace std;
LinearRing::LinearRing()
{
init();
Coordinates* tmp = new Coordinates();
tmp->addCoordinate(0.0, 0.0, 0.0);
AddChild(tmp);
}
LinearRing::LinearRing(std::string* s) : node(s)
{
init();
}
LinearRing::LinearRing(const LinearRing& orig)
{
}
LinearRing::~LinearRing()
{
}
void LinearRing::init()
{
name = "LinearRing";
}
void LinearRing::draw(cairo_t* cr, double a_x, double b_x, double a_y, double b_y, double *color)
{
PolyStyle *ps;
double width = 1.0;
node *tmp = parent;
bool fill = true;
bool outline = false;
while (!(dynamic_cast<Placemark*> (tmp)))
{
tmp = tmp->GetParent();
}
ps = dynamic_cast<Placemark*> (tmp)->getPolystyle();
double *col = 0;
if (ps)
{
col = ps->getColor();
fill = ps->getFill();
outline = ps->getOutline();
}
if (outline)
{
LineStyle *ls = dynamic_cast<Placemark*> (tmp)->getLinestyle();
if (ls)
{
col = ls->getColor();
if (ls->getWidth()) width = ls->getWidth();
}
if (color) //domyślnie czarny
{
cairo_set_source_rgba(cr, color[0], color[1], color[2], color[3]);
}
else if (col)
{
cairo_set_source_rgba(cr, col[0], col[1], col[2], col[3]);
}
else
{
cairo_set_source_rgb(cr, 0, 0, 0);
}
}
else //rysujemy na czarno
{
if (ps)
{
col = ps->getColor();
}
if (color) // najpierw biały oznaczający puste miejsce
{
cairo_set_source_rgba(cr, color[0], color[1], color[2], color[3]);
}
else if (col)
{
cairo_set_source_rgba(cr, col[0], col[1], col[2], col[3]);
}
else //domyślny czarny
{
cairo_set_source_rgb(cr, 0, 0, 0);
}
}
double *cor;
int n = (dynamic_cast<Coordinates*> (children.front()))->getSize();
cairo_set_line_width(cr, width);
cor = (dynamic_cast<Coordinates*> (children.front()))->getCoordinates(0);
cairo_move_to(cr, a_x * (cor[0] - b_x), a_y * (cor[1] - b_y));
for (int i = 1; i < n; i++)
{
cor = (dynamic_cast<Coordinates*> (children.front()))->getCoordinates(i);
cairo_line_to(cr, a_x * (cor[0] - b_x), a_y * (cor[1] - b_y));
}
cairo_close_path(cr);
if (outline)
{
cairo_stroke_preserve(cr);
}
if (fill) //kolory fill
{
if (ps)
{
col = ps->getColor();
}
if (color) // najpierw biały oznaczający puste miejsce
{
cairo_set_source_rgba(cr, color[0], color[1], color[2], color[3]);
}
else if (col)
{
cairo_set_source_rgba(cr, col[0], col[1], col[2], col[3]);
}
else //domyślny czarny
{
cairo_set_source_rgb(cr, 0, 0, 0);
}
cairo_fill(cr);
}
else
{
if (color)
{
cairo_set_source_rgba(cr, color[0], color[1], color[2], color[3]);
cairo_fill(cr);
}
}
cairo_stroke(cr);
}
bool LinearRing::ifRemoveOlny()
{
return true;
}