Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MakerWare compatibility patch by Steve Weller

Here's a patch to Pleasant3D 2.0.1 that makes it compatible with G-Code created with
MakerWare.

MakerWare omits the 103 and 101 codes so everything ends up one color. The fix tracks the
value of the extruder progress and uses retractions as an indication of travel. It's
backward compatible with the old G-Code as well.
  • Loading branch information...
commit f78cf113842c51edfbafc153443affc186d88088 1 parent bcbee8d
@zaggo authored
Showing with 45 additions and 2 deletions.
  1. +45 −2 src/Classes/ParsedGCode.m
View
47 src/Classes/ParsedGCode.m
@@ -63,6 +63,8 @@ - (BOOL)isLayerStartWithCurrentLocation:(Vector3*)currentLocation oldZ:(float*)o
{
if([self scanString:@"(<layer>" intoString:nil])
isLayerStart = YES;
+ if([self scanString:@"(Slice" intoString:nil])
+ isLayerStart = YES;
}
else if([self scanString:@"G1" intoString:nil] ||
[self scanString:@"G2" intoString:nil] ||
@@ -110,7 +112,8 @@ - (id)initWithGCodeString:(NSString*)gcode;
extrusionWidth = 0.;
- BOOL isThereALayerStartWord=[gCodeLineScanners isThereAFirstWord:@"(<layer>"];
+ // MakerWare 1.1 uses Slice and has no <layer>
+ BOOL isThereALayerStartWord=[gCodeLineScanners isThereAFirstWord:@"(<layer>"] || [gCodeLineScanners isThereAFirstWord:@"(Slice"];
panes = [NSMutableArray array];
__block NSMutableArray* currentPane = nil;
@@ -120,6 +123,11 @@ - (id)initWithGCodeString:(NSString*)gcode;
__block Vector3* highCorner = [[Vector3 alloc] initVectorWithX:-FLT_MAX Y:-FLT_MAX Z:-FLT_MAX];
__block Vector3* lowCorner = [[Vector3 alloc] initVectorWithX:FLT_MAX Y:FLT_MAX Z:FLT_MAX];
__block float localExtrutionWidth = 0.;
+ __block float lastEValue = 0;
+ __block float eValue = 0;
+ __block BOOL extrusionOff = NO;
+ __block BOOL makerWareInUse = YES;
+
[gCodeLineScanners enumerateObjectsUsingBlock:^(id scanner, NSUInteger idx, BOOL *stop) {
NSScanner* lineScanner = (NSScanner*)scanner;
[lineScanner setScanLocation:0];
@@ -129,7 +137,40 @@ - (id)initWithGCodeString:(NSString*)gcode;
currentPane = [NSMutableArray array];
[panes addObject:currentPane];
}
- if([lineScanner scanString:@"G1" intoString:nil])
+ BOOL hasG1E = [lineScanner scanString:@"G1 E" intoString:nil];
+ BOOL hasSnort = [[lineScanner string] rangeOfString:@"(snort)"].length != 0;
+ BOOL hasSquirt = [[lineScanner string] rangeOfString:@"(squirt)"].length != 0;
+
+ if(makerWareInUse && (hasG1E || hasSnort || hasSquirt))
+ {
+ // Track E value for MakerWare 1.0 only
+ // Makerware does not insert 101 and 103s into the G-Code, so coloring fails
+ // G1 E with E smaller is a 103, next G1 E setting is a 101
+ if(hasG1E) {
+ [lineScanner scanFloat:&eValue];
+ if(eValue<lastEValue) {
+ [currentPane addObject:(id)_extrusionOffColor];
+ extrusionOff = YES;
+ } else if (extrusionOff) {
+ extrusionNumber++;
+ [currentPane addObject:[_extrusionColors objectAtIndex:extrusionNumber%[_extrusionColors count]]];
+ extrusionOff = NO;
+ }
+ lastEValue = eValue;
+ } else {
+ // For MakerWare 1.1 only
+ // Makerware does not insert 101 and 103s into the G-Code, so coloring fails
+ // Snort and squirt are used
+ if(hasSnort) {
+ [currentPane addObject:(id)_extrusionOffColor];
+ } else if(hasSquirt) {
+ extrusionNumber++;
+ [currentPane addObject:[_extrusionColors objectAtIndex:extrusionNumber%[_extrusionColors count]]];
+ }
+ }
+
+ }
+ else if([lineScanner scanString:@"G1" intoString:nil])
{
[lineScanner updateLocation:currentLocation];
[currentPane addObject:[[currentLocation copy] autorelease]];
@@ -138,11 +179,13 @@ - (id)initWithGCodeString:(NSString*)gcode;
}
else if([lineScanner scanString:@"M101" intoString:nil])
{
+ makerWareInUse = NO;
extrusionNumber++;
[currentPane addObject:[_extrusionColors objectAtIndex:extrusionNumber%[_extrusionColors count]]];
}
else if([lineScanner scanString:@"M103" intoString:nil])
{
+ makerWareInUse = NO;
[currentPane addObject:(id)_extrusionOffColor];
}
else if([lineScanner scanString:@"(<extrusionWidth>" intoString:nil])
Please sign in to comment.
Something went wrong with that request. Please try again.