Exemplo n.º 1
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new MainForm());
     ComponentEntity component = new ComponentEntity();
 }
Exemplo n.º 2
0
 public void ParseFile(ComponentEntity _component)
 {
     component = _component;
     reader.ReadFile();
     reader.FileToList();
     reader.GetEntity(component);
 }
Exemplo n.º 3
0
        public void ParseFile(ComponentEntity currentComponent)
        {
            string fileName = string.Empty;
            var    dialog   = new OpenFileDialog();

            dialog.Filter = "Текстовые файлы|*.txt|VHDL файлы|*.vhd|DAT файлы|*.dat";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                fileName = dialog.FileName;
            }

            if (fileName.Contains("dat"))
            {
                using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate))
                {
                    BinaryFormatter formatter = new BinaryFormatter();

                    SaveImage newImage = (SaveImage)formatter.Deserialize(fs);

                    pictureBox1.Hide();
                    pictureBox2.Hide();

                    pictureBox3.BackgroundImage = newImage.bitmap;
                }
            }
            else
            {
                try
                {
                    Parser parser = new Parser(fileName);
                    parser.ParseFile(currentComponent);
                }
                catch (ArgumentException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemplo n.º 4
0
        private void DrawComponentLine(int amountOfGateIn, int amountOfGateOut, Rectangle componentRect, LineInOutX inOutX,
                                       Graphics graphics, ComponentEntity currentComponent)
        {
            List <GateNameLocation> currentListOfGateNameLocation = new List <GateNameLocation>();


            Font newFont = new Font("Arial", 9, FontStyle.Regular);

            int stepIn = componentRect.Height / (amountOfGateIn + 1);

            int currentY = componentRect.Top + stepIn;

            foreach (Gate entry in currentComponent.gateIn)
            {
                graphics.DrawLine(Pens.Black, inOutX.startOfLineInX, currentY,
                                  inOutX.endOfLineInX, currentY);

                listOfPointOfLine.Add(new Point((int)inOutX.startOfLineInX, currentY));


                if (entry.dimension > 0)
                {
                    graphics.DrawLine(Pens.Black, inOutX.startOfLineInX + (inOutX.endOfLineInX - inOutX.startOfLineInX) / 2 - 5, currentY + 5,
                                      inOutX.startOfLineInX + (inOutX.endOfLineInX - inOutX.startOfLineInX) / 2 + 5, currentY - 5);

                    graphics.DrawString(entry.dimension.ToString(), newFont, Brushes.Brown,
                                        inOutX.startOfLineInX + (inOutX.endOfLineInX - inOutX.startOfLineInX) / 2 - 5, currentY - 15);
                }



                SizeF newSize = graphics.MeasureString(entry.gateName, newFont);

                int param1 = componentRect.Left + pictureBox1.Width / 30;
                int param2 = currentY - (int)newSize.Height / 2;

                graphics.DrawString(entry.gateName, newFont, Brushes.Brown,
                                    param1, param2);

                GateNameLocation namesLocation = new GateNameLocation(entry, param1, param2,
                                                                      newSize.Width, newSize.Height);

                currentListOfGateNameLocation.Add(namesLocation);

                currentY += stepIn;
            }

            stepIn   = componentRect.Height / (amountOfGateOut + 1);
            currentY = componentRect.Top + stepIn;

            foreach (Gate entry in currentComponent.gateOut)
            {
                graphics.DrawLine(Pens.Black, inOutX.startOfLineOutX, currentY,
                                  inOutX.endOfLineOutX, currentY);

                listOfPointOfLine.Add(new Point((int)inOutX.endOfLineOutX, currentY));

                if (entry.dimension > 0)
                {
                    graphics.DrawLine(Pens.Black, inOutX.startOfLineOutX + (inOutX.endOfLineOutX - inOutX.startOfLineOutX) / 2 - 5, currentY + 5,
                                      inOutX.startOfLineOutX + (inOutX.endOfLineOutX - inOutX.startOfLineOutX) / 2 + 5, currentY - 5);

                    graphics.DrawString(entry.dimension.ToString(), newFont, Brushes.Brown,
                                        inOutX.startOfLineOutX + (inOutX.endOfLineOutX - inOutX.startOfLineOutX) / 2 - 5, currentY - 15);
                }

                SizeF newSize = graphics.MeasureString(entry.gateName, newFont);

                int param1 = componentRect.Left + componentRect.Width - (int)newSize.Width - pictureBox1.Width / 30;
                int param2 = currentY - (int)newSize.Height / 2;


                graphics.DrawString(entry.gateName, newFont, Brushes.Brown,
                                    param1, param2);

                GateNameLocation namesLocation = new GateNameLocation(entry, param1, param2,
                                                                      newSize.Width, newSize.Height);
                currentListOfGateNameLocation.Add(namesLocation);

                currentY += stepIn;
            }

            listForComponentsWithlistOfGateNameLocation.Add(currentListOfGateNameLocation);
        }
Exemplo n.º 5
0
        public void DrawComponent(PictureBox pictureBox1, ComponentEntity currentComponent)
        {
            int    pictureBoxWidth  = pictureBox1.Width;
            int    pictureBoxHeight = pictureBox1.Height;
            Bitmap bitmap           = null;

            if (listOfBitmap.Count < 2)
            {
                bitmap   = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                graphics = Graphics.FromImage(bitmap);
            }
            else
            {
                listOfBitmap[listOfPictureBox.IndexOf(pictureBox1)] = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                graphics = Graphics.FromImage(listOfBitmap[listOfPictureBox.IndexOf(pictureBox1)]);
            }

            SolidBrush backGround = new SolidBrush(Color.White);

            SolidBrush circle = new SolidBrush(Color.Black);

            graphics.FillRectangle(backGround, 0, 0, pictureBox1.Width, pictureBox1.Height);


            componentRect = new Rectangle(pictureBox1.Width / 6, pictureBox1.Height / 6,
                                          pictureBox1.Width / 6 * 4, pictureBox1.Height / 6 * 4);

            LineInOutX inOutX = new LineInOutX(0, pictureBox1.Width / 6,
                                               componentRect.Left + componentRect.Width,
                                               pictureBox1.Right);

            Font newFont = new Font("Arial", 9, FontStyle.Regular);

            SizeF newSize = graphics.MeasureString(currentComponent.componentName, newFont);

            graphics.DrawRectangle(Pens.Black, componentRect);


            graphics.DrawString(currentComponent.componentName, newFont, Brushes.Brown,
                                componentRect.Left + componentRect.Width / 2 - newSize.Width / 2,
                                componentRect.Top + componentRect.Height / 30);

            int amountOfGateIn = currentComponent.gateIn.Count();

            int amountOfGateOut = currentComponent.gateOut.Count();


            DrawComponentLine(amountOfGateIn, amountOfGateOut, componentRect, inOutX, graphics, currentComponent);


            if (startExist && endExist)
            {
                graphics.DrawLine(Pens.Black, startDrawLine, endDrawLine);
            }

            if (listOfBitmap.Count < 2)
            {
                listOfBitmap.Add(bitmap);
                pictureBox1.BackgroundImage = bitmap;
            }
            else
            {
                pictureBox1.BackgroundImage = listOfBitmap[listOfPictureBox.IndexOf(pictureBox1)];
            }
        }
Exemplo n.º 6
0
        public void GetEntity(ComponentEntity component)
        {
            int ingexOfEntity = 0;

            int indexOfPort = 0;

            int indexOfEnd = 0;

            string entityName = "";


            ingexOfEntity = listContent.IndexOf("entity");
            if (ingexOfEntity != 0)
            {
                entityName = listContent[ingexOfEntity + 1];
            }

            component.componentName = entityName;

            for (int i = 0; i < listContent.Count(); i++)
            {
                if (listContent[i].Contains("port"))
                {
                    indexOfPort = i;
                    break;
                }
            }

            indexOfEnd = listContent.IndexOf("end");

            if (indexOfPort != 0 && indexOfEnd != 0)
            {
                for (int i = indexOfPort; i < indexOfEnd; i++)
                {
                    listEntity.Add(listContent[i]);
                }
            }


            int indexOfAccessMode = 0;

            string typeOfGate = "";

            int currentPos = 0;

            string accessMode = "";

            int dimension = 0;

            while (currentPos < listEntity.Count())
            {
                if (ContainWord(currentPos, ref accessMode))
                {
                    dimension = 0;
                    GetTypeOfGate(ref currentPos, out typeOfGate, ref indexOfAccessMode, accessMode, ref dimension);

                    List <string> listCurrentGate = new List <string>();

                    GetGates(currentPos, indexOfAccessMode, listCurrentGate);

                    foreach (string entry in listCurrentGate)
                    {
                        Gate gate = new Gate(entry, typeOfGate, accessMode);

                        if (dimension > 0)
                        {
                            gate.dimension = dimension;
                        }

                        component.AddGate(gate);
                    }

                    FindNextPart(indexOfAccessMode, ref currentPos);
                }
            }
        }