Hi Support!
I create Pool Object and Lane Object, based on Planogrammer example ( as 2 racks objects ) , but there is something that I understood, I can´t move a Lane object inside Pool in a correct margin. The Planogrammer example has a Rack object with a label text in top of object. My problem is because Object Label is another position?
My code and a image:
//Diagram Lane
[Serializable]
public class Lane : LaneDisplay
{
//Variables
private static readonly Pen StandardPen = new Pen(Color.Black, 2);
private static readonly Pen HighlightPen = new Pen(Color.Green, 2);
private int CellGridSize = 3;
//Constuctor
public Lane()
{
this.Label.Text = "Lane";
}
//Create Grid
protected override GoGrid CreateGrid()
{
GoGrid grid = new LaneGrid();
grid.Selectable = false;
grid.AutoRescales = true;
grid.Resizable = true;
grid.ResizesRealtime = true;
grid.Bounds = new RectangleF(0, 0, 50, 50);
grid.SnapDrag = GoViewSnapStyle.Jump;
grid.SnapResize = GoViewSnapStyle.Jump;
grid.CellSize = new SizeF(CellGridSize, CellGridSize);
grid.Style = GoViewGridStyle.None;
grid.Pen = new Pen(Color.Black, 2);
grid.BrushColor = Color.White;
return grid;
}
//Make sure the Lane's Label is positioned in left corner of the Grid; this makes it potentially useful
//for selection and dragging even if all of the grid is covered by Items
public override void LayoutChildren(GoObject childchanged)
{
if (this.Count >= 2)
{
GoGrid grid = this.Grid;
GoText label = this.Label;
if (grid != null && label != null)
{
//Label in Left side
label.Width = grid.Height;
PointF center = grid.GetSpotLocation(MiddleLeft) - new SizeF(label.Height / 2 + 1, 0);
label.Center = center;
}
}
}
//The Location of a Lane is actually the Position of its Grid
public override PointF Location
{
get { return this.Grid.Position; }
set
{
SizeF off = GoTool.SubtractPoints(this.Grid.Position, this.Position);
SizeF pos = GoTool.SubtractPoints(value, off);
this.Position = new PointF(pos.Width, pos.Height);
}
}
//Show a differente color when node is dragged into lane
public override void SetHighlight(bool show)
{
GoGrid grid = this.Grid;
if (grid != null)
{
if (show)
{
grid.Pen = Lane.HighlightPen;
}
else
{
grid.Pen = Lane.StandardPen;
}
}
}
}
//Diagram Lane Grid
[Serializable]
public class LaneGrid : GoGrid
{
//Variables
private int CellGridSize = 3;
//Constructor
public LaneGrid()
{
}
//The grid in a Lane only snaps Items
public override bool CanSnapPoint(PointF p, GoObject obj, GoView view)
{
if (!(obj is GraphNode))
{
return false;
}
// do standard checks, such as whether the grid is a child of the OBJ,
// the value of the grid's snap style, whether the OBJ intersects with the grid,
// and whether the mouse point is in the grid
return base.CanSnapPoint(p, obj, view);
}
//It can be resized only in positive multiples of Item.UnitSize
public override RectangleF ComputeResize(RectangleF origRect, PointF newPoint, int handle, SizeF min, SizeF max, bool reshape)
{
RectangleF r = base.ComputeResize(origRect, newPoint, handle, min, max, reshape);
Lane lane = this.Parent as Lane;
if (lane != null)
{
RectangleF rMin = new RectangleF();
bool any = false;
foreach (GoObject obj in lane.GetEnumerator())
{
if (obj is GraphNode)
{
if (!any)
{
rMin = obj.Bounds;
any = true;
}
else
{
// add the object's bounding rect to this one
rMin = UnionRect(rMin, obj.Bounds);
}
}
}
if (any) r = UnionRect(r, rMin);
}
r.Width = Math.Max(1, (float)Math.Round(r.Width / CellGridSize)) * CellGridSize;
r.Height = Math.Max(1, (float)Math.Round(r.Height / CellGridSize)) * CellGridSize;
return r;
}
static RectangleF UnionRect(RectangleF a, RectangleF b)
{
float minx = Math.Min(a.X, b.X);
float miny = Math.Min(a.Y, b.Y);
float maxr = Math.Max(a.X + a.Width, b.X + b.Width);
float maxb = Math.Max(a.Y + a.Height, b.Y + b.Height);
return new RectangleF(minx, miny, maxr - minx, maxb - miny);
}
}
//Diagram Lane Group Display
[Serializable]
public class LaneDisplay : GoGroup, IGoLabeledNode
{
//Variables
private int CellGridSize = 3;
//Constructor
protected LaneDisplay()
{
//The Grid is always first, in the background
Add(CreateGrid());
Add(CreateLabel());
}
//Create Grid
protected virtual GoGrid CreateGrid()
{
GoGrid grid = new LaneGrid();
grid.Selectable = false;
grid.AutoRescales = true;
grid.Resizable = true;
grid.ResizesRealtime = true;
grid.Bounds = new RectangleF(0, 0, 50, 50);
grid.SnapDrag = GoViewSnapStyle.Jump;
grid.SnapResize = GoViewSnapStyle.Jump;
grid.CellSize = new SizeF(CellGridSize, CellGridSize);
grid.Style = GoViewGridStyle.None;
grid.Pen = new Pen(Color.Black, 2);
grid.BrushColor = Color.White;
return grid;
}
//Create label
protected virtual GoText CreateLabel()
{
////Label in Top Left
//GoText label = new GoText();
// label.Selectable = false;
// label.Multiline = true;
// label.Editable = true;
// label.FontSize = 11;
// label.TransparentBackground = false;
// label.BackgroundColor = Color.White;
// label.Bordered = true;
// return label;
//Label Left Side
RotatedText label = new RotatedText();
label.Selectable = false;
label.Multiline = true;
label.Editable = true;
label.FontSize = 11;
label.TransparentBackground = false;
label.BackgroundColor = Color.White;
label.Bordered = true;
// settings for rotation.
label.AutoResizes = false;
label.Alignment = Middle;
label.Angle = 270;
return label;
}
public virtual GoText Label
{
get { return this[1] as GoText; }
}
//Get Grid
public virtual GoGrid Grid
{
get { return this[0] as GoGrid; }
}
//IGoLabeledNode:
//Get Label
//Set and Get Label text
public virtual String Text
{
get
{
GoText lab = this.Label;
if (lab != null)
return lab.Text;
return null;
}
set
{
GoText lab = this.Label;
if (lab != null)
lab.Text = value;
}
}
public override void DoBeginEdit(GoView view)
{
if (this.Label != null)
{
this.Label.DoBeginEdit(view);
}
}
public override bool CanEdit()
{
return base.CanEdit();
}
//if the Label is not visible or if the view has a small DocScale,it's handy to be able to see the name of the lane
public override String GetToolTip(GoView view)
{
return this.Text;
}
//Selection:
//let users resize the grid, not the whole Lane
public override GoObject SelectionObject
{
get { return this.Grid; }
}
public override bool CanSelect()
{
return base.CanSelect();
}
//Unlike normal GoGroups, PickObjects picks all children at a particular PointF, not just the "top" one
public override IGoCollection PickObjects(PointF p, bool selectableOnly, IGoCollection coll, int max)
{
if (coll == null) coll = new GoCollection();
if (coll.Count >= max) return coll;
if (!CanView()) return coll;
foreach (GoObject child in this.Backwards)
{
LaneDisplay disp = child as LaneDisplay;
if (disp != null)
{
disp.PickObjects(p, selectableOnly, coll, max);
}
else
{
GoObject picked = child.Pick(p, selectableOnly);
if (picked != null)
{
coll.Add(picked);
if (coll.Count >= max) return coll;
}
}
}
return coll;
}
//Dragging:
//when dragging a non-Display onto a Display, highlight it to indicate that the dropped object(s) will be added to the Display
public override bool OnEnterLeave(GoObject from, GoObject to, GoView view)
{
if (from is LaneDisplay && from != this)
{
((LaneDisplay)from).SetHighlight(false);
}
SetHighlight(view.Tool is GoToolDragging && to == this && !view.Selection.IsEmpty && IsAddable(view.Selection.Primary) && view.Selection.Primary.Parent != this);
return true;
}
//Called after a GoToolDragging drop
public override bool OnSelectionDropped(GoObjectEventArgs evt, GoView view)
{
view.Selection.AddRange(AddItems(view.Selection));
return true;
}
//All ports on all nodes are hidden when the mouse hovers over the lane background.
public override bool OnHover(GoInputEventArgs evt, GoView view)
{
foreach (GoObject obj in this.Backwards)
{
if (obj is GraphNode)
{
GraphNode n = obj as GraphNode;
if (n != null)
{
foreach (GoPort p in n.Ports)
{
p.Style = GoPortStyle.None;
}
}
}
}
return true;
}
//Don't add Lanes as children of this Display
public virtual bool IsAddable(GoObject obj)
{
if (obj is Lane)
{
return false;
}
else
{
return true;
}
}
//Return a collection of objects that actually are added to this Lane
public virtual IGoCollection AddItems(IGoCollection coll)
{
//Skip all dropped Lanes -- just include Items and GoText labels
GoCollection items = new GoCollection();
foreach (GoObject obj in coll)
{
if (IsAddable(obj))
{
items.Add(obj);
}
}
if (items.IsEmpty)
{
return items;
}
IGoCollection added = AddCollection(items, false);
return added;
}
//Visually distinguish this Display from others, to indicate that it can (or just did) add an Item
public virtual void SetHighlight(bool show)
{
}
}
//Diagram Pool
[Serializable]
public class Pool : PoolDisplay
{
//Variables
private static readonly Pen StandardPen = new Pen(Color.Black, 2);
private static readonly Pen HighlightPen = new Pen(Color.Green, 2);
private int CellGridSize = 3;
//Constuctor
public Pool()
{
this.Label.Text = "Pool";
}
//Create Grid
protected override GoGrid CreateGrid()
{
GoGrid grid = new PoolGrid();
grid.Selectable = false;
grid.AutoRescales = true;
grid.Resizable = true;
grid.ResizesRealtime = true;
grid.Bounds = new RectangleF(0, 0, 50, 50);
grid.SnapDrag = GoViewSnapStyle.Jump;
grid.SnapResize = GoViewSnapStyle.Jump;
grid.CellSize = new SizeF(CellGridSize, CellGridSize);
grid.Style = GoViewGridStyle.None;
grid.Pen = new Pen(Color.Black, 2);
grid.BrushColor = Color.White;
return grid;
}
//Make sure the Lane's Label is positioned in left corner of the Grid; this makes it potentially useful
//for selection and dragging even if all of the grid is covered by Items
public override void LayoutChildren(GoObject childchanged)
{
if (this.Count >= 2)
{
GoGrid grid = this.Grid;
GoText label = this.Label;
if (grid != null && label != null)
{
//Label in Left side
label.Width = grid.Height;
PointF center = grid.GetSpotLocation(MiddleLeft) - new SizeF(label.Height / 2 + 1, 0);
label.Center = center;
}
}
}
//The Location of a Lane is actually the Position of its Grid
public override PointF Location
{
get { return this.Grid.Position; }
set
{
SizeF off = GoTool.SubtractPoints(this.Grid.Position, this.Position);
SizeF pos = GoTool.SubtractPoints(value, off);
this.Position = new PointF(pos.Width, pos.Height);
}
}
//Show a differente color when node is dragged into lane
public override void SetHighlight(bool show)
{
GoGrid grid = this.Grid;
if (grid != null)
{
if (show)
{
grid.Pen = Pool.HighlightPen;
}
else
{
grid.Pen = Pool.StandardPen;
}
}
}
}
//Diagram Pool Grid
[Serializable]
public class PoolGrid : GoGrid
{
//Variables
private int CellGridSize = 3;
//Constructor
public PoolGrid()
{
}
//The grid in a Poll only snaps Lanes
public override bool CanSnapPoint(PointF p, GoObject obj, GoView view)
{
if (!(obj is Lane))
{
return false;
}
// do standard checks, such as whether the grid is a child of the OBJ,
// the value of the grid's snap style, whether the OBJ intersects with the grid,
// and whether the mouse point is in the grid
return base.CanSnapPoint(p, obj, view);
}
public override RectangleF ComputeResize(RectangleF origRect, PointF newPoint, int handle, SizeF min, SizeF max, bool reshape)
{
RectangleF r = base.ComputeResize(origRect, newPoint, handle, min, max, reshape);
Pool pool = this.Parent as Pool;
if (pool != null)
{
RectangleF rMin = new RectangleF();
bool any = false;
foreach (GoObject obj in pool.GetEnumerator())
{
if (obj is Lane)
{
if (!any)
{
rMin = obj.Bounds;
any = true;
}
else
{
// add the object's bounding rect to this one
rMin = UnionRect(rMin, obj.Bounds);
}
}
}
if (any) r = UnionRect(r, rMin);
}
r.Width = Math.Max(1, (float)Math.Round(r.Width / CellGridSize)) * CellGridSize;
r.Height = Math.Max(1, (float)Math.Round(r.Height / CellGridSize)) * CellGridSize;
return r;
}
static RectangleF UnionRect(RectangleF a, RectangleF b)
{
float minx = Math.Min(a.X, b.X);
float miny = Math.Min(a.Y, b.Y);
float maxr = Math.Max(a.X + a.Width, b.X + b.Width);
float maxb = Math.Max(a.Y + a.Height, b.Y + b.Height);
return new RectangleF(minx, miny, maxr - minx, maxb - miny);
}
}
//Diagram Pool Group Display
[Serializable]
public class PoolDisplay : GoGroup, IGoLabeledNode
{
//Variables
private int CellGridSize = 3;
//Constructor
protected PoolDisplay()
{
//The Grid is always first, in the background
Add(CreateGrid());
Add(CreateLabel());
}
//Create Grid
protected virtual GoGrid CreateGrid()
{
GoGrid grid = new PoolGrid();
grid.Selectable = false;
grid.AutoRescales = true;
grid.Resizable = true;
grid.ResizesRealtime = true;
grid.Bounds = new RectangleF(0, 0, 50, 50);
grid.SnapDrag = GoViewSnapStyle.Jump;
grid.SnapResize = GoViewSnapStyle.Jump;
grid.CellSize = new SizeF(CellGridSize, CellGridSize);
grid.Style = GoViewGridStyle.None;
grid.Pen = new Pen(Color.Black, 2);
grid.BrushColor = Color.White;
return grid;
}
//Create label
protected virtual GoText CreateLabel()
{
//Label Left Side
RotatedText label = new RotatedText();
label.Selectable = false;
label.Multiline = true;
label.Editable = true;
label.FontSize = 11;
label.TransparentBackground = false;
label.BackgroundColor = Color.White;
label.Bordered = true;
// settings for rotation.
label.AutoResizes = false;
label.Alignment = Middle;
label.Angle = 270;
return label;
}
public virtual GoText Label
{
get { return this[1] as GoText; }
}
//Get Grid
public virtual GoGrid Grid
{
get { return this[0] as GoGrid; }
}
//IGoLabeledNode:
//Get Label
//Set and Get Label text
public virtual String Text
{
get
{
GoText lab = this.Label;
if (lab != null)
return lab.Text;
return null;
}
set
{
GoText lab = this.Label;
if (lab != null)
lab.Text = value;
}
}
public override void DoBeginEdit(GoView view)
{
if (this.Label != null)
{
this.Label.DoBeginEdit(view);
}
}
public override bool CanEdit()
{
return base.CanEdit();
}
//if the Label is not visible or if the view has a small DocScale,it's handy to be able to see the name of the lane
public override String GetToolTip(GoView view)
{
return this.Text;
}
//Selection:
//let users resize the grid, not the whole Lane
public override GoObject SelectionObject
{
get { return this.Grid; }
}
public override bool CanSelect()
{
return base.CanSelect();
}
//Unlike normal GoGroups, PickObjects picks all children at a particular PointF, not just the "top" one
public override IGoCollection PickObjects(PointF p, bool selectableOnly, IGoCollection coll, int max)
{
if (coll == null) coll = new GoCollection();
if (coll.Count >= max) return coll;
if (!CanView()) return coll;
foreach (GoObject child in this.Backwards)
{
PoolDisplay disp = child as PoolDisplay;
if (disp != null)
{
disp.PickObjects(p, selectableOnly, coll, max);
}
else
{
GoObject picked = child.Pick(p, selectableOnly);
if (picked != null)
{
coll.Add(picked);
if (coll.Count >= max) return coll;
}
}
}
return coll;
}
//Dragging:
//when dragging a non-Display onto a Display, highlight it to indicate that the dropped object(s) will be added to the Display
public override bool OnEnterLeave(GoObject from, GoObject to, GoView view)
{
if (from is PoolDisplay && from != this)
{
((PoolDisplay)from).SetHighlight(false);
}
SetHighlight(view.Tool is GoToolDragging && to == this && !view.Selection.IsEmpty && IsAddable(view.Selection.Primary) && view.Selection.Primary.Parent != this);
return true;
}
//Called after a GoToolDragging drop
public override bool OnSelectionDropped(GoObjectEventArgs evt, GoView view)
{
view.Selection.AddRange(AddItems(view.Selection));
return true;
}
//Don't add pools as children of this Display
public virtual bool IsAddable(GoObject obj)
{
if (obj is Lane)
{
return true;
}
else
{
return false;
}
}
//Return a collection of objects that actually are added to this Pool
public virtual IGoCollection AddItems(IGoCollection coll)
{
//Skip all dropped Lanes -- just include Items and GoText labels
GoCollection items = new GoCollection();
foreach (GoObject obj in coll)
{
if (IsAddable(obj))
{
items.Add(obj);
}
}
if (items.IsEmpty)
{
return items;
}
IGoCollection added = AddCollection(items, false);
return added;
}
//Visually distinguish this Display from others, to indicate that it can (or just did) add an Item
public virtual void SetHighlight(bool show)
{
}
}