Ejemplo n.º 1
0
        /// <summary>
        ///     Sets the switch.
        /// </summary>
        protected virtual void SetSwitch()
        {
#if DEBUG
            Console.WriteLine($"{this}: SetSwitch");
#endif
            this.Switch = new BoolSwitch(this.Menu, "Enabled", true, this);
        }
Ejemplo n.º 2
0
        protected override void OnDragDrop(DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(TreeNode)))
            {
                TreeNode   node            = (TreeNode)e.Data.GetData(typeof(TreeNode));
                SwitchBase sourceComponent = node.Tag as SwitchBase;
                if (sourceComponent != null)
                {
                    AddComponent(RenderingEngine, sourceComponent);
                }
            }
            else if (e.Data.GetDataPresent(typeof(ListViewItem)))
            {
                ListViewItem item     = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
                Variable     variable = item.Tag as Variable;
                if (variable != null)
                {
                    if (ModifierKeys == Keys.Control)
                    {
                        AddComponent(RenderingEngine, new SetterSwitch {
                            VariableKey = variable.Name
                        });
                    }
                    else
                    {
                        AddComponent(RenderingEngine, new GetterSwitch {
                            VariableKey = variable.Name
                        });
                    }
                }
            }

            base.OnDragDrop(e);
        }
Ejemplo n.º 3
0
 public void SetOutputValue(SwitchBase sw, DataContainer data)
 {
     foreach (var connection in FindInputs(sw))
     {
         connection.FromInputOutput.InputOutput.Data = data;
     }
 }
Ejemplo n.º 4
0
        private InputOutputSelector SetSelector(SwitchBase sw, InputOutputBase sourceIO)
        {
            var selector = new InputOutputSelector(sw, sourceIO);

            if (Input?.InputOutput is InputBase && sourceIO is OutputBase)
            {
                Output = selector;
            }

            if (Input?.InputOutput is OutputBase && sourceIO is InputBase)
            {
                Output = selector;
            }

            if (Output?.InputOutput is InputBase && sourceIO is OutputBase)
            {
                Input = selector;
            }

            if (Output?.InputOutput is OutputBase && sourceIO is InputBase)
            {
                Input = selector;
            }

            return(selector);
        }
Ejemplo n.º 5
0
        public void Draw(Graphics g, SwitchBase sw, DrawableBase parent, RenderingEngine e)
        {
            const float offset = 10;
            const float radius = 4;
            var         r      = sw.SelectionBounds;

            StringFormat format = new StringFormat();

            var textBounds = g.MeasureString(this.Title, FontTitle, r.Size, format);

            r = new RectangleF(r.X, r.Y - offset - textBounds.Height, r.Width, textBounds.Height);

            ExtendedGraphics extendedGraphics = new ExtendedGraphics(g, e);

            var brush = GetMainBrush(r);

            extendedGraphics.FillRoundRectangle(brush, r.X, r.Y, r.Width, r.Height, radius);
            extendedGraphics.DrawRoundRectangle(Pen, r.X, r.Y, r.Width, r.Height, radius);

            r = new RectangleF(r.X + 4, r.Y, r.Width, r.Height);

            var r1 = new RectangleF(r.X + 0.5f, r.Y + 0.5f, r.Width, r.Height);
            var r2 = new RectangleF(r.X, r.Y, r.Width, r.Height);

            g.DrawString(Title, FontTitle, Brushes.Black, r1, format);
            g.DrawString(Title, FontTitle, Brushes.White, r2, format);
        }
Ejemplo n.º 6
0
 public void FinishContextAction(bool canceled, SwitchBase createSwitch)
 {
     if (canceled || !InputOutputAvailable)
     {
         OnInComplete();
     }
     else
     {
         List <InputOutputBase> inputOutputs = new List <InputOutputBase>();
         if (Input != null)
         {
             inputOutputs.AddRange(createSwitch.Outputs);
         }
         else
         {
             inputOutputs.AddRange(createSwitch.Inputs);
         }
         var matchingIo = inputOutputs.FirstOrDefault(x => x.Signature.Matches(SelectedInputOutput.InputOutput.Signature));
         if (matchingIo != null)
         {
             SetSelector(createSwitch, matchingIo);
             OnCompleted();
         }
         else
         {
             OnInComplete();
         }
     }
     FinishContextActionIntern();
 }
Ejemplo n.º 7
0
        public SwitchBase AddComponent(SwitchBase sourceComponent, PointF pt)
        {
            SwitchBase switchBase = Activator.CreateInstance(sourceComponent.GetType()) as SwitchBase;

            if (sourceComponent is VariableSwitch && switchBase is VariableSwitch)
            {
                var variableComponent = switchBase as VariableSwitch;
                variableComponent.VariableKey = ((VariableSwitch)sourceComponent).VariableKey;
            }

            var sourcePrefabSwitch = sourceComponent as PrefabSwitch;

            if (sourcePrefabSwitch != null && switchBase is PrefabSwitch)
            {
                var prefabSwitch = switchBase as PrefabSwitch;
                prefabSwitch.Prefab = sourcePrefabSwitch.Prefab;
            }

            if (switchBase != null)
            {
                switchBase.Position = pt;
                CurrentProject.Add(this, switchBase);
                return(switchBase);
            }
            return(null);
        }
Ejemplo n.º 8
0
 public void Add(Engine renderingEngine, SwitchBase sw)
 {
     sw.Id = _currentSwitchId;
     ItemLookup.Add(_currentSwitchId, sw);
     Items.Add(sw);
     sw.Initialize(renderingEngine);
     _currentSwitchId++;
 }
Ejemplo n.º 9
0
 private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
 {
     SelectedSwitch = treeView.SelectedNode?.Tag as SwitchBase;
     if (SelectedSwitch != null)
     {
         lbSwitch.Text = $"Unique: {SelectedSwitch.UniqueName} -> Display:{SelectedSwitch.DisplayName}";
     }
     UpdateList();
 }
Ejemplo n.º 10
0
 public void Draw(Graphics g, SwitchBase sw, DrawableBase parent, RenderingEngine e)
 {
     if (Enabled)
     {
         if (Items.ContainsKey(sw.UniqueName) && sw.IsMouseOver)
         {
             Items[sw.UniqueName].Draw(g, sw, parent, e);
         }
     }
 }
Ejemplo n.º 11
0
        public void AddComponent(SwitchBase sourceComponent)
        {
            SwitchBase switchBase = Activator.CreateInstance(sourceComponent.GetType()) as SwitchBase;
            PointF     pt         = RenderingEngine.TranslatePoint(PointToClient(MousePosition)); // this.PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y)); //.Divide(CurrentProject.Zoom, CurrentProject.Zoom).Add(-CurrentProject.Translation.X, -CurrentProject.Translation.Y);

            if (switchBase != null)
            {
                switchBase.Position = pt;
                RenderingEngine.CurrentProject.Add(RenderingEngine, switchBase);
            }
        }
Ejemplo n.º 12
0
        public void DrawOutput(Graphics g, SwitchBase sw, int index, RenderingEngine e)
        {
            const float maxHelpHeight = 400;
            const float offsetWidth   = 5;
            const float offsetTextX   = 24;
            const float radius        = 4;

            var io = sw.OutputsSet[index];

            if (io.IsMouseOver)
            {
                var r        = io.DescriptionBounds;
                var swBounds = sw.DescriptionBounds;
                swBounds.Height = maxHelpHeight;
                StringFormat format = new StringFormat();

                var textBounds     = g.MeasureString(this.Title, FontTitle, swBounds.Size, format);
                var swSizeDesc     = new SizeF(240, swBounds.Height);
                var textDescBounds = g.MeasureString(this.Description, FontDescription, swSizeDesc, format);
                textDescBounds.Height = Math.Max(textDescBounds.Height, 8);

                var rText = new RectangleF(r.X + offsetTextX + swBounds.Width, r.Y, textBounds.Width + offsetWidth, textBounds.Height);
                var rDesc = new RectangleF(r.X + offsetTextX + swBounds.Width, r.Y + textBounds.Height + 2, textDescBounds.Width + offsetWidth, textDescBounds.Height);

                ExtendedGraphics extendedGraphics = new ExtendedGraphics(g, e);

                var brush     = GetMainBrush(rText);
                var brushDesc = GetMainBrush(rDesc);

                extendedGraphics.FillRoundRectangle(brush, rText.X, rText.Y, rText.Width, rText.Height, radius);
                extendedGraphics.DrawRoundRectangle(Pen, rText.X, rText.Y, rText.Width, rText.Height, radius);

                extendedGraphics.FillRoundRectangle(brushDesc, rDesc.X, rDesc.Y, rDesc.Width, rDesc.Height, radius);
                extendedGraphics.DrawRoundRectangle(Pen, rDesc.X, rDesc.Y, rDesc.Width, rDesc.Height, radius);

                rText = new RectangleF(rText.X + 4, rText.Y, rText.Width, rText.Height);
                rDesc = new RectangleF(rDesc.X + 4, rDesc.Y, rDesc.Width, rDesc.Height);

                var r1 = new RectangleF(rText.X - 1 + 0.5f, rText.Y + 0.5f, rText.Width, rText.Height);
                var r2 = new RectangleF(rText.X - 1, rText.Y, rText.Width, rText.Height);

                var r3 = new RectangleF(rDesc.X - 1 + 0.5f, rDesc.Y + 0.5f, rDesc.Width, rDesc.Height);
                var r4 = new RectangleF(rDesc.X - 1, rDesc.Y, rDesc.Width, rDesc.Height);

                g.DrawString(Title, FontTitle, Brushes.Black, r1, format);
                g.DrawString(Title, FontTitle, Brushes.White, r2, format);

                g.DrawString(Description, FontDescription, Brushes.Black, r3, format);
                g.DrawString(Description, FontDescription, Brushes.White, r4, format);
            }
        }
Ejemplo n.º 13
0
        protected override void OnDragDrop(DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(TreeNode)))
            {
                TreeNode   node            = (TreeNode)e.Data.GetData(typeof(TreeNode));
                SwitchBase sourceComponent = node.Tag as SwitchBase;
                if (sourceComponent != null)
                {
                    AddComponent(sourceComponent);
                }
            }

            base.OnDragDrop(e);
        }
Ejemplo n.º 14
0
        public void RemoveConnections(SwitchBase sw)
        {
            var outputs = Connections.Where(x => x.ToInputOutput.Origin == sw).ToList();
            var inputs  = Connections.Where(x => x.FromInputOutput.Origin == sw).ToList();

            foreach (var connection in outputs)
            {
                RemoveConnection(connection);
            }

            foreach (var connection in inputs)
            {
                RemoveConnection(connection);
            }
        }
Ejemplo n.º 15
0
 public void AddAvailableSwitch(SwitchBase sw)
 {
     if (!AvailableSwitchesDict.ContainsKey(sw.UniqueName))
     {
         AvailableSwitchesDict.Add(sw.UniqueName, sw);
     }
     else
     {
         var collidingSwitch = AvailableSwitchesDict[sw.UniqueName];
         ProcessorCompiler.AddError(
             new ExceptionEntry
         {
             Exception = new ArgumentException(
                 $"Switch Name {sw.UniqueName} is not unique ({sw.FullTypeName}) it collides with {collidingSwitch.DisplayName} ({collidingSwitch.FullTypeName}).\r\n" +
                 $"Make sure the UniqueName is unique or search, help and other features wont work correctly!"),
             Name = $"Switch {sw.UniqueName} is not unique."
         });
     }
 }
Ejemplo n.º 16
0
        public void Draw(Graphics g, SwitchBase sw, DrawableBase parent, RenderingEngine e)
        {
            MainEntry.Draw(g, sw, parent, e);
            for (int i = 0; i < sw.InputsSet.Count; i++)
            {
                if (Inputs.ContainsKey(i))
                {
                    Inputs[i].DrawInput(g, sw, i, e);
                }
            }

            for (int i = 0; i < sw.OutputsSet.Count; i++)
            {
                if (Outputs.ContainsKey(i))
                {
                    Outputs[i].DrawOutput(g, sw, i, e);
                }
            }
        }
Ejemplo n.º 17
0
        public void AddTag(SwitchBase sw, SearchTag tag)
        {
            var swResult = Engine.FindSwitch(sw.UniqueName);

            if (swResult != null)
            {
                var key = swResult.UniqueName;
                if (SearchDescriptionAvailable(key))
                {
                    var searchDescription = FindSearchDescription(key);
                    searchDescription.Add(tag);
                }
                else
                {
                    var desc = new SearchDescription(key);
                    desc.Add(tag);
                    AddSearchDescription(desc);
                }
            }
        }
Ejemplo n.º 18
0
        public void AddTags(SwitchBase sw, IEnumerable <SearchTag> tags)
        {
            var swResult = Engine.FindSwitch(sw.UniqueName);

            if (swResult != null)
            {
                var key = swResult.UniqueName;
                SearchDescription searchDescription;
                if (SearchDescriptionAvailable(key))
                {
                    searchDescription = FindSearchDescription(key);
                }
                else
                {
                    searchDescription = new SearchDescription(key);
                    AddSearchDescription(searchDescription);
                }

                searchDescription.AddRange(tags);
            }
        }
Ejemplo n.º 19
0
 public void AddTag(SwitchBase sw, string tag, string description = "")
 {
     AddTag(sw, new SearchTag(tag, description));
 }
Ejemplo n.º 20
0
        public void AddTags(SwitchBase sw, IEnumerable <string> tags)
        {
            List <SearchTag> searchTags = tags.Select(tag => new SearchTag(tag)).ToList();

            AddTags(sw, searchTags);
        }
Ejemplo n.º 21
0
 public InputOutputSelector(SwitchBase origin, InputOutputBase inputOutput)
 {
     Origin      = origin;
     InputOutput = inputOutput;
 }
Ejemplo n.º 22
0
 public TriggerEventArgs(SwitchBase origin, DataContainer data)
 {
     Origin = origin;
     Data   = data;
 }
Ejemplo n.º 23
0
 public void AddInternal(SwitchBase sw)
 {
     ItemLookup.Add(sw.Id, sw);
     _currentSwitchId = sw.Id + 1;
 }
Ejemplo n.º 24
0
 public void Initialize(Engine e, SwitchBase parent)
 {
     this.Parent = parent;
     UIComponent?.Initialize(e, this);
 }
Ejemplo n.º 25
0
 public void Remove(SwitchBase sw)
 {
     RemoveConnections(sw);
     ItemLookup.Remove(sw.Id);
     Items.Remove(sw);
 }
Ejemplo n.º 26
0
 public bool IsConnected(SwitchBase sw, InputOutputBase io)
 {
     return(InputLookup.ContainsKey(sw.Id) && InputLookup[sw.Id].Contains(io.Index));
 }
Ejemplo n.º 27
0
 public void AddComponent(RenderingEngine engine, SwitchBase sourceComponent)
 {
     engine.AddComponent(sourceComponent, engine.TranslatePoint(PointToClient(MousePosition)));
 }
Ejemplo n.º 28
0
 public IList <Connection> FindInputs(SwitchBase sw)
 {
     return(Connections.Where(x => x.ToInputOutput.Origin == sw).ToList());
 }
Ejemplo n.º 29
0
 public void AddInput(HelpDescriptionEntry helpEntry, SwitchBase sw, int index)
 {
     AddInput(helpEntry, sw.UniqueName, index);
 }