示例#1
0
        /// <summary>
        /// 화면에 마우스를 클릭할 때 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        /**
         * @brief 화면에 마우스를 클릭하는 이벤트의 Handler
         * @author 김효상
         * @date 2016-01-28
         * @remark 객체가 선택된 상태에서 마우스 오른쪽 클릭시, 메뉴 표시. 메뉴를 선택시 해당하는 기능의 함수로 연결.
         */
        protected void MouseDownHandler(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            int x = drag_off_x = e.X;
            int y = drag_off_y = e.Y;

            // 마우스 왼쪽 클릭
            if (e.Button == MouseButtons.Left)
            {
                /**
                 * @brief Zoom In/Out 상태에서 그림을 그릴 때, 화면의 좌표를 실제 좌표로 연산
                 * @author 장한결
                 * @date 2019-04-30
                 */
                //**************************//
                x = zoomControl.Real_X(x);  //
                y = zoomControl.Real_Y(y);  //
                //**************************//

                //박성식 배경이 두번 눌린거면 선택도구 취소하도록한다.
                if ((doc.getCurrentTool() == FIGURE.ARROW) || (doc.getCurrentTool() == FIGURE.BOX))
                {
                    pushedFigure = doc.findFigureAt(x, y);
                }
                if (e.Clicks == 2 && doc.findFigureAt(x, y) == null)
                {
                    // if double clicked,
                    switch (doc.getCurrentTool())
                    {
                    case FIGURE.ARROW:
                    case FIGURE.BOX:
                    case FIGURE.LINE:
                    case FIGURE.RECT:
                    case FIGURE.OVAL:
                    case FIGURE.FREELINE:
                    case FIGURE.CURVE:
                    case FIGURE.TEXT:
                    case FIGURE.FILL:
                        doc.setCurrentTool(FIGURE.ARROW);
                        break;

                    // polyline은 안쓰는 코드로 보인다.
                    //case FIGURE.POLYLINE:
                    //    doc.setIsMultSel(false);
                    //    // Poly라인의 경우 만 처리
                    //    if (doc.getCurrentFigure() != null)
                    //    {
                    //        // 스택에 현재까지의 상태를 저장
                    //        doc.pushStack();
                    //        doc.addObject(doc.getCurrentFigure());
                    //        doc.setCurrentFigure(null);
                    //    }
                    //  break;
                    default:
                        break;
                    }
                    GetDocument().UpdateAllViews();
                }
                else if (e.Button == MouseButtons.Right && doc.getDrawingFiguresCount() > 0)
                {
                    //오른쪽 클릭을 했을 때, 선택된 객체가 존재한다면 메뉴를 띄운다.
                    zIndexMenu.Show(this, e.Location);
                }
                else
                {
                    Color currentColor = doc.getCurrentColor();

                    switch (doc.getCurrentTool())
                    {
                    case FIGURE.ARROW:
                        if (e.Button == MouseButtons.Left && ModifierKeys == Keys.Control)
                        {
                            doc.setIsMultSel(true);
                        }
                        else
                        {
                            doc.setIsMultSel(false);
                        }
                        if (doc.getIsMultSel() == false)
                        {
                            // 모든 객체의 선택을 해재한다. (오직 한개만 선택되어야 하기 때문)
                            doc.deselectAll();
                            // 모든 객체에서 눌려진 좌표에 해당되는 객체를 찾는다.
                            doc.refreshDrawingFigure(doc.findFigureAt(x, y));
                            if (doc.getCurrentFigure() != null)
                            {
                                // 선택한다.
                                doc.getCurrentFigure().select();
                            }
                        }
                        else
                        {
                            // 모든 객체에서 눌려진 좌표에 해당되는 객체를 찾는다.
                            doc.refreshDrawingFigure(doc.findFigureAt(x, y));
                            if (doc.getDrawingFiguresCount() > 0)
                            {
                                // 선택한다.
                                doc.getCurrentFigure(doc.getDrawingFiguresCount() - 1).select();
                            }
                        }
                        break;

                    case FIGURE.BOX:
                        if (doc.findFigureAt(x, y) != null)
                        {
                            doc.setIsMultSel(true);
                        }
                        else
                        {
                            doc.setIsMultSel(false);
                            doc.refreshDrawingFigure(new Selection(x, y, x, y));
                        }
                        break;

                    case FIGURE.LINE:
                        doc.setIsMultSel(false);
                        // line 객체를 만든다.
                        doc.refreshDrawingFigure(new LineFigure(x, y, x, y, currentColor));
                        break;

                    case FIGURE.RECT:
                        doc.setIsMultSel(false);
                        // rect 객체를 만든다.
                        doc.refreshDrawingFigure(new RectFigure(x, y, x, y, currentColor));
                        break;

                    case FIGURE.OVAL:
                        doc.setIsMultSel(false);
                        // 타원객체를 만든다.
                        doc.refreshDrawingFigure(new OvalFigure(x, y, x, y, currentColor));
                        break;

                    case FIGURE.FREELINE:
                        doc.setIsMultSel(false);
                        // 자유선 객체를 만든다.
                        doc.refreshDrawingFigure(new FreeLineFigure(x, y, currentColor));
                        break;

                    case FIGURE.POLYLINE:
                        doc.setIsMultSel(false);
                        // poly 객체를 만든다.
                        if (doc.getCurrentFigure() == null)
                        {
                            doc.refreshDrawingFigure(new PolyLineFigure(x, y, currentColor));
                        }
                        else
                        {
                            doc.getCurrentFigure().add(new Pos(x, y));
                        }
                        break;

                    /*
                     * case FIGURE.CURVE:
                     *  // 곡선객체를 만든다.
                     *  figure = new CurveFigure(x, y,currentColor);
                     *  break;
                     */
                    case FIGURE.TEXT:
                        break;

                    case FIGURE.ERASE:
                        doc.setIsMultSel(false);
                        doc.deselectAll();
                        // 모든 객체에서 눌려진 좌표에 해당되는 객체를 찾는다.
                        doc.refreshDrawingFigure(doc.findFigureAt(x, y));
                        if (doc.getCurrentFigure() != null)
                        {
                            doc.removeOriginalFigure(doc.getCurrentFigure());
                        }
                        break;

                    //**********************************************************
                    //이름 : 박성식 [16-07-17]
                    //내용 : 피규어를 찾고 해당 피규어의 채우기 여부,색을 바꾼다.
                    //이유 : 그래야 paint함수에서 채우기 됨
                    //document의 현재 색으로 채운다.
                    //setcurrentcolor는 선그릴때도 사용되는 거라 수정이 필요할듯 보인다.
                    case FIGURE.FILL:
                        Figure f = doc.findFigureAt(x, y);
                        if (f != null)
                        {
                            f.fill(doc.getCurrentColor());
                        }
                        break;

                    default:
                        break;
                        //********************************************************
                    }
                    this.Capture = true;
                    doc.UpdateAllViews();
                }
            }
            // 마우스 오른쪽 클릭
            else
            {
                /**
                 * @brief 화면 이동 시작
                 * @author 장한결([email protected])
                 * @date 2019-04-30
                 */
                zoomControl.Anchoring_screen(x, y);
            }
        }
示例#2
0
        /**
         * @brief View에 그리는 이벤트의 Handler
         * @author 불명(김효상 확인)
         * @date 불명(2017-01-22 확인)
         * @param sender 사용되지 않음
         * @param e paint 이벤트에 대한 정보
         */
        protected void PaintHandler(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            /**
             * @brief: Canvas 크기를 고정. Canvas에 배경 이미지를 bitmap 형식으로 받을 수 있게 수정. 기존 코드는 주석 처리.
             * @Author: 장한결([email protected])
             * @data: 2019-05-12
             */
            int    Width        = 1028;
            int    Height       = 1024;
            Bitmap Canvas       = GetDocument().getBackground();
            float  screen_ratio = (float)Height / (float)Width;
            float  bitmap_ratio = (float)Canvas.Height / (float)Canvas.Width;

            //Bitmap Canvas = new Bitmap(Width, Height, e.Graphics);
            Graphics g = Graphics.FromImage(Canvas);
            //Graphics g = e.Graphics;

            /*
             * // draw all objects
             * //Graphics g = this.CreateGraphics ();
             * g.FillRectangle(
             *                  new SolidBrush(Color.White),
             *                  0,0,Width, Height);
             */


            int size = GetDocument().getObjectSize();

            for (int i = 0; i < size; i++)
            {
                Figure f = (Figure)doc.getObjectElementAt(i);
                f.paint(g);
            }
            if (doc.getCurrentFigure() != null)
            {
                doc.getCurrentFigure().paint(g);
                foreach (Figure f in doc.getHigherZFigures(doc.getCurrentFigure()))
                {
                    f.paint(g);
                }
            }
            g.Dispose();

            /**
             * @brief Zoom In/Out과 화면 이동을 반영하여 출력
             * @author 장한결([email protected])
             * @date 2019-04-30
             */
            Graphics g2 = e.Graphics;

            g2.Transform = zoomControl.mat;

            /**
             * @brief: 배경화면의 옵션을 적용해서 출력하는 코드. 출력방식을 e.Graphics.DrawImageUnscaled에서 DrawImage로 변경
             * @author: 장한결([email protected])
             * @date: 2019-05-12
             */
            Rectangle srcRect;
            Rectangle destRect;

            switch (doc.bgOption)
            {
            case 1:
            default:
                srcRect  = new Rectangle(0, 0, Canvas.Width, Canvas.Height);
                destRect = new Rectangle(0, 0, Width, Height);
                break;

            case 2:
                if (screen_ratio > bitmap_ratio)
                {
                    srcRect  = new Rectangle(0, 0, Canvas.Width, Canvas.Height);
                    destRect = new Rectangle(0, 0, Width, (int)(Width * bitmap_ratio));
                }
                else
                {
                    srcRect  = new Rectangle(0, 0, Canvas.Width, Canvas.Height);
                    destRect = new Rectangle(0, 0, (int)(Height / bitmap_ratio), Height);
                }
                break;

            case 3:
                if (screen_ratio > bitmap_ratio)
                {
                    int temp_width = (int)(Canvas.Height / screen_ratio);
                    srcRect  = new Rectangle((Canvas.Width - temp_width) / 2, 0, temp_width, Canvas.Height);
                    destRect = new Rectangle(0, 0, Width, Height);
                }
                else
                {
                    int temp_height = (int)(Canvas.Width * screen_ratio);
                    srcRect  = new Rectangle(0, (Canvas.Height - temp_height) / 2, Canvas.Width, temp_height);
                    destRect = new Rectangle(0, 0, Width, Height);
                }
                break;
            }
            e.Graphics.DrawImage(Canvas, destRect, srcRect, GraphicsUnit.Pixel);

            Canvas.Dispose();
        }
示例#3
0
        /**
         * @brief 화면에서 마우스 클릭을 떼는 이벤트의 Handler
         * @author 불명(김효상 확인)
         * @date 불명(2017-01-22 확인)
         * @param sender 사용되지 않음
         * @param e Mouse 이벤트에 대한 정보
         * @code
         * this.Capture = false;
         *
         *              switch(doc.getCurrentTool())
         *              {
         *      case FIGURE.ARROW:
         *          if (e.Button == MouseButtons.Left && ModifierKeys == Keys.Control) doc.setIsMultSel(true);
         *          else doc.setIsMultSel(false);
         *          isChanged =false;
         *                              break;
         *          //Select상태일 때 마우스를 떼면 Select객체를 임시 저장하고 객체를 doc에서
         *          //null로 바꾼 뒤 Figlist에 포함되는 Figure들을 저장한다.
         *          //그리고 Tool상태는 MULTISEL로 바꾼다. (**수정필요**)
         *      case FIGURE.SELECT:
         *          if (!doc.getIsMultSel())
         *          {
         *              Selection temp = (Selection)doc.getCurrentFigure();
         *              doc.setCurrentFigure(null);
         *              doc.setIsMultSel(true);
         *              doc.selectFigures(temp);
         *              doc.UpdateAllViews();
         *          }
         *          break;
         *                      case FIGURE.LINE:
         *                      case FIGURE.RECT:
         *                      case FIGURE.OVAL:
         *                      case FIGURE.FREELINE:
         *                      case FIGURE.CURVE:
         *          doc.setIsMultSel(false);
         *          if (doc.getCurrentFigure()==null)
         *                              {
         *                                      return;
         *                              }
         *                              // 객체가 비어있는지 검사.
         *                              if(doc.getCurrentFigure().isEmpty()!=true)
         *                              {
         *                                      // 스택에 현재까지의 상태를 저장
         *                                      doc.pushStack();
         *
         *                                      // Document 에 추가
         *                                      doc.addObject(doc.getCurrentFigure());
         *                                      doc.setCurrentFigure(null);
         *                              }
         *                              doc.UpdateAllViews();
         *          //((Form1)MdiParent).debugText.Text = doc.getObjectSize() + "";
         *                              break;
         *                      case FIGURE.POLYLINE:
         *                              break;
         *                      case FIGURE.TEXT:
         *                              break;
         *                      default:
         *                              break;
         *              }
         * @endcode
         */
        protected void MouseUpHandler(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            this.Capture = false;
            pushedFigure = null;

            // 마우스 왼쪽 버튼 이벤트
            if (e.Button == MouseButtons.Left)
            {
                switch (doc.getCurrentTool())
                {
                case FIGURE.ARROW:
                    if (e.Button == MouseButtons.Left && ModifierKeys == Keys.Control)
                    {
                        doc.setIsMultSel(true);
                    }
                    else
                    {
                        doc.setIsMultSel(false);
                    }
                    isChanged = false;
                    break;

                //Select상태일 때 마우스를 떼면 Select객체를 임시 저장하고 객체를 doc에서
                //null로 바꾼 뒤 Figlist에 포함되는 Figure들을 저장한다.
                //그리고 Tool상태는 MULTISEL로 바꾼다. (**수정필요**)
                case FIGURE.BOX:
                    if (!doc.getIsMultSel())
                    {
                        Selection temp = (Selection)doc.getCurrentFigure();
                        doc.refreshDrawingFigure(null);
                        doc.setIsMultSel(true);
                        doc.selectFigures(temp);
                        doc.UpdateAllViews();
                    }
                    break;

                case FIGURE.LINE:
                case FIGURE.RECT:
                case FIGURE.OVAL:
                case FIGURE.FREELINE:
                case FIGURE.CURVE:
                    doc.setIsMultSel(false);
                    if (doc.getCurrentFigure() == null)
                    {
                        return;
                    }
                    // 객체가 비어있는지 검사.
                    if (doc.getCurrentFigure().isEmpty() != true)
                    {
                        // 스택에 현재까지의 상태를 저장
                        doc.makeSnapshot();

                        // Document 에 추가
                        doc.addFigure(doc.getCurrentFigure());
                        doc.refreshDrawingFigure(null);
                    }
                    doc.UpdateAllViews();
                    //((Form1)MdiParent).debugText.Text = doc.getObjectSize() + "";
                    break;

                case FIGURE.POLYLINE:
                    break;

                case FIGURE.TEXT:
                    break;

                default:
                    break;
                }
            }
            // 마우스 오른쪽 버튼 이벤트
            else
            {
                /**
                 * @brief 화면 이동 종료
                 * @author 장한결([email protected])
                 * @date 2019-04-30
                 */
                if (e.Button == MouseButtons.Right)
                {
                    zoomControl.Releasing_screen();
                }
            }
        }
示例#4
0
 /**
  * @brief objList에 Figure를 추가한다.
  * @details Document의 objList에 새로운 도형을 추가하기 위해서 사용된다.
  * @param figure 추가하고자 하는 Figure
  */
 public void addFigure(Figure figure)
 {
     drawnFigures.Add(figure);
 }