public GCommand PopCommand() { var returnCommand = nextCommand; nextCommand = ParseNextCommand(); return(returnCommand); }
// Constructor public EventBlock(GCommand command) { // Initialize Component InitializeComponent(); StackContentText.Text = command.FriendlyName; _GCommand = command; _GEvent = new GEvent(_GCommand); // Initialize Hole List HoleList.Add(NextConnectHole); for (int i = 0; i < _GEvent.Arguments?.Count; i++) { VariableBlock variableBlock = BlockUtils.CreateVariableBlock(_GEvent.Arguments[i].Name, command.Optionals[i].FriendlyName); BaseBlock baseBlock = variableBlock as BaseBlock; baseBlock.MouseLeftButtonDown += BaseBlock_MouseLeftButtonDown; AllowVariableList.Add(variableBlock); ParameterBox.Children.Add(baseBlock); } // Initialize Block InitializeBlock(); }
public static void SaveGCommand(XmlWriter writer, GCommand command) { writer.WriteAttributeString("NamespaceName", command.NamespaceName); writer.WriteAttributeString("MethodName", command.MethodName); writer.WriteAttributeString("FriendlyName", command.FriendlyName); writer.WriteAttributeString("MethodType", command.MethodType.ToString()); writer.WriteAttributeString("ObjectType", command.ObjectType.AssemblyQualifiedName); if (command.Optionals != null) { writer.WriteStartElement("Optionals"); foreach (var option in command.Optionals) { writer.WriteStartElement("Optional"); writer.WriteAttributeString("Name", option.Name); writer.WriteAttributeString("FullName", option.FullName); writer.WriteAttributeString("FriendlyName", option.FriendlyName); writer.WriteAttributeString("ObjectType", option.ObjectType.AssemblyQualifiedName); writer.WriteEndElement(); } writer.WriteEndElement(); } }
private GEnum(GCommand command) { if (command.MethodType != GCommand.CommandType.Enum) { throw new Exception("Cannot create GEnum"); } _GCommand = command; }
private GCommand GetGCommandInStr(string strCmd) { GCommand res = GCommand.NONE; if ((strCmd == null) || (strCmd == "")) { return(res); } int[] indComment = { strCmd.IndexOf('('), strCmd.IndexOf(')') };//индексы скобок - открывающей и закрывающей комментарий if ((indComment[0] == 0) && (indComment[1] == strCmd.Count() - 1)) { return(res); // скобочки в начале и в конце строки - вся строка в комментарии } //проверим есть ли поддерживаемая G команда if (strCmd.IndexOf("G00") >= 0) { res = GCommand.G00; } else if (strCmd.IndexOf("G01") >= 0) { res = GCommand.G01; } else if (strCmd.IndexOf("G02") >= 0) { res = GCommand.G02; } else if (strCmd.IndexOf("G03") >= 0) { res = GCommand.G03; } //------------------------------------------------------------------//теперь проверим не сокращенный ли вариант else if (strCmd.IndexOf("G0") >= 0) { res = GCommand.G00; } else if (strCmd.IndexOf("G1") >= 0) { res = GCommand.G01; } else if (strCmd.IndexOf("G2") >= 0) { res = GCommand.G02; } else if (strCmd.IndexOf("G3") >= 0) { res = GCommand.G03; } //---------------------------------------------//если G команды нет, но есть X или Y или Z: значит продолжение предыдущей команды else if ((strCmd.IndexOf('G') < 0) && ((strCmd.IndexOf('X') >= 0) || (strCmd.IndexOf('Y') >= 0) || (strCmd.IndexOf('Z') >= 0))) { res = previousGCommand; } return(res); }
public virtual bool Add(string line) { GrblRequest request = new GrblRequest(); request.SetContent(line); if (request.IsRequestType(GrblRequestEnum.GCode)) { request = new GCommand(line, true); } return(Add(request)); }
public VoidCallBlock(GCommand command) { InitializeComponent(); _GCommand = command; _HoleList = BlockUtils.SetContent(command, WrapContent); _HoleList.Add(NextConnectHole); InitializeBlock(); }
public void Reset() { pauseItem = 0; _CyclePause = false; currentStrCommand = ""; previousStrCommand = ""; currentGCommand = GCommand.NONE; previousGCommand = GCommand.NONE; }
// 생성자 public ObjectCallBlock(GCommand command) { InitializeComponent(); _GCommand = command; _HoleList = BlockUtils.SetContent(command, WrapContent, new BrushConverter().ConvertFromString("#FF79297E") as Brush); _GObjectList = new List <GBase> { GObject }; InitializeBlock(); }
// 생성자 public PropertyBlock(GCommand command) { InitializeComponent(); _GCommand = command; _GProperty = new GProperty(command); _GObjectList = new List <GBase> { GObject }; PropertyName.Text = command.FriendlyName; InitializeBlock(); }
public static BaseBlock LoadBlockFromXml(XmlElement element, BlockEditor blockEditor) { GCommand command = BlockUtils.LoadGCommand(element); ObjectCallBlock block = new ObjectCallBlock(command); XmlNodeList elementList = element.SelectNodes("Holes/Hole"); for (int i = 0; i < block.HoleList.Count; i++) { BlockUtils.ConnectToHole(block.HoleList[i], LoadBlock(elementList[i].SelectSingleNode("Block") as XmlElement, blockEditor)); } return(block); }
private IEnumerator MoveHead(GCommand move, float width, float height) { var startPosition = transform.position; var nextPosition = transform.position; if (move.HasE && move.E > 0) { isExtruding = true; } if (MovementType == Movement.Relative) { nextPosition.x += move.X; nextPosition.y += move.Y; nextPosition.z += move.Z; } else { if (move.HasX) { nextPosition.x = move.X; } if (move.HasY) { nextPosition.z = move.Y; } if (move.HasZ) { nextPosition.y = move.Z; } } while (Vector3.Distance(transform.position, nextPosition) > .0001) { transform.position = Vector3.MoveTowards(transform.position, nextPosition, MoveStep * Time.deltaTime); yield return(null); } transform.position = nextPosition; if (isExtruding) { var line = GetFreeLine(); line.GetComponent <ProceduralMesh>().GenerateLine(startPosition, nextPosition, width, height); linesCreated.Add(line); } isExtruding = false; }
public GEvent(GCommand command) { GCommand = command; for (int i = 0; i < GCommand.Optionals?.Length; i++) { string variableName = GCommand.Optionals[i].Name; variableName = PREFIX_ARG + variableName[0].ToString().ToUpper() + variableName.Substring(1); GVariable variable = GSharpUtils.CreateGVariable(variableName); Arguments.Add(variable); ArgumentsType.Add(GCommand.Optionals[i].ObjectType); } }
public void Execute(GCommand command) { if ((SerialPort == null) || !SerialPort.IsConnected) { return; } if (command.CurrentPosePosition == null) { command.CurrentPosePosition = CommandStore.SharedInstance.CurrentPosePosition; } command.SendTimeStamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); SerialPort.WriteLine(command.CommandText); }
public static BaseBlock LoadBlockFromXml(XmlElement element, BlockEditor blockEditor) { GCommand command = BlockUtils.LoadGCommand(element); VoidCallBlock block = new VoidCallBlock(command); XmlNodeList elementList = element.SelectNodes("Holes/Hole"); var holeList = block.HoleList.Where(e => !(e is NextConnectHole)); for (int i = 0; i < holeList.Count(); i++) { BlockUtils.ConnectToHole(block.HoleList[i], LoadBlock(elementList[i].SelectSingleNode("Block") as XmlElement, blockEditor)); } return(block); }
private void SendCommandButton_OnClick(object sender, RoutedEventArgs e) { if (!_serialPort.IsConnected) { return; } var xInc = TextToInt(XCommandTextBox.Text); var yInc = TextToInt(YCommandTextBox.Text); var zInc = TextToInt(ZCommandTextBox.Text); var newCommand = new GCommand(xInc, yInc, zInc, _currentPosePosition); _commands.Enqueue(newCommand); new Thread(CommandExecutor.SharedInstance.Execute).Start(); }
private GCommand ParseNextCommand() { GCommand command = null; while (command == null && listLocation < gcodeText.Count()) { var trimmedLine = gcodeText[listLocation].Trim(); if (trimmedLine.Contains(";")) { trimmedLine = trimmedLine.Substring(0, trimmedLine.IndexOf(";")); } command = ParseGCommand(trimmedLine); listLocation++; } return(command); }
public void DoCommand(int i) { string strCommand = commandList[i]; if ((strCommand == null) || (strCommand == "")) { return; } DesplayCurGCodeStr(i + 1 + ": " + strCommand); if (owner.DoLog) { AddLog("-----------------------------------"); AddLog("CommandSender.DoCommand(): Command: " + (i + 1) + " : " + strCommand);//??---- } currentStrCommand = strCommand.ToUpper(); currentGCommand = GetGCommandInStr(currentStrCommand); switch (currentGCommand) { case GCommand.G00: DoCommandG00(); break; case GCommand.G01: DoCommandG01(); break; case GCommand.G02: DoCommandG02(); break; case GCommand.G03: DoCommandG03(); break; case GCommand.NONE: break; default: break; } previousGCommand = currentGCommand; }
private void MoveHeadImmediate(GCommand move, float width, float height) { var startPosition = transform.position; var nextPosition = transform.position; if (move.HasE && move.E > 0) { isExtruding = true; } if (MovementType == Movement.Relative) { nextPosition.x += move.X; nextPosition.y += move.Y; nextPosition.z += move.Z; } else { if (move.HasX) { nextPosition.x = move.X; } if (move.HasY) { nextPosition.z = move.Y; } if (move.HasZ) { nextPosition.y = move.Z; } } // Only extrude if we actually moved the nozzle if (isExtruding && (move.HasX || move.HasY || move.HasZ) && (transform.position - nextPosition).magnitude >= MinimumExtrusionLength) { var line = GetFreeLine(); line.GetComponent <ProceduralMesh>().GenerateLine(startPosition, nextPosition, width, height); linesCreated.Add(line); } transform.position = nextPosition; isExtruding = false; }
public void Callback(SerialPort sender, GCommand command) { var sp = sender; while (sp.BytesToRead > 0) { var d = sp.ReadLine(); if (command != null) { command.Receive(d); LogHandler?.Invoke(command.ToReceiveLog()); // if the gcommand is executed if (d.Equals("OK\r", StringComparison.InvariantCultureIgnoreCase)) { // update the current position if (command.NextPosePosition != null) { CommandStore.SharedInstance.CurrentPosePosition = command.NextPosePosition; } // report current position CommandExecutor.SharedInstance.brain.Arm.ReportPose( CommandExecutor.SharedInstance.RegisterId.Value, command.SendTimeStamp.ToString(), CommandStore.SharedInstance.CurrentPosePosition.X, CommandStore.SharedInstance.CurrentPosePosition.Y, CommandStore.SharedInstance.CurrentPosePosition.Z); LogHandler?.Invoke($"Reported Pose: {CommandStore.SharedInstance.CurrentPosePosition.X}, {CommandStore.SharedInstance.CurrentPosePosition.Y}, {CommandStore.SharedInstance.CurrentPosePosition.Z}"); lock (CommandExecutor.SharedInstance) { // clean the current command CommandStore.SharedInstance.CurrentCommand = null; // clean the waiting flag IsWaitingResponse = false; } } } } }
private void goToCoordinateButton_Click(object sender, RoutedEventArgs e) { if (!_serialPort.IsConnected) { return; } var coorX = TextToDouble(CoordinateXTextBox.Text); var coorY = TextToDouble(CoordinateYTextBox.Text); var coorZ = TextToDouble(CoordinateZTextBox.Text); var targetPose = _testBrain.Arm.ConvertCoordinateToPose( CommandExecutor.SharedInstance.RegisterId.Value, coorX, coorY, coorZ) as PosePosition; var newCommand = new GCommand(targetPose.X - _currentPosePosition.X, targetPose.Y - _currentPosePosition.Y, targetPose.Z - _currentPosePosition.Z, _currentPosePosition); //_commands.Enqueue(newCommand); //new Thread(CommandExecutor.SharedInstance.Execute).Start(); }
// 생성자 public EnumBlock(GCommand command) { InitializeComponent(); _GCommand = command; _GEnum = new GEnum(command); _GObjectList = new List <GBase> { GObject }; if (command.Optionals != null) { foreach (var opt in command.Optionals) { EnumName.Items.Add(opt); } } EnumName.SelectedIndex = 0; InitializeBlock(); }
public GEvent(GCommand command, List <GStatement> content) : this(command) { Content = content; }
public GVoidCall(GCommand command) { GCommand = command; }
private void ReturnUnusedCommand(GCommand command) { command.ResetCommand(); freeCommands.Add(command); }
public void ResetQueuePosition() { listLocation = 0; nextCommand = ParseNextCommand(); }
public GVoidCall(GCommand command, GObject[] arguments) : this(command) { Arguments = arguments; }
public GProperty(GCommand command) { _GCommand = command; }
public GEnum(GCommand command, int index = 0) : this(command) { SelectedIndex = index; }
/// <summary> /// 모듈 블럭들에게 필요한 구멍을 자동으로 찾아서 생성하고 위치시킵니다. /// </summary> /// <param name="Command">모듈을 호출하기 위해 필요한 GCommand 객체</param> /// <param name="Content">생성한 구멍과 내용을 추가할 Panel 객체</param> /// <returns>생성한 모든 구멍을 반환</returns> public static List <BaseHole> SetContent(GCommand Command, Panel Content, Brush brush = null) { // 기존 패널에 있는 내용 삭제 Content.Children.Clear(); // 반환을 위한 구멍 목록 생성 var holeList = new List <BaseHole>(); // Command의 FriendlyName에서 구멍 파싱 var start = -1; var last = 0; for (int i = 0; i < Command.FriendlyName.Length; i++) { var chr = Command.FriendlyName[i]; if (chr == '{') { start = i; } else if (chr == '}' && start >= 0) { var text = Command.FriendlyName.Substring(last, start - last); var holeNumber = Command.FriendlyName.Substring(start + 1, i - start - 1); int number; if (int.TryParse(holeNumber, out number) && 0 <= number && number < Command.Optionals.Length) { BaseHole hole = CreateHole(Command.Optionals[number].ObjectType); if (brush == null) { brush = new BrushConverter().ConvertFromString("#086748") as Brush; } hole.Foreground = brush; hole.VerticalAlignment = VerticalAlignment.Center; Content.Children.Add(new TextBlock { Text = text, FontWeight = FontWeights.Bold, Foreground = Brushes.White, VerticalAlignment = VerticalAlignment.Center }); Content.Children.Add(hole); holeList.Add(hole); start = -1; last = i + 1; } } } var lastText = Command.FriendlyName.Substring(last); Content.Children.Add(new TextBlock { Text = lastText, FontWeight = FontWeights.Bold, Foreground = Brushes.White, VerticalAlignment = VerticalAlignment.Center }); // 구멍 목록 반환 return(holeList); }