Esempio n. 1
0
        void cell_Paint(object sender, PaintEventArgs e)
        {
            if (init && !disposed && !Disposing && !IsDesigner)
            {
                Control cell      = (Control)sender;
                string  shapeName = (string)cell.Tag;
                if (string.IsNullOrEmpty(shapeName))
                {
                    return;
                }
                int           index   = layoutPanel.Controls.IndexOf(cell);
                PosShape      shape   = PosShape.GetPosShape(shapeName);
                List <string> lengths = new List <string>();
                if (pieceLengths.TryGetValue(index, out lengths) && (lengths.Count == 6))
                {
                    shape.SetShapeTexts(lengths[0], lengths[1], lengths[2], lengths[3], lengths[4], lengths[5]);
                }

                using (Bitmap bmp = shape.ToBitmap(device, view, model, CellBackColor, mCellSize.Width, mCellSize.Height))
                {
                    e.Graphics.DrawImageUnscaled(bmp, 0, 0);
                }

                shape.ClearShapeTexts();

                if (ShowShapeNames)
                {
                    using (Brush brush = new SolidBrush(IsDark(CellBackColor) ? Color.White : Color.Black))
                    {
                        e.Graphics.DrawString(shapeName, Font, brush, 4, 6);
                    }
                }

                if (mSelectedShape == shapeName)
                {
                    using (Pen pen = new Pen(mSelectionColor, 2.0f))
                    {
                        Rectangle rec = new Rectangle(0, 0, mCellSize.Width, mCellSize.Height);
                        rec.Inflate(-2, -2);
                        e.Graphics.DrawRectangle(pen, rec);
                    }
                }
            }
        }
Esempio n. 2
0
        public void SetShape(string shapeName)
        {
            SuspendUpdate();
            ClearItems();
            mShapeName = shapeName;

            if (!string.IsNullOrEmpty(mShapeName))
            {
                PosShape shape = PosShape.GetPosShape(shapeName);
                if (shape != null)
                {
                    PosShape shapeCopy = shape.Clone() as PosShape;
                    shapeCopy.ClearShapeTexts();
                    AddItem(shapeCopy);
                }
            }

            ResumeUpdate();
        }
Esempio n. 3
0
        public override bool WorldDraw(Drawable drawable, WorldDraw wd)
        {
            if (wd.RegenAbort || wd.IsDragging)
            {
                return(base.WorldDraw(drawable, wd));
            }

            RebarPos pos = drawable as RebarPos;

            if (pos == null)
            {
                return(base.WorldDraw(drawable, wd));
            }

            PosShape  shape    = PosShape.GetPosShape(pos.Shape);
            Extents3d?shapeExt = shape.Bounds;

            if (!shapeExt.HasValue)
            {
                return(base.WorldDraw(drawable, wd));
            }
            Extents3d ext = shapeExt.Value;

            WorldGeometry   g     = wd.Geometry;
            SubEntityTraits s     = wd.SubEntityTraits;
            TextStyle       style = new TextStyle();

            // Get geometry
            Point3d  pt   = pos.BasePoint;
            Vector3d dir  = pos.DirectionVector;
            Vector3d up   = pos.UpVector;
            Vector3d norm = pos.NormalVector;

            double w = pos.Width / dir.Length;
            double h = pos.Height / dir.Length;

            // Draw bound dimension lines
            foreach (RebarPos.BoundDimension dim in pos.GetBoundDimensions())
            {
                Line line = new Line(dim.TextPosition, pos.BasePoint);
                g.Draw(line);
            }

            // Draw shape
            double xmin = ext.MinPoint.X, ymin = ext.MinPoint.Y, xmax = ext.MaxPoint.X, ymax = ext.MaxPoint.Y;

            // Scale
            double scale = 0.025;
            // Client offsets
            double xoff = (w - scale * (xmax - xmin)) / 2.0;
            double yoff = 2.0 * h;//(h - scale * (ymax - ymin)) / 2.0;

            // Transform
            Matrix3d trans = Matrix3d.AlignCoordinateSystem(new Point3d(xmin, ymin, 0), Vector3d.XAxis / scale, Vector3d.YAxis / scale, Vector3d.ZAxis / scale, pt + dir * xoff + up * yoff, dir, up, norm);

            g.PushModelTransform(trans);

            // Draw shapes
            shape.SetShapeTexts(pos.A, pos.B, pos.C, pos.D, pos.E, pos.F);
            g.Draw(shape);
            shape.ClearShapeTexts();

            // Reset transform
            g.PopModelTransform();

            return(base.WorldDraw(drawable, wd));
        }