Example #1
0
		private PathStorage CombinePaths(IVertexSource a, IVertexSource b, ClipType clipType)
		{
			List<List<IntPoint>> aPolys = CreatePolygons(a);
			List<List<IntPoint>> bPolys = CreatePolygons(b);

			Clipper clipper = new Clipper();

			clipper.AddPaths(aPolys, PolyType.ptSubject, true);
			clipper.AddPaths(bPolys, PolyType.ptClip, true);

			List<List<IntPoint>> intersectedPolys = new List<List<IntPoint>>();
			clipper.Execute(clipType, intersectedPolys);

			PathStorage output = new PathStorage();

			foreach (List<IntPoint> polygon in intersectedPolys)
			{
				bool first = true;
				foreach (IntPoint point in polygon)
				{
					if (first)
					{
						output.Add(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandMoveTo);
						first = false;
					}
					else
					{
						output.Add(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandLineTo);
					}
				}

				output.ClosePolygon();
			}

			output.Add(0, 0, ShapePath.FlagsAndCommand.CommandStop);

			return output;
		}
Example #2
0
		public static PathStorage PolygonToPathStorage(Polygon polygon)
		{
			PathStorage output = new PathStorage();

			bool first = true;
			foreach (IntPoint point in polygon)
			{
				if (first)
				{
					output.Add(point.X, point.Y, ShapePath.FlagsAndCommand.CommandMoveTo);
					first = false;
				}
				else
				{
					output.Add(point.X, point.Y, ShapePath.FlagsAndCommand.CommandLineTo);
				}
			}

			output.ClosePolygon();

			output.Add(0, 0, ShapePath.FlagsAndCommand.CommandStop);

			return output;
		}
		public static PathStorage CreatePathStorage(List<List<IntPoint>> intersectedPolys, double scaling = 1000)
		{
			PathStorage output = new PathStorage();

			foreach (List<IntPoint> polygon in intersectedPolys)
			{
				bool first = true;
				foreach (IntPoint point in polygon)
				{
					if (first)
					{
						output.Add(point.X / scaling, point.Y / scaling, ShapePath.FlagsAndCommand.CommandMoveTo);
						first = false;
					}
					else
					{
						output.Add(point.X / scaling, point.Y / scaling, ShapePath.FlagsAndCommand.CommandLineTo);
					}
				}

				output.ClosePolygon();
			}
			return output;
		}
Example #4
0
        public static void Load(PathStorage vertexSource, string pathAndFileName)
        {
            vertexSource.remove_all();
            string[] allLines = File.ReadAllLines(pathAndFileName);
            foreach (string line in allLines)
            {
                string[] elements = line.Split(',');
                double x = double.Parse(elements[0]);
                double y = double.Parse(elements[1]);
                ShapePath.FlagsAndCommand flagsAndCommand = (ShapePath.FlagsAndCommand)System.Enum.Parse(typeof(ShapePath.FlagsAndCommand), elements[2].Trim());
                for (int i = 3; i < elements.Length; i++)
                {
                    flagsAndCommand |= (ShapePath.FlagsAndCommand)System.Enum.Parse(typeof(ShapePath.FlagsAndCommand), elements[i].Trim());
                }

                vertexSource.Add(x, y, flagsAndCommand);
            }
        }
Example #5
0
        public static void Load(PathStorage vertexSource, string pathAndFileName)
        {
            vertexSource.remove_all();
            string[] allLines = File.ReadAllLines(pathAndFileName);
            foreach (string line in allLines)
            {
                string[] elements = line.Split(',');
                double   x        = double.Parse(elements[0]);
                double   y        = double.Parse(elements[1]);
                ShapePath.FlagsAndCommand flagsAndCommand = (ShapePath.FlagsAndCommand)System.Enum.Parse(typeof(ShapePath.FlagsAndCommand), elements[2].Trim());
                for (int i = 3; i < elements.Length; i++)
                {
                    flagsAndCommand |= (ShapePath.FlagsAndCommand)System.Enum.Parse(typeof(ShapePath.FlagsAndCommand), elements[i].Trim());
                }

                vertexSource.Add(x, y, flagsAndCommand);
            }
        }
Example #6
0
        public override void Render(Graphics2D graphics2D, Affine transform, double layerScale, RenderType renderType)
        {
            if ((renderType & RenderType.Extrusions) == RenderType.Extrusions)
            {
                double extrusionLineWidths = 0.2 * layerScale;
                RGBA_Bytes extrusionColor = RGBA_Bytes.Black;
                //extrusionColor = color;

                PathStorage pathStorage = new PathStorage();
                VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, transform);
                Stroke stroke = new Stroke(transformedPathStorage, extrusionLineWidths);

                stroke.line_cap(LineCap.Round);
                stroke.line_join(LineJoin.Round);

                pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.CommandMoveTo);
                pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);

                graphics2D.Render(stroke, 0, extrusionColor);
            }
        }
Example #7
0
        public override void Render(Graphics2D graphics2D, Affine transform, double layerScale, RenderType renderType)
        {
            if ((renderType & RenderType.Moves) == RenderType.Moves)
            {
                double movementLineWidth = 0.35 * layerScale;
                RGBA_Bytes movementColor = new RGBA_Bytes(10, 190, 15);

                PathStorage pathStorage = new PathStorage();
                VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, transform);
                Stroke stroke = new Stroke(transformedPathStorage, movementLineWidth);

                stroke.line_cap(LineCap.Round);
                stroke.line_join(LineJoin.Round);

                pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.CommandMoveTo);
                if (end.x != start.x || end.y != start.y)
                {
                    pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
                }
                else
                {
                    pathStorage.Add(end.x + .01, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
                }
                graphics2D.Render(stroke, 0, movementColor);
            }
        }
		public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
		{
			if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
			{
				double movementLineWidth = 0.35 * renderInfo.LayerScale;
				RGBA_Bytes movementColor = new RGBA_Bytes(10, 190, 15);

				PathStorage pathStorage = new PathStorage();
				VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
				Stroke stroke = new Stroke(transformedPathStorage, movementLineWidth);

				stroke.line_cap(LineCap.Round);
				stroke.line_join(LineJoin.Round);

				Vector3Float start = this.GetStart(renderInfo);
				Vector3Float end = this.GetEnd(renderInfo);

				pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.CommandMoveTo);
				if (end.x != start.x || end.y != start.y)
				{
					pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
				}
				else
				{
					pathStorage.Add(end.x + .01, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
				}
				graphics2D.Render(stroke, 0, movementColor);
			}
		}
		public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
		{
			if (renderInfo.CurrentRenderType.HasFlag(RenderType.Extrusions))
			{
				double extrusionLineWidths = GetExtrusionWidth(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale;

				RGBA_Bytes extrusionColor = RGBA_Bytes.Black;
				if (extruderIndex > 0)
				{
					extrusionColor = MeshViewerWidget.GetMaterialColor(extruderIndex + 1);
				}
				if (renderInfo.CurrentRenderType.HasFlag(RenderType.SpeedColors))
				{
					extrusionColor = color;
				}

                if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion))
                {
                    extrusionColor = new RGBA_Bytes(extrusionColor, 200);
                }

                // render the part using opengl
                Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
				if (graphics2DGl != null)
				{
					Vector3Float startF = this.GetStart(renderInfo);
					Vector3Float endF = this.GetEnd(renderInfo);
					Vector2 start = new Vector2(startF.x, startF.y);
					renderInfo.Transform.transform(ref start);

					Vector2 end = new Vector2(endF.x, endF.y);
					renderInfo.Transform.transform(ref end);

					graphics2DGl.DrawAALineRounded(start, end, extrusionLineWidths/2, extrusionColor);
				}
				else
				{
					PathStorage pathStorage = new PathStorage();
					VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
					Stroke stroke = new Stroke(transformedPathStorage, extrusionLineWidths/2);

					stroke.line_cap(LineCap.Round);
					stroke.line_join(LineJoin.Round);

					Vector3Float start = this.GetStart(renderInfo);
					Vector3Float end = this.GetEnd(renderInfo);

					pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.CommandMoveTo);
					pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);

					graphics2D.Render(stroke, 0, extrusionColor);
				}
			}
		}
		public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
		{
			if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions)
			{
				double extrusionLineWidths = GetRadius(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale;

				RGBA_Bytes extrusionColor = RGBA_Bytes.Black;
				if (extruderIndex > 0)
				{
					extrusionColor = MeshViewerWidget.GetMaterialColor(extruderIndex + 1);
				}
				if ((renderInfo.CurrentRenderType & RenderType.SpeedColors) == RenderType.SpeedColors)
				{
					extrusionColor = color;
				}

				PathStorage pathStorage = new PathStorage();
				VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
				Stroke stroke = new Stroke(transformedPathStorage, extrusionLineWidths);

				stroke.line_cap(LineCap.Round);
				stroke.line_join(LineJoin.Round);

				Vector3Float start = this.GetStart(renderInfo);
				Vector3Float end = this.GetEnd(renderInfo);

				pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.CommandMoveTo);
				pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);

				graphics2D.Render(stroke, 0, extrusionColor);
			}
		}
		public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo)
		{
			if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves)
			{
				double movementLineWidth = 0.35 * renderInfo.LayerScale;
				RGBA_Bytes movementColor = new RGBA_Bytes(10, 190, 15);

				// render the part using opengl
				Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL;
				if (graphics2DGl != null)
				{
					Vector3Float startF = this.GetStart(renderInfo);
					Vector3Float endF = this.GetEnd(renderInfo);
					Vector2 start = new Vector2(startF.x, startF.y);
					renderInfo.Transform.transform(ref start);

					Vector2 end = new Vector2(endF.x, endF.y);
					renderInfo.Transform.transform(ref end);

					graphics2DGl.DrawAALineRounded(start, end, movementLineWidth, movementColor);
				}
				else
				{
					PathStorage pathStorage = new PathStorage();
					VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform);
					Stroke stroke = new Stroke(transformedPathStorage, movementLineWidth);

					stroke.line_cap(LineCap.Round);
					stroke.line_join(LineJoin.Round);

					Vector3Float start = this.GetStart(renderInfo);
					Vector3Float end = this.GetEnd(renderInfo);

					pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.CommandMoveTo);
					if (end.x != start.x || end.y != start.y)
					{
						pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
					}
					else
					{
						pathStorage.Add(end.x + .01, end.y, ShapePath.FlagsAndCommand.CommandLineTo);
					}

					graphics2D.Render(stroke, 0, movementColor);
				}
			}
		}