/// <summary> /// returns a list of movements according to Wohltmann TST: FA-Sequenz -1- /// </summary> /// <param name="SourceHook">position of roll pickup</param> /// <param name="TargetHook">position of roll placement</param> /// <param name="start_pos">actual trolley position</param> /// <param name="Cylinder_ID">roll on trolley</param> /// <returns></returns> public static TPlist SplitTransportOrder(Hook SourceHook, Hook TargetHook, Hook start_pos, int Cylinder_ID) { TPlist sequence = new TPlist(); bool use_back_carrier = BauerLib.Registry.UseCarrier2; sequence.Append("START", start_pos); if (Cylinder_ID == 0 && SourceHook != null && SourceHook.IsValidTrolleyPosition()) { if (SourceHook.Lift != 100) { sequence.Append("GET", SourceHook); } else { System.Diagnostics.Debug.WriteLine("omit get"); } } if (TargetHook.Lift == 100 && TargetHook.Telescope == 100) { sequence.Append("target", TargetHook); } else { sequence.Append("PUT", TargetHook); } TP TP_here = sequence[0]; TP TP_next = sequence[1]; while (TP_here != null && TP_next != null) // 1a { Hook here = TP_here.target; Hook next = TP_next.target; if (here.Bridge != next.Bridge) // 1b { if (here.Lift != 100 || here.Telescope != 100) // 1d { // top before next movement possible sequence.InsertAfter("top", ref TP_here, ref here); here.Lift = 100; here.Telescope = 100; // now here } if (here.Trolley != 1) // 1e { if (ChangingStorageSides(here, next) || next.Trolley == 1 || !use_back_carrier || // 1f BauerLib.Registry.Carrier2AllowedEndBridge < here.Bridge || BauerLib.Registry.Carrier2AllowedEndBridge < next.Bridge || BauerLib.Registry.Carrier2AllowedStartBridge > here.Bridge || BauerLib.Registry.Carrier2AllowedStartBridge > next.Bridge) { if (here.Trolley >= 10) { sequence.InsertAfter("before front row", ref TP_here, ref here); here.Trolley = 2; // now here } sequence.InsertAfter("front row", ref TP_here, ref here); here.Trolley = 1; // now here } else { if (here.Trolley != 10) // 1k { sequence.InsertAfter("back row", ref TP_here, ref here); here.Trolley = 10; } } } sequence.InsertAfter("carrier", ref TP_here, ref here); here.Bridge = next.Bridge; // right bridge reached 3) } if (here.Trolley != next.Trolley) // 1c { if (here.Lift != 100 || here.Telescope != 100) // 1h { sequence.InsertAfter("top", ref TP_here, ref here); here.Lift = 100; here.Telescope = 100; } if (here.Trolley >= 10 && next.Trolley == 1) { sequence.InsertAfter("trolley", ref TP_here, ref here); here.Trolley = 2; } if (here.Trolley == 1 && next.Trolley >= 10) { sequence.InsertAfter("trolley", ref TP_here, ref here); if (next.Bridge >= 6) { here.Trolley = 8; } else { here.Trolley = 9; } } sequence.InsertAfter("trolley", ref TP_here, ref here); here.Trolley = next.Trolley; } // lift only moves still not possible ! //if (here.Lift != next.Lift) // 1m //{ // sequence.InsertAfter("lift", ref TP_here, ref here); // here.Lift = next.Lift; //} //if (here.Telescope != next.Telescope && (new Hook(here.GetArray) { Telescope = next.Telescope } != next )) //{ // sequence.InsertAfter("telescope", ref TP_here, ref here); // here.Lift = next.Lift; // here.Telescope = next.Telescope; //} // next while int next_idx = sequence.IndexOf(TP_here) + 1; if (next_idx < sequence.Count - 1) { TP_here = sequence[next_idx]; TP_next = sequence[next_idx + 1]; } else { here = sequence[next_idx].target; // add last move at the end of the sequence if (here.Lift != 100 || here.Telescope != 100) // safe top at the very end { sequence.InsertAfter("STOP", ref TP_next, ref next); next.Lift = 100; next.Telescope = 100; } TP_here = null; TP_next = null; } } if (sequence != null && sequence.Count >= 2) { TP last = sequence[sequence.Count - 1]; TP before = sequence[sequence.Count - 2]; if (last.info == "target" && before.target == last.target) { sequence.Remove(last); } } return(sequence); }
private void btnCheckTowerOrBridge_Click(object sender, EventArgs e) { int bridge = 0; int trolley = 0; Unit tr = OrderManagement.FirstFreeTrolley(); if (tr == null) { MessageBox.Show("no trolley free. check aborted"); return; } string what = txtCheckTowerOrBridge.Text; if (what.Contains(",")) { string[] splitted = what.Split(','); bridge = int.Parse(splitted[0]); trolley = int.Parse(splitted[1]); var ordered = Main.Database.Fetch <SqlDbRack>("WHERE Order_ID<>0"); if (ordered.Count() > 0) { MessageBox.Show("Running orders for this tower. please wait. check aborted"); return; } } else { bridge = int.Parse(what); } if (bridge < 1 || bridge > 10) { MessageBox.Show("Wrong bridge"); return; } var possible_hooks = Main.Database.Fetch <SqlDbRack>( "SELECT *, " + "case when telescope<10 then 1000 * (10 - lift) + telescope else 10000 * lift + telescope end as sort " + "FROM Rack " + "WHERE Order_ID=0 AND HookType=1 AND cylinder_id=0 " + " AND (LastGet IS NULL OR LastGet < @2) " + " AND (LastPut IS NULL OR LastPut < @2) " + " AND (Trolley<>1 AND Trolley<>10) " + " AND Bridge=@0 AND (Trolley=@1 OR @1=0) " + " ORDER BY Trolley, sort", bridge, trolley, new DateTime(2010, 1, 1)); if (possible_hooks.Count() <= 0) { MessageBox.Show("all hooks checked or tower full of cylinders. check aborted."); return; } var first_hook_with_cylinder = Main.Database.Fetch <SqlDbRack>( "WHERE Order_ID=0 AND HookType=1 AND cylinder_id<>0 " + " AND Bridge=@0 AND (Trolley=@1) " + "ORDER BY Trolley, Lift DESC", tr.PlcPosition().Bridge, tr.PlcPosition().Trolley); if (first_hook_with_cylinder.Count() <= 0) { first_hook_with_cylinder = Main.Database.Fetch <SqlDbRack>( "WHERE Order_ID=0 AND HookType=1 AND cylinder_id<>0 " + " AND Bridge=@0 " + "ORDER BY Trolley, Lift DESC", bridge, trolley); if (first_hook_with_cylinder.Count() <= 0) { MessageBox.Show("no cylinder on this bridge found. check aborted."); return; } } Hook first_cylinder_hook = null; foreach (var htest in first_hook_with_cylinder) { var chk = new Hook(first_hook_with_cylinder[0]); if (chk.Trolley == tr.PlcPosition().Trolley) { first_cylinder_hook = chk; break; } } if (first_cylinder_hook == null) { first_cylinder_hook = new Hook(first_hook_with_cylinder[0]); } Hook last_hook = null; Hook next = new Hook(possible_hooks[0]); var cyl = first_cylinder_hook.Cylinder; var result = MovementSequencer.SplitTransportOrder(first_cylinder_hook, next, tr.PlcPosition(), 0); result.Remove(result[result.Count() - 1]); int putted = 0; TP put_remove_cylinder_too_big = null; foreach (var item in result) { if (item.info == "PUT" && item.target.MaxDiameter < cyl.Diameter) { put_remove_cylinder_too_big = item; } } if (put_remove_cylinder_too_big != null) { result.Remove(put_remove_cylinder_too_big); } else { putted++; } MovementSequencer.SaveMovements(result, tr.Unit_ID, "new", 0); last_hook = next; foreach (var item in possible_hooks) { next = new Hook(item); if (next == last_hook) { continue; } if (next.MaxDiameter < cyl.Diameter) { continue; } MoveOrderEntry mv = new MoveOrderEntry(); mv.ID = MoveOrderEntry.GetNextId(); mv.Unit_ID = tr.Unit_ID; mv.MoveStatus = MoveOrderStatus.@new; mv.Target = ""; mv.Source = last_hook.ToString(); mv.Info = "GET"; mv.Insert(); if (last_hook.Trolley != next.Trolley) { MoveOrderEntry mvt = new MoveOrderEntry(); mvt.ID = MoveOrderEntry.GetNextId(); mvt.Unit_ID = tr.Unit_ID; mvt.MoveStatus = MoveOrderStatus.@new; mvt.Target = new Hook(1, last_hook.Bridge, last_hook.Trolley, 100, 100).ToString(); mvt.Source = ""; mvt.Info = "top"; mvt.Insert(); MoveOrderEntry mvn = new MoveOrderEntry(); mvn.ID = MoveOrderEntry.GetNextId(); mvn.Unit_ID = tr.Unit_ID; mvn.MoveStatus = MoveOrderStatus.@new; mvn.Target = new Hook(1, last_hook.Bridge, next.Trolley, 100, 100).ToString(); mvn.Source = ""; mvn.Info = "next"; mvn.Insert(); } mv = new MoveOrderEntry(); mv.ID = MoveOrderEntry.GetNextId(); mv.Unit_ID = tr.Unit_ID; mv.MoveStatus = MoveOrderStatus.@new; mv.Source = ""; mv.Target = next.ToString(); mv.Info = "PUT"; mv.Insert(); putted++; last_hook = next; } if (putted == 0) { MessageBox.Show($"No possible hook found.\r\nThey are too small for the cylinder {cyl.Number} / {cyl.Diameter}"); } else { var mv_top = new MoveOrderEntry(); mv_top.ID = MoveOrderEntry.GetNextId(); mv_top.Unit_ID = tr.Unit_ID; mv_top.MoveStatus = MoveOrderStatus.@new; mv_top.Source = ""; mv_top.Target = new Hook(1, last_hook.Bridge, last_hook.Trolley, 100, 100).ToString(); mv_top.Info = "top"; mv_top.Insert(); if (putted < possible_hooks.Count()) { MessageBox.Show($"Only {putted} hooks of {possible_hooks.Count()} used.\r\nThe others are too small for the cylinder {cyl.Number} / {cyl.Diameter}"); } } }