// Intended for transient visual objects (such as the selection-rectangle)
        public void PutTransientVisual(string Key, ContainerVisual Graphic)
        {
            var Index = this.OwnerView.ViewChildren.IndexOfMatch(child => child.Key.IsEqual(Key));

            if (Index >= 0)
            {
                this.OwnerView.ViewChildren[Index] = ViewChild.Create(Key, Graphic);
            }
            else
            {
                this.OwnerView.ViewChildren.Add(ViewChild.Create(Key, Graphic));
                this.TransientObjectsCount++;
            }
        }
        /// <summary>
        /// Adds the supplied depiction to the displayed view to the top of the specified initial-level (first time).
        /// </summary>
        public void PutVisual(VisualObject Depiction, EVisualLevel InitialLevel = EVisualLevel.Elements)
        {
            if (InitialLevel == EVisualLevel.Transients)
            {
                throw new UsageAnomaly("Transient visuals cannot be displayed via PutVisual().");
            }

            // IMPORTANT: This is required in order to do successful undos and redos.
            if (this.OwnerView.IsEditingActive && !this.OwnerView.EditEngine.IsVariating)
            {
                // Console.WriteLine("Warning: Add-visual should be applied within a Command");
                throw new UsageAnomaly("Put-visual must be applied within a Command");
            }

            // Remove adorners, if any.
            if (this.ExposedAdorners.ContainsKey(Depiction))
            {
                if (this.OwnerView.Manipulator.ExposedAdornerLayer != null)
                {
                    this.OwnerView.Manipulator.ExposedAdornerLayer.Remove(this.ExposedAdorners[Depiction]);
                }

                this.ExposedAdorners.Remove(Depiction);
            }

            var Index = this.OwnerView.ViewChildren.IndexOfMatch(reg => reg.Key.IsEqual(Depiction));

            // Refresh graphic
            Depiction.GenerateGraphic(this, true);

            // Add, Insert or Update
            var VisReg = ViewChild.Create(Depiction, Depiction.Graphic);

            if (Index < 0)
            {
                // Start ready for Elements
                var Limit = (this.OwnerView.ViewChildren.Count - (this.OwnerView.VisualCountOfFloatings + this.TransientObjectsCount)) - 1;

                if (InitialLevel == EVisualLevel.Floatings)
                {
                    this.OwnerView.VisualCountOfFloatings++;
                    Limit = (this.OwnerView.ViewChildren.Count - this.TransientObjectsCount);
                }
                else
                if (InitialLevel <= EVisualLevel.Regions)
                {
                    this.OwnerView.VisualLevelForRegions++;
                    Limit = this.OwnerView.VisualLevelForRegions;

                    if (InitialLevel <= EVisualLevel.Background)
                    {
                        this.OwnerView.VisualLevelForBackground++;
                        Limit = this.OwnerView.VisualLevelForBackground;
                    }
                }
                else
                if (InitialLevel > EVisualLevel.Regions)
                {
                    Limit = this.OwnerView.VisualLevelForRegions + 1;
                }
                else
                if (InitialLevel > EVisualLevel.Background)
                {
                    Limit = this.OwnerView.VisualLevelForBackground + 1;
                }

                if (Limit <= this.OwnerView.ViewChildren.Count - 1)
                {
                    this.OwnerView.ViewChildren.Add(null);
                    for (int ShiftIndex = this.OwnerView.ViewChildren.Count - 1; ShiftIndex > Limit; ShiftIndex--)
                    {
                        var TempShifted = this.OwnerView.ViewChildren[ShiftIndex - 1];
                        this.OwnerView.ViewChildren[ShiftIndex - 1] = null;
                        this.OwnerView.ViewChildren[ShiftIndex]     = ViewChild.Create(TempShifted);
                    }

                    this.OwnerView.ViewChildren[Limit] = VisReg;
                }
                else
                {
                    this.OwnerView.ViewChildren.Add(VisReg);
                    Index = this.OwnerView.ViewChildren.Count - 1;
                }
            }
            else
            {
                /*T var Previous = this.OwnerView.ViewChildren[Index];
                 * if (Previous.IsEqual(VisReg) || Previous == VisReg)
                 *  Console.WriteLine("VP Equal:{0}, ==:{1}", Previous.IsEqual(VisReg),  Previous == VisReg); */

                this.OwnerView.ViewChildren[Index] = VisReg;
            }

            // Add adorners, if any.
            if (this.OwnerView.RegisteredAdorners.ContainsKey(Depiction))
            {
                var Adorner = this.OwnerView.RegisteredAdorners[Depiction];

                if (this.OwnerView.Manipulator.ExposedAdornerLayer != null)
                {
                    /*+? var Preexistent = this.OwnerView.Manipulator.ExposedAdornerLayer.GetAdorners(Adorner.AdornedElement)
                     *                          .NullDefault(Enumerable.Empty<Adorner>()).Contains(Adorner);
                     * if (Preexistent)
                     *  Console.WriteLine("Preexistent");
                     * else */
                    this.OwnerView.Manipulator.ExposedAdornerLayer.Add(Adorner);
                }

                this.ExposedAdorners.Add(Depiction, Adorner);
            }

            // Set as related-visible
            Depiction.IsRelatedVisible = true;
        }
Beispiel #3
0
 public static ViewChild Create(ViewChild source)
 {
     return(new ViewChild {
         Key_ = source.Key_, Content_ = source.Content_
     });
 }