Beispiel #1
0
        /// <summary>
        /// Register a shape for use with this object.
        /// This command is potentially slow, so should be called before time critical visual updates occur.
        /// i.e. Create and register all shapes before motion is simulated.
        /// </summary>
        /// <param name="shapeName">The name of the created shape.</param>
        /// <returns>
        /// An index to use in the other methods in this object.
        /// The index is an integer starting at 1, incremented for each shape registered.
        /// -1 for an error.
        /// </returns>
        public static Primitive ShapeIndex(Primitive shapeName)
        {
            Type            ShapesType = typeof(Shapes);
            UIElement       obj;
            RotateTransform rotateTransform;
            ScaleTransform  scaleTransform;
            Point           point;

            try
            {
                if (null == _mainCanvas)
                {
                    _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                }
                if (null == _objectsMap)
                {
                    _objectsMap = (Dictionary <string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                }
                if (null == _rotateTransformMap)
                {
                    _rotateTransformMap = (Dictionary <string, RotateTransform>)ShapesType.GetField("_rotateTransformMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                }
                if (null == _scaleTransformMap)
                {
                    _scaleTransformMap = (Dictionary <string, ScaleTransform>)ShapesType.GetField("_scaleTransformMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                }
                if (null == _positionMap)
                {
                    _positionMap = (Dictionary <string, Point>)ShapesType.GetField("_positionMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                }
                if (!_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                    return(-1);
                }
                if (!_rotateTransformMap.TryGetValue((string)shapeName, out rotateTransform))
                {
                    Shapes.Rotate(shapeName, 0);
                    Utilities.doUpdates();
                    if (!_rotateTransformMap.TryGetValue((string)shapeName, out rotateTransform))
                    {
                        return(-1);
                    }
                }
                if (!_scaleTransformMap.TryGetValue((string)shapeName, out scaleTransform))
                {
                    Shapes.Zoom(shapeName, 1, 1);
                    Utilities.doUpdates();
                    if (!_scaleTransformMap.TryGetValue((string)shapeName, out scaleTransform))
                    {
                        return(-1);
                    }
                }
                if (!_positionMap.TryGetValue((string)shapeName, out point))
                {
                    Shapes.Move(shapeName, 0, 0);
                    Utilities.doUpdates();
                    if (!_positionMap.TryGetValue((string)shapeName, out point))
                    {
                        return(-1);
                    }
                }

                ShapeProperty shapeProperty = new ShapeProperty(obj, rotateTransform, scaleTransform, point);
                shapeProperties.Add(shapeProperty);
                return(shapeProperties.Count);
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return(-1);
        }
Beispiel #2
0
        /// <summary>
        /// Register a shape for use with this object.
        /// This command is potentially slow, so should be called before time critical visual updates occur.
        /// i.e. Create and register all shapes before motion is simulated.
        /// </summary>
        /// <param name="shapeName">The name of the created shape.</param>
        /// <returns>
        /// An index to use in the other methods in this object.
        /// The index is an integer starting at 1, incremented for each shape registered.
        /// -1 for an error.
        /// </returns>
        public static Primitive ShapeIndex(Primitive shapeName)
        {
            Type ShapesType = typeof(Shapes);
            UIElement obj;
            RotateTransform rotateTransform;
            ScaleTransform scaleTransform;
            Point point;

            try
            {
                if (null == _mainCanvas) _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (null == _objectsMap) _objectsMap = (Dictionary<string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (null == _rotateTransformMap) _rotateTransformMap = (Dictionary<string, RotateTransform>)ShapesType.GetField("_rotateTransformMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (null == _scaleTransformMap) _scaleTransformMap = (Dictionary<string, ScaleTransform>)ShapesType.GetField("_scaleTransformMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (null == _positionMap) _positionMap = (Dictionary<string, Point>)ShapesType.GetField("_positionMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (!_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                    return -1;
                }
                if (!_rotateTransformMap.TryGetValue((string)shapeName, out rotateTransform))
                {
                    Shapes.Rotate(shapeName, 0);
                    Utilities.doUpdates();
                    if (!_rotateTransformMap.TryGetValue((string)shapeName, out rotateTransform)) return -1;
                }
                if (!_scaleTransformMap.TryGetValue((string)shapeName, out scaleTransform))
                {
                    Shapes.Zoom(shapeName, 1, 1);
                    Utilities.doUpdates();
                    if (!_scaleTransformMap.TryGetValue((string)shapeName, out scaleTransform)) return -1;
                }
                if (!_positionMap.TryGetValue((string)shapeName, out point))
                {
                    Shapes.Move(shapeName, 0, 0);
                    Utilities.doUpdates();
                    if (!_positionMap.TryGetValue((string)shapeName, out point)) return -1;
                }

                ShapeProperty shapeProperty = new ShapeProperty(obj, rotateTransform, scaleTransform, point);
                shapeProperties.Add(shapeProperty);
                return shapeProperties.Count;
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return -1;
        }