1/*
2 * Copyright 2009, Stephan A��mus <superstippi@gmx.de>. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6#include "RotatePathIndicesCommand.h"
7
8#include <stdio.h>
9
10#include <Catalog.h>
11#include <Locale.h>
12
13#include "VectorPath.h"
14
15
16#undef B_TRANSLATION_CONTEXT
17#define B_TRANSLATION_CONTEXT "Icon-O-Matic-RotatePathIndiciesCmd"
18
19
20RotatePathIndicesCommand::RotatePathIndicesCommand(VectorPath* path,
21		bool clockWise)
22	:
23	PathCommand(path),
24	fClockWise(clockWise)
25{
26}
27
28
29RotatePathIndicesCommand::~RotatePathIndicesCommand()
30{
31}
32
33
34status_t
35RotatePathIndicesCommand::InitCheck()
36{
37	status_t ret = PathCommand::InitCheck();
38	if (ret == B_OK && fPath->CountPoints() < 2)
39		return B_NOT_SUPPORTED;
40	return ret;
41}
42
43
44status_t
45RotatePathIndicesCommand::Perform()
46{
47	return _Rotate(fClockWise);
48}
49
50
51status_t
52RotatePathIndicesCommand::Undo()
53{
54	return _Rotate(!fClockWise);
55}
56
57
58void
59RotatePathIndicesCommand::GetName(BString& name)
60{
61	name << B_TRANSLATE("Rotate path indices");
62}
63
64
65status_t
66RotatePathIndicesCommand::_Rotate(bool clockWise)
67{
68	BPoint point;
69	BPoint pointIn;
70	BPoint pointOut;
71	bool connected;
72
73	int32 removeIndex;
74	int32 addIndex;
75	if (!clockWise) {
76		removeIndex = fPath->CountPoints() - 1;
77		addIndex = 0;
78	} else {
79		removeIndex = 0;
80		addIndex = fPath->CountPoints() - 1;
81	}
82
83	if (!fPath->GetPointsAt(removeIndex, point, pointIn, pointOut, &connected))
84		return B_ERROR;
85
86	fPath->RemovePoint(removeIndex);
87	fPath->AddPoint(point, addIndex);
88	fPath->SetPoint(addIndex, point, pointIn, pointOut, connected);
89
90	return B_OK;
91}
92
93