public MultiTracesCmd(RunnableModule runnableModule, MultiTracesCmdLine multiTracesCmdLine, MeasureHeightCmd mhCmd) : base(runnableModule, multiTracesCmdLine) { this.Valve = multiTracesCmdLine.Valve; var structure = runnableModule.CommandsModule.program.ModuleStructure; this.multiTracesCmdLine = multiTracesCmdLine; foreach (var trace in this.multiTracesCmdLine.Traces) { TraceBase newTrace = trace.Clone() as TraceBase; if (newTrace is TraceLine) { TraceLine traceLine = newTrace as TraceLine; traceLine.Start = structure.ToMachine(runnableModule, traceLine.Start); traceLine.End = structure.ToMachine(runnableModule, traceLine.End); } else { TraceArc traceArc = newTrace as TraceArc; traceArc.Start = structure.ToMachine(runnableModule, traceArc.Start); traceArc.Mid = structure.ToMachine(runnableModule, traceArc.Mid); traceArc.End = structure.ToMachine(runnableModule, traceArc.End); } this.traces.Add(newTrace); } LineStyle = multiTracesCmdLine.LineStyle; IsWeightControl = multiTracesCmdLine.IsWeightControl; wholeWeight = multiTracesCmdLine.WholeWeight; this.OffsetX = multiTracesCmdLine.OffsetX; this.OffsetY = multiTracesCmdLine.OffsetY; this.associatedMeasureHeightCmd = mhCmd; //this.CheckRepeat(); }
/// <summary> /// Author: liyi /// Date: 2019/08/27 /// Description:用于将界面参数更新至传入的轨迹数组 /// </summary> /// <param name="cmdLines"></param> private void UpdateCmdLineParam(List <CmdLine> cmdLines) { if (cmdLines.Count <= 0) { return; } if (this.rdoIncrementWeight.Checked) { isConstantWeight = false; } else if (this.rdoConstantWeight.Checked) { isConstantWeight = true; } if (this.cbxRotate.SelectedIndex == -1) { this.cbxRotate.SelectedIndex = 0; } double rotateAngle = this.cbxRotate.SelectedIndex * 90; // 机械坐标 -> 系统坐标 PointD referencePoint = this.pattern.SystemRel(new PointD(this.tbRefX.Value, this.tbRefY.Value)); PointD offsetPoint = this.pattern.SystemRel(new PointD(this.tbXOffset.Value, this.tbYOffset.Value)); double offsetX = offsetPoint.X; //this.tbXOffset.Value; double offsetY = offsetPoint.Y; //this.tbYOffset.Value; foreach (CmdLine cmdLine in cmdLines) { //判断是否是胶量模式 //1.胶量模式,全部启用胶量模式 //2.非胶量模式,全部禁用胶量模式 //3.都有的状态,只增加胶量值,不更改模式 if (cmdLine is CircleCmdLine) { CircleCmdLine circleCmdLine = cmdLine as CircleCmdLine; circleCmdLine.Weight = GetNewValue(circleCmdLine.Weight, tbWeight.Value, isConstantWeight); PointD temp = GetNewPosition(circleCmdLine.Start, referencePoint, offsetX, offsetY, rotateAngle); circleCmdLine.Start.X = temp.X; circleCmdLine.Start.Y = temp.Y; temp = GetNewPosition(circleCmdLine.Start, referencePoint, offsetX, offsetY, rotateAngle); circleCmdLine.End.X = temp.X; circleCmdLine.End.Y = temp.Y; temp = GetNewPosition(circleCmdLine.Middle, referencePoint, offsetX, offsetY, rotateAngle); circleCmdLine.Middle.X = temp.X; circleCmdLine.Middle.Y = temp.Y; temp = GetNewPosition(circleCmdLine.Middle, referencePoint, offsetX, offsetY, rotateAngle); circleCmdLine.Center.X = temp.X; circleCmdLine.Center.Y = temp.Y; if (this.cbxLineType.SelectedIndex != -1) { circleCmdLine.LineStyle = (LineStyle)this.cmdLineType; } if (this.cbIsWeightControl.CheckState != CheckState.Indeterminate) { circleCmdLine.IsWeightControl = this.cbIsWeightControl.Checked; } } else if (cmdLine is ArcCmdLine) { ArcCmdLine arcCmdLine = cmdLine as ArcCmdLine; arcCmdLine.Weight = GetNewValue(arcCmdLine.Weight, tbWeight.Value, isConstantWeight); PointD temp = GetNewPosition(arcCmdLine.Start, referencePoint, offsetX, offsetY, rotateAngle); arcCmdLine.Start.X = temp.X; arcCmdLine.Start.Y = temp.Y; temp = GetNewPosition(arcCmdLine.End, referencePoint, offsetX, offsetY, rotateAngle); arcCmdLine.End.X = temp.X; arcCmdLine.End.Y = temp.Y; temp = GetNewPosition(arcCmdLine.Middle, referencePoint, offsetX, offsetY, rotateAngle); arcCmdLine.Middle.X = temp.X; arcCmdLine.Middle.Y = temp.Y; temp = GetNewPosition(arcCmdLine.Center, referencePoint, offsetX, offsetY, rotateAngle); arcCmdLine.Center.X = temp.X; arcCmdLine.Center.Y = temp.Y; if (this.cbxLineType.SelectedIndex != -1) { arcCmdLine.LineStyle = (LineStyle)this.cmdLineType; } if (this.cbIsWeightControl.CheckState != CheckState.Indeterminate) { arcCmdLine.IsWeightControl = this.cbIsWeightControl.Checked; } } else if (cmdLine is DotCmdLine) { DotCmdLine dotCmdLine = cmdLine as DotCmdLine; dotCmdLine.Weight = GetNewValue(dotCmdLine.Weight, tbWeight.Value, isConstantWeight); PointD temp = GetNewPosition(dotCmdLine.Position, referencePoint, offsetX, offsetY, rotateAngle); dotCmdLine.Position.X = temp.X; dotCmdLine.Position.Y = temp.Y; if (this.cbxDotType.SelectedIndex != -1) { dotCmdLine.DotStyle = (DotStyle)this.cmdDotType; } if (this.cbIsWeightControl.CheckState != CheckState.Indeterminate) { dotCmdLine.IsWeightControl = this.cbIsWeightControl.Checked; } } else if (cmdLine is SnakeLineCmdLine) { SnakeLineCmdLine snakeLineCmdLine = cmdLine as SnakeLineCmdLine; if (this.cbxLineType.SelectedIndex != -1) { snakeLineCmdLine.LineStyle = (LineStyle)this.cmdLineType; } if (this.cbIsWeightControl.CheckState != CheckState.Indeterminate) { snakeLineCmdLine.IsWeightControl = this.cbIsWeightControl.Checked; } PointD temp = new PointD(); foreach (LineCoordinate item in snakeLineCmdLine.LineCoordinateList) { temp = GetNewPosition(item.Start, referencePoint, offsetX, offsetY, rotateAngle); item.Start.X = temp.X; item.Start.Y = temp.Y; temp = GetNewPosition(item.End, referencePoint, offsetX, offsetY, rotateAngle); item.End.X = temp.X; item.End.Y = temp.Y; } } else if (cmdLine is LineCmdLine) { LineCmdLine lineCmdLine = cmdLine as LineCmdLine; if (this.cbxLineType.SelectedIndex != -1) { lineCmdLine.LineStyle = (LineStyle)this.cmdLineType; } for (int i = 0; i < lineCmdLine.LineCoordinateList.Count; i++) { lineCmdLine.LineCoordinateList[i].LineStyle = lineCmdLine.LineStyle; } if (this.cbIsWeightControl.CheckState != CheckState.Indeterminate) { lineCmdLine.IsWeightControl = this.cbIsWeightControl.Checked; } if (lineCmdLine.LineMethod == LineMethod.Single) { lineCmdLine.WholeWeight = GetNewValue(lineCmdLine.WholeWeight, tbWeight.Value, isConstantWeight); } else if (lineCmdLine.LineMethod == LineMethod.Multi) { lineCmdLine.WholeWeight = GetNewValue(lineCmdLine.WholeWeight, tbWeight.Value, isConstantWeight); } else if (lineCmdLine.LineMethod == LineMethod.Poly) { lineCmdLine.WholeWeight = GetNewValue(lineCmdLine.WholeWeight, tbWeight.Value, isConstantWeight); } PointD temp = new PointD(); foreach (LineCoordinate item in lineCmdLine.LineCoordinateList) { temp = GetNewPosition(item.Start, referencePoint, offsetX, offsetY, rotateAngle); item.Start.X = temp.X; item.Start.Y = temp.Y; temp = GetNewPosition(item.End, referencePoint, offsetX, offsetY, rotateAngle); item.End.X = temp.X; item.End.Y = temp.Y; } } else if (cmdLine is MultiTracesCmdLine) { MultiTracesCmdLine multiTrace = cmdLine as MultiTracesCmdLine; PointD temp = new PointD(); foreach (var item in multiTrace.Traces) { if (item is TraceLine) { temp = GetNewPosition(item.Start, referencePoint, offsetX, offsetY, rotateAngle); item.Start.X = temp.X; item.Start.Y = temp.Y; temp = GetNewPosition(item.End, referencePoint, offsetX, offsetY, rotateAngle); item.End.X = temp.X; item.End.Y = temp.Y; } else if (item is TraceArc) { TraceArc traceArc = item as TraceArc; temp = GetNewPosition(traceArc.Start, referencePoint, offsetX, offsetY, rotateAngle); traceArc.Start.X = temp.X; traceArc.Start.Y = temp.Y; temp = GetNewPosition(traceArc.Mid, referencePoint, offsetX, offsetY, rotateAngle); traceArc.Mid.X = temp.X; traceArc.Mid.Y = temp.Y; temp = GetNewPosition(traceArc.End, referencePoint, offsetX, offsetY, rotateAngle); traceArc.End.X = temp.X; traceArc.End.Y = temp.Y; } } } else if (cmdLine is SymbolLinesCmdLine) { SymbolLinesCmdLine symbolLinesCmdLine = cmdLine as SymbolLinesCmdLine; PointD temp = new PointD(); double r = this.symbolLine1.GetPrm(); foreach (var item in symbolLinesCmdLine.Symbols) { item.transitionR = r; if (item.symbolType == SymbolType.Line) { temp = GetNewPosition(item.symbolPoints[0], referencePoint, offsetX, offsetY, rotateAngle); item.symbolPoints[0].X = temp.X; item.symbolPoints[0].Y = temp.Y; temp = GetNewPosition(item.symbolPoints[1], referencePoint, offsetX, offsetY, rotateAngle); item.symbolPoints[1].X = temp.X; item.symbolPoints[1].Y = temp.Y; } else if (item.symbolType == SymbolType.Arc) { temp = GetNewPosition(item.symbolPoints[0], referencePoint, offsetX, offsetY, rotateAngle); item.symbolPoints[0].X = temp.X; item.symbolPoints[0].Y = temp.Y; temp = GetNewPosition(item.symbolPoints[1], referencePoint, offsetX, offsetY, rotateAngle); item.symbolPoints[1].X = temp.X; item.symbolPoints[1].Y = temp.Y; temp = GetNewPosition(item.symbolPoints[2], referencePoint, offsetX, offsetY, rotateAngle); item.symbolPoints[2].X = temp.X; item.symbolPoints[2].Y = temp.Y; } } } } }
public EditMultiTracesForm(Pattern pattern, MultiTracesCmdLine multiTracesCmdLine) : base(pattern.GetOriginPos()) { InitializeComponent(); this.ReadLanguageResources(); this.pattern = pattern; this.origin = pattern.GetOriginPos(); if (multiTracesCmdLine == null) { isCreating = true; this.multiTracesCmdLine = new MultiTracesCmdLine(); this.multiTracesCmdLine.LineStyle = (LineStyle)Properties.Settings.Default.LineStyle; this.multiTracesCmdLine.IsWeightControl = Properties.Settings.Default.LineIsWt; this.multiTracesCmdLine.WholeWeight = Properties.Settings.Default.LineWt; //系统坐标->机械坐标 //PointD p = this.pattern.MachineRel(Properties.Settings.Default.LineEndX, Properties.Settings.Default.LineEndY); //this.tbPointX.Text = p.X.ToString("0.000"); //this.tbPointY.Text = p.Y.ToString("0.000"); //this.btnLastCmdLine.Visible = false; //this.btnNextCmdLine.Visible = false; } else { isCreating = false; this.multiTracesCmdLine = multiTracesCmdLine; } foreach (var item in this.multiTracesCmdLine.Traces) { this.tracesCache.Add(item.Clone() as TraceBase); } this.updatePointsCache(); //load points to listboxPoints this.LoadPoints2ListBox(); if (this.pointsCache.Count > 0) { this.listBoxPoints.SelectedIndex = 0; } //load lines to listboxLines this.LoadLines2ListBox(); if (this.tracesCache.Count > 0) { this.listBoxLines.SelectedIndex = 0; } //cbWeightControl.Checked = this.lineCmdLine.IsWeightControl; //if (this.lineCmdLine != null) //{ // this.lineCmdLineBackUp = (LineCmdLine)this.lineCmdLine.Clone(); //} this.rbLine.Checked = true; for (int i = 0; i < FluidProgram.Current.ProgramSettings.LineParamList.Count; i++) { comboBoxLineType.Items.Add("Type " + (i + 1)); } if (this.tracesCache.Count > 0) { comboBoxLineType.SelectedIndex = this.tracesCache[0].LineStyle; } else { comboBoxLineType.SelectedIndex = 0; } this.tbOffsetX.Text = this.multiTracesCmdLine.OffsetX.ToString("0.000"); this.tbOffsetY.Text = this.multiTracesCmdLine.OffsetY.ToString("0.000"); }
/// <summary> /// 将程序指令解析为绘图指令,添加到绘图workpiece或者pattern中 /// </summary> /// <param name="cmdLine"></param> /// <param name="pattern"></param> private void Parse(CmdLine cmdLine, DrawPattern pattern) { if (cmdLine is ArcCmdLine) { ArcCmdLine arc = cmdLine as ArcCmdLine; PointF centerPosition = new PointF((float)arc.Center.X, (float)arc.Center.Y); PointF startPosition = new PointF((float)arc.Start.X, (float)arc.Start.Y); PointF endPosition = new PointF((float)arc.End.X, (float)arc.End.Y); float degree = (float)arc.Degree; ArcDrawCmd arcDrawCmd = new ArcDrawCmd(centerPosition, startPosition, endPosition, degree, arc.Enabled); pattern.Add(arcDrawCmd); } //如果是DoPattern指令 else if (cmdLine is DoCmdLine) { if (this._drawPatterns.Count <= 0) { pattern.Add(null); } else if (pattern.GetType().Equals(typeof(DrawWorkPiece))) { DoCmdLine doPattern = cmdLine as DoCmdLine; //判断是paternList里的哪一个pattern int index = 0; for (int i = 0; i < fluidProgram.Patterns.Count; i++) { if (fluidProgram.Patterns[i].Name.Equals(doPattern.PatternName)) { index = i; } } PointF origin = new PointF((float)doPattern.Origin.X, (float)doPattern.Origin.Y); DoPatternDrawCmd doPatternDrawCmd = new DoPatternDrawCmd(this._drawPatterns[index], origin, doPattern.Enabled); pattern.Add(doPatternDrawCmd); } else { pattern.Add(null); } } else if (cmdLine is StepAndRepeatCmdLine) { if (pattern.GetType().Equals(typeof(DrawWorkPiece))) { StepAndRepeatCmdLine array = cmdLine as StepAndRepeatCmdLine; //判断是paternList里的哪一个pattern int index = 0; for (int i = 0; i < fluidProgram.Patterns.Count; i++) { if (fluidProgram.Patterns[i].Name.Equals(array.PatternName)) { index = i; } } PointF[] points = new PointF[array.DoCmdLineList.Count]; for (int i = 0; i < array.DoCmdLineList.Count; i++) { points[i] = new PointF((float)array.DoCmdLineList[i].Origin.X, (float)array.DoCmdLineList[i].Origin.Y); } ArrayDrawCmd arrayDrawCmd = new ArrayDrawCmd(this._drawPatterns[index], points, array.Enabled); pattern.Add(arrayDrawCmd); } else { pattern.Add(null); } } else if (cmdLine is CircleCmdLine) { CircleCmdLine circle = cmdLine as CircleCmdLine; PointF centerPosition = new PointF((float)circle.Center.X, (float)circle.Center.Y); float radius = (float)Math.Sqrt(Math.Pow(Math.Abs(circle.Start.X - circle.Center.X), 2) + Math.Pow(Math.Abs(circle.Start.Y - circle.Center.Y), 2)); CircleDrawCmd circleDrawCmd = new CircleDrawCmd(centerPosition, radius, circle.Enabled); pattern.Add(circleDrawCmd); } else if (cmdLine is DoMultiPassCmdLine) { if (pattern.GetType().Equals(typeof(DrawWorkPiece))) { DoMultiPassCmdLine doMultiPass = cmdLine as DoMultiPassCmdLine; //判断是paternList里的哪一个pattern int index = 0; for (int i = 0; i < fluidProgram.Patterns.Count; i++) { if (fluidProgram.Patterns[i].Name.Equals(doMultiPass.PatternName)) { index = i; } } PointF position = new PointF((float)doMultiPass.Origin.X, (float)doMultiPass.Origin.Y); DoMultiPassDrawCmd doMultiDrawCmd = new DoMultiPassDrawCmd(this._drawPatterns[index], position, doMultiPass.Enabled); pattern.Add(doMultiDrawCmd); } else { pattern.Add(null); } } else if (cmdLine is DotCmdLine) { DotCmdLine dot = cmdLine as DotCmdLine; PointF centerPosition = new PointF((float)dot.Position.X, (float)dot.Position.Y); DotDrawCmd dotDrawCmd = new DotDrawCmd(centerPosition, dot.Enabled); pattern.Add(dotDrawCmd); } else if (cmdLine is MeasureHeightCmdLine) { MeasureHeightCmdLine height = cmdLine as MeasureHeightCmdLine; PointF position = new PointF((float)height.Position.X, (float)height.Position.Y); HeightDrawCmd heightDrawCmd = new HeightDrawCmd(position, height.Enabled); pattern.Add(heightDrawCmd); } ///包含line、lines和polyline else if (cmdLine is LineCmdLine) { LineCmdLine line = cmdLine as LineCmdLine; int jointCount = 0; if (line.LineCoordinateList.Count == 1) { PointF startPoint = new PointF((float)line.LineCoordinateList[0].Start.X, (float)line.LineCoordinateList[0].Start.Y); PointF endPoint = new PointF((float)line.LineCoordinateList[0].End.X, (float)line.LineCoordinateList[0].End.Y); LineDrawCmd lineDrawCmd = new LineDrawCmd(startPoint, endPoint, true, line.Enabled); pattern.Add(lineDrawCmd); } else if (line.LineCoordinateList.Count > 1) { Line2Points[] lines = new Line2Points[line.LineCoordinateList.Count]; for (int i = 0; i < line.LineCoordinateList.Count; i++) { PointF startPoint = new PointF((float)line.LineCoordinateList[i].Start.X, (float)line.LineCoordinateList[i].Start.Y); PointF endPoint = new PointF((float)line.LineCoordinateList[i].End.X, (float)line.LineCoordinateList[i].End.Y); lines[i] = new Line2Points(startPoint, endPoint); //判断是不是polyline(如果所有相邻线段首尾点一致,则为polyline) if (i > 0 && lines[i].StartPoint == lines[i - 1].EndPoint) { jointCount++; } } //如果是polyline if (jointCount == line.LineCoordinateList.Count - 1) { PointF[] points = new PointF[line.LineCoordinateList.Count + 1]; for (int i = 0; i < lines.Length + 1; i++) { if (i == 0) { points[i] = new PointF((float)lines[0].StartPoint.X, (float)lines[0].StartPoint.Y); } else { points[i] = new PointF((float)lines[i - 1].EndPoint.X, (float)lines[i - 1].EndPoint.Y); } } PolyLineDrawCmd polyLineDrawCmd = new PolyLineDrawCmd(points, line.Enabled); pattern.Add(polyLineDrawCmd); } //如果是lines else { LinesDrawCmd linesDrawCmd = new LinesDrawCmd(lines, true, line.Enabled); pattern.Add(linesDrawCmd); } } } else if (cmdLine is MarkCmdLine) { MarkCmdLine mark = cmdLine as MarkCmdLine; PointF position = new PointF((float)mark.PosInPattern.X, (float)mark.PosInPattern.Y); MarkDrawCmd markDrawCmd = new MarkDrawCmd(position, mark.Enabled, MarkType.NormalMark); pattern.Add(markDrawCmd); } else if (cmdLine is BadMarkCmdLine) { BadMarkCmdLine mark = cmdLine as BadMarkCmdLine; PointF position = new PointF((float)mark.Position.X, (float)mark.Position.Y); MarkDrawCmd markDrawCmd = new MarkDrawCmd(position, mark.Enabled, MarkType.BadMark); pattern.Add(markDrawCmd); } else if (cmdLine is NozzleCheckCmdLine) { NozzleCheckCmdLine mark = cmdLine as NozzleCheckCmdLine; PointF position = new PointF((float)mark.Position.X, (float)mark.Position.Y); MarkDrawCmd markDrawCmd = new MarkDrawCmd(position, mark.Enabled, MarkType.CheckDotMark); pattern.Add(markDrawCmd); } else if (cmdLine is SnakeLineCmdLine) { SnakeLineCmdLine snake = cmdLine as SnakeLineCmdLine; Line2Points[] lines = new Line2Points[snake.LineCoordinateList.Count]; for (int i = 0; i < snake.LineCoordinateList.Count; i++) { PointF startPoint = new PointF((float)snake.LineCoordinateList[i].Start.X, (float)snake.LineCoordinateList[i].Start.Y); PointF endPoint = new PointF((float)snake.LineCoordinateList[i].End.X, (float)snake.LineCoordinateList[i].End.Y); lines[i] = new Line2Points(startPoint, endPoint); } SnakeLineDrawCmd snakeLineDrawCmd = new SnakeLineDrawCmd(lines, true, snake.Enabled); pattern.Add(snakeLineDrawCmd); } else if (cmdLine is SymbolLinesCmdLine) { SymbolLinesCmdLine symbolLines = cmdLine as SymbolLinesCmdLine; SymbolLinesDrawCmd symbolLinesDrawCmd = new SymbolLinesDrawCmd(symbolLines.Symbols, symbolLines.Enabled); pattern.Add(symbolLinesDrawCmd); } else if (cmdLine is MultiTracesCmdLine) { MultiTracesCmdLine tracesCmdLine = cmdLine as MultiTracesCmdLine; MultiTracesDrawCmd tracesDrawCmd = new MultiTracesDrawCmd(tracesCmdLine.Traces, tracesCmdLine.Enabled); pattern.Add(tracesDrawCmd); } //如果是别的逻辑指令,为了保证和程序指令一致性,添加一个null进去 else { pattern.Add(null); } }