Exemple #1
0
        private bool checkLineProximity(int indexno, int identifier, Graphics daGe)             //checks whether if the mouse pointer is on an object (i.e. shape)
        {
            Graphics g     = daGe;
            Pen      lePen = new Pen(Color.Yellow, 1);

            //g = this.CreateGraphics();

            g.TranslateTransform(8, canvasHeight + 8);                  //transforms point-of-origin to the lower left corner of the canvas.

            g.SmoothingMode = SmoothingMode.HighQuality;

            switch (identifier)                 //depending on the "identifier" value, the relevant object will be highlighted
            {
            case 2:                             //Line
            {
                Line line = (Line)drawingList[indexno];

                if (mainScale == 0)
                {
                    mainScale = 1;
                }

                if (line.Highlight(lePen, g, aPoint, mainScale))
                {
                    this.Cursor      = Cursors.Hand;
                    line.highlighted = true;
                    return(true);
                }

                break;
            }

            case 3:                             //rectangle
            {
                rectangle rect = (rectangle)drawingList[indexno];

                if (rect.Highlight(lePen, g, aPoint))
                {
                    this.Cursor      = Cursors.Hand;
                    rect.highlighted = true;
                    return(true);
                }

                break;
            }

            case 4:                             //circle
            {
                circle tempCircle = (circle)drawingList[indexno];

                if (mainScale == 0)
                {
                    mainScale = 1;
                }

                if (tempCircle.Highlight(lePen, g, aPoint, mainScale))
                {
                    this.Cursor            = Cursors.Hand;
                    tempCircle.highlighted = true;
                    return(true);
                }

                break;
            }

            case 5:                             //polyline
            {
                polyline tempPoly = (polyline)drawingList[indexno];

                if (mainScale == 0)
                {
                    mainScale = 1;
                }

                if (tempPoly.Highlight(lePen, g, aPoint, mainScale))
                {
                    this.Cursor          = Cursors.Hand;
                    tempPoly.highlighted = true;
                    return(true);
                }
                break;
            }

            case 6:                             //arc
            {
                Arc tempArc = (Arc)drawingList[indexno];

                if (mainScale == 0)
                {
                    mainScale = 1;
                }

                if (tempArc.Highlight(lePen, g, aPoint, mainScale))
                {
                    this.Cursor         = Cursors.Hand;
                    tempArc.highlighted = true;
                    return(true);
                }
                break;
            }
            }

            return(false);
        }
Exemple #2
0
        private void PolylineModule(StreamReader reader)                //Interpretes polyline objects in the DXF file
        {
            string line1, line2;

            line1 = "0";
            line2 = "0";

            double x1 = 0;
            double y1 = 0;

            //double x2= 0;
            //double y2 = 0;


            thePolyLine = new polyline(Color.White, 1);

            int ix = drawingList.Add(thePolyLine);

            objectIdentifier.Add(new DrawingObject(5, ix));

            int       counter          = 0;
            int       numberOfVertices = 1;
            int       openOrClosed     = 0;
            ArrayList pointList        = new ArrayList();


            do
            {
                GetLineCouple(reader, out line1, out line2);

                if (line1 == "90")
                {
                    numberOfVertices = Convert.ToInt32(line2);
                }

                if (line1 == "70")
                {
                    openOrClosed = Convert.ToInt32(line2);
                }


                if (line1 == "10")
                {
                    x1 = Convert.ToDouble(line2);
                    if (x1 > XMax)
                    {
                        XMax = x1;
                    }

                    if (x1 < XMin)
                    {
                        XMin = x1;
                    }
                }

                if (line1 == "20")
                {
                    y1 = Convert.ToDouble(line2);

                    if (y1 > YMax)
                    {
                        YMax = y1;
                    }

                    if (y1 < YMin)
                    {
                        YMin = y1;
                    }

                    pointList.Add(new Point((int)(x1 * importScale), (int)-(y1 * importScale)));
                    counter++;
                }
            }while(counter < numberOfVertices);

            //****************************************************************************************************//
            //***************This Part is related with the drawing editor...the data taken from the dxf file******//
            //***************is interpreted hereinafter***********************************************************//


            for (int i = 1; i < numberOfVertices; i++)
            {
                thePolyLine.AppendLine(new Line((Point)pointList[i - 1], (Point)pointList[i], Color.White, 1));
            }

            if (openOrClosed == 1)
            {
                thePolyLine.AppendLine(new Line((Point)pointList[numberOfVertices - 1], (Point)pointList[0], Color.White, 1));
            }

            if ((Math.Abs(XMax - XMin)) > canvasWidth)
            {
                scaleX = (double)(canvasWidth) / (double)(Math.Abs(XMax - XMin));
            }
            else
            {
                scaleX = 1;
            }


            if ((Math.Abs(YMax - YMin)) > canvasHeight)
            {
                scaleY = (double)(canvasHeight) / (double)(Math.Abs(YMax - YMin));
            }
            else
            {
                scaleY = 1;
            }

            mainScale = Math.Min(scaleX, scaleY);

            //////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////
        }
Exemple #3
0
        public void Draw(Graphics g)
        {
            //int xOffSet = 0;
            Pen  lePen        = new Pen(Color.White, 3);
            Size scrollOffset = new Size(this.AutoScrollPosition);

            g.TranslateTransform(1 + scrollOffset.Width, canvasHeight - 1 + scrollOffset.Height);

            if (YMin < 0)
            {
                g.TranslateTransform(0, -(int)Math.Abs(YMin));                                          //transforms point-of-origin to the lower left corner of the canvas.
            }
            if (XMin < 0)
            {
                g.TranslateTransform((int)Math.Abs(XMin), 0);
            }

            //	g.SmoothingMode = SmoothingMode.AntiAlias;

            showForks(g, lePen.Brush);

            foreach (DrawingObject obj in objectIdentifier)                                                     //iterates through the objects
            {
                switch (obj.shapeType)
                {
                case 2:                                                 //line
                {
                    Line temp = (Line)drawingList[obj.indexNo];

                    lePen.Color = temp.ContourColor;
                    lePen.Width = temp.LineWidth;


                    highlightedRegion.Location = temp.GetStartPoint;

                    highlightedRegion.Width  = temp.GetStartPoint.X - temp.GetEndPoint.X;
                    highlightedRegion.Height = temp.GetStartPoint.Y - temp.GetEndPoint.Y;
                    int centerX = (temp.GetStartPoint.X + temp.GetEndPoint.X) / 2;
                    int centerY = (temp.GetStartPoint.Y + temp.GetEndPoint.Y) / 2;
                    if (mainScale == 0)
                    {
                        mainScale = 1;
                    }

                    temp.Draw(lePen, g, mainScale);
                    g.DrawString("L" + obj.indexNo, new Font("宋体", 10), lePen.Brush, centerX, centerY);

                    break;
                }

                case 3:                                                 //rectangle
                {
                    rectangle temp = (rectangle)drawingList[obj.indexNo];

                    lePen.Color = temp.ContourColor;
                    lePen.Width = temp.LineWidth;


                    temp.Draw(lePen, g);

                    break;
                }

                case 4:                                                 //circle
                {
                    circle temp = (circle)drawingList[obj.indexNo];

                    lePen.Color = temp.ContourColor;
                    lePen.Width = temp.LineWidth;

                    if (mainScale == 0)
                    {
                        mainScale = 1;
                    }

                    temp.Draw(lePen, g, mainScale);

                    break;
                }

                case 5:                                                 //polyline
                {
                    polyline temp = (polyline)drawingList[obj.indexNo];

                    lePen.Color = temp.ContourColor;
                    lePen.Width = temp.LineWidth;

                    if (mainScale == 0)
                    {
                        mainScale = 1;
                    }

                    temp.Draw(lePen, g, mainScale);

                    break;
                }

                case 6:                                                 //arc
                {
                    Arc temp = (Arc)drawingList[obj.indexNo];

                    lePen.Color = temp.ContourColor;
                    lePen.Width = temp.LineWidth;

                    if (mainScale == 0)
                    {
                        mainScale = 1;
                    }

                    temp.Draw(lePen, g, mainScale);
                    g.DrawString("A" + obj.indexNo, new Font("宋体", 10), lePen.Brush, temp.CenterPoint);
                    break;
                }
                }
            }


            //	g.Dispose();		//not disposed because "g" is get from the paintbackground event..
            lePen.Dispose();
        }