int Data_Service::Put_Node_Data (Node_File &file, Node_Data &data) { file.Node (data.Node ()); file.X (UnRound (data.X ())); file.Y (UnRound (data.Y ())); file.Z (UnRound (data.Z ())); file.Subarea (data.Subarea ()); file.Partition (data.Partition ()); file.Notes (data.Notes ()); if (!file.Write ()) { Error (String ("Writing %s") % file.File_Type ()); } return (1); }
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); }
bool Data_Service::Get_Connect_Data (Connect_File &file, Connect_Data &connect_rec) { int link, dir, node, dir_index, to_index, lanes, low, high; Link_Data *link_ptr; Int_Map_Itr map_itr; //---- check/convert the link number and 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 ("Connection %d Link %d Direction %s was Not Found") % Progress_Count () % link_ptr->Link () % ((dir) ? "BA" : "AB")); return (false); } connect_rec.Dir_Index (dir_index); //---- convert the to-link number ---- link = file.To_Link (); map_itr = link_map.find (link); if (map_itr == link_map.end ()) { Warning (String ("Connection %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 ("Connection %d Node %d is Not on Link %d") % Progress_Count () % ptr->Node () % link_ptr->Link ()); return (false); } connect_rec.To_Index (to_index); //---- lane numbers ---- lanes = file.Lanes (); if (file.Version () <= 40 && lanes > 0) { low = lanes - 1; high = file.In_High () - 1; if (high < low) high = low; } else { Convert_Lane_Range (dir_index, lanes, low, high); } connect_rec.Low_Lane (low); connect_rec.High_Lane (high); lanes = file.To_Lanes (); if (file.Version () <= 40 && lanes > 0) { low = lanes - 1; high = file.Out_High () - 1; if (high < low) high = low; } else { Convert_Lane_Range (to_index, lanes, low, high); } connect_rec.To_Low_Lane (low); connect_rec.To_High_Lane (high); //---- optional fields ---- connect_rec.Type (file.Type ()); connect_rec.Penalty (file.Penalty ()); connect_rec.Speed (file.Speed ()); connect_rec.Capacity (file.Capacity ()); connect_rec.Notes (file.Notes ()); //---- check for duplicate records ---- if (file.Version () <= 40) { Int2_Map_Itr map2_itr; //max_in = dir_ptr->Thru () + dir_ptr->Left () + dir_ptr->Right (); //in_bear = dir_ptr->Out_Bearing (); //max_out = dir_ptr->Thru () + dir_ptr->Left () + dir_ptr->Right (); //out_bear = dir_ptr->In_Bearing (); //---- read and save the data ---- //int num, node_num, link, dir, in_link, out_link, max_in, max_out, in_bear, out_bear; //int in_low, in_high, out_low, out_high, type, penalty, speed, capacity, change; //if (type == 0 && compass.Num_Points () > 0) { // change = compass.Change (in_bear, out_bear) * 360 / compass.Num_Points (); // if (change >= -45 && change <= 45) { // type = THRU; // } else if (change < -165 || change > 165) { // type = UTURN; // } else if (change < 0) { // type = LEFT; // } else { // type = RIGHT; // } //} map2_itr = connect_map.find (Int2_Key (connect_rec.Dir_Index (), connect_rec.To_Index ())); if (map2_itr != connect_map.end ()) { Connect_Data *connect_ptr; //---- update optional fields ---- connect_ptr = &connect_array [map2_itr->second]; //---- merge the entry lane codes ---- if (connect_rec.Low_Lane () < connect_ptr->Low_Lane ()) { connect_ptr->Low_Lane (connect_rec.Low_Lane ()); } if (connect_rec.High_Lane () > connect_ptr->High_Lane ()) { connect_ptr->High_Lane (connect_rec.High_Lane ()); } //---- merge the exit lane codes ---- if (connect_rec.To_Low_Lane () < connect_ptr->To_Low_Lane ()) { connect_ptr->To_Low_Lane (connect_rec.To_Low_Lane ()); } if (connect_rec.To_High_Lane () > connect_ptr->To_High_Lane ()) { connect_ptr->To_High_Lane (connect_rec.To_High_Lane ()); } //---- merge the optional data ---- if (connect_rec.Type () > connect_ptr->Type ()) { connect_ptr->Type (connect_rec.Type ()); } if (connect_rec.Penalty () > connect_ptr->Penalty ()) { connect_ptr->Penalty (connect_rec.Penalty ()); } if (connect_rec.Speed () > connect_ptr->Speed ()) { connect_ptr->Speed (connect_rec.Speed ()); } connect_ptr->Capacity (connect_ptr->Capacity () + connect_rec.Capacity ()); return (false); } } return (true); }
bool Relocate::Get_Connect_Data (Connect_File &file, Connect_Data &connect_rec) { if (!target_flag) { if (!Data_Service::Get_Connect_Data (file, connect_rec)) return (false); return (true); } int link, dir, node, dir_index, to_index, lanes, low, high; bool new_flag; Link_Data *link_ptr; Int_Map_Itr map_itr; //---- check/convert the link number and direction ---- link = file.Link (); dir = file.Dir (); new_flag = false; map_itr = link_map.find (link); if (map_itr == link_map.end ()) { Warning (String ("Connection %d Link %d was Not Found") % Progress_Count () % link); return (false); } link_ptr = &link_array [map_itr->second]; if (link_ptr->Divided () == 3) { map_itr = target_link_map.find (link); if (map_itr != target_link_map.end ()) { link_ptr = &link_array [map_itr->second]; new_flag = true; } } else if (link_ptr->Divided () == 2) { new_flag = true; } 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 ("Connection %d Link %d Direction %s was Not Found") % Progress_Count () % link_ptr->Link () % ((dir) ? "BA" : "AB")); return (false); } connect_rec.Dir_Index (dir_index); connect_rec.Type (file.Type ()); //---- convert the to-link number ---- link = file.To_Link (); map_itr = link_map.find (link); if (map_itr == link_map.end ()) { Warning (String ("Connection %d Link %d was Not Found") % Progress_Count () % link); return (false); } link = map_itr->second; link_ptr = &link_array [link]; if (link_ptr->Divided () == 3) { map_itr = target_link_map.find (link); if (map_itr != target_link_map.end ()) { link_ptr = &link_array [map_itr->second]; new_flag = true; } } else if (link_ptr->Divided () == 2) { new_flag = true; } if (!new_flag) return (false); 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 ("Connection %d Node %d is Not on Link %d") % Progress_Count () % ptr->Node () % link_ptr->Link ()); return (false); } if (to_index < 0) { Node_Data *ptr = &node_array [node]; Warning (String ("Connection %d Link %d Node %d was Not Found") % Progress_Count () % link_ptr->Link () % ptr->Node ()); return (false); } connect_rec.To_Index (to_index); connect_rec.Node (node); //---- lane numbers ---- lanes = file.Lanes (); Convert_Lane_Range (dir_index, lanes, low, high); connect_rec.Low_Lane (low); connect_rec.High_Lane (high); lanes = file.To_Lanes (); Convert_Lane_Range (to_index, lanes, low, high); connect_rec.To_Low_Lane (low); connect_rec.To_High_Lane (high); //---- optional fields ---- connect_rec.Penalty (file.Penalty ()); connect_rec.Speed (file.Speed ()); connect_rec.Capacity (file.Capacity ()); return (true); }