-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineCommand.cpp
More file actions
executable file
·105 lines (90 loc) · 2.59 KB
/
LineCommand.cpp
File metadata and controls
executable file
·105 lines (90 loc) · 2.59 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
//------------------------------------------------------------------------------
/// Filename: LineCommand.cpp
/// Description: Base Class for LineCommands
/// Authors:
/// Ralph Ankele(0931953)
/// Tutor: Manuel Weber
/// Group: 24
/// Created: 08.09.2011
/// Last change: 19.09.2011
//------------------------------------------------------------------------------
#include "LineCommand.h"
#include "UserInterface.h"
#include "Database.h"
#include "SVGHandler.h"
#include "SVGLine.h"
#include "ErrorCodes.h"
#include "Error.h"
#include <sstream>
#include <iostream>
//------------------------------------------------------------------------------
LineCommand::LineCommand(UserInterface *ui,
Database *db,
SVGHandler *svgh): Command(ui,db),
svgh_(svgh)
{
name_.assign("line");
error_ = new Error();
}
//------------------------------------------------------------------------------
LineCommand::~LineCommand() throw()
{
delete error_;
}
//------------------------------------------------------------------------------
bool LineCommand::execute()
{
signed int id, group_id, x, y, int_value;
std::string id_str;
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();
}
for(unsigned int count = 1; count < 3; count++)
{
std::stringstream param_x;
param_x << " x"<< count <<"? ";
x = readParam(param_x.str());
coord->setX(x);
std::stringstream param_y;
param_y << " y"<< count <<"? ";
y = readParam(param_y.str());
coord->setY(y);
coordinates_.push_back(*coord);
}
group_id = readParam(" group? ");
delete coord;
try
{
SVGLine *line = new SVGLine(ui_, db_, svgh_, id, group_id, coordinates_);
db_->setSVGObject(line);
coordinates_.clear();
}
catch(std::bad_alloc& exception)
{
svgh_->setErrors(OUT_OF_MEMORY);
}
return true;
}
//------------------------------------------------------------------------------
signed int LineCommand::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;
}