コード例 #1
0
 public bool IsGcodeTypeShow(GcodeType type)
 {
     if (_showDic_types.ContainsKey(type))
     {
         return(_showDic_types[type]);
     }
     else
     {
         return(false);
     }
 }
コード例 #2
0
    public GcodeRenderBean(Vector3 vector3, float e, GcodeType type, int layerIndex)
    {
        this.vector3    = vector3;
        this.e          = e;
        this.layerIndex = layerIndex;

        if (e == 0)
        {
            this.type = GcodeType.Travel;
        }
        else
        {
            this.type = type;
        }
    }
コード例 #3
0
    /*************** public method ***************/
    //parse gcode file and simple layer list
    //if start succeed, return true; else return false
    public void StartParseGcodeFile(string path)
    {
        //1.reset
        _Layer_height  = 0.2f;
        _layerCount    = 0;
        _curType       = GcodeType.UNKNOWN;
        _curLayerIndex = int.MinValue;

        _curUnit       = Unit.Millimeter;
        _curCoordinate = Coordinate.Absolute;
        _curPosition   = Vector3.zero;

        _parseProgress = 0;

        _gcodeRenderPointList.Clear();

        _bounds_X = Vector2.zero;
        _bounds_Y = Vector2.zero;
        _bounds_Z = Vector2.zero;

        //2.parse
        string[] lineArray = File.ReadAllLines(path);

        Stopwatch sw = new Stopwatch();

        sw.Start();

        for (int i = 0; i < lineArray.Length; i++)
        {
            _parseProgress = ((float)i) / lineArray.Length;

            //";End GCode begin" means end of parsing gcode
            if (lineArray[i].Trim().StartsWith(";End GCode begin"))
            {
                break;
            }

            //parseLine: parse every line to layer, then add layers to layerList_origin
            parseLine(lineArray[i]);
        }

        _parseProgress = 1.0f;

        UnityEngine.Debug.Log("****************** Gcode File Parse Result ******************" + "\n");

        sw.Stop();
        UnityEngine.Debug.Log(string.Format("Parse Gcode File Cost : {0} ms" + "\n", sw.ElapsedMilliseconds));

        UnityEngine.Debug.Log("Gcode Render Point Count : " + _gcodeRenderPointList.Count + "\n");

        UnityEngine.Debug.Log("Layer Height : " + _Layer_height + "\n");

        UnityEngine.Debug.Log("Layer Count : " + _layerCount + "\n");

        int count = _gcodeRenderPointList.Count;

        UnityEngine.Debug.Log("Gcode Render Point count : " + count + "\n");

        if (count > 0)
        {
            UnityEngine.Debug.Log("Layer index min : " + _gcodeRenderPointList[0].layerIndex + "\n");

            UnityEngine.Debug.Log("Layer index max : " + _gcodeRenderPointList[_gcodeRenderPointList.Count - 1].layerIndex + "\n");
        }

        //		for (int i = 0; i < gcodePointList.Count; i++) {
        //			GcodePoint point = gcodePointList [i];
        //			UnityEngine.Debug.LogError (i+" " +point + "\n");
        //		}

        UnityEngine.Debug.Log("***************************************************" + "\n");
    }
コード例 #4
0
    /*************** private method ***************/
    private void parseLine(string line)
    {
        if (line.Trim().StartsWith(keyWord_TYPE))
        {
            string typeStr = line.Substring(keyWord_TYPE.Length);
            if (typeStr == "WALL-INNER")
            {
                _curType = GcodeType.WALL_INNER;
            }
            else if (typeStr == "WALL-OUTER")
            {
                _curType = GcodeType.WALL_OUTER;
            }
            else if (typeStr == "SKIN")
            {
                _curType = GcodeType.SKIN;
            }
            else if (typeStr == "SKIRT")
            {
                _curType = GcodeType.SKIRT;
            }
            else if (typeStr == "SUPPORT")
            {
                _curType = GcodeType.SUPPORT;
            }
            else if (typeStr == "FILL")
            {
                _curType = GcodeType.FILL;
            }
            else
            {
                _curType = GcodeType.UNKNOWN;
                UnityEngine.Debug.LogWarning("Unknown Gcode type" + "\n");
            }
            return;
        }
        else if (line.Trim().StartsWith(keyWord_LAYER))
        {
            ++_layerCount;
            _curLayerIndex = int.Parse(line.Substring(keyWord_LAYER.Length));
            return;
        }
        else if (line.Trim().StartsWith(keyWord_Layer_height))
        {
            _Layer_height = float.Parse(line.Substring(keyWord_Layer_height.Length));
            return;
        }

        //Remove comments (if any)
        char[] charArray = line.Split(';')[0].Trim().ToCharArray();
        if (charArray.Length < 3)
        {
            return;
        }

        if (charArray[0] == 'G')
        {
            if (charArray[1] == '0')
            {
                //G0
                parseG0G1(charArray);
            }
            else if (charArray[1] == '1' && charArray[2] == ' ')
            {
                //G1
                parseG0G1(charArray);
            }
            else if (charArray[1] == '2' && charArray[2] == '0')
            {
                //G20
                //unit is inch
                _curUnit = Unit.Inch;
            }
            else if (charArray[1] == '2' && charArray[2] == '1')
            {
                //G21
                //unit is millimeter
                _curUnit = Unit.Millimeter;
            }
            else if (charArray[1] == '2' && charArray[2] == '8')
            {
                //G28
                //Auto home
                _curPosition = Vector3.zero;
            }
            else if (charArray[1] == '9' && charArray[2] == '0')
            {
                //G90
                _curCoordinate = Coordinate.Absolute;
            }
            else if (charArray[1] == '9' && charArray[2] == '1')
            {
                //G91
                _curCoordinate = Coordinate.Relative;
            }
            else if (charArray[1] == '9' && charArray[2] == '2')
            {
                //G92
                //todo G92: set coordinate zero point
            }
        }
    }