예제 #1
0
        /// <summary>
        /// Funkcja wywo³ywana przy zakoñczeniu w¹tku.
        /// </summary>
        /// <param name="sender">obiekt wysy³aj¹cy ¿¹danie zakoñczenia</param>
        /// <param name="e">parametry</param>
        private void threadCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            int index = -1;
            RectTreeNode tempNode = null;

            Debug.WriteLine("W¹tek zakoñczony");
            if (this.algorithm.GetRectangle() == null)
            {
                MessageBox.Show("Rozwi¹zanie zerowe");
                this.algorithm = null;
                this.EnableMenu(true);
                return;
            }

            Solution s = new Solution(this.algorithm.GetTag(), this.algorithm.GetRectangle());

            // sprawdzane, czy dane rozwi¹zanie ju¿ wyst¹pi³o
            for (int i = 0; i < this.solutions.Count; ++i)
            {
                if (this.solutions[i].Tag == s.Tag && i < this.rectanglesTreeView.Nodes[1].Nodes.Count)
                {
                    index = i;
                    tempNode = (RectTreeNode)this.rectanglesTreeView.Nodes[1].Nodes[i];
                    break;
                }
            }

            if (index == -1)
                index = this.solutions.Count;

            if (tempNode != null)
            {
                this.rectanglesTreeView.SelectedNode = tempNode;
                removeRectangleFromTreeView();
            }

            // dodawanie rozwi¹zanie
            addSolution(s, index);
            this.rectanglesTreeView.SelectedNode = this.rectanglesTreeView.Nodes[1].Nodes[index];
            TreeNodeMouseClickEventArgs eventArg = new TreeNodeMouseClickEventArgs(this.rectanglesTreeView.SelectedNode,
                MouseButtons.Left, 1, 0, 0);

            s.Ts = DateTime.Now.Subtract(dt);
            text += "Suma pól wszystkich prostok¹tów:  " + countArea() + "\n";
            text += "Pole wyliczonego prostok¹ta:            " + s.Rectangle.Area + "\n";
            text += "Czas wykonania:                                " + s.Ts.ToString();
            ((RectTreeNode)this.rectanglesTreeView.SelectedNode).InfoOutput = text;
            rectanglesTreeView_NodeMouseClick(this, eventArg);
            this.rectanglesTreeView.Refresh();
            this.algorithm = null;
            this.EnableMenu(true);
        }
예제 #2
0
 /// <summary>
 /// Dodawane rozwi¹zanie do listy rozwi¹zañ w odpowiednie miejsce.
 /// </summary>
 /// <param name="newSolution">nowe rozwi¹zanie</param>
 /// <param name="index">wskazane miejsce</param>
 private void addSolution(Solution newSolution, int index)
 {
     if (newSolution != null && index >= 0)
     {
         solutions.Insert(index, newSolution);
         RectTreeNode node = new RectTreeNode();
         Rectangle nsolRect = newSolution.Rectangle;
         String descr = "";
         if (nsolRect != null)
             descr = " (" + nsolRect.SideA + ", " + nsolRect.SideB + ", " + nsolRect.Area + ")";
         node.Text = newSolution.Tag + descr;
         this.rectanglesTreeView.Nodes[1].Nodes.Insert(index, node);
     }
 }