Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

SVG Artiste - An SVG Editor

, 3 Aug 2010
A Vector based tool to create and edit SVG images
SVGArtiste2_exe.zip
SVGArtiste2_SampleSVGDrawings.zip
SVGArtiste2_src.zip
SVGLib
SVGLib.csproj.user
SVGLib.ndoc
Crom.Controls
Dock16x16.bmp
Internal
Docking
ControlCollections
Controls
DockButtons
Forms
Engine
Enums
EventArgs
Helpers
SharedHelpers
Properties
Public
Docking
Enums
EventArgs
Helpers
Renderers
TabbedDocument
Controls
Enums
Helpers
Renderers
Base
Draw
Command
Draw.csproj.user
RulerControl
Ruler.bmp
SvgArtiste2
Properties
Settings.settings
Resources
cancel.png
Ellipse.cur
exit.png
exit1.png
Line.cur
new.png
new_page.png
open.png
open1.png
pan.cur
pan_close.cur
Pencil.cur
Rectangle.cur
save.png
save_as.png
save_as1.png
Text.cur
SVGArtiste.csproj.user
Tools
Forms
UserControls
#region Header

/*  --------------------------------------------------------------------------------------------------------------
 *  I Software Innovations
 *  --------------------------------------------------------------------------------------------------------------
 *  SVG Artieste 2.0
 *  --------------------------------------------------------------------------------------------------------------
 *  File     :       WorkSpace.cs
 *  Author   :       ajaysbritto@yahoo.com
 *  Date     :       20/03/2010
 *  --------------------------------------------------------------------------------------------------------------
 *  Change Log
 *  --------------------------------------------------------------------------------------------------------------
 *  Author	Comments
 */

#endregion Header

namespace SVGEditor2.UserControls
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Xml;

    public partial class WorkSpace : UserControl
    {
        #region Constructors

        public WorkSpace()
        {
            InitializeComponent();
            drawArea.ToolDone += ResetToolSelection;
            drawArea.MousePan += DrawAreaMousePan;
            drawArea.ItemsSelected += DrawAreaItemsSelected;
            drawArea.Initialize(this);
            ResizeDrawArea();
        }

        #endregion Constructors

        #region Delegates

        public delegate void OnGridOptionChanged(object sender, EventArgs e);

        public delegate void OnItemsInSelection(object sender, MouseEventArgs e);

        public delegate void OnMousePan(object sender, MouseEventArgs e);

        public delegate void OnScrollMade(object sender, ScrollEventArgs e);

        public delegate void OnToolDone(object sender, EventArgs e);

        public delegate void OnZoomDone(object sender, EventArgs e);

        #endregion Delegates

        #region Events

        public event OnGridOptionChanged GridChange;

        public event OnItemsInSelection ItemsSelected;

        public event OnMousePan MousePan;

        public event OnScrollMade ScrollMade;

        public event WorkArea.OnToolDone ToolDone;

        public event OnZoomDone ZoomDone;

        #endregion Events

        #region Methods

        public void BringShapelToFront()
        {
            drawArea.GraphicsList.MoveSelectionToFront();
            drawArea.Refresh();
        }

        public bool CheckDirty()
        {
            return drawArea.Dirty;
        }

        public void Copy()
        {
            drawArea.GraphicsList.CopySelection();
            drawArea.Refresh();
        }

        public void Cut()
        {
            drawArea.GraphicsList.CutSelection();
            drawArea.Refresh();
        }

        public void Delete()
        {
            drawArea.GraphicsList.DeleteSelection();
            drawArea.Refresh();
        }

        public DrawTools.DrawArea.DrawToolType GetCurrentTool()
        {
            return drawArea.ActiveTool;
        }

        public float GetCurrentZoom()
        {
            return drawArea.ScaleDraw.Width;
        }

        public bool GetGridOption()
        {
            return drawArea.DrawGrid;
        }

        public int GetMinorGrids()
        {
            return (int)drawArea.Xdivs;
        }

        public String GetSvgDescription()
        {
            return drawArea.Description;
        }

        public Size GetWorkAreaSize()
        {
            return new Size(drawArea.Size.Width -1, drawArea.Size.Height -1);
        }

        public void GridOptionChanged(object sender, EventArgs e)
        {
            if (GridChange != null)
                GridChange(sender, e);

            if (sender.GetType().ToString() == "System.Windows.Forms.CheckBox")
            {
                var option = (CheckBox)sender;
                drawArea.DrawGrid = option.Checked;
            }
            else if (sender.GetType().ToString() == "System.Windows.Forms.NumericUpDown")
            {
                drawArea.Xdivs = (float)(((NumericUpDown)sender).Value);
                drawArea.Ydivs = (float)(((NumericUpDown)sender).Value);
            }

            drawArea.Refresh();
        }

        public void OpenFile(String fileName)
        {
            XmlTextReader reader = null;
            try
            {
                reader = new XmlTextReader(fileName);
                drawArea.LoadFromXml(reader);
                drawArea.FileName = fileName;
                ResizeDrawArea();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (reader != null) reader.Close();
            }
        }

        public void Paste()
        {
            drawArea.GraphicsList.PasteSelection();
            drawArea.Refresh();
        }

        public void PropertyChanged(GridItem itemChanged, object oldVal)
        {
            drawArea.PropertyChanged(itemChanged, oldVal);
            drawArea.Refresh();
        }

        public void Redo()
        {
            drawArea.GraphicsList.Redo();
            drawArea.Refresh();
        }

        public void ResizeDrawArea()
        {
            drawArea.Top = ClientRectangle.Top - VerticalScroll.Value;
            drawArea.Left = ClientRectangle.Left - HorizontalScroll.Value;
            drawArea.Width = (int)drawArea.SizePicture.Width + 1;
            drawArea.Height = (int)drawArea.SizePicture.Height + 1;
        }

        public void RestoreScroll()
        {
            HorizontalScroll.Value = _scrollPersistance.X;
            VerticalScroll.Value = _scrollPersistance.Y;
        }

        public void SaveFile(String fileName)
        {
            System.IO.StreamWriter writer = null;

            if (String.IsNullOrEmpty(fileName))
            {
                //I've opened this file. So i know the file name
                if (!(String.IsNullOrEmpty(drawArea.FileName)))
                {
                    fileName = drawArea.FileName;
                }
                else
                {
                    var dlgSaveFileDialog = new SaveFileDialog();
                    dlgSaveFileDialog.Filter = @"SVG files (*.svg)|*.svg|All files (*.*)|*.*";

                    if (dlgSaveFileDialog.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }
                    fileName = dlgSaveFileDialog.FileName;
                }
            }

            try
            {
                writer = new System.IO.StreamWriter(fileName);
                drawArea.SaveToXml(writer);
                MessageBox.Show(@"Save Done");
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (writer != null) writer.Close();
            }
        }

        public void SelectAll()
        {
            drawArea.GraphicsList.SelectAll();
            drawArea.Refresh();
        }

        public void SendShapeToBack()
        {
            drawArea.GraphicsList.MoveSelectionToBack();
            drawArea.Refresh();
        }

        public void SetDrawAreaProperties(Size size, String desc)
        {
            drawArea.Description = desc;
            drawArea.Size = size;
            drawArea.SizePicture = size;
            drawArea.Refresh();
        }

        public void SetGridDivs(float x, float y)
        {
            drawArea.Xdivs = x;
            drawArea.Ydivs = y;
            drawArea.Refresh();
        }

        public void SetTool(String tool)
        {
            switch (tool)
            {
                case "Pointer":
                    drawArea.ActiveTool = DrawTools.DrawArea.DrawToolType.Pointer;
                    break;

                case "Rectangle":
                    drawArea.ActiveTool = DrawTools.DrawArea.DrawToolType.Rectangle;
                    break;

                case "Ellipse":
                    drawArea.ActiveTool = DrawTools.DrawArea.DrawToolType.Ellipse;
                    break;

                case "Line":
                    drawArea.ActiveTool = DrawTools.DrawArea.DrawToolType.Line;
                    break;

                case "Pan":
                    drawArea.ActiveTool = DrawTools.DrawArea.DrawToolType.Pan;
                    break;

                case "Pencil":
                    drawArea.ActiveTool = DrawTools.DrawArea.DrawToolType.Polygon;
                    break;

                case "Text":
                    drawArea.ActiveTool = DrawTools.DrawArea.DrawToolType.Text;
                    break;

                case "Path":
                    drawArea.ActiveTool = DrawTools.DrawArea.DrawToolType.Path;
                    break;

                case "Image":
                    drawArea.ActiveTool = DrawTools.DrawArea.DrawToolType.Bitmap;
                    break;

                default:
                    drawArea.ActiveTool = DrawTools.DrawArea.DrawToolType.Pointer;
                    break;
            }
        }

        public void SetZoom(float zoom)
        {
            drawArea.DoScaling(new SizeF(zoom, zoom));
            ResizeDrawArea();
            drawArea.Refresh();
            ZoomDone((object)zoom, new EventArgs());
        }

        public void Undo()
        {
            drawArea.GraphicsList.Undo();
            drawArea.Refresh();
        }

        public void UnSelectAll()
        {
            drawArea.GraphicsList.UnselectAll();
            drawArea.Refresh();
        }

        protected override void OnScroll(ScrollEventArgs se)
        {
            _scrollPersistance.X = HorizontalScroll.Value;
            _scrollPersistance.Y = VerticalScroll.Value;

               if (ScrollMade != null)
                ScrollMade(this, se);
        }

        protected override Point ScrollToControl(Control activeControl)
        {
            return DisplayRectangle.Location;
        }

        void DrawAreaItemsSelected(object sender, MouseEventArgs e)
        {
            if(ItemsSelected != null)
                ItemsSelected(sender, e);
        }

        private void DrawAreaMousePan(object sender, MouseEventArgs e)
        {
            if (MousePan != null)
                MousePan(sender, e);
        }

        private void ResetToolSelection(object sender, EventArgs e)
        {
            if(ToolDone!= null)
                ToolDone(sender, e);
        }

        #endregion Methods
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ajay Britto
Engineer
Singapore Singapore
He is a Microsoft technology enthusiast, who wish to create applications which others find useful.He loves making small tools and getting involved in architecting bigger systems.

He is currently working as a professional developer in a software development firm in .Net technologies.
 
He likes reading technical blogs, contributing to opensource and most importantly, enjoying life.
 
His ambition is to be an impressive software maker.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 3 Aug 2010
Article Copyright 2010 by Ajay Britto
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid