Example #1
0
        /// <summary>
        /// Sets the Symbol-Format Property/Text-Format Value for the specified Instance and Key.
        /// </summary>
        public static void SetValue(VisualElement Instance, string PropertyKey, object Value)
        {
            object GlobalValue              = null;
            bool   ValuesAreDifferent       = false;
            MModelPropertyDefinitor PropDef = null;
            var StorageKey = PropertyKey;

            if (PropertyKey.StartsWith(TEXTFORMAT_PREFIX))
            {
                var TxtFormat = Instance.OwnerRepresentation.RepresentedIdea.IdeaDefinitor.DefaultSymbolFormat
                                .GetTextFormat((ETextPurpose)Enum.Parse(typeof(ETextPurpose), PropertyKey.Substring(1)));
                GlobalValue        = TxtFormat;
                ValuesAreDifferent = !TxtFormat.IsEquivalentTo((TextFormat)Value);
            }
            else
            {
                VisualElementFormat DefaultFormat = null;

                if (Instance is VisualSymbol)
                {
                    PropDef       = VisualSymbolFormat.__ClassDefinitor.GetPropertyDef(PropertyKey);
                    DefaultFormat = Instance.OwnerRepresentation.RepresentedIdea.IdeaDefinitor.DefaultSymbolFormat;
                }
                else
                {
                    PropDef       = VisualConnectorsFormat.__ClassDefinitor.GetPropertyDef(PropertyKey);
                    DefaultFormat = ((RelationshipVisualRepresentation)Instance.OwnerRepresentation).RepresentedRelationship
                                    .RelationshipDefinitor.Value.DefaultConnectorsFormat;
                }

                GlobalValue        = PropDef.Read(DefaultFormat);
                ValuesAreDifferent = (GlobalValue != Value);
            }

            // Do not do this concatenation for Visual-Symbol to not loose users' (stock) already stored formatting.
            if (Instance is VisualConnector)
            {
                StorageKey = VisualConnector.__ClassDefinitor.TechName + "." + PropertyKey; // Avoids ambiguity between VisualElementFormat descendants
            }
            if (ValuesAreDifferent)
            {
                if (Value != null && PropDef != null && PropDef.IsStoreBoxBased)
                {
                    Value = StoreBox.CreateStoreBoxForType(PropDef.DataType, Value);
                }

                Instance.OwnerRepresentation.CustomFormatValues.AddOrReplace(StorageKey, Value);
            }
            else
            {
                Instance.OwnerRepresentation.CustomFormatValues.Remove(StorageKey);
            }
        }
Example #2
0
        /// <summary>
        /// Gets the Element-Format Property/Text-Format value for the specified Instance and Key.
        /// </summary>
        public static object GetValue(VisualElement Instance, string PropertyKey)
        {
            object Result = null;
            MModelPropertyDefinitor PropDef       = null;
            VisualElementFormat     DefaultFormat = null;
            var StorageKey = PropertyKey;

            if (!PropertyKey.StartsWith(TEXTFORMAT_PREFIX))
            {
                if (Instance is VisualSymbol)
                {
                    PropDef       = VisualSymbolFormat.__ClassDefinitor.GetPropertyDef(PropertyKey);
                    DefaultFormat = Instance.OwnerRepresentation.RepresentedIdea.IdeaDefinitor.DefaultSymbolFormat;
                }
                else
                {
                    PropDef       = VisualConnectorsFormat.__ClassDefinitor.GetPropertyDef(PropertyKey);
                    DefaultFormat = ((RelationshipVisualRepresentation)Instance.OwnerRepresentation).RepresentedRelationship
                                    .RelationshipDefinitor.Value.DefaultConnectorsFormat;
                }

                // Do not do this concatenation for Visual-Symbol to not loose users' (stock) already stored formatting.
                if (Instance is VisualConnector)
                {
                    StorageKey = VisualConnector.__ClassDefinitor.TechName + "." + PropertyKey; // Avoids ambiguity between VisualElementFormat descendants
                }
            }

            if (Instance.OwnerRepresentation.CustomFormatValues.ContainsKey(StorageKey))
            {
                Result = Instance.OwnerRepresentation.CustomFormatValues[StorageKey];

                if (Result != null && PropDef != null && PropDef.IsStoreBoxBased)
                {
                    Result = ((StoreBoxBase)Result).StoredObject;
                }
            }
            else
            if (PropertyKey.StartsWith(TEXTFORMAT_PREFIX))
            {
                Result = Instance.OwnerRepresentation.RepresentedIdea.IdeaDefinitor.DefaultSymbolFormat
                         .GetTextFormat((ETextPurpose)Enum.Parse(typeof(ETextPurpose), PropertyKey.Substring(1)));
            }
            else
            {
                Result = PropDef.Read(DefaultFormat);
            }

            return(Result);
        }