├── CPOL.htm
├── CREDITS.TXT
├── NOTES.txt
├── README.txt
├── screenshot.png
├── settings.png
└── src
├── CNCInfusion.sln
├── CNCInfusion.suo
└── CNCInfusion
├── .gitignore
├── CNCInfusion.csproj
├── CNCInfusion.csproj.user
├── CustomPanel
├── CornerCurveMode.cs
├── CustomPanel.cs
└── LinearGradientMode.cs
├── Data
└── Mill.xml
├── Knob
├── ColorMng.cs
├── Knob.bmp
├── KnobRenderer.cs
├── LBKnob.Designer.cs
├── LBKnob.cs
├── LBKnob.resx
└── MathFunc.cs
├── Program.cs
├── Properties
├── AssemblyInfo.cs
├── Resources.Designer.cs
├── Resources.resx
├── Settings.Designer.cs
└── Settings.settings
├── Resources
├── Color.bmp
├── DisplayOpts.bmp
├── EditInformation.bmp
├── OpenFolder.bmp
├── Refresh.png
├── Select.png
├── ToolLayers.bmp
├── ViewFence.bmp
├── ViewFit.bmp
├── ViewFront.bmp
├── ViewIso.bmp
├── ViewRight.bmp
├── ViewTop.bmp
├── screens1.bmp
├── screens2.bmp
├── screens4.bmp
├── viewpan.bmp
├── viewrotate.bmp
├── viewzoom.bmp
└── web.bmp
├── Samples
├── Splash.nc
├── coleracing.nc
├── fierologo.nc
├── merryChristmas.nc
└── plexipinion.nc
├── Settings.Designer.cs
├── Settings.cs
├── Settings.resx
├── Settings1.cs
├── SevenSegment
├── SevenSegment.cs
└── SevenSegmentArray.cs
├── Viewer
├── MG_CS_BasicViewer.Designer.cs
├── MG_CS_BasicViewer.cs
├── MG_CS_BasicViewer.resx
├── clsCadRect.cs
├── clsDisplayList.cs
├── clsMotionRecord.cs
└── clsToolLayer.cs
├── _frmViewer.cs
├── about.Designer.cs
├── about.cs
├── about.resx
├── app.config
├── bin
└── Debug
│ ├── .gitignore
│ ├── CNCInfusion.exe
│ ├── CNCInfusion.vshost.exe
│ ├── Data
│ └── Mill.xml
│ └── Samples
│ ├── Splash.nc
│ ├── coleracing.nc
│ ├── fierologo.nc
│ ├── merryChristmas.nc
│ └── plexipinion.nc
├── clsMachine.cs
├── clsMotion.cs
├── clsProcessor.cs
├── clsSettings.cs
├── colorcombox
└── EmrColorComboBox.cs
├── frmToolLayers.Designer.cs
├── frmToolLayers.cs
├── frmToolLayers.resx
├── frmViewer.Designer.cs
├── frmViewer.cs
├── frmViewer.resx
├── grblPreprocessor.cs
└── joystick
└── Joystick.cs
/CPOL.htm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/CPOL.htm
--------------------------------------------------------------------------------
/CREDITS.TXT:
--------------------------------------------------------------------------------
1 | NOTES:
2 |
3 | Grbl CNC was assembled using many components from code project
4 | and other internet sources.
5 |
6 | 2012 Paul D. Fincato
7 | Code Project Open License
8 |
9 |
10 | Credit to original authors of components used in this application
11 |
12 | G codebackplot
13 | --------------
14 | Jason Titcomb
15 | http://www.codeproject.com/Articles/17424/CNC-Graphical-Backplotter
16 | Code Project Open License
17 |
18 | 7 segment
19 | ---------
20 | Dmitry Brant
21 | http://dmitrybrant.com
22 | This component is free for personal use.
23 |
24 | Custom Panel
25 | ------------
26 | Mark Jackson
27 | http://www.codeproject.com/Articles/7641/Customising-the-NET-Panel-control
28 | Code Project Open License
29 |
30 | Knob
31 | ----
32 | Luca Bonotto
33 | http://www.codeproject.com/Articles/36116/Industrial-Controls-2
34 | Code Project Open License
35 |
36 | Icons
37 | -----
38 | Mark James
39 | http://www.famfamfam.com/lab/icons/silk/
40 | Creative Commons Attribution 3.0 License
41 |
42 | Joystick
43 | --------
44 | Interfacing with a Joystick using C#
45 | http://www.codeproject.com/Articles/16704/Interfacing-with-a-Joystick-using-C
46 | M Harris
47 |
48 | ColorComboBox
49 | http://www.codeproject.com/Articles/14296/EmrColorComboBox
50 | Ampiroid
51 |
52 | Kudos to the Grbl innovators for a great project!
53 |
54 | https://github.com/grbl/grbl
--------------------------------------------------------------------------------
/NOTES.txt:
--------------------------------------------------------------------------------
1 |
2 | SPECIAL COMMANDS
3 |
4 | #define CMD_STATUS_REPORT '?'
5 | #define CMD_FEED_HOLD '!'
6 | #define CMD_CYCLE_START '~'
7 | #define CMD_RESET 0x18 // ctrl-x
8 |
9 | SUPPORTED GrbL GCODES
10 |
11 | // Pass 1: Commands
12 | while(next_statement(&letter, &value, line, &char_counter)) {
13 | int_value = trunc(value);
14 | switch(letter) {
15 | case 'G':
16 | switch(int_value) {
17 | case 0: gc.motion_mode = MOTION_MODE_SEEK; break;
18 | case 1: gc.motion_mode = MOTION_MODE_LINEAR; break;
19 | case 2: gc.motion_mode = MOTION_MODE_CW_ARC; break;
20 | case 3: gc.motion_mode = MOTION_MODE_CCW_ARC; break;
21 | case 4: next_action = NEXT_ACTION_DWELL; break;
22 | case 17: select_plane(X_AXIS, Y_AXIS, Z_AXIS); break;
23 | case 18: select_plane(X_AXIS, Z_AXIS, Y_AXIS); break;
24 | case 19: select_plane(Y_AXIS, Z_AXIS, X_AXIS); break;
25 | case 20: gc.inches_mode = true; break;
26 | case 21: gc.inches_mode = false; break;
27 | case 28: case 30: next_action = NEXT_ACTION_GO_HOME; break;
28 | case 53: absolute_override = true; break;
29 | case 80: gc.motion_mode = MOTION_MODE_CANCEL; break;
30 | case 90: gc.absolute_mode = true; break;
31 | case 91: gc.absolute_mode = false; break;
32 | case 92: next_action = NEXT_ACTION_SET_COORDINATE_OFFSET; break;
33 | case 93: gc.inverse_feed_rate_mode = true; break;
34 | case 94: gc.inverse_feed_rate_mode = false; break;
35 | default: FAIL(STATUS_UNSUPPORTED_STATEMENT);
36 | }
37 | break;
38 | case 'M':
39 | switch(int_value) {
40 | case 0: case 60: gc.program_flow = PROGRAM_FLOW_PAUSED; break; // Program pause
41 | case 1: gc.program_flow = PROGRAM_FLOW_OPT_PAUSED; break; // Program pause with optional stop on
42 | case 2: case 30: gc.program_flow = PROGRAM_FLOW_COMPLETED; break; // Program end and reset
43 | case 3: gc.spindle_direction = 1; break;
44 | case 4: gc.spindle_direction = -1; break;
45 | case 5: gc.spindle_direction = 0; break;
46 | default: FAIL(STATUS_UNSUPPORTED_STATEMENT);
47 | }
48 | break;
49 | case 'T': gc.tool = trunc(value); break;
50 | }
51 | if(gc.status_code) { break; }
52 | }
53 |
54 | // If there were any errors parsing this line, we will return right away with the bad news
55 | if (gc.status_code) { return(gc.status_code); }
56 |
57 | char_counter = 0;
58 | clear_vector(target);
59 | clear_vector(offset);
60 | memcpy(target, gc.position, sizeof(target)); // i.e. target = gc.position
61 |
62 | // Pass 2: Parameters
63 | while(next_statement(&letter, &value, line, &char_counter)) {
64 | int_value = trunc(value);
65 | unit_converted_value = to_millimeters(value);
66 | switch(letter) {
67 | case 'F':
68 | if (unit_converted_value <= 0) { FAIL(STATUS_BAD_NUMBER_FORMAT); } // Must be greater than zero
69 | if (gc.inverse_feed_rate_mode) {
70 | inverse_feed_rate = unit_converted_value; // seconds per motion for this motion only
71 | } else {
72 | if (gc.motion_mode == MOTION_MODE_SEEK) {
73 | gc.seek_rate = unit_converted_value;
74 | } else {
75 | gc.feed_rate = unit_converted_value; // millimeters per minute
76 | }
77 | }
78 | break;
79 | case 'I': case 'J': case 'K': offset[letter-'I'] = unit_converted_value; break;
80 | case 'P': p = value; break;
81 | case 'R': r = unit_converted_value; radius_mode = true; break;
82 | case 'S': gc.spindle_speed = value; break;
83 | case 'X': case 'Y': case 'Z':
84 | if (gc.absolute_mode || absolute_override) {
85 | target[letter - 'X'] = unit_converted_value;
86 | } else {
87 | target[letter - 'X'] += unit_converted_value;
88 | }
89 | break;
90 | }
91 | }
92 |
93 |
94 | /*
95 | Intentionally not supported:
96 |
97 | - Canned cycles
98 | - Tool radius compensation
99 | - A,B,C-axes
100 | - Multiple coordinate systems
101 | - Evaluation of expressions
102 | - Variables
103 | - Multiple home locations
104 | - Probing
105 | - Override control
106 |
107 | group 0 = {G10, G28, G30, G92.1, G92.2, G92.3} (Non modal G-codes)
108 | group 8 = {M7, M8, M9} coolant (special case: M7 and M8 may be active at the same time)
109 | group 9 = {M48, M49} enable/disable feed and speed override switches
110 | group 12 = {G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3} coordinate system selection
111 | group 13 = {G61, G61.1, G64} path control mode
112 | */
113 |
114 | COMPILE TIME OPTIONS
115 |
116 | #if REPORT_INCH_MODE
117 | #define DECIMAL_PLACES 3
118 | #define DECIMAL_MULTIPLIER 1000 // 10^DECIMAL_PLACES
119 | #else
120 | #define DECIMAL_PLACES 2 // mm-mode
121 | #define DECIMAL_MULTIPLIER 100
122 | #endif
123 |
124 | Reporting units is compile time option
125 |
126 | #if REPORT_INCH_MODE
127 | printString("MPos:["); printFloat(print_position[X_AXIS]/(settings.steps_per_mm[X_AXIS]*MM_PER_INCH));
128 | printString(","); printFloat(print_position[Y_AXIS]/(settings.steps_per_mm[Y_AXIS]*MM_PER_INCH));
129 | printString(","); printFloat(print_position[Z_AXIS]/(settings.steps_per_mm[Z_AXIS]*MM_PER_INCH));
130 | printString("],WPos:["); printFloat((print_position[X_AXIS]-sys.coord_offset[X_AXIS])/(settings.steps_per_mm[X_AXIS]*MM_PER_INCH));
131 | printString(","); printFloat((print_position[Y_AXIS]-sys.coord_offset[Y_AXIS])/(settings.steps_per_mm[Y_AXIS]*MM_PER_INCH));
132 | printString(","); printFloat((print_position[Z_AXIS]-sys.coord_offset[Z_AXIS])/(settings.steps_per_mm[Z_AXIS]*MM_PER_INCH));
133 | #else
134 | printString("MPos:["); printFloat(print_position[X_AXIS]/(settings.steps_per_mm[X_AXIS]));
135 | printString(","); printFloat(print_position[Y_AXIS]/(settings.steps_per_mm[Y_AXIS]));
136 | printString(","); printFloat(print_position[Z_AXIS]/(settings.steps_per_mm[Z_AXIS]));
137 | printString("],WPos:["); printFloat((print_position[X_AXIS]-sys.coord_offset[X_AXIS])/(settings.steps_per_mm[X_AXIS]));
138 | printString(","); printFloat((print_position[Y_AXIS]-sys.coord_offset[Y_AXIS])/(settings.steps_per_mm[Y_AXIS]));
139 | printString(","); printFloat((print_position[Z_AXIS]-sys.coord_offset[Z_AXIS])/(settings.steps_per_mm[Z_AXIS]));
140 | #endif
141 |
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | // NOTICE:
2 | // This is currently under development and is only recommended for
3 | // air cutting in a controlled environment!
4 |
5 | What this attempts to be:
6 |
7 | A Windows GUI frontend written in C# to control flow of gcode to an
8 | Arduino based Grbl Gcode processor (https://github.com/grbl/grbl)
9 |
10 | I have just concentrated on basic functionality for hobby use. My CNC exposure
11 | has been limited to my home built mill, so I am not familiar with most
12 | of the G codes for anything much more than basic motion and spindle control.
13 |
14 | It should be obvious that I am not a professional coder. If you are, please help
15 | correct and enhance all of my "mis-features".
16 |
17 | This was created using:
18 |
19 | Visual C# 2010 Express (as of version 0.1.7.0)
20 |
21 | targetting .NET 2.0 framework
22 | http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=19
23 |
24 | See CREDITS.txt for additional information about the components used
25 |
26 | This version assumes Grbl edge (Grbl 0.7d) which uses '?' to report status and
27 | status is returned in this format :
28 |
29 | // Grbl edge status update looks like this: (Feb 2012)
30 | //MPos:[0.00,0.00,0.00],WPos:[0.00,0.00,0.00]
31 |
32 | The Status Update Interval in the settings form will enable reporting and the interval
33 |
34 | CNCInfusion has only been tested with this Grbl version (and only with a 'scope), although I suspect it should
35 | work on any version if status updates remain disabled.
36 |
37 | // TESTERS WANTED! I currently don't have a machine to test this on
38 | // I'm using an Arduino (328) with a scope only for testing at the
39 | // moment
40 |
41 | // HISTORY
42 | //
43 | // 0.1.0.0 - initial version
44 | // 0.1.1.0 - feed hold / soft reset
45 | // 0.1.2.0 - restructuring of serial comm code
46 | // - known problem with feedhold/cyclestart
47 | // 0.1.3.0 - fixed feedhold/cyclestart problem caused by ok response confusion
48 | // - known problem ocassionally with re-running after abort
49 | // 0.1.4.0 - modified delegates for use in threads (created at startup)
50 | // - starting to create preprocessor that only accepts Grbl gcode
51 | // - fixed status update interval problem
52 | // - fixed re-run after abort problem (added lock in commreceive)
53 | // - added timers for RX and TX indicators
54 | // - added basic preprocessor for grbl code
55 | // that is actually loaded and displayed in the backplotter
56 | // 0.1.5.0 - Grbl preprocessor modifications (needs more thorough testing)
57 | // - changes to settings form, more options
58 | // - initial code to support joystick
59 | // 0.1.6.0 - Error checking to detect grbl when opening serial port
60 | // - Added machine/world toggle on display
61 | // - regex now used to parse Grbl status report
62 | // 0.1.7.0 - Switched to Visual C# Express 2010 due to some
63 | // problems with SharpDevelop 3.2
64 |
65 | // TODO
66 | // REPORTING:
67 | // Grbl reporting of status is undergoing development:
68 | // listbox shows line being buffered in Grbl, not actual line executing (Grbl code for line status needed)
69 | // XON/XOFF is being worked as well in Grbl for flow control need to update this when code stabilizes
70 | //
71 | // MDI
72 | // JOG
73 | // Zero axes (world/machine?)
74 | // Joystick/Joypad integration - having issues on X64 Win7 development box at moment
75 | // Load/Save settings
76 | // Color preferences
77 | //
78 | // KNOWN PROBLEMS
79 | // Abort when feedhold is active, sometime causes loss of sync
80 | // with Grbl. Hard reset of grbl from Settings page restores
81 | // stability.
82 |
83 | /*
84 | FEATURES:
85 |
86 | Hardware (DTR) Reset in Settings
87 | Software Reset (0x18) on main form
88 | Feed Hold / Cycle start
89 | Zero Axes - Untested
90 |
91 | INCOMPLETE FEATURES:
92 |
93 | Status reporting - GRbl is undergoing heavy development in this area. What is
94 | currently there is mostly a placeholder as a proof of concept but is functional
95 |
96 | Feed Override - Grbl work in progress
97 | JOG - Not yet coded, GUI components in place
98 | MDI - Not yet coded, GUI components in place
99 | Status of modal gcodes - Maybe some indicators?
100 | */
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/screenshot.png
--------------------------------------------------------------------------------
/settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/settings.png
--------------------------------------------------------------------------------
/src/CNCInfusion.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual C# Express 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CNCInfusion", "CNCInfusion\CNCInfusion.csproj", "{9FA4A89F-11D1-40B9-AB2A-85233298A342}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {9FA4A89F-11D1-40B9-AB2A-85233298A342}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {9FA4A89F-11D1-40B9-AB2A-85233298A342}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {9FA4A89F-11D1-40B9-AB2A-85233298A342}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {9FA4A89F-11D1-40B9-AB2A-85233298A342}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/src/CNCInfusion.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion.suo
--------------------------------------------------------------------------------
/src/CNCInfusion/.gitignore:
--------------------------------------------------------------------------------
1 | obj/
2 |
--------------------------------------------------------------------------------
/src/CNCInfusion/CNCInfusion.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.50727
7 | 2.0
8 | {9FA4A89F-11D1-40B9-AB2A-85233298A342}
9 | WinExe
10 | Properties
11 | CNCInfusion
12 | CNCInfusion
13 | CNCInfusion.Program
14 | C:\Users\pdf\AppData\Roaming\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis
15 | False
16 | False
17 | false
18 | v2.0
19 |
20 |
21 |
22 |
23 | 4.0
24 | false
25 |
26 | publish\
27 | true
28 | Disk
29 | false
30 | Foreground
31 | 7
32 | Days
33 | false
34 | false
35 | true
36 | 0
37 | 1.0.0.%2a
38 | false
39 | true
40 |
41 |
42 | true
43 | Full
44 | false
45 | bin\Debug\
46 | DEBUG;TRACE
47 | prompt
48 | 4
49 |
50 |
51 | pdbonly
52 | true
53 | bin\Release\
54 | TRACE
55 | prompt
56 | 4
57 |
58 |
59 | False
60 |
61 |
62 | False
63 | Auto
64 | 4194304
65 | x86
66 | 4096
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | Form
81 |
82 |
83 | about.cs
84 |
85 |
86 |
87 |
88 |
89 |
90 | Component
91 |
92 |
93 |
94 | Component
95 |
96 |
97 |
98 | Form
99 |
100 |
101 | frmToolLayers.cs
102 |
103 |
104 | Form
105 |
106 |
107 | frmViewer.cs
108 |
109 |
110 | Form
111 |
112 |
113 |
114 |
115 |
116 | UserControl
117 |
118 |
119 |
120 |
121 |
122 |
123 | about.cs
124 |
125 |
126 | frmToolLayers.cs
127 | Designer
128 |
129 |
130 | frmViewer.cs
131 | Designer
132 |
133 |
134 |
135 | ResXFileCodeGenerator
136 | Resources.Designer.cs
137 | Designer
138 |
139 |
140 | Settings.cs
141 |
142 |
143 | MG_CS_BasicViewer.cs
144 |
145 |
146 | True
147 | Resources.resx
148 | True
149 |
150 |
151 |
152 |
153 | SettingsSingleFileGenerator
154 | Settings.Designer.cs
155 |
156 |
157 |
158 |
159 | True
160 | Settings.settings
161 | True
162 |
163 |
164 | Form
165 |
166 |
167 | Settings.cs
168 |
169 |
170 |
171 | UserControl
172 |
173 |
174 | UserControl
175 |
176 |
177 |
178 |
179 |
180 |
181 | UserControl
182 |
183 |
184 |
185 |
186 |
187 | PreserveNewest
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 | False
213 | Microsoft .NET Framework 4 %28x86 and x64%29
214 | true
215 |
216 |
217 | False
218 | .NET Framework 3.5 SP1 Client Profile
219 | false
220 |
221 |
222 | False
223 | .NET Framework 3.5 SP1
224 | false
225 |
226 |
227 | False
228 | Windows Installer 3.1
229 | true
230 |
231 |
232 |
233 |
240 |
--------------------------------------------------------------------------------
/src/CNCInfusion/CNCInfusion.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ProjectFiles
5 | publish\
6 |
7 |
8 |
9 |
10 |
11 | en-US
12 | false
13 |
14 |
--------------------------------------------------------------------------------
/src/CNCInfusion/CustomPanel/CornerCurveMode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Utility.Panel
4 | {
5 | [FlagsAttribute()] public enum CornerCurveMode
6 | {
7 |
8 | None = 0,
9 | TopLeft = 1,
10 | TopRight = 2,
11 | TopLeft_TopRight = 3,
12 | BottomLeft = 4,
13 | TopLeft_BottomLeft = 5,
14 | TopRight_BottomLeft = 6,
15 | TopLeft_TopRight_BottomLeft = 7,
16 | BottomRight = 8,
17 | BottomRight_TopLeft = 9,
18 | BottomRight_TopRight = 10,
19 | BottomRight_TopLeft_TopRight = 11,
20 | BottomRight_BottomLeft = 12,
21 | BottomRight_TopLeft_BottomLeft = 13,
22 | BottomRight_TopRight_BottomLeft = 14,
23 | All = 15
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/CNCInfusion/CustomPanel/CustomPanel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Utility.Panel
4 | {
5 |
6 | [System.Drawing.ToolboxBitmapAttribute(typeof(System.Windows.Forms.Panel))]
7 | public class CustomPanel : System.Windows.Forms.Panel
8 | {
9 | // Fields
10 | private System.Drawing.Color _BackColour1 = System.Drawing.SystemColors.Window;
11 | private System.Drawing.Color _BackColour2 = System.Drawing.SystemColors.Window;
12 | private LinearGradientMode _GradientMode = LinearGradientMode.None;
13 | private System.Windows.Forms.BorderStyle _BorderStyle = System.Windows.Forms.BorderStyle.None;
14 | private System.Drawing.Color _BorderColour = System.Drawing.SystemColors.WindowFrame;
15 | private int _BorderWidth = 1;
16 | private int _Curvature = 0;
17 | // Properties
18 | // Shadow the Backcolor property so that the base class will still render with a transparent backcolor
19 | private CornerCurveMode _CurveMode = CornerCurveMode.All;
20 |
21 | [System.ComponentModel.DefaultValueAttribute(typeof(System.Drawing.Color), "Window"), System.ComponentModel.CategoryAttribute("Appearance"), System.ComponentModel.DescriptionAttribute("The primary background color used to display text and graphics in the control.")]
22 | public new System.Drawing.Color BackColor
23 | {
24 | get
25 | {
26 | return this._BackColour1;
27 | }
28 | set
29 | {
30 | this._BackColour1 = value;
31 | if (this.DesignMode == true)
32 | {
33 | this.Invalidate();
34 | }
35 | }
36 | }
37 |
38 | [System.ComponentModel.DefaultValueAttribute(typeof(System.Drawing.Color), "Window"), System.ComponentModel.CategoryAttribute("Appearance"), System.ComponentModel.DescriptionAttribute("The secondary background color used to paint the control.")]
39 | public System.Drawing.Color BackColor2
40 | {
41 | get
42 | {
43 | return this._BackColour2;
44 | }
45 | set
46 | {
47 | this._BackColour2 = value;
48 | if (this.DesignMode == true)
49 | {
50 | this.Invalidate();
51 | }
52 | }
53 | }
54 |
55 | [System.ComponentModel.DefaultValueAttribute(typeof(LinearGradientMode), "None"), System.ComponentModel.CategoryAttribute("Appearance"), System.ComponentModel.DescriptionAttribute("The gradient direction used to paint the control.")]
56 | public LinearGradientMode GradientMode
57 | {
58 | get
59 | {
60 | return this._GradientMode;
61 | }
62 | set
63 | {
64 | this._GradientMode = value;
65 | if (this.DesignMode == true)
66 | {
67 | this.Invalidate();
68 | }
69 | }
70 | }
71 |
72 | [System.ComponentModel.DefaultValueAttribute(typeof(System.Windows.Forms.BorderStyle), "None"), System.ComponentModel.CategoryAttribute("Appearance"), System.ComponentModel.DescriptionAttribute("The border style used to paint the control.")]
73 | public new System.Windows.Forms.BorderStyle BorderStyle
74 | {
75 | get
76 | {
77 | return this._BorderStyle;
78 | }
79 | set
80 | {
81 | this._BorderStyle = value;
82 | if (this.DesignMode == true)
83 | {
84 | this.Invalidate();
85 | }
86 | }
87 | }
88 |
89 | [System.ComponentModel.DefaultValueAttribute(typeof(System.Drawing.Color), "WindowFrame"), System.ComponentModel.CategoryAttribute("Appearance"), System.ComponentModel.DescriptionAttribute("The border color used to paint the control.")]
90 | public System.Drawing.Color BorderColor
91 | {
92 | get
93 | {
94 | return this._BorderColour;
95 | }
96 | set
97 | {
98 | this._BorderColour = value;
99 | if (this.DesignMode == true)
100 | {
101 | this.Invalidate();
102 | }
103 | }
104 | }
105 |
106 | [System.ComponentModel.DefaultValueAttribute(typeof(int), "1"), System.ComponentModel.CategoryAttribute("Appearance"), System.ComponentModel.DescriptionAttribute("The width of the border used to paint the control.")]
107 | public int BorderWidth
108 | {
109 | get
110 | {
111 | return this._BorderWidth;
112 | }
113 | set
114 | {
115 | this._BorderWidth = value;
116 | if (this.DesignMode == true)
117 | {
118 | this.Invalidate();
119 | }
120 | }
121 | }
122 |
123 | [System.ComponentModel.DefaultValueAttribute(typeof(int), "0"), System.ComponentModel.CategoryAttribute("Appearance"), System.ComponentModel.DescriptionAttribute("The radius of the curve used to paint the corners of the control.")]
124 | public int Curvature
125 | {
126 | get
127 | {
128 | return this._Curvature;
129 | }
130 | set
131 | {
132 | this._Curvature = value;
133 | if (this.DesignMode == true)
134 | {
135 | this.Invalidate();
136 | }
137 | }
138 | }
139 |
140 | [System.ComponentModel.DefaultValueAttribute(typeof(CornerCurveMode), "All"), System.ComponentModel.CategoryAttribute("Appearance"), System.ComponentModel.DescriptionAttribute("The style of the curves to be drawn on the control.")]
141 | public CornerCurveMode CurveMode
142 | {
143 | get
144 | {
145 | return this._CurveMode;
146 | }
147 | set
148 | {
149 | this._CurveMode = value;
150 | if (this.DesignMode == true)
151 | {
152 | this.Invalidate();
153 | }
154 | }
155 | }
156 |
157 | private int adjustedCurve
158 | {
159 | get
160 | {
161 | int curve = 0;
162 | if (!(this._CurveMode == CornerCurveMode.None))
163 | {
164 | if (this._Curvature > (this.ClientRectangle.Width / 2))
165 | {
166 | curve = DoubleToInt(this.ClientRectangle.Width / 2);
167 | }
168 | else
169 | {
170 | curve = this._Curvature;
171 | }
172 | if (curve > (this.ClientRectangle.Height / 2))
173 | {
174 | curve = DoubleToInt(this.ClientRectangle.Height / 2);
175 | }
176 | }
177 | return curve;
178 | }
179 | }
180 |
181 | public CustomPanel() : base()
182 | {
183 | // pdf - to show progress on program startup
184 | //SSA.Splash.Update(String.Format("initializing {0}...", SSA.Splash.GlobalCounter++));
185 | this.SetDefaultControlStyles();
186 | this.customInitialisation();
187 | }
188 |
189 | private void SetDefaultControlStyles()
190 | {
191 | this.SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer, true);
192 |
193 | // was false
194 | this.SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true);
195 |
196 | this.SetStyle(System.Windows.Forms.ControlStyles.ResizeRedraw, true);
197 | this.SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true);
198 | this.SetStyle(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor, true);
199 | }
200 |
201 | private void customInitialisation()
202 | {
203 | this.SuspendLayout();
204 | base.BackColor = System.Drawing.Color.Transparent;
205 | this.BorderStyle = System.Windows.Forms.BorderStyle.None;
206 | this.ResumeLayout(false);
207 | }
208 |
209 | protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
210 | {
211 | base.OnPaintBackground(pevent);
212 | pevent.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
213 | System.Drawing.Drawing2D.GraphicsPath graphPath;
214 | graphPath = this.GetPath();
215 | // Create Gradient Brush (Cannot be width or height 0)
216 | System.Drawing.Drawing2D.LinearGradientBrush filler;
217 | System.Drawing.Rectangle rect = this.ClientRectangle;
218 | if (this.ClientRectangle.Width == 0)
219 | {
220 | rect.Width += 1;
221 | }
222 | if (this.ClientRectangle.Height == 0)
223 | {
224 | rect.Height += 1;
225 | }
226 | if (this._GradientMode == LinearGradientMode.None)
227 | {
228 | filler = new System.Drawing.Drawing2D.LinearGradientBrush(rect, this._BackColour1, this._BackColour1, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
229 | }
230 | else
231 | {
232 | filler = new System.Drawing.Drawing2D.LinearGradientBrush(rect, this._BackColour1, this._BackColour2, ((System.Drawing.Drawing2D.LinearGradientMode)this._GradientMode));
233 | }
234 | pevent.Graphics.FillPath(filler, graphPath);
235 | filler.Dispose();
236 | if (this._BorderStyle == System.Windows.Forms.BorderStyle.FixedSingle)
237 | {
238 | System.Drawing.Pen borderPen = new System.Drawing.Pen(this._BorderColour, this._BorderWidth);
239 | pevent.Graphics.DrawPath(borderPen, graphPath);
240 | borderPen.Dispose();
241 | }
242 | else if (this._BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D)
243 | {
244 | DrawBorder3D(pevent.Graphics, this.ClientRectangle);
245 | }
246 | else if (this._BorderStyle == System.Windows.Forms.BorderStyle.None)
247 | {
248 | }
249 | filler.Dispose();
250 | graphPath.Dispose();
251 | }
252 |
253 | protected System.Drawing.Drawing2D.GraphicsPath GetPath()
254 | {
255 | System.Drawing.Drawing2D.GraphicsPath graphPath = new System.Drawing.Drawing2D.GraphicsPath();
256 | if (this._BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D)
257 | {
258 | graphPath.AddRectangle(this.ClientRectangle);
259 | }
260 | else
261 | {
262 | try
263 | {
264 | int curve = 0;
265 | System.Drawing.Rectangle rect = this.ClientRectangle;
266 | int offset = 0;
267 | if (this._BorderStyle == System.Windows.Forms.BorderStyle.FixedSingle)
268 | {
269 | if (this._BorderWidth > 1)
270 | {
271 | offset = DoubleToInt(this.BorderWidth / 2);
272 | }
273 | curve = this.adjustedCurve;
274 | }
275 | else if (this._BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D)
276 | {
277 | }
278 | else if (this._BorderStyle == System.Windows.Forms.BorderStyle.None)
279 | {
280 | curve = this.adjustedCurve;
281 | }
282 | if (curve == 0)
283 | {
284 | graphPath.AddRectangle(System.Drawing.Rectangle.Inflate(rect, -offset, -offset));
285 | }
286 | else
287 | {
288 | int rectWidth = rect.Width - 1 - offset;
289 | int rectHeight = rect.Height - 1 - offset;
290 | int curveWidth = 1;
291 | if ((this._CurveMode & CornerCurveMode.TopRight) != 0)
292 | {
293 | curveWidth = (curve * 2);
294 | }
295 | else
296 | {
297 | curveWidth = 1;
298 | }
299 | graphPath.AddArc(rectWidth - curveWidth, offset, curveWidth, curveWidth, 270, 90);
300 | if ((this._CurveMode & CornerCurveMode.BottomRight) != 0)
301 | {
302 | curveWidth = (curve * 2);
303 | }
304 | else
305 | {
306 | curveWidth = 1;
307 | }
308 | graphPath.AddArc(rectWidth - curveWidth, rectHeight - curveWidth, curveWidth, curveWidth, 0, 90);
309 | if ((this._CurveMode & CornerCurveMode.BottomLeft) != 0)
310 | {
311 | curveWidth = (curve * 2);
312 | }
313 | else
314 | {
315 | curveWidth = 1;
316 | }
317 | graphPath.AddArc(offset, rectHeight - curveWidth, curveWidth, curveWidth, 90, 90);
318 | if ((this._CurveMode & CornerCurveMode.TopLeft) != 0)
319 | {
320 | curveWidth = (curve * 2);
321 | }
322 | else
323 | {
324 | curveWidth = 1;
325 | }
326 | graphPath.AddArc(offset, offset, curveWidth, curveWidth, 180, 90);
327 | graphPath.CloseFigure();
328 | }
329 | }
330 | catch (System.Exception)
331 | {
332 | graphPath.AddRectangle(this.ClientRectangle);
333 | }
334 | }
335 | return graphPath;
336 | }
337 |
338 | public static void DrawBorder3D(System.Drawing.Graphics graphics, System.Drawing.Rectangle rectangle)
339 | {
340 | graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
341 | graphics.DrawLine(System.Drawing.SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Y);
342 | graphics.DrawLine(System.Drawing.SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.X, rectangle.Height - 1);
343 | graphics.DrawLine(System.Drawing.SystemPens.ControlDarkDark, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 1, rectangle.Y + 1);
344 | graphics.DrawLine(System.Drawing.SystemPens.ControlDarkDark, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Height - 1);
345 | graphics.DrawLine(System.Drawing.SystemPens.ControlLight, rectangle.X + 1, rectangle.Height - 2, rectangle.Width - 2, rectangle.Height - 2);
346 | graphics.DrawLine(System.Drawing.SystemPens.ControlLight, rectangle.Width - 2, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2);
347 | graphics.DrawLine(System.Drawing.SystemPens.ControlLightLight, rectangle.X, rectangle.Height - 1, rectangle.Width - 1, rectangle.Height - 1);
348 | graphics.DrawLine(System.Drawing.SystemPens.ControlLightLight, rectangle.Width - 1, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
349 | }
350 |
351 | public static int DoubleToInt(double value)
352 | {
353 | return System.Decimal.ToInt32(System.Decimal.Floor(System.Decimal.Parse((value).ToString())));
354 | }
355 | }
356 | }
--------------------------------------------------------------------------------
/src/CNCInfusion/CustomPanel/LinearGradientMode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | namespace Utility.Panel
3 | {
4 | public enum LinearGradientMode
5 | {
6 | Horizontal = 0,
7 | Vertical = 1,
8 | ForwardDiagonal = 2,
9 | BackwardDiagonal = 3,
10 | None = 4
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Data/Mill.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Mill
4 | Milling setup file
5 | False
6 | False
7 | False
8 | /*
9 | ()
10 | M30
11 | MILL
12 | X
13 | CCW
14 | 4
15 | :$O
16 | M99
17 | 4
18 | CAD
19 | Mill
20 | 315
21 | 0
22 | 315
23 | 0
24 | 0
25 | 0
26 | G90
27 | G91
28 | G03
29 | G02
30 | R
31 | G80
32 | G81
33 | G82
34 | G83
35 | G84
36 | G85
37 | G86
38 | G87
39 | G88
40 |
41 | G01
42 | G00
43 | G98
44 | G99
45 | B
46 | G17
47 | G18
48 | G19
49 | M98
50 | L
51 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Knob/ColorMng.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Creato da SharpDevelop.
3 | * Utente: lucabonotto
4 | * Data: 03/04/2008
5 | * Ora: 14.34
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 |
10 | using System;
11 | using System.Drawing;
12 |
13 | namespace CPOL.Utils
14 | {
15 | ///
16 | /// Manager for color
17 | ///
18 | public class LBColorManager : Object
19 | {
20 | public static double BlendColour ( double fg, double bg, double alpha )
21 | {
22 | double result = bg + (alpha * (fg - bg));
23 | if (result < 0.0)
24 | result = 0.0;
25 | if (result > 255)
26 | result = 255;
27 | return result;
28 | }
29 |
30 | public static Color StepColor ( Color clr, int alpha )
31 | {
32 | if ( alpha == 100 )
33 | return clr;
34 |
35 | byte a = clr.A;
36 | byte r = clr.R;
37 | byte g = clr.G;
38 | byte b = clr.B;
39 | float bg = 0;
40 |
41 | int _alpha = Math.Min(alpha, 200);
42 | _alpha = Math.Max(alpha, 0);
43 | double ialpha = ((double)(_alpha - 100.0))/100.0;
44 |
45 | if (ialpha > 100)
46 | {
47 | // blend with white
48 | bg = 255.0F;
49 | ialpha = 1.0F - ialpha; // 0 = transparent fg; 1 = opaque fg
50 | }
51 | else
52 | {
53 | // blend with black
54 | bg = 0.0F;
55 | ialpha = 1.0F + ialpha; // 0 = transparent fg; 1 = opaque fg
56 | }
57 |
58 | r = (byte)(LBColorManager.BlendColour(r, bg, ialpha));
59 | g = (byte)(LBColorManager.BlendColour(g, bg, ialpha));
60 | b = (byte)(LBColorManager.BlendColour(b, bg, ialpha));
61 |
62 | return Color.FromArgb ( a, r, g, b );
63 | }
64 | };
65 | }
66 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Knob/Knob.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Knob/Knob.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Knob/KnobRenderer.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Creato da SharpDevelop.
3 | * Utente: lucabonotto
4 | * Data: 07/04/2008
5 | * Ora: 14.42
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 |
10 | using System;
11 | using System.Drawing;
12 | using System.Drawing.Drawing2D;
13 | using CPOL.Utils;
14 |
15 | namespace CPOL.Knobs
16 | {
17 | ///
18 | /// Base class for the renderers of the knob
19 | ///
20 | public class LBKnobRenderer
21 | {
22 | #region Variables
23 | ///
24 | /// Control to render
25 | ///
26 | private LBKnob knob = null;
27 | #endregion
28 |
29 | #region Properies
30 | public LBKnob Knob
31 | {
32 | set { this.knob = value; }
33 | get { return this.knob; }
34 | }
35 | #endregion
36 |
37 | #region Virtual method
38 | ///
39 | /// Draw the background of the control
40 | ///
41 | ///
42 | ///
43 | ///
44 | public virtual bool DrawBackground( Graphics Gr, RectangleF rc )
45 | {
46 | if ( this.Knob == null )
47 | return false;
48 |
49 | Color c = this.Knob.BackColor;
50 | SolidBrush br = new SolidBrush ( c );
51 | Pen pen = new Pen ( c );
52 |
53 | Rectangle _rcTmp = new Rectangle(0, 0, this.Knob.Width, this.Knob.Height );
54 | Gr.DrawRectangle ( pen, _rcTmp );
55 | Gr.FillRectangle ( br, rc );
56 |
57 | br.Dispose();
58 | pen.Dispose();
59 |
60 | return true;
61 | }
62 |
63 | ///
64 | /// Draw the scale of the control
65 | ///
66 | ///
67 | ///
68 | ///
69 | public virtual bool DrawScale( Graphics Gr, RectangleF rc )
70 | {
71 | if ( this.Knob == null )
72 | return false;
73 |
74 | Color cKnob = this.Knob.ScaleColor;
75 | Color cKnobDark = LBColorManager.StepColor ( cKnob, 60 );
76 |
77 | LinearGradientBrush br = new LinearGradientBrush ( rc, cKnobDark, cKnob, 45 );
78 |
79 | Gr.FillEllipse ( br, rc );
80 |
81 | br.Dispose();
82 |
83 | return true;
84 | }
85 |
86 | ///
87 | /// Draw the knob of the control
88 | ///
89 | ///
90 | ///
91 | ///
92 | public virtual bool DrawKnob( Graphics Gr, RectangleF rc )
93 | {
94 | if ( this.Knob == null )
95 | return false;
96 |
97 | Color cKnob = this.Knob.KnobColor;
98 | Color cKnobDark = LBColorManager.StepColor ( cKnob, 60 );
99 |
100 | LinearGradientBrush br = new LinearGradientBrush ( rc, cKnob, cKnobDark, 45 );
101 |
102 | Gr.FillEllipse ( br, rc );
103 |
104 | br.Dispose();
105 |
106 | return true;
107 | }
108 |
109 | public virtual bool DrawKnobIndicator( Graphics Gr, RectangleF rc, PointF pos )
110 | {
111 | if ( this.Knob == null )
112 | return false;
113 |
114 | RectangleF _rc = rc;
115 | _rc.X = pos.X - 4;
116 | _rc.Y = pos.Y - 4;
117 | _rc.Width = 8;
118 | _rc.Height = 8;
119 |
120 | Color cKnob = this.Knob.IndicatorColor;
121 | Color cKnobDark = LBColorManager.StepColor ( cKnob, 60 );
122 |
123 | LinearGradientBrush br = new LinearGradientBrush ( _rc, cKnobDark, cKnob, 45 );
124 |
125 | Gr.FillEllipse ( br, _rc );
126 |
127 | br.Dispose();
128 |
129 | return true;
130 | }
131 | #endregion
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Knob/LBKnob.Designer.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Creato da SharpDevelop.
3 | * Utente: lucabonotto
4 | * Data: 05/04/2008
5 | * Ora: 13.35
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 | namespace CPOL.Knobs
10 | {
11 | partial class LBKnob
12 | {
13 | ///
14 | /// Designer variable used to keep track of non-visual components.
15 | ///
16 | private System.ComponentModel.IContainer components = null;
17 |
18 | ///
19 | /// Disposes resources used by the control.
20 | ///
21 | /// true if managed resources should be disposed; otherwise, false.
22 | protected override void Dispose(bool disposing)
23 | {
24 | if (disposing) {
25 | if (components != null) {
26 | components.Dispose();
27 | }
28 | }
29 | base.Dispose(disposing);
30 | }
31 |
32 | ///
33 | /// This method is required for Windows Forms designer support.
34 | /// Do not change the method contents inside the source code editor. The Forms designer might
35 | /// not be able to load this method if it was changed manually.
36 | ///
37 | private void InitializeComponent()
38 | {
39 | this.SuspendLayout();
40 | //
41 | // LBKnob
42 | //
43 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
44 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
45 | this.Name = "LBKnob";
46 | this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseDown);
47 | this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OnMouseMove);
48 | this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnMouseUp);
49 | this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnKeyDown);
50 | this.ResumeLayout(false);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Knob/LBKnob.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Creato da SharpDevelop.
3 | * Utente: lucabonotto
4 | * Data: 05/04/2008
5 | * Ora: 13.35
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 |
10 |
11 | // http://69.10.233.10/KB/cs/industrial_controls.aspx
12 | // Code Project Open License
13 |
14 | using System;
15 | using System.ComponentModel;
16 | using System.Drawing;
17 | using System.Windows.Forms;
18 |
19 | namespace CPOL.Knobs
20 | {
21 | ///
22 | /// Description of LBKnob.
23 | ///
24 | public partial class LBKnob : UserControl
25 | {
26 | #region Enumerators
27 | public enum KnobStyle
28 | {
29 | Circular = 0,
30 | }
31 | #endregion
32 |
33 | #region Properties variables
34 | private float minValue = 0.0F;
35 | private float maxValue = 1.0F;
36 | private float stepValue = 0.1F;
37 | private float currValue = 0.0F;
38 | private KnobStyle style = KnobStyle.Circular;
39 | private LBKnobRenderer renderer = null;
40 | private Color scaleColor = Color.Green;
41 | private Color knobColor = Color.Black ;
42 | private Color indicatorColor = Color.Red;
43 | private float indicatorOffset = 10F;
44 | #endregion
45 |
46 | #region Class variables
47 | private RectangleF drawRect;
48 | private RectangleF rectScale;
49 | private RectangleF rectKnob;
50 | private float drawRatio;
51 | private LBKnobRenderer defaultRenderer = null;
52 | private bool isKnobRotating = false;
53 | private PointF knobCenter;
54 | private PointF knobIndicatorPos;
55 | #endregion
56 |
57 | #region Constructor
58 | public LBKnob()
59 | {
60 | InitializeComponent();
61 |
62 | // Set the styles for drawing
63 | SetStyle(ControlStyles.AllPaintingInWmPaint |
64 | ControlStyles.ResizeRedraw |
65 | ControlStyles.DoubleBuffer |
66 | ControlStyles.SupportsTransparentBackColor,
67 | true);
68 |
69 | // Transparent background
70 | this.BackColor = Color.Transparent;
71 |
72 | this.defaultRenderer = new LBKnobRenderer();
73 | this.defaultRenderer.Knob = this;
74 |
75 | this.CalculateDimensions();
76 | }
77 | #endregion
78 |
79 | #region Properties
80 | [
81 | Category("Knob"),
82 | Description("Minimum value of the knob")
83 | ]
84 | public float MinValue
85 | {
86 | set
87 | {
88 | this.minValue = value;
89 | this.Invalidate();
90 | }
91 | get { return this.minValue; }
92 | }
93 |
94 | [
95 | Category("Knob"),
96 | Description("Maximum value of the knob")
97 | ]
98 | public float MaxValue
99 | {
100 | set
101 | {
102 | this.maxValue = value;
103 | this.Invalidate();
104 | }
105 | get { return this.maxValue; }
106 | }
107 |
108 | [
109 | Category("Knob"),
110 | Description("Step value of the knob")
111 | ]
112 | public float StepValue
113 | {
114 | set
115 | {
116 | this.stepValue = value;
117 | this.Invalidate();
118 | }
119 | get { return this.stepValue; }
120 | }
121 |
122 | [
123 | Category("Knob"),
124 | Description("Current value of the knob")
125 | ]
126 | public float Value
127 | {
128 | set
129 | {
130 | if ( value != this.currValue )
131 | {
132 | this.currValue = value;
133 | this.knobIndicatorPos = this.GetPositionFromValue ( this.currValue );
134 | this.Invalidate();
135 |
136 | LBKnobEventArgs e = new LBKnobEventArgs();
137 | e.Value = this.currValue;
138 | this.OnKnobChangeValue( e );
139 | }
140 | }
141 | get { return this.currValue; }
142 | }
143 |
144 | [
145 | Category("Knob"),
146 | Description("Style of the knob")
147 | ]
148 | public KnobStyle Style
149 | {
150 | set
151 | {
152 | this.style = value;
153 | this.Invalidate();
154 | }
155 | get { return this.style; }
156 | }
157 |
158 | [
159 | Category("Knob"),
160 | Description("Color of the knob")
161 | ]
162 | public Color KnobColor
163 | {
164 | set
165 | {
166 | this.knobColor = value;
167 | this.Invalidate();
168 | }
169 | get { return this.knobColor; }
170 | }
171 |
172 | [
173 | Category("Knob"),
174 | Description("Color of the scale")
175 | ]
176 | public Color ScaleColor
177 | {
178 | set
179 | {
180 | this.scaleColor = value;
181 | this.Invalidate();
182 | }
183 | get { return this.scaleColor; }
184 | }
185 |
186 | [
187 | Category("Knob"),
188 | Description("Color of the indicator")
189 | ]
190 | public Color IndicatorColor
191 | {
192 | set
193 | {
194 | this.indicatorColor = value;
195 | this.Invalidate();
196 | }
197 | get { return this.indicatorColor; }
198 | }
199 |
200 | [
201 | Category("Knob"),
202 | Description("Offset of the indicator from the kob border")
203 | ]
204 | public float IndicatorOffset
205 | {
206 | set
207 | {
208 | this.indicatorOffset = value;
209 | this.CalculateDimensions();
210 | this.Invalidate();
211 | }
212 | get { return this.indicatorOffset; }
213 | }
214 |
215 | [Browsable(false)]
216 | public LBKnobRenderer Renderer
217 | {
218 | get { return this.renderer; }
219 | set
220 | {
221 | this.renderer = value;
222 | if ( this.renderer != null )
223 | renderer.Knob = this;
224 | Invalidate();
225 | }
226 | }
227 |
228 | [Browsable(false)]
229 | public PointF KnobCenter
230 | {
231 | get { return this.knobCenter; }
232 | }
233 | #endregion
234 |
235 | #region Events delegates
236 |
237 | protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
238 | {
239 | bool blResult = true;
240 |
241 | ///
242 | /// Specified WM_KEYDOWN enumeration value.
243 | ///
244 | const int WM_KEYDOWN = 0x0100;
245 |
246 | ///
247 | /// Specified WM_SYSKEYDOWN enumeration value.
248 | ///
249 | const int WM_SYSKEYDOWN = 0x0104;
250 |
251 | float val = this.Value;
252 |
253 | if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
254 | {
255 | switch(keyData)
256 | {
257 | case Keys.Up:
258 | val += this.StepValue;
259 | if ( val <= this.MaxValue )
260 | this.Value = val;
261 | break;
262 |
263 | case Keys.Down:
264 | val -= this.StepValue;
265 | if ( val >= this.MinValue )
266 | this.Value = val;
267 | break;
268 |
269 | case Keys.PageUp:
270 | if ( val < this.MaxValue )
271 | {
272 | val += ( this.StepValue * 10 );
273 | this.Value = val;
274 | }
275 | break;
276 |
277 | case Keys.PageDown:
278 | if ( val > this.MinValue )
279 | {
280 | val -= ( this.StepValue * 10 );
281 | this.Value = val;
282 | }
283 | break;
284 |
285 | case Keys.Home:
286 | this.Value = this.MinValue;
287 | break;
288 |
289 | case Keys.End:
290 | this.Value = this.MaxValue;
291 | break;
292 |
293 | default:
294 | blResult = base.ProcessCmdKey(ref msg,keyData);
295 | break;
296 | }
297 | }
298 |
299 | return blResult;
300 | }
301 |
302 | [System.ComponentModel.EditorBrowsableAttribute()]
303 | protected override void OnClick(EventArgs e)
304 | {
305 | this.Focus();
306 | this.Invalidate();
307 | base.OnClick(e);
308 | }
309 |
310 | void OnMouseUp(object sender, MouseEventArgs e)
311 | {
312 | this.isKnobRotating = false;
313 |
314 | if ( this.rectKnob.Contains ( e.Location ) == false )
315 | return;
316 |
317 | float val = this.GetValueFromPosition ( e.Location );
318 | if ( val != this.Value )
319 | {
320 | this.Value = val;
321 | this.Invalidate();
322 | }
323 | }
324 |
325 | void OnMouseDown(object sender, MouseEventArgs e)
326 | {
327 | if ( this.rectKnob.Contains ( e.Location ) == false )
328 | return;
329 |
330 | this.isKnobRotating = true;
331 |
332 | this.Focus();
333 | }
334 |
335 | void OnMouseMove(object sender, MouseEventArgs e)
336 | {
337 | if ( this.isKnobRotating == false )
338 | return;
339 |
340 | float val = this.GetValueFromPosition ( e.Location );
341 | if ( val != this.Value )
342 | {
343 | this.Value = val;
344 | this.Invalidate ();
345 | }
346 | }
347 |
348 | // pdf - added mouse handler
349 | protected override void OnMouseWheel(MouseEventArgs e)
350 | {
351 | int delta = e.Delta;
352 | float val = this.Value;
353 |
354 | if (delta > 0)
355 | {
356 | val += this.StepValue;
357 | if (val <= this.MaxValue)
358 | this.Value++;
359 | }
360 | else
361 | {
362 | val -= this.StepValue;
363 | if (val >= this.MinValue)
364 | this.Value--;
365 | }
366 | }
367 |
368 | void OnKeyDown(object sender, KeyEventArgs e)
369 | {
370 | float val = this.Value;
371 |
372 | switch ( e.KeyCode )
373 | {
374 | case Keys.Up:
375 | val = this.Value + this.StepValue;
376 | break;
377 |
378 | case Keys.Down:
379 | val = this.Value - this.StepValue;
380 | break;
381 | }
382 |
383 | if ( val < this.MinValue )
384 | val = this.MinValue;
385 |
386 | if ( val > this.MaxValue )
387 | val = this.MaxValue;
388 |
389 | this.Value = val;
390 | }
391 |
392 |
393 | [System.ComponentModel.EditorBrowsableAttribute()]
394 | protected override void OnSizeChanged(EventArgs e)
395 | {
396 | base.OnSizeChanged(e);
397 |
398 | this.CalculateDimensions();
399 |
400 | this.Invalidate();
401 | }
402 |
403 | [System.ComponentModel.EditorBrowsableAttribute()]
404 | protected override void OnPaint(PaintEventArgs e)
405 | {
406 | RectangleF _rc = new RectangleF(0, 0, this.Width, this.Height );
407 | e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
408 |
409 | if ( this.Renderer == null )
410 | {
411 | this.defaultRenderer.DrawBackground( e.Graphics, _rc );
412 | this.defaultRenderer.DrawScale( e.Graphics, this.rectScale );
413 | this.defaultRenderer.DrawKnob( e.Graphics, this.rectKnob );
414 | this.defaultRenderer.DrawKnobIndicator( e.Graphics, this.rectKnob, this.knobIndicatorPos );
415 | return;
416 | }
417 |
418 | this.Renderer.DrawBackground( e.Graphics, _rc );
419 | this.Renderer.DrawScale( e.Graphics, this.rectScale );
420 | this.Renderer.DrawKnob( e.Graphics, this.rectKnob );
421 | this.Renderer.DrawKnobIndicator( e.Graphics, this.rectKnob, this.knobIndicatorPos );
422 | }
423 | #endregion
424 |
425 | #region Virtual functions
426 | protected virtual void CalculateDimensions()
427 | {
428 | // Rectangle
429 | float x, y, w, h;
430 | x = 0;
431 | y = 0;
432 | w = this.Size.Width;
433 | h = this.Size.Height;
434 |
435 | // Calculate ratio
436 | drawRatio = (Math.Min(w,h)) / 200;
437 | if ( drawRatio == 0.0 )
438 | drawRatio = 1;
439 |
440 | // Draw rectangle
441 | drawRect.X = x;
442 | drawRect.Y = y;
443 | drawRect.Width = w - 2;
444 | drawRect.Height = h - 2;
445 |
446 | if ( w < h )
447 | drawRect.Height = w;
448 | else if ( w > h )
449 | drawRect.Width = h;
450 |
451 | if ( drawRect.Width < 10 )
452 | drawRect.Width = 10;
453 | if ( drawRect.Height < 10 )
454 | drawRect.Height = 10;
455 |
456 | this.rectScale = this.drawRect;
457 | this.rectKnob = this.drawRect;
458 | this.rectKnob.Inflate ( -20 * this.drawRatio, -20 * this.drawRatio );
459 |
460 | this.knobCenter.X = this.rectKnob.Left + ( this.rectKnob.Width * 0.5F );
461 | this.knobCenter.Y = this.rectKnob.Top + ( this.rectKnob.Height * 0.5F );
462 |
463 | this.knobIndicatorPos = this.GetPositionFromValue ( this.Value );
464 | }
465 |
466 | public virtual float GetValueFromPosition ( PointF position )
467 | {
468 | float degree = 0.0F;
469 | float v = 0.0F;
470 |
471 | PointF center = this.KnobCenter;
472 |
473 | if ( position.X <= center.X )
474 | {
475 | degree = (center.Y - position.Y ) / (center.X - position.X );
476 | degree = (float)Math.Atan(degree);
477 | degree = (float)(180F + (degree) * (180F / Math.PI) + 0F);
478 | v = (degree * ( this.MaxValue - this.MinValue )/ 180F);
479 | }
480 | else
481 | {
482 | if ( position.X > center.X )
483 | {
484 | degree = (position.Y - center.Y ) / (position.X - center.X );
485 | degree = (float)Math.Atan(degree);
486 | degree = (float)( (degree) * (180F / Math.PI));
487 | v = (degree * ( this.MaxValue - this.MinValue ) / 180F);
488 | }
489 | }
490 |
491 | if ( v > this.MaxValue )
492 | v = this.MaxValue;
493 |
494 | if (v < this.MinValue )
495 | v = this.MinValue;
496 |
497 | return v;
498 | }
499 |
500 | public virtual PointF GetPositionFromValue ( float val )
501 | {
502 | PointF pos = new PointF( 0.0F, 0.0F );
503 |
504 | // Elimina la divisione per 0
505 | if ( ( this.MaxValue - this.MinValue ) == 0 )
506 | return pos;
507 |
508 | float _indicatorOffset = this.IndicatorOffset * this.drawRatio;
509 |
510 | float degree = 360F * val / ( this.MaxValue - this.MinValue );
511 | degree = (degree - 90) * (float)Math.PI / 180F;
512 |
513 | pos.X = (int)(Math.Cos(degree) * ((this.rectKnob.Width * 0.5F)- indicatorOffset ) + this.rectKnob.X + ( this.rectKnob.Width * 0.5F));
514 | pos.Y = (int)(Math.Sin(degree) * ((this.rectKnob.Width * 0.5F)- indicatorOffset ) + this.rectKnob.Y + ( this.rectKnob.Height * 0.5F));
515 |
516 | return pos;
517 | }
518 |
519 | #endregion
520 |
521 | #region Fire events
522 | public event KnobChangeValue KnobChangeValue;
523 | protected virtual void OnKnobChangeValue( LBKnobEventArgs e )
524 | {
525 | if( this.KnobChangeValue != null )
526 | this.KnobChangeValue( this, e );
527 | }
528 | #endregion
529 | }
530 |
531 | #region Classes for event and event delagates args
532 |
533 | #region Event args class
534 | ///
535 | /// Class for events delegates
536 | ///
537 | public class LBKnobEventArgs : EventArgs
538 | {
539 | private float val;
540 |
541 | public LBKnobEventArgs()
542 | {
543 | }
544 |
545 | public float Value
546 | {
547 | get { return this.val; }
548 | set { this.val = value; }
549 | }
550 | }
551 | #endregion
552 |
553 | #region Delegates
554 | public delegate void KnobChangeValue ( object sender, LBKnobEventArgs e );
555 | #endregion
556 |
557 | #endregion
558 | }
559 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Knob/LBKnob.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Knob/MathFunc.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Creato da SharpDevelop.
3 | * Utente: lucabonotto
4 | * Data: 03/04/2008
5 | * Ora: 15.01
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 |
10 | using System;
11 |
12 | namespace CPOL.Utils
13 | {
14 | ///
15 | /// Mathematic Functions
16 | ///
17 | public class LBMath : Object
18 | {
19 | public static float GetRadian ( float val )
20 | {
21 | return (float)(val * Math.PI / 180);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | namespace CNCInfusion
6 | {
7 | static class Program
8 | {
9 | ///
10 | /// The main entry point for the application.
11 | ///
12 | [STAThread]
13 | static void Main()
14 | {
15 | Application.EnableVisualStyles();
16 | Application.SetCompatibleTextRenderingDefault(false);
17 | Application.Run( new frmViewer());
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("CNCInfusion")]
9 | [assembly: AssemblyDescription("Paul D. Fincato, etal")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("NM156")]
12 | [assembly: AssemblyProduct("")]
13 | [assembly: AssemblyCopyright("")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("ad033ddf-3b16-47bd-a9fa-043ad2f29bc3")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("0.1.7.0")]
36 | [assembly: AssemblyFileVersion("0.1.7.0")]
37 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.239
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CNCInfusion.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CNCInfusion.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | internal static System.Drawing.Bitmap _Select {
64 | get {
65 | object obj = ResourceManager.GetObject("_Select", resourceCulture);
66 | return ((System.Drawing.Bitmap)(obj));
67 | }
68 | }
69 |
70 | internal static System.Drawing.Bitmap brick {
71 | get {
72 | object obj = ResourceManager.GetObject("brick", resourceCulture);
73 | return ((System.Drawing.Bitmap)(obj));
74 | }
75 | }
76 |
77 | internal static System.Drawing.Bitmap bullet_blue {
78 | get {
79 | object obj = ResourceManager.GetObject("bullet_blue", resourceCulture);
80 | return ((System.Drawing.Bitmap)(obj));
81 | }
82 | }
83 |
84 | internal static System.Drawing.Bitmap bullet_toggle_plus {
85 | get {
86 | object obj = ResourceManager.GetObject("bullet_toggle_plus", resourceCulture);
87 | return ((System.Drawing.Bitmap)(obj));
88 | }
89 | }
90 |
91 | internal static System.Drawing.Bitmap chart_curve_edit {
92 | get {
93 | object obj = ResourceManager.GetObject("chart_curve_edit", resourceCulture);
94 | return ((System.Drawing.Bitmap)(obj));
95 | }
96 | }
97 |
98 | internal static System.Drawing.Bitmap chart_line_edit {
99 | get {
100 | object obj = ResourceManager.GetObject("chart_line_edit", resourceCulture);
101 | return ((System.Drawing.Bitmap)(obj));
102 | }
103 | }
104 |
105 | internal static System.Drawing.Bitmap cog {
106 | get {
107 | object obj = ResourceManager.GetObject("cog", resourceCulture);
108 | return ((System.Drawing.Bitmap)(obj));
109 | }
110 | }
111 |
112 | internal static System.Drawing.Bitmap eye {
113 | get {
114 | object obj = ResourceManager.GetObject("eye", resourceCulture);
115 | return ((System.Drawing.Bitmap)(obj));
116 | }
117 | }
118 |
119 | internal static System.Drawing.Bitmap information {
120 | get {
121 | object obj = ResourceManager.GetObject("information", resourceCulture);
122 | return ((System.Drawing.Bitmap)(obj));
123 | }
124 | }
125 |
126 | internal static System.Drawing.Bitmap shape_align_center {
127 | get {
128 | object obj = ResourceManager.GetObject("shape_align_center", resourceCulture);
129 | return ((System.Drawing.Bitmap)(obj));
130 | }
131 | }
132 |
133 | internal static System.Drawing.Bitmap shape_align_left {
134 | get {
135 | object obj = ResourceManager.GetObject("shape_align_left", resourceCulture);
136 | return ((System.Drawing.Bitmap)(obj));
137 | }
138 | }
139 |
140 | internal static System.Drawing.Bitmap shape_align_middle {
141 | get {
142 | object obj = ResourceManager.GetObject("shape_align_middle", resourceCulture);
143 | return ((System.Drawing.Bitmap)(obj));
144 | }
145 | }
146 |
147 | internal static System.Drawing.Bitmap shape_flip_vertical {
148 | get {
149 | object obj = ResourceManager.GetObject("shape_flip_vertical", resourceCulture);
150 | return ((System.Drawing.Bitmap)(obj));
151 | }
152 | }
153 |
154 | internal static System.Drawing.Bitmap ViewFence {
155 | get {
156 | object obj = ResourceManager.GetObject("ViewFence", resourceCulture);
157 | return ((System.Drawing.Bitmap)(obj));
158 | }
159 | }
160 |
161 | internal static System.Drawing.Bitmap ViewFit {
162 | get {
163 | object obj = ResourceManager.GetObject("ViewFit", resourceCulture);
164 | return ((System.Drawing.Bitmap)(obj));
165 | }
166 | }
167 |
168 | internal static System.Drawing.Bitmap ViewFront {
169 | get {
170 | object obj = ResourceManager.GetObject("ViewFront", resourceCulture);
171 | return ((System.Drawing.Bitmap)(obj));
172 | }
173 | }
174 |
175 | internal static System.Drawing.Bitmap ViewIso {
176 | get {
177 | object obj = ResourceManager.GetObject("ViewIso", resourceCulture);
178 | return ((System.Drawing.Bitmap)(obj));
179 | }
180 | }
181 |
182 | internal static System.Drawing.Bitmap ViewPan {
183 | get {
184 | object obj = ResourceManager.GetObject("ViewPan", resourceCulture);
185 | return ((System.Drawing.Bitmap)(obj));
186 | }
187 | }
188 |
189 | internal static System.Drawing.Bitmap ViewRight {
190 | get {
191 | object obj = ResourceManager.GetObject("ViewRight", resourceCulture);
192 | return ((System.Drawing.Bitmap)(obj));
193 | }
194 | }
195 |
196 | internal static System.Drawing.Bitmap ViewRotate {
197 | get {
198 | object obj = ResourceManager.GetObject("ViewRotate", resourceCulture);
199 | return ((System.Drawing.Bitmap)(obj));
200 | }
201 | }
202 |
203 | internal static System.Drawing.Bitmap ViewTop {
204 | get {
205 | object obj = ResourceManager.GetObject("ViewTop", resourceCulture);
206 | return ((System.Drawing.Bitmap)(obj));
207 | }
208 | }
209 |
210 | internal static System.Drawing.Bitmap ViewZoom {
211 | get {
212 | object obj = ResourceManager.GetObject("ViewZoom", resourceCulture);
213 | return ((System.Drawing.Bitmap)(obj));
214 | }
215 | }
216 |
217 | internal static System.Drawing.Bitmap wrench_orange {
218 | get {
219 | object obj = ResourceManager.GetObject("wrench_orange", resourceCulture);
220 | return ((System.Drawing.Bitmap)(obj));
221 | }
222 | }
223 | }
224 | }
225 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.239
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CNCInfusion.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 |
26 | [global::System.Configuration.UserScopedSettingAttribute()]
27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
28 | [global::System.Configuration.DefaultSettingValueAttribute("0, 0")]
29 | public global::System.Drawing.Point ViewFormLocation {
30 | get {
31 | return ((global::System.Drawing.Point)(this["ViewFormLocation"]));
32 | }
33 | set {
34 | this["ViewFormLocation"] = value;
35 | }
36 | }
37 |
38 | [global::System.Configuration.UserScopedSettingAttribute()]
39 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
40 | [global::System.Configuration.DefaultSettingValueAttribute("True")]
41 | public bool RapidLines {
42 | get {
43 | return ((bool)(this["RapidLines"]));
44 | }
45 | set {
46 | this["RapidLines"] = value;
47 | }
48 | }
49 |
50 | [global::System.Configuration.UserScopedSettingAttribute()]
51 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
52 | [global::System.Configuration.DefaultSettingValueAttribute("True")]
53 | public bool RapidPoints {
54 | get {
55 | return ((bool)(this["RapidPoints"]));
56 | }
57 | set {
58 | this["RapidPoints"] = value;
59 | }
60 | }
61 |
62 | [global::System.Configuration.UserScopedSettingAttribute()]
63 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
64 | [global::System.Configuration.DefaultSettingValueAttribute("True")]
65 | public bool AxisLines {
66 | get {
67 | return ((bool)(this["AxisLines"]));
68 | }
69 | set {
70 | this["AxisLines"] = value;
71 | }
72 | }
73 |
74 | [global::System.Configuration.UserScopedSettingAttribute()]
75 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
76 | [global::System.Configuration.DefaultSettingValueAttribute("True")]
77 | public bool AxisIndicator {
78 | get {
79 | return ((bool)(this["AxisIndicator"]));
80 | }
81 | set {
82 | this["AxisIndicator"] = value;
83 | }
84 | }
85 |
86 | [global::System.Configuration.UserScopedSettingAttribute()]
87 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
88 | [global::System.Configuration.DefaultSettingValueAttribute("Mill")]
89 | public string LastMachine {
90 | get {
91 | return ((string)(this["LastMachine"]));
92 | }
93 | set {
94 | this["LastMachine"] = value;
95 | }
96 | }
97 |
98 | [global::System.Configuration.UserScopedSettingAttribute()]
99 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
100 | [global::System.Configuration.DefaultSettingValueAttribute("0, 0")]
101 | public global::System.Drawing.Point SetupFormLocation {
102 | get {
103 | return ((global::System.Drawing.Point)(this["SetupFormLocation"]));
104 | }
105 | set {
106 | this["SetupFormLocation"] = value;
107 | }
108 | }
109 |
110 | [global::System.Configuration.UserScopedSettingAttribute()]
111 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
112 | [global::System.Configuration.DefaultSettingValueAttribute("425, 475")]
113 | public global::System.Drawing.Size ViewFormSize {
114 | get {
115 | return ((global::System.Drawing.Size)(this["ViewFormSize"]));
116 | }
117 | set {
118 | this["ViewFormSize"] = value;
119 | }
120 | }
121 |
122 | [global::System.Configuration.UserScopedSettingAttribute()]
123 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
124 | [global::System.Configuration.DefaultSettingValueAttribute("True")]
125 | public bool Virgin {
126 | get {
127 | return ((bool)(this["Virgin"]));
128 | }
129 | set {
130 | this["Virgin"] = value;
131 | }
132 | }
133 |
134 | [global::System.Configuration.UserScopedSettingAttribute()]
135 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
136 | [global::System.Configuration.DefaultSettingValueAttribute("True")]
137 | public bool GrblPreprocesor {
138 | get {
139 | return ((bool)(this["GrblPreprocesor"]));
140 | }
141 | set {
142 | this["GrblPreprocesor"] = value;
143 | }
144 | }
145 |
146 | [global::System.Configuration.UserScopedSettingAttribute()]
147 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
148 | [global::System.Configuration.DefaultSettingValueAttribute("False")]
149 | public bool StatusUpdates {
150 | get {
151 | return ((bool)(this["StatusUpdates"]));
152 | }
153 | set {
154 | this["StatusUpdates"] = value;
155 | }
156 | }
157 |
158 | [global::System.Configuration.UserScopedSettingAttribute()]
159 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
160 | [global::System.Configuration.DefaultSettingValueAttribute("200")]
161 | public int UpdateInterval {
162 | get {
163 | return ((int)(this["UpdateInterval"]));
164 | }
165 | set {
166 | this["UpdateInterval"] = value;
167 | }
168 | }
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 0, 0
7 |
8 |
9 | True
10 |
11 |
12 | True
13 |
14 |
15 | True
16 |
17 |
18 | True
19 |
20 |
21 | Mill
22 |
23 |
24 | 0, 0
25 |
26 |
27 | 425, 475
28 |
29 |
30 | True
31 |
32 |
33 | True
34 |
35 |
36 | False
37 |
38 |
39 | 200
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/Color.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/Color.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/DisplayOpts.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/DisplayOpts.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/EditInformation.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/EditInformation.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/OpenFolder.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/OpenFolder.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/Refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/Refresh.png
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/Select.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/Select.png
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/ToolLayers.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/ToolLayers.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/ViewFence.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/ViewFence.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/ViewFit.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/ViewFit.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/ViewFront.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/ViewFront.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/ViewIso.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/ViewIso.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/ViewRight.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/ViewRight.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/ViewTop.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/ViewTop.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/screens1.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/screens1.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/screens2.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/screens2.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/screens4.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/screens4.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/viewpan.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/viewpan.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/viewrotate.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/viewrotate.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/viewzoom.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/viewzoom.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Resources/web.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/Resources/web.bmp
--------------------------------------------------------------------------------
/src/CNCInfusion/Settings.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by SharpDevelop.
3 | * User: pdf
4 | * Date: 2/14/2012
5 | * Time: 9:17 AM
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 | using System;
10 | using System.Drawing;
11 | using System.Windows.Forms;
12 | using System.Collections.Generic;
13 |
14 | namespace CNCInfusion
15 | {
16 | ///
17 | /// Description of Settings.
18 | ///
19 | public partial class Settings : Form
20 | {
21 | // reference to parent caller form
22 | public Form caller;
23 | private bool modified;
24 | private JoystickInterface.Joystick jst;
25 | private string[] sticks;
26 |
27 | public Settings()
28 | {
29 | InitializeComponent();
30 | modified = false;
31 | }
32 |
33 | // minimize flicker of stupid tab control
34 | protected override CreateParams CreateParams
35 | {
36 | get {
37 | CreateParams cp = base.CreateParams;
38 | cp.ExStyle |= 0x02000000;
39 | return cp;
40 | }
41 | }
42 |
43 | public void setUpdateMode(bool enabled)
44 | {
45 | rbStatusUpdate.Checked = enabled;
46 | }
47 |
48 | public void setGrblMode(bool enabled)
49 | {
50 | rbGrblOnly.Checked = enabled;
51 | rbAny.Checked = !enabled;
52 | }
53 |
54 | public void setInchUnits(bool enabled)
55 | {
56 | rbImperial.Checked = enabled;
57 | rbMetric.Checked = !enabled;
58 | }
59 |
60 | public void setUpdateInterval(int interval)
61 | {
62 | trackbarUpdateInterval.Value = interval;
63 | int timerInterval = 1000/trackbarUpdateInterval.Value;
64 | lblUpdate.Text = timerInterval + " updates / second";
65 | }
66 |
67 | void BtnReadSettingsClick(object sender, EventArgs e)
68 | {
69 | List RawSettings;
70 | string [] temp;
71 | string [] paramtext;
72 | string dollar;
73 | string description;
74 | string readvalue;
75 | string conversion;
76 | char[] charsToTrim = {'\r', '\n', ')'};
77 |
78 | dataGridView1.Rows.Clear();
79 | modified = false;
80 |
81 | // TODO I still can't figure all of the delegate stuff
82 | // between forms, so just do it the old fashioned "C" way...
83 | RawSettings = ((frmViewer)caller).GetSettings();
84 | dataGridView1.Columns[2].DefaultCellStyle.BackColor = System.Drawing.Color.PaleGreen;
85 |
86 | foreach(string val in RawSettings)
87 | {
88 | if(val.StartsWith("$")) {
89 | temp = val.Split('=');
90 | // Settings: $0 = 755.906 (steps/mm x)
91 | // temp[0] : $0
92 | // temp[1] : 755.906 (steps/mm x)
93 | paramtext = temp[1].Split('(');
94 | // paramtext[0] : 755.906
95 | // paramtext[1] : steps/mm x)
96 |
97 | dollar = temp[0].Trim();
98 | description = paramtext[1].TrimEnd(charsToTrim);
99 | readvalue = paramtext[0].Trim();
100 |
101 | conversion = convertUnits(readvalue, val);
102 | dataGridView1.Rows.Add(new object[]{dollar, description, readvalue, conversion});
103 | Application.DoEvents();
104 | }
105 | }
106 | btnSetSettings.Enabled = true;
107 | }
108 |
109 | string convertUnits(string readvalue, string setting)
110 | {
111 | double TOINCHES = 0.0393700787;
112 | string convert;
113 |
114 | try {
115 | if(setting.Contains("steps/mm")) {
116 | double fval = double.Parse(readvalue)*(1.0/TOINCHES);
117 | convert = fval.ToString();
118 | }
119 | else if(setting.Contains("mm")) {
120 | double fval = double.Parse(readvalue)*TOINCHES;
121 | convert = fval.ToString();
122 | }
123 | else if(setting.Contains("binary")) {
124 | int fval = int.Parse(readvalue);
125 | convert = GetIntBinaryString(fval);
126 | }
127 | else {
128 | convert = readvalue;
129 | }
130 | }
131 | catch (Exception ex)
132 | {
133 | convert = string.Empty;
134 | MessageBox.Show(ex.Message);
135 | }
136 |
137 | return convert;
138 | }
139 |
140 | void BtnSetSettingsClick(object sender, EventArgs e)
141 | {
142 | List WriteSettings = new List();
143 | string parameter;
144 | string setValue;
145 | string command;
146 |
147 | WriteSettings.Clear();
148 |
149 | foreach (DataGridViewRow dgval in dataGridView1.Rows)
150 | {
151 | parameter = dgval.Cells[0].Value.ToString().Trim();
152 | setValue = dgval.Cells[2].Value.ToString().Trim();
153 | command = parameter + "=" + setValue + "\n";
154 | // TODO only update changed settings
155 | WriteSettings.Add(command);
156 | }
157 |
158 | ((frmViewer)caller).WriteSettings(WriteSettings);
159 | MessageBox.Show("Settings have been successfully written",
160 | "Write Settings",
161 | MessageBoxButtons.OK,
162 | MessageBoxIcon.Information,
163 | MessageBoxDefaultButton.Button1,
164 | MessageBoxOptions.DefaultDesktopOnly);
165 | }
166 |
167 | void DataGridView1CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
168 | {
169 | float enteredValue;
170 |
171 | // Don't try to validate the 'new row' until finished
172 | // editing since there is no point in validating its initial value.
173 | if (dataGridView1.Rows[e.RowIndex].IsNewRow) { return; }
174 |
175 | // only continue if it is the editable column
176 | if (!dataGridView1.Columns[e.ColumnIndex].HeaderText.Equals("Value")) return;
177 |
178 | //if (sVal.Contains("."))
179 | // float.Parse(sVal);
180 | //else
181 | // int.Parse(sVal);
182 |
183 | // TODO error checking is weak
184 | try {
185 | enteredValue = float.Parse(e.FormattedValue.ToString());
186 | }
187 | catch {
188 | MessageBox.Show("The value must be a non-negative number. You entered '" +
189 | e.FormattedValue.ToString() + "' for parameter " + dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex-1].Value,
190 | "Invalid Settings Parameter",
191 | MessageBoxButtons.OK,
192 | MessageBoxIcon.Error,
193 | MessageBoxDefaultButton.Button1,
194 | MessageBoxOptions.DefaultDesktopOnly);
195 | e.Cancel = true;
196 | return;
197 | }
198 |
199 | e.Cancel = false;
200 | }
201 |
202 | // http://www.dotnetperls.com/binary-representation
203 | string GetIntBinaryString(int n)
204 | {
205 | char[] b = new char[8];
206 | int pos = 7;
207 | int i = 0;
208 |
209 | while (i < 8) {
210 | if ((n & (1 << i)) != 0)
211 | b[pos] = '1';
212 | else
213 | b[pos] = '0';
214 | pos--;
215 | i++;
216 | }
217 | return new string(b);
218 | }
219 |
220 | void TrackbarUpdateIntervalScroll(object sender, EventArgs e)
221 | {
222 | int timerInterval = 1000/trackbarUpdateInterval.Value;
223 | lblUpdate.Text = timerInterval + " updates / second";
224 | ((frmViewer)caller).UpdateInterval = trackbarUpdateInterval.Value;
225 | }
226 |
227 | void RbStatusUpdateClick(object sender, EventArgs e)
228 | {
229 | rbStatusUpdate.Checked = !rbStatusUpdate.Checked;
230 | ((frmViewer)caller).PerformStatusUpdates = rbStatusUpdate.Checked;
231 | }
232 |
233 | void SettingsShown(object sender, EventArgs e)
234 | {
235 | // what mode are we in?
236 | eMode mainMode = ((frmViewer)caller).currentMode;
237 |
238 | // only these modes allowed to change settings
239 | // otherwise Grbl is processing
240 | if( mainMode == eMode.CONNECTED || mainMode == eMode.ABORTED ||
241 | mainMode == eMode.FINISHED || mainMode == eMode.SOFTRESET) {
242 | pnlSettings.Enabled = true;
243 | dataGridView1.Enabled = true;
244 | pnlReset.Enabled = true;
245 | }
246 | else {
247 | pnlSettings.Enabled = false;
248 | dataGridView1.Enabled = false;
249 | pnlReset.Enabled = false;
250 | }
251 |
252 | colorComboBox1.SelectedColor = tabPage3.BackColor;
253 | }
254 |
255 | void BtnResetClick(object sender, EventArgs e)
256 | {
257 | ((frmViewer)caller).hardReset();
258 | }
259 |
260 | void BtnJoystickRefreshClick(object sender, EventArgs e)
261 | {
262 | getJoysticks();
263 | }
264 |
265 | void RbGrblOnlyCheckedChanged(object sender, EventArgs e)
266 | {
267 | ((frmViewer)caller).PreprocessorMode = rbGrblOnly.Checked;
268 | }
269 |
270 | void DataGridView1CellValueChanged(object sender, DataGridViewCellEventArgs e)
271 | {
272 | if(dataGridView1.SelectedRows.Count > 0) {
273 | modified = true;
274 | int row = dataGridView1.SelectedRows[0].Index;
275 |
276 | dataGridView1.Rows[row].Cells[3].Value =
277 | convertUnits(dataGridView1.Rows[row].Cells[2].Value.ToString(),
278 | dataGridView1.Rows[row].Cells[1].Value.ToString());
279 |
280 | dataGridView1.Rows[row].Cells[2].Style.BackColor = System.Drawing.Color.LightGoldenrodYellow;
281 | }
282 | }
283 |
284 | void SettingsFormClosing(object sender, FormClosingEventArgs e)
285 | {
286 | if(modified) {
287 | DialogResult res = MessageBox.Show("There are unsaved changes. Do you still want to close settings?",
288 | "Notice",
289 | MessageBoxButtons.YesNo,
290 | MessageBoxIcon.Information,
291 | MessageBoxDefaultButton.Button2,
292 | MessageBoxOptions.DefaultDesktopOnly);
293 | if(res == DialogResult.No) {
294 | e.Cancel = true;
295 | }
296 | }
297 | }
298 |
299 | void RbImperialCheckedChanged(object sender, EventArgs e)
300 | {
301 | ((frmViewer)caller).GrblReportMode = rbImperial.Checked;
302 | }
303 |
304 |
305 | // Placeholder test code for joystick:
306 |
307 | // Need to work out some issues with joystick code
308 | // I'm developing on Win7 X64, but I want to target back to XP X32
309 | // I get some exceptions from DX on startup, so I'll have to revist
310 | // how to get joystick code integrated
311 | //
312 | //Error while loading
313 | //C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.dll
314 | //An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
315 | //
316 | // TODO poll
317 | //jst.UpdateStatus();
318 |
319 | void CbJoySticksSelectedIndexChanged(object sender, EventArgs e)
320 | {
321 | try {
322 | jst.AcquireJoystick(sticks[cbJoySticks.SelectedIndex]);
323 | label9.Text = string.Format("Axes = {0}", jst.AxisCount);
324 | label10.Text = string.Format("Buttons = {0}", jst.ButtonCount);
325 |
326 | cbJoySticks.Items.Clear();
327 | cbXaxisJog.Items.Clear();
328 | cbYaxisJog.Items.Clear();
329 | cbZaxisJog.Items.Clear();
330 | cbAbort.Items.Clear();
331 | cbFeedHold.Items.Clear();
332 | cbJogSpeedDec.Items.Clear();
333 | cbJogSpeedInc.Items.Clear();
334 |
335 | for (int i = 0; i < jst.AxisCount; i++)
336 | {
337 | cbXaxisJog.Items.Add("AXIS " + (i + 1).ToString());
338 | cbYaxisJog.Items.Add("AXIS " + (i + 1).ToString());
339 | cbZaxisJog.Items.Add("AXIS " + (i + 1).ToString());
340 | }
341 |
342 | for (int i = 0; i < jst.ButtonCount; i++)
343 | {
344 | cbAbort.Items.Add("Button " + (i + 1).ToString());
345 | cbFeedHold.Items.Add("Button " + (i + 1).ToString());
346 | cbJogSpeedDec.Items.Add("Button " + (i + 1).ToString());
347 | cbJogSpeedInc.Items.Add("Button " + (i + 1).ToString());
348 | }
349 | }
350 | catch {}
351 | }
352 |
353 | void getJoysticks()
354 | {
355 | cbJoySticks.SelectedIndexChanged -= CbJoySticksSelectedIndexChanged;
356 |
357 | try {
358 | jst = new JoystickInterface.Joystick(this.Handle);
359 | sticks = jst.FindJoysticks();
360 |
361 |
362 | foreach(string joyName in sticks)
363 | cbJoySticks.Items.Add(joyName);
364 |
365 | }
366 | catch {} //(Exception ex) { MessageBox.Show(ex.Message); }
367 |
368 | cbJoySticks.SelectedIndexChanged += CbJoySticksSelectedIndexChanged;
369 |
370 | if(cbJoySticks.Items.Count > 0)
371 | cbJoySticks.SelectedIndex = 0;
372 | }
373 |
374 | void SettingsLoad(object sender, EventArgs e)
375 | {
376 | getJoysticks();
377 | }
378 |
379 | private void colorComboBox1_SelectedIndexChanged(object sender, EventArgs e)
380 | {
381 | panel1.BackColor = colorComboBox1.SelectedColor;
382 | }
383 |
384 | private void colorComboBox2_SelectedIndexChanged(object sender, EventArgs e)
385 | {
386 | customPanel5.BackColor = colorComboBox2.SelectedColor;
387 | customPanel5.Invalidate();
388 | }
389 |
390 | private void colorComboBox3_SelectedIndexChanged(object sender, EventArgs e)
391 | {
392 | customPanel5.BackColor2 = colorComboBox3.SelectedColor;
393 | customPanel5.Invalidate();
394 | }
395 |
396 | private void colorComboBox4_SelectedIndexChanged(object sender, EventArgs e)
397 | {
398 | customPanel5.BorderColor = colorComboBox4.SelectedColor;
399 | customPanel5.Invalidate();
400 | }
401 |
402 | void SetBackColorRecursive(Control control, Color color)
403 | {
404 | control.BackColor = color;
405 |
406 | foreach (Control c in control.Controls)
407 | SetBackColorRecursive(c, color);
408 | }
409 |
410 | private void SetTextBoxBackColor(Control Page, Color clr)
411 | {
412 |
413 | foreach (Control ctrl in Page.Controls) {
414 | if (ctrl is TextBox) {
415 | ((TextBox)(ctrl)).BackColor = clr;
416 | }
417 | else {
418 | if (ctrl.Controls.Count > 0) {
419 | SetTextBoxBackColor(ctrl, clr);
420 | }
421 | }
422 | }
423 | }
424 |
425 | }
426 | }
427 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Settings.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | False
122 |
123 |
124 | False
125 |
126 |
127 | False
128 |
129 |
130 | False
131 |
132 |
133 | False
134 |
135 |
136 | False
137 |
138 |
139 | False
140 |
141 |
142 | False
143 |
144 |
145 | False
146 |
147 |
148 | False
149 |
150 |
151 | False
152 |
153 |
154 | False
155 |
156 |
157 | False
158 |
159 |
160 | False
161 |
162 |
163 | False
164 |
165 |
166 | False
167 |
168 |
169 | False
170 |
171 |
172 | False
173 |
174 |
175 | False
176 |
177 |
178 | False
179 |
180 |
181 | False
182 |
183 |
184 | False
185 |
186 |
187 | False
188 |
189 |
190 | False
191 |
192 |
193 | False
194 |
195 |
196 | False
197 |
198 |
199 | True
200 |
201 |
202 | True
203 |
204 |
205 | True
206 |
207 |
208 | True
209 |
210 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Settings1.cs:
--------------------------------------------------------------------------------
1 | namespace CSharpBasicViewerApp.Properties {
2 |
3 |
4 | // This class allows you to handle specific events on the settings class:
5 | // The SettingChanging event is raised before a setting's value is changed.
6 | // The PropertyChanged event is raised after a setting's value is changed.
7 | // The SettingsLoaded event is raised after the setting values are loaded.
8 | // The SettingsSaving event is raised before the setting values are saved.
9 | internal sealed partial class Settings {
10 |
11 | public Settings() {
12 | // // To add event handlers for saving and changing settings, uncomment the lines below:
13 | //
14 | // this.SettingChanging += this.SettingChangingEventHandler;
15 | //
16 | // this.SettingsSaving += this.SettingsSavingEventHandler;
17 | //
18 | }
19 |
20 | private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
21 | // Add code to handle the SettingChangingEvent event here.
22 | }
23 |
24 | private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
25 | // Add code to handle the SettingsSaving event here.
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/CNCInfusion/SevenSegment/SevenSegmentArray.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 | using System.Drawing;
4 |
5 | /*
6 | * Seven-segment LED array control for .NET
7 | * (uses the original seven-segment LED control)
8 | *
9 | * Copyright 2009 Dmitry Brant. All Rights Reserved.
10 | * me@dmitrybrant.com
11 | * http://dmitrybrant.com
12 | *
13 | * This component is free for personal use.
14 | * If you would like to use it in a commercial application, please
15 | * e-mail me at the address above.
16 | * This software comes as-is, with no warranty.
17 | *
18 | * Features:
19 | * - Arbitrary number of array elements
20 | * - All the customizable settings of the original 7-seg control
21 | * - Accepts a string as a value, and distributes the characters
22 | * among the array elements, automatically handling decimal points.
23 | *
24 | */
25 |
26 | namespace DmitryBrant.CustomControls
27 | {
28 | public class SevenSegmentArray : UserControl
29 | {
30 | public SevenSegmentArray()
31 | {
32 | this.SuspendLayout();
33 | this.Name = "SevenSegmentArray";
34 | this.Size = new System.Drawing.Size(100, 25);
35 | this.Resize += new System.EventHandler(this.SevenSegmentArray_Resize);
36 | this.ResumeLayout(false);
37 |
38 | this.TabStop = false;
39 | elementPadding = new Padding(4, 4, 4, 4);
40 | RecreateSegments(4);
41 | }
42 |
43 |
44 | ///
45 | /// Array of segment controls that are currently children of this control.
46 | ///
47 | private SevenSegment[] segments = null;
48 |
49 | ///
50 | /// Change the number of elements in our LED array. This destroys
51 | /// the previous elements, and creates new ones in their place, applying
52 | /// all the current options to the new ones.
53 | ///
54 | /// Number of elements to create.
55 | private void RecreateSegments(int count)
56 | {
57 | if (segments != null)
58 | for (int i = 0; i < segments.Length; i++) { segments[i].Parent = null; segments[i].Dispose(); }
59 |
60 | if (count <= 0) return;
61 | segments = new SevenSegment[count];
62 |
63 | for (int i = 0; i < count; i++)
64 | {
65 | segments[i] = new SevenSegment();
66 | segments[i].Parent = this;
67 | segments[i].Top = 0;
68 | segments[i].Height = this.Height;
69 | segments[i].Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
70 | segments[i].Visible = true;
71 | }
72 |
73 | ResizeSegments();
74 | UpdateSegments();
75 | this.Value = theValue;
76 | }
77 |
78 | ///
79 | /// Align the elements of the array to fit neatly within the
80 | /// width of the parent control.
81 | ///
82 | private void ResizeSegments()
83 | {
84 | int segWidth = this.Width / segments.Length;
85 | for (int i = 0; i < segments.Length; i++)
86 | {
87 | segments[i].Left = this.Width * (segments.Length - 1 - i) / segments.Length;
88 | segments[i].Width = segWidth;
89 | }
90 | }
91 |
92 | ///
93 | /// Update the properties of each element with the properties
94 | /// we have stored.
95 | ///
96 | private void UpdateSegments()
97 | {
98 | for (int i = 0; i < segments.Length; i++)
99 | {
100 | segments[i].ColorBackground = colorBackground;
101 | segments[i].ColorDark = colorDark;
102 | segments[i].ColorLight = colorLight;
103 | segments[i].ElementWidth = elementWidth;
104 | segments[i].ItalicFactor = italicFactor;
105 | segments[i].DecimalShow = showDot;
106 | segments[i].Padding = elementPadding;
107 | }
108 | }
109 |
110 | private void SevenSegmentArray_Resize(object sender, EventArgs e) { ResizeSegments(); }
111 |
112 | protected override void OnPaintBackground(PaintEventArgs e) { e.Graphics.Clear(colorBackground); }
113 |
114 |
115 | private int elementWidth = 10;
116 | private float italicFactor = 0.0F;
117 | private Color colorBackground = Color.DarkGray;
118 | private Color colorDark = Color.DimGray;
119 | private Color colorLight = Color.Red;
120 | private bool showDot = true;
121 | private Padding elementPadding;
122 |
123 | ///
124 | /// Background color of the LED array.
125 | ///
126 | public Color ColorBackground { get { return colorBackground; } set { colorBackground = value; UpdateSegments(); } }
127 | ///
128 | /// Color of inactive LED segments.
129 | ///
130 | public Color ColorDark { get { return colorDark; } set { colorDark = value; UpdateSegments(); } }
131 | ///
132 | /// Color of active LED segments.
133 | ///
134 | public Color ColorLight { get { return colorLight; } set { colorLight = value; UpdateSegments(); } }
135 |
136 | ///
137 | /// Width of LED segments.
138 | ///
139 | public int ElementWidth { get { return elementWidth; } set { elementWidth = value; UpdateSegments(); } }
140 | ///
141 | /// Shear coefficient for italicizing the displays. Try a value like -0.1.
142 | ///
143 | public float ItalicFactor { get { return italicFactor; } set { italicFactor = value; UpdateSegments(); } }
144 | ///
145 | /// Specifies if the decimal point LED is displayed.
146 | ///
147 | public bool DecimalShow { get { return showDot; } set { showDot = value; UpdateSegments(); } }
148 |
149 | ///
150 | /// Number of seven-segment elements in this array.
151 | ///
152 | public int ArrayCount { get { return segments.Length; } set { if ((value > 0) && (value <= 100)) RecreateSegments(value); } }
153 | ///
154 | /// Padding that applies to each seven-segment element in the array.
155 | /// Tweak these numbers to get the perfect appearance for the array of your size.
156 | ///
157 | public Padding ElementPadding { get { return elementPadding; } set { elementPadding = value; UpdateSegments(); } }
158 |
159 |
160 | private string theValue = null;
161 | ///
162 | /// The value to be displayed on the LED array. This can contain numbers,
163 | /// certain letters, and decimal points.
164 | ///
165 | public string Value
166 | {
167 | get { return theValue; }
168 | set
169 | {
170 | theValue = value;
171 | for (int i = 0; i < segments.Length; i++) { segments[i].CustomPattern = 0; segments[i].DecimalOn = false; }
172 | if (theValue != null)
173 | {
174 | int segmentIndex = 0;
175 | for (int i = theValue.Length - 1; i >= 0; i--)
176 | {
177 | if (segmentIndex >= segments.Length) break;
178 | if (theValue[i] == '.') segments[segmentIndex].DecimalOn = true;
179 | else segments[segmentIndex++].Value = theValue[i].ToString();
180 | }
181 | }
182 | }
183 | }
184 |
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Viewer/MG_CS_BasicViewer.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace MacGen
2 | {
3 | partial class MG_CS_BasicViewer
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 |
11 | #region Component Designer generated code
12 |
13 | ///
14 | /// Required method for Designer support - do not modify
15 | /// the contents of this method with the code editor.
16 | ///
17 | private void InitializeComponent()
18 | {
19 | this.SuspendLayout();
20 | //
21 | // MG_CS_BasicViewer
22 | //
23 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
24 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
25 | this.Name = "MG_CS_BasicViewer";
26 | this.Size = new System.Drawing.Size(210, 211);
27 | this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.MG_BasicViewer_MouseWheel);
28 | this.Paint += new System.Windows.Forms.PaintEventHandler(this.MG_BasicViewer_Paint);
29 | this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MG_BasicViewer_MouseMove);
30 | this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MG_BasicViewer_MouseDown);
31 | this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MG_BasicViewer_MouseUp);
32 | this.SizeChanged += new System.EventHandler(this.MG_CS_BasicViewer_SizeChanged);
33 | this.ResumeLayout(false);
34 | }
35 |
36 | #endregion
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Viewer/MG_CS_BasicViewer.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/src/CNCInfusion/Viewer/clsCadRect.cs:
--------------------------------------------------------------------------------
1 | ///
2 | /// Custom rectangle
3 | ///
4 | ///
5 | /// Copyright © MacGen Programming 2006
6 | /// Jason Titcomb
7 | /// www.CncEdit.com
8 | ///
9 | using System.Drawing;
10 | public class clsCadRect
11 | {
12 | private float mX;
13 | public float X
14 | {
15 | get { return mX; }
16 | set
17 | {
18 | mX = value;
19 | mLeft = mX;
20 | mRight = mLeft + mWidth;
21 | }
22 | }
23 | private float my;
24 | public float Y
25 | {
26 | get { return my; }
27 | set
28 | {
29 | my = value;
30 | mTop = my + mHeight;
31 | mBottom = my;
32 | }
33 | }
34 | private float mLeft;
35 | public float Left
36 | {
37 | get { return mLeft; }
38 | }
39 | private float mRight;
40 | public float Right
41 | {
42 | get { return mRight; }
43 | }
44 | private float mWidth;
45 | public float Width
46 | {
47 | get { return mWidth; }
48 | set
49 | {
50 | mWidth = value;
51 | mRight = mLeft + mWidth;
52 | }
53 | }
54 | private float mHeight;
55 | public float Height
56 | {
57 | get { return mHeight; }
58 | set
59 | {
60 | mHeight = value;
61 | mTop = my + mHeight;
62 | }
63 | }
64 | private float mTop;
65 | public float Top
66 | {
67 | get { return mTop; }
68 | }
69 | private float mBottom;
70 | public float Bottom
71 | {
72 | get { return mBottom; }
73 | }
74 |
75 | public clsCadRect()
76 | {
77 | X = 0;
78 | Y = 0;
79 | Width = 0;
80 | Height = 0;
81 | }
82 |
83 | public clsCadRect(float x, float y, float width, float height)
84 | {
85 | this.X = x;
86 | this.Y = y;
87 | this.Width = width;
88 | this.Height = height;
89 | }
90 | public bool IntersectsLine(PointF p1, PointF p2)
91 | {
92 | return IntersectsLine(p1.X, p1.Y, p2.X, p2.Y);
93 | }
94 |
95 | public bool Contains(float x, float y)
96 | {
97 | return x > Left & x < Right & y > Bottom & y < Top;
98 | }
99 |
100 | public bool IntersectsLine(float x1, float y1, float x2, float y2)
101 | {
102 | //Trivial test inside
103 | if (this.Contains(x1, y1) | this.Contains(x2, y2))
104 | {
105 | return true;
106 | }
107 | //Trivial test outside
108 | if (x1 < this.Left & x2 < this.Left)
109 | {
110 | return false;
111 | }
112 | else if (x1 > this.Right & x2 > this.Right)
113 | {
114 | return false;
115 | }
116 | else if (y1 < this.Bottom & y2 < this.Bottom)
117 | {
118 | return false;
119 | }
120 | else if (y1 > this.Top & y2 > this.Top)
121 | {
122 | return false;
123 | }
124 |
125 | //Trivial test vertical or horizontal
126 | if (x1 == x2)
127 | {
128 | return true;
129 | }
130 | if (y1 == y2)
131 | {
132 | return true;
133 | }
134 |
135 | float slope = (y2 - y1) / (x2 - x1);
136 | float Yintercept = y1 - (slope * x1);
137 | float iptX = 0;
138 | float iptY = 0;
139 |
140 | //Left edge
141 | iptX = this.Left;
142 | iptY = (slope * iptX) + Yintercept;
143 | if (iptY > this.Bottom & iptY < this.Top)
144 | {
145 | return true;
146 | }
147 |
148 | //Right edge
149 | iptX = this.Right;
150 | if (iptY > this.Bottom & iptY < this.Top)
151 | {
152 | return true;
153 | }
154 |
155 | //Top edge
156 | iptY = this.Top;
157 | iptX = ((iptY - Yintercept) / slope);
158 | if (iptX > this.Left & iptX < this.Right)
159 | {
160 | return true;
161 | }
162 |
163 | //Bottom edge
164 | iptY = this.Bottom;
165 | iptX = ((iptY - Yintercept) / slope);
166 | if (iptX > this.Left & iptX < this.Right)
167 | {
168 | return true;
169 | }
170 | return false;
171 | }
172 | }
--------------------------------------------------------------------------------
/src/CNCInfusion/Viewer/clsDisplayList.cs:
--------------------------------------------------------------------------------
1 | using System.Drawing;
2 | public class clsDisplayList
3 | {
4 | public bool InView = true;
5 | public bool Rapid = true;
6 | public int ParentIndex;
7 | public Color Color;
8 | public PointF[] Points;
9 | }
--------------------------------------------------------------------------------
/src/CNCInfusion/Viewer/clsMotionRecord.cs:
--------------------------------------------------------------------------------
1 | using System.Drawing;
2 | namespace MacGen
3 | {
4 | public class clsMotionRecord
5 | {
6 | public string Codestring;
7 | //cnc codeline
8 | public MacGen.Motion MotionType;
9 | //point,arc,line etc....
10 | public int Linenumber;
11 | //line number of CNC file
12 | public float Xold;
13 | public float Yold;
14 | public float Zold;
15 | public float Xpos;
16 | public float Ypos;
17 | public float Zpos;
18 | public float Rpoint;
19 | public float Rad;
20 | public float Sang;
21 | public float Eang;
22 | public float Xcentr;
23 | public float Ycentr;
24 | public float Zcentr;
25 | public Color DrawClr;
26 | public float Tool;
27 | public float Speed;
28 | public float Feed;
29 | public bool BeginProfile;
30 | public bool Rotate;
31 | public float OldRotaryPos;
32 | public float NewRotaryPos;
33 | public int RotaryDir;
34 | public int WrkPlane;
35 | public float DrillClear;
36 | public bool Inview;
37 | }
38 | }
--------------------------------------------------------------------------------
/src/CNCInfusion/Viewer/clsToolLayer.cs:
--------------------------------------------------------------------------------
1 | using System.Drawing;
2 | public class clsToolLayer
3 | {
4 | public System.Drawing.Color Color;
5 | public float Number;
6 | public bool Hidden;
7 |
8 | public clsToolLayer(float number, Color color)
9 | {
10 | this.Number = number;
11 | this.Color = color;
12 | this.Hidden = false;
13 | }
14 | }
--------------------------------------------------------------------------------
/src/CNCInfusion/about.Designer.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by SharpDevelop.
3 | * User: ${USER}
4 | * Date: ${DATE}
5 | * Time: ${TIME}
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 | namespace CNCInfusion
10 | {
11 | partial class about : System.Windows.Forms.Form
12 | {
13 | ///
14 | /// Designer variable used to keep track of non-visual components.
15 | ///
16 | private System.ComponentModel.IContainer components = null;
17 |
18 | ///
19 | /// Disposes resources used by the form.
20 | ///
21 | /// true if managed resources should be disposed; otherwise, false.
22 | protected override void Dispose(bool disposing)
23 | {
24 | if (disposing) {
25 | if (components != null) {
26 | components.Dispose();
27 | }
28 | }
29 | base.Dispose(disposing);
30 | }
31 |
32 | ///
33 | /// This method is required for Windows Forms designer support.
34 | /// Do not change the method contents inside the source code editor. The Forms designer might
35 | /// not be able to load this method if it was changed manually.
36 | ///
37 | private void InitializeComponent()
38 | {
39 | this.lbInfo = new System.Windows.Forms.ListBox();
40 | this.panel1 = new System.Windows.Forms.Panel();
41 | this.label1 = new System.Windows.Forms.Label();
42 | this.lbVersion = new System.Windows.Forms.Label();
43 | this.button1 = new System.Windows.Forms.Button();
44 | this.listBox1 = new System.Windows.Forms.ListBox();
45 | this.panel1.SuspendLayout();
46 | this.SuspendLayout();
47 | //
48 | // lbInfo
49 | //
50 | this.lbInfo.BorderStyle = System.Windows.Forms.BorderStyle.None;
51 | this.lbInfo.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
52 | this.lbInfo.FormattingEnabled = true;
53 | this.lbInfo.ItemHeight = 14;
54 | this.lbInfo.Location = new System.Drawing.Point(12, 58);
55 | this.lbInfo.Name = "lbInfo";
56 | this.lbInfo.Size = new System.Drawing.Size(485, 70);
57 | this.lbInfo.TabIndex = 1;
58 | //
59 | // panel1
60 | //
61 | this.panel1.BackColor = System.Drawing.Color.CornflowerBlue;
62 | this.panel1.Controls.Add(this.label1);
63 | this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
64 | this.panel1.Location = new System.Drawing.Point(0, 0);
65 | this.panel1.Name = "panel1";
66 | this.panel1.Size = new System.Drawing.Size(509, 32);
67 | this.panel1.TabIndex = 2;
68 | //
69 | // label1
70 | //
71 | this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
72 | this.label1.ForeColor = System.Drawing.SystemColors.Window;
73 | this.label1.Location = new System.Drawing.Point(10, 7);
74 | this.label1.Name = "label1";
75 | this.label1.Size = new System.Drawing.Size(251, 24);
76 | this.label1.TabIndex = 0;
77 | this.label1.Text = "CNCInfusion ";
78 | //
79 | // lbVersion
80 | //
81 | this.lbVersion.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
82 | this.lbVersion.Location = new System.Drawing.Point(10, 38);
83 | this.lbVersion.Name = "lbVersion";
84 | this.lbVersion.Size = new System.Drawing.Size(161, 17);
85 | this.lbVersion.TabIndex = 3;
86 | this.lbVersion.Text = "Version";
87 | //
88 | // button1
89 | //
90 | this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
91 | this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
92 | this.button1.Location = new System.Drawing.Point(12, 293);
93 | this.button1.Name = "button1";
94 | this.button1.Size = new System.Drawing.Size(62, 23);
95 | this.button1.TabIndex = 5;
96 | this.button1.Text = "OK";
97 | this.button1.UseVisualStyleBackColor = true;
98 | //
99 | // listBox1
100 | //
101 | this.listBox1.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
102 | this.listBox1.FormattingEnabled = true;
103 | this.listBox1.ItemHeight = 14;
104 | this.listBox1.Items.AddRange(new object[] {
105 | "Grbl CNC was assembled using many components from code project",
106 | "and other internet sources. ",
107 | "",
108 | "2012 Paul D. Fincato",
109 | "Code Project Open License",
110 | "",
111 | "",
112 | "Credit to original authors of components used in this application",
113 | "",
114 | "G codebackplot",
115 | "--------------",
116 | "Jason Titcomb",
117 | "http://www.codeproject.com/Articles/17424/CNC-Graphical-Backplotter",
118 | "Code Project Open License",
119 | "",
120 | "7 segment",
121 | "---------",
122 | "Dmitry Brant",
123 | "http://dmitrybrant.com",
124 | "This component is free for personal use.",
125 | " ",
126 | "Custom Panel",
127 | "------------",
128 | "Mark Jackson",
129 | "http://www.codeproject.com/Articles/7641/Customising-the-NET-Panel-control",
130 | "Code Project Open License",
131 | "",
132 | "Knob",
133 | "----",
134 | "Luca Bonotto",
135 | "http://www.codeproject.com/Articles/36116/Industrial-Controls-2",
136 | "Code Project Open License",
137 | "",
138 | "Icons",
139 | "-----",
140 | "Mark James",
141 | "http://www.famfamfam.com/lab/icons/silk/",
142 | "Creative Commons Attribution 3.0 License",
143 | "",
144 | "Joystick",
145 | "--------",
146 | "Mark Harris",
147 | "Interfacing with a Joystick using C#",
148 | "http://www.codeproject.com/Articles/16704/Interfacing-with-a-Joystick-using-C",
149 | " ",
150 | "",
151 | "Kudos to the Grbl innovators for a great project!",
152 | "",
153 | "https://github.com/grbl/grbl"});
154 | this.listBox1.Location = new System.Drawing.Point(12, 142);
155 | this.listBox1.Name = "listBox1";
156 | this.listBox1.Size = new System.Drawing.Size(485, 144);
157 | this.listBox1.TabIndex = 13;
158 | //
159 | // about
160 | //
161 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
162 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
163 | this.ClientSize = new System.Drawing.Size(509, 331);
164 | this.Controls.Add(this.listBox1);
165 | this.Controls.Add(this.button1);
166 | this.Controls.Add(this.lbVersion);
167 | this.Controls.Add(this.panel1);
168 | this.Controls.Add(this.lbInfo);
169 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
170 | this.MaximizeBox = false;
171 | this.MinimizeBox = false;
172 | this.Name = "about";
173 | this.ShowInTaskbar = false;
174 | this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
175 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
176 | this.Text = "About";
177 | this.panel1.ResumeLayout(false);
178 | this.ResumeLayout(false);
179 | }
180 | private System.Windows.Forms.ListBox listBox1;
181 | private System.Windows.Forms.Label lbVersion;
182 | private System.Windows.Forms.Button button1;
183 | private System.Windows.Forms.Label label1;
184 | private System.Windows.Forms.Panel panel1;
185 | private System.Windows.Forms.ListBox lbInfo;
186 |
187 | void RichTextBox1TextChanged(object sender, System.EventArgs e)
188 | {
189 |
190 | }
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/src/CNCInfusion/about.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by SharpDevelop.
3 | * User: PAUL_FINCATO
4 | * Date: 12/19/2006
5 | * Time: 2:52 PM
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 |
10 | using System;
11 | using System.Drawing;
12 | using System.Windows.Forms;
13 |
14 | namespace CNCInfusion
15 | {
16 | ///
17 | /// Description of Form1.
18 | ///
19 | public partial class about
20 | {
21 | public about()
22 | {
23 | InitializeComponent();
24 |
25 | System.Reflection.Assembly asm;
26 | System.Reflection.AssemblyName asn;
27 | asm = System.Reflection.Assembly.LoadFile(System.Windows.Forms.Application.ExecutablePath);
28 | asn = asm.GetName();
29 | lbVersion.Text = "Version: " + asn.Version.ToString();
30 |
31 | foreach (System.Reflection.AssemblyName s in asm.GetReferencedAssemblies()) {
32 | lbInfo.Items.Add(s.Name + " [" + s.Version.ToString() + "]");
33 | }
34 | }
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/CNCInfusion/about.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/src/CNCInfusion/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | 0, 0
12 |
13 |
14 | True
15 |
16 |
17 | True
18 |
19 |
20 | True
21 |
22 |
23 | True
24 |
25 |
26 | Mill
27 |
28 |
29 | 0, 0
30 |
31 |
32 | 425, 475
33 |
34 |
35 | True
36 |
37 |
38 | True
39 |
40 |
41 | False
42 |
43 |
44 | 200
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/src/CNCInfusion/bin/Debug/.gitignore:
--------------------------------------------------------------------------------
1 | *.manifest
2 | *.config
3 | *.pdb
4 |
--------------------------------------------------------------------------------
/src/CNCInfusion/bin/Debug/CNCInfusion.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/bin/Debug/CNCInfusion.exe
--------------------------------------------------------------------------------
/src/CNCInfusion/bin/Debug/CNCInfusion.vshost.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nm156/CNCInfusion/d53dae81859c2f4ac69c2126d43746ee93060c65/src/CNCInfusion/bin/Debug/CNCInfusion.vshost.exe
--------------------------------------------------------------------------------
/src/CNCInfusion/bin/Debug/Data/Mill.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Mill
4 | Milling setup file
5 | False
6 | False
7 | False
8 | /*
9 | ()
10 | M30
11 | MILL
12 | X
13 | CCW
14 | 4
15 | :$O
16 | M99
17 | 4
18 | CAD
19 | Mill
20 | 315
21 | 0
22 | 315
23 | 0
24 | 0
25 | 0
26 | G90
27 | G91
28 | G03
29 | G02
30 | R
31 | G80
32 | G81
33 | G82
34 | G83
35 | G84
36 | G85
37 | G86
38 | G87
39 | G88
40 |
41 | G01
42 | G00
43 | G98
44 | G99
45 | B
46 | G17
47 | G18
48 | G19
49 | M98
50 | L
51 |
--------------------------------------------------------------------------------
/src/CNCInfusion/clsMachine.cs:
--------------------------------------------------------------------------------
1 | using MacGen;
2 | public class clsMachine
3 | {
4 | //Store all settings in this class
5 | public string Name; //file name
6 | public string Description; //file name
7 | public string ProgramId; public string Subcall;
8 | //call sub
9 | public string SubRepeats;
10 | public string SubReturn; //return from sub
11 | public string Endmain; //End of main program
12 | public string BlockSkip; //do not process lines that start with this
13 | public string Comments; //Comments
14 | public MachineType MachineType; //lathe ,mill etc..
15 | public bool LatheMinus; //this is for minus lathes
16 | public bool HelixPitch; //helix check box setting
17 | public bool AbsArcCenter; //Arc center chkbox
18 | public int Precision; //output precision 0.0001
19 | public string Searchstring; //a string that determines the setup record
20 | public string[] Drills = new string[10]; //10 drilling cycles 0 index is the cancel code
21 | public string[] ReturnLevel = new string[2];
22 | public string DrillRapid;
23 | public string Rapid;
24 | public string Linear;
25 | public string CCArc;
26 | public string CWArc;
27 | public string Incremental;
28 | public string Absolute;
29 | public string XYplane;
30 | public string XZplane;
31 | public string YZplane;
32 | public float[] ViewAngles = new float[3]; //Store pitch,roll,yaw
33 | public string Rotary; //Rotary axis code ABC
34 | public RotaryDirection RotaryDir; //+1 or -1
35 | public Axis RotaryAxis; //XYZ
36 | public RotaryMotionType RotaryType;
37 | public int RotPrecision; //output precision 0.0001
38 | public float[] ViewShift = new float[3]; //Shift the view for viewing
39 |
40 | public clsMachine(string name)
41 | {
42 | this.Name = name;
43 | }
44 | public clsMachine()
45 | {
46 | }
47 | }
--------------------------------------------------------------------------------
/src/CNCInfusion/clsMotion.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | internal struct Address
3 | {
4 | private char mLabel;
5 | public char Label
6 | {
7 | get { return mLabel; }
8 | set {
9 | mLabel = value;
10 | Letter = (clsProcessor.letters)Enum.Parse(typeof(clsProcessor.letters), mLabel.ToString());
11 | }
12 | }
13 | public float Value;
14 | public string StringValue;
15 | public clsProcessor.letters Letter;
16 | public bool Matches(Address a)
17 | {
18 | return (a.Letter == this.Letter) & (a.Value == this.Value);
19 | }
20 | }
21 |
22 | internal class clsMotion
23 | {
24 | public Address[] Drills = new Address[10]; //G81,G82
25 | public Address[] ReturnLevel = new Address[2]; //G98,G99
26 | public Address DrillRapid; //R
27 | public Address Rapid; //G00
28 | public Address Linear; //G01
29 | public Address CCArc; //G03
30 | public Address CWArc; //G02
31 | public Address Inc; //G91
32 | public Address Abs; //G90
33 | public Address[] Plane = new Address[3]; //G18,18,19
34 | public Address Rotary; //A B C
35 | public Address SubCall; //M98
36 | public Address SubReturn; //M99
37 | }
--------------------------------------------------------------------------------
/src/CNCInfusion/clsSettings.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 | using System.Xml;
4 | using MacGen;
5 | using System;
6 | using System.Windows.Forms;
7 | ///
8 | /// Reads and writes settings to disk.
9 | ///
10 | ///
11 | /// Copyright © MacGen Programming 2006
12 | /// Jason Titcomb
13 | /// www.CncEdit.com
14 | ///
15 | public class clsSettings
16 | {
17 | private List mMachines = new List();
18 | public clsMachine Machine;
19 | private const string DATEXTENSION = ".xml";
20 | private string mDatFolder;
21 | public event MachineLoadedEventHandler MachineLoaded;
22 | public delegate void MachineLoadedEventHandler(clsMachine m);
23 | public event MachineAddedEventHandler MachineAdded;
24 | public delegate void MachineAddedEventHandler(clsMachine m);
25 | public event MachineDeletedEventHandler MachineDeleted;
26 | public delegate void MachineDeletedEventHandler(string name);
27 | public event MachineMatchedEventHandler MachineMatched;
28 | public delegate void MachineMatchedEventHandler(clsMachine m);
29 | public event MachineActivatedEventHandler MachineActivated;
30 | public delegate void MachineActivatedEventHandler(clsMachine m);
31 | public event MachinesClearedEventHandler MachinesCleared;
32 | public delegate void MachinesClearedEventHandler();
33 |
34 | #region "Singleton"
35 | private static clsSettings mInstance;
36 | //PRIVATE constructor can only be called from this class
37 | private clsSettings()
38 | {
39 | }
40 | ///
41 | /// Static method for creating the single instance of the Constructor
42 | ///
43 | public static clsSettings Instance()
44 | {
45 | // initialize if not already done
46 | if (mInstance == null) {
47 | mInstance = new clsSettings();
48 | }
49 | // return the initialized instance of the Singleton Class
50 | return mInstance;
51 | }
52 | //Instance
53 | #endregion
54 | ///
55 | /// Sets or gets the folder containing the data files
56 | ///
57 | public string DatFolder {
58 | get { return mDatFolder; }
59 | set {
60 | if (value.EndsWith("\\")) {
61 | mDatFolder = value;
62 | }
63 | else {
64 | mDatFolder = value + "\\";
65 | }
66 | }
67 | }
68 |
69 | ///
70 | /// Sets or gets the name of the current machine
71 | ///
72 | public string MachineName {
73 | get { return Machine.Name; }
74 | set {
75 | foreach (clsMachine m in this.mMachines) {
76 | if (string.Compare(value, m.Name, true) == 0) {
77 | Machine = m;
78 | if (MachineActivated != null) {
79 | MachineActivated(m);
80 | }
81 | return;
82 | }
83 | }
84 | }
85 | }
86 |
87 | public void LoadMachine(string sName)
88 | {
89 | XmlReaderSettings settings = new XmlReaderSettings();
90 | int r = 0;
91 | Machine = new clsMachine();
92 | {
93 | settings.IgnoreWhitespace = true;
94 | settings.IgnoreComments = true;
95 | settings.IgnoreProcessingInstructions = true;
96 | settings.ProhibitDtd = true;
97 | settings.CloseInput = true;
98 | }
99 | using (XmlReader xReader = XmlReader.Create(sName, settings)) {
100 | {
101 | xReader.MoveToContent();
102 | xReader.ReadToDescendant("Name");
103 | Machine.Name = xReader.ReadElementContentAsString();
104 | Machine.Description = xReader.ReadElementContentAsString();
105 | Machine.AbsArcCenter = bool.Parse(xReader.ReadElementContentAsString());
106 | Machine.LatheMinus = bool.Parse(xReader.ReadElementContentAsString());
107 | Machine.HelixPitch = bool.Parse(xReader.ReadElementContentAsString());
108 | Machine.BlockSkip = xReader.ReadElementContentAsString();
109 | Machine.Comments = xReader.ReadElementContentAsString();
110 | Machine.Endmain = xReader.ReadElementContentAsString();
111 | Machine.MachineType = (MachineType)Enum.Parse(typeof(MachineType), xReader.ReadElementContentAsString());
112 | Machine.RotaryAxis = (Axis)Enum.Parse(typeof(Axis), xReader.ReadElementContentAsString());
113 | Machine.RotaryDir = (RotaryDirection)Enum.Parse(typeof(RotaryDirection), xReader.ReadElementContentAsString());
114 | Machine.Precision = int.Parse(xReader.ReadElementContentAsString());
115 | Machine.ProgramId = xReader.ReadElementContentAsString();
116 | Machine.SubReturn = xReader.ReadElementContentAsString();
117 | Machine.RotPrecision = int.Parse(xReader.ReadElementContentAsString());
118 | Machine.RotaryType = (RotaryMotionType)Enum.Parse(typeof(RotaryMotionType), xReader.ReadElementContentAsString());
119 | Machine.Searchstring = xReader.ReadElementContentAsString();
120 | for (r = 0; r <= Machine.ViewAngles.Length - 1; r++) {
121 | Machine.ViewAngles[r] = float.Parse(xReader.ReadElementContentAsString());
122 | }
123 | for (r = 0; r <= Machine.ViewShift.Length - 1; r++) {
124 | Machine.ViewShift[r] = float.Parse(xReader.ReadElementContentAsString());
125 | }
126 | Machine.Absolute = xReader.ReadElementContentAsString();
127 | Machine.Incremental = xReader.ReadElementContentAsString();
128 | Machine.CCArc = xReader.ReadElementContentAsString();
129 | Machine.CWArc = xReader.ReadElementContentAsString();
130 | Machine.DrillRapid = xReader.ReadElementContentAsString();
131 | for (r = 0; r <= Machine.Drills.Length - 1; r++) {
132 | Machine.Drills[r] = xReader.ReadElementContentAsString();
133 | }
134 | Machine.Linear = xReader.ReadElementContentAsString();
135 | Machine.Rapid = xReader.ReadElementContentAsString();
136 | Machine.ReturnLevel[0] = xReader.ReadElementContentAsString();
137 | Machine.ReturnLevel[1] = xReader.ReadElementContentAsString();
138 | Machine.Rotary = xReader.ReadElementContentAsString();
139 | Machine.XYplane = xReader.ReadElementContentAsString();
140 | Machine.XZplane = xReader.ReadElementContentAsString();
141 | Machine.YZplane = xReader.ReadElementContentAsString();
142 | Machine.Subcall = xReader.ReadElementContentAsString();
143 | Machine.SubRepeats = xReader.ReadElementContentAsString();
144 | }
145 | }
146 | mMachines.Add(Machine);
147 | if (MachineLoaded != null) {
148 | MachineLoaded(Machine);
149 | }
150 | }
151 |
152 | public void SaveMachine(clsMachine MySetup)
153 | {
154 | string sName = DatFolder + MySetup.Name + DATEXTENSION;
155 | XmlWriterSettings xSettings = new XmlWriterSettings();
156 | int r = 0;
157 | xSettings.Indent = true;
158 | xSettings.CheckCharacters = false;
159 | xSettings.CloseOutput = true;
160 | using (XmlWriter xWriter = XmlWriter.Create(sName, xSettings)) {
161 | {
162 | xWriter.WriteStartDocument(true);
163 | xWriter.WriteStartElement("Machine");
164 | xWriter.WriteElementString("Name", MySetup.Name);
165 | xWriter.WriteElementString("Description", MySetup.Description);
166 | xWriter.WriteElementString("AbsArcCenter", MySetup.AbsArcCenter.ToString());
167 | xWriter.WriteElementString("LatheMinus", MySetup.LatheMinus.ToString());
168 | xWriter.WriteElementString("HelixPitch", MySetup.HelixPitch.ToString());
169 | xWriter.WriteElementString("BlockSkip", MySetup.BlockSkip);
170 | xWriter.WriteElementString("Comments", MySetup.Comments);
171 | xWriter.WriteElementString("Endmain", MySetup.Endmain.ToString());
172 | xWriter.WriteElementString("MachineType", MySetup.MachineType.ToString());
173 | xWriter.WriteElementString("RotaryAxis", MySetup.RotaryAxis.ToString());
174 | xWriter.WriteElementString("RotaryDir", MySetup.RotaryDir.ToString());
175 | xWriter.WriteElementString("Precision", MySetup.Precision.ToString());
176 | xWriter.WriteElementString("ProgramId", MySetup.ProgramId);
177 | xWriter.WriteElementString("SubReturn", MySetup.SubReturn);
178 | xWriter.WriteElementString("RotPrecision", MySetup.RotPrecision.ToString());
179 | xWriter.WriteElementString("RotaryType", MySetup.RotaryType.ToString());
180 | xWriter.WriteElementString("Searchstring", MySetup.Searchstring);
181 | for (r = 0; r <= 2; r++) {
182 | xWriter.WriteElementString("ViewAngles_" + r.ToString(), MySetup.ViewAngles[r].ToString());
183 | }
184 | for (r = 0; r <= 2; r++) {
185 | xWriter.WriteElementString("ViewShift_" + r.ToString(), MySetup.ViewShift[r].ToString());
186 | }
187 | xWriter.WriteElementString("Absolute", MySetup.Absolute);
188 | xWriter.WriteElementString("Incremental", MySetup.Incremental);
189 | xWriter.WriteElementString("CCArc", MySetup.CCArc);
190 | xWriter.WriteElementString("CWArc", MySetup.CWArc);
191 | xWriter.WriteElementString("DrillRapid", MySetup.DrillRapid);
192 | for (r = 0; r <= MySetup.Drills.Length - 1; r++) {
193 | xWriter.WriteElementString("Drills_" + r.ToString(), MySetup.Drills[r]);
194 | }
195 | xWriter.WriteElementString("Linear", MySetup.Linear);
196 | xWriter.WriteElementString("Rapid", MySetup.Rapid);
197 | xWriter.WriteElementString("ReturnLevel_0", MySetup.ReturnLevel[0]);
198 | xWriter.WriteElementString("ReturnLevel_1", MySetup.ReturnLevel[1]);
199 | xWriter.WriteElementString("Rotary", MySetup.Rotary);
200 | xWriter.WriteElementString("XYplane", MySetup.XYplane);
201 | xWriter.WriteElementString("XZplane", MySetup.XZplane);
202 | xWriter.WriteElementString("YZplane", MySetup.YZplane);
203 | xWriter.WriteElementString("Subcall", MySetup.Subcall);
204 | xWriter.WriteElementString("SubRepeats", MySetup.SubRepeats);
205 | xWriter.WriteEndElement();
206 | //Machine
207 | }
208 | }
209 | }
210 |
211 | public void DeleteMachine(string name)
212 | {
213 | string fileToDelete = DatFolder + name + DATEXTENSION;
214 | if (System.IO.File.Exists(fileToDelete)) {
215 | System.IO.File.Delete(fileToDelete);
216 | mMachines.Remove(Machine);
217 | if (MachineDeleted != null) {
218 | MachineDeleted(name);
219 | }
220 | }
221 | }
222 |
223 | public void AddMachine(clsMachine m)
224 | {
225 | mMachines.Add(m);
226 | Machine = m;
227 | if (MachineAdded != null) {
228 | MachineAdded(m);
229 | }
230 | }
231 |
232 | public void RenameMachine(string newName, bool copy)
233 | {
234 | string newFile = DatFolder + newName + DATEXTENSION;
235 | string thisFile = DatFolder + Machine.Name + DATEXTENSION;
236 |
237 | if (copy) {
238 | Machine.Name = newName;
239 | SaveMachine(Machine);
240 | }
241 | else {
242 | System.IO.File.Delete(thisFile);
243 | Machine.Name = newName;
244 | SaveMachine(Machine);
245 | }
246 | }
247 |
248 | public void LoadAllMachines()
249 | {
250 | mMachines.Clear();
251 | if (MachinesCleared != null) {
252 | MachinesCleared();
253 | }
254 | string[] fls = System.IO.Directory.GetFiles(DatFolder, "*" + DATEXTENSION);
255 | foreach (string f in fls) {
256 | LoadMachine(f);
257 | }
258 | }
259 |
260 | public void LoadAllMachines(string sDatFolder)
261 | {
262 | DatFolder = sDatFolder;
263 | LoadAllMachines();
264 | }
265 |
266 | //Loads the combo with names
267 | public void LoadComboWithMachines(ref ComboBox cbo)
268 | {
269 | cbo.BeginUpdate();
270 | cbo.Items.Clear();
271 | foreach (clsMachine m in this.mMachines) {
272 | cbo.Items.Add(m.Name);
273 | }
274 | cbo.EndUpdate();
275 | }
276 |
277 | public void MatchMachineToFile(string sFullfile)
278 | {
279 | int ln = 0;
280 | System.Text.StringBuilder sb = new System.Text.StringBuilder();
281 | string sTemp = null;
282 | System.IO.StreamReader fileReader = default(System.IO.StreamReader);
283 |
284 | if (mMachines.Count == 0) {
285 | Machine = null;
286 | return;
287 | }
288 | //Open CNC file and get 50 lines of text
289 | fileReader = new System.IO.StreamReader(sFullfile);
290 | while (fileReader.Peek() >= 0) {
291 | if (ln >= 50) break;
292 | sb.Append(fileReader.ReadLine());
293 | ln += 1;
294 | }
295 | fileReader.Close();
296 | sTemp = sb.ToString();
297 | foreach (clsMachine m in mMachines) {
298 | if (sTemp.Contains(m.Searchstring)) {
299 | Machine = m;
300 | if (MachineMatched != null) {
301 | MachineMatched(Machine);
302 | }
303 | return;
304 | }
305 | }
306 | }
307 | }
--------------------------------------------------------------------------------
/src/CNCInfusion/frmToolLayers.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace CSharpBasicViewerApp
2 | {
3 | partial class frmToolLayers
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.btnDone = new System.Windows.Forms.Button();
32 | this.tvTools = new System.Windows.Forms.TreeView();
33 | this.SuspendLayout();
34 | //
35 | // btnDone
36 | //
37 | this.btnDone.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
38 | | System.Windows.Forms.AnchorStyles.Right)));
39 | this.btnDone.DialogResult = System.Windows.Forms.DialogResult.Cancel;
40 | this.btnDone.Location = new System.Drawing.Point(21, 172);
41 | this.btnDone.Name = "btnDone";
42 | this.btnDone.Size = new System.Drawing.Size(61, 26);
43 | this.btnDone.TabIndex = 3;
44 | this.btnDone.Text = "Done";
45 | this.btnDone.UseVisualStyleBackColor = true;
46 | this.btnDone.Click += new System.EventHandler(this.btnDone_Click);
47 | //
48 | // tvTools
49 | //
50 | this.tvTools.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
51 | | System.Windows.Forms.AnchorStyles.Left)
52 | | System.Windows.Forms.AnchorStyles.Right)));
53 | this.tvTools.CheckBoxes = true;
54 | this.tvTools.Location = new System.Drawing.Point(0, 0);
55 | this.tvTools.Name = "tvTools";
56 | this.tvTools.ShowLines = false;
57 | this.tvTools.ShowPlusMinus = false;
58 | this.tvTools.ShowRootLines = false;
59 | this.tvTools.Size = new System.Drawing.Size(102, 166);
60 | this.tvTools.TabIndex = 2;
61 | this.tvTools.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.tvTools_AfterCheck);
62 | this.tvTools.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.tvTools_BeforeSelect);
63 | //
64 | // frmToolLayers
65 | //
66 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
67 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
68 | this.CancelButton = this.btnDone;
69 | this.ClientSize = new System.Drawing.Size(102, 199);
70 | this.ControlBox = false;
71 | this.Controls.Add(this.btnDone);
72 | this.Controls.Add(this.tvTools);
73 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
74 | this.Name = "frmToolLayers";
75 | this.ResumeLayout(false);
76 |
77 | }
78 |
79 | #endregion
80 |
81 | internal System.Windows.Forms.Button btnDone;
82 | internal System.Windows.Forms.TreeView tvTools;
83 |
84 |
85 | }
86 | }
--------------------------------------------------------------------------------
/src/CNCInfusion/frmToolLayers.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Text;
7 | using System.Windows.Forms;
8 |
9 | namespace CSharpBasicViewerApp
10 | {
11 | public partial class frmToolLayers : Form
12 | {
13 | public frmToolLayers()
14 | {
15 | InitializeComponent();
16 | }
17 |
18 | private void tvTools_AfterCheck(object sender, TreeViewEventArgs e)
19 | {
20 | if (e.Action == TreeViewAction.Unknown)
21 | return;
22 | ((clsToolLayer)e.Node.Tag).Hidden = !e.Node.Checked;
23 | }
24 |
25 | private void tvTools_BeforeSelect(object sender, TreeViewCancelEventArgs e)
26 | {
27 | e.Cancel = true;
28 | }
29 |
30 | private void btnDone_Click(object sender, EventArgs e)
31 | {
32 | this.Close();
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/CNCInfusion/frmToolLayers.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/src/CNCInfusion/frmViewer.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | 115, 7
122 |
123 |
124 | 210, 11
125 |
126 |
127 | 315, 11
128 |
129 |
130 | 429, 11
131 |
132 |
133 | 31, 9
134 |
135 |
136 | 565, 11
137 |
138 |
139 | 49
140 |
141 |
--------------------------------------------------------------------------------
/src/CNCInfusion/grblPreprocessor.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by SharpDevelop.
3 | * User: pdf
4 | * Date: 2/17/2012
5 | * Time: 10:38 PM
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 | using System;
10 | using System.Collections.Generic;
11 | using System.Threading;
12 | using System.Windows.Forms;
13 | using System.Diagnostics;
14 | using System.Text.RegularExpressions;
15 |
16 | /*
17 | Excerpt from Grbl source:
18 |
19 | Intentionally not supported:
20 |
21 | - Canned cycles
22 | - Tool radius compensation
23 | - A,B,C-axes
24 | - Multiple coordinate systems
25 | - Evaluation of expressions
26 | - Variables
27 | - Multiple home locations
28 | - Probing
29 | - Override control
30 |
31 | group 0 = {G10, G28, G30, G92.1, G92.2, G92.3} (Non modal G-codes)
32 | group 8 = {M7, M8, M9} coolant (special case: M7 and M8 may be active at the same time)
33 | group 9 = {M48, M49} enable/disable feed and speed override switches
34 | group 12 = {G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3} coordinate system selection
35 | group 13 = {G61, G61.1, G64} path control mode
36 | */
37 |
38 | // Attempt to only allow Grbl specific gcode
39 | // case statements are explicitly supported codes
40 |
41 | namespace CNCInfusion
42 | {
43 | public partial class frmViewer : Form
44 | {
45 | private bool GrblPreprocess(string line)
46 | {
47 | const string pattern = "[A-Z]([-+]?[0-9]*[\\.,]?[0-9]*)";
48 | double arg;
49 |
50 | Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
51 | MatchCollection matches = rgx.Matches(line);
52 |
53 | if (matches.Count > 0) {
54 | foreach (Match match in matches) {
55 | arg = double.Parse(match.Value.Substring(1));
56 | switch(match.Value[0]) {
57 | case 'G':
58 | // explicitly supported G codes
59 | switch((int)arg) {
60 | case 0: // MOTION_MODE_SEEK
61 | case 1: // MOTION_MODE_LINEAR
62 | case 2: // MOTION_MODE_CW_ARC
63 | case 3: // MOTION_MODE_CCW_ARC
64 | case 4: // DWELL
65 | case 17: // select_plane(X_AXIS, Y_AXIS, Z_AXIS);
66 | case 18: // select_plane(X_AXIS, Z_AXIS, Y_AXIS)
67 | case 19: // select_plane(Y_AXIS, Z_AXIS, X_AXIS)
68 | case 20: // INCHES
69 | case 21: // METRIC
70 | case 28: // GO_HOME
71 | case 53: // absolute_override
72 | case 80: // MOTION_MODE_CANCEL
73 | case 90: // absolute_mode ON
74 | case 91: // absolute_mode OFF
75 | case 92: // COORDINATE_OFFSET
76 | case 93: // inverse_feed_rate ON
77 | case 94: // inverse_feed_rate OFF
78 | break;
79 | default:
80 | // any other G code
81 | return false;
82 | }
83 | break;
84 | // explicitly supported M codes
85 | case 'M':
86 | switch((int)arg) {
87 | case 0: // PROGRAM_FLOW_PAUSED
88 | case 1: // PROGRAM_FLOW_OPT_PAUSED
89 | case 2: // PROGRAM_FLOW_COMPLETED
90 | case 3: // spindle_direction = 1
91 | case 4: // spindle_direction = -1
92 | case 5: // spindle_direction = 0
93 | case 6: // TOOL CHANGE (Not supported by Grbl by caught by CNCInfusion)
94 | case 30: // PROGRAM_FLOW_COMPLETED
95 | case 60: // PROGRAM_FLOW_PAUSED
96 | break;
97 | default:
98 | // any other M code
99 | return false;
100 | }
101 | break;
102 | // supported codes with any argument
103 | case 'T': // TOOL
104 | case 'F': // FEEDRATE
105 | case 'S': // SPINDLE SPEED
106 | case 'I': // ARC
107 | case 'J': // ARC
108 | case 'K': // ??
109 | case 'P': // ??
110 | case 'R': // ?? ARC/HELIX?
111 | case 'X': // AXIS
112 | case 'Y': // AXIS
113 | case 'Z': // AXIS
114 | break;
115 | default:
116 | return false;
117 | }
118 | }
119 | }
120 | return true;
121 | }
122 | }
123 |
124 | }
125 |
126 |
--------------------------------------------------------------------------------
/src/CNCInfusion/joystick/Joystick.cs:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * C# Joystick Library - Copyright (c) 2006 Mark Harris - MarkH@rris.com.au
3 | ******************************************************************************
4 | * You may use this library in your application, however please do give credit
5 | * to me for writing it and supplying it. If you modify this library you must
6 | * leave this notice at the top of this file. I'd love to see any changes you
7 | * do make, so please email them to me :)
8 | *****************************************************************************/
9 | using System;
10 | using System.Collections.Generic;
11 | using System.Text;
12 | using Microsoft.DirectX.DirectInput;
13 | using System.Diagnostics;
14 |
15 | namespace JoystickInterface
16 | {
17 | ///
18 | /// Class to interface with a joystick device.
19 | ///
20 | public class Joystick
21 | {
22 | private Device joystickDevice;
23 | private JoystickState state;
24 |
25 | private int buttonCount;
26 | private int axisCount;
27 | ///
28 | /// Number of axes on the joystick.
29 | ///
30 | public int AxisCount
31 | {
32 | get { return axisCount; }
33 | }
34 |
35 | public int ButtonCount
36 | {
37 | get { return buttonCount; }
38 | }
39 |
40 | private int axisA;
41 | ///
42 | /// The first axis on the joystick.
43 | ///
44 | public int AxisA
45 | {
46 | get { return axisA; }
47 | }
48 |
49 | private int axisB;
50 | ///
51 | /// The second axis on the joystick.
52 | ///
53 | public int AxisB
54 | {
55 | get { return axisB; }
56 | }
57 |
58 | private int axisC;
59 | ///
60 | /// The third axis on the joystick.
61 | ///
62 | public int AxisC
63 | {
64 | get { return axisC; }
65 | }
66 |
67 | private int axisD;
68 | ///
69 | /// The fourth axis on the joystick.
70 | ///
71 | public int AxisD
72 | {
73 | get { return axisD; }
74 | }
75 |
76 | private int axisE;
77 | ///
78 | /// The fifth axis on the joystick.
79 | ///
80 | public int AxisE
81 | {
82 | get { return axisE; }
83 | }
84 |
85 | private int axisF;
86 | ///
87 | /// The sixth axis on the joystick.
88 | ///
89 | public int AxisF
90 | {
91 | get { return axisF; }
92 | }
93 | private IntPtr hWnd;
94 |
95 | private bool[] buttons;
96 | ///
97 | /// Array of buttons availiable on the joystick. This also includes PoV hats.
98 | ///
99 | public bool[] Buttons
100 | {
101 | get { return buttons; }
102 | }
103 |
104 | private string[] systemJoysticks;
105 |
106 | ///
107 | /// Constructor for the class.
108 | ///
109 | /// Handle of the window which the joystick will be "attached" to.
110 | public Joystick(IntPtr window_handle)
111 | {
112 | hWnd = window_handle;
113 | axisA = -1;
114 | axisB = -1;
115 | axisC = -1;
116 | axisD = -1;
117 | axisE = -1;
118 | axisF = -1;
119 | axisCount = 0;
120 | }
121 |
122 | private void Poll()
123 | {
124 | try
125 | {
126 | // poll the joystick
127 | joystickDevice.Poll();
128 | // update the joystick state field
129 | state = joystickDevice.CurrentJoystickState;
130 | }
131 | catch (Exception err)
132 | {
133 | // we probably lost connection to the joystick
134 | // was it unplugged or locked by another application?
135 | Debug.WriteLine("Poll()");
136 | Debug.WriteLine(err.Message);
137 | Debug.WriteLine(err.StackTrace);
138 | }
139 | }
140 |
141 | ///
142 | /// Retrieves a list of joysticks attached to the computer.
143 | ///
144 | ///
145 | /// [C#]
146 | ///
147 | /// JoystickInterface.Joystick jst = new JoystickInterface.Joystick(this.Handle);
148 | /// string[] sticks = jst.FindJoysticks();
149 | ///
150 | ///
151 | /// A list of joysticks as an array of strings.
152 | public string[] FindJoysticks()
153 | {
154 | systemJoysticks = null;
155 |
156 | try
157 | {
158 | // Find all the GameControl devices that are attached.
159 | DeviceList gameControllerList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);
160 |
161 | // check that we have at least one device.
162 | if (gameControllerList.Count > 0)
163 | {
164 | systemJoysticks = new string[gameControllerList.Count];
165 | int i = 0;
166 | // loop through the devices.
167 | foreach (DeviceInstance deviceInstance in gameControllerList)
168 | {
169 | // create a device from this controller so we can retrieve info.
170 | joystickDevice = new Device(deviceInstance.InstanceGuid);
171 | joystickDevice.SetCooperativeLevel(hWnd,
172 | CooperativeLevelFlags.Background |
173 | CooperativeLevelFlags.NonExclusive);
174 |
175 | systemJoysticks[i] = joystickDevice.DeviceInformation.InstanceName;
176 |
177 | i++;
178 | }
179 | }
180 | }
181 | catch (Exception err)
182 | {
183 | Debug.WriteLine("FindJoysticks()");
184 | Debug.WriteLine(err.Message);
185 | Debug.WriteLine(err.StackTrace);
186 | }
187 |
188 | return systemJoysticks;
189 | }
190 |
191 | ///
192 | /// Acquire the named joystick. You can find this joystick through the method.
193 | ///
194 | /// Name of the joystick.
195 | /// The success of the connection.
196 | public bool AcquireJoystick(string name)
197 | {
198 | try
199 | {
200 | DeviceList gameControllerList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);
201 | int i = 0;
202 | bool found = false;
203 | // loop through the devices.
204 | foreach (DeviceInstance deviceInstance in gameControllerList)
205 | {
206 | if (deviceInstance.InstanceName == name)
207 | {
208 | found = true;
209 | // create a device from this controller so we can retrieve info.
210 | joystickDevice = new Device(deviceInstance.InstanceGuid);
211 | joystickDevice.SetCooperativeLevel(hWnd,
212 | CooperativeLevelFlags.Background |
213 | CooperativeLevelFlags.NonExclusive);
214 | break;
215 | }
216 |
217 | i++;
218 | }
219 |
220 | if (!found)
221 | return false;
222 |
223 | // Tell DirectX that this is a Joystick.
224 | joystickDevice.SetDataFormat(DeviceDataFormat.Joystick);
225 |
226 | // Finally, acquire the device.
227 | joystickDevice.Acquire();
228 |
229 | // How many axes?
230 | // Find the capabilities of the joystick
231 | DeviceCaps cps = joystickDevice.Caps;
232 | Debug.WriteLine("Joystick Axis: " + cps.NumberAxes);
233 | Debug.WriteLine("Joystick Buttons: " + cps.NumberButtons);
234 |
235 | axisCount = cps.NumberAxes;
236 | buttonCount = cps.NumberButtons;
237 |
238 | UpdateStatus();
239 | }
240 | catch (Exception err)
241 | {
242 | Debug.WriteLine("FindJoysticks()");
243 | Debug.WriteLine(err.Message);
244 | Debug.WriteLine(err.StackTrace);
245 | return false;
246 | }
247 |
248 | return true;
249 | }
250 |
251 | ///
252 | /// Unaquire a joystick releasing it back to the system.
253 | ///
254 | public void ReleaseJoystick()
255 | {
256 | joystickDevice.Unacquire();
257 | }
258 |
259 | ///
260 | /// Update the properties of button and axis positions.
261 | ///
262 | public void UpdateStatus()
263 | {
264 | Poll();
265 |
266 | int[] extraAxis = state.GetSlider();
267 | //Rz Rx X Y Axis1 Axis2
268 | axisA = state.Rz;
269 | axisB = state.Rx;
270 | axisC = state.X;
271 | axisD = state.Y;
272 | axisE = extraAxis[0];
273 | axisF = extraAxis[1];
274 |
275 | // not using buttons, so don't take the tiny amount of time it takes to get/parse
276 | byte[] jsButtons = state.GetButtons();
277 | buttons = new bool[jsButtons.Length];
278 |
279 | int i = 0;
280 | foreach (byte button in jsButtons)
281 | {
282 | buttons[i] = button >= 128;
283 | i++;
284 | }
285 | }
286 | }
287 | }
288 |
--------------------------------------------------------------------------------