Esempio n. 1
0
        public static ICollection <Graphic> GetGraphics(IDesignFace iDesignFace, PointUV pointUV, double span, double position, HandleTypeEnum handleType)
        {
            Debug.Assert(iDesignFace != null);

            Window activeWindow = Window.ActiveWindow;
            var    graphics     = new List <Graphic>();

            var primitives = new List <Primitive>();

            SurfaceEvaluation eval   = iDesignFace.Shape.Geometry.Evaluate(pointUV);
            Point             point  = eval.Point;
            Direction         normal = eval.Normal;

            double pixelSize      = activeWindow.ActiveContext.GetPixelSize(point);
            double shaftDiameter  = 4 * pixelSize;
            double handleDiameter = 8 * pixelSize;
            double handleHeight   = 4 * pixelSize;

            Point  startPoint          = point - (normal * (span * (position + 1) / 2 - handleHeight));
            Point  endPoint            = startPoint + normal * (span + 2 * handleHeight);
            Vector handleHalfThickness = normal * handleHeight / 2;

            bool isDrawingAll = handleType == HandleTypeEnum.All;
            var  mesh         = new List <Primitive>();
            var  style        = new GraphicStyle
            {
                EnableDepthBuffer = true,
                LineColor         = Color.DimGray,
                LineWidth         = 1,
                FillColor         = Color.DimGray
            };

            switch (handleType)
            {
            case HandleTypeEnum.All:
            case HandleTypeEnum.Shaft:
                mesh.AddRange(ShapeHelper.CreateCylinderMesh(startPoint, endPoint, shaftDiameter, 8));
                graphics.Add(Graphic.Create(style, mesh));

                if (isDrawingAll)
                {
                    goto case HandleTypeEnum.Base;
                }
                else
                {
                    break;
                }

            case HandleTypeEnum.Base:
                mesh.AddRange(ShapeHelper.CreateCylinderMesh(point - handleHalfThickness, point + handleHalfThickness, handleDiameter, 12));
                style.LineColor = Color.DodgerBlue;
                style.FillColor = Color.DodgerBlue;
                graphics.Add(Graphic.Create(style, mesh));

                if (isDrawingAll)
                {
                    goto case HandleTypeEnum.Start;
                }
                else
                {
                    break;
                }

            case HandleTypeEnum.Start:
                mesh.AddRange(ShapeHelper.CreateCylinderMesh(startPoint - handleHalfThickness, startPoint + handleHalfThickness, handleDiameter, 12));
                style.LineColor = Color.DarkViolet;
                style.FillColor = Color.DarkViolet;
                graphics.Add(Graphic.Create(style, mesh));

                if (isDrawingAll)
                {
                    goto case HandleTypeEnum.End;
                }
                else
                {
                    break;
                }

            case HandleTypeEnum.End:
                mesh.AddRange(ShapeHelper.CreateCylinderMesh(endPoint - handleHalfThickness, endPoint + handleHalfThickness, handleDiameter, 12));
                style.LineColor = Color.DarkViolet;
                style.FillColor = Color.DarkViolet;
                graphics.Add(Graphic.Create(style, mesh));

                break;
            }

            return(graphics);
        }