Exemple #1
0
 public ctlRule()
 {
     this.InitializeComponent();
     this._rule = new rule();
     this.currentLine = new lineChain();
     // done for unitTests
     if (Parent == null) Parent = new Form();
     #if DEBUG
     this.showDebugInfoToolStripMenuItem.Visible = true;
     #endif
 }
        public void testSerialisationOfDeletedLineChain()
        {
            ctlRule ruleControl = new ctlRule(){Parent = new Form()};

            lineChain newChain = new lineChain();
            rule targetRule = ruleControl.getRule();
            targetRule.AddLineChainToGlobalPool(newChain);

            // Delete the new chain
            newChain.requestDelete();

            // Ser and deser
            String serialized = ruleControl.serialiseRule();
            ctlRule deSerRuleControl = new ctlRule();
            deSerRuleControl.deserialiseRule(serialized);

            // Verify that our deleted linechain exists
            Assert.AreEqual(1, deSerRuleControl.getRule().lineChainCount);
            // and that it has been deleted
            Assert.AreEqual(true, deSerRuleControl.getRule().GetLineChainFromGuid(newChain.serial).isDeleted);
        }
Exemple #3
0
        public void testStartRunRuleItemLinkedToDebugItem()
        {
            rule targetRule = new rule();
            ruleItemBase startItem = targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItem_startRun)));
            ruleItemBase debugItem = targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItem_debug)));

            lineChain newChain = new lineChain();
            startItem.pinInfo["StartOfSim"].connectTo(newChain.serial, debugItem.pinInfo["input"]);
            targetRule.AddLineChainToGlobalPool(newChain);

            targetRule.start();
            Assert.AreEqual(false, startItem.pinInfo["StartOfSim"].value.data);
            Assert.AreEqual(tristate.noValue, debugItem.pinInfo["input"].value.data);
            targetRule.advanceDelta();
            Assert.AreEqual(true, startItem.pinInfo["StartOfSim"].value.data);
            Assert.AreEqual(tristate.yes, debugItem.pinInfo["input"].value.data);
            targetRule.advanceDelta();
            Assert.AreEqual(false, startItem.pinInfo["StartOfSim"].value.data);
            Assert.AreEqual(tristate.no, debugItem.pinInfo["input"].value.data);
            targetRule.stop();
        }
Exemple #4
0
        public frmDebug(lineChain debugThis)
        {
            this.InitializeComponent();

            if (debugThis.serial != null)
                this.lblDebugInfo.Text += "ID = " + debugThis.serial.ToString() + Environment.NewLine;
            else
                this.lblDebugInfo.Text += "ID is null!" + Environment.NewLine;
            this.lblDebugInfo.Text += "Color = " + debugThis.col.ToString() + Environment.NewLine;
            this.lblDebugInfo.Text += "Deleted = " + debugThis.isDeleted.ToString() + Environment.NewLine;
            /*
            if (debugThis.sourcePin!= null)
                this.lblDebugInfo.Text += "Src.  Pin name = " + debugThis.sourcePin.ToString() + Environment.NewLine;
            else
                this.lblDebugInfo.Text += "Src.  Pin id is null!" + Environment.NewLine;

            if (debugThis.destPin != null)
                this.lblDebugInfo.Text += "Dst.  pin id = " + debugThis.destPin.ToString() + Environment.NewLine;
            else
                this.lblDebugInfo.Text += "Dst.  pin id is null!" + Environment.NewLine;
             * */
        }
 public static void WriteElementLineChain(this XmlWriter writer, String localname, lineChain value)
 {
     writer.WriteStartElement("lineChain");
     value.WriteXml(writer);
     writer.WriteEndElement();
 }
Exemple #6
0
 // Here we have manipulation functions for our collections. 'global' in this sense means to the rule.
 // Really, needing this functions is a symptom of the code not being wonderfully OO. Wish I'd thought
 // ahead a bit more when I wrote them..
 //
 // TODO/FIXME: Remove neccesity for these functions
 public void AddLineChainToGlobalPool(lineChain addThis)
 {
     lineChains.Add(addThis.serial.id.ToString(), addThis);
 }
        private void testSerialisationOfRuleWithNamedRuleItem(Type targetType)
        {
            ctlRule ruleControl = new ctlRule();

            // Make a new rule with one RuleItem, of the specified type, and one lineChain.
            ruleItemInfo myInfo = new ruleItemInfo();
            myInfo.itemType = ruleItemType.RuleItem;
            myInfo.ruleItemBaseType = targetType;
            ruleControl.addRuleItem(myInfo);

            lineChain newChain = new lineChain();
            rule targetRule = ruleControl.getRule();
            targetRule.AddLineChainToGlobalPool(newChain);
            newChain.start.X = 10;
            newChain.start.Y = 20;
            newChain.end.X = 11;
            newChain.end.Y = 22;
            newChain.col = Color.CornflowerBlue;
            newChain.isdrawnbackwards = true;
            newChain.midPoints = new List<Point>();
            newChain.midPoints.Add(new Point(33, 44));

            // serialise it
            String serialised = ruleControl.serialiseRule();

            // Deserialise it!
            ctlRule deSerRuleControl = new ctlRule();
            deSerRuleControl.deserialiseRule(serialised);

            Assert.IsTrue(deSerRuleControl.getRule().lineChainCount == 1, "Deserialised rule did not have exactly one lineChain");
            Assert.IsTrue(deSerRuleControl.getRule().ruleItemCount == 1, "Deserialised rule did not have exactly one ruleItem");

            // Ensure that we can get the lineChain by the same GUID as we had before
            lineChain deSerLineChain = deSerRuleControl.getRule().GetLineChainFromGuid(newChain.serial);

            // Get the ruleItem. Note that we don't know its GUID yet so we must find it via its iterator.
            string ruleGuid = null;
            foreach (string indexer in deSerRuleControl.getRule().ruleItems.Keys)
                ruleGuid = indexer;

            Assert.IsNotNull(ruleGuid);

            rule deserialisedRule = deSerRuleControl.getRule();
            Assert.IsInstanceOfType(deserialisedRule.GetRuleItemFromGuid(new ruleItemGuid(ruleGuid)), targetType, "Deserialised rule did not preserve type of its ruleItem");
            Assert.IsTrue(deSerLineChain.start.X == 10);
            Assert.IsTrue(deSerLineChain.start.Y == 20);
            Assert.IsTrue(deSerLineChain.end.X == 11);
            Assert.IsTrue(deSerLineChain.end.Y == 22);
            Assert.IsTrue(deSerLineChain.col.R == Color.CornflowerBlue.R);
            Assert.IsTrue(deSerLineChain.col.G == Color.CornflowerBlue.G);
            Assert.IsTrue(deSerLineChain.col.B == Color.CornflowerBlue.B);
            Assert.IsFalse(deSerLineChain.isDeleted);
            Assert.IsTrue(deSerLineChain.isdrawnbackwards);
            Assert.IsTrue(deSerLineChain.midPoints.Count == 1);
            Assert.IsTrue(deSerLineChain.midPoints[0].X == 33);
            Assert.IsTrue(deSerLineChain.midPoints[0].Y == 44);
        }
        public void testSerialisationOfRuleWithTwoRuleItemWithPinsConnected()
        {
            rule rule = new rule("test");
            lineChain line = new lineChain();

            ruleItemInfo myInfo = new ruleItemInfo();
            myInfo.itemType = ruleItemType.RuleItem;
            myInfo.ruleItemBaseType = typeof(ruleItem_and);
            ruleItemBase andItem = rule.addRuleItem(myInfo);
            ruleItemGuid andGuid = andItem.serial;

            ruleItemInfo myInfo2 = new ruleItemInfo();
            myInfo2.itemType = ruleItemType.RuleItem;
            myInfo2.ruleItemBaseType = typeof(ruleItem_desktopMessage);
            ruleItemBase messageItem = rule.addRuleItem(myInfo2);
            ruleItemGuid messageGuid = messageItem.serial;

            messageItem.pinInfo["trigger"].parentRuleItem = messageGuid;
            messageItem.pinInfo["trigger"].connectTo(line.serial,andItem.pinInfo["output1"]);
            andItem.pinInfo["output1"].connectTo(line.serial, messageItem.pinInfo["trigger"]);
            andItem.pinInfo["output1"].parentRuleItem = andGuid;
            rule.AddLineChainToGlobalPool(line);

            String serialised = rule.serialise();

            rule = rule.deserialise(serialised);

            Assert.AreEqual("test", rule.name);
            Assert.AreEqual(1, rule.lineChainCount);
            Assert.AreEqual(2, rule.ruleItems.Count);
            andItem = rule.ruleItems[andGuid.id.ToString()];
            messageItem = rule.ruleItems[messageGuid.id.ToString()];
            Assert.IsInstanceOfType(andItem, typeof(ruleItem_and));
            Assert.IsInstanceOfType(messageItem, typeof(ruleItem_desktopMessage));
            Assert.AreEqual(1, messageItem.pinInfo.Count);
            Assert.AreEqual(3, andItem.pinInfo.Count);
            Assert.AreEqual(line.serial.id.ToString(), messageItem.pinInfo["trigger"].parentLineChain.id.ToString());
            Assert.AreEqual(line.serial.id.ToString(), andItem.pinInfo["output1"].parentLineChain.id.ToString());
            Assert.AreEqual(andItem.pinInfo["output1"].serial.id.ToString(), messageItem.pinInfo["trigger"].linkedTo.id.ToString());
            Assert.AreEqual(messageItem.pinInfo["trigger"].serial.id.ToString(), andItem.pinInfo["output1"].linkedTo.id.ToString());
            Assert.AreEqual(typeof(pinDataBool), andItem.pinInfo["output1"].valueType);
            Assert.AreEqual(typeof(pinDataBool), messageItem.pinInfo["trigger"].valueType) ;
        }
Exemple #9
0
 private void readAndAddLineChain(XmlReader reader)
 {
     lineChain toRet = new lineChain();
     toRet.ReadXml(reader);
     AddLineChainToGlobalPool(toRet);
 }
Exemple #10
0
        private void startLine(PictureBox from)
        {
            pin source = (pin)from.Tag;

            if ( source.isConnected )
            {
                MessageBox.Show("Pin is already connected to something");
                return;
            }

            this.currentlyConnecting = from;
            this.currentlyConnecting.BackColor = this.connectingPinColour;
            this.currentLine = new lineChain
                {
                    serial = new lineChainGuid(){id = Guid.NewGuid()},
                    start = this.PointToClient(Control.MousePosition),
                    end = this.PointToClient(Control.MousePosition)
                };
            // set temporarily, so the line doesn't stretch to the origin until the first mouseMove
        }
Exemple #11
0
        private void selectCurrentHandleAsDragging(Point cursor)
        {
            IEnumerable<lineChain> lines = this._rule.getNonDeletedLineChains();
            foreach (lineChain aLine in lines)
            {
                int pointIndex = 0;

                foreach (Point aPoint in aLine.midPoints)
                {
                    if (this.isHandleUnderPoint(aPoint, cursor))
                    {
                        this.currentlyDraggingLine = aLine;
                        this.currentlyDraggingPoint = pointIndex;
                        return;
                    }
                    pointIndex++;
                }
            }
        }
Exemple #12
0
        private void selectCurrentHandleAsContexted(Point cursor)
        {
            // Find the handle under the mouse cursor and select it as the 'contexted'.
            this.currentlyConextedLine = null;
            this.currentlyConextedPoint = -1;

            IEnumerable<lineChain> lines = this._rule.getNonDeletedLineChains();
            foreach (lineChain aLine in lines)
            {

                // First, see if the cursor is over a draggable midPoint, and start
                // dragging it if so.
                int pointIndex = 0;
                foreach (Point aPoint in aLine.midPoints)
                {
                    if (this.isHandleUnderPoint(aPoint, cursor))
                    {
                        this.currentlyConextedLine = aLine ;
                        this.currentlyConextedPoint = pointIndex;
                        return;
                    }
                    pointIndex++;
                }
            }

            // If we got here, we didn't find the handle under the pointer.
            // Perhaps a start/end is being positioned (which are handled differently).
            foreach (lineChain aLine in lines)
            {
                // If the cursor _is_ hovering over a start or end, don't set
                // currentlyContextedPoint (since there isn't one),just -Line.
                if (this.isHandleUnderPoint(aLine.start, cursor))
                {
                    this.currentlyConextedLine = aLine;
                    return;
                }

                if (this.isHandleUnderPoint(aLine.end, cursor))
                {
                    this.currentlyConextedLine = aLine;
                    return;
                }
            }

            throw new Exception("Unable to find current Handle");
        }
Exemple #13
0
 private void FrmRule_MouseUp(object sender, MouseEventArgs e)
 {
     this.currentlyDraggingPoint = -1;
     this.currentlyDraggingLine = null;
 }
Exemple #14
0
        public void finishLine(PictureBox endTarget)
        {
            ctlRuleItemWidget sourceItemWidget;

            pin source;
            pin dest;

            // Which direction has the user drawn a line in?
            if (((pin)this.currentlyConnecting.Tag).direction == pinDirection.output)
            {
                sourceItemWidget = ((ctlRuleItemWidget)this.currentlyConnecting.Parent);

                source = (pin)this.currentlyConnecting.Tag;
                dest = (pin)endTarget.Tag;
            }
            else
            {
                // the user has drawn the line from destination to source.
                this.currentLine.isdrawnbackwards = true;
                sourceItemWidget = ((ctlRuleItemWidget)endTarget.Parent);

                dest = (pin)this.currentlyConnecting.Tag;
                source = (pin)endTarget.Tag;
            }
            Contract.Assume(source != null && dest != null);

            this.currentlyConnecting.BackColor = this.normalPinColour;  // erase highlight

            // A few sanity checks
            bool errored = false;
            if (source.isConnected || dest.isConnected )
            {
                MessageBox.Show("Pin is already connected to something");
                errored = true;
            }
            if (source == dest)
            {
                MessageBox.Show("Pin cannot be connected to itself");
                errored = true;
            }
            if (source.direction == dest.direction)
            {
                MessageBox.Show(source.direction.ToString() + " pins cannot be connected to other " + source.direction.ToString() + " pins. Wires must connect inputs to outputs.");
                errored = true;
            }
            if (dest.possibleTypes.Count(t => t == source.valueType) < 1)
            {
                MessageBox.Show("Pins types are incompatable");
                errored = true;
            }

            if(errored)
            {
                this.currentLine = new lineChain();
                source.parentLineChain.id = Guid.Empty;
                this.currentlyConnecting = null;
                return;
            }

            // Hook pins up
            this.currentLine.onLineDeleted += source.Disconnected;
            this.currentLine.onLineDeleted += dest.Disconnected;
            dest.connectTo(this.currentLine.serial, source);
            source.connectTo(this.currentLine.serial, dest);

            // hook ruleitem events up to the line
            ctlRuleItemWidget ruleEnd = ((ctlRuleItemWidget) endTarget.Parent);
            ctlRuleItemWidget ruleStart = ((ctlRuleItemWidget) this.currentlyConnecting.Parent);
            ruleEnd.OnRuleItemMoved += this.currentLine.LineMoved;
            ruleStart.OnRuleItemMoved += this.currentLine.LineMoved;

            this._rule.AddLineChainToGlobalPool(this.currentLine);

            this.currentLine = new lineChain();

            ruleEnd.alignWires();
            ruleStart.alignWires();

            this.currentlyConnecting = null;
        }