Exemplo n.º 1
0
 private void Area_tool_Click(object sender, EventArgs e)
 {
     if (ImagePropertiesClass.scale_set)
     {
         form_areadetails = new AreaDetails();
         currentpen = Commonforallfunctions.getdefaultpen();//to set default pen
         functiontime_settools(false);//set the tools enable property to false
         this.Cancel_tool.Enabled = true;
         Commonforallfunctions.setareabool(true);
         Commonforallfunctions.setdrawbool(true);
         Commonforallfunctions.setRecordpointsbool(true);//to indicate that points clicked are to be recorded in list.
         if (form_areadetails.ShowDialog() == DialogResult.OK)
         {
             area_class = new Area();
             this.LineStyle_tool.Enabled = true;
             area_class.area_name = form_areadetails.setareaname();
             area_thread = new AreaCalculation_Thread();
             Console.WriteLine("Area name is:" + area_class.area_name);//debugging purpose
             calculationfinish_Thread = new Thread(this.run);//thread started to see when above thread is finished.
             calculationfinish_Thread.Start();
         }
     }
     else
     {
         MessageBox.Show("Scale is to be set First \n Click on \"SetScale\" to set the scale", "You are missing something!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Exemplo n.º 2
0
        public static string solutionName = null; //To store project name

        #endregion Fields

        #region Methods

        public static bool addImage(int iid)
        {
            //Just adds the node and create the required dynamic functions..

            //TODO
            //the function should also create an image class and object,
            //that has image properties and dynamic functions to the tree nodes

            SQLiteDataReader db_data_local;
            SQLiteCommand db_cmd_local = ProjectClass.db_con.CreateCommand(); ;

            SQLiteDataReader db_data_local_2;
            SQLiteCommand db_cmd_local_2 = ProjectClass.db_con.CreateCommand(); ;

            string imageName = "";
            string imagePath = "";
            Line line_class;
            Area area_class;
            PointF pt;
            string pen_style="";//to insert pen_style for line and ares

            //Read iid from DB
            db_cmd_local.CommandText = "SELECT name, extension, scale,scale_set,scale_x1,scale_y1,scale_x2,scale_y2 ,scale_unit FROM images WHERE iid='" + iid + "';";
            db_data_local = db_cmd_local.ExecuteReader();
            if (db_data_local.Read())
            {
                imageName = db_data_local.GetString(0);
                imagePath = System.IO.Path.Combine(imageDirPath, iid + db_data_local.GetString(1));
                ImagePropertiesClass.scale_value = db_data_local.GetFloat(2);
                if (ImagePropertiesClass.scale_value != 0)
                {
                    ImagePropertiesClass.scale_value = db_data_local.GetFloat(2);
                    ImagePropertiesClass.scale_set = true;
                    Console.WriteLine("!!!!!!!!!!!!!!!!!!!Vale of scale set:" + db_data_local.GetName(3) + db_data_local.GetName(4));
                    ImagePropertiesClass.scale_startpt.X = db_data_local.GetFloat(4);
                    ImagePropertiesClass.scale_startpt.Y = db_data_local.GetFloat(5);
                    ImagePropertiesClass.scale_endpt.X = db_data_local.GetFloat(6);
                    ImagePropertiesClass.scale_endpt.Y = db_data_local.GetFloat(7);
                    ImagePropertiesClass.scale_unit = db_data_local.GetString(8);

                }
                Console.WriteLine("Value of scale set:" + db_data_local.GetName(3));

            }
            db_data_local.Close();

            string tempiid = "image_" + iid.ToString();

            //To add node in the first node of tree
            TreeNode mainNode = new TreeNode();
            mainNode.Name = tempiid;
            mainNode.Text = imageName;
            mainForm.treeView1.Nodes[0].Nodes.Add(mainNode);
            mainForm.treeView1.Nodes[0].ExpandAll();

            mainNode = new TreeNode();
            mainNode.Name = iid.ToString() + "_Lines";
            mainNode.Text = "Lines";
            mainForm.treeView1.Nodes[0].FirstNode.Nodes.Add(mainNode);
            mainForm.treeView1.ExpandAll();
            mainForm.line_list = mainNode;

            mainNode = new TreeNode();
            mainNode.Name = iid.ToString() + "_Areas";
            mainNode.Text = "Areas";
            mainForm.treeView1.Nodes[0].FirstNode.Nodes.Add(mainNode);
            mainForm.treeView1.ExpandAll();
            mainForm.area_list = mainNode;

            db_cmd_local.CommandText = "SELECT name, x1, y1, x2, y2, color,length,line_style,lid  FROM lines;"; // WHERE iid='" + iid + "';";
            db_data_local = db_cmd_local.ExecuteReader();
            while (db_data_local.Read())
            {

                line_class = new Line();

                line_class.line_name = db_data_local.GetString(0);
                line_class.start.X = db_data_local.GetFloat(1);
                line_class.start.Y = db_data_local.GetFloat(2);
                line_class.end.X = db_data_local.GetFloat(3);
                line_class.end.Y = db_data_local.GetFloat(4);
                line_class.line_pen.Color = System.Drawing.Color.FromArgb(db_data_local.GetInt32(5));
                line_class.line_length = db_data_local.GetFloat(6);

                 pen_style=db_data_local.GetString(7);
                 line_class.lid = db_data_local.GetInt32(8);
                 Console.WriteLine("pen_style recorded: " + pen_style);
                if (pen_style == "Dot")
                {
                    line_class.line_pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                }
                else if (pen_style == "Dash")
                {
                    line_class.line_pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                }
                else if (pen_style == "DashDot")
                {
                    line_class.line_pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
                }
                else
                {
                    line_class.line_pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                }

                //added for multipoint nov19

                db_cmd_local_2.CommandText = "SELECT x, y FROM line_points WHERE lid=@lid ORDER BY pid;";
                db_cmd_local_2.Parameters.AddWithValue("@lid", line_class.lid);
                db_data_local_2 = db_cmd_local_2.ExecuteReader();
                while (db_data_local_2.Read())
                {
                    pt = new PointF();
                    pt.X = db_data_local_2.GetFloat(0);
                    pt.Y = db_data_local_2.GetFloat(1);
                    line_class.points.Add(pt);

                }
                db_data_local_2.Close();

                ProjectClass.mainForm.vector_lines.Add(line_class);

                //Added  by SAM for tree
                mainForm.line_list.Nodes.Add(new TreeNode(line_class.line_name));
            }
            db_data_local.Close();

            db_cmd_local.CommandText = "SELECT name, aid, color,area,area_style,shape ,radius FROM areas;"; // WHERE iid='" + iid + "';";
            db_data_local = db_cmd_local.ExecuteReader();
            while (db_data_local.Read())
            {
                area_class = new Area();
                area_class.area_name = db_data_local.GetString(0);
                area_class.aid = db_data_local.GetInt32(1);
                area_class.area_pen.Color = System.Drawing.Color.FromArgb(db_data_local.GetInt32(2));
                area_class.area_value = db_data_local.GetFloat(3);
                area_class.areapoints = new System.Collections.ArrayList();
                Console.WriteLine("value is:" + db_data_local.GetValue(5));
                area_class.shape = db_data_local.GetString(5);
                area_class.radius = db_data_local.GetFloat(6);
                //entry of area_style
                //Console.WriteLine("Area Style Type: "+db_data_local.GetString(4));
                pen_style = db_data_local.GetString(4);
                Console.WriteLine("pen_style recorded: " + pen_style);
                if (pen_style == "Dot")
                {
                    Console.WriteLine("pen_style is " + pen_style);
                    area_class.area_pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                }
                else if (pen_style == "Dash")
                {
                    Console.WriteLine("pen_style is " + pen_style);
                    area_class.area_pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                }
                else if (pen_style == "DashDot")
                {
                    Console.WriteLine("pen_style is " + pen_style);
                    area_class.area_pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
                }
                else
                {

                    area_class.area_pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                }

                db_cmd_local_2.CommandText = "SELECT x, y FROM area_points WHERE aid=@aid ORDER BY pid;"; // WHERE iid='" + iid + "';";
                db_cmd_local_2.Parameters.AddWithValue("@aid", area_class.aid);
                db_data_local_2 = db_cmd_local_2.ExecuteReader();
                while (db_data_local_2.Read())
                {
                    pt = new PointF();
                    pt.X = db_data_local_2.GetFloat(0);
                    pt.Y = db_data_local_2.GetFloat(1);
                    area_class.areapoints.Add(pt);
                }
                db_data_local_2.Close();

                //Added  by SAM for tree
                mainForm.area_list.Nodes.Add(new TreeNode(area_class.area_name));

                ProjectClass.mainForm.vector_areas.Add(area_class);
            }
            db_data_local.Close();

            //TODO optional
            //EXCEPTION File not exist exception unhandeled

            if (System.IO.File.Exists(imagePath))//to see if image file exists
            {
                mainForm.pictureBox1.Image = Image.FromFile(imagePath);
                //set the values of ImagePropertiesClass attributes.
                ImagePropertiesClass.imageLoaded = true;
                ImagePropertiesClass.originalImage = Image.FromFile(imagePath);
                ImagePropertiesClass.setvalues(imageName, iid, imagePath, Image.FromFile(imagePath), Image.FromFile(imagePath).PhysicalDimension);//set its values
               // return imgindatabase;
                return true;
            }

            else
            {
                return false;
            }

               // return true;
        }