Example #1
0
        private static void SampleOfOCP()
        {
            //Create shapes
            IShape        rectangle = new RectangleShape();
            IShape        square    = new SquareShape();
            DrawingShapes d         = new DrawingShapes();

            //add feature to draw rectangle
            d.AddShape(rectangle);
            //drawing images
            d.DrawImages();

            Console.WriteLine("Press Any key to Contunue the sample of OCP");
            Console.ReadKey();

            //add feature to draw square
            d.AddShape(square);

            //drawing images
            d.DrawImages();

            //try to implement another shape to see the important of this principle

            Console.ReadKey();
        }
Example #2
0
 public DataList(DrawingShapes drawing)
 {
     foreach (var item in drawing.GetListofRectangles)
     {
         listOfObjects.Add(item);
     }
     foreach (var item in drawing.GetListofCircles)
     {
         listOfObjects.Add(item);
     }
 }
Example #3
0
 protected void panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     //PAINTING
     if (IsPainting)
     {
         //check it's not at the same place it was last time,
         //saves on recording more data.
         if (LastPos != e.Location)
         {
             //set this position as the last position
             LastPos = e.Location;
             //store the position, width, colour and shape relation data
             DrawingShapes.NewShape(LastPos, CurrentWidth,
                                    CurrentColour, ShapeNum);
         }
     }
     //refresh the panel so it will be forced to re-draw.
     panel1.Refresh();
 }
Example #4
0
 private void panel1_Paint(object sender, PaintEventArgs e)
 {
     //Apply a smoothing mode to smooth out the line.
     e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
     //DRAW THE LINES
     for (int i = 0; i < DrawingShapes.NumberOfShapes() - 1; i++)
     {
         Shape T  = DrawingShapes.GetShape(i);
         Shape T1 = DrawingShapes.GetShape(i + 1);
         //make sure shape the two adjoining shape numbers are part of the same shape
         if (T.ShapeNumber == T1.ShapeNumber)
         {
             //create a new pen with its width and colour
             Pen p = new Pen(T.Colour, T.Width);
             p.StartCap = System.Drawing.Drawing2D.LineCap.Round;
             p.EndCap   = System.Drawing.Drawing2D.LineCap.Round;
             //draw a line between the two adjoining points
             e.Graphics.DrawLine(p, T.Location, T1.Location);
             //get rid of the pen when finished
             p.Dispose();
         }
     }
 }
Example #5
0
        static void Main(string[] args)
        {
            RectangleShape rect  = new RectangleShape(0, 0, 100, 100);
            RectangleShape rect1 = new RectangleShape(0, 0, 50, 50);
            RectangleShape rect2 = new RectangleShape(0, 0, 25, 25);

            Console.WriteLine($"rectangle created: {rect}");



            CircleShape circ = new OOPFinalProject.BL.CircleShape(0, 0, 80, 80);


            DrawingShapes drawingShapes1 = new DrawingShapes();



            drawingShapes1.AddToList(rect1);
            rect1 = new RectangleShape(10, 10, 666, 999);

            drawingShapes1.AddToList(rect1);

            drawingShapes1.AddToList(circ);
            circ = new CircleShape(333, 333, 1000, 1000);
            drawingShapes1.AddToList(circ);

            foreach (var rec in drawingShapes1.GetListofRectangles)
            {
                Console.WriteLine("Rectangle: " + rec.Height.ToString());
            }

            foreach (var rec in drawingShapes1.GetListofCircles)
            {
                Console.WriteLine("Circle: " + rec.Radius1.ToString());
            }



            Console.WriteLine("Number of Entities in DrawingShapes List of Rectangles =" + drawingShapes1.GetListofRectangles.Count);
            Console.WriteLine("Number of Entities in DrawingShapes List of Circles =" + drawingShapes1.GetListofCircles.Count);


            DataList dataList = new DataList(drawingShapes1);


            dataList.SerializeIt();

            dataList.listOfObjects = null;

            Console.WriteLine("lalalala");



            //Console.WriteLine("Antes do Deserialize >>> " + dataList.listOfObjects.ElementAt(0));

            dataList.DeserializeIt();

            foreach (var item in dataList.listOfObjects)
            {
                if (item is RectangleShape rec)
                {
                    Console.WriteLine($"This Rectangle Shape has Width =  {rec.Width}");
                }
                if (item is CircleShape cU)
                {
                    Console.WriteLine($"This Circle Shape has Radius =  {cU.Radius1}");
                }
            }

            rect2 = new RectangleShape(0, 0, 2222, 2222);

            drawingShapes1.AddToList(rect2);
            dataList = new DataList(drawingShapes1);

            dataList.SerializeIt();



            //Console.WriteLine("Depois do Deserialize >>> " + dataList.listOfObjects.ElementAt(0));

            //Console.WriteLine($"The Rectangle info is: {rect2.X}, {rect2.Y}, {rect2.Width}, {rect2.Height}");

            Console.ReadLine();
        }