From b0b114d1db2a345805048b5b7656e8ceda2c6aa6 Mon Sep 17 00:00:00 2001 From: w-mj Date: Mon, 25 Dec 2017 11:26:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=9C=A8=E8=A7=82=E7=9C=8B-1?= =?UTF-8?q?=E5=B1=82=E6=97=B6=E6=B7=BB=E5=8A=A0=E8=BD=A6=E5=87=BA=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- car.cpp | 30 ++++++++++++++++++++---------- car.h | 13 +++++++++---- parkingLotManager.cpp | 23 +++++++++++++++++------ 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/car.cpp b/car.cpp index fcb0d1e..9d9bfaf 100644 --- a/car.cpp +++ b/car.cpp @@ -100,11 +100,6 @@ int Car::getNum() return num; } -int Car::getFloor() -{ - return floor; -} - int Car::getEntryNum() { return entryNum; @@ -174,16 +169,31 @@ qreal Car::getDir() return this->rotation(); } +int Car::getTargetFloor() const +{ + return targetFloor; +} + +void Car::setTargetFloor(int value) +{ + targetFloor = value; +} + +int Car::getCurrentFloor() const +{ + return currentFloor; +} + +void Car::setCurrentFloor(int value) +{ + currentFloor = value; +} + void Car::setEntryNum(int value) { entryNum = value; } -void Car::setFloor(int value) -{ - floor = value; -} - void Car::setNum(int value) { num = value; diff --git a/car.h b/car.h index eca5e62..f3ba363 100644 --- a/car.h +++ b/car.h @@ -36,11 +36,13 @@ public: void setPath(Path *path); int getNum(); - int getFloor(); + void setNum(int value); int getEntryNum(); void setEntryNum(int value); - void setFloor(int value); - void setNum(int value); + int getTargetFloor() const; + void setTargetFloor(int value); + int getCurrentFloor() const; + void setCurrentFloor(int value); //动画 void moveTo(QPointF target); @@ -55,6 +57,8 @@ public: QPropertyAnimation *posAni; + + private: Color m_color; //车身颜色 N为0, 顺时针递增 QPixmap m_pic; @@ -65,7 +69,8 @@ private: PathPoint m_target; PathPoint m_current; int entryNum; - int floor; + int targetFloor; + int currentFloor; int num; signals: void entry(Car* car); diff --git a/parkingLotManager.cpp b/parkingLotManager.cpp index a9bb234..1d52d5e 100644 --- a/parkingLotManager.cpp +++ b/parkingLotManager.cpp @@ -71,6 +71,12 @@ void ParkingLotManager::showParkingLot(uint pos) if (m_showGraph) { m_scene->addItem(m_graph_pixmap.at(m_current_floor)); } + for (auto c: m_all_cars) { + if (c->getCurrentFloor() != static_cast(pos)) + c->hide(); + else + c->show(); + } emit setCapacity(QString::number(m_capacity.at(pos))); emit setLoad(QString::number(m_capacity.at(pos) - m_num_of_cars[pos])); emit setLayerName(m_name.at(pos)); @@ -136,11 +142,12 @@ void ParkingLotManager::requestOut(Car *car, int exit) void ParkingLotManager::requestStair(Car *car) { - int l = car->getFloor(); + int l = car->getTargetFloor(); int n = car->getNum(); int e = car->getEntryNum(); Path *p = m_graph[l]->findPath(NODE_TYPE::stair, e, NODE_TYPE::space, n); car->setPath(p); + car->setCurrentFloor(l); car->followPath(); } @@ -153,15 +160,15 @@ void ParkingLotManager::requestIn(Car* car) m_pool.removeAt(0); Log::i(QString("分配第%1层%2号车位,剩余%3个空车位").arg(l).arg(n).arg(m_pool.size())); Path* p; - if (l == m_current_floor) - p = m_graph[l]->findPath(NODE_TYPE::queueHead, entry, NODE_TYPE::space, n); + if (l == 1) + p = m_graph[1]->findPath(NODE_TYPE::queueHead, entry, NODE_TYPE::space, n); else { - p = m_graph[m_current_floor]->findPath(NODE_TYPE::queueHead, entry, NODE_TYPE::stair, entry); + p = m_graph[1]->findPath(NODE_TYPE::queueHead, entry, NODE_TYPE::stair, entry); } m_waitting[entry - 1].removeOne(car); // 移除等候 m_cars[l][n - 1] = car; car->setPath(p); - car->setFloor(l); + car->setTargetFloor(l); car->setNum(n); car->followPath(); } else { @@ -171,7 +178,7 @@ void ParkingLotManager::requestIn(Car* car) void ParkingLotManager::leave(Car* car) { - int l = car->getFloor(); + int l = car->getCurrentFloor(); int n = car->getNum(); m_pool.append(qMakePair(l, n)); Log::i(QString("有车离开,当前共有%1个空车位").arg(m_pool.size())); @@ -189,9 +196,13 @@ void ParkingLotManager::addCar(int entry) m_waitting[entry].append(car); Path *p = m_graph[1]->findPath(NODE_TYPE::entry, entry + 1, NODE_TYPE::queueHead, entry + 1); car->setPath(p); + car->setCurrentFloor(1); // 刚添加的车一定是在一层 + car->setTargetFloor(1); car->followPath(); m_all_cars.append(car); m_scene->addItem(car); + if (m_current_floor != 1) + car->hide(); } void ParkingLotManager::showMargin(bool enable)