-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExecuteStep.cpp
154 lines (139 loc) · 3.34 KB
/
ExecuteStep.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "pch.h"
#include "ExecuteStep.h"
using namespace Platform;
using namespace Platform::Collections;
using namespace AlgorithmVisualization;
using namespace Windows::System::Threading;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::UI::Core;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="id"></param>
/// <param name="type"></param>
AlgorithmVisualization::SingleStep::SingleStep(int type)
{
this->Type = type;
HighlightLines = ref new Vector<int>();
ThisState = ref new Vector<IVector<int>^>();
ToNextStep = ref new Vector<ExcuteInstruct^>();
}
/// <summary>
/// 步骤计数
/// </summary>
/// <returns>步骤总数</returns>
int AlgorithmVisualization::ExecuteStep::CountStep()
{
return StepList->Size;
}
/// <summary>
/// 加入步骤
/// </summary>
/// <param name="step">要插入的步骤</param>
/// <returns>步骤总数</returns>
int AlgorithmVisualization::ExecuteStep::AddStep(SingleStep^ step)
{
StepList->Append(step);
return CountStep();
}
/// <summary>
/// 删除指定步骤
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
int AlgorithmVisualization::ExecuteStep::RemoveStep(int index)
{
StepList->RemoveAt(index);
return CountStep();
}
/// <summary>
/// 清空步骤
/// </summary>
void AlgorithmVisualization::ExecuteStep::ClearStep()
{
StepList->Clear();
}
/// <summary>
/// 导航到第一步
/// </summary>
/// <returns></returns>
SingleStep^ AlgorithmVisualization::ExecuteStep::NavigateToFirst()
{
return NavigateToStep(0);
}
/// <summary>
/// 导航到最后一步
/// </summary>
/// <returns></returns>
SingleStep^ AlgorithmVisualization::ExecuteStep::NavigateToLast()
{
return NavigateToStep(CountStep() - 1);
}
/// <summary>
/// 是否是第一步
/// </summary>
/// <returns></returns>
bool AlgorithmVisualization::ExecuteStep::IsFirstStep()
{
return CurrentStep == 0;
}
/// <summary>
/// 是否是最后一步
/// </summary>
/// <returns></returns>
bool AlgorithmVisualization::ExecuteStep::IsLastStep()
{
if (StepList->Size != 0) return CurrentStep == StepList->Size - 1;
else return true;
}
/// <summary>
/// 获取第一步
/// </summary>
/// <returns></returns>
SingleStep^ AlgorithmVisualization::ExecuteStep::GetFirstStep()
{
if (StepList->Size == 0) return nullptr;
else return StepList->GetAt(0);
}
/// <summary>
/// 获取最后一步
/// </summary>
/// <returns></returns>
SingleStep^ AlgorithmVisualization::ExecuteStep::GetLastStep()
{
if (StepList->Size == 0) return nullptr;
else return StepList->GetAt(StepList->Size - 1);
}
/// <summary>
/// 默认初始化
/// </summary>
void AlgorithmVisualization::ExecuteStep::DefaultInit()
{
SpeedList = ref new Vector<int>{ 0, 20, 40, 60, 80,
100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950,
1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000 };
StepList = ref new Vector<SingleStep^>();
CurrentStep = 0;
Speed = 500; //默认速度
ThreadTimer = nullptr;
}
/// <summary>
/// 获取计时器是否在运行
/// </summary>
/// <returns></returns>
bool AlgorithmVisualization::ExecuteStep::TimerIsRunning()
{
return ThreadTimer != nullptr;
}
/// <summary>
/// 终止计时器
/// </summary>
void AlgorithmVisualization::ExecuteStep::StopTimer()
{
if (ThreadTimer != nullptr)
{
//不为空就取消并设为空
ThreadTimer->Cancel();
ThreadTimer = nullptr;
}
}