2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
9 #include "InsertPointCommand.h"
17 #include "VectorPath.h"
20 #undef B_TRANSLATION_CONTEXT
21 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-InsertPointCmd"
27 InsertPointCommand::InsertPointCommand(VectorPath
* path
,
29 const int32
* selected
,
34 fOldSelectionCount(count
)
36 if (fPath
&& (!fPath
->GetPointsAt(fIndex
, fPoint
, fPointIn
, fPointOut
)
37 || !fPath
->GetPointOutAt(fIndex
- 1, fPreviousOut
)
38 || !fPath
->GetPointInAt(fIndex
+ 1, fNextIn
))) {
41 if (fOldSelectionCount
> 0 && selected
) {
42 fOldSelection
= new (nothrow
) int32
[count
];
43 memcpy(fOldSelection
, selected
, count
* sizeof(int32
));
48 InsertPointCommand::~InsertPointCommand()
50 delete[] fOldSelection
;
55 InsertPointCommand::Perform()
57 status_t status
= InitCheck();
61 // path point is already added
62 // but in/out points might still have changed
63 fPath
->GetPointInAt(fIndex
, fPointIn
);
64 fPath
->GetPointOutAt(fIndex
, fPointOut
);
71 InsertPointCommand::Undo()
73 status_t status
= InitCheck();
77 AutoNotificationSuspender
_(fPath
);
79 // remove the inserted point
80 if (fPath
->RemovePoint(fIndex
)) {
81 // remember current previous "out" and restore it
82 BPoint previousOut
= fPreviousOut
;
83 fPath
->GetPointOutAt(fIndex
- 1, fPreviousOut
);
84 fPath
->SetPointOut(fIndex
- 1, previousOut
);
85 // remember current next "in" and restore it
86 BPoint nextIn
= fNextIn
;
87 fPath
->GetPointInAt(fIndex
, fNextIn
);
88 fPath
->SetPointIn(fIndex
, nextIn
);
89 // restore previous selection
90 _Select(fOldSelection
, fOldSelectionCount
);
100 InsertPointCommand::Redo()
102 status_t status
= InitCheck();
107 AutoNotificationSuspender
_(fPath
);
109 // insert point again
110 if (fPath
->AddPoint(fPoint
, fIndex
)) {
111 fPath
->SetPoint(fIndex
, fPoint
, fPointIn
, fPointOut
, true);
112 // remember current previous "out" and restore it
113 BPoint previousOut
= fPreviousOut
;
114 fPath
->GetPointOutAt(fIndex
- 1, fPreviousOut
);
115 fPath
->SetPointOut(fIndex
- 1, previousOut
);
116 // remember current next "in" and restore it
117 BPoint nextIn
= fNextIn
;
118 fPath
->GetPointInAt(fIndex
+ 1, fNextIn
);
119 fPath
->SetPointIn(fIndex
+ 1, nextIn
);
120 // select inserted point
131 InsertPointCommand::GetName(BString
& name
)
133 // name << _GetString(INSERT_CONTROL_POINT, "Insert Control Point");
134 name
<< B_TRANSLATE("Insert Control Point");