コード例 #1
0
        // Intended for Model related visual objects
        public void ClearVisual(VisualObject Depiction)
        {
            // IMPORTANT: This is required in order to do successful undos and redos.
            if (this.OwnerView.IsEditingActive && !this.OwnerView.EditEngine.IsVariating)
            {
                // Console.WriteLine("Warning: Remove-visual should be applied within a Command");
                throw new UsageAnomaly("Remove-visual must be applied within a Command");
            }

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

            if (Index < 0)
            {
                return;
            }

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

                this.ExposedAdorners.Remove(Depiction);
            }

            // Update levels
            var Level = this.OwnerView.GetLevelOf(Depiction);

            if (Level != null && Level.HasValue)
            {
                if (Level.Value == EVisualLevel.Floatings)
                {
                    this.OwnerView.VisualCountOfFloatings--;
                }
                else
                if (Level.Value <= EVisualLevel.Regions)
                {
                    this.OwnerView.VisualLevelForRegions--;

                    if (Level.Value <= EVisualLevel.Background)
                    {
                        this.OwnerView.VisualLevelForBackground--;
                    }
                }
            }

            // Delete visual
            this.OwnerView.ViewChildren.RemoveAt(Index);
            Depiction.IsRelatedVisible = false;
        }
コード例 #2
0
        /// <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;
        }
コード例 #3
0
 // -------------------------------------------------------------------------------------------
 /// <summary>
 /// Indicates whether the supplied visual object exists in this presenter.
 /// </summary>
 public bool HasVisualObject(VisualObject Target)
 {
     return(this.OwnerView.ViewChildren.Any(reg => reg.Key.IsEqual(Target)));
 }