2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
9 #include "RemovePointsCommand.h"
17 #include "VectorPath.h"
20 #undef B_TRANSLATION_CONTEXT
21 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-RemovePointsCmd"
27 // * when clicking a point in Remove mode, with other points selected
28 RemovePointsCommand::RemovePointsCommand(VectorPath
* path
,
30 const int32
* selected
,
40 fOldSelectionCount(count
)
42 _Init(&index
, 1, selected
, count
);
46 // * when hitting the Delete key, so the selected points are the
47 // same as the ones to be removed
48 RemovePointsCommand::RemovePointsCommand(VectorPath
* path
,
49 const int32
* selected
,
59 fOldSelectionCount(count
)
61 _Init(selected
, count
, selected
, count
);
65 RemovePointsCommand::~RemovePointsCommand()
72 delete[] fOldSelection
;
77 RemovePointsCommand::InitCheck()
79 status_t status
= PathCommand::InitCheck();
82 if (!fIndex
|| !fPoint
|| !fPointIn
|| !fPointOut
|| !fConnected
)
89 RemovePointsCommand::Perform()
91 // path points are already removed
97 RemovePointsCommand::Undo()
99 status_t status
= InitCheck();
103 AutoNotificationSuspender
_(fPath
);
105 // add points again at their respective index
106 for (int32 i
= 0; i
< fCount
; i
++) {
107 if (fPath
->AddPoint(fPoint
[i
], fIndex
[i
])) {
108 fPath
->SetPoint(fIndex
[i
],
119 fPath
->SetClosed(fWasClosed
);
121 if (status
>= B_OK
) {
122 // select the added points
123 _Select(fIndex
, fCount
);
131 RemovePointsCommand::Redo()
133 status_t status
= InitCheck();
137 AutoNotificationSuspender
_(fPath
);
140 // the loop assumes the indices in the collection
141 // are increasing (removal at "index[i] - i" to account
142 // for items already removed)
143 for (int32 i
= 0; i
< fCount
; i
++) {
144 if (!fPath
->RemovePoint(fIndex
[i
] - i
)) {
150 fPath
->SetClosed(fWasClosed
&& fPath
->CountPoints() > 1);
152 if (status
>= B_OK
) {
154 _Select(fOldSelection
, fOldSelectionCount
);
162 RemovePointsCommand::GetName(BString
& name
)
165 // name << _GetString(REMOVE_CONTROL_POINTS, "Remove Control Points");
167 // name << _GetString(REMOVE_CONTROL_POINT, "Remove Control Point");
169 name
<< B_TRANSLATE("Remove Control Points");
171 name
<< B_TRANSLATE("Remove Control Point");
176 RemovePointsCommand::_Init(const int32
* indices
, int32 count
,
177 const int32
* selection
, int32 selectionCount
)
179 if (indices
&& count
> 0) {
180 fIndex
= new (nothrow
) int32
[count
];
181 fPoint
= new (nothrow
) BPoint
[count
];
182 fPointIn
= new (nothrow
) BPoint
[count
];
183 fPointOut
= new (nothrow
) BPoint
[count
];
184 fConnected
= new (nothrow
) bool[count
];
188 if (InitCheck() < B_OK
)
191 memcpy(fIndex
, indices
, count
* sizeof(int32
));
192 for (int32 i
= 0; i
< count
; i
++) {
193 if (!fPath
->GetPointsAt(fIndex
[i
],
204 fWasClosed
= fPath
->IsClosed();
206 if (selectionCount
> 0 && selection
) {
207 fOldSelectionCount
= selectionCount
;
208 fOldSelection
= new (nothrow
) int32
[selectionCount
];
209 memcpy(fOldSelection
, selection
, selectionCount
* sizeof(int32
));