public Controller(Model model, View view)
        {
            /* initialize class fields */
            this.model = model;
            this.view = view;
            this.workers = new List<BackgroundWorker>();
            this.cancelled = false;
            this.running = 0;
            this.mapType = Map.MapType.Empty;
            this.nodeEditBackColor = Color.White;
            this.nodeEditForeColor = Color.White;
            this.nodeEditBackColor = Color.White;
            this.nodeEditState = NodeEditState.DISABLED;
            this.nodeEditFinishAgentId = Agent.AgentID.Agent_0;
            this.nodeEditStartAgentId = Agent.AgentID.Agent_0;

            /* initialize the volatile variables */
            tempMapSize = model.getSimulation().get(View.ViewNumericUpDown.MapSize);
            tempPercentWalkable = model.getSimulation().get(View.ViewNumericUpDown.PercentWalkable);
            tempNumberofAgents = model.getSimulation().get(View.ViewNumericUpDown.NumberOfAgents);

            /* generate an empty map without agents */
            generateMapCommon(null, false);
            model.getSimulation().setMapID(0);

            /* mouse event handlers */
            view.getPanelMap().MouseDown += new MouseEventHandler(Controller_MouseDown);
            view.getPanelMap().MouseUp += new MouseEventHandler(Controller_MouseUp);
            view.getPanelMap().MouseClick += new MouseEventHandler(Controller_MouseClick);

            this.mouseDownNodes = new List<Node>();
            mouseDownRunning = false;
            mouseDownBackgroundWorker = new BackgroundWorker();
            mouseDownBackgroundWorker.DoWork += new DoWorkEventHandler(collectNodes_DoWork);
        }
        public void PostStep(Agent agent, Model model)
        {
            Agent.AgentID id = model.getSimulation().getViewableAgent();

            /* only update the selected agent or all agents if selected */

            Node currentNode = model.getMap().getNodeAtLocation(agent.getNode(Agent.NodeType.Current).getPosition());

            Color backColor = agent.getColor(Agent.ColorType.BackColor);
            Color foreColor = agent.getColor(Agent.ColorType.ForeColor);

            if (currentNode.isEqual(agent.getNode(Agent.NodeType.Finish)))
                currentNode.repaintNode(backColor, foreColor, "F");
            else
            {
                if (model.getSimulation().getVisualizations() == View.Visualizations.Enabled)
                    currentNode.repaintNode(backColor, foreColor, currentNode.Text);
                else
                    currentNode.repaintNode(backColor, foreColor, "");
            }

            if (agent.getNode(Agent.NodeType.Current).getParent() != null)
            {
                Node parentNode = model.getMap().getNodeAtLocation(agent.getNode(Agent.NodeType.Current).getParent().getPosition());

                if (model.getSimulation().getPersistenceEnabled() == View.PathPersistence.Disabled | !agent.isActive())
                {
                    if (model.isSpecialNode(parentNode))
                    {
                        Agent specialAgent = model.getSpecialNodeAgent(parentNode);
                        backColor = specialAgent.getColor(Agent.ColorType.BackColor);
                        foreColor = specialAgent.getColor(Agent.ColorType.ForeColor);
                        parentNode.repaintNode(backColor, foreColor, "");
                    }
                    else
                    {
                        if (agent.isActive())
                            if (parentNode.getFlag(Node.Flag.IsWalkable))
                                parentNode.repaintNode(Color.White, Color.White, "");
                            else
                                parentNode.repaintNode(Color.Gray, Color.Gray, "");
                        else
                        {
                            /* is node visible on active agent's map */
                            Agent viewAgent = model.getAgent(model.getSimulation().getViewableAgent());
                            bool isVisibleOnActiveAgentsMap = viewAgent.getMap().isNodeFlag(parentNode, Node.Flag.IsVisible);

                            if (isVisibleOnActiveAgentsMap)
                            {
                                /* is node special */
                                bool isSpecial = viewAgent.getMap().isNodeFlag(parentNode, Node.Flag.IsSpecial);
                                if (isSpecial)
                                {
                                    if (parentNode.isEqual(viewAgent.getNode(Agent.NodeType.Start)))
                                        parentNode.repaintNode(viewAgent.getColor(Agent.ColorType.BackColor), viewAgent.getColor(Agent.ColorType.ForeColor), "S");
                                    else
                                        parentNode.repaintNode(viewAgent.getColor(Agent.ColorType.BackColor), viewAgent.getColor(Agent.ColorType.ForeColor), "F");
                                }
                                else
                                {
                                    /* is node walkable on active agent's map */
                                    bool isWalkable = viewAgent.getMap().isNodeFlag(parentNode, Node.Flag.IsWalkable);
                                    if (isWalkable)
                                    {
                                        bool isPathNode = viewAgent.getMap().isNodeFlag(parentNode,Node.Flag.IsPath);
                                        if (isPathNode)
                                        {
                                            if (model.getSimulation().getPersistenceEnabled() == View.PathPersistence.Enabled)
                                            {
                                                /* non active agent's parent node is also the active agent's path node */
                                                Color b = viewAgent.getColor(Agent.ColorType.BackColor);
                                                Color f = viewAgent.getColor(Agent.ColorType.ForeColor);
                                                parentNode.repaintNode(b, f, "");
                                            }
                                            else
                                            {
                                                /* non active agent's walkable path node with persistence disabled */
                                                parentNode.repaintNode(Color.White, Color.White, "");
                                            }
                                        }
                                        else
                                        {
                                            /* non active agent's parent node is just a visible walkable node */
                                            parentNode.repaintNode(Color.White, Color.White, "");
                                        }
                                    }
                                    else
                                    {
                                        /* non active agent's parent node is just a visible non-walkable node */
                                        parentNode.repaintNode(Color.Gray, Color.Gray, "");
                                    }
                                }
                            }
                            else
                            {
                                /* node is not visible on active agent's map therefore we can just paint it black */
                                parentNode.repaintNode(Color.Black, Color.Black, "");
                            }
                        }
                    }
                }
            }
        }
 protected bool visualizationPaintOK(Node node, Agent agent, Model model)
 {
     bool isActive = agent.isActive();
     View.Visualizations visualizations = model.getSimulation().getVisualizations();
     bool notSpecial = !model.isSpecialNode(node);
     bool notPath = !model.isPathNode(node);
     if (isActive && visualizations == View.Visualizations.Enabled && notSpecial && notPath)
         return true;
     else
         return false;
 }
        private Agent.AgentID incNodeEditAgentId(Model model, Agent.AgentID init)
        {
            int index = (int)init;
            int maxIndex = (model.getSimulation().get(View.ViewNumericUpDown.NumberOfAgents) - 1);

            index = (index == maxIndex) ? (int)Agent.AgentID.Agent_0 : index + 1;

            this.nodeEditBackColor = model.getAgent((Agent.AgentID)index).getColor(Agent.ColorType.BackColor);
            this.nodeEditForeColor = model.getAgent((Agent.AgentID)index).getColor(Agent.ColorType.ForeColor);

            return (Agent.AgentID)index;
        }