-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.cpp
95 lines (83 loc) · 1.83 KB
/
action.cpp
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
#include "action.h"
#include "edgeitem.h"
#include "labelimage.h"
#include "endpoint.h"
#include <QDebug>
EndPointMove::EndPointMove(EndPoint *pPoint, unsigned int oldInd, unsigned int newInd)
{
endPoint = pPoint;
oldIndex = oldInd;
newIndex = newInd;
}
void EndPointMove::perform()
{
endPoint->moveTo(newIndex);
endPoint->blink();
}
void EndPointMove::reverse()
{
endPoint->moveTo(oldIndex);
endPoint->blink();
}
SplitEdge::SplitEdge(LabelImage* pImage, EdgeItem *pEdge)
{
image = pImage;
oldEdge = pEdge;
newEdge1 = NULL;
newEdge2 = NULL;
}
void SplitEdge::perform()
{
if (!newEdge1 || !newEdge2) {
std::vector<EdgeItem*> newEdges = oldEdge->split();
if (newEdges.size() != 2) return;
newEdge1 = newEdges[0];
newEdge2 = newEdges[1];
}
image->performSplitEdge(oldEdge, newEdge1, newEdge2);
newEdge1->blink();
newEdge2->blink();
}
void SplitEdge::reverse()
{
if (!newEdge1 || !newEdge2) return;
image->reverseSplitEdge(oldEdge, newEdge1, newEdge2);
oldEdge->blink();
}
SelectEdge::SelectEdge(EdgeItem* pEdge)
{
edge = pEdge;
}
void SelectEdge::perform()
{
edge->select();
}
void SelectEdge::reverse()
{
edge->unselect();
edge->blink();
}
ConnectPoint::ConnectPoint(LabelImage* image, EndPoint* point1, EndPoint* point2, QPointF pos)
{
pImage = image;
pPoint1 = point1;
pPoint2 = point2;
pos2 = pos;
createPoint = point2 == NULL;
}
void ConnectPoint::perform()
{
if (createPoint) {
pPoint2 = new EndPoint(pImage, pos2);
pImage->addStrayPoint(pPoint2);
}
pImage->addConnection(pPoint1, pPoint2);
}
void ConnectPoint::reverse()
{
if (createPoint) {
pImage->removeStrayPoint(pPoint2);
if (pPoint2) delete pPoint2;
}
pImage->removeConnection(pPoint1, pPoint2);
}