Exemple #1
0
        private void Reset()
        {
            //Make base
            Mesh baseSlab = BuildSlab(baseLength, baseWidth, baseHeight);

            //Make column
            Mesh   column  = BuildColumn1(column1Length, column1Width, column1Height);
            double Xoffset = (((baseLength - column1Length) / 2) + column1XOffset);
            double Yoffset = (((baseWidth + column1Width) / 2) + column1YOffset);

            column.Translate(Xoffset, Yoffset, baseHeight);

            //Add Base Length Dimension
            Point3D corner1 = new Point3D(0, 0, 0);
            Plane   XY      = Plane.XY;

            XY.Origin = corner1;
            LinearDim dimLength = new LinearDim(XY, new Point3D(0, -250, 0), new Point3D(baseLength, -250, 0), new Point3D(baseLength / 2, -250, 0), 100);

            viewportLayout1.Entities.Add(dimLength);

            //Add Base Width Dimension
            Point3D corner2 = new Point3D(0, 0, 0);
            Plane   YX      = Plane.YX;

            YX.Origin = corner2;
            LinearDim dimWidth = new LinearDim(YX, new Point3D(-250, 0, 0), new Point3D(-250, baseWidth, 0), new Point3D(-250, baseWidth / 2, 0), -100);

            viewportLayout1.Entities.Add(dimWidth);

            //Add Base Height Dimension
            Point3D corner3 = new Point3D(0, 0, 0);
            Plane   ZX      = Plane.ZX;

            ZX.Origin = corner3;
            LinearDim dimHeight = new LinearDim(ZX, new Point3D(-250, 0, 0), new Point3D(-250, 0, baseHeight), new Point3D(-250, 0, baseHeight / 2), -100);

            //******* dimHeight.Billboard = true; This is actually pretty cool**********

            viewportLayout1.Entities.Add(dimHeight);

            viewportLayout1.Entities.Add(baseSlab, Color.Transparent);
            viewportLayout1.Entities.Add(column, Color.Transparent);

            viewportLayout1.Invalidate();
        }
Exemple #2
0
        public void CreateLinearDim(Model model1)
        {
            // Plane 정의(원점(0, 0, 0), 노멀백터(0, 0, 1))
            Point3D  point  = new Point3D(0, 0, 0);
            Vector3D normal = new Vector3D(0, 0, 1);
            Plane    plane  = new Plane(point, normal);

            // 치수선 위치
            Point2D extLine1   = new Point2D(5, 5);
            Point2D extLine2   = new Point2D(95, 5);
            Point2D dimLinePos = new Point2D(50, 25);

            // text 높이, 화살표 크기에도 영향
            double textHeight = 3;

            // 치수 생성
            LinearDim dim = new LinearDim(plane, extLine1, extLine2, dimLinePos, textHeight);

            model1.Entities.Add(dim, Color.Red);

            model1.Invalidate();
        }
        private Entity[] AddLinearDimsToSheet(List <Entity> toAdd, ref Sheet sheet, double unitsConversionFactor, double scale, bool addScene)
        {
            foreach (var ent in toAdd)
            {
                if (ent is LinearDim)
                {
                    LinearDim ld = (LinearDim)ent;
                    ld.Scale(unitsConversionFactor);
                    // sets the same layer as wires segments
                    ld.LayerName = drawings1.WiresLayerName;
                    // sets the linear scale as the inverted of the sheet scale factor.
                    ld.LinearScale = 1 / scale;
                }

                if (addScene)
                {
                    sheet.Entities.Add(ent);
                }
            }

            return(toAdd.ToArray());
        }
Exemple #4
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            var mousePosition = RenderContextUtility.ConvertPoint(GetMousePosition(e));

            if (DrawingLinearDim && ActionMode == actionType.None)
            {
                if (GetToolBar().Contains(mousePosition))
                {
                    base.OnMouseDown(e);

                    return;
                }

                if (e.ChangedButton == MouseButton.Left)
                {
                    if (_numPoints < 2)
                    {
                        if (_snappedPoint != null)
                        {
                            _points[_numPoints++] = _snappedPoint; // adds the snapped point to the list of points
                        }

                        if (_numPoints == 1)
                        {
                            int index = GetEntityUnderMouseCursor(_mouseLocation);
                            if (index != -1)
                            {
                                var view = Entities[index] as devDept.Eyeshot.Entities.View;
                                if (view != null)
                                {
                                    _viewScale = view.Scale;
                                }
                                else
                                {
                                    _viewScale = 1;
                                }
                            }
                        }
                    }
                    else
                    {
                        // the following lines need to add LinearDim to Drawings
                        ScreenToPlane(mousePosition, _plane, out _current);
                        double unitsConversionFactor = GetUnitsConversionFactor();
                        var    linearDim             = new LinearDim(_drawingPlane, _points[0] / unitsConversionFactor, _points[1] / unitsConversionFactor, _current / unitsConversionFactor, DimTextHeight);
                        linearDim.Scale(unitsConversionFactor);
                        linearDim.LayerName   = WiresLayerName;
                        linearDim.LinearScale = 1 / _viewScale;
                        Entities.Add(linearDim);
                        Invalidate();

                        DisableDimensioning();
                    }
                }
                else if (e.RightButton == MouseButtonState.Pressed) // restarts dimensioning
                {
                    _points    = new Point3D[3];
                    _numPoints = 0;
                    _viewScale = 1;
                }
            }

            base.OnMouseDown(e);
        }
Exemple #5
0
        public bool AreEqual(Entity ent1, Entity ent2)
        {
            if (ent1 is CompositeCurve)
            {
                CompositeCurve cc1 = (CompositeCurve)ent1;
                CompositeCurve cc2 = (CompositeCurve)ent2;

                if (cc1.CurveList.Count == cc2.CurveList.Count)
                {
                    int equalCurvesInListCount = 0;

                    foreach (Entity entC in cc1.CurveList)
                    {
                        foreach (Entity entC2 in cc2.CurveList)
                        {
                            if (entC.GetType() == entC2.GetType())
                            {
                                if (CompareIfEqual(entC, entC2))
                                {
                                    equalCurvesInListCount++;
                                    break;
                                }
                            }
                        }
                    }

                    if (cc1.CurveList.Count == equalCurvesInListCount)
                    {
                        return(true);
                    }
                }
            }

            else if (ent1 is LinearPath)
            {
                LinearPath lp1 = (LinearPath)ent1;
                LinearPath lp2 = (LinearPath)ent2;

                if (lp1.Vertices.Length == lp2.Vertices.Length)
                {
                    for (int i = 0; i < lp1.Vertices.Length; i++)
                    {
                        if (!(lp1.Vertices[i] == lp2.Vertices[i]))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            }

            else if (ent1 is PlanarEntity)
            {
                PlanarEntity pe1 = (PlanarEntity)ent1;
                PlanarEntity pe2 = (PlanarEntity)ent2;
                if (
                    pe1.Plane.AxisZ == pe2.Plane.AxisZ &&
                    pe1.Plane.AxisX == pe2.Plane.AxisX
                    )
                {
                    if (ent1 is Arc)
                    {
                        Arc arc1 = (Arc)ent1;
                        Arc arc2 = (Arc)ent2;

                        if (
                            arc1.Center == arc2.Center &&
                            arc1.Radius == arc2.Radius &&
                            arc1.Domain.Min == arc2.Domain.Min &&
                            arc1.Domain.Max == arc2.Domain.Max
                            )
                        {
                            return(true);
                        }
                    }
                    else if (ent1 is Circle)
                    {
                        Circle c1 = (Circle)ent1;
                        Circle c2 = (Circle)ent2;

                        if (
                            c1.Center == c2.Center &&
                            c1.Radius == c2.Radius
                            )
                        {
                            return(true);
                        }
                    }
                    else if (ent1 is EllipticalArc)
                    {
                        EllipticalArc e1 = (EllipticalArc)ent1;
                        EllipticalArc e2 = (EllipticalArc)ent2;

                        if (
                            e1.Center == e2.Center &&
                            e1.RadiusX == e2.RadiusX &&
                            e1.RadiusY == e2.RadiusY &&
                            e1.Domain.Low == e2.Domain.Low &&
                            e1.Domain.High == e2.Domain.High
                            )
                        {
                            return(true);
                        }
                    }
                    else if (ent1 is Ellipse)
                    {
                        Ellipse e1 = (Ellipse)ent1;
                        Ellipse e2 = (Ellipse)ent2;

                        if (
                            e1.Center == e2.Center &&
                            e1.RadiusX == e2.RadiusX &&
                            e1.RadiusY == e2.RadiusY
                            )
                        {
                            return(true);
                        }
                    }

                    else if (ent1 is Text)
                    {
                        if (ent1 is Dimension)
                        {
                            Dimension dim1 = (Dimension)ent1;
                            Dimension dim2 = (Dimension)ent2;

                            if (
                                dim1.InsertionPoint == dim2.InsertionPoint &&
                                dim1.DimLinePosition == dim2.DimLinePosition
                                )
                            {
                                if (ent1 is AngularDim)
                                {
                                    AngularDim ad1 = (AngularDim)ent1;
                                    AngularDim ad2 = (AngularDim)ent2;

                                    if (
                                        ad1.ExtLine1 == ad2.ExtLine1 &&
                                        ad1.ExtLine2 == ad2.ExtLine2 &&
                                        ad1.StartAngle == ad2.StartAngle &&
                                        ad1.EndAngle == ad2.EndAngle &&
                                        ad1.Radius == ad2.Radius
                                        )
                                    {
                                        return(true);
                                    }
                                }
                                else if (ent1 is LinearDim)
                                {
                                    LinearDim ld1 = (LinearDim)ent1;
                                    LinearDim ld2 = (LinearDim)ent2;

                                    if (
                                        ld1.ExtLine1 == ld2.ExtLine1 &&
                                        ld1.ExtLine2 == ld2.ExtLine2
                                        )
                                    {
                                        return(true);
                                    }
                                }
                                else if (ent1 is DiametricDim)
                                {
                                    DiametricDim dd1 = (DiametricDim)ent1;
                                    DiametricDim dd2 = (DiametricDim)ent2;

                                    if (
                                        dd1.Distance == dd2.Distance &&
                                        dd1.Radius == dd2.Radius &&
                                        dd1.CenterMarkSize == dd2.CenterMarkSize
                                        )
                                    {
                                        return(true);
                                    }
                                }
                                else if (ent1 is RadialDim)
                                {
                                    RadialDim rd1 = (RadialDim)ent1;
                                    RadialDim rd2 = (RadialDim)ent2;

                                    if (
                                        rd1.Radius == rd2.Radius &&
                                        rd1.CenterMarkSize == rd2.CenterMarkSize
                                        )
                                    {
                                        return(true);
                                    }
                                }
                                else if (ent1 is OrdinateDim)
                                {
                                    OrdinateDim od1 = (OrdinateDim)ent1;
                                    OrdinateDim od2 = (OrdinateDim)ent2;

                                    if (
                                        od1.DefiningPoint == od2.DefiningPoint &&
                                        od1.Origin == od2.Origin &&
                                        od1.LeaderEndPoint == od2.LeaderEndPoint
                                        )
                                    {
                                        return(true);
                                    }
                                }
                                else
                                {
                                    Console.Write("Type " + ent1.GetType() + " not implemented.");
                                    return(true);
                                }
                            }
                        }

                        else if (ent1 is devDept.Eyeshot.Entities.Attribute)
                        {
                            devDept.Eyeshot.Entities.Attribute att1 = (devDept.Eyeshot.Entities.Attribute)ent1;
                            devDept.Eyeshot.Entities.Attribute att2 = (devDept.Eyeshot.Entities.Attribute)ent2;

                            if (
                                att1.Value == att2.Value &&
                                att1.InsertionPoint == att2.InsertionPoint
                                )
                            {
                                return(true);
                            }
                        }

                        else
                        {
                            Text tx1 = (Text)ent1;
                            Text tx2 = (Text)ent2;

                            if (
                                tx1.InsertionPoint == tx2.InsertionPoint &&
                                tx1.TextString == tx2.TextString &&
                                tx1.StyleName == tx2.StyleName &&
                                tx1.WidthFactor == tx2.WidthFactor &&
                                tx1.Height == tx2.Height
                                )
                            {
                                return(true);
                            }
                        }
                    }

                    else
                    {
                        Console.Write("Type " + ent1.GetType() + " not implemented.");
                        return(true);
                    }
                }
            }

            else if (ent1 is Line)
            {
                Line line1 = (Line)ent1;
                Line line2 = (Line)ent2;

                if (
                    line1.StartPoint == line2.StartPoint &&
                    line1.EndPoint == line2.EndPoint
                    )
                {
                    return(true);
                }
            }

            else if (ent1 is devDept.Eyeshot.Entities.Point)
            {
                devDept.Eyeshot.Entities.Point point1 = (devDept.Eyeshot.Entities.Point)ent1;
                devDept.Eyeshot.Entities.Point point2 = (devDept.Eyeshot.Entities.Point)ent2;

                if (
                    point1.Position == point2.Position
                    )
                {
                    return(true);
                }
            }

#if NURBS
            else if (ent1 is Curve)
            {
                Curve cu1 = (Curve)ent1;
                Curve cu2 = (Curve)ent2;

                if (
                    cu1.ControlPoints.Length == cu2.ControlPoints.Length &&
                    cu1.KnotVector.Length == cu2.KnotVector.Length &&
                    cu1.Degree == cu2.Degree
                    )
                {
                    for (int k = 0; k < cu1.ControlPoints.Length; k++)
                    {
                        if (cu1.ControlPoints[k] != cu2.ControlPoints[k])
                        {
                            return(false);
                        }
                    }

                    for (int k = 0; k < cu1.KnotVector.Length; k++)
                    {
                        if (cu1.KnotVector[k] != cu2.KnotVector[k])
                        {
                            return(false);
                        }
                    }

                    return(true);
                }
            }
#endif

            else
            {
                Console.Write("Type " + ent1.GetType() + " not implemented.");
                return(true);
            }
            return(false);
        }
Exemple #6
0
        public void Render()
        {
            _viewportLayout.Clear();

            SetBackgroundStyleAndColor();

            // Reset grid

            double avg = (double)(_width + _length + _height) / 3;
            double fontHeight = avg / 14;
            double gridExtension = avg / 5;
            _viewportLayout.Grid = CreateGrid(gridExtension);
            int box = _viewportLayout.Layers.Add("Box", Color.DarkGray);
            var bottom = new[] {
                new Point3D(0, 0, 0),
                new Point3D(_width, 0, 0),
                new Point3D(_width, _length, 0),
                new Point3D(0, _length, 0)
            };
            var top = new[] {
                new Point3D(0, 0, _height),
                new Point3D(_width, 0, _height),
                new Point3D(_width, _length, _height),
                new Point3D(0, _length, _height)
            };
            var south = new[] {
                bottom[0], bottom[1], top[1], top[0]
            };
            var north = new[] {
                bottom[2], bottom[3], top[3], top[2]
            };
            var west = new[] {
                bottom[0], bottom[3], top[3], top[0]
            };
            var east = new[] {
                bottom[1], bottom[2], top[2], top[1]
            };
            _viewportLayout.Entities.Add(new Quad(bottom[0], bottom[1], bottom[2], bottom[3]), box, Color.Cyan);
            _viewportLayout.Entities.Add(new Quad(top[0], top[1], top[2], top[3]), box, Color.BurlyWood);
            _viewportLayout.Entities.Add(new Quad(south[0], south[1], south[2], south[3]), box, Color.Aquamarine);
            _viewportLayout.Entities.Add(new Quad(north[0], north[1], north[2], north[3]), box, Color.Chartreuse);
            _viewportLayout.Entities.Add(new Quad(west[0], west[1], west[2], west[3]), box, Color.Beige);
            _viewportLayout.Entities.Add(new Quad(east[0], east[1], east[2], east[3]), box, Color.Cornsilk);

            // Labels
            var halfHeight = _height / 2;
            _viewportLayout.Labels.Add(new LeaderAndText((south[0].X + south[1].X) / 2, south[0].Y, halfHeight, "South", new Font("Tahoma", 8.25f), Color.Black, new Vector2D(10, 10)));
            _viewportLayout.Labels.Add(new LeaderAndText((north[0].X + north[1].X) / 2, north[0].Y, halfHeight, "North", new Font("Tahoma", 8.25f), Color.Black, new Vector2D(10, 10)));
            _viewportLayout.Labels.Add(new LeaderAndText(east[0].X, (east[0].Y + east[1].Y) / 2, halfHeight, "East", new Font("Tahoma", 8.25f), Color.Black, new Vector2D(10, 10)));
            _viewportLayout.Labels.Add(new LeaderAndText(west[0].X, (west[0].Y + west[1].Y) / 2, halfHeight, "West", new Font("Tahoma", 8.25f), Color.Black, new Vector2D(10, 10)));

            _viewportLayout.Labels.Add(new LeaderAndText((top[0].X + top[2].X) / 2, (top[0].Y + top[2].Y) / 2, _height, "Top", new Font("Tahoma", 8.25f), Color.Black, new Vector2D(10, 10)));
            _viewportLayout.Labels.Add(new LeaderAndText((bottom[0].X + bottom[2].X) / 2, (bottom[0].Y + bottom[2].Y) / 2, 0, "Bottom", new Font("Tahoma", 8.25f), Color.Black, new Vector2D(10, 10)));

            // Dimensions
            //xyPlane.Rotate(Math.PI / 2, Vector3D.AxisZ, Point3D.Origin);
            //Plane dimPlane2 = Plane.YZ;
            //dimPlane2.Rotate(Math.PI / 2, Vector3D.AxisX, Point3D.Origin);

            Plane xyPlane = Plane.XY;
            var widthDim = new LinearDim(xyPlane, bottom[0], bottom[1], new Point3D(0, -gridExtension * 2, gridExtension * 2), fontHeight);
            widthDim.TextSuffix = " m";
            _viewportLayout.Entities.Add(widthDim, box, Color.Black);

            xyPlane.Rotate(Math.PI / 2, Vector3D.AxisZ, Point3D.Origin);
            var lengthDim = new LinearDim(xyPlane, bottom[1], bottom[2], new Point3D(bottom[1].X + gridExtension * 2, gridExtension * 2, gridExtension * 2), fontHeight);
            lengthDim.TextSuffix = " m";
            _viewportLayout.Entities.Add(lengthDim, box, Color.Black);

            Plane zxPlane = Plane.ZX;
            zxPlane.Rotate(Math.PI, Vector3D.AxisZ, Point3D.Origin);
            var heightDim = new LinearDim(zxPlane, bottom[1], top[1], new Point3D(bottom[1].X, gridExtension * 2, gridExtension * 2), fontHeight);
            heightDim.TextSuffix = " m";
            _viewportLayout.Entities.Add(heightDim, box, Color.Black);

            _viewportLayout.ZoomFit();
            //viewportLayout.WriteAsciiSTL("c:\\temp\\out.txt", false);
        }
Exemple #7
0
        public void Render()
        {
            _viewportLayout.Clear();

            SetBackgroundStyleAndColor();

            // Reset grid

            double avg           = (double)(_width + _length + _height) / 3;
            double fontHeight    = avg / 14;
            double gridExtension = avg / 5;

            _viewportLayout.Grid = CreateGrid(gridExtension);
            int box    = _viewportLayout.Layers.Add("Box", Color.DarkGray);
            var bottom = new[] {
                new Point3D(0, 0, 0),
                new Point3D(_width, 0, 0),
                new Point3D(_width, _length, 0),
                new Point3D(0, _length, 0)
            };
            var top = new[] {
                new Point3D(0, 0, _height),
                new Point3D(_width, 0, _height),
                new Point3D(_width, _length, _height),
                new Point3D(0, _length, _height)
            };
            var south = new[] {
                bottom[0], bottom[1], top[1], top[0]
            };
            var north = new[] {
                bottom[2], bottom[3], top[3], top[2]
            };
            var west = new[] {
                bottom[0], bottom[3], top[3], top[0]
            };
            var east = new[] {
                bottom[1], bottom[2], top[2], top[1]
            };

            _viewportLayout.Entities.Add(new Quad(bottom[0], bottom[1], bottom[2], bottom[3]), box, Color.Cyan);
            _viewportLayout.Entities.Add(new Quad(top[0], top[1], top[2], top[3]), box, Color.BurlyWood);
            _viewportLayout.Entities.Add(new Quad(south[0], south[1], south[2], south[3]), box, Color.Aquamarine);
            _viewportLayout.Entities.Add(new Quad(north[0], north[1], north[2], north[3]), box, Color.Chartreuse);
            _viewportLayout.Entities.Add(new Quad(west[0], west[1], west[2], west[3]), box, Color.Beige);
            _viewportLayout.Entities.Add(new Quad(east[0], east[1], east[2], east[3]), box, Color.Cornsilk);

            // Labels
            var halfHeight = _height / 2;

            _viewportLayout.Labels.Add(new LeaderAndText((south[0].X + south[1].X) / 2, south[0].Y, halfHeight, "South", new Font("Tahoma", 8.25f), Color.Black, new Vector2D(10, 10)));
            _viewportLayout.Labels.Add(new LeaderAndText((north[0].X + north[1].X) / 2, north[0].Y, halfHeight, "North", new Font("Tahoma", 8.25f), Color.Black, new Vector2D(10, 10)));
            _viewportLayout.Labels.Add(new LeaderAndText(east[0].X, (east[0].Y + east[1].Y) / 2, halfHeight, "East", new Font("Tahoma", 8.25f), Color.Black, new Vector2D(10, 10)));
            _viewportLayout.Labels.Add(new LeaderAndText(west[0].X, (west[0].Y + west[1].Y) / 2, halfHeight, "West", new Font("Tahoma", 8.25f), Color.Black, new Vector2D(10, 10)));

            _viewportLayout.Labels.Add(new LeaderAndText((top[0].X + top[2].X) / 2, (top[0].Y + top[2].Y) / 2, _height, "Top", new Font("Tahoma", 8.25f), Color.Black, new Vector2D(10, 10)));
            _viewportLayout.Labels.Add(new LeaderAndText((bottom[0].X + bottom[2].X) / 2, (bottom[0].Y + bottom[2].Y) / 2, 0, "Bottom", new Font("Tahoma", 8.25f), Color.Black, new Vector2D(10, 10)));

            // Dimensions
            //xyPlane.Rotate(Math.PI / 2, Vector3D.AxisZ, Point3D.Origin);
            //Plane dimPlane2 = Plane.YZ;
            //dimPlane2.Rotate(Math.PI / 2, Vector3D.AxisX, Point3D.Origin);

            Plane xyPlane  = Plane.XY;
            var   widthDim = new LinearDim(xyPlane, bottom[0], bottom[1], new Point3D(0, -gridExtension * 2, gridExtension * 2), fontHeight);

            widthDim.TextSuffix = " m";
            _viewportLayout.Entities.Add(widthDim, box, Color.Black);

            xyPlane.Rotate(Math.PI / 2, Vector3D.AxisZ, Point3D.Origin);
            var lengthDim = new LinearDim(xyPlane, bottom[1], bottom[2], new Point3D(bottom[1].X + gridExtension * 2, gridExtension * 2, gridExtension * 2), fontHeight);

            lengthDim.TextSuffix = " m";
            _viewportLayout.Entities.Add(lengthDim, box, Color.Black);

            Plane zxPlane = Plane.ZX;

            zxPlane.Rotate(Math.PI, Vector3D.AxisZ, Point3D.Origin);
            var heightDim = new LinearDim(zxPlane, bottom[1], top[1], new Point3D(bottom[1].X, gridExtension * 2, gridExtension * 2), fontHeight);

            heightDim.TextSuffix = " m";
            _viewportLayout.Entities.Add(heightDim, box, Color.Black);

            _viewportLayout.ZoomFit();
            //viewportLayout.WriteAsciiSTL("c:\\temp\\out.txt", false);
        }
Exemple #8
0
        private void RebuildChair()
        {
            string currentMatName = (currentFrameMaterial == materialEnum.Cherry) ? cherryMatName : mapleMatName;

            model1.Entities.Clear();
            model1.Labels.Clear();

            double legDepth  = 3;
            double legWidth  = 3;
            double legHeight = 56.5;

            double seatDepth  = 29;
            double seatWidth  = sizeTrackBar.Value;
            double seatHeight = 1.6;
            double seatY      = 27.4;

            //
            // Build the legs
            //
            Mesh leg1 = MakeBox(legWidth, legDepth, legHeight);
            Mesh leg4 = (Mesh)leg1.Clone();


            Mesh leg2 = MakeBox(legWidth, legDepth, seatY);
            Mesh leg3 = (Mesh)leg2.Clone();

            leg2.Translate(seatDepth - legDepth, 0, 0);
            leg3.Translate(seatDepth - legDepth, seatWidth - legWidth, 0);
            leg4.Translate(0, seatWidth - legWidth, 0);

            AddEntityWithMaterial(ref leg1, currentMatName);
            AddEntityWithMaterial(ref leg2, currentMatName);
            AddEntityWithMaterial(ref leg3, currentMatName);
            AddEntityWithMaterial(ref leg4, currentMatName);

            //
            // Build the seat
            //
            double dx             = 0.3;
            double dy             = 0.2;
            double delta          = 0.1;
            double seatPartDepth  = 4.5;
            double seatPartOffset = 0.5;

            Point3D[] seatFirstPartPoints = { new Point3D(legDepth + delta,                         0, 0),
                                              new Point3D(seatPartDepth,                            0, 0),
                                              new Point3D(seatPartDepth,    seatWidth,                 0),
                                              new Point3D(legDepth + delta, seatWidth,                 0),
                                              new Point3D(legDepth + delta, seatWidth - legWidth + dy, 0),
                                              new Point3D(-dx,              seatWidth - legWidth,      0),
                                              new Point3D(-dx,              legWidth,                  0),
                                              new Point3D(legDepth + delta, legWidth + dy,             0),
                                              new Point3D(legDepth + delta,                         0, 0) };

            Region seatFirstPart = new Region(new LinearPath(seatFirstPartPoints));
            Mesh   seatPart0     = seatFirstPart.ExtrudeAsMesh(new Vector3D(0, 0, seatHeight), 0.01, Mesh.natureType.Smooth);

            seatPart0.Translate(0, -dy, seatY);
            Mesh seatPart1 = MakeBox(seatWidth + 2 * dx, seatPartDepth, seatHeight);

            seatPart1.Translate(seatPartDepth + seatPartOffset, -dy, seatY);

            Mesh seatPart2 = (Mesh)seatPart1.Clone();

            seatPart2.Translate(seatPartDepth + seatPartOffset, 0, 0);

            Mesh seatPart3 = (Mesh)seatPart2.Clone();

            seatPart3.Translate(seatPartDepth + seatPartOffset, 0, 0);

            Mesh seatPart4 = (Mesh)seatPart3.Clone();

            seatPart4.Translate(seatPartDepth + seatPartOffset, 0, 0);

            Mesh seatPart5 = (Mesh)seatPart4.Clone();

            seatPart5.Translate(seatPartDepth + seatPartOffset, 0, 0);

            model1.Entities.Add(seatPart0, plasticMatName);
            model1.Entities.Add(seatPart1, plasticMatName);
            model1.Entities.Add(seatPart2, plasticMatName);
            model1.Entities.Add(seatPart3, plasticMatName);
            model1.Entities.Add(seatPart4, plasticMatName);
            model1.Entities.Add(seatPart5, plasticMatName);

            //
            // Build the bars under the seat
            //
            double underSeatXBarWidth  = legWidth * 0.8;
            double underSeatXBarDepth  = seatDepth - 2 * legDepth;
            double underSeatXBarHeight = 5.0;

            double underSeatYBarWidth  = seatWidth - 2 * legWidth;
            double underSeatYBarDepth  = legDepth * 0.8;
            double underSeatYBarHeight = underSeatXBarHeight;

            Mesh barUnderSeatLeft = MakeBox(underSeatXBarWidth, underSeatXBarDepth, underSeatXBarHeight);

            barUnderSeatLeft.Translate(legDepth, (legWidth - underSeatXBarWidth) / 2, seatY - underSeatXBarHeight);

            Mesh barUnderSeatRight = (Mesh)barUnderSeatLeft.Clone();

            barUnderSeatRight.Translate(0, seatWidth - legWidth, 0);

            Mesh barUnderSeatBack = MakeBox(seatWidth - 2 * legWidth, legDepth * 0.8, underSeatYBarHeight);

            barUnderSeatBack.Translate((legDepth - underSeatYBarDepth) / 2, legWidth, seatY - underSeatYBarHeight);

            Mesh barUnderSeatFront = (Mesh)barUnderSeatBack.Clone();

            barUnderSeatFront.Translate(seatDepth - legDepth, 0, 0);

            AddEntityWithMaterial(ref barUnderSeatLeft, currentMatName);
            AddEntityWithMaterial(ref barUnderSeatRight, currentMatName);
            AddEntityWithMaterial(ref barUnderSeatFront, currentMatName);
            AddEntityWithMaterial(ref barUnderSeatBack, currentMatName);

            //
            // Build the two cylinders on the sides
            //
            double CylinderRadius = legWidth / 3;
            double cylinderY      = 14.5;
            Mesh   leftCylinder   = MakeCylinder(CylinderRadius, seatDepth - 2 * legDepth, 16);

            leftCylinder.ApplyMaterial(currentMatName, textureMappingType.Cylindrical, .25, 1);
            leftCylinder.Rotate(Math.PI / 2, new Vector3D(0, 1, 0));
            leftCylinder.Translate(legDepth, legWidth / 2, cylinderY);

            model1.Entities.Add(leftCylinder);

            Mesh rightCylinder = (Mesh)leftCylinder.Clone();

            rightCylinder.Translate(0, seatWidth - legWidth, 0);

            model1.Entities.Add(rightCylinder);


            //
            //  Build the chair back
            //
            double chairBackHorizHeight = 4;
            double chairBackHorizDepth  = 2;
            double horizHeight1         = seatY + seatHeight + 7;
            Mesh   chairBackHorizontal1 = MakeBox(seatWidth - 2 * legWidth, chairBackHorizDepth, chairBackHorizHeight);

            chairBackHorizontal1.Translate((legDepth - chairBackHorizDepth) / 2.0, legWidth, horizHeight1);

            double cylinderHeight       = 12;
            double horizHeight2         = cylinderHeight + chairBackHorizHeight;
            Mesh   chairBackHorizontal2 = (Mesh)chairBackHorizontal1.Clone();

            chairBackHorizontal2.Translate(0, 0, horizHeight2);

            AddEntityWithMaterial(ref chairBackHorizontal1, currentMatName);
            AddEntityWithMaterial(ref chairBackHorizontal2, currentMatName);

            double chairBackCylinderRadius = chairBackHorizDepth / 4.0;
            double chairBackCylinderHeight = horizHeight2 - chairBackHorizHeight;
            Mesh   chairBackCylinder       = MakeCylinder(chairBackCylinderRadius, chairBackCylinderHeight, 16);

            chairBackCylinder.Translate(legDepth / 2.0, legWidth, horizHeight1 + chairBackHorizHeight);

            double chairBackWidth = seatWidth - 2 * legWidth;
            double cylinderOffset = 7;
            int    nCylinders     = (int)(chairBackWidth / cylinderOffset);
            double offset         = (chairBackWidth - (nCylinders + 1) * cylinderOffset) / 2.0;

            offset += cylinderOffset;

            for (int i = 0; i < nCylinders; i++, offset += cylinderOffset)
            {
                Mesh cyl = (Mesh)chairBackCylinder.Clone();
                cyl.ApplyMaterial(currentMatName, textureMappingType.Cylindrical, .25, 1);
                cyl.Translate(0, offset, 0);
                model1.Entities.Add(cyl);
            }

            //
            // Add the linear dimension
            //
            Point3D dimCorner = new Point3D(0, 0, legHeight);
            Plane   myPlane   = Plane.YZ;

            myPlane.Origin = dimCorner;

            LinearDim ad = new LinearDim(myPlane, new Point3D(0, 0, legHeight + 1), new Point3D(0, seatWidth, legHeight + 1), new Point3D(seatDepth + 10, seatWidth / 2, legHeight + 10), 3);

            ad.TextSuffix = " cm";
            model1.Entities.Add(ad);

            model1.Entities.UpdateBoundingBox();

            //
            // Update extents
            //
            widthTextBox.Text  = model1.Entities.BoxSize.X.ToString("f2") + " cm";
            depthTextBox.Text  = model1.Entities.BoxSize.Y.ToString("f2") + " cm";
            heightTextBox.Text = model1.Entities.BoxSize.Z.ToString("f2") + " cm";

            //
            // Update weight
            //
            double totalWeight = CalcWeight();

            weightTextBox.Text = totalWeight.ToString("f2") + " kg";

            //
            // Product ID label
            //
            devDept.Eyeshot.Labels.LeaderAndText prodIdLabel = new LeaderAndText(seatDepth / 2, seatWidth, 25, "Product ID goes here", new Font("Tahoma", 8.25f), System.Drawing.Color.Black, new Vector2D(20, 0));
            model1.Labels.Add(prodIdLabel);
        }
Exemple #9
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            var mousePos = RenderContextUtility.ConvertPoint(GetMousePosition(e));

            this.selEntityIndex = GetEntityUnderMouseCursor(mousePos);

            if (waitingForSelection)
            {
                if (this.selEntityIndex != -1)
                {
                    if (selEntity == null || drawingAngularDim)
                    {
                        this.selEntity = this.Entities[selEntityIndex];
                        if (activeOperationLabel != "")
                        {
                            this.selEntity.Selected = true;
                        }
                    }

                    // drawingAngularDim from lines needs more than one selection
                    if (!drawingAngularDim || this.Entities[selEntityIndex] is Arc)
                    {
                        waitingForSelection = false;
                    }
                }
            }

            if (GetToolBar().Contains(mousePos))
            {
                base.OnMouseDown(e);

                return;
            }

            #region Handle LMB Clicks
            if (ActionMode == actionType.None && e.ChangedButton == MouseButton.Left)
            {
                // we need to skip adding points for entity selection click
                editingMode = doingOffset || doingMirror || doingExtend || doingTrim || doingFillet || doingChamfer || doingTangents;

                ScreenToPlane(mousePos, plane, out current);

                if (objectSnapEnabled && snapPoint != null)
                {
                    if (!(editingMode && firstClick))
                    {
                        points.Add(snapPoint);
                    }
                }
                else if (IsPolygonClosed())//control needed to close curve and polyline when cursor is near the starting point of polyline or curve
                {
                    //if the distance from current point and first point stored is less than given threshold
                    points.Add((Point3D)points[0].Clone()); //the point to add to points is the first point stored.
                    current = (Point3D)points[0].Clone();
                }
                else if (gridSnapEnabled)
                {
                    if (!(editingMode && firstClick))
                    {
                        SnapToGrid(ref current);
                        points.Add(current);
                    }
                }
                else
                {
                    if (!(editingMode && firstClick))
                    {
                        points.Add(current);
                    }
                }
                firstClick = false;

                // If drawing points, create and add new point entity on each LMB click
                if (drawingPoints)
                {
                    devDept.Eyeshot.Entities.Point point;

                    if (objectSnapEnabled && snapPoint != null)
                    {
                        point = new devDept.Eyeshot.Entities.Point(snap);
                    }
                    else
                    {
                        point = new devDept.Eyeshot.Entities.Point(current);
                    }

                    AddAndRefresh(point, ActiveLayerName);
                }
                else if (drawingText)
                {
                    devDept.Eyeshot.Entities.Text text = new Text(current, "Sample Text", 5);
                    AddAndRefresh(text, ActiveLayerName);
                }
                else if (drawingLeader)
                {
                    if (points.Count == 3)
                    {
                        Leader leader = new Leader(Plane.XY, points);
                        leader.ArrowheadSize = 3;
                        AddAndRefresh(leader, ActiveLayerName);
                        devDept.Eyeshot.Entities.Text text = new Text((Point3D)current.Clone(), "Sample Text", leader.ArrowheadSize);
                        AddAndRefresh(text, ActiveLayerName);

                        drawingLeader = false;
                    }
                }
                // If LINE drawing is finished, create and add line entity to model
                else if (drawingLine && points.Count == 2)
                {
                    Line line = new Line(points[0], points[1]);
                    AddAndRefresh(line, ActiveLayerName);
                    drawingLine = false;
                }
                // If CIRCLE drawing is finished, create and add a circle entity to model
                else if (drawingCircle && points.Count == 2)
                {
                    Circle circle = new Circle(drawingPlane, drawingPlane.Origin, radius);
                    AddAndRefresh(circle, ActiveLayerName);

                    drawingCircle = false;
                }
                // If ARC drawing is finished, create and add an arc entity to model
                // Input - Center and two end points
                else if (drawingArc && points.Count == 3)
                {
                    Arc arc = new Arc(drawingPlane, drawingPlane.Origin, radius, 0, arcSpanAngle);
                    AddAndRefresh(arc, ActiveLayerName);

                    drawingArc = false;
                }
                // If drawing ellipse, create and add ellipse entity to model
                // Inputs - Ellipse center, End of first axis, End of second axis
                else if (drawingEllipse && points.Count == 3)
                {
                    Ellipse ellipse = new Ellipse(drawingPlane, drawingPlane.Origin, radius, radiusY);
                    AddAndRefresh(ellipse, ActiveLayerName);

                    drawingEllipse = false;
                }
                // If EllipticalArc drawing is finished, create and add EllipticalArc entity to model
                // Input - Ellipse center, End of first axis, End of second axis, end point
                else if (drawingEllipticalArc && points.Count == 4)
                {
                    EllipticalArc ellipticalArc = new EllipticalArc(drawingPlane, drawingPlane.Origin, radius, radiusY, 0, arcSpanAngle, true);
                    AddAndRefresh(ellipticalArc, ActiveLayerName);

                    drawingEllipticalArc = false;
                }
                else if (drawingLinearDim && points.Count == 3)
                {
                    LinearDim linearDim = new LinearDim(drawingPlane, points[0], points[1], current, dimTextHeight);
                    AddAndRefresh(linearDim, ActiveLayerName);

                    drawingLinearDim = false;
                }
                else if (drawingAlignedDim && points.Count == 3)
                {
                    LinearDim alignedDim = new LinearDim(drawingPlane, points[0], points[1], current, dimTextHeight);
                    AddAndRefresh(alignedDim, ActiveLayerName);

                    drawingAlignedDim = false;
                }
                else if (drawingOrdinateDim && points.Count == 2)
                {
                    OrdinateDim ordinateDim = new OrdinateDim(Plane.XY, points[0], points[1], drawingOrdinateDimVertical, dimTextHeight);
                    AddAndRefresh(ordinateDim, ActiveLayerName);

                    drawingOrdinateDim = false;
                }
                else if ((drawingRadialDim || drawingDiametricDim) && points.Count == 2)
                {
                    if (selEntity is Circle)
                    {
                        Circle circle = selEntity as Circle;

                        // ensures that radialDim plane has always the correct normal
                        Circle orientedCircle = new Circle(Plane.XY, circle.Center, circle.Radius);

                        if (drawingRadialDim)
                        {
                            RadialDim radialDim = new RadialDim(orientedCircle, points[points.Count - 1], dimTextHeight);
                            AddAndRefresh(radialDim, ActiveLayerName);
                            drawingRadialDim = false;
                        }
                        else
                        {
                            DiametricDim diametricDim = new DiametricDim(orientedCircle, points[points.Count - 1], dimTextHeight);
                            AddAndRefresh(diametricDim, ActiveLayerName);
                            drawingDiametricDim = false;
                        }
                    }
                }
                else if (drawingAngularDim)
                {
                    if (!drawingAngularDimFromLines)
                    {
                        if (selEntity is Arc && points.Count == 2 && !drawingQuadrantPoint)
                        {
                            Arc     arc        = selEntity as Arc;
                            Plane   myPlane    = (Plane)arc.Plane.Clone();
                            Point3D startPoint = arc.StartPoint;
                            Point3D endPoint   = arc.EndPoint;

                            // checks if the Arc is clockwise
                            if (Utility.IsOrientedClockwise(arc.Vertices))
                            {
                                myPlane.Flip();
                                startPoint = arc.EndPoint;
                                endPoint   = arc.StartPoint;
                            }

                            AngularDim angularDim = new AngularDim(myPlane, startPoint, endPoint, points[points.Count - 1], dimTextHeight);

                            angularDim.TextSuffix = "°";

                            AddAndRefresh(angularDim, ActiveLayerName);
                            drawingAngularDim = false;
                        }
                    }

                    // If it's not time to set quadrantPoint, adds the lines for angular dim
                    if (selEntity is Line && !drawingQuadrantPoint && quadrantPoint == null)
                    {
                        Line selectedLine = (Line)selEntity;

                        if (firstLine == null)
                        {
                            firstLine = selectedLine;
                        }
                        else if (secondLine == null && !ReferenceEquals(firstLine, selectedLine))
                        {
                            secondLine           = selectedLine;
                            drawingQuadrantPoint = true;
                            // resets points to get only the quadrant point and text position point
                            points.Clear();
                        }

                        drawingAngularDimFromLines = true;
                    }
                    else if (drawingQuadrantPoint)
                    {
                        ScreenToPlane(mousePos, plane, out quadrantPoint);
                        drawingQuadrantPoint = false;
                    }
                    //if all parameters are present, gets angular dim
                    else if (points.Count == 2 && quadrantPoint != null)
                    {
                        AngularDim angularDim = new AngularDim(plane, (Line)firstLine.Clone(), (Line)secondLine.Clone(), quadrantPoint, points[points.Count - 1], dimTextHeight);

                        angularDim.TextSuffix = "°";

                        AddAndRefresh(angularDim, ActiveLayerName);

                        drawingAngularDim          = false;
                        drawingAngularDimFromLines = false;
                    }
                }
                else if (doingOffset && points.Count == 1)
                {
                    CreateOffsetEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingMirror && points.Count == 2 && selEntity != null)
                {
                    CreateMirrorEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingExtend && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    ExtendEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingTrim && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    TrimEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingFillet && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    CreateFilletEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingChamfer && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    CreateChamferEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingTangents && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    CreateTangentEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingMove && points.Count == 2)
                {
                    if (points.Count == 2)
                    {
                        foreach (Entity ent in this.selEntities)
                        {
                            Vector3D movement = new Vector3D(points[0], points[1]);
                            ent.Translate(movement);
                        }

                        Entities.Regen();
                        ClearAllPreviousCommandData();
                    }
                }
                else if (doingRotate)
                {
                    if (points.Count == 3)
                    {
                        foreach (Entity ent in this.selEntities)
                        {
                            ent.Rotate(arcSpanAngle, Vector3D.AxisZ, points[0]);
                        }

                        Entities.Regen();
                        ClearAllPreviousCommandData();
                    }
                }
                else if (doingScale)
                {
                    if (points.Count == 3)
                    {
                        foreach (Entity ent in this.selEntities)
                        {
                            ent.Scale(points[0], scaleFactor);
                        }

                        Entities.Regen();
                        ClearAllPreviousCommandData();
                    }
                }
            }
            #endregion

            #region Handle RMB Clicks
            else if (e.ChangedButton == MouseButton.Right)
            {
                ScreenToPlane(mousePos, plane, out current);

                if (drawingPoints)
                {
                    points.Clear();
                    drawingPoints = false;
                }
                else if (drawingText)
                {
                    drawingText = false;
                }
                else if (drawingLeader)
                {
                    drawingLeader = false;
                }

                // If drawing polyline, create and add LinearPath entity to model
                else if (drawingPolyLine)
                {
                    LinearPath lp = new LinearPath(points);
                    AddAndRefresh(lp, ActiveLayerName);

                    drawingPolyLine = false;
                }
                // If drawing spline, create and add curve entity to model
                else if (drawingCurve)
                {
#if NURBS
                    Curve curve = Curve.CubicSplineInterpolation(points);
                    AddAndRefresh(curve, ActiveLayerName);
#endif
                    drawingCurve = false;
                }
                else
                {
                    ClearAllPreviousCommandData();
                }
            }
            #endregion

            base.OnMouseDown(e);
        }