-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolygonCommand.cpp
More file actions
executable file
·146 lines (131 loc) · 3.5 KB
/
PolygonCommand.cpp
File metadata and controls
executable file
·146 lines (131 loc) · 3.5 KB
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
//------------------------------------------------------------------------------
/// Filename: PolygonCommand.cpp
/// Description: Base Class for PolygonCommands
/// Authors:
/// Ralph Ankele(0931953)
/// Tutor: Manuel Weber
/// Group: 24
/// Created: 08.09.2011
/// Last change: 19.09.2011
//------------------------------------------------------------------------------
#include "PolygonCommand.h"
#include "UserInterface.h"
#include "Database.h"
#include "SVGHandler.h"
#include "SVGPolygon.h"
#include "ErrorCodes.h"
#include "Error.h"
#include <sstream>
#include <iostream>
//------------------------------------------------------------------------------
PolygonCommand::PolygonCommand(UserInterface *ui,
Database *db,
SVGHandler *svgh): Command(ui,db),
svgh_(svgh)
{
name_.assign("polygon");
error_ = new Error();
}
//------------------------------------------------------------------------------
PolygonCommand::~PolygonCommand() throw()
{
delete error_;
}
//------------------------------------------------------------------------------
bool PolygonCommand::execute()
{
signed int id, group_id, int_value;
std::string fill, str_value, id_str;
while(true)
{
while(true)
{
ui_->getParam(" id? ", false, false, int_value, id_str, false);
if(!ui_->checkIfIdExists(id_str))
break;
error_->idAlreadyExist();
}
if(ui_->stringToSignedInt(id_str, id))
break;
error_->invalidParameter();
}
readCoordinates();
ui_->getParam(" fill? ", true, false, int_value, fill, false);
while(true)
{
if(ui_->getParam(" group? ", false, false, group_id, str_value, true))
break;
}
try
{
SVGPolygon *polygon = new SVGPolygon(ui_, db_, svgh_, id, group_id,
coordinates_, fill);
db_->setSVGObject(polygon);
coordinates_.clear();
}
catch(std::bad_alloc& exception)
{
svgh_->setErrors(OUT_OF_MEMORY);
}
return true;
}
//------------------------------------------------------------------------------
void PolygonCommand::readCoordinates()
{
Coordinates *coord = new Coordinates(0,0);
unsigned int count = 0;
signed int x = 0, y = 0, int_value = 0;
std::string x_str, y_str;
bool end_polygon = false;
while(true)
{
while(true)
{
if(!ui_->getParam(" x? ", true, false, int_value, x_str, false))
end_polygon = true;
else
{
if(!ui_->stringToSignedInt(x_str, x))
error_->invalidParameter();
break;
}
if(end_polygon)
{
end_polygon = false;
if(count == 0)
error_->invalidParameter();
else
{
delete coord;
return;
}
}
}
coord->setX(x);
while(true)
{
if(!ui_->getParam(" y? ", true, false, int_value, y_str, false))
end_polygon = true;
else
{
if(!ui_->stringToSignedInt(y_str, y))
error_->invalidParameter();
break;
}
if(end_polygon)
{
end_polygon = false;
if(count == 0)
error_->invalidParameter();
else
{
delete coord;
return;
}
}
}
coord->setY(y);
count++;
coordinates_.push_back(*coord);
}
}