private void SetInitalLayer()
        {
            activeLayerIndex = 0;
            if (LoadedGCode.LineCount > 0)
            {
                int     firstExtrusionIndex = 0;
                Vector3 lastPosition        = LoadedGCode.Instruction(0).Position;
                double  ePosition           = LoadedGCode.Instruction(0).EPosition;
                // let's find the first layer that has extrusion if possible and go to that
                for (int i = 1; i < LoadedGCode.LineCount; i++)
                {
                    PrinterMachineInstruction currentInstruction = LoadedGCode.Instruction(i);
                    if (currentInstruction.EPosition > ePosition && lastPosition != currentInstruction.Position)
                    {
                        firstExtrusionIndex = i;
                        break;
                    }

                    lastPosition = currentInstruction.Position;
                }

                if (firstExtrusionIndex > 0)
                {
                    for (int layerIndex = 0; layerIndex < LoadedGCode.NumChangesInZ; layerIndex++)
                    {
                        if (firstExtrusionIndex < LoadedGCode.GetInstructionIndexAtLayer(layerIndex))
                        {
                            activeLayerIndex = Math.Max(0, layerIndex - 1);
                            break;
                        }
                    }
                }
            }
        }
        public void CenterPartInView()
        {
            RectangleDouble partBounds     = LoadedGCode.GetBounds();
            Vector2         weightedCenter = LoadedGCode.GetWeightedCenter();

            unscaledRenderOffset = -weightedCenter;
            layerScale           = Math.Min(Height / partBounds.Height, Width / partBounds.Width);

            Invalidate();
        }