Пример #1
0
        public void SubtractDefaultFromDistinct(FlagProperties defaultFlags, Property[] defaultProperties)
        {
            var overridenFlagsPropertiesMask = defaultFlags ^ distinctFlagProperties;
            var newDistinctFlagProperties    = (distinctFlagProperties & overridenFlagsPropertiesMask) | (distinctFlagProperties & ~defaultFlags);

            if (distinctFlagProperties != newDistinctFlagProperties)
            {
                PushUndoEntry(PropertyUndoEntry.DistinctFlagPropertiesFakeId, distinctFlagProperties);
                distinctFlagProperties = newDistinctFlagProperties;
            }

            if (defaultProperties != null)
            {
                var savedDistinctMask = false;
                foreach (var prop in defaultProperties)
                {
                    if (distinctPropertyMask.IsSet(prop.Id) && properties[(int)(prop.Id - PropertyBitMask.FirstNonFlag)] == prop.Value)
                    {
                        if (!savedDistinctMask)
                        {
                            PushUndoEntry(distinctPropertyMask);
                            savedDistinctMask = true;
                        }

                        distinctPropertyMask.Clear(prop.Id);
                    }
                }
            }
        }
Пример #2
0
        public void UndoProperties(int undoLevel)
        {
            InternalDebug.Assert(undoLevel <= propertyUndoStackTop);

            for (var i = propertyUndoStackTop - 1; i >= undoLevel; i--)
            {
                if (propertyUndoStack[i].IsFlags)
                {
                    flagProperties = propertyUndoStack[i].flags.flags;
                }
                else if (propertyUndoStack[i].IsDistinctFlags)
                {
                    distinctFlagProperties = propertyUndoStack[i].flags.flags;
                }
                else if (propertyUndoStack[i].IsDistinctMask1)
                {
                    distinctPropertyMask.Set1(propertyUndoStack[i].bits.bits);
                }
                else if (propertyUndoStack[i].IsDistinctMask2)
                {
                    distinctPropertyMask.Set2(propertyUndoStack[i].bits.bits);
                }
                else
                {
                    if (propertyUndoStack[i].property.Value.IsNull)
                    {
                        propertyMask.Clear(propertyUndoStack[i].property.Id);
                    }
                    else
                    {
                        properties[(int)(propertyUndoStack[i].property.Id - PropertyBitMask.FirstNonFlag)] = propertyUndoStack[i].property.Value;
                        propertyMask.Set(propertyUndoStack[i].property.Id);
                    }
                }
            }

            propertyUndoStackTop = undoLevel;
        }
Пример #3
0
        public int ApplyProperties(FlagProperties flagProperties, Property[] propList, FlagProperties flagInheritanceMask, PropertyBitMask propertyInheritanceMask)
        {
            var undoStackPosition = propertyUndoStackTop;

            var allInheritedFlagProperties = this.flagProperties & flagInheritanceMask;

            var newEffectiveFlagProperties = allInheritedFlagProperties | flagProperties;

            if (newEffectiveFlagProperties != this.flagProperties)
            {
                PushUndoEntry(PropertyUndoEntry.FlagPropertiesFakeId, this.flagProperties);
                this.flagProperties = newEffectiveFlagProperties;
            }


            var overridenFlagsPropertiesMask = allInheritedFlagProperties ^ flagProperties;

            var newDistinctFlagProperties = (flagProperties & overridenFlagsPropertiesMask) | (flagProperties & ~allInheritedFlagProperties);

            if (newDistinctFlagProperties != distinctFlagProperties)
            {
                PushUndoEntry(PropertyUndoEntry.DistinctFlagPropertiesFakeId, distinctFlagProperties);
                distinctFlagProperties = newDistinctFlagProperties;
            }

            var maskedOutProperties = propertyMask & ~propertyInheritanceMask;

            foreach (var propId in maskedOutProperties)
            {
                PushUndoEntry(propId, properties[(int)(propId - PropertyBitMask.FirstNonFlag)]);
            }

            var newDistinctPropertyMask = PropertyBitMask.AllOff;

            propertyMask &= propertyInheritanceMask;

            if (propList != null)
            {
                foreach (var prop in propList)
                {
                    if (propertyMask.IsSet(prop.Id))
                    {
                        if (properties[(int)(prop.Id - PropertyBitMask.FirstNonFlag)] != prop.Value)
                        {
                            PushUndoEntry(prop.Id, properties[(int)(prop.Id - PropertyBitMask.FirstNonFlag)]);

                            if (prop.Value.IsNull)
                            {
                                propertyMask.Clear(prop.Id);
                            }
                            else
                            {
                                properties[(int)(prop.Id - PropertyBitMask.FirstNonFlag)] = prop.Value;
                                newDistinctPropertyMask.Set(prop.Id);
                            }
                        }
                    }
                    else if (!prop.Value.IsNull)
                    {
                        if (!maskedOutProperties.IsSet(prop.Id))
                        {
                            PushUndoEntry(prop.Id, PropertyValue.Null);
                        }

                        properties[(int)(prop.Id - PropertyBitMask.FirstNonFlag)] = prop.Value;

                        propertyMask.Set(prop.Id);

                        newDistinctPropertyMask.Set(prop.Id);
                    }
                }
            }

            if (newDistinctPropertyMask != distinctPropertyMask)
            {
                PushUndoEntry(distinctPropertyMask);
                distinctPropertyMask = newDistinctPropertyMask;
            }

            return(undoStackPosition);
        }