11/* GRBL-Plotter. Another GCode sender for GRBL.
22 This file is part of the GRBL-Plotter application.
33
4- Copyright (C) 2015-2024 Sven Hasemann contact: [email protected] 4+ Copyright (C) 2015-2025 Sven Hasemann contact: [email protected] 55
66 This program is free software: you can redistribute it and/or modify
77 it under the terms of the GNU General Public License as published by
@@ -114,7 +114,17 @@ private void GCodeFromImage_FormClosing(object sender, FormClosingEventArgs e)
114114 {
115115 Logger . Info ( "++++++ GCodeFromImage STOP ++++++" ) ;
116116 Properties . Settings . Default . locationImageForm = Location ;
117- Properties . Settings . Default . importImagePixelArt = RbPixelArt . Checked ;
117+
118+ int processingMode = Properties . Settings . Default . importImageProcessingMode ;
119+ if ( RbGrayscalePattern . Checked ) { Properties . Settings . Default . importImageProcessingMode = 0 ; }
120+ else if ( RbGrayscaleVector . Checked ) { Properties . Settings . Default . importImageProcessingMode = 1 ; }
121+ else if ( RbPixelArt . Checked ) { Properties . Settings . Default . importImageProcessingMode = 2 ; }
122+
123+ if ( RbStartGrayZ . Checked ) { Properties . Settings . Default . importImageGrayAsMode = 0 ; }
124+ else if ( RbStartGrayS . Checked ) { Properties . Settings . Default . importImageGrayAsMode = 1 ; }
125+ else if ( RbStartGraySpecial . Checked ) { Properties . Settings . Default . importImageGrayAsMode = 2 ; }
126+
127+ Properties . Settings . Default . Save ( ) ;
118128
119129 pictureBox1 . Image = null ;
120130 adjustedImage = null ;
@@ -158,25 +168,13 @@ public GCodeFromImage(bool loadFile = false)
158168 }
159169
160170 #region load picture
161- //On form load
162- /* not used ??? */
163- private void GCodeFromImage_Load ( object sender , EventArgs e )
164- {
165- lblStatus . Text = "Done" ;
166- GetToolTableSettings ( ) ;
167- AutoZoomToolStripMenuItem_Click ( this , null ) ; //Set preview zoom mode
168- RbStartGrayS . Checked = ! Properties . Settings . Default . importImageGrayAsZ ;
169- RbPixelArtShape . Checked = ! Properties . Settings . Default . importImagePixelArtDrawDot ;
170- }
171-
172171 // load picture when form opens
173172 private void ImageToGCode_Load ( object sender , EventArgs e )
174173 {
175174 Location = Properties . Settings . Default . locationImageForm ;
176175 Size desktopSize = System . Windows . Forms . SystemInformation . PrimaryMonitorSize ;
177176 if ( ( Location . X < - 20 ) || ( Location . X > ( desktopSize . Width - 100 ) ) || ( Location . Y < - 20 ) || ( Location . Y > ( desktopSize . Height - 100 ) ) ) { CenterToScreen ( ) ; }
178177
179- RbStartGrayS . Checked = ! Properties . Settings . Default . importImageGrayAsZ ;
180178 RbPixelArtShape . Checked = ! Properties . Settings . Default . importImagePixelArtDrawDot ;
181179 RbPixelArtDrawShapeRect . Checked = ! Properties . Settings . Default . importImagePixelArtDrawShapeCircle ;
182180
@@ -187,18 +185,37 @@ private void ImageToGCode_Load(object sender, EventArgs e)
187185 else
188186 { tabControl2 . SelectedTab = tabPage2Gray ; }
189187
190- if ( Properties . Settings . Default . importImageGrayVectorize )
191- { RbGrayscaleVector . Checked = true ; }
192- else
193- { RbGrayscalePattern . Checked = true ; }
188+ int processingMode = Properties . Settings . Default . importImageProcessingMode ;
189+ if ( processingMode <= 0 )
190+ {
191+ RbGrayscalePattern . Checked = true ;
192+ GbOutputSizeSet . Visible = true ;
193+ GbOutputSizeShow . Visible = false ;
194+ RbGrayscaleVector_CheckedChanged ( sender , e ) ;
195+ }
196+ else if ( processingMode == 1 )
197+ {
198+ RbGrayscaleVector . Checked = true ;
199+ GbOutputSizeSet . Visible = true ;
200+ GbOutputSizeShow . Visible = false ;
201+ RbGrayscaleVector_CheckedChanged ( sender , e ) ;
202+ }
203+ else if ( processingMode >= 2 )
204+ {
205+ RbPixelArt . Checked = true ;
206+ GbOutputSizeSet . Visible = false ;
207+ GbOutputSizeShow . Visible = true ;
208+ RbGrayscaleVector_CheckedChanged ( sender , e ) ;
209+ }
194210
195- if ( ! Properties . Settings . Default . importImageGrayAsZ )
196- RbStartGrayS . Checked = true ;
211+ int grayMode = Properties . Settings . Default . importImageGrayAsMode ;
212+ if ( grayMode <= 0 ) { RbStartGrayZ . Checked = true ; }
213+ else if ( grayMode == 1 ) { RbStartGrayS . Checked = true ; }
214+ else if ( grayMode >= 2 ) { RbStartGraySpecial . Checked = true ; }
197215
198216 TabControl2_SelectedIndexChanged ( null , null ) ; // don't 'ApplyColorCorrections'
199217 }
200218 EnableControlEvents ( ) ;
201- RbPixelArt . Checked = Properties . Settings . Default . importImagePixelArt ;
202219
203220 ResetColorCorrectionControls ( ) ;
204221
@@ -207,6 +224,7 @@ private void ImageToGCode_Load(object sender, EventArgs e)
207224
208225 ProcessLoading ( ) ; // reset color corrections
209226 UpdateToolTableList ( ) ; // show tool-files and last loaded tools
227+ Highlight ( ) ;
210228 }
211229
212230 private static string lastFile = "" ;
@@ -302,7 +320,7 @@ public void LoadUrl(string url) // called from MainFormLoadFile 654
302320 MessageBox . Show ( string . Format ( "Error on loading from URL '{0}'\r \n {1}" , url , err . Message ) , "Error" ) ;
303321 }
304322 }
305-
323+
306324 private void GCodeFromImage_DragEnter ( object sender , DragEventArgs e )
307325 { e . Effect = DragDropEffects . All ; }
308326
@@ -359,7 +377,7 @@ private void ProcessLoading()
359377 GenerateResultImageGray ( ref resultToolNrArray ) ; // fill resultToolNrArray (Image-Pixel=GrayVal)
360378 }
361379 #endregion
362-
380+
363381 private void GetToolTableSettings ( )
364382 {
365383 if ( useColorMode ) // use color mode
@@ -449,7 +467,7 @@ private void ListAvailableTools(bool all = true)
449467 }
450468 CheckedListBoxTools . SelectedIndexChanged += CheckedListBoxTools_SelectedIndexChanged ;
451469 }
452-
470+
453471 /// <summary>
454472 /// update result after deselecting tools
455473 /// </summary>
@@ -517,7 +535,7 @@ private void ApplyColorCorrectionsEvent(object sender, EventArgs e) // nUDMaxCo
517535 if ( logEnable ) Logger . Trace ( "ApplyColorCorrectionsEvent sender:{0} preventEvent:{1} " , ( ( Control ) sender ) . Name , preventEvent ) ;
518536 if ( preventEvent ) return ;
519537 if ( ( sender . GetType ( ) == typeof ( RadioButton ) ) && ! ( ( RadioButton ) sender ) . Checked ) return ;
520- // if ((sender.GetType() == typeof(CheckBox)) && !((CheckBox)sender).Checked) return;
538+ // if ((sender.GetType() == typeof(CheckBox)) && !((CheckBox)sender).Checked) return;
521539
522540 DisableControlEvents ( ) ;
523541 {
@@ -573,7 +591,7 @@ private void ApplyColorCorrections(string source)
573591 resoFactorX = 1 ;
574592 resoFactorY = 1 ;
575593
576- LbLSizeXPic . Text = originalImage . Width . ToString ( ) + " px" ;
594+ LbLSizeXPic . Text = originalImage . Width . ToString ( ) + " px" ;
577595 LbLSizeYPic . Text = originalImage . Height . ToString ( ) + " px" ;
578596 UpdateSizeControls ( ) ;
579597
@@ -601,7 +619,7 @@ private void ApplyColorCorrections(string source)
601619 ySize = originalImage . Height * ( int ) NuDPixelArtDotsPerPixel . Value ;
602620 }
603621 pixelCount = xSize * ySize ;
604- Logger . Info ( "●●● ApplyColorCorrections pixelCount:{0} Size:{1} x {2} resoVal:{3} desiredX:{4} desiredY:{5}" , pixelCount , xSize , ySize , nUDResoX . Value , resoDesiredX , resoDesiredY ) ;
622+ Logger . Info ( "●●● ApplyColorCorrections pixelCount:{0} Size:{1} x {2} resoVal:{3:0.0000 } desiredX:{4:0.0000 } desiredY:{5:0.0000 }" , pixelCount , xSize , ySize , nUDResoX . Value , resoDesiredX , resoDesiredY ) ;
605623
606624 try
607625 {
@@ -1181,7 +1199,7 @@ private void Timer1_Tick(object sender, EventArgs e)
11811199 }
11821200 }
11831201 }
1184-
1202+
11851203 /// <summary>
11861204 /// Count amount of different colors in adjusted image
11871205 /// </summary>
@@ -1367,12 +1385,12 @@ private void PictureBox1_MouseMove(object sender, MouseEventArgs e)
13671385 oldPoint = e . Location ;
13681386 }
13691387 }
1370-
1388+
13711389 private static String HexConverter ( System . Drawing . Color c )
13721390 {
13731391 return "#" + c . R . ToString ( "X2" ) + c . G . ToString ( "X2" ) + c . B . ToString ( "X2" ) ;
13741392 }
1375-
1393+
13761394 private void CbExceptColor_CheckedChanged ( object sender , EventArgs e )
13771395 {
13781396 if ( cbExceptColor . Checked )
@@ -1559,6 +1577,11 @@ private void Highlight()
15591577 else
15601578 { RbStartGrayS . BackColor = GbStartGrayS . BackColor = Color . WhiteSmoke ; }
15611579
1580+ if ( RbStartGraySpecial . Checked )
1581+ { RbStartGraySpecial . BackColor = GbStartGraySpecial . BackColor = Color . Yellow ; }
1582+ else
1583+ { RbStartGraySpecial . BackColor = GbStartGraySpecial . BackColor = Color . WhiteSmoke ; }
1584+
15621585 if ( RbEngravingLine . Checked )
15631586 { RbEngravingLine . BackColor = GbEngravingLine . BackColor = Color . Yellow ; }
15641587 else
@@ -1597,7 +1620,40 @@ private void RbEngravingLine_CheckedChanged(object sender, EventArgs e)
15971620
15981621 private void BtnReloadPattern_Click ( object sender , EventArgs e )
15991622 {
1600- // dummy function,
1623+ // dummy function,
16011624 }
1625+
1626+ private void TbPixelArtDrawShapeFileDialog_Click ( object sender , EventArgs e )
1627+ {
1628+ SetFilePath ( TbPixelArtDrawShapeScript ) ;
1629+ }
1630+
1631+ private void SetFilePath ( TextBox tmp , string filter = "GCode (*.nc)|*.nc|All Files (*.*)|*.*" )
1632+ {
1633+ OpenFileDialog opnDlg = new OpenFileDialog ( ) ;
1634+ string ipath = Datapath . MakeAbsolutePath ( tmp . Text ) ;
1635+ Logger . Info ( "SetFilePath initiial: box:{0} makeAbsolute:{1}" , tmp . Text , ipath ) ;
1636+ opnDlg . InitialDirectory = ipath . Substring ( 0 , ipath . LastIndexOf ( "\\ " ) ) ;
1637+ opnDlg . Filter = filter ; //"GCode (*.nc)|*.nc|All Files (*.*)|*.*";
1638+ // MessageBox.Show(opnDlg.InitialDirectory+"\r\n"+ Application.StartupPath);
1639+ if ( opnDlg . ShowDialog ( this ) == DialogResult . OK )
1640+ {
1641+ FileInfo f = new FileInfo ( opnDlg . FileName ) ;
1642+ string path ;
1643+ Logger . Info ( "SetFilePath DirectoryName:{0} Datapath.AppDataFolder:{1}" , f . DirectoryName , Datapath . AppDataFolder ) ;
1644+ if ( f . DirectoryName == Datapath . AppDataFolder )
1645+ path = f . Name ; // only file name
1646+ else if ( f . DirectoryName . StartsWith ( Datapath . AppDataFolder ) )
1647+ path = f . FullName . Replace ( Datapath . AppDataFolder , "." ) ;
1648+ else
1649+ path = f . FullName ; // Full path
1650+ if ( path . StartsWith ( @".\" ) )
1651+ path = path . Substring ( 2 ) ;
1652+ tmp . Text = path ;
1653+ Logger . Info ( "SetFilePath changed: box:{0} makeAbsolute:{1}" , path , opnDlg . FileName ) ;
1654+ }
1655+ opnDlg . Dispose ( ) ;
1656+ }
1657+
16021658 }
16031659}
0 commit comments