Пример #1
0
        /* ==================================================================== */

        // constructor
        public ScriptCanvas(string scriptName, List <StateModel> stateModelList = null) : base()
        {
            // fill in the father container
            Dock = DockStyle.Fill;

            // allow drop operation
            AllowDrop = true;

            // to avoid flashing when invalidating
            DoubleBuffered = true;

            // set this script name
            mScriptNameAtCanvas = scriptName;

            // render the state-models if existed
            if (!(stateModelList is null))
            {
                stateModelList.ForEach(it => {
                    // build state-view
                    StateView stateView;
                    if (it.StateType == StateType.START)
                    {
                        stateView = new StartStateView(it.LocOnScript.X, it.LocOnScript.Y, it.ContentText, true);
                    }
                    else if (it.StateType == StateType.END)
                    {
                        stateView = new EndStateView(it.LocOnScript.X, it.LocOnScript.Y, it.ContentText, true);
                    }
                    else
                    {
                        stateView = new GeneralStateView(it.LocOnScript.X, it.LocOnScript.Y, it.ContentText, true);
                    }

                    stateView.Id = it.Id;

                    // add link-views
                    var allPortTypes = Enum.GetValues(typeof(PortType));
                    foreach (PortType portType in allPortTypes)
                    {
                        // add outgoing links
                        foreach (LinkModel linkModel in it.getCertainPortModel(portType).getLinks(true))
                        {
                            mExistedOutgoingLinks.Add(new LinkView(linkModel));
                        }
                        // add ingoing links
                        foreach (LinkModel linkModel in it.getCertainPortModel(portType).getLinks(false))
                        {
                            mExistedIngoingLinks.Add(new LinkView(linkModel));
                        }
                    }

                    // add state-view
                    mExistedStateViewList.Add(stateView);
                    Controls.Add(stateView);
                });

                Invalidate();
            }
        }
Пример #2
0
        // re-set the whole script
        public void setDataByScriptModel(ScriptModel scriptModel)
        {
            if (scriptModel is null)
            {
                return;
            }

            // set the script name
            mScriptNameAtCanvas = scriptModel.Name;

            mExistedStateViewList.Clear();
            Controls.Clear();
            mExistedIngoingLinks.Clear();
            mExistedOutgoingLinks.Clear();

            scriptModel.getCopiedStateList().ForEach(it => {
                // build state-view
                StateView stateView;
                if (it.StateType == StateType.START)
                {
                    stateView = new StartStateView(it.LocOnScript.X, it.LocOnScript.Y, it.ContentText, true);
                }
                else if (it.StateType == StateType.END)
                {
                    stateView = new EndStateView(it.LocOnScript.X, it.LocOnScript.Y, it.ContentText, true);
                }
                else
                {
                    stateView = new GeneralStateView(it.LocOnScript.X, it.LocOnScript.Y, it.ContentText, true);
                }

                stateView.Id = it.Id;

                // add link-views
                var allPortTypes = Enum.GetValues(typeof(PortType));
                foreach (PortType portType in allPortTypes)
                {
                    // add outgoing links
                    foreach (LinkModel linkModel in it.getCertainPortModel(portType).getLinks(true))
                    {
                        mExistedOutgoingLinks.Add(new LinkView(linkModel));
                    }
                    // add ingoing links
                    foreach (LinkModel linkModel in it.getCertainPortModel(portType).getLinks(false))
                    {
                        mExistedIngoingLinks.Add(new LinkView(linkModel));
                    }
                }

                // add state-view
                mExistedStateViewList.Add(stateView);
                Controls.Add(stateView);
            });

            Invalidate();
        }
Пример #3
0
        // drag-dropped, a new state-view added on current script
        protected override void OnDragDrop(DragEventArgs e)
        {
            //var bmp = (Bitmap) e.Data.GetData(DataFormats.Bitmap);

            // get the client point
            Point clientPoint = PointToClient(new Point(e.X, e.Y));

            // add the state at the location of client point
            StateView newStateView = null;

            switch (MouseManager.CurrentHoldingType)
            {
            case StateType.START:
                newStateView = new StartStateView(clientPoint.X, clientPoint.Y, "", true);
                break;

            case StateType.END:
                newStateView = new EndStateView(clientPoint.X, clientPoint.Y, "", true);
                break;

            case StateType.GENERAL:
                // prompt the typing form to get the state content from user
                string newStateContent = promptTypingFormAndGetTypedText();

                // if the result is null, means that user cancels the addition of state
                if (!(newStateContent is null))
                {
                    newStateView = new GeneralStateView(clientPoint.X, clientPoint.Y, newStateContent, true);
                }

                break;
            }
            if (!(newStateView is null))
            {
                // resize the state with current scale
                newStateView.Size = new Size((int)(newStateView.Size.Width * currentScale),
                                             (int)(newStateView.Size.Height * currentScale));
                newStateView.resetPortPositions();

                // add the state-view
                AddStateView(newStateView, textArgb: Color.Black.ToArgb());
            }

            // reset both the holding type and dragging to NONE
            MouseManager.CurrentHoldingType = StateType.NONE;

            // paint on the picture-box
            Invalidate();
        }
Пример #4
0
        // put the 3 types of states on the left side of GUI
        private void buildUpStatesList()
        {
            int panelW = statesListPanel.Width;

            int locX = panelW / 2;

            StateView startStateView = new StartStateView(locX, 50, "", false);

            statesListPanel.Controls.Add(startStateView);
            mStateViewListOnTheShell.Add(startStateView);

            StateView endStateView = new EndStateView(locX, 140, "", false);

            statesListPanel.Controls.Add(endStateView);
            mStateViewListOnTheShell.Add(endStateView);

            StateView generalStateView = new GeneralStateView(locX, 240, "", false);

            statesListPanel.Controls.Add(generalStateView);
            mStateViewListOnTheShell.Add(generalStateView);
        }