コード例 #1
0
ファイル: FormLibrary.cs プロジェクト: hebskjcc/OpenR8-1
        public void resetButton()
        {
            foreach (Button b in buttons)
            {
                b.Dispose();
            }
            buttons.Clear();
            buttonsLocationY = buttonStartY;

            //labels

            foreach (Label l in labels)
            {
                l.Dispose();
            }
            labels.Clear();

            //urls
            functionsURL.Clear();

            int           functionGroupNum = 0;
            int           functionNum      = 0;
            StringBuilder str  = new StringBuilder(R7.STRING_SIZE);
            StringBuilder str2 = new StringBuilder(R7.STRING_SIZE);

            functionGroupNum = R8.GetFunctionGroupNum();

            //20170124 leo: 加入 BrainVersion
            R7.GetVersion(str, R7.STRING_SIZE);
            //addLabel("version:" + str.ToString());
            buttonsLocationY += 5;

            for (int i = 0; i < functionGroupNum; i++)
            {
                R8.GetFunctionGroupName(str, R7.STRING_SIZE, i);
                addLabel(str.ToString());//GroupName
                functionNum = R8.GetFunctionNumInGroup(i);
                for (int j = 0; j < functionNum; j++)
                {
                    R8.GetFunctionName(str, R7.STRING_SIZE, i, j);
                    R8.GetFunctionDoc(str2, R7.STRING_SIZE, i, j);
                    //System.Console.WriteLine("getURL:" + str2);
                    if (isInSearchMode)
                    {
                        if (str.ToString().ToLower().Contains(textBoxSearch.Text.ToLower()))
                        {
                            addButton(str.ToString(), str2.ToString());
                        }
                    }
                    else
                    {
                        addButton(str.ToString(), str2.ToString());
                    }
                }
            }
            str.Clear();
            str2.Clear();
            this.Text = str_Libraries + "  " + buttons.Count + " of " + allFunctionCount;
            return;
        }
コード例 #2
0
ファイル: FormVariable.cs プロジェクト: hebskjcc/OpenR8-1
        private void FormVariable_Load(object sender, EventArgs e)
        {
            formMain = (FormMain)this.MdiParent;
            //comboBox1.DataSource = Enum.GetValues(typeof(Data.VariableType));
            //comboBox1.DataSource = R8.typeArray;
            int variableNum = R8.GetVariableNum();

            //MessageBox.Show("variableNum = " + variableNum);
            variableNum = R8.GetVariableNum();
            StringBuilder str = new StringBuilder(R7.STRING_SIZE);

            string[] typeArray;
            if (variableNum > 0)
            {
                typeArray = new string[variableNum];
                for (int i = 0; i < variableNum; i++)
                {
                    R8.GetVariableType(str, R7.STRING_SIZE, i);
                    typeArray[i] = str.ToString();
                    // MessageBox.Show("typeArray" + i + " = " + str);
                }
                comboBox1.DataSource = typeArray;
            }
            else
            {
                //如果沒讀到,用預設值
                comboBox1.DataSource = new string[] { "int", "bool", "float", "double", "string", "image", "json" };
            }

            //20170327 Variable 沒 SN ,不顯示視窗元件。
            if (variableSn == -1 || variableSn == 0)
            {
                comboBox1.Visible     = false;
                label1.Visible        = false;
                labelValue.Visible    = false;
                label3.Visible        = false;
                label4.Visible        = false;
                labelSn.Visible       = false;
                textBoxName.Visible   = false;
                label5.Visible        = false;
                textBoxRemark.Visible = false;
                buttonDelete.Visible  = false;
            }
            else
            {
                comboBox1.Visible     = true;
                label1.Visible        = true;
                labelValue.Visible    = true;
                label3.Visible        = true;
                label4.Visible        = true;
                labelSn.Visible       = true;
                textBoxName.Visible   = true;
                label5.Visible        = true;
                textBoxRemark.Visible = true;
                buttonDelete.Visible  = true;
            }

            str_Variable = R8.TranslationString(str_Variable);
            this.Text    = str_Variable;
        }
コード例 #3
0
ファイル: R8.cs プロジェクト: hebskjcc/OpenR8-1
        public R8 clone()
        {
            R8 newR8 = new R8();

            newR8.version         = this.version;
            newR8.functionSnCount = this.functionSnCount;
            newR8.variableSnCount = this.variableSnCount;
            newR8.functionSnMax   = this.functionSnMax;
            newR8.variableSnMax   = this.variableSnMax;

            // public Function[] functions = new Function[R7.FUNCTIONS_SIZE];
            // public Variable[] variables = new Variable[R7.VARIABLES_SIZE];

            for (int i = 0; i < this.getFunctionSnLast(); i++)
            {
                if (this.functions[i] != null)
                {
                    newR8.functions[i] = this.functions[i].clone();
                }
            }


            for (int i = 0; i < this.getVariableSnLast(); i++)
            {
                if (this.variables[i] != null)
                {
                    newR8.variables[i] = this.variables[i].clone();
                }
            }

            return(newR8);
        }
コード例 #4
0
ファイル: FormVariable.cs プロジェクト: hebskjcc/OpenR8-1
        //20170327 leo: 依今天信件增加 [選到 variable 時,自動 focus 到 Value] 功能。
        public void focusToValueBox()
        {
            //20170531 leo: 依信件指示改為[Edit 時,如果 variable name 是預設值,則 focus 到 Variable From Name ,如果 variable name 有改過,則 focus 到 Variable From Value ]
            if (variableSn != -1 && variableSn != 0)
            {
                StringBuilder str = new StringBuilder(R7.STRING_SIZE);
                R8.GetVariableType(str, R7.STRING_SIZE, FormMain.r8.variables[variableSn].type);

                if ((str.ToString() + variableSn.ToString()).Equals(FormMain.r8.variables[variableSn].name))
                {
                    textBoxName.Focus();
                }
                else if (valueComboBox != null)
                {
                    valueComboBox.Focus();
                }
                else if (valueNumericUpDown != null)
                {
                    valueNumericUpDown.Focus();
                }
                else if (valueTextBox != null)
                {
                    valueTextBox.Focus();
                }


                preVariableType = str.ToString();

                str.Clear();
            }



            return;
        }
コード例 #5
0
ファイル: R8.cs プロジェクト: hebskjcc/OpenR8-1
        public static string TranslationString_backup2(string key)
        {
            //銜接 json 版
            StringBuilder sb_key   = new StringBuilder(key);
            StringBuilder sb_value = new StringBuilder(R7.STRING_SIZE);
            int           res      = R8.TranslationString(sb_key, sb_value);

            MessageBox.Show("res = " + res + "key = " + sb_key.ToString() + " value = " + sb_value.ToString());

            //然後轉 UTF8
            //https://msdn.microsoft.com/zh-tw/library/system.text.encoding.utf8(v=vs.110).aspx
            //https://www.chilkatsoft.com/p/p_320.asp
            //Encoding enc = new UTF8Encoding(true, true);
            //System.Text.Encoding utf_8 = System.Text.Encoding.UTF8;
            byte[] byteArray = new byte[sb_value.Length * sizeof(char)];
            System.Buffer.BlockCopy(sb_value.ToString().ToCharArray(), 0, byteArray, 0, byteArray.Length);
            // string value = System.Text.Encoding.UTF8.GetString(byteArray);
            byte[] bytes        = Encoding.UTF8.GetBytes(sb_value.ToString());
            byte[] bytes_toUTF8 = Encoding.Convert(Encoding.UTF8, Encoding.Default, bytes);

            string value = Encoding.Default.GetString(bytes_toUTF8);

            // String returnValue = enc.GetString(sb_value.ToString());
            //enc.GetBytes(sb_value.ToString());
            //......轉起來中文一直變亂碼有時候還會開檔失敗- -....放棄使用 jansson 了,我直接手動轉
            return(value);
        }
コード例 #6
0
ファイル: FormVariables.cs プロジェクト: hebskjcc/OpenR8-1
        private void FormVariable_Load(object sender, EventArgs e)
        {
            formMain = (FormMain)this.MdiParent;
            FormVariables_SizeChanged(sender, e);

            str_Variables = R8.TranslationString(str_Variables);
            this.Text     = str_Variables;
        }
コード例 #7
0
        private void FormLog_Load(object sender, EventArgs e)
        {
            richTextBox1.Height = this.ClientSize.Height - 15;
            richTextBox1.Width  = this.ClientSize.Width - 15 - buttonClear.Width;
            formMain            = (FormMain)this.MdiParent;

            str_Log   = R8.TranslationString(str_Log);
            this.Text = str_Log;
        }
コード例 #8
0
        //20170929 leo: undo redo 用
        public void readProgramR8(R8 r8)
        {
            //清空畫面
            foreach (Button b in buttons)
            {
                b.Dispose();
            }
            buttons.Clear();
            buttonsLocationY = buttonStartY;

            //標籤也要清空
            foreach (Label l in lineLabels)
            {
                l.Dispose();
            }
            lineLabels.Clear();


            //20170322 leo: 增加[New File] 模式,清空 variable 後就 return
            if (r8 == null)
            {
                formMain.formVariables.showVariables(null);
                formMain.formFunction.showFunction(null);
                R8.clearLogBox();
                this.Text = Program_Functions + "  " + buttons.Count + " of " + FormMain.r8.getFunctionsCount();
                return;
            }
            Function        function     = null;
            List <Function> functionList = new List <Function>();

            //改為 sort 完依 posY 排序再放 button
            for (int i = 0; i < r8.getFunctionSnLast(); i++)
            {
                function = r8.functions[i];
                if (function == null)
                {
                    continue;
                }
                functionList.Add(function);
            }

            functionList.Sort(delegate(Function i1, Function i2) { return(i1.posY.CompareTo(i2.posY)); });
            for (int i = 0; i < functionList.Count; i++)
            {
                function = functionList.ElementAt(i);
                addButton(getFunctionShowText(function), function.sn, function.enable);
                function.posY = buttons.Count;//讀出 button 後,應該要再依實際 button 位置進行 posY排序
            }
            this.Text = Program_Functions + "  " + buttons.Count + " of " + FormMain.r8.getFunctionsCount();
            formMain.formVariables.showVariables(null);
            formMain.formFunction.showFunction(null);
            this.Invalidate();
            return;
        }
コード例 #9
0
ファイル: FormLibrary.cs プロジェクト: hebskjcc/OpenR8-1
        public FormLibrary()
        {
            panel2 = new R8.PanelNoScrollOnFocus();
            this.panel2.AutoScroll = true;
            this.panel2.Location   = new System.Drawing.Point(0, 50);
            this.panel2.Name       = "panel2";
            this.panel2.TabIndex   = 1;
            this.Controls.Add(this.panel2);
            InitializeComponent();

            str_Libraries = R8.TranslationString(str_Libraries);
            this.Text     = str_Libraries;
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: hebskjcc/OpenR8-1
        //然後這邊是把整個 R8 讀取出來
        public static R8 loadProgramFromRecord()
        {
            /*
             * if (true)
             * {
             *  MessageBox.Show("undoRedoNowAt at " + undoRedoNowAt);
             *  String str = "recordProgram\r\n";
             *  for (int j = 0; j < recordList.Count; j++)
             *  {
             *      str += "at " + j + "\r\n";
             *      str += "undoRedoNowAt = " + undoRedoNowAt + "\r\n";
             *      str += "recordList Size = " + recordList.Count + "\r\n";
             *      //str += "getFunctionSnLast = " + r8.getFunctionSnLast() + "\r\n";
             *      //str += "getVariableSnLast = " + r8.getVariableSnLast() + "\r\n";
             *      for (int i = 0; i < recordList[j].getFunctionSnLast(); i++)
             *      {
             *          if (recordList[j].functions[i] != null)
             *          {
             *              str += "function " + recordList[j].functions[i] + "\r\n";
             *          }
             *      }
             *      str += "\r\n";
             *  }
             *  MessageBox.Show(str);
             * }
             */
            R8 r8 = null;

            if (undoRedoNowAt >= 0 && undoRedoNowAt < recordList.Count)
            {
                //r8 = recordList.ElementAt(undoRedoNowAt).clone();
                r8 = recordList[undoRedoNowAt].clone();
            }
            else
            {
                if (FormMain.r8 != null)
                {
                    return(FormMain.r8.clone()); //如果沒有上一步的紀錄,回傳原本的 R8
                }
                else
                {
                    return(null);
                }
            }

            return(r8);
        }
コード例 #11
0
        public FormImage(int mode, Function function, FormFunction formFunction, int baseSn)
        {
            GC.Collect();
            this.mode         = mode;
            this.function     = function;
            this.formFunction = formFunction;
            this.baseSn       = baseSn;
            if (mode == 1)//mode1: imageCut
            {
                Rectangle rect =
                    new Rectangle(R8.stringToInt(FormMain.r8.variables[function.parameters.ElementAt(1).variableSn].value)
                                  , R8.stringToInt(FormMain.r8.variables[function.parameters.ElementAt(2).variableSn].value)
                                  , R8.stringToInt(FormMain.r8.variables[function.parameters.ElementAt(3).variableSn].value)
                                  , R8.stringToInt(FormMain.r8.variables[function.parameters.ElementAt(4).variableSn].value));
                SizeableArea sa = new SizeableArea(rect, Color.Blue);
                listSQ.Add(sa);
            }
            else if (mode == 2)  //mode2: 多個 rect
            {
                inputRectArrayString(FormMain.r8.variables[function.parameters.ElementAt(baseSn).variableSn].value);
            }
            InitializeComponent();
            if (mode != 0)
            {
                setToolStripMenuItem.Visible = true;
            }

            if (mode == 3 || mode == 4)
            {
                rotateValue                 = R8.stringToDouble(FormMain.r8.variables[function.parameters.ElementAt(baseSn).variableSn].value);
                labelRotate.Visible         = true;
                numericUpDownRotate.Visible = true;
                numericUpDownRotate.Value   = (decimal)rotateValue;

                if (mode == 4)
                {
                    Rectangle rect =
                        new Rectangle(R8.stringToInt(FormMain.r8.variables[function.parameters.ElementAt(baseSn + 1).variableSn].value)
                                      , R8.stringToInt(FormMain.r8.variables[function.parameters.ElementAt(baseSn + 2).variableSn].value)
                                      , R8.stringToInt(FormMain.r8.variables[function.parameters.ElementAt(baseSn + 3).variableSn].value)
                                      , R8.stringToInt(FormMain.r8.variables[function.parameters.ElementAt(baseSn + 4).variableSn].value));
                    SizeableArea sa = new SizeableArea(rect, Color.Blue);
                    listSQ.Add(sa);
                }
            }
        }
コード例 #12
0
ファイル: FormLibrary.cs プロジェクト: hebskjcc/OpenR8-1
        private void loadButtons()
        {
            allFunctionCount = 0;
            //addButton("OpenImage", "OpenImage");
            //addButton("SaveImage", "SaveImage");
            //addButton("DebugImage", "DebugImage");
            //addButton("Binarize", "Binarize");
            //20170123 leo : 改為從 function list 的 json 檔案 動態產生

            buttonsLocationY = buttonStartY;

            int           functionGroupNum = 0;
            int           functionNum      = 0;
            StringBuilder str  = new StringBuilder(R7.STRING_SIZE);
            StringBuilder str2 = new StringBuilder(R7.STRING_SIZE);

            functionGroupNum = R8.GetFunctionGroupNum();

            //20170124 leo: 加入 BrainVersion
            R7.GetVersion(str, R7.STRING_SIZE);
            //addLabel("version:" + str.ToString());
            buttonsLocationY += 5;

            functionURL.Clear();
            for (int i = 0; i < functionGroupNum; i++)
            {
                R8.GetFunctionGroupName(str, R7.STRING_SIZE, i);
                addLabel(str.ToString());//GroupName
                functionNum = R8.GetFunctionNumInGroup(i);
                for (int j = 0; j < functionNum; j++)
                {
                    allFunctionCount++;
                    R8.GetFunctionName(str, R7.STRING_SIZE, i, j);
                    R8.GetFunctionDoc(str2, R7.STRING_SIZE, i, j);
                    //System.Console.WriteLine("getURL:" + str2);
                    addButton(str.ToString(), str2.ToString());

                    //20170603 leo: 增加 "如果 function 有說明 URL ,在右方 function 小視窗中的右下方顯示 help 按鈕。"
                    //所以有url 連結的 name 要存起來
                    functionURL.Add(str.ToString(), str2.ToString());
                }
            }
            str.Clear();
            str2.Clear();
            return;
        }
コード例 #13
0
ファイル: R8.cs プロジェクト: hebskjcc/OpenR8-1
        public static int getVariableTypeByString(string type)
        {
            int           res         = 0;
            int           variableNum = R8.GetVariableNum();
            StringBuilder str         = new StringBuilder(R7.STRING_SIZE);

            for (int i = 0; i < variableNum; i++)
            {
                R8.GetVariableType(str, R7.STRING_SIZE, i);
                if (str.ToString().Equals(type))
                {
                    res = i;
                    break;
                }
            }
            str.Clear();
            return(res);
        }
コード例 #14
0
        private void FormFunctions_Load(object sender, EventArgs e)
        {
            formMain = (FormMain)this.MdiParent;
            //20170117 leo: 討論後移除 start

            /*
             * Function function = new Function("start", 0, 0);
             * formMain.r8.addFunction(function);
             * addVariableSn(function);
             * addButton("start", 0);
             */
            Program_Functions = R8.TranslationString(Program_Functions);

            this.Text = Program_Functions + "  0 of 0";

            FormFunctions_SizeChanged(sender, e);
            return;
        }
コード例 #15
0
 private void FormAbout_Load(object sender, EventArgs e)
 {
     //this.textBoxMac.Text = R8.MacAddress;
     str_AboutR8                   = R8.TranslationString(str_AboutR8);
     this.labelAboutR8.Text        = str_AboutR8;
     str_Copyright                 = R8.TranslationString(str_Copyright);
     this.labelAboutCopyright.Text = str_Copyright;
     str_Website                   = R8.TranslationString(str_Website);
     this.labelAboutWebsite.Text   = str_Website;
     str_Email = R8.TranslationString(str_Email);
     this.labelAboutEmail.Text = str_Email;
     str_label1       = R8.TranslationString(str_label1);
     this.label1.Text = str_label1;
     str_label2       = R8.TranslationString(str_label2);
     this.label2.Text = str_label2;
     str_label3       = R8.TranslationString(str_label3);
     this.label3.Text = str_label3;
     str_label4       = R8.TranslationString(str_label4);
     this.label4.Text = str_label4;
 }
コード例 #16
0
ファイル: FormVariables.cs プロジェクト: hebskjcc/OpenR8-1
        //20170327 Functions Variables 方塊不顯示 SN
        // Variables 的名稱顯示分散太多地方,把它都整合到這邊
        private string getVariableShowText(Variable variable)
        {
            string returnStr = "";

            if (variable.sn != -1 && variable.sn != 0)
            {
                StringBuilder str = new StringBuilder(R7.STRING_SIZE);
                R8.GetVariableType(str, R7.STRING_SIZE, variable.type);
                switch (str.ToString())
                {
                case "image":
                case "Image":
                case "mat":
                case "Mat":
                case "json":
                case "Json":
                case "object":
                case "Object":
                    returnStr = variable.name;
                    break;

                default:
                    if (variable.value == null || variable.value.Length == 0 || variable.value.Equals(""))
                    {
                        returnStr = variable.name;
                    }
                    else
                    {
                        returnStr = variable.name + " (" + variable.value + ")";
                    }
                    break;
                }
                str.Clear();
            }
            if (variable.remark.Length > 0)
            {
                returnStr += " (" + variable.remark + ")";
            }
            return(returnStr);
        }
コード例 #17
0
        public override string ToString()
        {
            //20170209 leo: 討論後, Mat 類型的不印 value

            /*
             * if (sn != -1)
             * {
             *  StringBuilder str = new StringBuilder(R7.STRING_SIZE);
             *  R8.GetVariableType(str, R7.STRING_SIZE, FormMain.r8.variables[sn].type);
             *  switch (str.ToString())
             *  {
             *      case "image":
             *      case "Image":
             *      case "mat":
             *      case "Mat":
             *      case "json":
             *      case "Json":
             *          return "[" + sn + "][" + name + "]";
             *          //break;
             *      default:
             *          break;
             *  }
             *  str.Clear();
             * }
             *      return "[" + sn + "][" + name + "][" + value + "]";
             */
            //20170309 leo: 依早上討論,顯示格式修改 sample path #1 [a2_sample3.png][remark]
            string returnStr = "";

            if (sn != -1 && sn != 0 && FormMain.r8.variables[sn] != null)
            {
                StringBuilder str = new StringBuilder(R7.STRING_SIZE);
                R8.GetVariableType(str, R7.STRING_SIZE, FormMain.r8.variables[sn].type);
                switch (str.ToString())
                {
                case "image":
                case "Image":
                case "mat":
                case "Mat":
                case "json":
                case "Json":
                case "object":
                case "Object":
                    //returnStr = name + " " + sn + " ";
                    returnStr = name;
                    break;

                default:
                    //returnStr = name + " " + sn + " " + "[" + value + "]";
                    if (value == null || value.Length == 0 || value.Equals(""))
                    {
                        returnStr = name;
                    }
                    else
                    {
                        returnStr = name + " (" + value + ")";
                    }
                    break;
                }
                str.Clear();
            }

            if (remark.Length > 0)
            {
                returnStr += " (" + remark + ")";
            }
            return(returnStr);
        }
コード例 #18
0
ファイル: Function.cs プロジェクト: hebskjcc/OpenR8-1
        //20170117 leo: 今天討論後, Function 預設裡面不塞 Data ,但[parameters 的格子] 留著
        //暫時開一個接 Parameters 的結構。以後這個應該會從 json 接。
        //20170123 leo : 改成從 json 接
        public static List <Parameter> getFunctionParameters(string name)
        {
            List <Parameter> args = new List <Parameter>();

            /*
             * switch (name)
             * {
             *  case "OpenImage":
             *      args.Add(new Parameter("Image File Name", R8.getDataTypeByString("string"), true));
             *      args.Add(new Parameter("Image ", R8.getDataTypeByString("image"), false));
             *      break;
             *  case "SaveImage":
             *      //arg1: (input, mat) image
             *      //arg2: (input, string) imagePath
             *      args.Add(new Parameter("Image", R8.getDataTypeByString("image"), true));
             *      args.Add(new Parameter("Image File Name", R8.getDataTypeByString("string"), true));
             *      break;
             *  case "Binarize":
             *      //cv::threshold(image, thresholdedImage, gv, 255, type);
             *
             *      args.Add(new Parameter("Input Image", R8.getDataTypeByString("image"), true));
             *      args.Add(new Parameter("Threshold", R8.getDataTypeByString("int"), true));
             *      //args.Add(new Parameter("thresholdType", Data.VariableType.Int, true));//對應 cv::threshold 的 type 參數
             *      args.Add(new Parameter("Output Image", R8.getDataTypeByString("image"), false));
             *      break;
             * }*/
            //20170123 leo : 改從 json 接
            int           functionGroupNum = 0;
            int           functionNum      = 0;
            int           variableNum      = 0;
            StringBuilder str = new StringBuilder(R7.STRING_SIZE);

            functionGroupNum = R8.GetFunctionGroupNum();
            string tempNameString;

            for (int i = 0; i < functionGroupNum; i++)
            {
                functionNum = R8.GetFunctionNumInGroup(i);
                for (int j = 0; j < functionNum; j++)
                {
                    R8.GetFunctionName(str, R7.STRING_SIZE, i, j);
                    //addButton(str.ToString());
                    if (str.ToString().Equals(name))
                    {
                        variableNum = R8.GetVariableNumInFunction(i, j);
                        for (int k = 0; k < variableNum; k++)
                        {
                            R8.GetVariableNameInFunction(str, R7.STRING_SIZE, i, j, k);
                            tempNameString = str.ToString();
                            R8.GetVariableTypeInFunction(str, R7.STRING_SIZE, i, j, k);
                            Parameter parameter = new Parameter(tempNameString, R8.getVariableTypeByString(str.ToString()));
                            //20170214 加入 Direction
                            //20171024 Direction 變成 Option
                            //option
                            R8.GetVariableOptionInFunction(str, R7.STRING_SIZE, i, j, k);
                            parameter.option = str.ToString();
                            args.Add(parameter);

                            //GetVariableDirectionInFunction
                        }
                    }
                }
            }
            str.Clear();
            return(args);
        }
コード例 #19
0
 private void buttonClear_Click(object sender, EventArgs e)
 {
     R8.clearLogBox();
 }
コード例 #20
0
ファイル: R8.cs プロジェクト: hebskjcc/OpenR8-1
        public R8(XElement xml)
        {
            XElement element = xml.Element("functionSnCount");
            //20170626 leo:加入舊版支援
            bool isOldVerson = false;

            if (element == null)
            {
                //此時判定為舊版
                isOldVerson = true;
                element     = xml.Element("intentSnCount");
                if (!Int32.TryParse(element.Value, out functionSnCount))
                {
                    functionSnCount = 0;
                }

                element = xml.Element("dataSnCount");
                if (!Int32.TryParse(element.Value, out variableSnCount))
                {
                    variableSnCount = 0;
                }

                element = xml.Element("intentSnMax");
                if (!Int32.TryParse(element.Value, out functionSnMax))
                {
                    functionSnMax = 0;
                }

                element = xml.Element("dataSnMax");
                if (!Int32.TryParse(element.Value, out variableSnMax))
                {
                    variableSnMax = 0;
                }
            }
            else
            {
                if (!Int32.TryParse(element.Value, out functionSnCount))
                {
                    functionSnCount = 0;
                }

                element = xml.Element("variableSnCount");
                if (!Int32.TryParse(element.Value, out variableSnCount))
                {
                    variableSnCount = 0;
                }

                element = xml.Element("functionSnMax");
                if (!Int32.TryParse(element.Value, out functionSnMax))
                {
                    functionSnMax = 0;
                }

                element = xml.Element("variableSnMax");
                if (!Int32.TryParse(element.Value, out variableSnMax))
                {
                    variableSnMax = 0;
                }
            }

            element = xml.Element("version");
            version = element.Value.ToString();


            int res;
            IEnumerable <XElement> variableElements;// = xml.Element("variables").Elements("variable");

            if (isOldVerson)
            {
                variableElements = xml.Element("datas").Elements("data");
            }
            else
            {
                variableElements = xml.Element("variables").Elements("variable");
            }
            Variable      variable;
            string        tempTypeString;
            int           variableNum = R8.GetVariableNum();
            StringBuilder str         = new StringBuilder(R7.STRING_SIZE);
            int           tempInt     = -1;

            for (int i = 0; i < variableElements.Count(); i++)
            {
                variable = new Variable();
                element  = variableElements.ElementAt(i);
                if (!Int32.TryParse(element.Element("sn").Value, out res))
                {
                    res = -1;
                }
                variable.sn = res;

                /*
                 * if (!Int32.TryParse(element.Element("type").Value, out res))
                 * {
                 *  res = -1;
                 * }
                 */

                tempTypeString = element.Element("type").Value;
                tempInt        = -1;
                for (int j = 0; j < variableNum; j++)
                {
                    R8.GetVariableType(str, R7.STRING_SIZE, j);
                    //統一轉小寫再比
                    if (str.ToString().ToLower().Equals(tempTypeString.ToLower()))
                    {
                        tempInt = j;
                        break;
                    }
                }
                //System.Console.WriteLine("type: " + tempTypeString + "  value:" + tempInt);
                if (tempInt != -1)
                {
                    variable.type = tempInt;
                }
                //Variable.VariableType.String;
                variable.value         = element.Element("value").Value;
                variable.name          = element.Element("name").Value;
                variable.remark        = element.Element("remark").Value;
                variables[variable.sn] = variable;
            }
            str.Clear();

            IEnumerable <XElement> functionElements;// = xml.Element("functions").Elements("function");

            if (isOldVerson)
            {
                functionElements = xml.Element("intents").Elements("intent");
            }
            else
            {
                functionElements = xml.Element("functions").Elements("function");
            }
            IEnumerable <XElement> variableSnElements = null;
            XElement subElement;
            Function function;

            for (int i = 0; i < functionElements.Count(); i++)
            {
                function = new Function();
                element  = functionElements.ElementAt(i);
                if (!Int32.TryParse(element.Element("sn").Value, out res))
                {
                    res = -1;
                }
                function.sn         = res;
                function.name       = element.Element("name").Value;
                function.remark     = element.Element("remark").Value;
                function.parameters = Function.getFunctionParameters(function.name);

                if (element.Element("enable") != null)
                {
                    if (element.Element("enable").Value.Equals("0"))
                    {
                        function.enable = false;
                    }
                    else
                    {
                        function.enable = true;
                    }
                }
                else
                {
                    function.enable = true;
                }

                if (R8.HAS_POS)
                {
                    if (!Int32.TryParse(element.Element("posX").Value, out res))
                    {
                        res = -1;
                    }
                    function.rectangle.X = res;
                    if (!Int32.TryParse(element.Element("posY").Value, out res))
                    {
                        res = -1;
                    }
                    function.rectangle.Y = res;
                }
                else
                {
                    function.rectangle.X = 0;
                    function.rectangle.Y = function.sn * 60;
                    //20170118 leo 新的 posY
                    if (!Int32.TryParse(element.Element("posY").Value, out res))
                    {
                        res = 0;
                    }
                    function.posY = res;
                }
                functions[function.sn] = function;

                //variableSn 不分 input/ output 了,由 Function.Parameter 定義 (以後要從 json 撈)
                if (isOldVerson)
                {
                    variableSnElements = element.Elements("dataSn");
                }
                else
                {
                    variableSnElements = element.Elements("variableSn");
                }
                int j = 0;
                //20170407 leo add: 就算 supportList 沒找到目標 function name,也把 parameters variable 補齊,避免 user 開不同版本運行後, program 壞掉。
                if (variableSnElements.Count() != function.parameters.Count && function.parameters.Count == 0)
                {
                    //MessageBox.Show("Warning: function [" + function.name + "] may not in support list.");

                    for (j = 0; j < variableSnElements.Count(); j++)
                    {
                        subElement = variableSnElements.ElementAt(j);
                        if (!Int32.TryParse(subElement.Value, out res))
                        {
                            res = -1;
                        }

                        int type = 0;
                        if (res != -1)
                        {
                            //parameter 名稱遺失了,但 variable 的 type 還是會有
                            //type = variables[res].type;
                            if (variables[res] != null)
                            {
                                type = variables[res].type;
                            }
                        }

                        Function.Parameter parameter = new Function.Parameter("unload", type);
                        parameter.option     = "IN";
                        parameter.variableSn = res;
                        function.parameters.Add(parameter);
                        // MessageBox.Show("Adding: " + parameter.name + " " + parameter.type);
                    }
                }
                //20170817 leo: 發現當版本不同時,如果同一個 function 名稱,新版的參數比舊版多,
                //然後用舊版 R8 開啟 .r6 檔案時,這邊會 error 。
                //修正:
                else if (variableSnElements.Count() != function.parameters.Count)
                {
                    for (j = 0; j < variableSnElements.Count() && j < function.parameters.Count; j++)
                    {
                        subElement = variableSnElements.ElementAt(j);
                        if (!Int32.TryParse(subElement.Value, out res))
                        {
                            res = -1;
                        }
                        function.parameters.ElementAt(j).variableSn = res;
                    }

                    for (j = function.parameters.Count; j < variableSnElements.Count(); j++)
                    {
                        subElement = variableSnElements.ElementAt(j);
                        if (!Int32.TryParse(subElement.Value, out res))
                        {
                            res = -1;
                        }

                        int type = 0;
                        if (res != -1)
                        {
                            //parameter 名稱遺失了,但 variable 的 type 還是會有
                            //type = variables[res].type;
                            if (variables[res] != null)
                            {
                                type = variables[res].type;
                            }
                        }

                        Function.Parameter parameter = new Function.Parameter("unload", type);
                        parameter.option     = "IN";
                        parameter.variableSn = res;
                        function.parameters.Add(parameter);
                        // MessageBox.Show("Adding: " + parameter.name + " " + parameter.type);
                    }
                }
                else
                {
                    //for (int j = 0; j < variableSnElements.Count() && j < function.parameters.Count; j++)
                    for (j = 0; j < variableSnElements.Count(); j++)
                    {
                        subElement = variableSnElements.ElementAt(j);
                        if (!Int32.TryParse(subElement.Value, out res))
                        {
                            res = -1;
                        }
                        function.parameters.ElementAt(j).variableSn = res;
                    }
                }

                //Console.WriteLine("sn = " + function.sn);
                //Console.WriteLine("name = " + function.name);
            }

            // Console.WriteLine("functionSnCount = " + functionSnCount);
        }
コード例 #21
0
        private int inputRectArrayString(string str)
        {
            if (str == null || str.Length < 2)   //json array 至少會有前後刮符,至少有2個字元
            {
                return(-1);
            }

            /*
             * [
             * {"x": "725", "y": "15", "width": "110", "height": "110"},
             * {"x": "20", "y": "25", "width": "110", "height": "110"},
             * {"x": "732", "y": "485", "width": "110", "height": "110"},
             * {"x": "25", "y": "490", "width": "110", "height": "110"}
             * ]
             */
            //MessageBox.Show(str);
            //Rectangle rect = new Rectangle();
            //string 避免 user 亂填導致 error , try catch 一下
            try
            {
                int start = str.IndexOf("{");
                if (start == -1)
                {
                    return(-2);
                }
                int      end       = str.IndexOf("}");
                string   targetStr = str.Substring(start, end - start);
                string[] rectStrings;
                string   objectString;
                int      subStart, subEnd;
                string   key, value;
                while (start != -1)
                {
                    end       = str.IndexOf("}", start + 1);
                    targetStr = str.Substring(start, end - start + 1);
                    //MessageBox.Show(targetStr);
                    start       = str.IndexOf("{", start + 1);
                    rectStrings = targetStr.Split(',');
                    Rectangle rect = new Rectangle(0, 0, 10, 10);
                    for (int i = 0; i < rectStrings.Length; i++)
                    {
                        objectString = rectStrings[i];
                        //每個 objectString 裡面會有4個 " 符號
                        subStart = objectString.IndexOf("\"");
                        subEnd   = objectString.IndexOf("\"", subStart + 1);
                        //冒號本身不抓所以要去頭去尾
                        key = objectString.Substring(subStart + 1, subEnd - subStart - 1);

                        subStart = objectString.IndexOf("\"", subEnd + 1);
                        subEnd   = objectString.IndexOf("\"", subStart + 1);
                        value    = objectString.Substring(subStart + 1, subEnd - subStart - 1);
                        //MessageBox.Show("key = " + key + " value = " + value);
                        switch (key)
                        {
                        case "x":
                            rect.X = R8.stringToInt(value);
                            break;

                        case "y":
                            rect.Y = R8.stringToInt(value);
                            break;

                        case "width":
                            rect.Width = R8.stringToInt(value);
                            break;

                        case "height":
                            rect.Height = R8.stringToInt(value);
                            break;
                        }
                    }
                    SizeableArea sa = new SizeableArea(rect, Color.Blue);
                    listSQ.Add(sa);
                }
            } catch (Exception e) {
                MessageBox.Show("Decode rect array string error, target string may be not a rect array." + e.ToString());
            }

            return(1);
        }
コード例 #22
0
ファイル: Program.cs プロジェクト: hebskjcc/OpenR8-1
        //20170929 leo: undo 與 redo 用,整個 R8 記錄下來
        public static void recordProgram(R8 r8, ToolStripMenuItem undoButton, ToolStripMenuItem redoButton)
        {
            /*
             * for (int i = recordList.Count - 1; i > undoRedoNowAt + 1; i--) {
             *  recordList.RemoveAt(i);
             * }
             */

            if (recordList.Count > 0)
            {
                for (int i = undoRedoNowAt - 1; i >= 0; i--)
                {
                    //MessageBox.Show("RemoveAt " + i);
                    recordList.RemoveAt(i);
                }
                undoRedoNowAt = 0;
            }


            recordList.Insert(undoRedoNowAt, r8.clone());

            if (recordList.Count > recordListMaxSize)
            {
                recordList.RemoveAt(recordList.Count - 1);
            }
            Program.undoRedoButtonSetEnableOrDisable(undoButton, redoButton);

            isFileChange = true;
            //MessageBox.Show("isFileChange = true");

            /*
             * if (false)
             * {
             *  String str = "recordProgram\r\n";
             *  for (int j = 0; j < recordList.Count; j++)
             *  {
             *      str += "at " + j + "\r\n";
             *      str += "undoRedoNowAt = " + undoRedoNowAt + "\r\n";
             *      str += "recordList Size = " + recordList.Count + "\r\n";
             *      //str += "getFunctionSnLast = " + r8.getFunctionSnLast() + "\r\n";
             *      //str += "getVariableSnLast = " + r8.getVariableSnLast() + "\r\n";
             *      for (int i = 0; i < recordList[j].getFunctionSnLast(); i++)
             *      {
             *          if (recordList[j].functions[i] != null)
             *          {
             *              str += "function " + recordList[j].functions[i] + "\r\n";
             *          }
             *      }
             *      str += "===\r\n";
             *      for (int i = 0; i < recordList[j].getVariableSnLast(); i++)
             *      {
             *          if (recordList[j].variables[i] != null)
             *          {
             *              str += "variables " + recordList[j].variables[i] + "\r\n";
             *          }
             *      }
             *      str += "\r\n";
             *  }
             *  MessageBox.Show(str);
             * }
             */

            /*
             * if (false)
             * {
             *  String str = "recordProgram\r\n";
             *
             *  str += "undoRedoNowAt = " + undoRedoNowAt + "\r\n";
             *  str += "recordList Size = " + recordList.Count + "\r\n";
             *  //str += "getFunctionSnLast = " + r8.getFunctionSnLast() + "\r\n";
             *  //str += "getVariableSnLast = " + r8.getVariableSnLast() + "\r\n";
             *  for (int i = 0; i < r8.getFunctionSnLast(); i++)
             *  {
             *      if (r8.functions[i] != null)
             *      {
             *          str += "function " + r8.functions[i] + "\r\n";
             *      }
             *  }
             *  str += "===\r\n";
             *  for (int i = 0; i < r8.getVariableSnLast(); i++)
             *  {
             *      if (r8.variables[i] != null)
             *      {
             *          str += "variables " + r8.variables[i] + "\r\n";
             *      }
             *  }
             *  str += "\r\n";
             *
             *  MessageBox.Show(str);
             * }
             */

            return;
        }
コード例 #23
0
ファイル: R8.cs プロジェクト: hebskjcc/OpenR8-1
        public static void writeProgramXml(string path)
        {
            XElement xml = new XElement("program");

            //根據 http://stackoverflow.com/questions/27548227/add-new-xelements-with-new-line-in-xdocument-with-preservewhitespace-loadoptions
            //換行需要自己加...
            xml.Add(Environment.NewLine);
            xml.Add(new XElement("version", FormMain.r8.getVersion()));
            xml.Add(Environment.NewLine);
            //xml.Add(new XElement("workSpacePath", FormMain.workSpacePath));//20170120 leo: 寫檔時,應該也把 workSpacePath 寫進去
            //xml.Add(Environment.NewLine);//20170306 leo: 改為不寫入 workSpacePath
            xml.Add(new XElement("functionSnMax", FormMain.r8.getFunctionSnMax()));
            xml.Add(Environment.NewLine);
            xml.Add(new XElement("variableSnMax", FormMain.r8.getVariableSnMax()));
            xml.Add(Environment.NewLine);
            xml.Add(new XElement("functionSnCount", FormMain.r8.getFunctionsCount()));
            xml.Add(Environment.NewLine);
            xml.Add(new XElement("variableSnCount", FormMain.r8.getVariablesCount()));
            xml.Add(Environment.NewLine);

            XElement functionsXml = new XElement("functions");

            xml.Add(functionsXml);
            xml.Add(Environment.NewLine);
            functionsXml.Add(Environment.NewLine);

            int      i, j;
            Function function;
            XElement functionXml = null;

            for (i = 0; i < FormMain.r8.getFunctionSnLast(); i++)
            {
                function = FormMain.r8.functions[i];
                if (function == null)
                {
                    continue;
                }
                functionXml = new XElement("function");
                functionXml.Add(Environment.NewLine);
                functionXml.Add(new XElement("sn", function.sn));
                functionXml.Add(Environment.NewLine);
                functionXml.Add(new XElement("name", function.name));
                functionXml.Add(Environment.NewLine);
                functionXml.Add(new XElement("posY", function.posY));
                functionXml.Add(Environment.NewLine);
                if (function.enable)
                {
                    functionXml.Add(new XElement("enable", "1"));
                }
                else
                {
                    functionXml.Add(new XElement("enable", "0"));
                }
                functionXml.Add(Environment.NewLine);
                functionXml.Add(new XElement("remark", function.remark));
                functionXml.Add(Environment.NewLine);
                if (R8.HAS_POS)
                {
                    functionXml.Add(new XElement("posX", function.getPosX()));
                    functionXml.Add(Environment.NewLine);
                    functionXml.Add(new XElement("posY", function.getPosY()));
                    functionXml.Add(Environment.NewLine);
                }
                for (j = 0; j < function.parameters.Count; j++)
                {
                    functionXml.Add(new XElement("variableSn", function.parameters.ElementAt(j).variableSn));
                    functionXml.Add(Environment.NewLine);
                }
                functionsXml.Add(functionXml);
                functionsXml.Add(Environment.NewLine);
            }


            XElement variablesXml = new XElement("variables");

            xml.Add(variablesXml);
            xml.Add(Environment.NewLine);
            variablesXml.Add(Environment.NewLine);
            StringBuilder str = new StringBuilder(R7.STRING_SIZE);
            Variable      variable;
            XElement      variableXml = null;

            for (i = 0; i < FormMain.r8.getVariableSnLast(); i++)
            {
                variable = FormMain.r8.variables[i];
                if (variable == null)
                {
                    continue;
                }
                variableXml = new XElement("variable");
                variableXml.Add(Environment.NewLine);
                variableXml.Add(new XElement("sn", variable.sn));
                variableXml.Add(Environment.NewLine);
                variableXml.Add(new XElement("name", variable.name));
                variableXml.Add(Environment.NewLine);
                //20170119 leo 今天討論後, type 要改為 string 小寫
                //variableXml.Add(new XElement("type", variable.type));
                //variableXml.Add(new XElement("type", Enum.GetName(typeof(Variable.VariableType), variable.type).ToLower()));
                //variableXml.Add(new XElement("type", R8.typeArray[variable.type].ToLower()));
                R8.GetVariableType(str, R7.STRING_SIZE, variable.type);
                variableXml.Add(new XElement("type", str));
                variableXml.Add(Environment.NewLine);
                variableXml.Add(new XElement("value", variable.value));
                variableXml.Add(Environment.NewLine);
                variableXml.Add(new XElement("remark", variable.remark));
                variableXml.Add(Environment.NewLine);
                variablesXml.Add(variableXml);
                variablesXml.Add(Environment.NewLine);
            }
            str.Clear();
            //xml.Save(path);
            //20180212 現在這邊要求要加標頭:

            /*
             #R7
             # -*- coding: utf-8 -*-
             # R7 version 1.8.6
             */
            //改用 stream
            StreamWriter streamWriter = new StreamWriter(path);

            streamWriter.WriteLine("#!R7");
            streamWriter.WriteLine("# -*- coding: utf-8 -*-");
            StringBuilder sb = new StringBuilder(1024);

            R7.GetVersion(sb, 1024);
            streamWriter.WriteLine("# R7 version " + sb.ToString());
            sb.Clear();
            xml.Save(streamWriter);
            streamWriter.Close();
            return;
        }
コード例 #24
0
        public void readProgramXml(string path)
        {
            //清空畫面
            foreach (Button b in buttons)
            {
                b.Dispose();
            }
            buttons.Clear();
            buttonsLocationY = buttonStartY;

            //標籤也要清空
            foreach (Label l in lineLabels)
            {
                l.Dispose();
            }
            lineLabels.Clear();


            //20170322 leo: 增加[New File] 模式,清空 variable 後就 return
            if (path == null)
            {
                FormMain.r8 = new R8();
                formMain.formVariables.showVariables(null);
                formMain.formFunction.showFunction(null);
                R8.clearLogBox();
                this.Text = Program_Functions + "  " + buttons.Count + " of " + FormMain.r8.getFunctionsCount();
                return;
            }
            //20170322 end

            //讀 xml
            //20180212 新的 r6 不是純 xml 了,前面會有額外的字串 # XXXXX
            //總之改用 Stream 先讀一遍,把是 # 開頭的砍了

            int    counter = 0;
            string line;

            System.IO.StreamReader file          = new System.IO.StreamReader(path);
            StringBuilder          stringBuilder = new StringBuilder();

            while ((line = file.ReadLine()) != null)
            {
                // MessageBox.Show("Line " + counter + " = " + line);
                if (line.Length > 1)
                {
                    if (line[0] != '#')
                    {
                        stringBuilder.Append(line);
                    }
                }
                counter++;
            }
            FormMain.r8 = new R8(XElement.Parse(stringBuilder.ToString()));
            file.Close();
            stringBuilder.Clear();

            //FormMain.r8 = new R8(XElement.Load(path));

            Function        function     = null;
            List <Function> functionList = new List <Function>();

            //改為 sort 完依 posY 排序再放 button
            for (int i = 0; i < FormMain.r8.getFunctionSnLast(); i++)
            {
                function = FormMain.r8.functions[i];
                if (function == null)
                {
                    continue;
                }
                functionList.Add(function);
                //addButton("[" + function.sn + "] [" + function.name + "]", function.sn);
            }

            functionList.Sort(delegate(Function i1, Function i2) { return(i1.posY.CompareTo(i2.posY)); });
            for (int i = 0; i < functionList.Count; i++)
            {
                function = functionList.ElementAt(i);
                //20170309 leo: 依早上討論,顯示格式修改 ImageOpen 1 [remark][disabled]
                //addButton("[" + function.sn + "] [" + function.name + "]", function.sn, function.enable);

                /*
                 * if (function.remark.Length > 0)
                 * {
                 *  addButton(function.name + " " + function.sn + " " + "[" + function.remark + "]" , function.sn, function.enable);
                 * }
                 * else {
                 *  addButton(function.name + " " + function.sn + " ", function.sn, function.enable);
                 * }*/
                addButton(getFunctionShowText(function), function.sn, function.enable);
                //20170309 leo end
                function.posY = buttons.Count;//讀出 button 後,應該要再依實際 button 位置進行 posY排序
            }
            this.Text = Program_Functions + "  " + buttons.Count + " of " + FormMain.r8.getFunctionsCount();
            //20170125 leo: 讀檔案後 show variable
            formMain.formVariables.showVariables(null);
            //20170208 leo: 讀檔案後 formFunction 清空
            formMain.formFunction.showFunction(null);
            this.Invalidate();
            Program.clearRecord();
            Program.recordProgram(FormMain.r8, formMain.toolStripMenuItemUndo, formMain.toolStripMenuItemRedo);
            //Program.recordProgram(FormMain.r8);
            return;
        }
コード例 #25
0
ファイル: FormVariable.cs プロジェクト: hebskjcc/OpenR8-1
        public void showVariable(int variableSn)
        {
            //20170315 leo: 發現介面 bug :若 showVariable 運行中時,又觸發一次 showVariable ,會導致 FormVariable 介面錯亂。
            //加個 bool 變數,若 showVariable 運行中,則不再觸發
            if (isShowVariableRunning)
            {
                return;
            }
            isShowVariableRunning = true;
            //System.Console.WriteLine("showVariable variableSn " + variableSn + ", " + this.variableSn);
            if (this.variableSn != variableSn)
            {
                //variableSn 更換, setVariable
                // setVariable();//20170214 leo: 改為 任何一個FormVariable 的零件 unfocus 時觸發
            }
            this.variableSn = variableSn;
            if (variableSn == -1 || variableSn == 0)
            {
                textBoxName.Text             = "";
                labelSn.Text                 = "";
                this.comboBox1.SelectedIndex = 0;
                textBoxRemark.Text           = "";
                if (valueComboBox != null)
                {
                    valueComboBox.Dispose();
                    valueComboBox = null;
                }
                if (valueNumericUpDown != null)
                {
                    valueNumericUpDown.Dispose();
                    valueNumericUpDown = null;
                }
                if (valueTextBox != null)
                {
                    valueTextBox.Dispose();
                    valueTextBox = null;
                }

                //20170327 Variable 沒 SN ,不顯示視窗元件。
                comboBox1.Visible     = false;
                label1.Visible        = false;
                labelValue.Visible    = false;
                label3.Visible        = false;
                label4.Visible        = false;
                labelSn.Visible       = false;
                textBoxName.Visible   = false;
                label5.Visible        = false;
                textBoxRemark.Visible = false;
                buttonDelete.Visible  = false;
            }
            else
            {
                //20170327 Variable 沒 SN ,不顯示視窗元件。
                comboBox1.Visible     = true;
                label1.Visible        = true;
                labelValue.Visible    = true;
                label3.Visible        = true;
                label4.Visible        = true;
                labelSn.Visible       = true;
                textBoxName.Visible   = true;
                label5.Visible        = true;
                textBoxRemark.Visible = true;
                buttonDelete.Visible  = true;

                textBoxName.Text = FormMain.r8.variables[variableSn].name;
                labelSn.Text     = FormMain.r8.variables[variableSn].sn.ToString();
                //20170117 leo: type 改為不鎖定
                //this.comboBox1.Enabled = true;
                this.comboBox1.SelectedIndex = FormMain.r8.variables[variableSn].type;
                //this.comboBox1.Enabled = false;
                value = FormMain.r8.variables[variableSn].value;
                this.textBoxRemark.Text = FormMain.r8.variables[variableSn].remark;

                //如果 type 為 image ,不顯示 value
                if (FormMain.r8.variables[variableSn].type == R8.getVariableTypeByString("image") ||
                    FormMain.r8.variables[variableSn].type == R8.getVariableTypeByString("json") ||
                    FormMain.r8.variables[variableSn].type == R8.getVariableTypeByString("object")
                    )
                {
                    FormMain.r8.variables[variableSn].value = "";
                    //this.textBoxValue.Visible = false;
                }
                else
                {
                    //this.textBoxValue.Visible = true;
                }
                //20170120 leo value 欄位依 type 切換元件。 textBox / comboBox / domainUpDown
                Point valueLocation = new Point(this.labelValue.Location.X + this.labelValue.Width + 10, this.labelValue.Location.Y);



                StringBuilder str = new StringBuilder(R7.STRING_SIZE);
                R8.GetVariableType(str, R7.STRING_SIZE, FormMain.r8.variables[variableSn].type);

                //20170330 leo: 切換元件時,若[type沒換]則不進行切換 (避免設置 value,按 enter 然後focus跳掉)
                bool needChangeValueBox = true;
                if (preVariableType.Equals(str.ToString()))
                {
                    needChangeValueBox = false;
                }

                preVariableType = str.ToString();

                if (needChangeValueBox)
                {
                    if (valueComboBox != null)
                    {
                        valueComboBox.Dispose();
                        valueComboBox = null;
                    }
                    if (valueNumericUpDown != null)
                    {
                        valueNumericUpDown.Dispose();
                        valueNumericUpDown = null;
                    }
                    if (valueTextBox != null)
                    {
                        valueTextBox.Dispose();
                        valueTextBox = null;
                    }
                }
                switch (str.ToString())
                {
                case "bool":
                case "Bool":
                case "boolean":
                case "Boolean":
                    //comboBox
                {
                    if (needChangeValueBox || valueComboBox == null)
                    {
                        valueComboBox = new ComboBox();

                        valueComboBox.Items.AddRange(new string[] { "False", "True" });
                        int res = 0;
                        if (!Int32.TryParse(value, out res))
                        {
                            res = 0;
                        }
                        if (res >= 1)
                        {
                            res = 1;
                        }
                        else
                        {
                            res = 0;
                        }
                        valueComboBox.SelectedIndex         = res;
                        valueComboBox.Location              = valueLocation;
                        valueComboBox.SelectedIndexChanged += valueComboBox_SelectedIndexChanged;
                        //valueComboBox.LostFocus += buttonSet_Click;
                        valueComboBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox_KeyDown);
                        valueComboBox.Leave   += new System.EventHandler(this.focus_Leave);
                        valueComboBox.TabIndex = 4;
                        this.Controls.Add(valueComboBox);
                    }
                    else
                    {
                        int res = 0;
                        if (!Int32.TryParse(value, out res))
                        {
                            res = 0;
                        }
                        if (res >= 1)
                        {
                            res = 1;
                        }
                        else
                        {
                            res = 0;
                        }
                        valueComboBox.SelectedIndex = res;
                    }
                }
                break;

                case "double":
                case "Double":
                    //numericUpDown
                {
                    if (needChangeValueBox || valueNumericUpDown == null)
                    {
                        valueNumericUpDown               = new NumericUpDown();
                        valueNumericUpDown.Maximum       = (decimal)int.MaxValue;
                        valueNumericUpDown.Minimum       = (decimal)int.MinValue;
                        valueNumericUpDown.Increment     = (decimal)0.5;
                        valueNumericUpDown.DecimalPlaces = 3;
                        valueNumericUpDown.Text          = value;
                        valueNumericUpDown.Location      = valueLocation;
                        valueNumericUpDown.TextChanged  += valueNumericUpDown_TextChanged;
                        valueNumericUpDown.Leave        += new System.EventHandler(this.focus_Leave);
                        valueNumericUpDown.TabIndex      = 4;
                        valueNumericUpDown.KeyDown      += new System.Windows.Forms.KeyEventHandler(this.textBox_KeyDown);
                        //valueNumericUpDown.LostFocus += buttonSet_Click;
                        this.Controls.Add(valueNumericUpDown);
                    }
                    else
                    {
                        valueNumericUpDown.Text = value;
                    }
                }
                break;

                case "float":
                case "Float":
                    //numericUpDown
                {
                    if (needChangeValueBox || valueNumericUpDown == null)
                    {
                        valueNumericUpDown               = new NumericUpDown();
                        valueNumericUpDown.Maximum       = (decimal)int.MaxValue;
                        valueNumericUpDown.Minimum       = (decimal)int.MinValue;
                        valueNumericUpDown.Increment     = (decimal)0.5;
                        valueNumericUpDown.DecimalPlaces = 3;
                        valueNumericUpDown.Text          = value;
                        valueNumericUpDown.Location      = valueLocation;
                        valueNumericUpDown.TextChanged  += valueNumericUpDown_TextChanged;
                        valueNumericUpDown.Leave        += new System.EventHandler(this.focus_Leave);
                        valueNumericUpDown.TabIndex      = 4;
                        //valueNumericUpDown.LostFocus += buttonSet_Click;
                        valueNumericUpDown.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox_KeyDown);
                        this.Controls.Add(valueNumericUpDown);
                    }
                    else
                    {
                        valueNumericUpDown.Text = value;
                    }
                }
                break;

                case "image":
                case "Image":
                case "mat":
                case "Mat":
                case "json":
                case "Json":     //20170216 新增 type: json
                case "object":
                case "Object":   //20170612 新增 type: object
                    //none

                    break;

                case "int":
                case "Int":
                    //numericUpDown
                {
                    if (needChangeValueBox || valueNumericUpDown == null)
                    {
                        valueNumericUpDown              = new NumericUpDown();
                        valueNumericUpDown.Maximum      = (decimal)int.MaxValue;
                        valueNumericUpDown.Minimum      = (decimal)int.MinValue;
                        valueNumericUpDown.Increment    = (decimal)1;
                        valueNumericUpDown.Text         = value;
                        valueNumericUpDown.Location     = valueLocation;
                        valueNumericUpDown.TextChanged += valueNumericUpDown_TextChanged;
                        valueNumericUpDown.Leave       += new System.EventHandler(this.focus_Leave);
                        valueNumericUpDown.TabIndex     = 4;
                        // valueNumericUpDown.LostFocus += buttonSet_Click;
                        valueNumericUpDown.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox_KeyDown);
                        this.Controls.Add(valueNumericUpDown);
                    }
                    else
                    {
                        valueNumericUpDown.Text = value;
                    }
                }
                break;

                case "string":
                case "String":
                case "str":
                case "Str":
                    //textBox
                {
                    if (needChangeValueBox || valueTextBox == null)
                    {
                        valueTextBox              = new TextBox();
                        valueTextBox.Text         = value;
                        valueTextBox.Location     = valueLocation;
                        valueTextBox.Width        = textBoxName.Width;  // 20170316_ 2. Value 的文字框寬度拉到跟 Name 的文字框相同。
                        valueTextBox.TextChanged += valueTextBox_TextChanged;
                        valueTextBox.Leave       += new System.EventHandler(this.focus_Leave);
                        valueTextBox.TabIndex     = 4;
                        //valueTextBox.Multiline = true;
                        valueTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox_KeyDown);
                        // valueTextBox.LostFocus += buttonSet_Click;
                        this.Controls.Add(valueTextBox);
                    }
                    else
                    {
                        valueTextBox.Text = value;
                    }
                }
                break;
                }
                str.Clear();
            }
            isShowVariableRunning = false;
            return;
        }