예제 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            FluidProgram.Create("xiaoxu", 0, 0);
            DotCmdLine dot = new DotCmdLine();

            dot.Position.X = 100;
            dot.Position.Y = 100;
            FluidProgram.CurrentOrDefault().Workpiece.AddCmdLine(dot);

            DoCmdLine doPattern = new DoCmdLine("1", 300, 300);

            FluidProgram.CurrentOrDefault().Workpiece.AddCmdLine(doPattern);

            Pattern    pattern = new Pattern(FluidProgram.CurrentOrDefault(), "1", 200, 200);
            DotCmdLine dot1    = new DotCmdLine();

            dot1.Position.X = 200;
            dot1.Position.Y = 200;
            pattern.AddCmdLine(dot1);
            FluidProgram.CurrentOrDefault().AddPattern(pattern);



            DrawingMsgCenter.Instance.SendMsg(DrawingMessage.需要更新绘图程序, FluidProgram.CurrentOrDefault());

            DrawProgram.Instance.SetGraphics(this.g, 1);
            DrawProgram.Instance.Drawing();
        }
예제 #2
0
        private void tsiReverse_Click(object sender, EventArgs e)
        {
            if (!canOperate())
            {
                return;
            }
            var        selectedIndexs = listView1.SelectedIndices;
            List <int> selected       = new List <int>();

            for (int i = 0; i < listView1.SelectedIndices.Count; i++)
            {
                selected.Add(listView1.SelectedIndices[i]);
            }

            Dictionary <int, CmdLine> cmdLineList = new Dictionary <int, CmdLine>();
            CmdLine cmdLine = null;

            for (int i = 0; i < commandsModule.CmdLineList.Count; i++)
            {
                cmdLine = commandsModule.CmdLineList[i];
                if (commandsModule.CmdLineList[i] is EndCmdLine == false)
                {
                    cmdLine.Enabled = true;
                }
                cmdLineList.Add(i, cmdLine);
            }

            for (int i = 0; i < selectedIndexs.Count; i++)
            {
                if (cmdLineList[selectedIndexs[i]] is DoCmdLine)
                {
                    DoCmdLine doCmdLine = cmdLineList[selectedIndexs[i]] as DoCmdLine;
                    doCmdLine.Reverse = true;
                }
            }

            update(cmdLineList, false);

            for (int i = 0; i < selected.Count; i++)
            {
                this.listView1.Items[selected[i]].Selected = true;
            }

            FluidProgram.Current.Parse();
            this.UpdateDrawPanel();
        }
예제 #3
0
        private void btnOk_Click(object sender, System.EventArgs e)
        {
            if (listBoxPatterns.SelectedIndex < 0)
            {
                //MessageBox.Show("No Pattern is selected.");
                MetroSetMessageBox.Show(this, "请选择一个拼版.");
                return;
            }
            if (!tbHNums.IsValid || !tbVNums.IsValid || !tbOriginX.IsValid || !tbOriginY.IsValid ||
                !tbHEndX.IsValid || !tbHEndY.IsValid || !tbVEndX.IsValid || !tbVEndY.IsValid)
            {
                //MessageBox.Show("Please input valid values.");
                MetroSetMessageBox.Show(this, "请输入正确的参数.");
                return;
            }
            if (tbVNums.Value < 1)
            {
                //MessageBox.Show("Vertical Nums can not be smaller than 1.");
                MetroSetMessageBox.Show(this, "纵向拼版数不可以小于 1.");
                return;
            }
            if (tbHNums.Value < 1)
            {
                //MessageBox.Show("Horizontal Nums can not be smaller than 1.");
                MetroSetMessageBox.Show(this, "横向拼版个数不可以小于1.");
                return;
            }
            if (tbHNums.Value * tbVNums.Value == 1)
            {
                MetroSetMessageBox.Show(this, "拼版数量不可以等于1.");
                return;
            }
            if (tbOriginX.Value == tbHEndX.Value && tbOriginY.Value == tbHEndY.Value)
            {
                //MessageBox.Show("Origin can not be same with horizontal end.");
                if (tbVNums.Value == 1 || tbHNums.Value != 1)
                {
                    MetroSetMessageBox.Show(this, "原点坐标和横向终点坐标不可以相同");
                    return;
                }
            }
            if (tbOriginX.Value == tbVEndX.Value && tbOriginY.Value == tbVEndY.Value)
            {
                //MessageBox.Show("Origin can not be same with vertical end.");
                if (tbHNums.Value == 1 || tbVNums.Value != 1)
                {
                    MetroSetMessageBox.Show(this, "原点坐标和纵向终点坐标不可以相同");
                    return;
                }
            }
            if (tbHEndX.Value == tbVEndX.Value && tbHEndY.Value == tbVEndY.Value)
            {
                //MessageBox.Show("Horizontal end can not be same with vertical end.");
                if (tbHNums.Value != 1 && tbVNums.Value != 1)
                {
                    MetroSetMessageBox.Show(this, "横向终点和纵向终点不能相同");
                    return;
                }
            }
            stepAndRepeatCmdLine.PatternName = patternNameList[listBoxPatterns.SelectedIndex];
            //机械坐标->系统坐标
            PointD pO = this.pattern.SystemRel(tbOriginX.Value, tbOriginY.Value);
            PointD pH = this.pattern.SystemRel(tbHEndX.Value, tbHEndY.Value);
            PointD pV = this.pattern.SystemRel(tbVEndX.Value, tbVEndY.Value);

            stepAndRepeatCmdLine.Origin.X        = pO.X;
            stepAndRepeatCmdLine.Origin.Y        = pO.Y;
            stepAndRepeatCmdLine.HorizontalEnd.X = pH.X;
            stepAndRepeatCmdLine.HorizontalEnd.Y = pH.Y;
            stepAndRepeatCmdLine.VerticalEnd.X   = pV.X;
            stepAndRepeatCmdLine.VerticalEnd.Y   = pV.Y;
            stepAndRepeatCmdLine.HorizontalNums  = tbHNums.Value;
            stepAndRepeatCmdLine.VerticalNums    = tbVNums.Value;
            stepAndRepeatCmdLine.DoCmdLineList.Clear();
            foreach (PatternItem item in patternItems)
            {
                DoCmdLine doCmdLine = new DoCmdLine(stepAndRepeatCmdLine.PatternName, item.Point.X, item.Point.Y)
                {
                    Enabled = item.Enabled, Reverse = item.Reverse
                };
                doCmdLine.Valve = item.Valve;
                stepAndRepeatCmdLine.DoCmdLineList.Add(doCmdLine);
            }
            if (isCreating)
            {
                MsgCenter.Broadcast(Constants.MSG_FINISH_ADDING_CMD_LINE, this, stepAndRepeatCmdLine);
            }
            else
            {
                MsgCenter.Broadcast(Constants.MSG_FINISH_EDITING_CMD_LINE, this, stepAndRepeatCmdLine);
            }

            CompareObj.CompareField(this.stepAndRepeatCmdLine, this.stepAndRepeatCmdLineBackUp, null, this.GetType().Name, true);
            if (this.stepAndRepeatCmdLineBackUp.DoCmdLineList != null && this.stepAndRepeatCmdLine.DoCmdLineList != null)
            {
                if (this.stepAndRepeatCmdLineBackUp.DoCmdLineList.Count == this.stepAndRepeatCmdLine.DoCmdLineList.Count)
                {
                    for (int i = 0; i < this.stepAndRepeatCmdLine.DoCmdLineList.Count; i++)
                    {
                        string pathRoot = this.GetType().Name + "\\stepAndRepeatCmdLine\\DoCmdLineList";
                        CompareObj.CompareField(this.stepAndRepeatCmdLine.DoCmdLineList[i], this.stepAndRepeatCmdLineBackUp.DoCmdLineList[i], null, pathRoot, true);
                    }
                }
            }
        }
예제 #4
0
 public EditDoForm1(Pattern pattern, DoCmdLine doCmdLine) : base(pattern.GetOriginPos())
 {
     InitializeComponent();
     this.cbxValveType.Items.Add(ValveType.Valve1);
     this.cbxValveType.Items.Add(ValveType.Valve2);
     this.cbxValveType.Items.Add(ValveType.Both);
     this.pattern = pattern;
     this.origin = pattern.GetOriginPos();
     if (doCmdLine == null)
     {
         isCreating = true;
         this.doCmdLine = new DoCmdLine();
     }
     else
     {
         isCreating = false;
         this.doCmdLine = doCmdLine;
     }
     
     // patter list
     foreach (Pattern item in FluidProgram.Current.Patterns)
     {
         if (item.HasPassBlocks)
         {
             continue;
         }
         if (item.Name == this.pattern.Name) // 指令所在拼版不显示,自循环引用防呆
         {
             continue;
         }
         patternNameList.Add(item.Name);
     }
     foreach (string patternName in patternNameList)
     {
         listBoxPatterns.Items.Add(patternName);
     }
     if (isCreating)
     {
         // 新建时,默认选中第一条
         if (listBoxPatterns.Items.Count > 0)
         {
             listBoxPatterns.SelectedIndex = 0;
         }
     }
     // 选中当前patter name
     else
     {
         int index = -1;
         for (int i = 0; i < patternNameList.Count; i++)
         {
             if (patternNameList[i] == doCmdLine.PatternName)
             {
                 index = i;
                 break;
             }
         }
         if (index > -1)
         {
             listBoxPatterns.SelectedIndex = index;
         }
     }
     //系统坐标->机械坐标
     PointD p = this.pattern.MachineRel(this.doCmdLine.Origin);
     tbOriginX.Text = p.X.ToString("0.000");
     tbOriginY.Text = p.Y.ToString("0.000");
     this.ckbReverse.Checked = this.doCmdLine.Reverse;
     this.cbxValveType.SelectedItem = this.doCmdLine.Valve;
     this.txtBoardNo.Text = this.doCmdLine.BoardNo.ToString();
     if (Machine.Instance.Setting.ValveSelect == ValveSelection.单阀)
     {
         this.lblValveType.Visible = false;
         this.cbxValveType.Visible = false;
     }
     if (this.doCmdLine != null)
     {
         this.doCmdLineBackUp = (DoCmdLine)this.doCmdLine.Clone();
     }
     this.ReadLanguageResources();
 }
예제 #5
0
        /// <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);
            }
        }