-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimerrefreshthread.cpp
More file actions
126 lines (113 loc) · 3.15 KB
/
Copy pathtimerrefreshthread.cpp
File metadata and controls
126 lines (113 loc) · 3.15 KB
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
// Author : XuBenHao
// Version : 1.0.0
// Mail : xbh370970843@163.com
// Copyright : XuBenHao 2020 - 2030
#include "timerrefreshthread.h"
#include "Ui/Drawing/arrayvaluevisitdrawingwidget.h"
#include <QTimer>
namespace NAnimationService
{
void TimerRefreshThread::Pause()
{
}
TimerRefreshThread::TimerRefreshThread(
//const NParameter::ArrayNcParameter& arrParam_,
//const NFileParse::ArrayModalData& arrModalData_,
NSync::FixBufferFor1P1C<NNcShow::NcShow*, 20>* pNcShowBuffer_,
QWidget* pWidget_,
QObject* pParent_)
: QThread(pParent_)
{
//m_nParam = arrParam_;
//m_nModalData = arrModalData_;
//m_pNcCodeBuffer = pNcCodeBuffer_;
//m_pNcStepBuffer = pNcStepBuffer_;
m_pNcShowBuffer = pNcShowBuffer_;
m_pWidget = pWidget_;
m_bStop = false;
m_nState = PRODUCER_NOT_START;
m_pTimer = nullptr;
}
TimerRefreshThread::~TimerRefreshThread()
{
}
void TimerRefreshThread::Stop()
{
m_bStop = true;
}
THREAD_STATE TimerRefreshThread::GetThreadState()
{
if(m_nState == PRODUCER_NOT_START)
{
return THREAD_NOT_START;
}
else if(m_nState == PRODUCER_RUNNING)
{
return THREAD_RUNNING;
}
else if(m_nState == PRODUCER_PAUSED)
{
return THREAD_PAUSED;
}
else if(m_nState == PRODUCER_NORMAL_END)
{
return THREAD_NORMALLY_END;
}
else
{
return THREAD_ABNORMALLY_END;
}
}
void TimerRefreshThread::Update()
{
// for every object in the assembly line
// it actor as a producer and a consumer
// we need to process the state of the object
if(!m_bStop)
{
NNcShow::NcShow* _pNcShow = nullptr;
int _nRet = m_pNcShowBuffer->Pop(_pNcShow);
if(_nRet == 1)
{
// ok
}
else if(_nRet == 0)
{
// producer normally end
assert(false);
m_nState = PRODUCER_ABNORMAL_END_AS_CONSUMER_NORMAL_END;
}
else
{
m_nState = PRODUCER_ABNORMAL_END_AS_CONSUMER_ABNORAML_END;
}
if(_nRet == 1 && _pNcShow)
{
// Consumer a NcShow
ArrayValueVisitDrawingWidget* _pW = (ArrayValueVisitDrawingWidget*)m_pWidget;
_pW->ProcessNcShow(_pNcShow);
delete _pNcShow;
}
}
if(m_bStop || m_nState != PRODUCER_RUNNING)
{
pthread_exit(nullptr);
}
}
void TimerRefreshThread::timerEvent(QTimerEvent *event)
{
if(event->timerId() == m_nTimerId)
{
Update();
}
}
void TimerRefreshThread::run()
{
m_nState = PRODUCER_RUNNING;
//m_nTimerId = startTimer(20);
m_pTimer = new QTimer(this);
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(Update()), Qt::DirectConnection);
//m_pTimer->start(20);
exec();
}
}