Esempio n. 1
0
        public void DrawCylinder(Cylinder cyl)
        {
            System.Drawing.Graphics g = Graphics;

            // get points
            Point[] pt = TransformPoint(cyl.TopPoints);
            // bottom (draw only path)
            Brush brushSolid = new SolidBrush(cyl.ColorTop);
            g.FillPolygon(brushSolid, pt);
            Brush brushPath = new SolidBrush(cyl.ColorPath);
            Pen penPath = new Pen(brushPath);
            g.DrawPolygon(penPath, pt);
        }
        public void Draw(Graphics3DControl ctrl, Graphics3D graphics)
        {
            if (null == _dt)
                return;
            DataCase dtCase = _dt as DataCase;
            if (null != dtCase)
            {
                Box b = new Box(0, ToCase(dtCase));
                graphics.AddBox(b);
                graphics.AddDimensions(new DimensionCube(dtCase.OuterDimensions));
            }
            DataBox dtBox = _dt as DataBox;
            if (null != dtBox)
            {
                Box b = new Box(0, ToBox(dtBox));
                graphics.AddBox(b);
                graphics.AddDimensions(new DimensionCube(dtBox.Dimensions));
            }
            DataPallet dtPallet = _dt as DataPallet;
            if (null != dtPallet)
            {
                Pallet pallet = new Pallet(ToPallet(dtPallet));
                pallet.Draw(graphics, Sharp3D.Math.Core.Transform3D.Identity);
                graphics.AddDimensions(new DimensionCube(dtPallet.Dimensions));
            }
            DataInterlayer dtInterlayer = _dt as DataInterlayer;
            if (null != dtInterlayer)
            {
                graphics.AddBox(new Box(0, ToInterlayer(dtInterlayer)));
                graphics.AddDimensions(new DimensionCube(dtInterlayer.Dimensions));
            }

            DataPalletCap dtPalletCap = _dt as DataPalletCap;
            if (null != dtPalletCap)
            {
                PalletCap palletCap = new PalletCap(0, ToPalletCap(dtPalletCap), Sharp3D.Math.Core.Vector3D.Zero);
                palletCap.Draw(graphics);
                graphics.AddDimensions(new DimensionCube(dtPalletCap.Dimensions));
            }

            DataCylinder dtCylinder = _dt as DataCylinder;
            if (null != dtCylinder)
            {
                Cylinder cyl = new Cylinder(0, ToCylinder(dtCylinder));
                graphics.AddCylinder(cyl);
            }
        }
Esempio n. 3
0
        internal void Draw(Cylinder cyl)
        {
            System.Drawing.Graphics g = Graphics;

            // build pen path
            Brush brushPath    = new SolidBrush(cyl.ColorPath);
            Pen   penPathThick = new Pen(brushPath, 1.7f);
            Pen   penPathThin  = new Pen(brushPath, 1.5f);

            // bottom (draw only path)
            Point[] ptsBottom = TransformPoint(GetCurrentTransformation(), cyl.BottomPoints);
            g.DrawPolygon(penPathThick, ptsBottom);
            // top
            Point[] ptsTop = TransformPoint(GetCurrentTransformation(), cyl.TopPoints);
            g.DrawPolygon(penPathThick, ptsTop);

            // outer wall
            Face[] facesWalls = cyl.FacesWalls;
            foreach (Face face in facesWalls)
            {
                Vector3D normal = face.Normal;
                // visible ?
                if (!face.IsVisible(_vTarget - _vCameraPos))
                {
                    continue;
                }

                // color
                double cosA = System.Math.Abs(Vector3D.DotProduct(face.Normal, VLight));
                if (cosA < 0 || cosA > 1)
                {
                    cosA = 1.0;
                }
                Color color = Color.FromArgb((int)(face.ColorFill.R * cosA), (int)(face.ColorFill.G * cosA), (int)(face.ColorFill.B * cosA));
                // brush
                Brush brush = new SolidBrush(color);
                // draw polygon
                Point[] ptsFace = TransformPoint(GetCurrentTransformation(), face.Points);
                g.FillPolygon(brush, ptsFace);
            }
            // top
            double cosTop     = System.Math.Abs(Vector3D.DotProduct(HalfAxis.ToVector3D(cyl.Position.Direction), VLight));
            Color  colorTop   = Color.FromArgb((int)(cyl.ColorTop.R * cosTop), (int)(cyl.ColorTop.G * cosTop), (int)(cyl.ColorTop.B * cosTop));
            Brush  brushTop   = new SolidBrush(colorTop);
            bool   topVisible = Vector3D.DotProduct(HalfAxis.ToVector3D(cyl.Position.Direction), _vTarget - _vCameraPos) < 0;

            if (cyl.DiameterInner > 0)
            {
                Face[] facesTop = cyl.FacesTop;
                foreach (Face face in facesTop)
                {
                    Vector3D normal = face.Normal;

                    // visible ?
                    if (!face.IsVisible(_vTarget - _vCameraPos))
                    {
                        continue;
                    }
                    // color
                    // draw polygon
                    Point[] ptsFace = TransformPoint(GetCurrentTransformation(), face.Points);
                    g.FillPolygon(brushTop, ptsFace);
                }
            }
            else
            {
                if (topVisible)
                {
                    g.FillPolygon(brushTop, ptsTop);
                }
                else
                {
                    g.FillPolygon(brushTop, ptsBottom);
                }
            }

            if (topVisible)
            {
                g.DrawPolygon(penPathThin, ptsTop);
            }
            else
            {
                g.DrawPolygon(penPathThin, ptsBottom);
            }

            ++_boxDrawingCounter;
        }
Esempio n. 4
0
        /// <summary>
        /// Draw all entities stored in buffer
        /// </summary>
        public void Flush()
        {
            // initialize
            Vector3D vLight = _vCameraPos - _vTarget; vLight.Normalize();

            _boxDrawingCounter = 0;
            _currentTransf     = null;
            System.Drawing.Graphics g = Graphics;
            g.Clear(_backgroundColor);

            if (EnableFaceSorting)
            {
                // sort face list
                FaceComparison faceComparer = new FaceComparison(GetWorldToEyeTransformation());
                _faces.Sort(faceComparer);
            }
            // draw background segments
            foreach (Segment s in _segmentsBackground)
            {
                Draw(s);
            }
            // draw background faces
            foreach (Face face in _facesBackground)
            {
                Draw(face, FaceDir.FRONT);
            }
            // draw all faces using solid / transparency depending on
            foreach (Face face in _faces)
            {
                Draw(face, FaceDir.BACK);
            }

            // sort box list
            if (_useBoxelOrderer)
            {
                BoxelOrderer boxelOrderer = new BoxelOrderer(_boxes);
                boxelOrderer.Direction = _vTarget - _vCameraPos;
                _boxes = boxelOrderer.GetSortedList();
            }
            else
            {
                _boxes.Sort(new BoxComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation()));
            }

            // sort cylinder list
            _cylinders.Sort(new CylinderComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation()));

            if (_cylinders.Count > 0)
            {
                // sort by Z
                List <Drawable> drawableList = new List <Drawable>();
                drawableList.AddRange(_boxes);
                drawableList.AddRange(_cylinders);
                drawableList.Sort(new DrawableComparerSimplifiedPainterAlgo());

                List <Box>      boxes         = new List <Box>();
                List <Cylinder> cylinders     = new List <Cylinder>();
                bool            processingBox = drawableList[0] is Box;
                foreach (Drawable drawable in drawableList)
                {
                    Box      b = drawable as Box;
                    Cylinder c = drawable as Cylinder;

                    if ((null != b) && processingBox)
                    {
                        boxes.Add(b);
                    }
                    else if ((null == b) && !processingBox)
                    {
                        cylinders.Add(c);
                    }
                    else
                    {
                        if (boxes.Count > 0)
                        {
                            BoxelOrderer boxelOrderer = new BoxelOrderer(boxes);
                            boxelOrderer.Direction = _vTarget - _vCameraPos;
                            boxes = boxelOrderer.GetSortedList();
                            // draw boxes
                            foreach (Box bb in boxes)
                            {
                                Draw(bb);
                            }
                            // clear
                            boxes.Clear();
                        }
                        if (cylinders.Count > 0)
                        {
                            cylinders.Sort(new CylinderComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation()));
                            // draw cylinders
                            foreach (Cylinder cc in cylinders)
                            {
                                Draw(cc);
                            }
                            // clear
                            cylinders.Clear();
                        }
                        if (null != b)
                        {
                            boxes.Add(b);
                            processingBox = true;
                        }
                        else
                        {
                            cylinders.Add(c);
                            processingBox = false;
                        }
                    }
                }

                // remaining boxes
                BoxelOrderer boxelOrdererRem = new BoxelOrderer(boxes);
                boxelOrdererRem.Direction = _vTarget - _vCameraPos;
                boxes = boxelOrdererRem.GetSortedList();
                // draw boxes
                foreach (Box bb in boxes)
                {
                    Draw(bb);
                }

                // remaining cylinders
                cylinders.Sort(new CylinderComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation()));
                // draw cylinders
                foreach (Cylinder cc in cylinders)
                {
                    Draw(cc);
                }
                // clear
                boxes.Clear();
            }
            else
            {
                // draw all boxes
                foreach (Box box in _boxes)
                {
                    Draw(box);
                }
            }

            // draw faces : end
            foreach (Face face in _faces)
            {
                Draw(face, FaceDir.FRONT);
            }

            // draw segment list (e.g. hatching)
            foreach (Segment seg in _segments)
            {
                Draw(seg);
            }

            // draw cotation cubes
            foreach (DimensionCube qc in _dimensions)
            {
                qc.Draw(this);
            }
        }
Esempio n. 5
0
 public void AddCylinder(Cylinder cylinder)
 {
     _cylinders.Add(cylinder);
 }
Esempio n. 6
0
        private void AppendCylinderElement(CylinderProperties cylProperties, XmlElement elemAnalysis, XmlDocument xmlDoc)
        {
            string ns = xmlDoc.DocumentElement.NamespaceURI;
            // get CylinderProperties
            XmlElement elemCylinder = xmlDoc.CreateElement("cylinder", ns);
            elemAnalysis.AppendChild(elemCylinder);
            // name
            XmlElement elemName = xmlDoc.CreateElement("name", ns);
            elemName.InnerText = cylProperties.Name;
            elemCylinder.AppendChild(elemName);
            // description
            XmlElement elemDescription = xmlDoc.CreateElement("description", ns);
            elemDescription.InnerText = cylProperties.Description;
            elemCylinder.AppendChild(elemDescription);

            AppendElementValue(xmlDoc, elemCylinder, "radius", UnitsManager.UnitType.UT_LENGTH, cylProperties.RadiusOuter);
            AppendElementValue(xmlDoc, elemCylinder, "width", UnitsManager.UnitType.UT_LENGTH, cylProperties.Height);
            AppendElementValue(xmlDoc, elemCylinder, "height", UnitsManager.UnitType.UT_MASS, cylProperties.Weight);
            // --- build image
            Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail));
            graphics.CameraPosition = Graphics3D.Corner_0;
            graphics.Target = Vector3D.Zero;
            Cylinder cyl = new Cylinder(0, cylProperties);
            graphics.AddCylinder(cyl);
            DimensionCube dc = new DimensionCube(cyl.DiameterOuter, cyl.DiameterOuter, cyl.Height);   dc.FontSize = 6.0f;
            graphics.AddDimensions(dc);
            graphics.Flush();
            // ---
            // view_case_iso
            XmlElement elemImage = xmlDoc.CreateElement("view_cylinder_iso", ns);
            TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap));
            elemImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[])));
            XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style");
            styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 4, graphics.Bitmap.Height / 4);
            elemImage.Attributes.Append(styleAttribute);
            elemCylinder.AppendChild(elemImage);
            // save image
            SaveImageAs(graphics.Bitmap, "view_cylinder_iso.png");
        }
Esempio n. 7
0
        internal void Draw(Cylinder cyl)
        {
            System.Drawing.Graphics g = Graphics;

            // build pen path
            Brush brushPath = new SolidBrush(cyl.ColorPath);
            Pen penPathThick = new Pen(brushPath, 1.7f);
            Pen penPathThin = new Pen(brushPath, 1.5f);

            // bottom (draw only path)
            Point[] ptsBottom = TransformPoint(GetCurrentTransformation(), cyl.BottomPoints);
            g.DrawPolygon(penPathThick, ptsBottom);
            // top
            Point[] ptsTop = TransformPoint(GetCurrentTransformation(), cyl.TopPoints);
            g.DrawPolygon(penPathThick, ptsTop);

            // outer wall
            Face[] facesWalls = cyl.FacesWalls;
            foreach (Face face in facesWalls)
            {
                Vector3D normal = face.Normal;
                // visible ?
                if (!face.IsVisible(_vTarget - _vCameraPos))
                    continue;

                // color
                double cosA = System.Math.Abs(Vector3D.DotProduct(face.Normal, VLight));
                if (cosA < 0 || cosA > 1) cosA = 1.0;
                Color color = Color.FromArgb((int)(face.ColorFill.R * cosA), (int)(face.ColorFill.G * cosA), (int)(face.ColorFill.B * cosA));
                // brush
                Brush brush = new SolidBrush(color);
                // draw polygon
                Point[] ptsFace = TransformPoint(GetCurrentTransformation(), face.Points);
                g.FillPolygon(brush, ptsFace);
            }
            // top
            double cosTop = System.Math.Abs(Vector3D.DotProduct(HalfAxis.ToVector3D(cyl.Position.Direction), VLight));
            Color colorTop = Color.FromArgb((int)(cyl.ColorTop.R * cosTop), (int)(cyl.ColorTop.G * cosTop), (int)(cyl.ColorTop.B * cosTop));
            Brush brushTop = new SolidBrush(colorTop);
            bool topVisible = Vector3D.DotProduct(HalfAxis.ToVector3D(cyl.Position.Direction), _vTarget - _vCameraPos) < 0;

            if (cyl.DiameterInner > 0)
            {
                Face[] facesTop = cyl.FacesTop;
                foreach (Face face in facesTop)
                {
                    Vector3D normal = face.Normal;

                    // visible ?
                    if (!face.IsVisible(_vTarget - _vCameraPos))
                        continue;
                    // color
                    // draw polygon
                    Point[] ptsFace = TransformPoint(GetCurrentTransformation(), face.Points);
                    g.FillPolygon(brushTop, ptsFace);
                }
            }
            else
            {
                if (topVisible)
                    g.FillPolygon(brushTop, ptsTop);
                else
                    g.FillPolygon(brushTop, ptsBottom);
            }

            if (topVisible)
                g.DrawPolygon(penPathThin, ptsTop);
            else
                g.DrawPolygon(penPathThin, ptsBottom);

            ++_boxDrawingCounter;
        }
Esempio n. 8
0
 public void AddCylinder(Cylinder cylinder)
 {
     _cylinders.Add(cylinder);
 }
 public void Draw(Graphics3DControl ctrl, Graphics3D graphics)
 {
     CylinderProperties cylProperties = new CylinderProperties(
         null, CylinderName, Description
         , RadiusOuter, RadiusInner, CylinderHeight, Weight
         , ColorTop, ColorWallOuter, ColorWallInner);
     Cylinder cyl = new Cylinder(0, cylProperties);
     graphics.AddCylinder(cyl);
 }