Exemplo n.º 1
0
    public void AttachAppendage(Appendage attachment, string linkPointID)
    {
        if (!_linkPoints.ContainsKey(linkPointID))
        {
            Debug.LogError($"'{linkPointID}' is not a valid attachment point!");
            return;
        }
        if (attachment == null)
        {
            RemoveAppendage(linkPointID);
            return;
        }
        if (_linkPoints[linkPointID].AttachedItem != null)
        {
            RemoveAppendage(linkPointID);
        }

        LinkPoint linkPoint = _linkPoints[linkPointID];

        attachment.transform.SetParent(linkPoint.transform, false);
        attachment.transform.localPosition = Vector3.zero;
        attachment.transform.localRotation = Quaternion.Euler(0, Random.Range(0, 360f), 0);
        linkPoint.SetAttachedItem(attachment);
        attachment.OnAttached(_rigidbody);
    }
Exemplo n.º 2
0
 //picture box mouse up event
 private void pictureBox_MouseUp(object sender, MouseEventArgs e)
 {
     // stop block moving
     if (e.Button == MouseButtons.Middle && selected != null)
     {
         scrollDown = false;
         selected.SetLayout(selected.X > pictureBox.Image.Width ? pictureBox.Image.Width : selected.X, selected.Y > pictureBox.Image.Height ? pictureBox.Image.Height : selected.Y);
         selected.SetLayout(selected.X < 0 ? 0 : selected.X, selected.Y < 0 ? 0 : selected.Y);
     }
     // check and create link
     else if (e.Button == MouseButtons.Left && selectedLinkPoint != null && button == linkButton)
     {
         LinkPoint x;
         foreach (Block block in blockList)
         {
             if ((x = block.CheckPoint(e.X, e.Y, true)) != null)
             {
                 if (x.Block != selectedLinkPoint.Block)
                 {
                     Link link = new Link(selectedLinkPoint, x);
                     selectedLinkPoint.SetLink(link);
                     x.SetLink(link);
                 }
             }
         }
         selectedLinkPoint = null;
         linking           = false;
     }
     // reselect if was selected
     if (selected != null)
     {
         selected.Select();
     }
     RefreshScheme();
 }
Exemplo n.º 3
0
 // sets link point which draw link during drawing
 public void ChangeDrawingLinkPoint(LinkPoint linkPoint)
 {
     if (linkPoint == from)
     {
         to.DeleteDrawingLinkPoint();
     }
     else
     {
         from.DeleteDrawingLinkPoint();
     }
 }
Exemplo n.º 4
0
        public void SetChannelsCount(int chanCount)
        {
            while (_Links.Count > chanCount)
            {
                var pair = _Links[_Links.Count - 1];
                _Links.RemoveAt(_Links.Count - 1);

                var tp  = pair.Item1;
                var lbl = pair.Item2;

                tp.Unlink();

                Controls.Remove(tp);
                Controls.Remove(lbl);
            }

            while (_Links.Count < chanCount)
            {
                var i = _Links.Count;

                var tp = new LinkPoint()
                {
                    Direction = enLinkDirection.Input,
                    LinkType  = enLinkType.Axle,
                    Left      = -3,
                    Top       = 19 * i + 32,
                    Name      = "LNK_IN_" + _ModeNumber + "_" + i
                };

                var lbl = new Label()
                {
                    Text = "Channel " + (i + 1),
                    Left = tbName.Left,
                    Top  = 31 + 19 * i
                };

                Controls.Add(tp);
                Controls.Add(lbl);

                _Links.Add(new Tuple <LinkPoint, Label>(tp, lbl));
            }

            Height = 35 + _Links.Count * 19;
        }
Exemplo n.º 5
0
 public void BeforeMoveVGuide(int guide)
 {
     FGuideLinks.Clear();
     foreach (Base obj in Designer.Objects)
     {
         if (obj is ReportComponentBase && !(obj is BandBase))
         {
             ReportComponentBase c    = obj as ReportComponentBase;
             LinkPoint           link = LinkPoint.None;
             if (Math.Abs(c.Left - Page.Guides[guide]) < 0.01)
             {
                 link = LinkPoint.Left;
             }
             else if (Math.Abs(c.Right - Page.Guides[guide]) < 0.01)
             {
                 link = LinkPoint.Right;
             }
             if (link != LinkPoint.None)
             {
                 LinkInfo info = new LinkInfo();
                 info.Obj  = c;
                 info.Link = link;
                 // check if object is also linked to another guide
                 int i = Page.Guides.IndexOf(c.Left);
                 if (i != -1 && i != guide)
                 {
                     info.DoubleLinked = true;
                 }
                 i = Page.Guides.IndexOf(c.Right);
                 if (i != -1 && i != guide)
                 {
                     info.DoubleLinked = true;
                 }
                 FGuideLinks.Add(info);
             }
         }
     }
 }
Exemplo n.º 6
0
 public void BeforeMoveHGuide(BandBase band, int guide)
 {
     FGuideLinks.Clear();
     foreach (Base obj in Designer.Objects)
     {
         if (obj is ReportComponentBase && !(obj is BandBase) && obj.Parent == band)
         {
             ReportComponentBase c    = obj as ReportComponentBase;
             LinkPoint           link = LinkPoint.None;
             if (Math.Abs(c.Top - band.Guides[guide]) < 0.01)
             {
                 link = LinkPoint.Top;
             }
             else if (Math.Abs(c.Bottom - band.Guides[guide]) < 0.01)
             {
                 link = LinkPoint.Bottom;
             }
             if (link != LinkPoint.None)
             {
                 LinkInfo info = new LinkInfo();
                 info.Obj  = c;
                 info.Link = link;
                 // check if object is also linked to another guide
                 int i = band.Guides.IndexOf(c.Top);
                 if (i != -1 && i != guide)
                 {
                     info.DoubleLinked = true;
                 }
                 i = band.Guides.IndexOf(c.Bottom);
                 if (i != -1 && i != guide)
                 {
                     info.DoubleLinked = true;
                 }
                 FGuideLinks.Add(info);
             }
         }
     }
 }
Exemplo n.º 7
0
        private static void LoadBaseSceneItem(XmlNode node, object item)
        {
            TraceLogger.TraceInfo("Beginning Serialize Base Scene Item");
            XmlNode nd = node.Attributes.GetNamedItem("name");
            ((SceneItem)item).Name = node.Attributes["name"].InnerText;
            foreach (XmlNode _siNode in node.ChildNodes)
            {
                PropertyInfo _prop = item.GetType().GetProperty(_siNode.Name);
                if (_prop != null)
                {
                    string t = _prop.PropertyType.Name;
                    if (_prop.PropertyType.IsGenericType)
                    {
                        if (_prop.Name == "SourceRectangle")
                        {
                            SetProperty(_prop.Name, item, node);
                        }
                        if (_prop.Name == "LinkPoints")
                        {
                            #region LinkPoints

                            XmlNode _node = node.SelectSingleNode("LinkPoints");
                            List<LinkPoint> _linkpnts = new List<LinkPoint>();
                            foreach (XmlNode _compNode in _node.ChildNodes)
                            {
                                LinkPoint linkPoint = new LinkPoint();
                                foreach (XmlNode nd1 in _compNode)
                                {
                                    SetProperty(nd1.Name, linkPoint, _compNode);
                                }
                                XmlNode _mounts = _compNode.SelectSingleNode("Mounts");
                                if (_mounts != null)
                                {
                                    foreach (XmlNode mount in _mounts)
                                    {
                                        linkPoint.Mounts.Add(
                                            mount.SelectSingleNode("ChildSceneItem").InnerText,
                                            mount.SelectSingleNode("ChildLinkPoint").InnerText);
                                    }
                                }
                                linkPoint.Owner = item as SceneItem;
                                _linkpnts.Add(linkPoint);
                            }
                            if (_linkpnts.Count > 0)
                            {
                                _prop.SetValue(item, _linkpnts, null);
                            }

                            #endregion
                        }
                        if (_prop.Name == "Components")
                        {
                            #region Components

                            XmlNode _node = node.SelectSingleNode("Components");
                            List<IceComponent> _components = new List<IceComponent>();
                            foreach (XmlNode _compNode in _node.ChildNodes)
                            {
                                TraceLogger.TraceInfo("Load Component");
                                TraceLogger.TraceInfo(_compNode.Name);
                                Components.IceComponent _comp = CreateComponentInstance(_compNode.Name);
                                if (_comp == null)
                                    TraceLogger.TraceWarning("Couldnt Find Component (" + _compNode.Name + ")");
                                else
                                {
                                    foreach (XmlNode nd1 in _compNode)
                                    {
                                        SetProperty(nd1.Name, _comp, _compNode);
                                    }
                                    if (_comp != null)
                                    {
                                        _comp.SetOwner((SceneItem)item);
                                        _components.Add(_comp);
                                    }
                                }
                            }
                            _prop.SetValue(item, _components, null);

                            #endregion
                        }
                    }
                    else
                    {
                        SetProperty(_prop.Name, item, node);
                    }
                }
                else if (_siNode.Name.ToUpper() == "MOUNTS")
                {
                    #region Mounts
                    XmlNode _node = node.SelectSingleNode("Mounts");
                    //List<LinkPoint> _linkpnts = new List<LinkPoint>();
                    foreach (XmlNode _compNode in _node.ChildNodes)
                    {
                        SceneItem it = (SceneItem)item;
                        string itemName = "";
                        bool isTemplate = false;

                        XmlAttribute b = _compNode.Attributes["sceneItemRef"];
                        if (b == null)
                        {
                            isTemplate = true;
                            itemName = _compNode.Attributes["templateItemRef"].InnerText;
                        }
                        else
                            itemName = b.InnerText;


                        it.Mount(itemName,
                        _compNode.Attributes["targetLink"].InnerText,
                        _compNode.Attributes["sourceLink"].InnerText,
                        isTemplate);

                    }
                    #endregion
                }

            }
            TraceLogger.TraceInfo("Ending Serialize Base Scene Item");
        }
Exemplo n.º 8
0
 public Link(LinkPoint from, LinkPoint to)
 {
     this.from = from;
     this.to   = to;
 }
Exemplo n.º 9
0
        // load scheme event
        private void LoadScheme_Click(object sender, EventArgs e)
        {
            var fileContent = string.Empty;
            var filePath    = string.Empty;

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = "c:\\";
                openFileDialog.Filter           = "diag files (*.diag)|*.diag";
                openFileDialog.FilterIndex      = 2;
                openFileDialog.RestoreDirectory = true;
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    //Get the path of specified file
                    filePath = openFileDialog.FileName;
                    //Read the contents of the file into a stream
                    int width      = 0;
                    int height     = 0;
                    var fileStream = openFileDialog.OpenFile();
                    //create binary formater and deserialize
                    BinaryFormatter binaryFormatter = new BinaryFormatter();
                    using (StreamReader reader = new StreamReader(fileStream))
                    {
                        try
                        {
                            blockList = (List <Block>)binaryFormatter.Deserialize(fileStream);
                            width     = (int)binaryFormatter.Deserialize(fileStream);
                            height    = (int)binaryFormatter.Deserialize(fileStream);
                        }
                        catch (Exception)
                        {
                            //message after fail deserialization
                            MessageBox.Show(resourceManager.GetString("LoadFail"));
                            return;
                        }
                        //reset aplication setup
                        textSelectedBlock.Enabled = false;
                        textSelectedBlock.Text    = "";
                        xDis              = 0; yDis = 0;
                        scrollDown        = false;
                        selected          = null;
                        pictureBoxImage   = null;
                        linking           = false;
                        selectedLinkPoint = null;
                        foreach (Block block in blockList)
                        {
                            if (block.IsSelected())
                            {
                                selected = block;
                                textSelectedBlock.Text    = selected.GetText();
                                textSelectedBlock.Enabled = textSelectedBlock.Enabled = (selected.GetType().Name == "DecidingBlock" || selected.GetType().Name == "OperatingBlock");
                            }
                        }
                        ClearPictureBoxPanel();
                        pictureBox = NewSchemeCanvas(width, height);
                        canvas     = Graphics.FromImage(pictureBox.Image);
                        pictureBoxPanel.Controls.Add(pictureBox);
                        RefreshScheme();
                        fileContent = reader.ReadToEnd();
                        //message after property deserialization
                        MessageBox.Show(resourceManager.GetString("LoadSucces"));
                    }
                }
            }
        }
Exemplo n.º 10
0
 // picture box mouse down event
 private void pictureBox_MouseDown(object sender, MouseEventArgs e)
 {
     // disable buttons during block moving
     if (scrollDown)
     {
         return;
     }
     // if block has to start moving
     if (e.Button == MouseButtons.Middle && selected != null && !linking)
     {
         scrollDown      = true;
         pictureBoxImage = CreateImageWithoutSelectedBlock(selected);
         xDis            = selected.X - e.X;
         yDis            = selected.Y - e.Y;
     }
     // (un)select block
     if (e.Button == MouseButtons.Right)
     {
         SelectBlock(e.X, e.Y);
         RefreshScheme();
         pictureBoxImage = (Image)pictureBox.Image.Clone();
     }
     // left click mouse interaction
     if (e.Button == MouseButtons.Left)
     {
         // create operation block
         if (button == OperationBoxButton)
         {
             canvas = Graphics.FromImage(pictureBox.Image);
             OperatingBlock bloc = new OperatingBlock(e.X, e.Y, resourceManager.GetString("OperationBlock"));
             bloc.Draw(canvas);
             blockList.Add(bloc);
         }
         // create decide block
         else if (button == DecidingBoxButton)
         {
             canvas = Graphics.FromImage(pictureBox.Image);
             DecidingBlock bloc = new DecidingBlock(e.X, e.Y, resourceManager.GetString("DecideBlock"));
             bloc.Draw(canvas);
             blockList.Add(bloc);
         }
         // create start block
         else if (button == startBoxButton)
         {
             if (FindNearestBlock((Block b) =>
             {
                 if (b.GetType().Name == "StartBlock")
                 {
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }, blockList, e.X, e.Y) == null)
             {
                 // create
                 canvas = Graphics.FromImage(pictureBox.Image);
                 StartBlock bloc = new StartBlock(e.X, e.Y, resourceManager.GetString("StartBlock"));
                 bloc.Draw(canvas);
                 blockList.Add(bloc);
             }
             else
             {
                 // if already exist then show message
                 MessageBox.Show(resourceManager.GetString("DoubleStartBlockWarning"));
             }
         }
         //create end block
         else if (button == endBoxButton)
         {
             canvas = Graphics.FromImage(pictureBox.Image);
             EndBlock bloc = new EndBlock(e.X, e.Y, resourceManager.GetString("StopBlock"));
             bloc.Draw(canvas);
             blockList.Add(bloc);
         }
         // start link creating
         else if (button == linkButton)
         {
             LinkPoint x = null;
             foreach (Block block in blockList)
             {
                 if ((x = block.CheckPoint(e.X, e.Y, false)) != null)
                 {
                     selectedLinkPoint = x;
                 }
             }
             if (selectedLinkPoint != null)
             {
                 linking = true;
                 pictureBox.Refresh();
                 pictureBoxImage = (Image)pictureBox.Image.Clone();
             }
         }
         // delete block
         else if (button == deleteButton)
         {
             Block removed = FindNearestBlock((Block block) => block.Click(e.X, e.Y), blockList, e.X, e.Y);
             if (removed != null)
             {
                 textSelectedBlock.Enabled = false;
                 textSelectedBlock.Text    = "";
                 if (selected == removed)
                 {
                     selected = null;
                 }
                 removed.Remove();
                 blockList.Remove(removed);
             }
             RefreshScheme();
         }
     }
     pictureBox.Refresh();
 }
        /// <summary>
        /// Add a named link point with given position and rotation.  Position is in unscaled
        /// object space, so -1 to 1 ranges over the entire object (irrespective of Size).
        /// </summary>
        /// <param name="name">Name of new link point.</param>
        /// <param name="position">Link point position.</param>
        /// <param name="rotation">Link point rotation.</param>
        public void AddLinkPoint(string name, Vector2 position, float rotation)
        {
            // if we already have this one, just update it
            SList<LinkPoint> walk = _linkPoints;
            while (walk != null)
            {
                if (walk.Val.Name == name)
                {
                    walk.Val.Position.Value = position;
                    walk.Val.Rotation.Value = rotation;
                    return;
                }
                walk = walk.Next;
            }
            LinkPoint link = new LinkPoint();
            link.Name = name;
            link.Position = new ValueInPlaceInterface<Vector2>(position);
            link.Rotation = new ValueInPlaceInterface<float>(rotation);
            if (Owner != null)
            {
                Owner.RegisterInterface(this, link.Position);
                Owner.RegisterInterface(this, link.Rotation);
            }

            SList<LinkPoint>.InsertFront(ref _linkPoints, link);
        }
        public override void CopyTo(TorqueComponent obj)
        {
            base.CopyTo(obj);

            T2DLinkPointComponent obj2 = (T2DLinkPointComponent)obj;
            SList<LinkPoint> walk = _linkPoints;
            while (walk != null)
            {
                LinkPoint mp = new LinkPoint();
                mp.Name = walk.Val.Name;
                mp.Position = new ValueInPlaceInterface<Vector2>(walk.Val.Position.Value);
                mp.Rotation = new ValueInPlaceInterface<float>(walk.Val.Rotation.Value);
                SList<LinkPoint>.InsertFront(ref obj2._linkPoints, mp);
                walk = walk.Next;
            }
        }