Making progress, nearing an alpha release of the revamp of the code.
Migrated all the locations into a location manager so the code is much less cluttered with textbox related stuff and removed a lot of stuff from the properties.settings.
Also it now supports an unlimited number of arbitrary locations so the mark code is all gone
The location code is quite elegant and i'm happy with the way it looks aesthetically. This code will populate pull down menu items with one line functions to set or update the locations
Code: Select all
private void UpdateGoToPulldownMenu() {
goToLocationToolStripMenuItem.DropDownItems.Clear();
setLocationToolStripMenuItem.DropDownItems.Clear();
foreach (var name in Locations.GetNames()) {
var x = new ToolStripMenuItem(name);
var y = new ToolStripMenuItem(name);
x.Click += (s,e) => { Cnc.CNC_XY_m(Locations.GetLocation(s.ToString())); };
y.Click += (s, e) => { Locations.GetLocation(s.ToString()).SetTo(Cnc.XYLocation);};
y.BackColor = Color.Orange;
goToLocationToolStripMenuItem.DropDownItems.Add(x);
setLocationToolStripMenuItem.DropDownItems.Add(y);
}
}
and I've added event handles that trigger whenever anything changes so it synchronizes the pulldowns with the locations (in a table, databound) and saves using xml serialization on any change with just 3 lines of code
Code: Select all
//setup location jumps
UpdateGoToPulldownMenu();
Locations.GetList().ListChanged += delegate { UpdateGoToPulldownMenu(); }; //update if list changed
Locations.LocationChangeEvent += (s, e) => { if (e.PropertyName.Equals("Name")) UpdateGoToPulldownMenu(); Locations.Save(); }; //update if name on list changes
The xml serialization (once setup) is very simple way to synchronize data. For example, _locations is a type of list of locations. This is all the code you need to save it - and it works for any type of data structure.
Code: Select all
Global.Serialization(_locations, FileName);
As the componens and job data have been migrated in a similar way, once the job list is saved, it includes all the relevant component - so the job file will contain everything you need (no need for pick and place once thtat's setup).
The only issue/question I have is that I see no need for the job offset as the offset will be captured in the machine coordinates. I'm just going to remove support for that as well (the fewer lines of code, the easier it is to manage and extend it).
I need to finish integrating my vacuum pressure detection and figure out a way to mechanically align my new upcamera (the logitec one that was recommended). It's just taped into place now and I can't imagine that'll be accurate. Alternatively, I'm considering implementing something like this
http://www.pyimagesearch.com/2014/08/25 ... m-example/ to compensate for misalignment of the camera.