public HGeometry Copy()
 {
     if (type != GeometryType.CIRCLE)
     {
         var new_geom = new HGeometry();
         new_geom.type         = this.type;
         new_geom.penWidth     = this.penWidth;
         new_geom.transparency = this.transparency;
         new_geom.color        = this.color;
         new_geom.points       = new List <Point>(this.points);
         return(new_geom);
     }
     else
     {
         var new_geom = new HCircle();
         new_geom.type         = this.type;
         new_geom.penWidth     = this.penWidth;
         new_geom.transparency = this.transparency;
         new_geom.color        = this.color;
         new_geom.points       = new List <Point>(this.points);
         new_geom.radius       = (this as HCircle).radius;
         new_geom.filled       = (this as HCircle).filled;
         return(new_geom);
     }
 }
Exemple #2
0
        //


        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (sym_expo_textbox.Focused)
            {
                return;
            }
            e.Handled = true;
            switch (e.KeyCode)
            {
            case Keys.Oemplus:
                vp.projection_scale *= 2;
                break;

            case Keys.OemMinus:
                vp.projection_scale /= 2;
                break;

            case Keys.Delete:     // Delete geometry or point
                if (selected_geometry_idx != -1)
                {
                    if (selected_point_idx != -1)
                    {
                        if (symbol.geometry[selected_geometry_idx].points.Count() != 1)     // if only one point left - not need to delete it
                        {
                            symbol.geometry[selected_geometry_idx].removePoint(selected_point_idx);

                            selected_point_idx = -1;
                        }
                    }
                    else
                    {
                        symbol.geometry.RemoveAt(geom_explorer.SelectedIndex);
                        selected_geometry_idx = -1;
                        updateExplorerList();
                    }
                }

                break;

            case Keys.Left:

                if (selected_geometry_idx != -1)
                {
                    if (selected_point_idx != -1)     // if point selected - move point
                    {
                        moveSelectedPoint(-1, 0);
                    }
                    else
                    {     // else move whole geometry
                        symbol.geometry[selected_geometry_idx].move(-1, 0);
                    }
                }

                if (_edit_mode == Edit_mode.EDIT_SYMBOL)
                {
                    symbol.move(-1, 0);
                }


                break;

            case Keys.Right:
                if (selected_geometry_idx != -1)
                {
                    if (selected_point_idx != -1)     // if point selected - move point
                    {
                        moveSelectedPoint(1, 0);
                    }
                    else
                    {     // else move whole geometry
                        symbol.geometry[selected_geometry_idx].move(1, 0);
                    }
                }

                if (_edit_mode == Edit_mode.EDIT_SYMBOL)
                {
                    symbol.move(1, 0);
                }

                break;

            case Keys.Up:
                if (selected_geometry_idx != -1)
                {
                    if (selected_point_idx != -1)     // if point selected - move point
                    {
                        moveSelectedPoint(0, -1);
                    }
                    else
                    {     // else move whole geometry
                        symbol.geometry[selected_geometry_idx].move(0, -1);
                    }
                }

                if (_edit_mode == Edit_mode.EDIT_SYMBOL)
                {
                    symbol.move(0, -1);
                }

                break;

            case Keys.Down:
                if (selected_geometry_idx != -1)
                {
                    if (selected_point_idx != -1)     // if point selected - move point
                    {
                        moveSelectedPoint(0, 1);
                    }
                    else       // else move whole geometry

                    {
                        symbol.geometry[selected_geometry_idx].move(0, 1);
                    }
                }

                if (_edit_mode == Edit_mode.EDIT_SYMBOL)
                {
                    symbol.move(0, 1);
                }

                break;

            // Copy
            case Keys.C:

                if (e.Control && selected_geometry_idx != -1)
                {
                    var selected_geometry = symbol.geometry[selected_geometry_idx];
                    Clipboard.Clear();

                    // Set data to clipboard

                    Clipboard.SetDataObject(selected_geometry);
                    e.SuppressKeyPress = true;
                }
                break;

            //Paste
            case Keys.V:
                if (e.Control)
                {
                    // Get data from clipboard
                    HGeometry paste_result = null;

                    IDataObject data_object = Clipboard.GetDataObject();

                    if (Clipboard.ContainsData("S52_HPGL_Editor.HLineString"))
                    {
                        paste_result = (HGeometry)Clipboard.GetData("S52_HPGL_Editor.HLineString");
                    }
                    else if (Clipboard.ContainsData("S52_HPGL_Editor.HPolygon"))
                    {
                        paste_result = (HGeometry)Clipboard.GetData("S52_HPGL_Editor.HPolygon");
                    }
                    if (Clipboard.ContainsData("S52_HPGL_Editor.HPoint"))
                    {
                        paste_result = (HGeometry)Clipboard.GetData("S52_HPGL_Editor.HPoint");
                    }
                    else if (Clipboard.ContainsData("S52_HPGL_Editor.HCircle"))
                    {
                        paste_result = (HGeometry)Clipboard.GetData("S52_HPGL_Editor.HCircle");
                    }

                    if (paste_result != null)
                    {
                        symbol.geometry.Add(paste_result);
                        updateExplorerList();
                        geom_explorer.SelectedIndex = symbol.geometry.Count() - 1;
                        selectGeometry(symbol.geometry.Count() - 1);
                    }
                    e.SuppressKeyPress = true;
                }
                break;

            default:
                e.Handled = false;
                return;
                //break;
            }

            updatePointPosition();
            Refresh();
        }
Exemple #3
0
        // Mouse events

        private void canvas_MouseDown(object sender, MouseEventArgs e)
        {
            _mouse_startX = e.X;
            _mouse_startY = e.Y;


            if (e.Button == MouseButtons.Left)
            {
                if (_edit_mode == Edit_mode.ADD_GEOM) //Add new geometry of chosen type in selected point
                {
                    HGeometry new_geometry = null;

                    if (_addMode == GeometryType.CIRCLE)
                    {
                        new_geometry = new HCircle();
                        setEditiMode(Edit_mode.EDIT_GEOMETRY);
                    }
                    else if (_addMode == GeometryType.POINT)
                    {
                        new_geometry = new HPoint();
                        setEditiMode(Edit_mode.EDIT_GEOMETRY);
                    }
                    else if (_addMode == GeometryType.LINE)
                    {
                        new_geometry = new HLineString();
                        setEditiMode(Edit_mode.ADD_POINT);
                    }
                    else if (_addMode == GeometryType.POLYGON)
                    {
                        new_geometry = new HPolygon();
                        setEditiMode(Edit_mode.ADD_POINT);
                    }
                    var p = vp.unproject(new Point(e.X, e.Y));
                    new_geometry.addPoint(p);
                    symbol.geometry.Add(new_geometry);
                    updateExplorerList();
                    geom_explorer.SelectedIndex = symbol.geometry.Count() - 1;
                    selectGeometry(symbol.geometry.Count() - 1);
                    canvas.Refresh();
                }
                else if (_edit_mode == Edit_mode.ADD_POINT) // Append point to selected geometry
                {
                    symbol.geometry[selected_geometry_idx].points.Add(vp.unproject(new Point(e.X, e.Y)));

                    canvas.Refresh();
                }
                else
                {
                    if (selected_geometry_idx != -1)
                    {
                        var s_geom = symbol.geometry[selected_geometry_idx];

                        for (int i = 0; i < s_geom.points.Count(); i++)
                        {
                            var p = vp.project(s_geom.points[i]);

                            if (Math.Abs(p.X - e.X) < 6 && Math.Abs(p.Y - e.Y) < 6)
                            {
                                if (e.Button == MouseButtons.Left)
                                {
                                    selected_point_idx = i;

                                    p = symbol.geometry[selected_geometry_idx].points[selected_point_idx];

                                    point_x_val.Enabled = true;
                                    point_y_val.Enabled = true;

                                    point_x_val.Value = p.X;
                                    point_y_val.Value = p.Y;

                                    canvas.Refresh();
                                }
                            }
                        }
                    }
                }
            }
        }