Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/31/14 17:24:36 (10 years ago)
Author:
bburlacu
Message:

#1772: Tracking building blocks: worked on tracking logic and on the FragmentView.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeTile.cs

    r10677 r10685  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Drawing;
    2425using System.Linq;
     26using HeuristicLab.Common;
    2527using HeuristicLab.Visualization;
    2628
     
    3537    public double PreferredNodeWidth { get; set; }
    3638    public double PreferredNodeHeight { get; set; }
     39
     40    public Size Size {
     41      get {
     42        int xmin = 0, ymin = 0, xmax = 0, ymax = 0;
     43
     44        foreach (var p in Primitives.OfType<RectangularPrimitiveBase>()) {
     45          if (xmin > p.LowerLeft.X) xmin = (int)Math.Floor(p.LowerLeft.X);
     46          if (xmax < p.UpperRight.X) xmax = (int)Math.Ceiling(p.UpperRight.X);
     47          if (ymin > p.LowerLeft.Y) ymin = (int)Math.Floor(p.LowerLeft.Y);
     48          if (ymax < p.UpperRight.Y) ymax = (int)Math.Ceiling(p.UpperRight.Y);
     49        }
     50
     51        return new Size(xmax - xmin, ymax - ymin);
     52      }
     53    }
     54
     55    private Point position;
     56    public Point Position {
     57      get { return position; }
     58      set {
     59        var oldpos = position;
     60        position = value;
     61        int ox = position.X - oldpos.X;
     62        int oy = position.Y - oldpos.Y;
     63        // translate all primitives to the new position
     64        foreach (var p in Primitives) {
     65          var rpb = p as RectangularPrimitiveBase;
     66          if (rpb != null) {
     67            var lowerLeft = new Point((int)Math.Floor(rpb.LowerLeft.X) + ox, (int)Math.Floor(rpb.LowerLeft.Y + oy));
     68            var upperRight = new PointD(lowerLeft.X + rpb.Size.Width, lowerLeft.Y + rpb.Size.Height);
     69            rpb.SetPosition(lowerLeft, upperRight);
     70          }
     71          var line = p as LinearPrimitiveBase;
     72          if (line != null) {
     73            var start = new Point((int)Math.Floor(line.Start.X) + ox, (int)Math.Floor(line.Start.Y) + oy);
     74            var end = new Point(start.X + (int)line.Size.Width, start.Y + (int)line.Size.Height);
     75            line.SetPosition(start, end);
     76          }
     77        }
     78      }
     79    }
     80
    3781    private ISymbolicExpressionTree symbolicExpressionTree;
    3882    public ISymbolicExpressionTree SymbolicExpressionTree {
     
    63107      : base(chart) {
    64108      primitiveMap = new Dictionary<IPrimitive, ISymbolicExpressionTreeNode>();
    65 
     109      PreferredNodeWidth = 80;
     110      PreferredNodeHeight = 40;
    66111      Group = new Group(chart);
    67112    }
    68113    public SymbolicExpressionTreeTile(IChart chart, ISymbolicExpressionTree tree)
    69114      : this(chart) {
    70       PreferredNodeWidth = 80;
    71       PreferredNodeHeight = 40;
    72115      SymbolicExpressionTree = tree;
    73116    }
     
    95138        primitiveMap.Add(rectangularPrimitive, node); // to be able to retrieve nodes via primitives
    96139        this.Add(rectangularPrimitive);
     140
     141        //        int x = Position.X, y = Position.Y;
     142        //        if (x > rectangularPrimitive.LowerLeft.X) {
     143        //          x = (int)Math.Floor(rectangularPrimitive.LowerLeft.X);
     144        //        }
     145        //        if (y > rectangularPrimitive.LowerLeft.Y) {
     146        //          y = (int)Math.Floor(rectangularPrimitive.LowerLeft.Y);
     147        //        }
     148        //        Position = new Point(x, y);
     149        //        int w = Size.Width, h = Size.Height;
     150
     151
     152        if (rectangularPrimitive.Size.Width.IsAlmost(0) || rectangularPrimitive.Size.Height.IsAlmost(0)) {
     153          throw new Exception("Primitive size cannot be zero.");
     154        }
    97155      }
    98156
Note: See TracChangeset for help on using the changeset viewer.