|
@@ -20,68 +20,79 @@ single_base<area_list, int, std::shared_ptr<area>>::m_instance=std::make_shared<
|
|
|
|
|
|
struct underground_area:area
|
|
|
{
|
|
|
- underground_area(int limit_count_person, int limit_time_person,double scale,int32_t mapid)
|
|
|
- :area(-1,limit_count_person,limit_time_person,scale,mapid,(1<<1)|(1<<2)|(1<<3)|(1<<4))
|
|
|
+ underground_area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t type)
|
|
|
+ :area(id,limit_count_person,limit_time_person,scale,mapid,type)
|
|
|
{
|
|
|
- m_area_business_list=area_business::get_instance_list(m_area_type);
|
|
|
- }
|
|
|
-
|
|
|
- void db_load_card_count()
|
|
|
- {
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
- virtual bool in_area(const std::shared_ptr<site>&s, const point & p)
|
|
|
- {
|
|
|
- //根据s的地面、地下属性判断
|
|
|
- return false;
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-struct ground_area:area
|
|
|
-{
|
|
|
- virtual bool in_area(const std::shared_ptr<site>&s, const point & p)
|
|
|
+ virtual bool in_area(const std::shared_ptr<site>&s,const std::shared_ptr<card_location_base>&c, const point & p,int &sarid)
|
|
|
{
|
|
|
- //根据s的地面、地下属性判断
|
|
|
- return false;
|
|
|
+ bool f =false;
|
|
|
+ int id = c->get_area();
|
|
|
+ if(id!=-1)
|
|
|
+ f=true;
|
|
|
+ return f;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
struct special_area:area
|
|
|
{
|
|
|
- virtual bool in_area(const std::shared_ptr<site>&s, const point & p)
|
|
|
+ special_area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t type)
|
|
|
+ :area(id,limit_count_person,limit_time_person,scale,mapid,type)
|
|
|
+ {}
|
|
|
+ virtual bool in_area(const std::shared_ptr<site>&s,const std::shared_ptr<card_location_base>&c, const point & p,int &sarid)
|
|
|
{
|
|
|
- return false;
|
|
|
+ bool f=false;
|
|
|
+ int id = c->get_area();
|
|
|
+ if(id == m_id)
|
|
|
+ {
|
|
|
+ f=true;
|
|
|
+ sarid=m_id;
|
|
|
+ }
|
|
|
+ return f;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-void area::on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
|
|
|
+area::area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t type)
|
|
|
+ :m_id(id)
|
|
|
+ ,m_area_type(type)
|
|
|
+ ,m_limit_person_second(limit_time_person)
|
|
|
+ ,m_limit_person_count(limit_count_person)
|
|
|
+ ,m_scale(scale)
|
|
|
+ ,m_mapid(mapid)
|
|
|
+ ,m_person_count(0)
|
|
|
+ ,m_vehicle_count(0)
|
|
|
+ {
|
|
|
+ m_area_business_list=area_business::get_instance_list(m_area_type);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+void area::on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c)
|
|
|
{
|
|
|
- for(auto i:m_area_business_list)
|
|
|
+ for(const auto &i:m_area_business_list)
|
|
|
{
|
|
|
i->on_hover(a,c,a->get_business_data(i->area_business_type()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void area::on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
|
|
|
+void area::on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c)
|
|
|
{
|
|
|
log_info("on_enter..%d areaId:%d",c->m_id,m_id);
|
|
|
- for(auto i:m_area_business_list)
|
|
|
+ for(const auto &i:m_area_business_list)
|
|
|
{
|
|
|
i->on_enter(a,c,a->get_business_data(i->area_business_type()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void area::on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
|
|
|
+void area::on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c)
|
|
|
{
|
|
|
log_info("on_leave..%d areaId:%d",c->m_id,m_id);
|
|
|
- for(auto i:m_area_business_list)
|
|
|
+ for(const auto &i:m_area_business_list)
|
|
|
{
|
|
|
i->on_leave(a,c,a->get_business_data(i->area_business_type()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-bool area::in_area(const std::shared_ptr<site>&s, const point & p)
|
|
|
+bool area::in_area(const std::shared_ptr<site>&s,const std::shared_ptr<card_location_base>&c, const point & p,int & sarid)
|
|
|
{
|
|
|
if(m_bound.empty())
|
|
|
return false;
|
|
@@ -129,8 +140,6 @@ void area_list::init_monkeycar_area(int id)
|
|
|
sql.append(" AND a.area_id=");
|
|
|
sql.append(std::to_string(id));
|
|
|
sql.append(";");
|
|
|
-
|
|
|
- std_debug("基础数据 monkeycar area 增加或修改区域 sql=%s", sql.c_str());
|
|
|
log_info("基础数据 monkeycar area 增加或修改区域 sql=%s", sql.c_str());
|
|
|
}
|
|
|
|
|
@@ -190,10 +199,8 @@ void area_list::init_monkeycar_area(int id)
|
|
|
std::shared_ptr<db_area> da = std::make_shared<db_area>();
|
|
|
da->m_default_speed = monkeycar_speed;
|
|
|
da->m_point = init_path(monkeycar_coor);
|
|
|
-
|
|
|
- std::shared_ptr<area> ap = std::make_shared<monkey_area>(da,area_id,over_count_person, over_time_person,scale,map_id,area_type_id);
|
|
|
- //初始化区域逻辑
|
|
|
- ap->m_area_business_list=std::move(area_business::get_instance_list(b_type));
|
|
|
+ std::shared_ptr<area> ap = std::make_shared<monkey_area>(da,area_id,over_count_person, over_time_person,scale,map_id,b_type);
|
|
|
+ ap->update(over_count_person, over_time_person,scale,map_id,area_type_id, over_count_vehicle,over_time_vehicle);
|
|
|
|
|
|
ap->m_bound=init_path(path);
|
|
|
for(const auto &p : ap->m_bound)
|
|
@@ -209,13 +216,11 @@ void area_list::init_monkeycar_area(int id)
|
|
|
std::shared_ptr<db_area> da = std::make_shared<db_area>();
|
|
|
da->m_default_speed = monkeycar_speed;
|
|
|
da->m_point = init_path(monkeycar_coor);
|
|
|
- std::shared_ptr<area> ap = area_list::instance()->get(id);
|
|
|
- if(!ap)
|
|
|
- {
|
|
|
- ap = std::make_shared<monkey_area>(da,area_id,over_count_person, over_time_person,scale,map_id,area_type_id);
|
|
|
- area_list::instance()->add(id, ap);
|
|
|
- }
|
|
|
- ap->m_area_business_list=std::move(area_business::get_instance_list(b_type));
|
|
|
+ std::shared_ptr<area> ap = std::make_shared<monkey_area>(da,area_id,over_count_person, over_time_person,scale,map_id,b_type);
|
|
|
+ if(auto area_=area_list::instance()->get(id))
|
|
|
+ area_=ap;
|
|
|
+ else
|
|
|
+ area_list::instance()->add(area_id,ap);
|
|
|
|
|
|
ap->m_bound=init_path(path);
|
|
|
ap->update(over_count_person, over_time_person,scale,map_id,area_type_id, over_count_vehicle,over_time_vehicle);
|
|
@@ -238,6 +243,22 @@ void area_list::init_monkeycar_area(int id)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+std::shared_ptr<area> area_list::create(int type,int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t b_type)
|
|
|
+{
|
|
|
+ if(type==AREA_TYPE_FORBIDDEN)
|
|
|
+ {
|
|
|
+ return std::make_shared<special_area>(id,limit_count_person,limit_time_person,scale,mapid,b_type);
|
|
|
+ }
|
|
|
+ else if(type == AREA_TYPE_DOWNMINE)
|
|
|
+ {
|
|
|
+ return std::make_shared<underground_area>(id,limit_count_person,limit_time_person,scale,mapid,b_type);
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return std::make_shared<area>(id,limit_count_person,limit_time_person,scale,mapid,b_type);
|
|
|
+ }
|
|
|
+}
|
|
|
void area_list::init_from_db(int id/*=-1*/)
|
|
|
{
|
|
|
std::string sql = "SELECT a.area_id, a.name, a.map_id, a.area_type_id, a.path,b.scale, \
|
|
@@ -245,7 +266,7 @@ void area_list::init_from_db(int id/*=-1*/)
|
|
|
over_speed_vehicle, is_attendance,business_type \
|
|
|
FROM dat_area a,dat_map b\
|
|
|
where a.map_id = b.map_id and area_id not in \
|
|
|
- (select monkeycar_base_info_id from dat_monkeycar_base_info)";
|
|
|
+ (select monkeycar_base_info_id from dat_monkeycar_base_info)";
|
|
|
|
|
|
if(-1 == id)
|
|
|
{
|
|
@@ -307,18 +328,13 @@ void area_list::init_from_db(int id/*=-1*/)
|
|
|
|
|
|
if(-1 == id)
|
|
|
{
|
|
|
- std::shared_ptr<area> ap = std::make_shared<area>(area_id,over_count_person,over_time_person,
|
|
|
- scale,map_id,area_type_id);
|
|
|
-
|
|
|
+ std::shared_ptr<area> ap = create(area_type_id,area_id,over_count_person,over_time_person, scale,map_id,b_type);
|
|
|
ap->m_limit_vehicle_second = over_time_vehicle;
|
|
|
ap->m_limit_vehicle_count = over_count_vehicle;
|
|
|
|
|
|
ap->m_bound=init_path(path);
|
|
|
for(const auto &p : ap->m_bound)
|
|
|
log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
|
|
|
-
|
|
|
- ap->m_area_business_list=std::move(area_business::get_instance_list(b_type));
|
|
|
-
|
|
|
map.insert({area_id,ap});
|
|
|
|
|
|
// CheckAreaType(ap,area_type_id,0);
|
|
@@ -328,12 +344,11 @@ void area_list::init_from_db(int id/*=-1*/)
|
|
|
auto tmp_ptr = area_list::instance()->get(id);
|
|
|
if(!tmp_ptr)
|
|
|
{
|
|
|
- tmp_ptr= std::make_shared<area>(area_id,over_count_person,over_time_person,scale,map_id,area_type_id);
|
|
|
+ tmp_ptr = create(area_type_id,area_id,over_count_person,over_time_person, scale,map_id,b_type);
|
|
|
area_list::instance()->add(id, tmp_ptr);
|
|
|
}
|
|
|
tmp_ptr->update(over_count_person, over_time_person,scale,map_id,area_type_id, over_count_vehicle,over_time_vehicle);
|
|
|
tmp_ptr->m_bound=init_path(path);
|
|
|
- tmp_ptr->m_area_business_list=std::move(area_business::get_instance_list(b_type));
|
|
|
for(const auto &p : tmp_ptr->m_bound)
|
|
|
log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
|
|
|
// CheckAreaType(tmp_ptr,area_type_id,tmp_ptr->m_area_type);
|
|
@@ -349,8 +364,8 @@ void area_list::init_from_db(int id/*=-1*/)
|
|
|
{
|
|
|
log_info( "init_area. The record count=%d\n", nCount );
|
|
|
area_list::instance()->add(map);
|
|
|
- init_monkeycar_area();
|
|
|
}
|
|
|
+ init_monkeycar_area(id);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -455,34 +470,36 @@ std::vector<point> area_list::init_path(std::string &str)
|
|
|
return std::move(vp);
|
|
|
}
|
|
|
|
|
|
-std::vector<std::shared_ptr<area>> area_list::get_area(const std::shared_ptr<site> s,const point&pt)
|
|
|
+std::vector<std::shared_ptr<area>> area_list::get_area(const std::shared_ptr<site> s,const std::shared_ptr<card_location_base> &c,const point&pt,int & sarid)
|
|
|
{
|
|
|
std::vector<std::shared_ptr<area>> ret;
|
|
|
|
|
|
auto map = area_list::instance()->m_map;
|
|
|
|
|
|
for(const auto &a:map)
|
|
|
- if(a.second->in_area(s, pt))
|
|
|
+ if(a.second->in_area(s,c,pt,sarid))
|
|
|
ret.push_back(a.second);
|
|
|
//区域覆盖不完全地图,很多车辆人行驶在地图外,如何确认.
|
|
|
return std::move(ret);
|
|
|
}
|
|
|
|
|
|
-void area_tool::on_point(const std::shared_ptr<site>&s,std::shared_ptr<card_location_base> c,const point&pt)
|
|
|
+void area_tool::on_point(const std::shared_ptr<site>&s,const std::shared_ptr<card_location_base>& c,const point&pt)
|
|
|
{
|
|
|
log_info("on_point...cardid:%d,type:%d",c->m_id,c->m_type);
|
|
|
setLandmark(pt);
|
|
|
-
|
|
|
- std::vector<std::shared_ptr<area>> areas=area_list::instance()->get_area(s, pt);//找出所有的区域
|
|
|
- int sa = c->get_area();
|
|
|
- if(sa!=-1)
|
|
|
+
|
|
|
+ int special_area=-1;
|
|
|
+ std::vector<std::shared_ptr<area>> areas=area_list::instance()->get_area(s,c, pt,special_area);
|
|
|
+ if(special_area != -1)
|
|
|
{
|
|
|
- auto area_=area_list::instance()->get(sa);
|
|
|
+ areas.clear();
|
|
|
+ auto area_=area_list::instance()->get(special_area);
|
|
|
areas.push_back(area_);
|
|
|
}
|
|
|
- std::sort(areas.begin(),areas.end(),[](const std::shared_ptr<area>&l,const std::shared_ptr<area>&r){
|
|
|
- return l->id()<r->id();
|
|
|
- });
|
|
|
+ else
|
|
|
+ std::sort(areas.begin(),areas.end(),[](const std::shared_ptr<area>&l,const std::shared_ptr<area>&r){
|
|
|
+ return l->id()<r->id();
|
|
|
+ });
|
|
|
|
|
|
auto c1=m_hover_list.begin(),ce=m_hover_list.end();
|
|
|
auto a1=areas.begin() ,ae=areas.end();
|