@@ -24,44 +24,39 @@ namespace WernerCAD
2424 /// </summary>
2525 public partial class MainForm : Form
2626 {
27- List < Tuple < String , PointF ? > > Lines = new List < Tuple < string , PointF ? > > ( ) ;
28-
29- Matrix TransformationMatrix ;
30-
3127 OpenFileDialog OpenDialog ;
3228 SaveFileDialog SaveDialog ;
3329
34-
3530 public MainForm ( )
3631 {
3732 InitializeComponent ( ) ;
3833
3934 SaveDialog = new SaveFileDialog ( ) ;
4035 SaveDialog . Title = "Destination File" ;
41- SaveDialog . Filter = "TAP-Dateien(*.tap)|*.tap" ;
42-
36+ SaveDialog . Filter = "TAP-Dateien(*.tap)|*.tap|GCode-Dateien(*.gcode)|*.gcode" ;
4337
4438 OpenDialog = new OpenFileDialog ( ) ;
4539 OpenDialog . Title = "Source File" ;
46- OpenDialog . Filter = "TAP-Dateien(*.tap)|*.tap" ;
40+ OpenDialog . Filter = "TAP-Dateien(*.tap)|*.tap|GCode-Dateien(*.gcode)|*.gcode " ;
4741 }
48- void TransformPoints ( )
42+
43+ List < Tuple < string , PointF ? > > TransformLines ( Matrix matrix , List < Tuple < string , PointF ? > > lines )
4944 {
5045 List < PointF > list = new List < PointF > ( ) ;
51- foreach ( var l in Lines )
46+ foreach ( var l in lines )
5247 {
5348 if ( l . Item2 != null )
5449 {
5550 list . Add ( ( PointF ) l . Item2 ) ;
5651 }
5752 }
5853 PointF [ ] pointArr = list . ToArray ( ) ;
59- TransformationMatrix . TransformPoints ( pointArr ) ;
54+ matrix . TransformPoints ( pointArr ) ;
6055
6156 List < Tuple < String , PointF ? > > newLines = new List < Tuple < string , PointF ? > > ( ) ;
6257
6358 int i = 0 ;
64- foreach ( var l in Lines )
59+ foreach ( var l in lines )
6560 {
6661 if ( l . Item2 != null )
6762 {
@@ -74,22 +69,24 @@ void TransformPoints()
7469 }
7570 }
7671
77- Lines = newLines ;
72+
73+ return newLines ;
7874 }
7975
80-
81- void CalculateMatrix ( PointF soll , PointF ist )
76+ Matrix CalculateMatrix ( PointF soll , PointF ist )
8277 {
83- TransformationMatrix = new Matrix ( ) ;
78+ Matrix transformationMatrix = new Matrix ( ) ;
8479 double angleRad = Math . Atan2 ( soll . X * ist . Y - soll . Y * ist . X , soll . X * ist . X + soll . Y * ist . Y ) ;
8580 double angleDeg = angleRad * 180 / Math . PI ;
86- TransformationMatrix . RotateAt ( - ( float ) angleDeg , PointF . Empty ) ;
81+ transformationMatrix . RotateAt ( - ( float ) angleDeg , PointF . Empty ) ;
8782 Debug . WriteLine ( "Angle: " + angleDeg ) ;
83+ return transformationMatrix ;
8884 }
8985
90- void ReadFile ( )
86+ List < Tuple < String , PointF ? > > ReadFile ( )
9187 {
92- try
88+ List < Tuple < String , PointF ? > > lines = new List < Tuple < string , PointF ? > > ( ) ;
89+ try
9390 {
9491 using ( StreamReader r = new StreamReader ( SourceFileLabel . Text ) )
9592 {
@@ -98,11 +95,15 @@ void ReadFile ()
9895
9996 while ( ( line = r . ReadLine ( ) ) != null )
10097 {
98+ if ( line . Contains ( ';' ) )
99+ line = line . Split ( ';' ) [ 0 ] ;
100+ if ( line == "" )
101+ continue ;
102+
101103 Match otherMatch = Regex . Match ( line , @"[A-WZ][0-9\.]+" ) ;
102104 Match xMatch = Regex . Match ( line , @"X([0-9\.]+)" ) ;
103105 Match yMatch = Regex . Match ( line , @"Y([0-9\.]+)" ) ;
104106
105-
106107 string other = "" ;
107108
108109 while ( otherMatch . Success )
@@ -127,7 +128,7 @@ void ReadFile ()
127128 else
128129 point = new PointF ( lastX , lastY ) ;
129130
130- Lines . Add ( new Tuple < string , PointF ? > ( other , point ) ) ;
131+ lines . Add ( new Tuple < string , PointF ? > ( other , point ) ) ;
131132 }
132133 }
133134 }
@@ -140,32 +141,37 @@ void ReadFile ()
140141
141142 try
142143 {
143- CalculateMatrix ( new PointF ( float . Parse ( textBoxSollX . Text ) , float . Parse ( textBoxSollY . Text ) ) , new PointF ( float . Parse ( textBoxIstX . Text ) , float . Parse ( textBoxIstY . Text ) ) ) ;
144- TransformPoints ( ) ;
144+ PointF soll = new PointF ( float . Parse ( textBoxSollX . Text ) , float . Parse ( textBoxSollY . Text ) ) ;
145+ PointF ist = new PointF ( float . Parse ( textBoxIstX . Text ) , float . Parse ( textBoxIstY . Text ) ) ;
146+ Matrix matrix = CalculateMatrix ( soll , ist ) ;
147+
148+ return TransformLines ( matrix , lines ) ;
149+
145150 }
146151
147152 catch ( Exception ex )
148153 {
149154 MessageBox . Show ( ex . ToString ( ) ) ;
155+ return null ;
150156 }
151157 }
152158
153- void Button1Click ( object sender , EventArgs e )
159+ void ButtonStartClick ( object sender , EventArgs e )
154160 {
155161 if ( textBoxIstX . Text == "" || textBoxIstY . Text == "" || textBoxSollX . Text == "" || textBoxSollY . Text == "" || SourceFileLabel . Text == "" || DestFileLabel . Text == "" )
156162 {
157163 MessageBox . Show ( "Please fill all required fields!" ) ;
158164 return ;
159165 }
160- ReadFile ( ) ;
166+ List < Tuple < String , PointF ? > > lines = ReadFile ( ) ;
161167
162168 try
163169 {
164170 progressBar1 . Value = 50 ;
165171 String formatString = "N" + numericUpDownDecCount . Value ;
166172
167173 string output = "" ;
168- foreach ( var l in Lines )
174+ foreach ( var l in lines )
169175 {
170176 String line = "" ;
171177 line += l . Item1 ;
@@ -177,15 +183,9 @@ void Button1Click ( object sender, EventArgs e )
177183
178184 output += line + Environment . NewLine ;
179185 }
180-
181- if ( File . Exists ( SaveDialog . FileName ) )
182- File . Delete ( SaveDialog . FileName ) ;
183-
184186 File . WriteAllText ( SaveDialog . FileName , output ) ;
185-
186187 progressBar1 . Value = 100 ;
187-
188- MessageBox . Show ( "Successfully converted .TAP File!" ) ;
188+ MessageBox . Show ( "Successfully converted File!" ) ;
189189 }
190190
191191 catch ( Exception ex )
0 commit comments