-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectCommand.cpp
More file actions
executable file
·102 lines (89 loc) · 2.76 KB
/
RectCommand.cpp
File metadata and controls
executable file
·102 lines (89 loc) · 2.76 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
//------------------------------------------------------------------------------
/// Filename: RectCommand.cpp
/// Description: Base Class for RectCommands
/// Authors:
/// Ralph Ankele(0931953)
/// Tutor: Manuel Weber
/// Group: 24
/// Created: 08.09.2011
/// Last change: 19.09.2011
//------------------------------------------------------------------------------
#include "RectCommand.h"
#include "UserInterface.h"
#include "Database.h"
#include "SVGHandler.h"
#include "SVGRect.h"
#include "Coordinates.h"
#include "ErrorCodes.h"
#include "Error.h"
//------------------------------------------------------------------------------
RectCommand::RectCommand(UserInterface *ui,
Database *db,
SVGHandler *svgh): Command(ui,db),
svgh_(svgh)
{
name_.assign("rect");
error_ = new Error();
}
//------------------------------------------------------------------------------
RectCommand::~RectCommand() throw()
{
delete error_;
}
//------------------------------------------------------------------------------
bool RectCommand::execute()
{
signed int id, group_id, x, y, width, height, int_value;
std::string fill, stroke, id_str, stroke_width;
Coordinates *coord = new Coordinates(0,0);
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();
}
x = readParam(" x? ");
coord->setX(x);
y = readParam(" y? ");
coord->setY(y);
coordinates_.push_back(*coord);
delete coord;
width = readParam(" width? ");
height = readParam(" height? ");
ui_->getParam(" fill? ", false, false, int_value, fill, false);
ui_->getParam(" stroke? ", false, false, int_value, stroke, false);
ui_->getParam(" stroke-width? ", false, false, int_value, stroke_width,
false);
group_id = readParam(" group? ");
try
{
SVGRect *rect = new SVGRect(ui_, db_, svgh_, id, group_id, coordinates_,
width, height, fill, stroke, stroke_width);
db_->setSVGObject(rect);
coordinates_.clear();
}
catch(std::bad_alloc& exception)
{
svgh_->setErrors(OUT_OF_MEMORY);
}
return true;
}
//------------------------------------------------------------------------------
signed int RectCommand::readParam(std::string prompt)
{
signed int param = 0;
std::string str_value;
while(true)
{
if(ui_->getParam(prompt, false, false, param, str_value, true))
break;
}
return param;
}