示例#1
0
 public void find_setNode(int id)
 {
     m_blnfind_setNode = false;//每次呼叫重新搜尋
     foreach (TreeNode tn_buf in tvTreeView.Nodes)
     {
         Tree_Node tn = (Tree_Node)tn_buf;
         if (m_blnfind_setNode == false)
         {
             if (tn.m_id == id)
             {
                 SelectedNode      = tn_buf;
                 m_blnfind_setNode = true;
                 break;
             }
             else
             {
                 if (tn.Nodes.Count > 0)
                 {
                     find_setNode(id, tn);
                 }
             }
         }
         else
         {
             break;
         }
     }
 }
示例#2
0
        public static List <Tree_Node> Neighbours(Tree_Node node, Node[,] array, Node finish)
        {
            var neighbours = NeighboursSelective(node, node.Currentnode.X(), node.Currentnode.Y(), array,
                                                 node.Currentnode.DestinationFromPrevious, finish);

            return(neighbours);
        }
示例#3
0
 private void find_setNode(int id, Tree_Node bufNode)
 {
     if (m_blnfind_setNode == false)
     {
         foreach (TreeNode tn_buf in bufNode.Nodes)
         {
             if (m_blnfind_setNode == false)
             {
                 Tree_Node tn = (Tree_Node)tn_buf;
                 if (tn.m_id == id)
                 {
                     SelectedNode      = tn_buf;
                     m_blnfind_setNode = true;
                     break;
                 }
                 else
                 {
                     if ((tn_buf.Nodes.Count > 0))
                     {
                         find_setNode(id, tn);
                     }
                 }
             }
             else
             {
                 break;
             }
         }
     }
 }
示例#4
0
        public static void NeighboursAndTJP(Informer start, Informer finish,
                                            Node[,] nodesArray, out DebugInformationAlgorithm debugInfo)
        {
            var startNode = new Node(start, NodeState.Processed);

            startNode.NormMatrix = nodesArray[startNode.X(), startNode.Y()].NormMatrix;
            startNode.Distance   = MetricsAStar(start, finish);
            var startTreeNode          = new Tree_Node(null, startNode);
            var finishNode             = new Node(finish, NodeState.Processed);
            var sraightLinesFromStart  = new StraightLinesFromNode(startNode);
            var sraightLinesFromFinish = new StraightLinesFromNode(finishNode);
            var neighbours             = Neighbours(startTreeNode, nodesArray, finishNode);

            var minMetrics = startNode.Distance;
            var tempList   = new List <Node>();

            if (sraightLinesFromStart.Lines != null)
            {
                foreach (var lineFromFinish in sraightLinesFromFinish.Lines)
                {
                    foreach (var line in sraightLinesFromStart.Lines)
                    {
                        var coordinates = StraightLine.Crossing(line, lineFromFinish);
                        if (coordinates != null && Reachable(nodesArray[coordinates.X, coordinates.Y], finishNode, nodesArray) &&
                            Reachable(startNode, nodesArray[coordinates.X, coordinates.Y], nodesArray))
                        {
                            var tempNode = new Node(nodesArray[coordinates.X, coordinates.Y]);
                            tempNode.Distance            = Metrics(new Tree_Node(startTreeNode, tempNode), finishNode);
                            tempNode.TargetJP            = true;
                            tempNode.DestinationToFinish = DestinationInverse(lineFromFinish.Destination);
                            tempNode.Visited             = NodeState.Discovered;
                            if (tempNode.Distance < minMetrics)
                            {
                                minMetrics = tempNode.Distance;
                                tempList.Clear();
                                tempList.Add(tempNode);
                            }
                            else if (Math.Abs(tempNode.Distance - minMetrics) < 0.00000000001)
                            {
                                tempList.Add(tempNode);
                            }
                        }
                    }
                }
            }
            var straightLines = StraightLinesFromNode.JoinLines(sraightLinesFromStart, sraightLinesFromFinish,
                                                                nodesArray);

            debugInfo = new DebugInformationAlgorithm
            {
                From            = startNode.InformerNode,
                To              = finishNode.InformerNode,
                Observed        = ToNodes(neighbours),
                LinesFromFinish = straightLines,
                CrossPoints     = tempList,
                Destroy         = false
            };
        }
        public static float Metrics(Tree_Node from, Node to)
        {
            var metricAStar = MetricsAStar(from.Currentnode.InformerNode, to.InformerNode);

            if (from.Parent != null)
            {
                var metric = (to.Position - from.Currentnode.Position).sqrMagnitude +
                             (from.Currentnode.Position - from.Parent.Position).sqrMagnitude;
                return(metric);
            }
            else
            {
                return(metricAStar);
            }
        }
示例#6
0
        public static bool SelectJPFromNeighbours(Tree_Node parent, Tree_Node neighbour)
        {
            var result = false;

            if (neighbour.Currentnode.DestinationFromPrevious == Destinations.UpLeft &&
                parent.Currentnode.NormMatrix[0, 0] > 0)
            {
                result = true;
            }
            if (neighbour.Currentnode.DestinationFromPrevious == Destinations.Up &&
                parent.Currentnode.NormMatrix[0, 1] > 0)
            {
                result = true;
            }
            if (neighbour.Currentnode.DestinationFromPrevious == Destinations.UpRight &&
                parent.Currentnode.NormMatrix[0, 2] > 0)
            {
                result = true;
            }
            if (neighbour.Currentnode.DestinationFromPrevious == Destinations.Left &&
                parent.Currentnode.NormMatrix[1, 0] > 0)
            {
                result = true;
            }
            if (neighbour.Currentnode.DestinationFromPrevious == Destinations.Right &&
                parent.Currentnode.NormMatrix[1, 2] > 0)
            {
                result = true;
            }
            if (neighbour.Currentnode.DestinationFromPrevious == Destinations.DownLeft &&
                parent.Currentnode.NormMatrix[2, 0] > 0)
            {
                result = true;
            }
            if (neighbour.Currentnode.DestinationFromPrevious == Destinations.Down &&
                parent.Currentnode.NormMatrix[2, 1] > 0)
            {
                result = true;
            }
            if (neighbour.Currentnode.DestinationFromPrevious == Destinations.DownRight &&
                parent.Currentnode.NormMatrix[2, 2] > 0)
            {
                result = true;
            }
            return(result);
        }
示例#7
0
        //---
        //修正TreeView元件支援shift全選後還要可以支援選擇三態
        public void KeybordTriState(Tree_Node BufNode)
        {
            Stack <TreeNode> stNodes;
            TreeNode         tnBuffer;
            bool             bMixedState;
            int iIndex;

            tnBuffer = BufNode;                                                         // re-buffer clicked node.

            stNodes = new Stack <TreeNode>(tnBuffer.Nodes.Count);                       // create a new stack and
            stNodes.Push(tnBuffer);                                                     // push buffered node first.
            do
            {                                                                           // let's pop node from stack,
                tnBuffer         = stNodes.Pop();                                       // inherit buffered node's
                tnBuffer.Checked = BufNode.Checked;                                     // check state and push
                for (int i = 0; i < tnBuffer.Nodes.Count; i++)                          // each child on the stack
                {
                    stNodes.Push(tnBuffer.Nodes[i]);                                    // until there is no node
                }
            } while (stNodes.Count > 0);                                                // left.

            bMixedState = false;
            tnBuffer    = BufNode;
            while (tnBuffer.Parent != null)
            {                                                                   // while we get a parent we
                foreach (TreeNode tnChild in tnBuffer.Parent.Nodes)             // determine mixed check states
                {
                    bMixedState |= (tnChild.Checked != tnBuffer.Checked |       // and convert current check
                                    tnChild.StateImageIndex == 2);              // state to state image index.
                }
                iIndex = (int)Convert.ToUInt32(tnBuffer.Checked);               // set parent's check state and
                tnBuffer.Parent.Checked = bMixedState || (iIndex > 0);          // state image in dependency
                if (bMixedState)                                                // of mixed state.
                {
                    tnBuffer.Parent.StateImageIndex = CheckBoxesTriState ? 2 : 1;
                }
                else
                {
                    tnBuffer.Parent.StateImageIndex = iIndex;
                }
                tnBuffer = tnBuffer.Parent;                                                                     // finally buffer parent and
            }                                                                                                   // loop here.
        }
        public JsonResult GetTreeData()
        {
            List <CampStep>  dbsteps   = db.CampSteps.ToList <CampStep>();
            List <Tree_Node> treeNodes = new List <Tree_Node>();
            int nid = 0;

            foreach (CampStep s in dbsteps)
            {
                Tree_Node TN = new Tree_Node();

                TN.Text = s.Name;
                TN.Idx  = s.StepID;
                TN.nid  = nid;

                //create Nodes Obj for Tree Node
                List <Tree_SubNodes> treeSubNodes = new List <Tree_SubNodes>();

                int sCounter = 0;
                foreach (CampSubStep ss in s.CampSubSteps.ToList <CampSubStep>())
                {
                    sCounter += 1;
                    nid      += 1;

                    Tree_SubNodes TsN = new Tree_SubNodes();
                    TsN.text = ss.Name;
                    TsN.Idx  = ss.SubStepID;
                    TsN.href = "tabPanel" + ss.StepID.ToString() + "-" + ss.SubStepID.ToString();
                    TsN.nid  = nid;
                    treeSubNodes.Add(TsN);
                }

                TN.Nodes = treeSubNodes;

                treeNodes.Add(TN);
                nid += 1;
            }

            return(Json(treeNodes, JsonRequestBehavior.AllowGet));
        }
示例#9
0
        private void TreeViewNodeSelect(object sender, EventArgs e)
        {
            //---
            //按照『V8 功能選單』一個一個改-部門 ~ 修正ComboBoxTreeView元件未分類目錄顏色會因為選擇過而錯亂的BUG
            for (int i = 0; i < tvTreeView.Nodes.Count; i++)
            {
                Tree_Node tmp = (Tree_Node)tvTreeView.Nodes[i];
                if ((tmp.Text != this.tvTreeView.SelectedNode.Text))
                {
                    tmp.ForeColor = tmp.m_ColorBackup;
                }
            }
            //---按照『V8 功能選單』一個一個改-部門 ~ 修正ComboBoxTreeView元件未分類目錄顏色會因為選擇過而錯亂的BUG

            if (this._absoluteChildrenSelectableOnly)
            {
                //---
                //jash modified

                /*
                 *              if(this.tvTreeView.SelectedNode.Nodes.Count == 0)
                 *              {
                 *                      tbSelectedValue.Text = this.tvTreeView.SelectedNode.FullPath.Replace(@"\", this._branchSeparator);
                 *                      this.ToggleTreeView(sender,null);
                 *              }
                 */
                tbSelectedValue.Text = this.tvTreeView.SelectedNode.Text;
                this.ToggleTreeView(sender, null);
                //---jash modified
            }
            else
            {
                tbSelectedValue.Text = this.tvTreeView.SelectedNode.FullPath.Replace(@"\", this._branchSeparator);
                this.ToggleTreeView(sender, null);
            }
        }
示例#10
0
        public static List <Tree_Node> NeighboursSelective(Tree_Node parent, int x, int y, Node[,] array,
                                                           Destinations destination, Node finish)
        {
            var neighbours = new List <Tree_Node>();
            var parentNode = parent.Currentnode;


            //Left
            if (!array[x - 1, y].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Left ||
                    destination == Destinations.Up || destination == Destinations.Down ||
                    destination == Destinations.UpLeft || destination == Destinations.DownLeft)
                {
                    var delta = parentNode.NormMatrix[1, 0];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x - delta, y]);
                    node.DestinationFromPrevious = Destinations.Left;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Up-left
            if (!array[x - 1, y + 1].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Left ||
                    destination == Destinations.Up || destination == Destinations.UpLeft)
                {
                    var delta = parentNode.NormMatrix[0, 0];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x - delta, y + delta]);
                    node.DestinationFromPrevious = Destinations.UpLeft;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Up
            if (!array[x, y + 1].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Left ||
                    destination == Destinations.Up || destination == Destinations.Right ||
                    destination == Destinations.UpLeft || destination == Destinations.UpRight)
                {
                    var delta = parentNode.NormMatrix[0, 1];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x, y + delta]);
                    node.DestinationFromPrevious = Destinations.Up;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Up-right
            if (!array[x + 1, y + 1].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Right ||
                    destination == Destinations.Up || destination == Destinations.UpRight)
                {
                    var delta = parentNode.NormMatrix[0, 2];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x + delta, y + delta]);
                    node.DestinationFromPrevious = Destinations.UpRight;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Right
            if (!array[x + 1, y].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Right ||
                    destination == Destinations.Up || destination == Destinations.Down ||
                    destination == Destinations.UpRight || destination == Destinations.DownRight)
                {
                    var delta = parentNode.NormMatrix[1, 2];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x + delta, y]);
                    node.DestinationFromPrevious = Destinations.Right;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Down-right
            if (!array[x + 1, y - 1].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Right ||
                    destination == Destinations.Down || destination == Destinations.DownRight)
                {
                    var delta = parentNode.NormMatrix[2, 2];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x + delta, y - delta]);
                    node.DestinationFromPrevious = Destinations.DownRight;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Down
            if (!array[x, y - 1].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Left ||
                    destination == Destinations.Right || destination == Destinations.Down ||
                    destination == Destinations.DownLeft || destination == Destinations.DownRight)
                {
                    var delta = parentNode.NormMatrix[2, 1];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x, y - delta]);
                    node.DestinationFromPrevious = Destinations.Down;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Down-left
            if (!array[x - 1, y - 1].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Left ||
                    destination == Destinations.Down || destination == Destinations.DownLeft)
                {
                    var delta = parentNode.NormMatrix[2, 0];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x - delta, y - delta]);
                    node.DestinationFromPrevious = Destinations.DownLeft;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            foreach (var node in neighbours)
            {
                if (finish != null)
                {
                    node.Currentnode.Distance = Metrics(node, finish);
                }
                else
                {
                    node.Currentnode.Distance = parentNode.Distance + Metrics(node, parentNode);
                }
                node.Currentnode.Visited = NodeState.Discovered;
            }

            return(neighbours);
        }
示例#11
0
        public static List <Tree_Node> NeighboursForGB(Tree_Node parent, Tree_Node[,] tree_array, Node finish)
        {
            var array = new Node[tree_array.Rows(), tree_array.Columns()];

            for (var i = 0; i < array.Rows(); ++i)
            {
                for (var j = 0; j < array.Columns(); ++j)
                {
                    array[i, j] = tree_array[i, j].Currentnode;
                }
            }
            var neighbours  = new List <Tree_Node>();
            var parentNode  = parent.Currentnode;
            var x           = parent.Currentnode.X();
            var y           = parent.Currentnode.Y();
            var destination = parent.Currentnode.DestinationFromPrevious;

            //Left
            if (!array[x - 1, y].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Left ||
                    destination == Destinations.Up || destination == Destinations.Down ||
                    destination == Destinations.UpLeft || destination == Destinations.DownLeft)
                {
                    var delta = parentNode.NormMatrix[1, 0];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x - 1, y]);
                    node.DestinationFromPrevious = Destinations.Left;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Up-left
            if (!array[x - 1, y + 1].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Left ||
                    destination == Destinations.Up || destination == Destinations.UpLeft)
                {
                    var delta = parentNode.NormMatrix[0, 0];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x - 1, y + 1]);
                    node.DestinationFromPrevious = Destinations.UpLeft;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Up
            if (!array[x, y + 1].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Left ||
                    destination == Destinations.Up || destination == Destinations.Right ||
                    destination == Destinations.UpLeft || destination == Destinations.UpRight)
                {
                    var delta = parentNode.NormMatrix[0, 1];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x, y + 1]);
                    node.DestinationFromPrevious = Destinations.Up;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Up-right
            if (!array[x + 1, y + 1].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Right ||
                    destination == Destinations.Up || destination == Destinations.UpRight)
                {
                    var delta = parentNode.NormMatrix[0, 2];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x + 1, y + 1]);
                    node.DestinationFromPrevious = Destinations.UpRight;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Right
            if (!array[x + 1, y].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Right ||
                    destination == Destinations.Up || destination == Destinations.Down ||
                    destination == Destinations.UpRight || destination == Destinations.DownRight)
                {
                    var delta = parentNode.NormMatrix[1, 2];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x + 1, y]);
                    node.DestinationFromPrevious = Destinations.Right;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Down-right
            if (!array[x + 1, y - 1].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Right ||
                    destination == Destinations.Down || destination == Destinations.DownRight)
                {
                    var delta = parentNode.NormMatrix[2, 2];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x + 1, y - 1]);
                    node.DestinationFromPrevious = Destinations.DownRight;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Down
            if (!array[x, y - 1].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Left ||
                    destination == Destinations.Right || destination == Destinations.Down ||
                    destination == Destinations.DownLeft || destination == Destinations.DownRight)
                {
                    var delta = parentNode.NormMatrix[2, 1];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x, y - 1]);
                    node.DestinationFromPrevious = Destinations.Down;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            //Down-left
            if (!array[x - 1, y - 1].InformerNode.IsObstacle)
            {
                if (destination == Destinations.Default || destination == Destinations.Left ||
                    destination == Destinations.Down || destination == Destinations.DownLeft)
                {
                    var delta = parentNode.NormMatrix[2, 0];
                    delta = Math.Abs(delta);
                    var node = new Node(array[x - 1, y - 1]);
                    node.DestinationFromPrevious = Destinations.DownLeft;
                    if (delta != 0)
                    {
                        node.Visited = NodeState.Discovered;
                        neighbours.Add(new Tree_Node(parent, node));
                    }
                }
            }
            foreach (var node in neighbours)
            {
                if (node.DistanceFromParent > 10)
                {
                    node.Currentnode.Distance = node.Parent.Distance + (float)Math.Sqrt(2);
                }
                else
                {
                    node.Currentnode.Distance = node.Parent.Distance + 1f;
                }
                node.Currentnode.Visited = NodeState.Discovered;
            }

            return(neighbours);
        }