/// <summary> /// 入力した内容を解析するアルゴリズム /// </summary> public void FormulaAnalysis() { //Define Parameters ToKen token; TknKind bef_tok_kind = TknKind.None; loopInfo = 0; //DV2_Drawing dv2d_FA = new DV2_Drawing(); string objName = ""; string objAnalysisData = ""; string objCommandData = ""; string[] storageData; int dataGridView_index = 0; int objFinder_index = 0; System.DateTime currentTime = new System.DateTime(); currentTime = System.DateTime.Now; #region Boolean Flags bool pointDef_flg = false; bool pointGet_flg = false; bool pointSol_flg = false; bool objPlus_flg = false; bool rotation_flg = false; bool setPoint_flg = false; bool clear_flg = false; bool cleartar_flg = false; #endregion //Debug //LogOutput("Resources.Graph_line :> " + Properties.Resources.Graph_line); LogOutput("Formula Analysis Strat at -> ******* " + currentTime + " *******"); //LogOutput("Settings.GraphicInstruction :> " + DV2.Net_Graphics_Application.Properties.Settings.Default.GraphicInstruction); //LogOutput(dataStorage.Text.Length); if (dataStorage.Text.Length != 0) { LogOutput(String.Format("{0, -15}", "Text") + String.Format("{0, -15}", "Kind") + String.Format("{0, -15}", "numVal")); LogOutput("---------------------------------------------"); #region コマンド内容はチャ-の単位として循環処理 for (char txtChar = ' '; loopInfo < dataStorage.Text.Length;) { txtChar = dataStorage.Text[loopInfo]; token = nextTkn(txtChar); LogOutput(">>>token.kind iS -> " + String.Format("{0, -15}", token.kind)); //LogOutput(">>bef_tok_kind iS -> " + String.Format("{0, -15}", bef_tok_kind)); #region コマンド終わり判断 if (token.kind == TknKind.END_line) { break; } #endregion #region Command "Assign" Route if (token.kind == TknKind.Assign) { //例:対象を定義する obj1 = line(0,0,20,10) if (bef_tok_kind == TknKind.Ident) { //dataStorage storageData = Regex.Split(dataStorage.Text, "=", RegexOptions.IgnoreCase); //LogOutput("TknKind.Ident+TknKind.Assign Length ->" + storageData.Length); //入力した命令を保存する if (storageData.Length == 2) { if (ObjectFinder(storageData[0].Replace(" ", "")) == -1) { ObjName.Add(storageData[0].Replace(" ", "")); ObjCommand.Add(storageData[1].Replace(" ", "")); } else { objName = storageData[0].Replace(" ", ""); ObjCommand[ObjectFinder(storageData[0].Replace(" ", ""))] = storageData[1].Replace(" ", ""); } //データ監視器--データ導入 dataGridView_index = this.dataGridView_monitor.Rows.Add(); this.dataGridView_monitor.Rows[dataGridView_index].Cells[0].Value = storageData[0].Replace(" ", ""); this.dataGridView_monitor.Rows[dataGridView_index].Cells[1].Value = storageData[1].Replace(" ", ""); } else { codeOutput("Error @FormulaAnalysis @341"); break; } } } #endregion #region Command "Show" Route if (token.kind == TknKind.Ident) { //表示命令を判別する if (bef_tok_kind == TknKind.Show) { //tabControl_Graphics.SelectTab(1); //表示したい対象名が存在するかどうかを判断する if (ObjectFinder(token.text) != -1) { objFinder_index = ObjectFinder(token.text); } else { tobeRead.SpeakAsync("表示される " + token.text + " 対象は不存在,もう一度確認してください。"); codeOutput("表示される " + token.text + " 対象は不存在,もう一度確認してください。"); return; } //表示したい対象名が存在する場合は,その同じ順番配列データの有効性を判断する if (ObjName[objFinder_index] != null && ObjAnalysis[objFinder_index] != null) { //LogOutput(ObjCommand[objFinder_index]); //LogOutput(ObjAnalysis[objFinder_index]); //分析結果を転送する ParameterChecker(ObjAnalysis[objFinder_index], objFinder_index); picBox.Refresh(); } else { tobeRead.SpeakAsync("表示される " + token.text + " 対象は不存在,もう一度確認してください。"); codeOutput("表示される " + token.text + " 対象は不存在,もう一度確認してください。"); } if (!ROTATIONFLAG) { LogOutput("ROTATIONFLAG is " + ROTATIONFLAG); debug_Image.RotateFlip(RotateFlipType.RotateNoneFlipY); picBox.Refresh(); ROTATIONFLAG = true; } MakeObjectBraille(); } } #endregion #region Command "Point Define" Route if (token.kind == TknKind.Point) { //変数pをPoint型として宣言 if (bef_tok_kind == TknKind.Colon) { //Ex:"var p : Point" -> "p = Point(0,0)" -- このコマンドは点pを原点に初期値(0,0)に設定する storageData = Regex.Split(dataStorage.Text, ":", RegexOptions.IgnoreCase); if (ObjectFinder(storageData[0].Replace(" ", "")) == -1) { ObjName.Add(storageData[0].Replace(" ", "")); ObjCommand.Add(storageData[1].Replace(" ", "")); } else { objName = storageData[0].Replace(" ", ""); ObjCommand[ObjectFinder(storageData[0].Replace(" ", ""))] = storageData[1].Replace(" ", ""); } //データ監視器--データ導入 dataGridView_index = this.dataGridView_monitor.Rows.Add(); this.dataGridView_monitor.Rows[dataGridView_index].Cells[0].Value = storageData[0]; this.dataGridView_monitor.Rows[dataGridView_index].Cells[1].Value = storageData[1].Replace(" ", ""); //pointDef_flgフラグをtrueに設定する pointDef_flg = true; } } #endregion #region Command "Get P" Route if (token.kind == TknKind.Ident) { //To get the finger point on the object //Ex:get p on obj1 if (bef_tok_kind == TknKind.Get) { //pointGet_flgフラグをtrueに設定する pointGet_flg = true; } } #endregion #region Command "Slove" Route if (token.kind == TknKind.Ident) { //Slove the math program //Ex:solve c by contact(obj1,obj2,p) if (bef_tok_kind == TknKind.Solve) { //pointSol_flgフラグをtrueに設定する pointSol_flg = true; } } #endregion #region Command "Object Plus" Route if (token.kind == TknKind.Ident) { //Ex:obj3=obj1+obj2 if (bef_tok_kind == TknKind.Plus) { //objPlus_flgフラグをtrueに設定する objPlus_flg = true; } } #endregion #region Command "Clear Object" Route if (token.kind == TknKind.Ident) { //Ex:clear obj if (bef_tok_kind == TknKind.Clear) { LogOutput("Clear The graphObj"); //cleartar_flgフラグをtrueに設定する cleartar_flg = true; } } #endregion #region Command "Clear ALL" Route if (token.kind == TknKind.Clear) { //Ex:clear if (dataStorage.Text.Length != 0 && dataStorage.Text.ToLower() == "clear") { LogOutput("Clear ALL The graphObj"); //clear_flgフラグをtrueに設定する clear_flg = true; } } #endregion #region Command "Set" Route if (token.kind == TknKind.Set) { //Setting the parameters } #endregion #region Command "Rotate" Route if (token.kind == TknKind.Lparen) { if (bef_tok_kind == TknKind.Rotation) { //画像を回転する rotation_flg = true; } } #endregion #region Command "SetPoint" Route if (token.kind == TknKind.SetPoint) { //相対位置処理入口 setPoint_flg = true; } #endregion bef_tok_kind = token.kind; objAnalysisData += token.kind + "|"; objCommandData += token.text + "|"; //LogOutput(String.Format("{0, -15}", token.text) + String.Format("{0, -15}", token.kind) + String.Format("{0, -15}", token.dblVal)); } #endregion #region 書き処理 //Modify old data if (ObjAnalysis.Count == ObjName.Count && objName != "" && ObjectFinder(objName) != -1) { bool assignFlag = false; int loop_i; //分析結果を保存する //正規表現関数 for (loop_i = 0; loop_i < Regex.Split(objAnalysisData, @"\|", RegexOptions.IgnoreCase).Length; loop_i++) { if (Regex.Split(objAnalysisData, @"\|", RegexOptions.IgnoreCase)[loop_i] == "Assign") { assignFlag = true; break; } } if (assignFlag) { objAnalysisData = string.Join("|", Regex.Split(objAnalysisData, @"\|", RegexOptions.IgnoreCase).Skip(loop_i + 1).ToArray()); ObjAnalysis[ObjectFinder(objName)] = objAnalysisData.Substring(0, objAnalysisData.Length - 1); this.dataGridView_monitor.Rows[dataGridView_index].Cells[2].Value = objAnalysisData.Substring(0, objAnalysisData.Length - 1); } else { ObjAnalysis[ObjectFinder(objName)] = objAnalysisData.Substring(0, objAnalysisData.Length - 1); this.dataGridView_monitor.Rows[dataGridView_index].Cells[2].Value = objAnalysisData.Substring(0, objAnalysisData.Length - 1); } //Ex:"obj1|=|line|(|1|,|2|,|20.0|,|25.5|)|" -> "obj1|=|line|(|1|,|2|,|20.0|,|25.5|)" ObjCommand[ObjectFinder(objName)] = objCommandData.Substring(0, objCommandData.Length - 1); LogOutput("Modify Debug Point"); } #endregion #region 解析結果 //New data appended! if (ObjAnalysis.Count < ObjName.Count) { bool assignFlag = false; int loop_i; //分析結果を保存する //正規表現関数 for (loop_i = 0; loop_i < Regex.Split(objAnalysisData, @"\|", RegexOptions.IgnoreCase).Length; loop_i++) { if (Regex.Split(objAnalysisData, @"\|", RegexOptions.IgnoreCase)[loop_i] == "Assign") { assignFlag = true; break; } } if (assignFlag) { objAnalysisData = String.Join("|", Regex.Split(objAnalysisData, @"\|", RegexOptions.IgnoreCase).Skip(loop_i + 1).ToArray()); ObjAnalysis.Add(objAnalysisData.Substring(0, objAnalysisData.Length - 1)); this.dataGridView_monitor.Rows[dataGridView_index].Cells[2].Value = objAnalysisData.Substring(0, objAnalysisData.Length - 1); } else { ObjAnalysis.Add(objAnalysisData.Substring(0, objAnalysisData.Length - 1)); this.dataGridView_monitor.Rows[dataGridView_index].Cells[2].Value = objAnalysisData.Substring(0, objAnalysisData.Length - 1); } if (ObjCommand.Count == ObjName.Count) { //Ex:"obj1|=|line|(|1|,|2|,|20.0|,|25.5|)|" -> "obj1|=|line|(|1|,|2|,|20.0|,|25.5|)" ObjCommand.RemoveAt(ObjCommand.Count - 1); ObjCommand.Add(objCommandData.Substring(0, objCommandData.Length - 1)); } } #endregion } else { codeOutput("Error @FormulaAnalysis MSG: Please Input Data!"); } //此処から処理するのデータは自動保存されていない。 if (dataStorage.Text.Length != 0 && ObjName.Count != 0) { //未完成 //予定機能は対象名の重複データをチェックする //DuplicateChecking(); } #region PointDefine Route if (pointDef_flg) { if (Regex.Split(objAnalysisData, @"\|", RegexOptions.IgnoreCase)[0].ToLower() == "var") { string[] temp = Regex.Split(ObjCommand[ObjCommand.Count - 1].ToString(), @"\|", RegexOptions.IgnoreCase); //Data Remove ObjName.RemoveAt(ObjName.Count - 1); ObjCommand.RemoveAt(ObjCommand.Count - 1); ObjAnalysis.RemoveAt(ObjAnalysis.Count - 1); //New Data Append ObjName.Add(temp[1]); ObjCommand.Add("Point|(|0|,|0|)"); ObjAnalysis.Add("Point|Lparen|IntNum|Comma|IntNum|Rparen"); //データ監視器 Rewirte this.dataGridView_monitor.Rows[dataGridView_index].Cells[0].Value = temp[1]; this.dataGridView_monitor.Rows[dataGridView_index].Cells[1].Value = "point(0,0)"; this.dataGridView_monitor.Rows[dataGridView_index].Cells[2].Value = "Point|Lparen|IntNum|Comma|IntNum|Rparen"; } } #endregion #region PointGet Route if (pointGet_flg) { //get P on obj1 //objCommandData "get|p|on|obj1|" //objAnalysisData "Get|Ident|On|Ident|" objCommandData = objCommandData.Substring(0, objCommandData.Length - 1); objAnalysisData = objAnalysisData.Substring(0, objAnalysisData.Length - 1); if (Regex.Split(objAnalysisData, @"\|", RegexOptions.IgnoreCase).Count() == 4) { GetPointOnObject(objCommandData, objAnalysisData); } else { //Error LogOutput("Error @FormulaAnalysis PointGet Route"); tobeRead.SpeakAsync("入力ミスが発生していた。"); } } #endregion #region The Solve Route if (pointSol_flg) { //solve c by contact(obj1,ojb2,p) //objCommandData "solve|c|by|contact|(|obj1|,|ojb2|,|p|)|" //objAnalysisData "Solve|Ident|Ident|Contact|Lparen|Ident|Comma|Ident|Comma|Ident|Rparen|" objCommandData = objCommandData.Substring(0, objCommandData.Length - 1); objAnalysisData = objAnalysisData.Substring(0, objAnalysisData.Length - 1); string[] tmpCommData = Regex.Split(objCommandData, @"\|", RegexOptions.IgnoreCase); string[] tmpAnaData = Regex.Split(objAnalysisData, @"\|", RegexOptions.IgnoreCase); int identCounter = 0; bool contact_flag = false; foreach (var temp in tmpAnaData) { if (temp == "Ident") { identCounter++; } if (temp == "Contact") { contact_flag = true; } } if (contact_flag == true && identCounter == 5) { TheSolveMode(objCommandData, tmpCommData, objAnalysisData, tmpAnaData); } } #endregion #region objPlus Route if (objPlus_flg) { //obj3=obj1+obj2 //objCommandData "obj3|=|obj1|+|obj2|" //objAnalysisData "Ident|Plus|Ident|" objCommandData = objCommandData.Substring(0, objCommandData.Length - 1); objAnalysisData = objAnalysisData.Substring(0, objAnalysisData.Length - 1); AssignRemover(ref objCommandData); string[] tmpCommData = Regex.Split(objCommandData, @"\|", RegexOptions.IgnoreCase); string[] tmpAnaData = Regex.Split(objAnalysisData, @"\|", RegexOptions.IgnoreCase); if (objAnalysisData != "Ident|Plus|Ident") { //Error Route return; } for (int i = 0; i < tmpAnaData.Length; i++) { if (tmpAnaData[i] == "Ident") { if (ObjectFinder(tmpCommData[i]) == -1) { tobeRead.SpeakAsync(ObjectFinder(tmpCommData[i]) + "対象は定義されていません!"); codeOutput(ObjectFinder(tmpCommData[i]) + "対象は定義されていません!"); } } } } #endregion #region Rotation Route if (rotation_flg) { //rotation -30 //objCommandData "rotation|(|obj1|,|30|)|" //objAnalysisData "Rotation|Lparen|Ident|Comma|IntNum|Rparen|" objCommandData = objCommandData.Substring(0, objCommandData.Length - 1); objAnalysisData = objAnalysisData.Substring(0, objAnalysisData.Length - 1); Rotation(objCommandData, objAnalysisData); } #endregion #region setPoint Route if (setPoint_flg) { //obj1:setpoint(LEFT,obj2,Right,10,0) //objCommandData "obj1|:|setpoint|(|LEFT|,|obj2|,|Right|,|10|,|0|)|" //objAnalysisData "Ident|Colon|SetPoint|Lparen|Left|Comma|Ident|Comma|Right|Comma|IntNum|Comma|IntNum|Rparen|" objCommandData = objCommandData.Substring(0, objCommandData.Length - 1); objAnalysisData = objAnalysisData.Substring(0, objAnalysisData.Length - 1); LogOutput("objCommandData " + objCommandData); LogOutput("objAnalysisData " + objAnalysisData); TheSetPointMode(objCommandData, objAnalysisData); } #endregion #region Clear Route if (clear_flg) { LogOutput("clear_flg" + clear_flg); graphObj.Dispose(); debug_Image.Dispose(); graphObj = PreparePaper(); picBox.Image = (Image)debug_Image; picBox.Refresh(); ObjDisplayed.Clear(); DotDataInitialization(ref forDisDots); DotDataInitialization(ref allDotData); Dv2Instance.SetDots(forDisDots, BlinkInterval); if (!ROTATIONFLAG) { LogOutput("ROTATIONFLAG is " + ROTATIONFLAG); debug_Image.RotateFlip(RotateFlipType.RotateNoneFlipY); picBox.Refresh(); ROTATIONFLAG = true; } } if (cleartar_flg) { //clear objA //objCommandData clear|objA //objAnalysisData Clear|Ident objCommandData = objCommandData.Substring(0, objCommandData.Length - 1); objAnalysisData = objAnalysisData.Substring(0, objAnalysisData.Length - 1); LogOutput("objCommandData " + objCommandData); LogOutput("objAnalysisData " + objAnalysisData); if (ObjDisplayed.Count == 1 || ObjDisplayed.Count == 0) { graphObj.Dispose(); debug_Image.Dispose(); graphObj = PreparePaper(); picBox.Image = (Image)debug_Image; picBox.Refresh(); ObjDisplayed.Clear(); DotDataInitialization(ref forDisDots); DotDataInitialization(ref allDotData); Dv2Instance.SetDots(forDisDots, BlinkInterval); } else { //Processing if (!ClearTargetAndCheck(objCommandData, objAnalysisData)) { //処理失敗の流れ } } } #endregion LogOutput("---------------------------------------------"); LogOutput("Formula Analysis End at -> ******* " + System.DateTime.Now + " *******"); if (ROTATIONFLAG) { LogOutput("ROTATIONFLAG is " + ROTATIONFLAG); debug_Image.RotateFlip(RotateFlipType.RotateNoneFlipY); ROTATIONFLAG = false; } }
/// <summary> /// DV-2のボタンを動作イベント関数 /// このイベントを宣言すると,DV-2のボタンが押された時に,処理できる /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Dv2KeyEventHandle(object sender, DV.KeyEventArgs e) { bool moved_flg = false; //for the test int objFinder_index = 0; tobeRead.SpeakAsyncCancelAll(); #region Debug if (false) { codeOutput("************************************************"); codeOutput("Shift -+-> " + e.Shift); codeOutput("Kind -+-> " + e.Kind); codeOutput("Value -+-> " + e.Value); } #endregion //DotViewの何かのキーが押された時の処理 #region フロントキー処理 // ***************フロントキー処理*************** if (e.Shift == 128 && e.Kind == 0 && e.Value == 0) { //親指キー tobeRead.SpeakAsync("親指キー"); int cir_x = 24 + movement.X; int cir_y = 16 + movement.Y; ObjName.Add("obj11"); ObjCommand.Add("obj11|=|circle|(|" + cir_x + "|,|" + cir_y + "|,|15|)"); ObjAnalysis.Add("Circle|Lparen|IntNum|Comma|IntNum|Comma|IntNum|Rparen"); objFinder_index = ObjectFinder("obj11"); ParameterChecker(ObjAnalysis[objFinder_index], objFinder_index); MakeObjectBraille(); } if (e.Shift == 64 && e.Kind == 0 && e.Value == 0) { //ステータスキー tobeRead.SpeakAsync("ステータスキー"); } if (e.Shift == 0 && e.Kind == 4 && e.Value == 16) { //拡大キー tobeRead.SpeakAsync("拡大キー"); } if (e.Shift == 0 && e.Kind == 4 && e.Value == 128) { //縮小キー tobeRead.SpeakAsync("縮小キー"); } if (e.Shift == 0 && e.Kind == 5 && e.Value == 8) { //方向レバー 上 //tobeRead.SpeakAsync("方向レバー 上"); movement.Y -= 1; moved_flg = true; if (movement.Y < 0) { movement.Y = 0; moved_flg = false; } } if (e.Shift == 0 && e.Kind == 5 && e.Value == 4) { //方向レバー 下 //tobeRead.SpeakAsync("方向レバー 下"); movement.Y += 1; moved_flg = true; if (movement.Y + 0 > picBox.Height) { movement.Y = picBox.Height - 0; moved_flg = false; } } if (e.Shift == 0 && e.Kind == 5 && e.Value == 16) { //方向レバー 左 //tobeRead.SpeakAsync("方向レバー 左"); movement.X -= 1; moved_flg = true; if (movement.X < 0) { movement.X = 0; moved_flg = false; } } if (e.Shift == 0 && e.Kind == 5 && e.Value == 2) { //方向レバー 右 //tobeRead.SpeakAsync("方向レバー 右"); movement.X += 1; moved_flg = true; if (movement.X + 0 > picBox.Width) { movement.X = picBox.Width - 0; moved_flg = false; } } if (e.Shift == 16 && e.Kind == 0 && e.Value == 0) { //方向レバー 中心 tobeRead.SpeakAsync("方向レバー 中心"); } #endregion #region サイドキー処理 // ***************サイドキー処理*************** if (e.Shift == 0 && e.Kind == 4 && e.Value == 1) { //上矢印キー tobeRead.SpeakAsync("上矢印キー"); } if (e.Shift == 0 && e.Kind == 4 && e.Value == 2) { //下矢印キー tobeRead.SpeakAsync("下矢印キー"); } if (e.Shift == 0 && e.Kind == 4 && e.Value == 8) { //左矢印キー tobeRead.SpeakAsync("左矢印キー"); } if (e.Shift == 0 && e.Kind == 4 && e.Value == 4) { //右矢印キー tobeRead.SpeakAsync("右矢印キー"); } if (e.Shift == 32 && e.Kind == 0 && e.Value == 0) { //センターキー tobeRead.SpeakAsync("センターキー"); } if (e.Shift == 0 && e.Kind == 4 && e.Value == 64) { //エンドキー tobeRead.SpeakAsync("エンドキー"); } if (e.Shift == 0 && e.Kind == 4 && e.Value == 32) { //ホームキー tobeRead.SpeakAsync("ホームキー"); } #endregion // *************** 移動処理 *************** if (moved_flg) { DotDataInitialization(ref forDisDots); for (int width = 0; width < 48; width++) { for (int height = 0; height < 32; height++) { #region for Test /* * if (movement.X + width >= picBox.Width) * { * movement.X = picBox.Width - width; * } * * if (movement.Y + height >= picBox.Height) * { * movement.Y = picBox.Height - height; * } */ #endregion forDisDots[width, height] = allDotData[movement.X + width, movement.Y + height]; } } Dv2Instance.SetDots(forDisDots, BlinkInterval); label_posX.Text = movement.X.ToString(); label_posY.Text = movement.Y.ToString(); } }