Пример #1
0
 protected ITransformable GetManipulatorNode(TransformationTypes xformType)
 {
     ITransformable manipNode = null;
     var selectionCntx = DesignView.Context.As<ISelectionContext>();
     var visibilityContext = DesignView.Context.As<IVisibilityContext>();
     if (selectionCntx.LastSelected != null)
     {
         Path<object> path = selectionCntx.LastSelected.As<Path<object>>();
         foreach (object obj in path)
         {
             DomNode pathnode = obj.As<DomNode>();
             if (pathnode == null) break;
             object item = Util.AdaptDomPath(pathnode);
             if (selectionCntx.SelectionContains(item))
             {
                 var xformable = pathnode.As<ITransformable>();
                 if (xformable != null 
                     && (xformable.TransformationType & xformType) != 0
                     && visibilityContext.IsVisible(pathnode))
                 {
                     manipNode = xformable;                           
                 }
                 break;
             }
         }
     }
     return manipNode;
 }
Пример #2
0
        private void CheckScaleFlags()
        {
            ITransformable thisNode = this.As <ITransformable>();

            if (thisNode == null)
            {
                return;
            }

            // Assume that Scale is set and UniformScale is not set until we know otherwise.
            TransformationTypes newFlags = thisNode.TransformationType;

            newFlags |= TransformationTypes.Scale;
            newFlags &= ~TransformationTypes.UniformScale;

            var transformables = GetChildList <ITransformable>(Schema.transformObjectGroupType.objectChild);

            foreach (ITransformable childNode in transformables)
            {
                if ((childNode.TransformationType & TransformationTypes.Scale) == 0)
                {
                    newFlags &= ~(TransformationTypes.Scale);
                }
                if ((childNode.TransformationType & TransformationTypes.UniformScale) != 0)
                {
                    newFlags |= TransformationTypes.UniformScale;
                }
            }

            thisNode.TransformationType = newFlags;
        }
Пример #3
0
        protected ITransformable GetManipulatorNode(TransformationTypes xformType)
        {
            ITransformable manipNode         = null;
            var            selectionCntx     = DesignView.Context.As <ISelectionContext>();
            var            visibilityContext = DesignView.Context.As <IVisibilityContext>();

            if (selectionCntx.LastSelected != null)
            {
                Path <object> path = selectionCntx.LastSelected.As <Path <object> >();
                foreach (object obj in path)
                {
                    DomNode pathnode = obj.As <DomNode>();
                    if (pathnode == null)
                    {
                        break;
                    }
                    object item = Util.AdaptDomPath(pathnode);
                    if (selectionCntx.SelectionContains(item))
                    {
                        var xformable = pathnode.As <ITransformable>();
                        if (xformable != null &&
                            (xformable.TransformationType & xformType) != 0 &&
                            visibilityContext.IsVisible(pathnode))
                        {
                            manipNode = xformable;
                        }
                        break;
                    }
                }
            }
            return(manipNode);
        }
Пример #4
0
        protected ITransformable GetManipulatorNode(TransformationTypes xformType)
        {
            ITransformable manipNode         = null;
            var            selectionCntx     = DesignView.Context.As <ISelectionContext>();
            var            visibilityContext = DesignView.Context.As <IVisibilityContext>();

            if (selectionCntx.LastSelected != null)
            {
                Path <object> path = selectionCntx.LastSelected.As <Path <object> >();
                if (path != null)
                {
                    foreach (object obj in path)
                    {
                        // Check if this object actually exists in the current selection
                        // somewhere. DavidJ -- rewrote this because some controls (like
                        // the Project Lister) use a different path of path object, and as a
                        // result the old version would sometimes incorrectly fail.
                        var i = selectionCntx.Selection.Where(
                            x =>
                        {
                            var p = x.As <Path <object> >();
                            return((p != null) && (p.Last == obj));
                        }).FirstOrDefault();

                        if (i != null)
                        {
                            var xformable = obj.As <ITransformable>();
                            if (xformable != null &&
                                (xformable.TransformationType & xformType) != 0 &&
                                visibilityContext.IsVisible(obj))
                            {
                                manipNode = xformable;
                            }
                            break;
                        }
                    }
                }
            }
            return(manipNode);
        }
        /// <summary>
        /// Creates an array of property descriptors that are associated with the adapted DomNode's
        /// DomNodeType. No duplicates will be in the array (based on the property descriptor's Name
        /// property).</summary>
        /// <returns>Array of property descriptors</returns>
        protected override System.ComponentModel.PropertyDescriptor[] GetPropertyDescriptors()
        {
            // Initialize property desciptors with the ones from the base class
            // If this is not done, the new property descriptors would be used instead of
            // rather than in addition to the ones defined in the schema
            List <System.ComponentModel.PropertyDescriptor> descriptors =
                new List <System.ComponentModel.PropertyDescriptor>(base.GetPropertyDescriptors());

            // Add ITransformable properties:
            // Translation, Rotation, Scale, RotatePivot, ScalePivot (if supported by this object)

            ITransformable      node          = this.Cast <ITransformable>();
            TransformationTypes transformType = node.TransformationType;

            NumericTupleEditor tupleEditor =
                new NumericTupleEditor(typeof(float), new string[] { "x", "y", "z" });
            NumericTupleEditor rotationTupleEditor =
                new NumericTupleEditor(typeof(float), new string[] { "x", "y", "z" });

            rotationTupleEditor.ScaleFactor = 360 / (2 * Math.PI); // Radians to Degrees

            FloatArrayConverter converter         = new FloatArrayConverter();
            FloatArrayConverter rotationConverter = new FloatArrayConverter();

            rotationConverter.ScaleFactor = 360 / (2 * Math.PI); // Radians to Degrees


            string category = "Transform".Localize();

            // Check for transform types
            if ((transformType & TransformationTypes.Translation) != 0)
            {
                descriptors.Add(
                    new AttributePropertyDescriptor(
                        "Translation", Schema.gameObjectType.translateAttribute, category, "Translation of Game Object along X, Y, and Z axes".Localize(),
                        false, tupleEditor, converter));
            }

            if ((transformType & TransformationTypes.Rotation) != 0)
            {
                descriptors.Add(new AttributePropertyDescriptor(
                                    "Rotation".Localize(), Schema.gameObjectType.rotateAttribute, category,
                                    "Origin of Rotation transform relative to Game Object Translation".Localize(),
                                    false, rotationTupleEditor, rotationConverter));
            }

            if ((transformType & TransformationTypes.Scale) != 0)
            {
                if ((transformType & TransformationTypes.UniformScale) == 0)
                {
                    descriptors.Add(
                        new AttributePropertyDescriptor(
                            "Scale".Localize(),
                            Schema.gameObjectType.scaleAttribute, category,
                            "Scale of Game Object along X, Y, and Z axes".Localize(),
                            false, tupleEditor, converter));
                }
                else
                {
                    descriptors.Add(
                        new AttributePropertyDescriptor(
                            "Scale".Localize(), Schema.gameObjectType.scaleAttribute,
                            category,
                            "Scale of Game Object along X, Y, and Z axes".Localize(),
                            false, new UniformArrayEditor <Single>(), new UniformFloatArrayConverter()));
                }
            }

            if ((transformType & TransformationTypes.Pivot) != 0)
            {
                descriptors.Add(
                    new AttributePropertyDescriptor(
                        "Pivot".Localize(), Schema.gameObjectType.pivotAttribute, category,
                        "Origin of Rotation and scale transform relative to Game Object Translation".Localize(),
                        false, tupleEditor, converter));
            }


            // remove hidden properties
            HashSet <string> hiddenProps = (HashSet <string>) this.DomNode.Type.GetTag(SchemaLoader.HiddenProperties);

            if (hiddenProps != null)
            {
                List <PropertyDescriptor> removeList = new List <PropertyDescriptor>();
                foreach (AttributePropertyDescriptor propdescr in descriptors.AsIEnumerable <AttributePropertyDescriptor>())
                {
                    if (hiddenProps.Contains(propdescr.AttributeInfo.Name))
                    {
                        removeList.Add(propdescr);
                    }
                }

                foreach (PropertyDescriptor propDescr in removeList)
                {
                    descriptors.Remove(propDescr);
                }
            }


            return(descriptors.ToArray());
        }