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 CPOL
A Vector based tool to create and edit SVG images
SVGArtiste2_exe.zip
SvgArtiste.exe
SvgArtiste.vshost.exe.manifest
SVGLib.dll
Crom.Controls.dll
Draw.dll
SVGArtiste2_SampleSVGDrawings.zip
mercialago18.svg
SVGArtiste.svg
SVGArtiste2_src.zip
SVGLib
SVGLib.csproj.user
SVGLib.ndoc
SvgArtiste2.suo
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     :       DrawArea.cs
 *  Author   :       ajaysbritto@yahoo.com
 *  Date     :       21/03/2010
 *  --------------------------------------------------------------------------------------------------------------
 *  Change Log
 *  --------------------------------------------------------------------------------------------------------------
 *  Author	Comments
 */

#endregion Header

namespace SVGEditor2
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;
    using Crom.Controls.Docking;
    using Tools.ToolBoxes;

    public partial class SvgArtiste : Form
    {
        #region Fields

        static int _counter;

        DockableFormInfo _infoDocumentProperties;
        DockableFormInfo _infoFilesMain;
        DockableFormInfo _infoShapeProperties;
        DockableFormInfo _infoToolbar;
        shapeProperties _shapeProperties;
        WorkArea _svgMainFiles;
        WorkSpaceControlBox _svgProperties;
        ToolBox _toolBox;

        #endregion Fields

        #region Constructors

        public SvgArtiste()
        {
            InitializeComponent();
            Intialize();
        }

        #endregion Constructors

        #region Methods

        public void OnZoomChanged(object sender, EventArgs e)
        {
            _svgMainFiles.OnZoomChange(sender, e);
        }

        private void AboutToolStripMenuItemClick(object sender, EventArgs e)
        {
            var objAbout = new AboutBox();
            objAbout.ShowDialog();
        }

        private void BringToFrontToolStripMenuItemClick(object sender, EventArgs e)
        {
            _svgMainFiles.GetCurrentWorkForm().svgDrawForm.BringShapelToFront();
        }

        private void CopyToolStripMenuItemClick(object sender, EventArgs e)
        {
            _svgMainFiles.GetCurrentWorkForm().svgDrawForm.Copy();
        }

        private void CutToolStripMenuItemClick(object sender, EventArgs e)
        {
            _svgMainFiles.GetCurrentWorkForm().svgDrawForm.Cut();
        }

        private void DeleteToolStripMenuItemClick(object sender, EventArgs e)
        {
            _svgMainFiles.GetCurrentWorkForm().svgDrawForm.Delete();
        }

        private void ExitToolStripMenuItemClick(object sender, EventArgs e)
        {
            if (_svgMainFiles.CloseAll())
            {
                Close();
            }
        }

        private void GridOptionChaged(object sender, EventArgs e)
        {
            _svgMainFiles.GridOptionChanges(sender, e);
        }

        private void Intialize()
        {
            _svgMainFiles = new WorkArea();
            _svgMainFiles.PageChanged += OnPageSelectionChanged;
            _svgMainFiles.ToolDone += OnToolDone;
            _svgMainFiles.ItemsSelected += SvgMainFilesItemsSelected;

            _toolBox = new ToolBox {Size = new Size(113, 165)};
            _toolBox.ToolSelectionChanged += ToolSelectionChanged;

            _svgProperties = new WorkSpaceControlBox();
            _svgProperties.ZoomChange += OnZoomChanged;
            _svgProperties.GridOptionChange += GridOptionChaged;
            _svgProperties.WorkAreaOptionChange += SvgPropertiesWorkAreaOptionChange;

            _infoFilesMain = _docker.Add(_svgMainFiles, zAllowedDock.Fill, new Guid("a6402b80-2ebd-4fd3-8930-024a6201d001"));
            _infoFilesMain.ShowCloseButton = false;

            _infoToolbar = _docker.Add(_toolBox, zAllowedDock.All, new Guid("a6402b80-2ebd-4fd3-8930-024a6201d002"));
            _infoToolbar.ShowCloseButton = false;

            _infoDocumentProperties = _docker.Add(_svgProperties, zAllowedDock.All, new Guid("a6402b80-2ebd-4fd3-8930-024a6201d003"));
            _infoDocumentProperties.ShowCloseButton = false;

            _shapeProperties = new shapeProperties();
            _shapeProperties.PropertyChanged += ShapePropertiesPropertyChanged;
            _infoShapeProperties = _docker.Add(_shapeProperties, zAllowedDock.All, new Guid("a6402b80-2ebd-4fd3-8930-024a6201d004"));
            _infoShapeProperties.ShowCloseButton = false;
        }

        private void NewToolStripMenuItemNewClick(object sender, EventArgs e)
        {
            _svgMainFiles.AddNewPage("New:" + _counter++);
        }

        private void OnPageSelectionChanged(object sender, EventArgs e)
        {
            var tool = _svgMainFiles.GetCurrentTool();

            _svgProperties.SetZoom(_svgMainFiles.GetZoom());

            bool opt = _svgMainFiles.GetGridOption();
            int minorGrids = _svgMainFiles.GetMinorGrids();
            Size gridSize = _svgMainFiles.GetCurrentWorkForm().svgDrawForm.GetWorkAreaSize();
            String desc = _svgMainFiles.GetCurrentWorkForm().svgDrawForm.GetSvgDescription();

            _svgProperties.SetGridOption(opt, minorGrids, gridSize, desc);
            _toolBox.SetToolSelection(tool);
        }

        private void OnToolDone(object sender, EventArgs e)
        {
            //Set to pointer
            _toolBox.SetToolSelection(DrawTools.DrawArea.DrawToolType.Pointer);
            if (((DrawTools.DrawArea)sender).GraphicsList.SelectionCount == 0)
            {
                _shapeProperties.propertyGrid.SelectedObject = null;
            }
        }

        private void OpenToolStripMenuItemClick(object sender, EventArgs e)
        {        
            var flgOpenFileDialog = new OpenFileDialog();
            flgOpenFileDialog.Filter = @"SVG files (*.svg)|*.svg|All files (*.*)|*.*";

            if (flgOpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                _svgMainFiles.OpenDocument(flgOpenFileDialog.FileName);
            }
        }

        private void PasteToolStripMenuItemClick(object sender, EventArgs e)
        {
            _svgMainFiles.GetCurrentWorkForm().svgDrawForm.Paste();
        }

        private void RedoToolStripMenuItemClick(object sender, EventArgs e)
        {
            _svgMainFiles.GetCurrentWorkForm().svgDrawForm.Redo();
        }

        private void SaveToolStripMenuItemClick(object sender, EventArgs e)
        {
            var dlgSaveFileDialog = new SaveFileDialog();
            dlgSaveFileDialog.Filter = @"SVG files (*.svg)|*.svg|All files (*.*)|*.*";
            if (dlgSaveFileDialog.ShowDialog() == DialogResult.OK)
            {
                _svgMainFiles.SaveDocument(dlgSaveFileDialog.FileName);
            }
        }

        private void SendBackToolStripMenuItemClick(object sender, EventArgs e)
        {
            _svgMainFiles.GetCurrentWorkForm().svgDrawForm.SendShapeToBack();
        }

        void ShapePropertiesPropertyChanged(object sender, PropertyValueChangedEventArgs e)
        {
            _svgMainFiles.PropertyChanged(e.ChangedItem, e.OldValue);
        }

        void SvgMainFilesItemsSelected(object sender, MouseEventArgs e)
        {
            int i = 0;
            var selectedItems = (List<Draw.DrawObject>)sender;
            var obj = new object[selectedItems.Count];
            foreach (Draw.DrawObject dob in selectedItems)
            {
                obj[i++] = dob;
            }

            if (selectedItems.Count > 0)
            {
                _shapeProperties.propertyGrid.SelectedObjects = obj;
            }
        }

        private void SvgMainShown(object sender, EventArgs e)
        {
            _docker.DockForm(_infoToolbar, DockStyle.Left, zDockMode.Inner);
            _docker.DockForm(_infoFilesMain, DockStyle.Fill, zDockMode.Inner);
            _docker.DockForm(_infoDocumentProperties, DockStyle.Right, zDockMode.Inner);
            _docker.DockForm(_infoShapeProperties,_infoToolbar, DockStyle.Bottom, zDockMode.Outer);
            _svgMainFiles.AddNewPage("New:" + _counter++);
        }

        void SvgPropertiesWorkAreaOptionChange(object sender, WorkSpaceControlBox.ControlBoxEventArgs e)
        {
            _svgMainFiles.GetCurrentWorkForm().svgDrawForm.SetDrawAreaProperties(e.Size, e.Description);
        }

        private void ToolSelectionChanged(object sender, EventArgs e)
        {
            _svgMainFiles.SetTool((String)sender);
        }

        private void ToolStripButtonCloseClick(object sender, EventArgs e)
        {
            _svgMainFiles.CloseActiveDocument();
        }

        private void TsSelectAllClick(object sender, EventArgs e)
        {
            _svgMainFiles.GetCurrentWorkForm().svgDrawForm.SelectAll();
        }

        private void UndoToolStripMenuItemClick(object sender, EventArgs e)
        {
            _svgMainFiles.GetCurrentWorkForm().svgDrawForm.Undo();
        }

        private void UnSelectAllToolStripMenuItemClick(object sender, EventArgs e)
        {
            _svgMainFiles.GetCurrentWorkForm().svgDrawForm.UnSelectAll();
        }

        #endregion Methods

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _svgMainFiles.SaveDocument("");
        }
    }
}

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)

Share

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 | Terms of Use | Mobile
Web04 | 2.8.1411023.1 | Last Updated 3 Aug 2010
Article Copyright 2010 by Ajay Britto
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid