Browse Source

also save as svg file

Rumei Ma 5 years ago
parent
commit
3d147bfde1

+ 1 - 11
SketchAssistant/SketchAssistant/Form1.Designer.cs

@@ -45,7 +45,6 @@ namespace SketchAssistant
 			this.toolStripLoadStatus = new System.Windows.Forms.ToolStripStatusLabel();
 			this.backgroundWorker2 = new System.ComponentModel.BackgroundWorker();
 			this.mouseTimer = new System.Windows.Forms.Timer(this.components);
-			this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 			this.tableLayoutPanel1.SuspendLayout();
 			((System.ComponentModel.ISupportInitialize)(this.pictureBoxRight)).BeginInit();
 			((System.ComponentModel.ISupportInitialize)(this.pictureBoxLeft)).BeginInit();
@@ -114,8 +113,7 @@ namespace SketchAssistant
 			// fileToolStripMenuItem
 			// 
 			this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
-            this.loadToolStripMenuItem,
-            this.saveToolStripMenuItem});
+            this.loadToolStripMenuItem});
 			this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
 			this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
 			this.fileToolStripMenuItem.Text = "File";
@@ -190,13 +188,6 @@ namespace SketchAssistant
 			this.mouseTimer.Interval = 1;
 			this.mouseTimer.Tick += new System.EventHandler(this.mouseTimer_Tick);
 			// 
-			// saveToolStripMenuItem
-			// 
-			this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
-			this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
-			this.saveToolStripMenuItem.Text = "Save...";
-			this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
-			// 
 			// Form1
 			// 
 			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -245,7 +236,6 @@ namespace SketchAssistant
         private System.Windows.Forms.ToolStripButton canvasButton;
         private System.Windows.Forms.ToolStripButton drawButton;
         private System.Windows.Forms.ToolStripButton deleteButton;
-		private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
 	}
 }
 

+ 29 - 1
SketchAssistant/SketchAssistant/Form1.cs

@@ -8,6 +8,8 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using System.IO;
+
 
 
 // This is the code for your desktop app.
@@ -98,7 +100,7 @@ namespace SketchAssistant
 		{
 			if (rightImage != null)
 			{
-				saveFileDialogRight.Filter = "Image|*.jpg;*.png;*.jpeg|" + "All files (*.*)|*.*";
+				saveFileDialogRight.Filter = "Image|*.jpg;*.png;*.jpeg|" + "Vector Graphics (*svg|*.svg" + "All files (*.*)|*.*" ;
 				ImageFormat format = ImageFormat.Jpeg;
 
 				if (saveFileDialogRight.ShowDialog() == DialogResult.OK)
@@ -106,6 +108,11 @@ namespace SketchAssistant
 
 					switch (saveFileDialogRight.Filter)
 					{
+						case ".svg":
+							String returnString = createSvgTxt();
+							File.WriteAllText(saveFileDialogRight.FileName, returnString);
+							return;
+
 						case ".png":
 
 							format = ImageFormat.Png;
@@ -130,6 +137,7 @@ namespace SketchAssistant
 
 		}
 
+
 		//Changes the state of the program to drawing
 		private void drawButton_Click(object sender, EventArgs e)
         {
@@ -423,5 +431,25 @@ namespace SketchAssistant
             return returnSet;
         }
 
+
+		private String createSvgTxt()
+		{
+			String newString = String.Format(@"< svg viewBox = ""0 0 {0} {1}"" xmlns = ""http://www.w3.org/2000/svg"" >", rightImage.Width, rightImage.Height);
+			foreach (Tuple<bool,Line> lineTuple in lineList)
+			{
+				if(lineTuple.Item1 == true)
+				{
+					String nextLine = String.Format("\n" + @"<line x1 = ""{0}"" y1 = ""{1}""2 x2 = ""{2}"" y2 = ""{3}"" stroke = ""black"" />\n", 
+													lineTuple.Item2.GetStartPoint().X, lineTuple.Item2.GetStartPoint().Y, lineTuple.Item2.GetEndPoint().X, lineTuple.Item2.GetEndPoint().X);
+					newString += nextLine;
+				}
+			}
+			return newString;
+		}
+
+		private void saveToolStripMenuItem1_Click(object sender, EventArgs e)
+		{
+
+		}
 	}
 }