コード例 #1
0
 private void drawShape(CADSpriteBatch spriteBatch, Shape s, Color col)
 {
     for (int i = 0; i < s.Points.Count; i++)
     {
         Vector2 spv = this.pointToLocation(s.Points[i]);
         Vector2 tpv = this.pointToLocation(s.Points[((i + 1) == s.Points.Count) ? 0 : i + 1]);
         spriteBatch.drawLine((int)spv.X, (int)spv.Y, (int)tpv.X, (int)tpv.Y, 1, col);
     }
 }
コード例 #2
0
        /// <summary>
        /// Draw CAD 2D Point
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="p"></param>
        private void drawPoint(CADSpriteBatch spriteBatch, Point2D p, Color col)
        {
            Vector2 spv = this.pointToLocation(p);

            spriteBatch.Draw(
                this.TexturePoint,
                new Vector2(spv.X - 2, spv.Y - 2),
                null,
                null,
                new Vector2(0, 0),
                0f,
                null,
                col,
                SpriteEffects.None,
                spriteBatch.LayerDepth
                );
        }
コード例 #3
0
        /// <summary>
        /// Draws CAD 2D Drawing Panel
        /// </summary>
        /// <param name="spriteBatch"></param>
        public void draw(CADSpriteBatch spriteBatch)
        {
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // Draw Background Color
            //
            spriteBatch.LayerDepth = this.ldBackRectangle;
            spriteBatch.drawRectangle(this.Left, this.Top, this.Width, this.Height, this.BackgroundColor);

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // Draw Grid
            //
            spriteBatch.LayerDepth = this.ldGrid;

            // Vertical
            decimal x = 0;

            while (x <= DocSizeMmX)
            {
                int xd = (int)(x * this.RatioDotsPerMm);
                spriteBatch.drawLine(
                    this.Left + xd - this.DocViewXOffset,
                    this.Top - this.DocViewYOffset,
                    this.DocSizeDotsY,
                    this.getGridColor(),
                    true
                    );
                x = x + this.gridStepMm;
            }

            // Horizontal
            decimal y = 0;

            while (y <= DocSizeMmY)
            {
                int yd = (int)(y * this.RatioDotsPerMm);
                spriteBatch.drawLine(
                    this.Left - this.DocViewXOffset,
                    this.Top + yd - this.DocViewYOffset,
                    this.DocSizeDotsX,
                    this.getGridColor()
                    );
                y = y + this.gridStepMm;
            }

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // Draw Document Content
            //

            // Draw Shapes
            spriteBatch.LayerDepth = this.ldContentShapes;
            foreach (Shape p in this.File.Shapes)
            {
                if (this.Toolbox.SelectTool.Elements.Contains(p))
                {
                    // Selected Point
                    this.drawShape(spriteBatch, p, Color.Red);
                }
                else
                {
                    this.drawShape(spriteBatch, p, Color.LightGreen);
                }
            }

            // Draw Points
            spriteBatch.LayerDepth = this.ldContentPoints;
            foreach (Point2D p in this.File.Points)
            {
                if (this.Toolbox.SelectTool.Elements.Contains(p))
                {
                    // Selected Point
                    this.drawPoint(spriteBatch, p, Color.Red);
                    spriteBatch.DrawString(
                        this.FontCanvas,
                        (this.Toolbox.SelectTool.Elements.IndexOf(p) + 1).ToString(),
                        this.pointToLocation(p) + new Vector2(5, 5),
                        Color.Red
                        );
                }
                else
                {
                    this.drawPoint(spriteBatch, p, Color.White);
                }
            }

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // Draw Machine Location
            //
            spriteBatch.LayerDepth = this.ldMachinePosition;
            if (this.Machine != null && this.TextureMachineTool != null)
            {
                Vector2 spv = this.pointToLocation(this.Machine.Position);
                spriteBatch.Draw(
                    this.TextureMachineTool,
                    new Vector2(spv.X - 12, spv.Y - 12),
                    null,
                    null,
                    new Vector2(0, 0),
                    0f,
                    null,
                    Color.White,
                    SpriteEffects.None,
                    spriteBatch.LayerDepth
                    );
            }

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // Draw Cursor Point
            //
            spriteBatch.LayerDepth = this.ldCursor;
            if (this.isCanvasHovered() || this.isCanvasPushed())
            {
                Point2D p           = this.mouseCursorToPoint(this.Mouse.CurrentState);
                string  description = String.Format("X:{0},Y:{1}", p.X, p.Y);
                Point2D sp          = this.getNearestSnapPoint(p);

                if (this.Toolbox.SelectedTool.GetType() == typeof(PointTool))
                {
                    this.drawPoint(spriteBatch, sp, Color.Green);
                }

                string snapDesc = String.Format("X:{0},Y:{1}", sp.X, sp.Y);

                spriteBatch.DrawString(
                    this.FontCanvas,
                    description,
                    new Vector2(this.Mouse.CurrentState.X + 20, this.Mouse.CurrentState.Y),
                    Color.Red,
                    0f,
                    new Vector2(0, 0),
                    new Vector2(1, 1),
                    SpriteEffects.None,
                    spriteBatch.LayerDepth
                    );

                spriteBatch.DrawString(
                    this.FontCanvas,
                    snapDesc,
                    new Vector2(this.Mouse.CurrentState.X + 20, this.Mouse.CurrentState.Y + 20),
                    Color.Green,
                    0f,
                    new Vector2(0, 0),
                    new Vector2(1, 1),
                    SpriteEffects.None,
                    spriteBatch.LayerDepth
                    );
            }

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // Draw Scroll Bars
            //
            spriteBatch.LayerDepth = this.ldScrollBars;
            // - Vertical Scroll Bar
            if (this.VerticalScrollVisible)
            {
                scrollBarVertical.draw(spriteBatch);
            }

            // - Horizontal Scroll Bar
            if (this.HorizontalScrollVisible)
            {
                scrollBarHorizontal.draw(spriteBatch);
            }
        }
コード例 #4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Creates ContentFactory
            this.cadContent = new CADContentFactory(Content);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new CADSpriteBatch(GraphicsDevice, this.cadContent);

            // Create Controls
            btnXup                 = new Button();
            btnXup.Left            = 10;
            btnXup.Top             = 10;
            btnXup.Width           = 39;
            btnXup.Height          = 39;
            btnXup.TextureDisabled = this.cadContent.imgButtonArrowDisabled;
            btnXup.TextureIdle     = this.cadContent.imgButtonArrowOff;
            btnXup.TexturePressed  = this.cadContent.imgButtonArrowOn;
            btnXup.TextureHover    = this.cadContent.imgButtonArrowHover;
            btnXup.TextureOriginX  = 19;
            btnXup.TextureOriginY  = 19;
            btnXup.TextureRotation = (float)Math.PI * 2 * 0;
            btnXup.Enabled         = true;

            btnDrillPoints                 = new Button();
            btnDrillPoints.Left            = 300;
            btnDrillPoints.Top             = 10;
            btnDrillPoints.Width           = 120;
            btnDrillPoints.Height          = 40;
            btnDrillPoints.TextOffsetY     = 12;
            btnDrillPoints.Enabled         = true;
            btnDrillPoints.Text            = "Drill Points";
            btnDrillPoints.Font            = this.cadContent.fontConsolas12;
            btnDrillPoints.FontColor       = Color.LightGreen;
            btnDrillPoints.BackGroundColor = Color.DarkGreen;

            btnDrillShapes                 = new Button();
            btnDrillShapes.Left            = 720;
            btnDrillShapes.Top             = 10;
            btnDrillShapes.Width           = 120;
            btnDrillShapes.Height          = 40;
            btnDrillShapes.TextOffsetY     = 12;
            btnDrillShapes.Enabled         = true;
            btnDrillShapes.Text            = "Drill Shapes";
            btnDrillShapes.Font            = this.cadContent.fontConsolas12;
            btnDrillShapes.FontColor       = Color.LightGreen;
            btnDrillShapes.BackGroundColor = Color.DarkGreen;

            this.sbManualSpeed                       = new ScrollBar();
            this.sbManualSpeed.Top                   = 10;
            this.sbManualSpeed.Left                  = 860;
            this.sbManualSpeed.Width                 = 200;
            this.sbManualSpeed.Height                = 25;
            this.sbManualSpeed.Value                 = 0.5f;
            this.sbManualSpeed.Enabled               = true;
            this.sbManualSpeed.Range                 = 0.1f;
            this.sbManualSpeed.TextureArrowOn        = this.cadContent.scrollArrowOn;
            this.sbManualSpeed.TextureArrowOff       = this.cadContent.scrollArrowOff;
            this.sbManualSpeed.TextureArrowHover     = this.cadContent.scrollArrowHover;
            this.sbManualSpeed.TextureArrowDisabled  = this.cadContent.scrollArrowDisabled;
            this.sbManualSpeed.TextureRangeOn        = this.cadContent.scrollRangeOn;
            this.sbManualSpeed.TextureRangeDisabled  = this.cadContent.scrollRangeDisabled;
            this.sbManualSpeed.TextureBarEdgeOn      = this.cadContent.scrollBarEdgeOn;
            this.sbManualSpeed.TextureBarEdgeOff     = this.cadContent.scrollBarEdgeOff;
            this.sbManualSpeed.TextureBarEdgeHover   = this.cadContent.scrollBarEdgeHover;
            this.sbManualSpeed.TextureBarCenterOn    = this.cadContent.scrollBarCenterOn;
            this.sbManualSpeed.TextureBarCenterOff   = this.cadContent.scrollBarCenterOff;
            this.sbManualSpeed.TextureBarCenterHover = this.cadContent.scrollBarCenterHover;

            btnGoToOrigin                 = new Button();
            btnGoToOrigin.Left            = 440;
            btnGoToOrigin.Top             = 10;
            btnGoToOrigin.Width           = 120;
            btnGoToOrigin.Height          = 40;
            btnGoToOrigin.TextOffsetY     = 12;
            btnGoToOrigin.Enabled         = true;
            btnGoToOrigin.Text            = "GoTo Origin";
            btnGoToOrigin.Font            = this.cadContent.fontConsolas12;
            btnGoToOrigin.FontColor       = Color.LightGreen;
            btnGoToOrigin.BackGroundColor = Color.DarkGreen;

            btnClearPoints                 = new Button();
            btnClearPoints.Left            = 580;
            btnClearPoints.Top             = 10;
            btnClearPoints.Width           = 120;
            btnClearPoints.Height          = 40;
            btnClearPoints.TextOffsetY     = 12;
            btnClearPoints.Enabled         = true;
            btnClearPoints.Text            = "Clear Points";
            btnClearPoints.Font            = this.cadContent.fontConsolas12;
            btnClearPoints.FontColor       = Color.LightGreen;
            btnClearPoints.BackGroundColor = Color.DarkGreen;

            // Drawing Toolbox
            this.toolbox = new Toolbox();
            this.toolbox.TextureToolSelect = this.cadContent.imgToolsSelect;
            this.toolbox.TextureToolMove   = this.cadContent.imgToolsMove;
            this.toolbox.TextureToolDelete = this.cadContent.imgToolsDelete;
            this.toolbox.TextureToolPoint  = this.cadContent.imgToolsPoint;
            this.toolbox.TextureToolShape  = this.cadContent.imgToolsShape;
            this.toolbox.Left      = 10;
            this.toolbox.Top       = 60;
            this.toolbox.LayerBase = 0.1f;
            this.toolbox.Enabled   = true;
            this.toolbox.createTools();


            // Machine
            this.machine                   = new Machine();
            this.machine.Left              = 60;
            this.machine.Top               = 10;
            this.machine.Width             = 200;
            this.machine.Height            = 40;
            this.machine.Enabled           = true;
            this.machine.ComPortName       = "COM7";
            this.machine.TextureController = this.cadContent.machineController;
            this.machine.Enabled           = true;
            try {
                this.machine.connect();
                this.machine.origin();
            } catch (MachineException) {
                this.machine.SimulationMode = true;
            }

            // Drill tool
            this.drillTool = new DrillTool(this.machine);

            // CAD Panel
            cadPanel                             = new CAD2DDrawingPanel();
            cadPanel.Left                        = 10 + 46;
            cadPanel.Top                         = 60;
            cadPanel.Width                       = config.windowSizeX - 20 - 46;
            cadPanel.Height                      = config.windowSizeY - 70;
            cadPanel.BackgroundColor             = Color.Black;
            cadPanel.ScrollSize                  = 25;
            cadPanel.LayerBase                   = 0.9f;
            cadPanel.TextureScrollArrowOn        = this.cadContent.scrollArrowOn;
            cadPanel.TextureScrollArrowOff       = this.cadContent.scrollArrowOff;
            cadPanel.TextureScrollArrowHover     = this.cadContent.scrollArrowHover;
            cadPanel.TextureScrollArrowDisabled  = this.cadContent.scrollArrowDisabled;
            cadPanel.TextureScrollRangeOn        = this.cadContent.scrollRangeOn;
            cadPanel.TextureScrollRangeDisabled  = this.cadContent.scrollRangeDisabled;
            cadPanel.TextureScrollBarEdgeOn      = this.cadContent.scrollBarEdgeOn;
            cadPanel.TextureScrollBarEdgeOff     = this.cadContent.scrollBarEdgeOff;
            cadPanel.TextureScrollBarEdgeHover   = this.cadContent.scrollBarEdgeHover;
            cadPanel.TextureScrollBarCenterOn    = this.cadContent.scrollBarCenterOn;
            cadPanel.TextureScrollBarCenterOff   = this.cadContent.scrollBarCenterOff;
            cadPanel.TextureScrollBarCenterHover = this.cadContent.scrollBarCenterHover;
            cadPanel.FontCanvas                  = this.cadContent.fontConsolas12;
            cadPanel.TexturePoint                = this.cadContent.imgPoint;
            cadPanel.TextureMachineTool          = this.cadContent.machineTool;
            cadPanel.Enabled                     = true;
            cadPanel.Machine                     = this.machine;
            cadPanel.Toolbox                     = this.toolbox;
        }