示例#1
0
int ArcNet::Get_Phasing_Data (Phasing_File &file, Phasing_Data &phasing_rec)
{
	int signal = Data_Service::Get_Phasing_Data (file, phasing_rec);

	if (signal >= 0) {
		if (arcview_phasing.Is_Open ()) {
			arcview_phasing.Copy_Fields (file);
		}
		if (!file.Nested ()) {
			if (time_flag) {
				Signal_Data *signal_ptr = &signal_array [signal];

				Signal_Time_Itr itr;
				bool keep = false;

				for (itr = signal_ptr->begin (); itr != signal_ptr->end (); itr++) {
					if (itr->Phasing () == phasing_rec.Phasing () && 
						itr->Start () <= time && time <= itr->End ()) {
						keep = true;
						break;
					}
				}
				if (!keep) {
					phasing_rec.Phasing (0);
					return (-1);
				}
			}
			return (signal);
		}
		if (arcview_phasing.Is_Open ()) {
			arcview_phasing.parts.clear ();
			arcview_phasing.clear ();

			if (phasing_rec.size () == 0) return (-1);

			Movement_Itr move_itr = --phasing_rec.end ();

			double side_in, side_out;

			Connect_Data *connect_ptr = &connect_array [move_itr->Connection ()];

			int dir_in = connect_ptr->Dir_Index ();
			int dir_out = connect_ptr->To_Index ();

			if (lanes_flag) {
				int center_in, center_out;
				double width;

				Points_Itr pt_itr;
				Lane_Map_Array lane_map;
				Lane_Map_Itr map_itr;

				width = lane_width / 2.0;
				center_in = center_out = 1;

				if (center_flag) {
					Link_Data *link_ptr;
					Dir_Data *dir_ptr;

					//---- gather inbound data ----

					dir_ptr = &dir_array [dir_in];
					link_ptr = &link_array [dir_ptr->Link ()];

					if (link_ptr->BA_Dir () < 0 || link_ptr->AB_Dir () < 0) {
						center_in = dir_ptr->Left () + dir_ptr->Lanes () + dir_ptr->Right () + 1;
					}

					//---- gather outbound data ----

					dir_ptr = &dir_array [dir_out];
					link_ptr = &link_array [dir_ptr->Link ()];

					if (link_ptr->BA_Dir () < 0 || link_ptr->AB_Dir () < 0) {
						center_out = dir_ptr->Left () + dir_ptr->Lanes () + dir_ptr->Right () + 1;
					}
				}
				
				//---- get the lane map ----

				Lane_Map (connect_ptr, lane_map);

				//---- draw each connection ----

				for (map_itr = lane_map.begin (); map_itr != lane_map.end (); map_itr++) {
					side_in = (2 + 2 * map_itr->In_Lane () - center_in) * width;
					side_out = (2 + 2 * map_itr->Out_Lane () - center_out) * width;

					Turn_Shape (dir_in, dir_out, points, turn_shape_setback, curve_flag, side_in, side_out);

					arcview_phasing.parts.push_back ((int) arcview_phasing.size ());

					for (pt_itr = points.begin (); pt_itr != points.end (); pt_itr++) {
						arcview_phasing.push_back (*pt_itr);
					}
				}
			} else {
				side_in = side_out = link_offset;

				arcview_phasing.parts.push_back ((int) arcview_phasing.size ());

				Turn_Shape (dir_in, dir_out, arcview_phasing, turn_shape_setback, curve_flag, side_in, side_out);
			}
			if (!arcview_phasing.Write_Record ()) {
				Error (String ("Writing %s") % arcview_phasing.File_Type ());
			}
		}
		return (signal);
	}
	return (-1);
}
示例#2
0
bool TransimsNet::Get_Phasing_Data (Phasing_File &file, Phasing_Record &phasing_rec)
{
	int link, dir, node, dir_index, to_index, num, detector, signal;
	String svalue;
	
	Int_Map_Itr map_itr;
	Int2_Map_Itr map2_itr;
	Link_Data *link_ptr;
	Dir_Data *dir_ptr;

	Phasing_Data *phasing_ptr = &(phasing_rec.phasing_data);

	//---- process the header record ----
	
	if (!file.Nested ()) {
		signal = file.Signal ();
		if (signal == 0) return (false);

		map_itr = signal_map.find (signal);
		if (map_itr == signal_map.end ()) {
			Warning (String ("Phasing Signal %d was Not Found") % signal);
			return (false);
		}
		phasing_rec.Signal (map_itr->second);

		phasing_ptr->Phasing (file.Phasing ());
		phasing_ptr->Phase (file.Phase ());

		//---- process the detectors ----

		svalue = file.Detectors ();

		if (!svalue.empty ()) {
			Strings detect;
			Str_Itr itr;

			num = svalue.Parse (detect, "|+/");

			for (itr = detect.begin (); itr != detect.end (); itr++) {
				detector = itr->Integer ();
				if (detector <= 0) break;

				map_itr = detector_map.find (detector);
				if (map_itr == detector_map.end ()) {
					Warning (String ("Signal %d Detector %d was Not Found") % file.Signal () % detector);
					break;
				}
				phasing_ptr->detectors.push_back (map_itr->second);
			}
		}
		if (file.Version () > 40) return (phasing_rec.Signal () >= 0);
	}
	Movement_Data move_rec;

	move_rec.Movement (file.Movement ());

	//---- convert the link direction ----
	
	link = file.Link ();
	dir = file.Dir ();

	link_ptr = Set_Link_Direction (file, link, dir);

	if (link_ptr == 0) return (false);

	if (dir) {
		dir_index = link_ptr->BA_Dir ();
		node = link_ptr->Anode ();
	} else {
		dir_index = link_ptr->AB_Dir ();
		node = link_ptr->Bnode ();
	}
	if (dir_index < 0) {
		Warning (String ("Phasing Plan %d Link %d Direction %s was Not Found") % Progress_Count () % 
			link_ptr->Link () % ((dir) ? "BA" : "AB"));
		return (false);
	}

	//---- convert the to-link number ----

	link = file.To_Link ();

	map_itr = link_map.find (link);
	if (map_itr == link_map.end ()) {
		Warning (String ("Phasing Plan %d Link %d was Not Found") % Progress_Count () % link);
		return (false);
	}
	link = map_itr->second;

	link_ptr = &link_array [link];

	if (link_ptr->Anode () == node) {
		to_index = link_ptr->AB_Dir ();
	} else if (link_ptr->Bnode () == node) {
		to_index = link_ptr->BA_Dir ();
	} else {
		Node_Data *ptr = &node_array [node];
		Warning (String ("Phasing Plan %d Node %d is Not on Link %d") % Progress_Count () % ptr->Node () % link_ptr->Link ());
		return (false);
	}

	//---- check the link connection ----

	map2_itr = connect_map.find (Int2_Key (dir_index, to_index));

	if (map2_itr == connect_map.end ()) {
		to_index = link_ptr->Link ();

		dir_ptr = &dir_array [dir_index];
		link_ptr = &link_array [dir_ptr->Link ()];
		dir_index = link_ptr->Link ();

		if (file.Version () > 40) {
			Warning (String ("No Link Connection between %d and %d") % dir_index % to_index);
		}
		return (false);
	}

	//---- save the data ----

	move_rec.Connection (map2_itr->second);

	move_rec.Protection (file.Protection ());

	if (file.Version () <= 40 && move_rec.Movement () == 0) {
		Connect_Data *connect_ptr;
		const char *direction;

		dir_ptr = &dir_array [dir_index];
		direction = compass.Point_Text (dir_ptr->In_Bearing (), 4);

		if (*direction == 'N') {
			dir = NB_TH;
		} else if (*direction == 'S') {
			dir = SB_TH;
		} else if (*direction == 'E') {
			dir = EB_TH;
		} else {
			dir = WB_TH;
		}
		connect_ptr = &connect_array [map2_itr->second];
		num = connect_ptr->Type ();
		
		if (num == RIGHT || num == R_SPLIT) {
			dir += NB_RT - NB_TH;
		} else if (num == LEFT || num == L_SPLIT) {
			dir += NB_LT - NB_TH;
		} else if (num == UTURN) {
			dir += NB_UT - NB_TH;
		}
		move_rec.Movement (dir);
	}
	phasing_ptr->push_back (move_rec);

	return (phasing_rec.Signal () >= 0);
}