修复了到站不停车的问题
用nullptr替代了NULL
This commit is contained in:
parent
752ddf8a33
commit
73b096aa3d
|
@ -46,7 +46,6 @@ public:
|
||||||
|
|
||||||
virtual ~BusStrategyBase();
|
virtual ~BusStrategyBase();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得当前公交车应该前进的方向
|
* 获得当前公交车应该前进的方向
|
||||||
* @return 公交车前进的方向
|
* @return 公交车前进的方向
|
||||||
|
@ -78,11 +77,6 @@ public:
|
||||||
*/
|
*/
|
||||||
void PrintStateSignal(QString string);
|
void PrintStateSignal(QString string);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得公交车前进方向的信号
|
|
||||||
*/
|
|
||||||
void GetBusDirectionSignal();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 运行公交车的信号
|
* 运行公交车的信号
|
||||||
* @param direction 公交车前进的方向
|
* @param direction 公交车前进的方向
|
||||||
|
@ -113,11 +107,6 @@ public slots:
|
||||||
*/
|
*/
|
||||||
void OneTickSlot(int remaining_time);
|
void OneTickSlot(int remaining_time);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得公交车前进方向的槽函数
|
|
||||||
*/
|
|
||||||
void GetBusDirectionSlot();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理到站事件的槽函数
|
* 处理到站事件的槽函数
|
||||||
*/
|
*/
|
||||||
|
@ -136,9 +125,9 @@ private:
|
||||||
QString PrintState(int remaining_time) const;
|
QString PrintState(int remaining_time) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置各种连接
|
* 决定公交车状态的函数
|
||||||
*/
|
*/
|
||||||
void SetConnection() const;
|
void DetermineBusStatus();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理请求
|
* 处理请求
|
||||||
|
|
|
@ -8,11 +8,10 @@ int BusFCFSStrategy::GetBusDirection()
|
||||||
{
|
{
|
||||||
bus_query_t *p = bus_model->target_query;
|
bus_query_t *p = bus_model->target_query;
|
||||||
|
|
||||||
if(p == NULL)
|
if(p == nullptr)
|
||||||
{
|
{
|
||||||
return BUS_STOP;
|
return BUS_STOP;
|
||||||
} //如果没有请求,公交车停止
|
} //如果没有请求,公交车停止
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int clockwise = 0;
|
int clockwise = 0;
|
||||||
|
|
|
@ -9,7 +9,7 @@ int BusSCANStrategy::GetBusDirection()
|
||||||
int orientation = bus_model->direction;
|
int orientation = bus_model->direction;
|
||||||
bus_query_t *query = bus_model->target_query;
|
bus_query_t *query = bus_model->target_query;
|
||||||
|
|
||||||
if(query == NULL)
|
if(query == nullptr)
|
||||||
{
|
{
|
||||||
return BUS_STOP;
|
return BUS_STOP;
|
||||||
}
|
}
|
||||||
|
@ -53,22 +53,22 @@ bus_query_t *BusSCANStrategy::GetTargetQuery()
|
||||||
int direction = bus_model->direction;
|
int direction = bus_model->direction;
|
||||||
|
|
||||||
// 当前没有请求
|
// 当前没有请求
|
||||||
if(queries == NULL)
|
if(queries == nullptr)
|
||||||
{
|
{
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(direction == BUS_STOP)
|
if(direction == BUS_STOP)
|
||||||
{
|
{
|
||||||
// 在停止的状态下第一次开始选择方向
|
// 在停止的状态下第一次开始选择方向
|
||||||
int distance = 9999;
|
int distance = 9999;
|
||||||
bus_query_t *query = NULL;
|
bus_query_t *query = nullptr;
|
||||||
bus_query_t *p = queries;
|
bus_query_t *p = queries;
|
||||||
|
|
||||||
// 遍历顺时针方向
|
// 遍历顺时针方向
|
||||||
// 在两个方向路程相同时选择顺时针方向
|
// 在两个方向路程相同时选择顺时针方向
|
||||||
// 所以先遍历顺时针方向
|
// 所以先遍历顺时针方向
|
||||||
while (p != NULL)
|
while (p != nullptr)
|
||||||
{
|
{
|
||||||
int temp = bus_model->GetQueryDistance(p, BUS_CLOCK_WISE);
|
int temp = bus_model->GetQueryDistance(p, BUS_CLOCK_WISE);
|
||||||
if(temp < distance)
|
if(temp < distance)
|
||||||
|
@ -81,7 +81,7 @@ bus_query_t *BusSCANStrategy::GetTargetQuery()
|
||||||
|
|
||||||
// 遍历逆时针方向
|
// 遍历逆时针方向
|
||||||
p = queries;
|
p = queries;
|
||||||
while (p != NULL)
|
while (p != nullptr)
|
||||||
{
|
{
|
||||||
int temp = bus_model->GetQueryDistance(p, BUS_COUNTER_CLOCK_WISE);
|
int temp = bus_model->GetQueryDistance(p, BUS_COUNTER_CLOCK_WISE);
|
||||||
if(temp < distance)
|
if(temp < distance)
|
||||||
|
@ -98,10 +98,10 @@ bus_query_t *BusSCANStrategy::GetTargetQuery()
|
||||||
{
|
{
|
||||||
// 在已经有方向的情况下处理方向
|
// 在已经有方向的情况下处理方向
|
||||||
int distance = 9999;
|
int distance = 9999;
|
||||||
bus_query_t *query = NULL;
|
bus_query_t *query = nullptr;
|
||||||
bus_query_t *p = queries;
|
bus_query_t *p = queries;
|
||||||
|
|
||||||
while (p != NULL)
|
while (p != nullptr)
|
||||||
{
|
{
|
||||||
int temp = bus_model->GetQueryDistance(p, direction);
|
int temp = bus_model->GetQueryDistance(p, direction);
|
||||||
if(temp < distance)
|
if(temp < distance)
|
||||||
|
@ -123,7 +123,7 @@ bus_query_t *BusSCANStrategy::HandleBTWQuery()
|
||||||
|
|
||||||
bus_query_t *p = query_model->queries;
|
bus_query_t *p = query_model->queries;
|
||||||
|
|
||||||
while(p != NULL)
|
while(p != nullptr)
|
||||||
{
|
{
|
||||||
if(p->node == now_position)
|
if(p->node == now_position)
|
||||||
{
|
{
|
||||||
|
@ -135,5 +135,5 @@ bus_query_t *BusSCANStrategy::HandleBTWQuery()
|
||||||
p = p->next_node;
|
p = p->next_node;
|
||||||
}//遍历请求链表,判断是否有可以顺便处理的请求
|
}//遍历请求链表,判断是否有可以顺便处理的请求
|
||||||
|
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ int BusSSTFStrategy::GetBusDirection()
|
||||||
{
|
{
|
||||||
bus_query_t *query = bus_model->target_query;
|
bus_query_t *query = bus_model->target_query;
|
||||||
|
|
||||||
if (query == NULL)
|
if (query == nullptr)
|
||||||
{
|
{
|
||||||
return BUS_STOP;
|
return BUS_STOP;
|
||||||
}
|
}
|
||||||
|
@ -33,10 +33,10 @@ bus_query_t *BusSSTFStrategy::HandleBTWQuery()
|
||||||
// 这里只是处理顺便服务的代码
|
// 这里只是处理顺便服务的代码
|
||||||
|
|
||||||
bus_query_t *query = query_model->queries;
|
bus_query_t *query = query_model->queries;
|
||||||
bus_query_t *allow_query = NULL;
|
bus_query_t *allow_query = nullptr;
|
||||||
rail_node_t *now_node = bus_model->rail_pos;
|
rail_node_t *now_node = bus_model->rail_pos;
|
||||||
|
|
||||||
while (query != NULL)
|
while (query != nullptr)
|
||||||
{
|
{
|
||||||
if(query->node == now_node)
|
if(query->node == now_node)
|
||||||
{
|
{
|
||||||
|
@ -62,19 +62,19 @@ bus_query_t *BusSSTFStrategy::GetTargetQuery()
|
||||||
bus_query_t *queries = query_model->queries;
|
bus_query_t *queries = query_model->queries;
|
||||||
|
|
||||||
// 当前没有请求
|
// 当前没有请求
|
||||||
if(queries == NULL)
|
if(queries == nullptr)
|
||||||
{
|
{
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int distance = 9999;
|
int distance = 9999;
|
||||||
bus_query_t *query = NULL;
|
bus_query_t *query = nullptr;
|
||||||
bus_query_t *p = queries;
|
bus_query_t *p = queries;
|
||||||
|
|
||||||
// 遍历顺时针方向
|
// 遍历顺时针方向
|
||||||
// 在两个方向路程相同时选择顺时针方向
|
// 在两个方向路程相同时选择顺时针方向
|
||||||
// 所以先遍历顺时针方向
|
// 所以先遍历顺时针方向
|
||||||
while (p != NULL)
|
while (p != nullptr)
|
||||||
{
|
{
|
||||||
int temp = bus_model->GetQueryDistance(p, BUS_CLOCK_WISE);
|
int temp = bus_model->GetQueryDistance(p, BUS_CLOCK_WISE);
|
||||||
if(temp < distance)
|
if(temp < distance)
|
||||||
|
@ -87,7 +87,7 @@ bus_query_t *BusSSTFStrategy::GetTargetQuery()
|
||||||
|
|
||||||
// 遍历逆时针方向
|
// 遍历逆时针方向
|
||||||
p = queries;
|
p = queries;
|
||||||
while (p != NULL)
|
while (p != nullptr)
|
||||||
{
|
{
|
||||||
int temp = bus_model->GetQueryDistance(p, BUS_COUNTER_CLOCK_WISE);
|
int temp = bus_model->GetQueryDistance(p, BUS_COUNTER_CLOCK_WISE);
|
||||||
if(temp < distance)
|
if(temp < distance)
|
||||||
|
|
|
@ -12,8 +12,6 @@ BusStrategyBase::BusStrategyBase()
|
||||||
|
|
||||||
bus_tick = 0;
|
bus_tick = 0;
|
||||||
strategy = -1;
|
strategy = -1;
|
||||||
|
|
||||||
SetConnection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BusStrategyBase::~BusStrategyBase()
|
BusStrategyBase::~BusStrategyBase()
|
||||||
|
@ -23,12 +21,6 @@ BusStrategyBase::~BusStrategyBase()
|
||||||
delete bus_model;
|
delete bus_model;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BusStrategyBase::SetConnection() const
|
|
||||||
{
|
|
||||||
QObject::connect(this, &BusStrategyBase::GetBusDirectionSignal,
|
|
||||||
this, &BusStrategyBase::GetBusDirectionSlot);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BusStrategyBase::AppendQuerySlot(int query_type, int node_id)
|
void BusStrategyBase::AppendQuerySlot(int query_type, int node_id)
|
||||||
{
|
{
|
||||||
rail_node_t *node = rails_model->FindNode(node_id);
|
rail_node_t *node = rails_model->FindNode(node_id);
|
||||||
|
@ -37,7 +29,7 @@ void BusStrategyBase::AppendQuerySlot(int query_type, int node_id)
|
||||||
// 如果公交车停车且在系统在运行
|
// 如果公交车停车且在系统在运行
|
||||||
if(bus_model->direction == BUS_STOP && status == BUS_RUNNING)
|
if(bus_model->direction == BUS_STOP && status == BUS_RUNNING)
|
||||||
{
|
{
|
||||||
emit GetBusDirectionSignal();
|
DetermineBusStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +51,7 @@ void BusStrategyBase::BusBeginSlot()
|
||||||
QString str = PrintState(0);
|
QString str = PrintState(0);
|
||||||
emit PrintStateSignal(str);
|
emit PrintStateSignal(str);
|
||||||
|
|
||||||
emit GetBusDirectionSignal();
|
DetermineBusStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BusStrategyBase::BusEndSlot()
|
void BusStrategyBase::BusEndSlot()
|
||||||
|
@ -70,7 +62,7 @@ void BusStrategyBase::BusEndSlot()
|
||||||
bus_model->ResetBus(rails_model->rails);
|
bus_model->ResetBus(rails_model->rails);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BusStrategyBase::GetBusDirectionSlot()
|
void BusStrategyBase::DetermineBusStatus()
|
||||||
{
|
{
|
||||||
bus_model->target_query = GetTargetQuery();
|
bus_model->target_query = GetTargetQuery();
|
||||||
bus_model->direction = GetBusDirection();
|
bus_model->direction = GetBusDirection();
|
||||||
|
@ -108,6 +100,8 @@ void BusStrategyBase::HandleQuery()
|
||||||
{
|
{
|
||||||
if(bus_model->target_query->node == bus_model->rail_pos)
|
if(bus_model->target_query->node == bus_model->rail_pos)
|
||||||
{
|
{
|
||||||
|
bus_model->direction = BUS_STOP;
|
||||||
|
|
||||||
// 如果已经到站
|
// 如果已经到站
|
||||||
while (bus_model->target_query != nullptr and
|
while (bus_model->target_query != nullptr and
|
||||||
bus_model->target_query->node == bus_model->rail_pos)
|
bus_model->target_query->node == bus_model->rail_pos)
|
||||||
|
@ -118,24 +112,31 @@ void BusStrategyBase::HandleQuery()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 需要停一tick处理请求
|
// 需要停一tick处理请求
|
||||||
emit BusRunningSignal(BUS_STOP, 1000);
|
emit BusRunningSignal(BUS_STOP, Settings::tick);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 没有到站就进行顺便处理
|
// 没有到站就进行顺便处理
|
||||||
bus_query_t *query = HandleBTWQuery();
|
bus_query_t *query = HandleBTWQuery();
|
||||||
|
bool is_handled = false;
|
||||||
if(query != nullptr)
|
|
||||||
{
|
|
||||||
// 需要停一tick处理请求
|
|
||||||
emit BusRunningSignal(BUS_STOP, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
while(query != nullptr)
|
while(query != nullptr)
|
||||||
{
|
{
|
||||||
emit DeleteQuerySignal(query->type, query->node->id);
|
emit DeleteQuerySignal(query->type, query->node->id);
|
||||||
query_model->DeleteQuery(query);
|
query_model->DeleteQuery(query);
|
||||||
query = HandleBTWQuery();
|
query = HandleBTWQuery();
|
||||||
|
is_handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_handled)
|
||||||
|
{
|
||||||
|
// 需要停一tick处理请求
|
||||||
|
bus_model->direction = BUS_STOP;
|
||||||
|
emit BusRunningSignal(BUS_STOP, Settings::tick);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DetermineBusStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,9 +152,8 @@ void BusStrategyBase::OnStopSlot()
|
||||||
{
|
{
|
||||||
bus_model->rail_pos = bus_model->rail_pos->last_node;
|
bus_model->rail_pos = bus_model->rail_pos->last_node;
|
||||||
}
|
}
|
||||||
HandleQuery();
|
|
||||||
|
|
||||||
emit GetBusDirectionSignal();
|
HandleQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BusStrategyBase::PrintState(int remaining_time) const
|
QString BusStrategyBase::PrintState(int remaining_time) const
|
||||||
|
@ -164,7 +164,7 @@ QString BusStrategyBase::PrintState(int remaining_time) const
|
||||||
|
|
||||||
if(node == nullptr)
|
if(node == nullptr)
|
||||||
{
|
{
|
||||||
return QString("No rails");
|
return {"No rails"};
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
|
|
|
@ -8,7 +8,7 @@ BusStrategyBase *StrategyFactory::GetStrategy(const QString& file_name)
|
||||||
{
|
{
|
||||||
QByteArray bytes = file_name.toLatin1();
|
QByteArray bytes = file_name.toLatin1();
|
||||||
|
|
||||||
FILE *config_file = NULL;
|
FILE *config_file = nullptr;
|
||||||
char buffer[30];
|
char buffer[30];
|
||||||
int total_station = 0;
|
int total_station = 0;
|
||||||
int distance = 0;
|
int distance = 0;
|
||||||
|
@ -17,7 +17,7 @@ BusStrategyBase *StrategyFactory::GetStrategy(const QString& file_name)
|
||||||
fopen_s(&config_file, bytes.data(), "r");
|
fopen_s(&config_file, bytes.data(), "r");
|
||||||
|
|
||||||
// 循环读取文件的每一行
|
// 循环读取文件的每一行
|
||||||
while (fgets(buffer, sizeof buffer, config_file) != NULL)
|
while (fgets(buffer, sizeof buffer, config_file) != nullptr)
|
||||||
{
|
{
|
||||||
char first_char = buffer[0];
|
char first_char = buffer[0];
|
||||||
char *p;
|
char *p;
|
||||||
|
|
|
@ -139,6 +139,13 @@ void MainWindow::RunBusClicked()
|
||||||
|
|
||||||
void MainWindow::StopBusClicked()
|
void MainWindow::StopBusClicked()
|
||||||
{
|
{
|
||||||
|
// 处理在未加载配置文件的情况下
|
||||||
|
// 点击停止按钮自动闪退的问题
|
||||||
|
if(controller == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
central_widget->ResetOutput();
|
central_widget->ResetOutput();
|
||||||
emit StopBusSignal();
|
emit StopBusSignal();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user