Exemplo n.º 1
0
        public Bone(Bone parent, double angle, double length, PointF shift)
        {
            if (parent == null)
            {
                throw new Exception("Родительская кость не может быть null");
            }

            Bone root = parent.FindRoot();
            uint id = (uint)root.GetAllChildrenCount();
            while (root.IdentificatorExists(id))
            {
                id++;
            }

            this.ID = id;

            this.IsRoot = false;
            this.Parent = parent;
            parent.children.Add(this);
            this.Angle = angle;
            this.Length = length;
            this.Shift = shift;
            this.Visible = true;
            Name = "Новая кость";
        }
Exemplo n.º 2
0
 public static void DrawBones(Bone start, Graphics graph, PointF p0)
 {
     DrawBone(start, graph, p0);
     for (int i = 0; i < start.Children.Count; i++)
     {
         DrawBones(start.Children[i], graph, p0);
     }
 }
Exemplo n.º 3
0
        public static void DrawBone(Bone b, Graphics graph, PointF rootPos, bool selected = false)
        {
            if (b.IsRoot)
            {
                if (selected)
                {
                    graph.DrawEllipse(Pens.Orange, rootPos.X - 30, rootPos.Y - 30, 60, 60);
                }
                else
                {
                    graph.DrawEllipse(Pens.Black, rootPos.X - 30, rootPos.Y - 30, 60, 60);
                }
            }
            else
            {
                PointV p0 = new PointV(b.StartPoint);
                PointV p3 = new PointV(b.EndPoint);
                PointV p1 = p3 - p0;
                PointV p2 = p1.Rotate(-0.2745);
                p1 = p1.Rotate(0.2745);
                p2.Length = p2.Length * 0.2;
                p1.Length = p1.Length * 0.2;
                p2 = p2 + p0;
                p1 = p1 + p0;
                Pen pen0 = new Pen(Color.Black);
                Brush brush0 = new SolidBrush(Color.FromArgb(180, Color.DarkGray));
                Pen pen1 = new Pen(Color.Black);
                pen1.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                PointF[] pts = new PointF[] { p0.Add(rootPos).Point, p1.Add(rootPos).Point,
                        p3.Add(rootPos).Point, p2.Add(rootPos).Point };
                if (selected)
                {
                    brush0 = new SolidBrush(Color.FromArgb(180, Color.Orange));
                    pen1.Color = Color.Orange;
                    pen0.Color = Color.Orange;
                    graph.DrawPolygon(pen0, pts);
                    graph.FillPolygon(brush0, pts);
                    graph.DrawLine(pen1, PointV.Add(rootPos, b.StartPoint), PointV.Add(rootPos, b.Parent.EndPoint));

                }
                else
                {
                    graph.DrawPolygon(pen0, pts);
                    graph.FillPolygon(brush0, pts);
                    graph.DrawLine(pen1, PointV.Add(rootPos, b.StartPoint), PointV.Add(rootPos, b.Parent.EndPoint));
                }

            }
        }
Exemplo n.º 4
0
        public static void DrawBone(Bone bone, Graphics graph, PointF p0)
        {
            if (bone.IsRoot)
            {
                graph.DrawEllipse(Pens.Orange, p0.X - 6, p0.Y - 6, 12, 12);
                return;
            }
            PointF ps = bone.StartPoint, pe = bone.EndPoint;

            ps = new PointF(ps.X + p0.X, ps.Y + p0.Y);
            pe = new PointF(pe.X + p0.X, pe.Y + p0.Y);
            Pen pen = Pens.Black;
            pen.Width = 3;
            graph.DrawLine(pen, ps, pe);            
            graph.DrawEllipse(pen, ps.X - 4, ps.Y - 4, 8, 8);
            graph.DrawEllipse(pen, ps.X - 2, ps.Y - 2, 4, 4);            
        }
Exemplo n.º 5
0
        internal Bone(Bone parent, double angle, double length, PointF shift, string name, uint id)
        {
            if (parent == null)
            {
                throw new Exception("Родительская кость не может быть null");
            }

            this.ID = id;

            this.IsRoot = false;
            this.Parent = parent;
            parent.children.Add(this);
            this.Angle = angle;
            this.Length = length;
            this.Shift = shift;
            this.Visible = true;
            Name = name;
        }
Exemplo n.º 6
0
        public static void DrawControls(Graphics graph, PointF rootPos, Bone b, DrawParametres p)
        {
            PointV p0 = new PointV(b.StartPoint);
            PointV p3 = new PointV(b.EndPoint);
            PointV p1;
            PointV p2;
            Pen gpen = new Pen(Color.Blue);
            gpen.Width = 2f;
            gpen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            if (b is BoneGraphics)
            {
                PointF pp = b.ParentPoint;
                graph.DrawEllipse(Pens.Blue, pp.X - 3, pp.Y - 3, 6, 6);
                float psize = 5;
                p1 = p0.Add(rootPos);
                graph.DrawLine(Pens.Blue, (float)p1.X, (float)p1.Y - psize, (float)p1.X, (float)p1.Y + psize);
                graph.DrawLine(Pens.Blue, (float)p1.X - psize, (float)p1.Y, (float)p1.X + psize, (float)p1.Y);
                graph.DrawLine(gpen, p0.Add(rootPos), p3.Add(rootPos));

            }
            if (b is BoneImage)
            {
                PointF pp = b.ParentPoint;
                graph.DrawEllipse(Pens.Blue, pp.X - 3, pp.Y - 3, 6, 6);
                float psize = 5;
                p1 = p0.Add(rootPos);
                graph.DrawLine(Pens.Green, (float)p1.X, (float)p1.Y - psize, (float)p1.X, (float)p1.Y + psize);
                graph.DrawLine(Pens.Green, (float)p1.X - psize, (float)p1.Y, (float)p1.X + psize, (float)p1.Y);
                gpen.Color = Color.Green;
                graph.DrawLine(gpen, p0.Add(rootPos), p3.Add(rootPos));
                p1 = p3 - p0;
                p2 = p1.Rotate(Math.PI / 2);
                p1.Length = (b as BoneImage).Image.Height;
                p2.Length = (b as BoneImage).Image.Width;
                graph.DrawPolygon(Pens.Green, new PointF[]{
                    p0.Add(rootPos),
                    p0.Add(p2).Add(rootPos) ,
                    p0.Add(p1).Add(p2).Add(rootPos)  ,
                    p0.Add(p1).Add(rootPos)

                });
            }

            if ((p & DrawParametres.DrawAngleCtl) == DrawParametres.DrawAngleCtl ||
                        (p & DrawParametres.DrawFreeEditCtl) == DrawParametres.DrawFreeEditCtl)
            {
                Pen pen = new Pen(Color.Green);
                int r = 20;
                pen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
                pen.Width = 5f;
                p2 = p3 - p0;
                p2.Length = p2.Length - r;
                p2 = p2.Add(rootPos).Add(p0);
                float k = (float)(180 / Math.PI);
                graph.DrawArc(pen, new RectangleF((float)p2.X - r, (float)p2.Y - r, r * 2, r * 2),
                  (float)b.AbsoluteAngle * k, 90);
                graph.DrawArc(pen, new RectangleF((float)p2.X - r, (float)p2.Y - r, r * 2, r * 2),
                  (float)b.AbsoluteAngle * k, -90);
            }
            if ((p & DrawParametres.DrawShiftCtl) == DrawParametres.DrawShiftCtl)
            {
                int padding = 4;
                int length = 16;
                Pen pen = new Pen(Color.Blue);
                pen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
                pen.Width = 5f;
                p2 = p0.Add(rootPos);
                graph.DrawLine(pen, (float)p2.X, (float)p2.Y + padding, (float)p2.X, (float)p2.Y + padding + length);
                graph.DrawLine(pen, (float)p2.X, (float)p2.Y - padding, (float)p2.X, (float)p2.Y - padding - length);
                graph.DrawLine(pen, (float)p2.X + padding, (float)p2.Y, (float)p2.X + padding + length, (float)p2.Y);
                graph.DrawLine(pen, (float)p2.X - padding, (float)p2.Y, (float)p2.X - padding - length, (float)p2.Y);
            }
            if ((p & DrawParametres.DrawStretchCtl) == DrawParametres.DrawStretchCtl ||
                (p & DrawParametres.DrawFreeEditCtl) == DrawParametres.DrawFreeEditCtl)
            {
                int padding = 4;
                int length = 20;
                Pen pen = new Pen(Color.Blue);
                pen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
                pen.Width = 5f;
                p2 = p3 - p0;
                p1 = p3 - p0;
                p2.Length = length;
                p1.Length = padding;

                graph.DrawLine(pen, p1.Add(rootPos).Add(p3).Point, p2.Add(rootPos).Add(p3).Point);
                p1 = p1.Rotate(Math.PI);
                p2 = p2.Rotate(Math.PI);
                graph.DrawLine(pen, p1.Add(rootPos).Add(p3).Point, p2.Add(rootPos).Add(p3).Point);
            }
        }
Exemplo n.º 7
0
 public void RemoveBone(Bone b)
 {
     if (parentBoneNode != null)
     {
         TreeNode[] nodes = parentBoneNode.Nodes.Find("bone" + bones.IndexOf(b), true);
         if (nodes.Length > 0)
         {
             nodes[0].Remove();
         }
     }
     if (bonesTree != null)
     {
         TreeNode[] nodes = bonesTree.Nodes.Find("bone" + bones.IndexOf(b), true);
         if (nodes.Length > 0)
         {
             nodes[0].Remove();
         }
     }
     RemoveSubBones(b);
     bones.Remove(b);
     b.Remove();
     Redraw();
 }
Exemplo n.º 8
0
        private static void ReadBone(Bone parent, BinaryReader reader)
        {
            string name = reader.ReadString() ;
            uint id = reader.ReadUInt32();
            bool isRoot = reader.ReadBoolean();
            if (isRoot)
            {
                throw new Exception("Неожиданная ошибка при чтении файла: не корневая кость помечена, как корневая");
            }
            double angle = reader.ReadDouble();
            double length = reader.ReadDouble();
            float sx = reader.ReadSingle();
            float sy = reader.ReadSingle();
            Bone bone = new Bone(parent, angle, length, new System.Drawing.PointF(sx, sy), name, id);
            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                ReadBone(bone, reader);
            }
        }
Exemplo n.º 9
0
 public void SetParent(Bone bone)
 {
     this.Parent = bone;
     
 }
Exemplo n.º 10
0
        void picBox_MouseClick(object sender, MouseEventArgs e)
        {
            if (picLostFocus)
            {
                picLostFocus = false;
                return;
            }

            if (SelectMode == SelectModes.None)
                return;

            PointF loc = e.Location;
            if (editMode == EditModes.None &&  (SelectMode & SelectModes.Bones) > 0)
            {
                selectedBone = null;
                ToRootBoneCoordinates(ref loc);
                double min = 100;
                int mini = -1;
                double dst = 0;
                for (int i = 0; i < bones.Count; i++)
                {
                    if ((dst = Math.Abs(VMath.GetDistance(bones[i].StartPoint, bones[i].EndPoint, loc))) < min)
                    {
                        min = dst;
                        mini = i;
                    }
                    /*if (VMath.CheckDistance(bones[i].StartPoint, bones[i].EndPoint, loc, 20, true))
                    {
                        selectedBone = bones[i];

                        break;
                    }*/
                }
                if (mini >= 0)
                {
                    selectedBone = bones[mini];
                    if (parentBoneNode != null)
                    {
                        TreeNode[] snodes = parentBoneNode.Nodes.Find("bone" + mini, true);
                        if (snodes != null && snodes.Length>0)
                        {
                            snodes[0].TreeView.SelectedNode = snodes[0];
                            snodes[0].EnsureVisible();

                        }
                    }
                    if (bonesTree != null)
                    {
                        TreeNode[] snodes = bonesTree.Nodes.Find("bone" + mini, true);
                        if (snodes != null && snodes.Length > 0)
                        {
                            snodes[0].TreeView.SelectedNode = snodes[0];
                        }
                    }

                }
            }
            Redraw();
        }
Exemplo n.º 11
0
 public Bone AddBone(Bone b)
 {
     b = b.AddChild();
     bones.Add(b);
     if (bonesTree != null)
     {
         TreeNode[] pnodes = bonesTree.Nodes.Find("bone" + bones.IndexOf(b.Parent), true);
         if (pnodes != null)
         {
             TreeNode n = pnodes[0].Nodes.Add("bone" + bones.IndexOf(b), b.Name);
             n.ImageKey = "bone";
             n.SelectedImageKey = "bone";
             n.Tag = b;
             bonesTree.SelectedNode = n;
         }
     }
     if (parentBoneNode != null)
     {
         TreeNode[] pnodes = parentBoneNode.Nodes.Find("bone" + bones.IndexOf(b.Parent), true);
         if (pnodes != null)
         {
             TreeNode n = pnodes[0].Nodes.Add("bone" + bones.IndexOf(b), b.Name);
             n.ImageKey = "bone";
             n.SelectedImageKey = "bone";
             n.Tag = b;
             parentBoneNode.TreeView.SelectedNode = n;
         }
     }
     return b;
 }
Exemplo n.º 12
0
 void bonesTree_AfterSelect(object sender, TreeViewEventArgs e)
 {
     selectedBone = null;
     if (e.Node.Tag as Bone == null)
         return;
     selectedBone = (Bone)e.Node.Tag;
     Redraw();
 }
Exemplo n.º 13
0
 void mainTree_AfterSelect(object sender, TreeViewEventArgs e)
 {
     if (e.Node.Tag as Bone != null)
     {
         selectedBone = (Bone)e.Node.Tag;
     }
     Redraw();
 }
Exemplo n.º 14
0
 public void AddGraphics(Bone bone)
 {
     BoneGraphics bg;
     Character.GraphicsManager.Add(bg = new BoneGraphics(Character));
     bg.SetParent(bone);
     if (parentImageNode == null)
         return;
     TreeNode node = parentImageNode.Nodes.Add("boneGraphics" + (Character.GraphicsManager.Count - 1),
         bone.Name + " graphics " + (Character.GraphicsManager.Count - 1), "graphics");
     node.SelectedImageKey = "graphics";
     node.Tag = bg;
     node.EnsureVisible();
 }
Exemplo n.º 15
0
 private static void LoadV1(Character ch, BinaryReader reader)
 {
     ch.Name = reader.ReadString();
     ch.Author = reader.ReadString();
     ch.Description = reader.ReadString();
     //root bone read
     Bone root = new Bone();
     root.Name = reader.ReadString();
     uint id = reader.ReadUInt32();
     bool isroot = reader.ReadBoolean();
     if (!isroot)
     {
         throw new Exception("Неожиданная ошибка при чтении файла: первая кость не помечена, как корневая");
     }
     ch.RootBone = root;
     int children = reader.ReadInt32();
     for (int i = 0; i < children; i++)
     {
         ReadBone(root, reader);
     }
 }
Exemplo n.º 16
0
 public void LoadCharacter(Character ch)
 {
     Character = ch;
     root = ch.RootBone;
     bones.Clear();
     bones.Add(root);
     AddSubBones(root);
     RefreshBonesNode();
     RefreshBonesTree();
     Redraw();
 }
Exemplo n.º 17
0
        public void FillBoneNode(Bone bone, TreeNode node)
        {
            TreeNode n;
            foreach (Bone b in bone.Children)
            {
                n = node.Nodes.Add("bone" + bones.IndexOf(b,0), b.Name);
                n.ImageKey = "bone";
                n.SelectedImageKey = "bone";
                n.Tag = b;

                FillBoneNode(b, n);
            }
        }
Exemplo n.º 18
0
 public void ExtractBone(Bone b)
 {
     throw new Exception("Not implemented exception");
 }
Exemplo n.º 19
0
 public void DrawBone(Bone b)
 {
     BoneDrawer.DrawBone(b, graph, PointV.Add(ref rootPos, ref screenCenter), b == selectedBone);
     for (int i = 0; i < b.Children.Count; i++)
     {
         DrawBone(b.Children[i]);
     }
 }
Exemplo n.º 20
0
 public void AddSubBones(Bone b)
 {
     for (int i = 0; i < b.Children.Count; i++)
     {
         bones.Add(b.Children[i]);
         AddSubBones(b.Children[i]);
     }
 }
Exemplo n.º 21
0
 protected void RemoveSubBones(Bone b)
 {
     foreach (Bone bone in b.Children)
     {
         bones.Remove(bone);
         RemoveSubBones(bone);
     }
 }
Exemplo n.º 22
0
 protected void WriteBone(Bone b, BinaryWriter writer)
 {
     if (b.Name == null)
         b.Name = "";
     writer.Write(b.Name);
     writer.Write(b.ID);
     writer.Write(b.IsRoot);
     if (!b.IsRoot)
     {
         writer.Write(b.Angle);
         writer.Write(b.Length);
         writer.Write(b.Shift.X);
         writer.Write(b.Shift.Y);
     }
     writer.Write(b.Children.Count);
     for (int i = 0; i < b.Children.Count; i++)
     {
         WriteBone(b.Children[i], writer);
     }
 }