-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotateCommand.cpp
More file actions
executable file
·81 lines (72 loc) · 2.13 KB
/
RotateCommand.cpp
File metadata and controls
executable file
·81 lines (72 loc) · 2.13 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
//------------------------------------------------------------------------------
/// Filename: RotateCommand.cpp
/// Description: Base Class for RotateCommands
/// Authors:
/// Ralph Ankele(0931953)
/// Tutor: Manuel Weber
/// Group: 24
/// Created: 08.09.2011
/// Last change: 08.09.2011
//------------------------------------------------------------------------------
#include "RotateCommand.h"
#include "UserInterface.h"
#include "Database.h"
#include "Error.h"
//------------------------------------------------------------------------------
RotateCommand::RotateCommand(UserInterface *ui,
Database *db): Command(ui,db)
{
name_.assign("rotate");
error_ = new Error();
}
//------------------------------------------------------------------------------
RotateCommand::~RotateCommand() throw()
{
delete error_;
}
//------------------------------------------------------------------------------
bool RotateCommand::execute()
{
signed int int_value, group_id;
std::string id, str_value, direction;
size_t found;
while(true)
{
if(!ui_->getParam(" id? ", false, true, int_value, id, false))
return false;
if(ui_->checkID(id))
{
if(ui_->checkIfIdExists(id))
break;
error_->idDoesnotExist();
}
}
while(true)
{
ui_->getParam(" cw/ccw? ", false, false, int_value, direction, false);
if(!direction.compare("cw") || !direction.compare("ccw"))
break;
error_->invalidParameter();
}
found = id.find("gr-");
if(found != std::string::npos)
{
str_value = id.substr(found + 3);
if(!ui_->stringToSignedInt(str_value, group_id))
return false;
for(std::vector<SVGObject*>::iterator it = db_->getSVGObjectByGrp(group_id)
.begin(); it != db_->getSVGObjectByGrp(group_id).end(); ++it)
{
if(!((*it)->rotate(direction)))
return false;
}
}
else
{
signed int object_id = 0;
ui_->stringToSignedInt(id, object_id);
if(!db_->getSVGObjectByID(object_id)->rotate(direction))
return false;
}
return true;
}