public void AddNewRobot(int robotID, Renderer r) { Color color; try { color = colors[robotID - 1]; } catch (IndexOutOfRangeException e) { Random rand = new Random(); color = Color.FromArgb((int)(rand.NextDouble() * 255), (int)(rand.NextDouble() * 255), (int)(rand.NextDouble() * 255)); } Color colorBloated; try { colorBloated = colorsBloated[robotID - 1]; } catch (IndexOutOfRangeException e) { Random rand = new Random(); colorBloated = Color.FromArgb((int)(rand.NextDouble() * 255), (int)(rand.NextDouble() * 255), (int)(rand.NextDouble() * 255)); } if (robotID != 5) { RobotRenderer rr = new RobotRenderer("Robot " + robotID, color); //robots[robotID] = new Robot(rr, color, robotID); robots[robotID] = new Robot(rr, color, colorBloated, robotID); r.AddRenderable(rr); r.AddRenderable(robots[robotID].PathRenderer); r.AddRenderable(robots[robotID].LidarRendererFront); r.AddRenderable(robots[robotID].LidarRendererRear); r.AddRenderable(robots[robotID].PolygonRenderer); r.AddRenderable(robots[robotID].BloatedPolygonRenderer); r.UpdateRobotPose(robotID, new Magic.Common.RobotPose()); } }
public void OnMouseDown(Renderer r, MouseEventArgs e) { PointF worldPoint = r.ScreenToWorld(e.Location); if (e.Button == MouseButtons.Right) { //if (GestureExpData != null) // GestureExpData(this, new GestureExpPointToolEventArgs("right down click, at " + e.X + ", " + e.Y + " (screen), " + worldPoint.X + ", " + worldPoint.Y + " (world)")); } else if (e.Button.Equals(MouseButtons.Left)) { //PointF worldPoint = r.ScreenToWorld(e.Location); if (modeNewPOI == true) { if (POItype == "PICTURE") { if (r.Selectables.Count() > 0) { foreach (ISelectable sel in r.Selectables) { RobotRenderer rr = sel as RobotRenderer; if (rr != null && rr.IsSelected) { r.AddRenderable(new FakeObjectRenderer("important", rr.GetBoundingPolygon().Center.ToPointF(), "picture")); if (GestureExpData != null) { GestureExpData(this, new GestureExpHRIEventArgs("Tool:PointTool|left click down|take picture|Robot " + rr.GetName().Substring(rr.GetName().Length - 1) + "|" + e.X + "|" + e.Y + "|(screen)|" + worldPoint.X + "|" + worldPoint.Y + "|(world)")); } } } } } else { NotepointRenderer newPoint = new NotepointRenderer(); newPoint.Name = POItype; if (POItype == "SQUARE") { newPoint.Color = Color.DarkMagenta; } else if (POItype == "TRIANGLE") { newPoint.Color = Color.DarkGreen; } else if (POItype == "SPIRAL") { newPoint.Color = Color.DarkRed; } newPoint.X = worldPoint.X; newPoint.Y = worldPoint.Y; newPoint.Z = 0; poiList.Add(newPoint); r.AddRenderable(newPoint); if (GestureExpData != null) { GestureExpData(this, new GestureExpHRIEventArgs("Tool:PointTool|left click down|create|" + newPoint.Name + "|" + e.X + "|" + e.Y + "|(screen)|" + worldPoint.X + "|" + worldPoint.Y + "|(world)")); } } } else if (modeDeletePOI == true) { if (poiList.Count > 0) { List <NotepointRenderer> pointsToRemove = new List <NotepointRenderer>(); foreach (NotepointRenderer np in poiList) { if ((worldPoint.X - np.X > -.25) && (worldPoint.Y - np.Y > -.25) && (worldPoint.X - np.X < .25) && (worldPoint.Y - np.Y < .25)) { pointsToRemove.Add(np); r.RemoveRenderable(np); if (GestureExpData != null) { GestureExpData(this, new GestureExpHRIEventArgs("Tool:PointTool|left click down|remove|" + np.Name + "|" + e.X + "|" + e.Y + "|(screen)|" + worldPoint.X + "|" + worldPoint.Y + "|(world)")); } } } if (pointsToRemove.Count > 0) { foreach (NotepointRenderer n in pointsToRemove) { poiList.Remove(n); } myToolManager.SelectTool.TempReactivate(); myToolManager.PathTool.TempReactivate(); modeDeletePOI = false; } } } else if (modeMovePOI == true) { if (poiList.Count > 0) { foreach (NotepointRenderer np in poiList) { if ((worldPoint.X - np.X > -.25) && (worldPoint.Y - np.Y > -.25) && (worldPoint.X - np.X < .25) && (worldPoint.Y - np.Y < .25)) { shouldMove = true; pointToMove = np; if (GestureExpData != null) { GestureExpData(this, new GestureExpHRIEventArgs("Tool:PointTool|left click down|move|" + np.Name + "|" + e.X + "|" + e.Y + "|(screen)|" + worldPoint.X + "|" + worldPoint.Y + "|(world)")); } break; } } } } } }
public void OnMouseDown(Renderer r, MouseEventArgs e) { PointF worldPoint = r.ScreenToWorld(e.Location); if (e.Button == MouseButtons.Right) { //if (GestureExpData != null) // GestureExpData(this, new GestureExpPointToolEventArgs("right down click, at " + e.X + ", " + e.Y + " (screen), " + worldPoint.X + ", " + worldPoint.Y + " (world)")); } else if(e.Button.Equals(MouseButtons.Left)) { //PointF worldPoint = r.ScreenToWorld(e.Location); if (modeNewPOI == true) { if (POItype == "PICTURE") { if (r.Selectables.Count() > 0) { foreach (ISelectable sel in r.Selectables) { RobotRenderer rr = sel as RobotRenderer; if (rr != null && rr.IsSelected) { r.AddRenderable(new FakeObjectRenderer("important", rr.GetBoundingPolygon().Center.ToPointF(), "picture")); if (GestureExpData != null) { GestureExpData(this, new GestureExpHRIEventArgs("Tool:PointTool|left click down|take picture|Robot " + rr.GetName().Substring(rr.GetName().Length-1) + "|" + e.X + "|" + e.Y + "|(screen)|" + worldPoint.X + "|" + worldPoint.Y + "|(world)")); } } } } } else { NotepointRenderer newPoint = new NotepointRenderer(); newPoint.Name = POItype; if (POItype == "SQUARE") { newPoint.Color = Color.DarkMagenta; } else if (POItype == "TRIANGLE") { newPoint.Color = Color.DarkGreen; } else if (POItype == "SPIRAL") { newPoint.Color = Color.DarkRed; } newPoint.X = worldPoint.X; newPoint.Y = worldPoint.Y; newPoint.Z = 0; poiList.Add(newPoint); r.AddRenderable(newPoint); if (GestureExpData != null) { GestureExpData(this, new GestureExpHRIEventArgs("Tool:PointTool|left click down|create|" + newPoint.Name + "|" + e.X + "|" + e.Y + "|(screen)|" + worldPoint.X + "|" + worldPoint.Y + "|(world)")); } } } else if (modeDeletePOI == true) { if (poiList.Count > 0) { List<NotepointRenderer> pointsToRemove= new List<NotepointRenderer>(); foreach (NotepointRenderer np in poiList) { if ((worldPoint.X - np.X > -.25) && (worldPoint.Y - np.Y > -.25) && (worldPoint.X - np.X < .25) && (worldPoint.Y - np.Y < .25)) { pointsToRemove.Add(np); r.RemoveRenderable(np); if (GestureExpData != null) GestureExpData(this, new GestureExpHRIEventArgs("Tool:PointTool|left click down|remove|" + np.Name + "|" + e.X + "|" + e.Y + "|(screen)|" + worldPoint.X + "|" + worldPoint.Y + "|(world)")); } } if (pointsToRemove.Count>0) { foreach (NotepointRenderer n in pointsToRemove) { poiList.Remove(n); } myToolManager.SelectTool.TempReactivate(); myToolManager.PathTool.TempReactivate(); modeDeletePOI = false; } } } else if (modeMovePOI == true) { if (poiList.Count > 0) { foreach (NotepointRenderer np in poiList) { if ((worldPoint.X - np.X > -.25) && (worldPoint.Y - np.Y > -.25) && (worldPoint.X - np.X < .25) && (worldPoint.Y - np.Y < .25)) { shouldMove = true; pointToMove = np; if (GestureExpData != null) GestureExpData(this, new GestureExpHRIEventArgs("Tool:PointTool|left click down|move|" + np.Name + "|" + e.X + "|" + e.Y + "|(screen)|" + worldPoint.X + "|" + worldPoint.Y + "|(world)")); break; } } } } } }