private void SetPathDetails(PathDetails oldpath) { try { if (!SystemArgs.Request.PathDetailsExist(Order.PathDetails)) { SystemArgs.Request.InsertPathDetails(Order.PathDetails); } Order.PathDetails = SystemArgs.Request.GetPathDetails(Order.PathDetails); SystemArgs.Request.SetPathDetailsAllOrder(Order); if (SystemArgs.Request.CheckedNeedRemovePathDetails(oldpath)) { SystemArgs.Request.DeletePathDetails(oldpath); } var updateOrders = SystemArgs.Orders.FindAll(p => p.Number == Order.Number); foreach (var order in updateOrders) { order.PathDetails = Order.PathDetails; } } catch (Exception Ex) { throw new Exception(Ex.Message, Ex); } }
/// <summary> /// check ray against all other servos and entities /// </summary> /// <param name="originalServo"></param> /// <param name="path"></param> /// <returns></returns> private bool CheckIfClear(Servo originalServo, ref PathDetails path) { //create ray using servo + next destination foreach (Entity entity in _entities) { if (!entity.Equals(originalServo)) { path.BlockedMain |= entity.Intersection(path.MainRay, ref path.MainNear); path.BlockedSide0 |= entity.Intersection(path.SideRay0, ref path.SideNear0); path.BlockedSide1 |= entity.Intersection(path.SideRay1, ref path.SideNear1); } } foreach (Person person in _people) { path.BlockedMain |= person.Intersection(path.MainRay, ref path.MainNear); path.BlockedSide0 |= person.Intersection(path.SideRay0, ref path.SideNear0); path.BlockedSide1 |= person.Intersection(path.SideRay1, ref path.SideNear1); } //Debug _worldGrid.DrawCircleAt(path.Offset0, 0.1f, (Colors.DarkSlateGray)); _worldGrid.DrawCircleAt(path.Offset1, 0.1f, (Colors.Red)); _worldGrid.DrawCircleAt(path.Origin, 0.1f, (Colors.Fuchsia)); bool isBlocked = path.BlockedMain || path.BlockedSide0 || path.BlockedSide1; return(!isBlocked); }
/// <summary> /// check whether the servos have pending waypoints /// and try to go to those waypoints /// </summary> private void CheckServos() { foreach (Servo servo in _servos) { DrawServo(servo); DrawWaypoints(servo); // Console.WriteLine(servo.Name); // Console.WriteLine(servo.Waypoints.Count); if (servo.Waypoints.Count > 0) { PathDetails pathDetails = new PathDetails(servo, servo.Waypoints.Peek()); // Console.WriteLine(servo.Name); if (CheckIfClear(servo, ref pathDetails)) { //if clear move servo by some episilon //check if near humans: bool isClose = false; for (int i = 0; i < _people.Count; i++) { float distance = Vector2.Distance(servo.Position, _people[i].Position); if (distance < _people[i].Radius + _servoPersonDistance) { isClose = true; } } double speed = isClose ? 0.5 : 1; servo.MoveTo(pathDetails.MainRay.GetHit(_moveEpisilon), speed); } else { //TODO: else create new node orthogonal to the blockage } } } }
private void ChangePathDetailsDWG_B_Click(object sender, EventArgs e) { try { if (Order.PathDetails.PathDWG == PathDetailsDWG_TB.Text) { FolderBrowserDialog dialog = new FolderBrowserDialog(); if (dialog.ShowDialog() == DialogResult.OK) { PathDetails oldpath = Order.PathDetails; string ModelPath = dialog.SelectedPath; if (ModelPath.Substring(0, 2) != @"\\") { using (var managementObject = new ManagementObject()) { managementObject.Path = new ManagementPath($"Win32_LogicalDisk='{ModelPath.Substring(0, 2)}'"); var driveType = (DriveType)(uint)managementObject["DriveType"]; var networkPath = Convert.ToString(managementObject["ProviderName"]); ModelPath = networkPath + ModelPath.Remove(0, 2); } } ModelPath = ModelPath.Replace("tekla-fs", "10.0.7.249"); Order.PathDetails = new PathDetails { DateCreate = DateTime.Now, PathDWG = ModelPath, PathPDF = Order.PathDetails.PathPDF, PathDXF = Order.PathDetails.PathDXF }; SetPathDetails(oldpath); PathDetailsDWG_TB.Text = ModelPath; MessageBox.Show("Путь успешно изменен!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { if (!Directory.Exists(PathDetailsDWG_TB.Text)) { throw new Exception("Не найдена папка"); } PathDetails oldpath = Order.PathDetails; string ModelPath = PathDetailsDWG_TB.Text; if (ModelPath.Substring(0, 2) != @"\\") { using (var managementObject = new ManagementObject()) { managementObject.Path = new ManagementPath($"Win32_LogicalDisk='{ModelPath.Substring(0, 2)}'"); var driveType = (DriveType)(uint)managementObject["DriveType"]; var networkPath = Convert.ToString(managementObject["ProviderName"]); ModelPath = networkPath + ModelPath.Remove(0, 2); } } ModelPath = ModelPath.Replace("tekla-fs", "10.0.7.249"); Order.PathDetails = new PathDetails { DateCreate = DateTime.Now, PathDWG = ModelPath, PathPDF = Order.PathDetails.PathPDF, PathDXF = Order.PathDetails.PathDXF }; SetPathDetails(oldpath); PathDetailsDWG_TB.Text = ModelPath; MessageBox.Show("Путь успешно изменен!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception E) { SystemArgs.PrintLog(E.ToString()); MessageBox.Show(E.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public PathDetails CalculatePath(GridOccupant wielder, Vector2Int direction, Grid.Grid grid) { PathDetails path = new PathDetails { Travelled = new List <Grid.Grid.Node>(), IsLastNodeTarget = false }; var normalised = direction.CardinalNormalise(); var magnitude = projectile.Range; var node = new Grid.Grid.Node(); for (int i = 1; i <= magnitude; i++) { if (grid.TryGetNodeAt(wielder.Position + i * normalised, ref node)) { path.Travelled.Add(node); // if we have hit something that has a type then weve eiher hit something we cant move though // or weve hit our target if (node.Occupants.Any(it => it.Type != null)) { path.IsLastNodeTarget = node.Occupants.Any(it => it.Type != null && TargetTypes.Contains(it.Type)); break; } // todo(chris) add back in when we implement penetration // else // { // var targetOccupants = node.Occupants.Where(it => TargetTypes.Contains(it.Type)); // // var gridOccupants = targetOccupants as GridOccupant[] ?? targetOccupants.ToArray(); // // // occupant isnt a target so cant go through // if (gridOccupants.Length == 0) // { // break; // } // // path.Hits.Add(node); // // var penetrating = gridOccupants.Where(occupant => projectile.PenitrationTags.Contains(occupant.Type)); // // var penetratingArray = penetrating as GridOccupant[] ?? penetrating.ToArray(); // // // cant penetrate target to this will be as far as we go // if (penetratingArray.Length == 0) // { // break; // } // // // if we cant penetrate all then we are done // if (remainingDepth <= penetratingArray.Length) // { // break; // } // // // continue; // } } else { break; } } if (path.IsLastNodeTarget && path.Travelled.Count == 0) { path = new PathDetails { Travelled = new List <Grid.Grid.Node>(), IsLastNodeTarget = false }; } else { path.Travelled.RemoveAt(0); } return(path); }