public virtual void ObserveGcodeLine(GCodeLine line) { if (line.Type != LineType.GCode) { return; } double x = VertexPrevious.Position.x; double y = VertexPrevious.Position.y; GCodeUtil.TryFindParamNum(line.Parameters, "X", ref x); GCodeUtil.TryFindParamNum(line.Parameters, "Y", ref y); VertexCurrent.Position = new Vector3d(x, y, 0); double f = GCodeUtil.UnspecifiedValue; if (GCodeUtil.TryFindParamNum(line.Parameters, "F", ref f)) { VertexCurrent.FeedRate = f; } double extrusionAmount = GCodeUtil.UnspecifiedValue; bool featureActive = GCodeUtil.TryFindParamNum(line.Parameters, "E", ref extrusionAmount) && extrusionAmount > VertexPrevious.Extrusion.x && currentFeatureInfo != null; foreach (var s in endFeatureComments) { if (!string.IsNullOrWhiteSpace(line.Comment) && line.Comment.ToLower().Contains(s)) { featureActive = false; } } if (featureActive) { Vector2d average = new Segment2d(VertexCurrent.Position.xy, VertexPrevious.Position.xy).Center; double distance = VertexCurrent.Position.Distance(VertexPrevious.Position); double extrusion = extrusionAmount - VertexPrevious.Extrusion.x; currentFeatureInfo.Extrusion += extrusion; currentFeatureInfo.Distance += distance; currentFeatureInfo.BoundingBox.Contain(VertexPrevious.Position.xy); currentFeatureInfo.BoundingBox.Contain(VertexCurrent.Position.xy); currentFeatureInfo.UnweightedCenterOfMass += average * extrusion; currentFeatureInfo.Duration += distance / VertexCurrent.FeedRate; VertexCurrent.Extrusion = new Vector3d(extrusionAmount, 0, 0); } VertexPrevious = new PrintVertex(VertexCurrent); }
public void ObserveGcodeLine(GCodeLine line) { if (line.type != GCodeLine.LType.GCode) { return; } double x = VertexPrevious.Position.x; double y = VertexPrevious.Position.y; bool found_x = GCodeUtil.TryFindParamNum(line.parameters, "X", ref x); bool found_y = GCodeUtil.TryFindParamNum(line.parameters, "Y", ref y); if (!found_x || !found_y) { return; } VertexCurrent.Position = new Vector3d(x, y, 0); double f = GCodeUtil.UnspecifiedValue; if (GCodeUtil.TryFindParamNum(line.parameters, "F", ref f)) { VertexCurrent.FeedRate = f; } double extrusionAmount = GCodeUtil.UnspecifiedValue; if (GCodeUtil.TryFindParamNum(line.parameters, "E", ref extrusionAmount) && extrusionAmount >= VertexPrevious.Extrusion.x && currentFeatureInfo != null) { Vector2d average = new Segment2d(VertexCurrent.Position.xy, VertexPrevious.Position.xy).Center; double distance = VertexCurrent.Position.Distance(VertexPrevious.Position); double extrusion = extrusionAmount - VertexPrevious.Extrusion.x; currentFeatureInfo.Extrusion += extrusion; currentFeatureInfo.Distance += distance; currentFeatureInfo.BoundingBox.Contain(VertexCurrent.Position.xy); currentFeatureInfo.UnweightedCenterOfMass += average * extrusion; currentFeatureInfo.Duration += distance / VertexCurrent.FeedRate; VertexCurrent.Extrusion = new Vector3d(extrusionAmount, 0, 0); } VertexPrevious = new PrintVertex(VertexCurrent); }