/// <summary> /// Method that locks commands when waiting for user interaction, until the requested /// action has been performed. For example, if a command requests for a Joint, then it /// gets locked until the user picks one by any means available. /// </summary> /// <param name="waitingFor">The object that was picked by the user</param> /// <param name="startSelection">The type of object that the command requests (i.e. Joint, Line, Point, etc.)</param> private void wait(WaitingFor waitingFor, bool startSelection) { Commands.ModelCommand mc; selectionFilter = waitingFor; if (startSelection) { controller.SelectionCommand.Start(this); } while (selectionFilter != WaitingFor.None) { // if ModelCmd has been cancelled or ModelCmd is no longer registered on the Controller // Cancel the command and stop the waiting if (((mc = controller.ModelCommand) == null) || ((mc != null) && (mc.Cancel))) { throw new CancelCommandException(); } // Para evitar que este ciclo se coma todo el cpu, porque // DoEvents sólo pasa el control al MessageLoop de la aplicación // para que cheque si hay mensajes y en caso contrario regresa // inmediatamente, lo que hace que este ciclo se convierta en un // while que consume el 100% del cpu nomás por esperar // (Exactamente como el PropertyGrid cuando despliega un DropDown) // La llamada a la rutina de abajo duerme al hilo hasta que ocurra // cualquier evento, con lo que se arregla el problema Canguro.Utility.NativeHelperMethods.WaitInMainThread(250); } }
/// <summary> /// Method that responds to a click on an Item. It releases any waiting locks, /// i.e.sets waitingObj to pickedObj and the selectionFilter to None. /// </summary> /// <param name="pickedObj">The clicked Item</param> public void SelectionDone(object pickedObj) { switch (selectionFilter) { case WaitingFor.None: waitingObj = null; break; default: waitingObj = pickedObj; selectionFilter = WaitingFor.None; break; } }
//public event EventHandler ShowCommandPanel; public CommandServices(Controller controller) { selectionFilter = WaitingFor.None; waitingObj = null; this.controller = controller; // Aquí se recibe el evento de cambio en la selección desde el Model //Canguro.Model.Model.Instance.SelectionChanged += new Canguro.Model.Model.SelectionChangedEventHandler(onSelectionChanged); // Este será para cuando el SmallPanel esté integrado con DirectX //Canguro.View.GraphicViewManager.Instance.EnterData += new Canguro.View.EnterDataEventHandler(onEnterData); // Este funciona para recibir el input del SmallPanel independiente controller.MainFrm.SmallPanel.EnterData += new Canguro.View.EnterDataEventHandler(onEnterData); }
/// <summary> /// Method that tries to assign waitingObj by parsing a string containing an Item /// index and a list containing the actual objects being refered to. If successful, /// it assigns waitingObj, selects the Item and sets the selectionFilter to None. /// If the string cannot be parsed or the index does not exist in the given list, /// it displays an error to the user and returns without changing anything. /// </summary> /// <param name="parseStr">The user input</param> /// <param name="list">The list of Items where the search will be carried out (i.e. JointList)</param> /// <param name="dataStr">String with the Item being searched for in the proper language</param> private void parseItem(string parseStr, System.Collections.IList list, string dataStr) { if ((list != null) && (!string.IsNullOrEmpty(parseStr))) { try { int index = int.Parse(parseStr.Trim()); if (index >= 0 && index < list.Count) { waitingObj = (Canguro.Model.Item)list[index]; } else { throw new Canguro.Model.InvalidIndexException(dataStr); } if (waitingObj == null) { throw new Canguro.Model.InvalidIndexException(dataStr); } } catch (FormatException) { System.Windows.Forms.MessageBox.Show( Culture.Get("enterDataError") + "'" + dataStr + "'", Culture.Get("enterDataErrorTitle"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } catch (Canguro.Model.InvalidIndexException) { System.Windows.Forms.MessageBox.Show( Culture.Get("enterDataIndexError").Replace("*type*", dataStr) + "'" + parseStr + "'", Culture.Get("enterDataErrorTitle"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } if (waitingObj != null) { ((Canguro.Model.Item)waitingObj).IsSelected = true; } selectionFilter = WaitingFor.None; }
private void mymethod() { foreach (Cargo i in cargos) { System.Threading.Thread.Sleep(5000); App.Current.Dispatcher.Invoke((Action) delegate { WaitingFor.Add(i); }); } /* * System.Threading.Thread.Sleep(5000); * App.Current.Dispatcher.Invoke((Action)delegate * { * WaitingFor.Add(cargos[numberGenerator(0, 4)]); * }); */ }
/// <summary> /// Method that locks commands when waiting for user interaction, until the requested /// action has been performed. For example, if a command requests for a Joint, then it /// gets locked until the user picks one by any means available. /// </summary> /// <param name="waitingFor">The object that was picked by the user</param> /// <param name="startSelection">The type of object that the command requests (i.e. Joint, Line, Point, etc.)</param> private void wait(WaitingFor waitingFor, bool startSelection) { Commands.ModelCommand mc; selectionFilter = waitingFor; if (startSelection) controller.SelectionCommand.Start(this); while (selectionFilter != WaitingFor.None) { // if ModelCmd has been cancelled or ModelCmd is no longer registered on the Controller // Cancel the command and stop the waiting if (((mc = controller.ModelCommand) == null) || ((mc != null) && (mc.Cancel))) throw new CancelCommandException(); // Para evitar que este ciclo se coma todo el cpu, porque // DoEvents sólo pasa el control al MessageLoop de la aplicación // para que cheque si hay mensajes y en caso contrario regresa // inmediatamente, lo que hace que este ciclo se convierta en un // while que consume el 100% del cpu nomás por esperar // (Exactamente como el PropertyGrid cuando despliega un DropDown) // La llamada a la rutina de abajo duerme al hilo hasta que ocurra // cualquier evento, con lo que se arregla el problema Canguro.Utility.NativeHelperMethods.WaitInMainThread(250); } }
/// <summary> /// Method that tries to assign waitingObj by parsing a string containing an Item /// index and a list containing the actual objects being refered to. If successful, /// it assigns waitingObj, selects the Item and sets the selectionFilter to None. /// If the string cannot be parsed or the index does not exist in the given list, /// it displays an error to the user and returns without changing anything. /// </summary> /// <param name="parseStr">The user input</param> /// <param name="list">The list of Items where the search will be carried out (i.e. JointList)</param> /// <param name="dataStr">String with the Item being searched for in the proper language</param> private void parseItem(string parseStr, System.Collections.IList list, string dataStr) { if ((list != null) && (!string.IsNullOrEmpty(parseStr))) { try { int index = int.Parse(parseStr.Trim()); if (index >= 0 && index < list.Count) waitingObj = (Canguro.Model.Item)list[index]; else throw new Canguro.Model.InvalidIndexException(dataStr); if (waitingObj == null) throw new Canguro.Model.InvalidIndexException(dataStr); } catch (FormatException) { System.Windows.Forms.MessageBox.Show( Culture.Get("enterDataError") + "'" + dataStr + "'", Culture.Get("enterDataErrorTitle"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } catch (Canguro.Model.InvalidIndexException) { System.Windows.Forms.MessageBox.Show( Culture.Get("enterDataIndexError").Replace("*type*", dataStr) + "'" + parseStr + "'", Culture.Get("enterDataErrorTitle"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } if (waitingObj != null) ((Canguro.Model.Item)waitingObj).IsSelected = true; selectionFilter = WaitingFor.None; }
/// <summary> /// Method that responds to the EnterData event of SmallPanel. /// The text input by the user on the SmallPanel's TextBox (data) is /// parsed here. If the input is successfull locks are released and /// execution continues normally, i.e.: waitingObj is assigned to the /// refered object and the selectionFilter is set to None. Otherwise, /// the input is rejected. /// </summary> /// <param name="sender">Usually, the SmallPanel in MainFrm</param> /// <param name="e">Event args with the user input</param> void onEnterData(object sender, Canguro.View.EnterDataEventArgs e) { char[] charSeparators = new char[] {',', ';', ' ', '\t', '@'}; waitingObj = null; switch (selectionFilter) { case WaitingFor.Point: if (!string.IsNullOrEmpty(e.Data)) { bool relativePt = false; string trimmedPt = e.Data.Trim(); if (trimmedPt.Length > 0 && trimmedPt[0] == '@') relativePt = true; string[] pt = trimmedPt.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); Microsoft.DirectX.Vector3 v; try { if (pt.Length != 3) throw new FormatException(); v = new Microsoft.DirectX.Vector3( float.Parse(pt[0]), float.Parse(pt[1]), float.Parse(pt[2])); if (relativePt) v += lastPoint; } catch (FormatException) { System.Windows.Forms.MessageBox.Show( Culture.Get("enterDataError") + "'" + Culture.Get("enterDataPoint") + "'", Culture.Get("enterDataErrorTitle"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } waitingObj = new Snap.PointMagnet(v); } selectionFilter = WaitingFor.None; break; case WaitingFor.Joint: parseItem(e.Data, Canguro.Model.Model.Instance.JointList, Culture.Get("enterDataJoint")); break; case WaitingFor.Line: parseItem(e.Data, Canguro.Model.Model.Instance.LineList, Culture.Get("enterDataLine")); break; case WaitingFor.Area: parseItem(e.Data, Canguro.Model.Model.Instance.AreaList, Culture.Get("enterDataArea")); break; case WaitingFor.Text: waitingObj = e.Data; selectionFilter = WaitingFor.None; break; case WaitingFor.SimpleValue: try { waitingObj = float.Parse(e.Data); selectionFilter = WaitingFor.None; } catch (FormatException) { System.Windows.Forms.MessageBox.Show( Culture.Get("enterDataError") + "'" + Culture.Get("enterDataSimpleValue") + "'", Culture.Get("enterDataErrorTitle"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } break; case WaitingFor.Any: case WaitingFor.Many: case WaitingFor.None: break; default: throw new NotImplementedException("CommandServices.onEnterData"); } }
/// <summary> /// Method that responds to the EnterData event of SmallPanel. /// The text input by the user on the SmallPanel's TextBox (data) is /// parsed here. If the input is successfull locks are released and /// execution continues normally, i.e.: waitingObj is assigned to the /// refered object and the selectionFilter is set to None. Otherwise, /// the input is rejected. /// </summary> /// <param name="sender">Usually, the SmallPanel in MainFrm</param> /// <param name="e">Event args with the user input</param> void onEnterData(object sender, Canguro.View.EnterDataEventArgs e) { char[] charSeparators = new char[] { ',', ';', ' ', '\t', '@' }; waitingObj = null; switch (selectionFilter) { case WaitingFor.Point: if (!string.IsNullOrEmpty(e.Data)) { bool relativePt = false; string trimmedPt = e.Data.Trim(); if (trimmedPt.Length > 0 && trimmedPt[0] == '@') { relativePt = true; } string[] pt = trimmedPt.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); Microsoft.DirectX.Vector3 v; try { if (pt.Length != 3) { throw new FormatException(); } v = new Microsoft.DirectX.Vector3( float.Parse(pt[0]), float.Parse(pt[1]), float.Parse(pt[2])); if (relativePt) { v += lastPoint; } } catch (FormatException) { System.Windows.Forms.MessageBox.Show( Culture.Get("enterDataError") + "'" + Culture.Get("enterDataPoint") + "'", Culture.Get("enterDataErrorTitle"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } waitingObj = new Snap.PointMagnet(v); } selectionFilter = WaitingFor.None; break; case WaitingFor.Joint: parseItem(e.Data, Canguro.Model.Model.Instance.JointList, Culture.Get("enterDataJoint")); break; case WaitingFor.Line: parseItem(e.Data, Canguro.Model.Model.Instance.LineList, Culture.Get("enterDataLine")); break; case WaitingFor.Area: parseItem(e.Data, Canguro.Model.Model.Instance.AreaList, Culture.Get("enterDataArea")); break; case WaitingFor.Text: waitingObj = e.Data; selectionFilter = WaitingFor.None; break; case WaitingFor.SimpleValue: try { waitingObj = float.Parse(e.Data); selectionFilter = WaitingFor.None; } catch (FormatException) { System.Windows.Forms.MessageBox.Show( Culture.Get("enterDataError") + "'" + Culture.Get("enterDataSimpleValue") + "'", Culture.Get("enterDataErrorTitle"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } break; case WaitingFor.Any: case WaitingFor.Many: case WaitingFor.None: break; default: throw new NotImplementedException("CommandServices.onEnterData"); } }