Exemplo n.º 1
0
        private void repositoryItemSearchControl1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                string   text = (sender as TextEdit).Text;
                FlowView view = this.GetCurrentGraphView();
                if (view == null)
                {
                    return;
                }

                // if the search keyword has change, then reset the search enumerator
                // otherwise, keep searching for the next result
                if (text != OldSearchKeyWord)
                {
                    view.BlockSearcher.SearchReset = true;
                }
                OldSearchKeyWord = text;

                BlockSearchResult?.FxPlayer.FadeToNormalColor();

                BlockSearchResult = view.BlockSearcher.SearchNextBlock(text);
                if (BlockSearchResult == null)
                {
                    return;
                }

                // highlight search result
                BlockSearchResult?.FxPlayer?.DarkenColor();
                view.ScrollRectangleToVisible(BlockSearchResult);
            }
        }
Exemplo n.º 2
0
 public void ScrollRectangleToVisible(FlowBlock Block)
 {
     RectangleF rect = new RectangleF();
     rect.Location = new PointF(Block.Location.X - Block.Size.Width/2, Block.Location.Y - Block.Size.Height/2);
     rect.Size = Block.Size;
     ScrollRectangleToVisible(rect);
 }
Exemplo n.º 3
0
        private void InitializeCatalog()
        {
            paletteMain.Width  = pnlLeft.Width;
            paletteMain.Height = 1500;
            // paletteMain.Height = pnlLeft.Height;
            // paletteMain.Size = pnlLeft.Size;
            paletteMain.Location = new System.Drawing.Point(pnlLeft.Location.X, paletteMain.Location.Y);

            FlowBlock n;

            n = new FlowBlock(BlockType.Start);
            paletteMain.Document.Add(n);
            n = new FlowBlock(BlockType.Input);
            paletteMain.Document.Add(n);
            n = new FlowBlock(BlockType.Process);
            paletteMain.Document.Add(n);
            n = new FlowBlock(BlockType.Condition);
            paletteMain.Document.Add(n);
            n = new FlowBlock(BlockType.Output);
            paletteMain.Document.Add(n);
            n = new FlowBlock(BlockType.End);
            paletteMain.Document.Add(n);

            //paletteMain.GridCellSize = new SizeF(40, (int)n.Height + 3);
            // myPalette.Document.Add(c);

            GoComment c = new GoComment();

            c.TopLeftMargin     = new SizeF(8, 8);
            c.BottomRightMargin = new SizeF(8, 8);
            c.Shadowed          = true;
            c.Text = "comment sth";
            paletteMain.Document.Add(c);
        }
Exemplo n.º 4
0
        private VarInfo HandleEndBlock(FlowBlock CurrentBlock, out string ErrorReport)
        {
            FlowMap map = form.ActiveMdiChild as FlowMap;

            ErrorReport = "";
            MainInterface.Instance.UserLog("Flow execution has completed!", LogType.Success);
            return(null);
        }
Exemplo n.º 5
0
        private VarInfo HandleStartBlock(FlowBlock CurrentBlock, out string ErrorReport)
        {
            FlowMap map = form.ActiveMdiChild as FlowMap;

            ErrorReport = "";
            MainInterface.Instance.UserLog("Flow execution has started", LogType.Normal);
            return(null);
        }
Exemplo n.º 6
0
        private bool ResetFlow()
        {
            State           = FlowRunState.Start;
            LastBlockResult = null;
            CurrentBlock    = null;
            FlowData.ClearData();

            return(true);
        }
Exemplo n.º 7
0
        public void InsertNode(BlockType k)
        {
            GoObject n = new FlowBlock(k);

            n.Position = NextNodePosition();
            StartTransaction();
            Add(n);
            FinishTransaction("Insert Block");
        }
Exemplo n.º 8
0
 public static bool IsLinked(FlowBlock a, FlowBlock b)
 {
     if (a.BottomPort == null)
         return false;
     return a.BottomPort.IsLinked(b.TopPort) ||
            a.BottomPort.IsLinked(b.LeftPort) ||
            a.BottomPort.IsLinked(b.RightPort) ||
            a.BottomPort.IsLinked(b.BottomPort);
 }
Exemplo n.º 9
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public DarkenBlockEffectPlayer(FlowBlock block)
        {
            this.Block = block;

            OriginalBrushColor     = (Block.Background as GoShape).BrushColor;
            OriginalBrushMidColor  = (Block.Background as GoShape).BrushMidColor;
            OriginalBrushForeColor = (Block.Background as GoShape).BrushForeColor;
            OriginalPenColor       = (Block.Background as GoShape).PenColor;

            CurFadingFrame    = FadingFrame;
            FadingTimer.Tick += this.FadingTimer_TickUpdate;
        }
Exemplo n.º 10
0
        private bool MatchedBlock(FlowBlock Block, string KeyWord)
        {
            string Text = Block.Text;

            if (!SearchCaseSensitive)
            {
                Text    = Text.ToUpper();
                KeyWord = KeyWord.ToUpper();
            }
            int index = Text.IndexOf(KeyWord);

            return(index >= 0);
        }
Exemplo n.º 11
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Handle blocks /////////////////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////


        // handle blocks behavior and return value of blocks if available
        private VarInfo HandleBlock(FlowBlock CurrentBlock, out string ErrorReport)
        {
            FlowMap map         = form.ActiveMdiChild as FlowMap;
            VarInfo BlockResult = null;

            ErrorReport = "";

            MainInterface.Instance.UserLog("--> " + CurrentBlock.Kind.ToString() + " Block: " + CurrentBlock.Text, LogType.Normal);

            switch (CurrentBlock.Kind)
            {
            case BlockType.Start:
            {
                BlockResult = HandleStartBlock(CurrentBlock, out ErrorReport);
                break;
            }

            case BlockType.End:
            {
                BlockResult = HandleEndBlock(CurrentBlock, out ErrorReport);
                break;
            }

            case BlockType.Process:
            {
                BlockResult = HandleProcessBlock(CurrentBlock, out ErrorReport);
                break;
            }

            case BlockType.Input:
            {
                BlockResult = HandleInputBlock(CurrentBlock, out ErrorReport);
                break;
            }

            case BlockType.Output:
            {
                BlockResult = HandleOutputblock(CurrentBlock, out ErrorReport);
                break;
            }

            case BlockType.Condition:
            {
                BlockResult = HandleConditionBlock(CurrentBlock, out ErrorReport);
                break;
            }
            }

            UpdateWatch();
            return(BlockResult);
        }
Exemplo n.º 12
0
        public GoPort FindNearestPort(PointF pt, FlowBlock fb)
        {
            float  maxdist = 10e20f;
            GoPort closest = null;
            GoPort p;

            p = fb.TopPort;
            if (p != null)
            {
                float dist = (p.Left - pt.X) * (p.Left - pt.X) + (p.Top - pt.Y) * (p.Top - pt.Y);
                if (dist < maxdist)
                {
                    maxdist = dist;
                    closest = p;
                }
            }
            p = fb.RightPort;
            if (p != null)
            {
                float dist = (p.Left - pt.X) * (p.Left - pt.X) + (p.Top - pt.Y) * (p.Top - pt.Y);
                if (dist < maxdist)
                {
                    maxdist = dist;
                    closest = p;
                }
            }
            p = fb.BottomPort;
            if (p != null)
            {
                float dist = (p.Left - pt.X) * (p.Left - pt.X) + (p.Top - pt.Y) * (p.Top - pt.Y);
                if (dist < maxdist)
                {
                    maxdist = dist;
                    closest = p;
                }
            }
            p = fb.LeftPort;
            if (p != null)
            {
                float dist = (p.Left - pt.X) * (p.Left - pt.X) + (p.Top - pt.Y) * (p.Top - pt.Y);
                if (dist < maxdist)
                {
                    maxdist = dist;
                    closest = p;
                }
            }
            return(closest);
        }
Exemplo n.º 13
0
        public FlowBlock GetNextBlock(FlowBlock CurrentBlock, VarInfo blockResult, out string ErrorReport)
        {
            if( CurrentBlock == null )
                return GetStartBlock(out ErrorReport);
            ErrorReport = "";

            if(CurrentBlock.Kind == BlockType.End)
            {
                return null;
            }

            List<IGoLink> OutLinks = new List<IGoLink>();
            OutLinks.Clear();
            foreach(IGoLink link in CurrentBlock.Links)
            {
                if( (link.FromNode as FlowBlock).GetHashCode() == CurrentBlock.GetHashCode() )
                    OutLinks.Add(link);
            }

            if( OutLinks.Count < 1 )
            {
                ErrorReport = "Error: No out-link is found";
                return null;
            }

            if(CurrentBlock.Kind == BlockType.Condition)
            {
                OutLinks[0] = PickLinkFromConditionBlock(OutLinks, blockResult, out ErrorReport);
                if( ErrorReport != "" )
                    return null;
            }
            else
            if( OutLinks.Count > 1 )
            {
                ErrorReport = "Error: Regular blocks should only have ONE out-link";
                return null;
            }

            if(OutLinks[0] != null)
            {
                return OutLinks[0].ToNode as FlowBlock;
            }
            else
            {
                // already handled before ;)
                return null;
            }
        }
Exemplo n.º 14
0
        private VarInfo HandleConditionBlock(FlowBlock CurrentBlock, out string ErrorReport)
        {
            FlowMap map = form.ActiveMdiChild as FlowMap;

            ErrorReport = "";

            string  expression = CurrentBlock.Text;
            VarInfo varRes     = FlowData.HandleExpression(expression, out ErrorReport);

            if (ErrorReport != "")
            {
                return(null);
            }

            MainInterface.Instance.UserLog("Value: " + CurrentBlock.Text + " = " + varRes.value, LogType.Normal);
            return(varRes);
        }
Exemplo n.º 15
0
        private VarInfo HandleProcessBlock(FlowBlock CurrentBlock, out string ErrorReport)
        {
            FlowMap map = form.ActiveMdiChild as FlowMap;

            ErrorReport = "";

            string expression = CurrentBlock.Text;

            if (CurrentBlock.Text == "")
            {
                ErrorReport = "Blank expression";
                return(null);
            }

            // handle deletion
            if (CurrentBlock.Text[0] == '~')
            {
                FlowData.HandleDeletion(expression, out ErrorReport);
                if (ErrorReport != "")
                {
                    return(null);
                }

                MainInterface.Instance.UserLog("Deletion: " + expression.Remove(0, 1), LogType.Normal);
                return(null);
            }

            VarInfo varRes = FlowData.HandleAssignment(expression, out ErrorReport);

            if (ErrorReport != "")
            {
                return(null);
            }

            if (!varRes.isNull)
            {
                MainInterface.Instance.UserLog("Assignment: " + CurrentBlock.Text + " = " + varRes.value, LogType.Normal);
            }
            else
            {
                MainInterface.Instance.UserLog("Declaration: " + CurrentBlock.Text, LogType.Normal);
            }

            return(varRes);
        }
Exemplo n.º 16
0
        public frmBlockEdit(FlowBlock block)
        {
            InitializeComponent();

            // round the corner of form
            this.FormBorderStyle = FormBorderStyle.None;
            Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));

            this.Block        = block;
            tbType.Text       = block.Kind.ToString();
            tbExpression.Text = block.Text;

            InitMoveFormHandlers();
            InitializeAutoComplete();

            // Additional event handler
            tbExpression.TextChanged += tbExpression_UpdateCheckValidValue;
        }
Exemplo n.º 17
0
        public FlowBlock SearchNextBlock(string KeyWord)
        {
            if (SearchReset)
            {
                SearchResetEnumerator();
            }

            // if search is still not available at the yet
            if (SearchReset)
            {
                // invoke the event again
                SearchReset = true;
                return(null);
            }

            // start iterating the collection
            while (true)
            {
                try
                {
                    if (!SearchEnumerator.MoveNext())
                    {
                        MessageBox.Show("No match left!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        SearchReset = true;
                        return(null);
                    }
                }
                catch
                {
                    SearchReset = true;
                    return(null);
                }

                if (SearchEnumerator.Current is FlowBlock)
                {
                    FlowBlock Block = SearchEnumerator.Current as FlowBlock;
                    if (MatchedBlock(Block, KeyWord))
                    {
                        return(Block);
                    }
                }
            }
        }
Exemplo n.º 18
0
        private VarInfo HandleInputBlock(FlowBlock CurrentBlock, out string ErrorReport)
        {
            FlowMap map = form.ActiveMdiChild as FlowMap;

            ErrorReport = "";

            string varAndType = CurrentBlock.Text;
            string varName;

            FlowData.HandleDeclaration(varAndType, out varName, out ErrorReport);
            if (ErrorReport != "")
            {
                return(null);
            }

            DataType varType = FlowData.GetVarInfo(varName, out ErrorReport).type;

            if (ErrorReport != "")
            {
                return(null);
            }

            frmScan      InputForm    = new frmScan(varName, varType);
            DialogResult dialogResult = InputForm.ShowDialog();

            if (dialogResult == DialogResult.Cancel)
            {
                ErrorReport = "Error: User input was canceled";
                return(null);
            }

            VarInfo InputVarInfo = InputForm.VarInfoResult;

            FlowData.AssignVariable(varName, InputVarInfo, out ErrorReport);
            if (ErrorReport != "")
            {
                return(null);
            }

            MainInterface.Instance.UserLog("Input: " + varName + " = " + InputVarInfo.value, LogType.Normal);
            return(null);
        }
Exemplo n.º 19
0
 public override void DoMouseMove()
 {
     if (myLink != null && myLink.ToPort != null)
     {
         GoPort p = myLink.ToPort.GoObject as GoPort;
         if (p != null)
         {
             p.Position = this.LastInput.DocPoint;
             FlowBlock gn = this.View.PickObject(true, false, this.LastInput.DocPoint, true) as FlowBlock;
             if (gn != null && gn != this.Predecessor && !FlowView.IsLinked(this.Predecessor, gn))
             {
                 GoPort nearest = FindNearestPort(this.LastInput.DocPoint, gn);
                 if (nearest != null)
                 {
                     p.Position = nearest.Position;
                     p.ToSpot   = nearest.ToSpot;
                 }
             }
         }
     }
 }
Exemplo n.º 20
0
 public override void DoMouseDown()
 {
     if (this.Predecessor == null)
     {
         FlowBlock gn = this.View.PickObject(true, false, this.LastInput.DocPoint, true) as FlowBlock;
         if (gn == null)
         {
             return;
         }
         if (!gn.IsPredecessor)
         {
             return;
         }
         this.Predecessor = gn;
         MainBase.App.SetStatusMessage("From block " + this.Predecessor.Text);
         MakeTemporaryLink();
     }
     else
     {
         FlowBlock gn = this.View.PickObject(true, false, this.LastInput.DocPoint, true) as FlowBlock;
         if (gn != null && gn != this.Predecessor && !FlowView.IsLinked(this.Predecessor, gn))
         {
             // delete the temporary link
             this.View.Layers.Default.Remove(myLink);
             myLink = null;
             // create the link in the design
             GoPort  nearest = FindNearestPort(this.LastInput.DocPoint, gn);
             IGoLink link    = this.View.CreateLink(this.Predecessor.BottomPort, nearest);
             if (link != null)
             {
                 this.TransactionResult = "New link";
                 this.View.RaiseLinkCreated(link.GoObject);
                 this.View.Selection.Select(link.GoObject);
             }
             StopTool();
         }
     }
 }
Exemplo n.º 21
0
        // Logic for running flow ////////////////////////////////////////////////////////////////////////////////////////////////////
        public FlowBlock GetStartBlock(out string ErrorReport)
        {
            FlowDocument doc = this.Document as FlowDocument;
            int countStart = 0;
            ErrorReport = "";
            FlowBlock result = null;

            foreach (GoObject obj in doc)
            {
                if (obj is GoTextNode)
                {
                    if ((obj as FlowBlock).Kind == BlockType.Start)
                    {
                        countStart++;
                        result = (obj as FlowBlock);
                    }
                }
            }

            if(countStart < 1)
            {
                ErrorReport = "Error: Your flow is lack of the Start block";
                return null;
            }
            if(countStart > 1)
            {
                ErrorReport = "Error: Your flow should only have one Start block";
                return null;
            }

            if(countStart == 1)
            {
                return result;
            }

            return null;
        }
Exemplo n.º 22
0
 public void CreateRelationshipsAmongSelection()
 {
     FlowBlock boss = this.Selection.Primary as FlowBlock;
     if (boss != null)
     {
         if (boss.BottomPort == null)
         {
             MessageBox.Show(this, "Cannot create link originating from this block.", "Error", MessageBoxButtons.OK);
         }
         else
         {
             StartTransaction();
             foreach (GoObject obj in this.Selection)
             {
                 FlowBlock n = obj as FlowBlock;
                 if (n != null && n != boss && !IsLinked(boss, n))
                 {
                     if (n.TopPort == null)
                     {
                         MessageBox.Show(this, "Cannot create link finishing with this block.", "Error", MessageBoxButtons.OK);
                     }
                     else
                     {
                         IGoLink l = CreateLink(boss.BottomPort, n.TopPort);
                         if (l != null)
                         {
                             this.Document.Add(l.GoObject);
                             RaiseLinkCreated(l.GoObject);
                         }
                     }
                 }
             }
             FinishTransaction("Create links among selection blocks");
         }
     }
 }
Exemplo n.º 23
0
 public override IGoLink CreateLink(IGoPort from, IGoPort to)
 {
     IGoLink il = base.CreateLink(from, to);
     if (il != null)
     {
         GoLabeledLink l = il.GoObject as GoLabeledLink;
         if (l != null)
         {
             FlowBlock fromNode = from.Node.GoObject as FlowBlock;
             if (fromNode != null && fromNode.Kind == BlockType.Condition)
             {
                 GoText t = new GoText();
                 t.Text = "yes";
                 t.Selectable = false;
                 t.Editable = true;
                 l.FromLabel = t;
             }
             //l.Orthogonal = true;
             //l.Style = GoStrokeStyle.RoundedLine;
             //l.ToArrow = true;
         }
     }
     return il;
 }
Exemplo n.º 24
0
        /// return false if the flow is terminated due to error or end-block
        private bool ExecuteNextBlock()
        {
            string   ErrorReport = "";
            FlowView view        = form.GetCurrentGoView() as FlowView;
            FlowMap  map         = form.ActiveMdiChild as FlowMap;

            if (view == null)
            {
                MainInterface.Instance.UserLog("Error: No flow is found", LogType.Error);
                MainInterface.Instance.UserLog("Please create a new Flow art or open your old project", LogType.Normal);
                ResetFlow();
                RaiseError?.Invoke(this, new EventArgs());
                return(false);
            }
            if (map == null)
            {
                return(false);
            }

            FlowBlock OldBlock = CurrentBlock;

            CurrentBlock = view.GetNextBlock(CurrentBlock, LastBlockResult, out ErrorReport);
            // remember to check if this view is the same as the previous view

            // reset flow when there is link error
            if (CurrentBlock == null)
            {
                MainInterface.Instance.UserLog(ErrorReport, LogType.Error);
                ResetFlow();
                RaiseError?.Invoke(this, new EventArgs());
                return(false);
            }

            // unhighlight old block
            if (PlayFadingEffect)
            {
                OldBlock?.FxPlayer.FadeToNormalColor();
            }
            else
            {
                OldBlock?.FxPlayer.NormalizeColor();
            }

            // highlight new block
            CurrentBlock?.FxPlayer.DarkenColor();

            EnterNextBlock?.Invoke(this, new EventArgs());

            // reset flow if there is expression error
            LastBlockResult = HandleBlock(CurrentBlock, out ErrorReport);
            if (ErrorReport != "")
            {
                MainInterface.Instance.UserLog(ErrorReport, LogType.Error);
                ResetFlow();
                RaiseError?.Invoke(this, new EventArgs());
                return(false);
            }

            // reset flow if this is then End-block
            if (CurrentBlock.Kind == BlockType.End)
            {
                ResetFlow();
                ReachEndBlock?.Invoke(this, new EventArgs());
                return(false);
            }

            // blank space because it's beautiful :)
            MainInterface.Instance.UserLog("", LogType.Normal);

            return(true);
        }