/
SVGPolygon.cpp
executable file
·108 lines (95 loc) · 2.94 KB
/
SVGPolygon.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
//------------------------------------------------------------------------------
/// Filename: SVGPolygon.cpp
/// Description: Base Class of SVG Objects
/// Authors:
/// Ralph Ankele(0931953)
/// Tutor: Manuel Weber
/// Group: 24
/// Created: 08.09.2011
/// Last change: 25.09.2011
//------------------------------------------------------------------------------
#include "SVGPolygon.h"
#include "UserInterface.h"
#include "Database.h"
#include "SVGHandler.h"
#include "Error.h"
#include <iostream>
//------------------------------------------------------------------------------
SVGPolygon::SVGPolygon(UserInterface *ui,
Database *db,
SVGHandler *svgh,
signed int id,
signed int group_id,
std::vector<Coordinates> coordinates,
std::string fill):
SVGObject(ui, db, svgh, id, group_id, coordinates),
fill_("")
{
fill_.assign(fill);
error_ = new Error();
}
//------------------------------------------------------------------------------
SVGPolygon::~SVGPolygon() throw()
{
delete error_;
}
//------------------------------------------------------------------------------
bool SVGPolygon::resize()
{
std::string str_value;
unsigned int coord_count = 0;
Coordinates *coord = new Coordinates(0,0);
std::cout << "id: " << id_ << std::endl;
for(std::vector<Coordinates>::iterator it = coordinates_.begin() + 1;
it != coordinates_.end(); ++it)
{
std::cout << "x: " << (*it).getX() << std::endl;
std::cout << "y: " << (*it).getY() << std::endl;
}
coord_count = coordinates_.size();
coordinates_.erase(coordinates_.begin()+1,coordinates_.end());
signed int y = 0;
signed int x = 0;
for(unsigned int count = 0; count < coord_count - 1; count++)
{
while(true)
{
if(ui_->getParam(" x? ", false, false, x, str_value, true))
break;
}
coord->setX(x);
while(true)
{
if(ui_->getParam(" y? ", false, false, y, str_value, true))
break;
}
coord->setY(y);
coordinates_.push_back(*coord);
}
delete coord;
return true;
}
//------------------------------------------------------------------------------
bool SVGPolygon::move(signed int x, signed int y)
{
for(std::vector<Coordinates>::iterator it = coordinates_.begin();
it != coordinates_.end(); ++it)
{
(*it).setX((*it).getX() + x);
(*it).setY((*it).getY() + y);
}
return true;
}
//------------------------------------------------------------------------------
std::string SVGPolygon::getSVGTag()
{
tag_ << "<polygon points=\"";
for (std::vector<Coordinates>::iterator it = coordinates_.begin();
it != coordinates_.end(); ++it)
{
tag_ << (*it).getX() << " " << (*it).getY() << " ";
}
tag_ << "\" " << "fill=\"" << fill_
<< "\" style=\"stroke:gray;stroke-width:1\" />";
return tag_.str();
}