public PolygonExport(Polygon poly) { Name = poly.Name; Points = new List<PolyPointExport>(poly.Children.Count); foreach (PolyPoint point in poly.Children) { Points.Add(new PolyPointExport(point)); } }
//Method mainly for the copy paste function, make a clone of the //poly that way when you change a point in one you don't change it for every //copied poly. public Polygon ClonePolygon(Polygon toClone) { var poly = new Polygon(); poly.Name = toClone.Name; foreach (PolyPoint child in toClone.Children) { var point = new PolyPoint(child.X, child.Y); poly.AddChild(point); } poly.Parent = toClone.Parent; return poly; }
public ImageViewer() { _instance = this; _mode = Mode.Center; _paused = false; _poly = null; _polyGroup = null; _moving = null; if (!DesignMode) { _arrowNormCursor = new Cursor("Cursors/ArrowNorm.cur"); _arrowOverCursor = new Cursor("Cursors/ArrowOver.cur"); _penCursor = new Cursor("Cursors/Pen.cur"); _penOverCursor = new Cursor("Cursors/PenOver.cur"); _movingCursor = Cursors.Hand; } Timer refreshTimer = new Timer(); refreshTimer.Interval = (int)(1000 * 1 / 30.0f); refreshTimer.Tick += Refresh; refreshTimer.Start(); }
public void ExecutePasteCommand(object o) { //Setting the data to the Polygon itself doesn't raise propertyChanged so you have to do it directly to the collection //This updates in the view automatically as well. This only changes the points within the poly and nothing else //(makes sense to me that it doesn't change the name and such but that is easy to implement as well if desired) if(_copyData is Polygon) { var clone = new Polygon().ClonePolygon(_copyData as Polygon); switch (_currentSelectedNode.Type) { case "Polygon": //set the parent of the clone to the polygongroup that you're pasting into. clone.Parent = _viewModelLocator.ImageFrameView.PolygonGroup; _viewModelLocator.ImageFrameView.Polygon.Children = clone.Children; break; case "PolygonGroup": clone.Parent = _viewModelLocator.ImageFrameView.PolygonGroup; if (_viewModelLocator.ImageFrameView.PolygonGroup.Children.Count != 0) _viewModelLocator.ImageFrameView.PolygonGroup.Children[0] = clone; else _viewModelLocator.ImageFrameView.PolygonGroup.Children.Add(clone); break; case "ImageFrame": //in the case of wanting to drop a polygon into a image frame, we'll check the Polygroup that it's from and see if there is a //group that matches, if there is, we then paste the polygon into the first spot, overwriting whatever is there. foreach (var child in _currentSelectedNode.Children) { if (child.Name == clone.Parent.Name) { clone.Parent = child; if (child.Children.Count == 0) child.Children.Add(clone); else child.Children[0] = clone; break; } } break; } } else if(_copyData is PolygonGroup) { var clone = new PolygonGroup(); foreach (var child in _copyData.Children) { var temp = new Polygon().ClonePolygon(child as Polygon); temp.Parent = clone; clone.Children.Add(temp); } clone.Name = _copyData.Name; switch (_currentSelectedNode.Type) { case "PolygonGroup": clone.Parent = _currentSelectedNode.Parent; _currentSelectedNode.Children = clone.Children; break; case "ImageFrame": //in the case of wanting to drop a polygon into a image frame, we'll check the Polygroup that it's from and see if there is a //group that matches, if there is, we then paste the polygon into the first spot, overwriting whatever is there. var target =_viewModelLocator.ImageFrameView.Frame.Children.FirstOrDefault(t => t.Name == clone.Name); if (target != null) { //rewire the parents of the children to be the target now target.Children.Clear(); foreach (var child in clone.Children) { child.Parent = target; target.Children.Add(child); } } else { clone.Parent = _viewModelLocator.ImageFrameView.Frame; _viewModelLocator.ImageFrameView.Frame.AddChild(clone); } break; } } }
//method to create a new polygon with a button click etc. public void CreateNewPolygon() { if (_currentSelectedNode is Polygon) { var group = _currentSelectedNode.Parent as PolygonGroup; var newPoly = new Polygon(); newPoly.Parent = group; newPoly.Name = "Polygon " + (group.Children.Count + 1); newPoly.Initialize(); group.Children.Add(newPoly); var index = group.Children.IndexOf(newPoly); (group.Children[index] as Polygon).IsSelected = true; _currentSelectedNode = group.Children[index] as NodeWithName; } }
public void ExecuteAutoTraceCommand(object o) { var dialog = new AutoTraceWindow(); dialog.ShowDialog(); var vm = dialog.DataContext as AutoTraceWindowVM; if (vm.IsOk) { using (var ms = new MemoryStream(Data)) { var imageBitmap = Image.FromStream(ms); var errorBuilder = new StringBuilder(); var shape = TraceService.CreateComplexShape(imageBitmap, 20000, errorBuilder, vm.HullTolerence, vm.AlphaTolerence, vm.MultipartDetection, vm.HoleDetection); if (shape != null) { var polygonGroup = new PolygonGroup("Body"); polygonGroup.Initialize(); var count = 1; foreach (var polygon in shape.Vertices) { var poly = new Polygon() { Name = "Polygon " + count }; foreach (var point in polygon) { poly.AddChild(new PolyPoint((int)point.X, (int)point.Y)); } polygonGroup.AddChild(poly); count++; } AddChild(polygonGroup); } ms.Close(); } } }
public void ExecuteNewPolygonCommand(object o) { var polygonGroup = new Polygon(); AddChild(polygonGroup); }
protected override void OnMouseDown(MouseEventArgs e) { //if right down, get current mouse location if (e.Button == MouseButtons.Right) { _currentX = e.X; _currentY = e.Y; } //if left down if (e.Button == MouseButtons.Left) { //end center mode - move center point if (_mode == Mode.Center) { _centerMoving = true; Vector2 centerPoint = _camera2D.GetWorldCoordinates(new Vector2(e.X, e.Y)); _image.CenterPointX = (int)centerPoint.X; _image.CenterPointY = (int)centerPoint.Y; } else if (_poly != null && _mode == Mode.Polygon && _moving == null) { //check if selecting existing point _moving = CheckIfMouseIsInPolygon(e.X, e.Y); // if not add point if (_moving == null && _poly.Children.Count < Settings.Default.MaxVerts) { var polyWorldCenter = _camera2D.GetWorldCoordinates(new Vector2(e.X, e.Y)); var p = new PolyPoint { X = (int) polyWorldCenter.X, Y = (int) polyWorldCenter.Y, Parent = _poly }; _poly.Children.Add(p); //added point, now dirty. Glue.Instance.DocumentIsSaved = false; _moving = p; } else if( _poly.Children.Count >= Settings.Default.MaxVerts && _moving == null) { MessageBox.Show( string.Format("Max Amount of Verts hit! The Max amount of verts for a polygon is {0}.", Settings.Default.MaxVerts)); } } //Movement start. else if (_poly != null && _moving == null && _mode == Mode.Moving) { var polyWorldCenter = _camera2D.GetWorldCoordinates(new Vector2(e.X, e.Y)); var p = new PolyPoint { X = (int)polyWorldCenter.X, Y = (int)polyWorldCenter.Y, }; if (!CanMoveAnyPolygon) { //check if mouse is inside a polygon if (MouseIsInPolygon(_poly.Children, p)) { //store the original point then we'll check later to see how much we have to offset all the other points by _originalPoint = p; } } //if it wasn't inside the selected polygon see if it's inside another of the same polygroup else { foreach (Polygon polygon in _polyGroup.Children) { if (MouseIsInPolygon(polygon.Children, p)) { _originalPoint = p; _poly = polygon; _poly.IsSelected = true; Mode = Mode.Moving; break; } } } } } }
public void RedrawAfterDeletePolygon() { _poly = null; Draw(); }
private static void AddPlatformBoxStub(ImageFrame frame) { var platformGroup = new PolygonGroup { Name = "Platform", Parent = frame }; platformGroup.Initialize(); frame.AddChild(platformGroup); var attack = new Polygon { Name = "Polygon 1", Parent = platformGroup }; platformGroup.AddChild(attack); }
private static void AddLandingBoxStub(ImageFrame frame) { var landingGroup = new PolygonGroup { Name = "Landing", Parent = frame }; landingGroup.Initialize(); frame.AddChild(landingGroup); var attack = new Polygon { Name = "Polygon 1", Parent = landingGroup}; landingGroup.AddChild(attack); }
private static void AddDefaultFootBox(ImageFrame frame) { var footGroup = new PolygonGroup { Name = "Foot", Parent = frame }; footGroup.Initialize(); frame.AddChild(footGroup); var foot = new Polygon { Name = "Foot", Parent = footGroup }; var bottom = frame.TrimRectangle.Bottom - 1; var left = frame.TrimRectangle.Left; var right = frame.TrimRectangle.Right; var width = frame.TrimRectangle.Width; var tl = new PolyPoint(left + (int)(width * 0.25f), bottom - 2) { Parent = foot }; var tr = new PolyPoint(right - (int)(width * 0.25f), bottom - 2) { Parent = foot }; var br = new PolyPoint(right - (int)(width * 0.25f), bottom) { Parent = foot }; var bl = new PolyPoint(left + (int)(width * 0.25f), bottom) { Parent = foot }; foot.AddChild(tl); foot.AddChild(tr); foot.AddChild(br); foot.AddChild(bl); footGroup.AddChild(foot); }
private static void AddDefaultDepthBox(ImageFrame frame) { var depthGroup = new PolygonGroup { Name = "Depth", Parent = frame }; depthGroup.Initialize(); frame.AddChild(depthGroup); var depth = new Polygon { Name = "Depth", Parent = depthGroup }; var bottom = frame.TrimRectangle.Bottom - 1; var left = frame.TrimRectangle.Left; var right = frame.TrimRectangle.Right; var width = frame.TrimRectangle.Width; var defaultDepthPercentage = (int)(frame.TrimRectangle.Height * 0.125f); const float defaultWidthBorder = 0.9f; // 10% on each side = 80% var tl = new PolyPoint(left + (int)(width * defaultWidthBorder), bottom - defaultDepthPercentage) { Parent = depth }; var tr = new PolyPoint(right - (int)(width * defaultWidthBorder), bottom - defaultDepthPercentage) { Parent = depth }; var br = new PolyPoint(right - (int)(width * defaultWidthBorder), bottom) { Parent = depth }; var bl = new PolyPoint(left + (int)(width * defaultWidthBorder), bottom) { Parent = depth }; depth.AddChild(tl); depth.AddChild(tr); depth.AddChild(br); depth.AddChild(bl); depthGroup.AddChild(depth); }
private static void AddBodyTrace(ImageFrame frame) { using (var ms = new MemoryStream(frame.Data)) { var imageBitmap = Image.FromStream(ms); var errorBuilder = new StringBuilder(); var bodyGroup = new PolygonGroup { Name = "Body", Parent = frame }; bodyGroup.Initialize(); frame.AddChild(bodyGroup); var shape = TraceService.CreateSimpleShape(imageBitmap, 200, errorBuilder); if (shape == null) { frame.FailsAutoTrace = true; return; } var count = 1; foreach (var polygon in shape.Vertices) { var poly = new Polygon { Name = "Polygon " + count, Parent = bodyGroup }; foreach (var point in polygon) { var x = (int)ConvertUnits.ToDisplayUnits(point.X); var y = (int)ConvertUnits.ToDisplayUnits(point.Y); x += (int)(frame.Width * 0.5f); y += (int)(frame.Height * 0.5f); poly.AddChild(new PolyPoint(x, y) { Parent = poly }); } bodyGroup.AddChild(poly); count++; } } }
private static void AddAttackBoxStub(ImageFrame frame) { var attackGroup = new PolygonGroup { Name = "Attack", Parent = frame}; attackGroup.Initialize(); frame.AddChild(attackGroup); var attack = new Polygon { Name = "Polygon 1", Parent = attackGroup }; attackGroup.AddChild(attack); }
private static void TransformPolygon(NodeWithName @group, IEnumerable<Vector2> points, string name) { var poly = new Polygon {Name = name, Parent = @group}; foreach (var point in points) { var x = ConvertUnits.ToDisplayUnits(point.X); var y = ConvertUnits.ToDisplayUnits(point.Y); poly.AddChild(new PolyPoint((int) x, (int) y) {Parent = poly}); } @group.AddChild(poly); }