#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Collections.Generic; using System.Drawing; using System.Linq; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.Visualization; namespace HeuristicLab.EvolutionaryTracking.Views.Primitives { // a class representing a primitive group with an area defined by the LowerLeft and UpperRight points // the area is important for deciding which group was selected and for layouting public class PrimitiveGroup : Group, ILayoutNode { // two points to determine the area of the primitive group private PointF lowerLeft; public PointF LowerLeft { get { return lowerLeft; } set { lowerLeft = value; } } private PointF upperRight; public PointF UpperRight { get { return upperRight; } set { upperRight = value; } } public PrimitiveGroup(IChart chart) : base(chart) { lowerLeft = new PointF(); upperRight = new PointF(); } public SizeF Size { get { return new SizeF(upperRight.X - lowerLeft.X, upperRight.Y - lowerLeft.Y); } } public void UpdateBounds() { // update corner points var primitives = Primitives.Where(p => p is RectangularPrimitiveBase).Cast().ToList(); var xmin = (float)primitives.Min(p => p.LowerLeft.X); var ymin = (float)primitives.Min(p => p.LowerLeft.Y); LowerLeft = new PointF(xmin, ymin); var xmax = (float)primitives.Max(p => p.UpperRight.X); var ymax = (float)primitives.Max(p => p.UpperRight.Y); UpperRight = new PointF(xmax, ymax); } public override void AddRange(IEnumerable primitives) { foreach (var primitive in primitives) Add(primitive); } public override void Move(Offset delta) { base.Move(delta); UpdateBounds(); } public bool IsLeaf { get { return Children == null || Children.Count == 0; } } public ILayoutNode NextLeft { get { return Children == null ? Thread : Children.First(); } } public ILayoutNode NextRight { get { return Children == null ? Thread : Children.Last(); } } public ILayoutNode LeftSibling { get { if (Parent == null) return null; return Number == 0 ? null : Parent.Children[Number - 1]; } } public ILayoutNode LeftmostSibling { get { if (Parent == null) return null; return Number == 0 ? null : Parent.Children[0]; } } public ILayoutNode Thread { get; set; } public ILayoutNode Ancestor { get; set; } public ILayoutNode Parent { get; set; } public List> Children { get; set; } public float Mod { get; set; } public float Prelim { get; set; } public float Change { get; set; } public float Shift { get; set; } public int Number { get; set; } public int Level { get; set; } public float X { get; set; } public float Y { get; set; } public ISymbolicExpressionTree Content { get; set; } } }