Hi Jake!
Is this the only way to do it? The result was not good.
The LimitingSubGraphMarker stay with the same size…But the GoSubGraph object ( SubProcess) size was ignored when user open file after set AutoRescales property.
In the file, the size is correct:
<subprocess id="0" Port="1" text="SubProcess" loc="220 80"
size="415 275" />
After I inserted obj.AutoRescales = false ;
When user open file, the GoSubGraph object size was ignored !!
Code:
//SubProcessItem Class: SubProcess
[Serializable]
public class SubProcessItem : GoSubGraph
{
//Variables
private ResourceManager rm;
public SubProcessItem()
{
//this.LabelSpot = GoObject.MiddleTop; // default
this.CollapsedLabelSpot = GoObject.MiddleBottom;
this.Corner = new SizeF(5, 5);
this.TopLeftMargin = new SizeF(10, 5);
this.BottomRightMargin = new SizeF(10, 10);
this.CollapsedTopLeftMargin = new SizeF(10, 5);
this.CollapsedBottomRightMargin = new SizeF(10, 2);
this.Opacity = 50f;
this.BackgroundColor = Color.LightGray;
this.BorderPenColor = Color.Gray;
this.Handle.Style = GoCollapsibleHandleStyle.PlusMinus;
this.Handle.Brush = null;
this.Handle.Bordered = false;
GoObject obj = new LimitingSubGraphMarker();
obj.Position = new PointF(10, 10);
Add(obj);
obj = new LimitingSubGraphMarker();
obj.Position = new PointF(200, 200);
Add(obj);
}
protected override GoText CreateLabel()
{
//Resources
rm = new ResourceManager("constants", this.GetType().Assembly);
GoText label = base.CreateLabel();
label.Text = rm.GetString("PROCESS_DIAGRAM_SUBPROCESSITEM");
label.Bold = false;
//label.FontSize = 8;
label.Alignment = GoObject.MiddleTop;
label.AutoResizes = false;
label.Multiline = false;
label.StringTrimming = StringTrimming.EllipsisCharacter;
return label;
}
protected override void PaintDecoration(Graphics g, GoView view)
{
base.PaintDecoration(g, view);
if (this.IsExpanded)
{
RectangleF rect = ComputeBorder();
float y = this.Label.Bottom + 2;
GoShape.DrawLine(g, view, this.BorderPen, rect.X, y, rect.Right, y);
}
}
public override void LayoutLabel()
{
GoText lab = this.Label;
if (lab == null)
return;
RectangleF rect;
// just let the label sit in place on a collapse
if (this.IsExpanded)
{
// don't move label if it's the only thing left (besides the standard children)
int numchildren = 0;
if (this.Handle != null) numchildren++;
if (this.Label != null) numchildren++;
if (this.Port != null) numchildren++;
if (this.CollapsedObject != null) numchildren++;
if (numchildren == this.Count) return;
// find bounds of meaningful children, excluding Label and ignoring Margin
rect = ComputeInsideMargins(lab);
PointF pt = new PointF(rect.X + rect.Width / 2, rect.Y - this.TopLeftMargin.Height - lab.Height);
lab.SetSpotLocation(TopCenter, pt);
}
}
public override void LayoutHandle()
{
if (!this.IsExpanded) return;
GoSubGraphHandle h = this.Handle;
if (h != null)
{
RectangleF rect = ComputeInsideMargins(h);
// top-right, inside margin
PointF pt = new PointF(rect.Right, rect.Y - this.TopLeftMargin.Height);
if (this.Label != null) pt.Y = this.Label.Location.Y;
h.SetSpotLocation(TopRight, pt);
}
}
// Make sure the collapsed subgraph body (including any CollapsedObject)
// is positioned to the left of the handle.
protected override RectangleF ComputeCollapsedRectangle(SizeF s)
{
PointF hpos = ComputeReferencePoint();
return new RectangleF(hpos.X + this.Handle.Width - s.Width, hpos.Y, s.Width, s.Height);
}
public override PointF Location
{
get
{
if (this.Label != null)
return this.Label.Position;
else
return this.Position;
}
set
{
if (this.Label != null)
{
// we move the node, which substitutes presumably unnecessary calls to LayoutChildren with calls to MoveChildren
SizeF off = GoTool.SubtractPoints(this.Label.Position, this.Position);
this.Position = new PointF(value.X - off.Width, value.Y - off.Height);
}
else
{
this.Position = value;
}
}
}
public override void DoResize(GoView view, RectangleF origRect, PointF newPoint,int whichHandle, GoInputState evttype, SizeF min, SizeF max)
{
base.DoResize(view, origRect, newPoint, whichHandle, evttype, min, max);
LayoutPort();
if (this.IsExpanded)
{
LayoutHandle();
}
}
protected override GoPort CreatePort()
{
GoBoxPort bp = new GoBoxPort();
bp.LinkPointsSpread = true;
bp.Style = GoPortStyle.None;
bp.IsValidTo = false;
bp.IsValidFrom = false;
return bp;
}
public override void LayoutPort()
{
GoPort p = this.Port;
if (p != null && p.CanView())
{
RectangleF r = ComputeBorder();
p.Bounds = r;
}
}
public override RectangleF ComputeInsideMargins(GoObject ignore)
{
RectangleF rect = base.ComputeInsideMargins(ignore);
// if width of subgraph changes, change width of label to correspond.
if (this.Label != null && ignore == this.Label && this.State == GoSubGraphState.Expanded)
{
this.Label.Width = rect.Width;
}
if (this.Label != null && ignore == null && this.State == GoSubGraphState.Collapsed)
{
rect = this.Label.Bounds;
}
return rect;
}
// making collapsed nodes a fixed size (the size of the label)
public override SizeF ComputeCollapsedSize(bool visible)
{
SizeF sz = base.ComputeCollapsedSize(visible);
if (this.Label != null) sz = this.Label.Size;
return sz;
}
public override bool OnSelectionDropped(GoObjectEventArgs evt, GoView view)
{
if (true)
{ //this.AllowDragInOut
// add all selected objects to this BoxArea
view.Selection.AddRange(AddCollection(view.Selection, true));
return true;
}
//else {
// return false;
//}
}
//Context Menu
public override bool OnContextClick(GoInputEventArgs evt, GoView view)
{
GoDocument doc = this.Document;
GenerateProcess GenProcess = doc as GenerateProcess;
if ((evt.Buttons == MouseButtons.Right) && (GenProcess != null))
{
if ((GenProcess.ProcessDiagramBarManager != null) && (GenProcess.ProcessDiagramPopupMenu != null))
{
//Clear the contents of PopUp Menu.
GenProcess.ProcessDiagramBarManager.Items.Clear();
GenProcess.ProcessDiagramPopupMenu.LinksPersistInfo.Clear();
SubProcessItem selSubProcess = this as SubProcessItem;
if (selSubProcess != null)
{
//Create Menu Item: Remove SubProcess Item
BarButtonItem RemoveSubProcessItem = new BarButtonItem();
RemoveSubProcessItem.Caption = rm.GetString("PROCESSDIAGRAM_REMOVE");
RemoveSubProcessItem.ItemClick += new ItemClickEventHandler(this.RemoveSubprocessItem_Command);
GenProcess.ProcessDiagramBarManager.Items.Add(RemoveSubProcessItem);
GenProcess.ProcessDiagramPopupMenu.AddItem(RemoveSubProcessItem);
}
}
if (GenProcess.ProcessDiagramPopupMenu.ItemLinks.Count > 0)
{
//Show popupMenuNodes
GenProcess.ProcessDiagramPopupMenu.ShowPopup(Cursor.Position);
}
return true;
}
else
{
return false;
}
}
//Context Menu events
private void RemoveSubprocessItem_Command(Object sender, EventArgs e)
{
SubProcessItem selSubProcessItem = this as SubProcessItem;
if (selSubProcessItem != null)
{
GoDocument doc = this.Document;
doc.StartTransaction();
doc.Remove(this);
this.LayoutChildren(null);
doc.FinishTransaction("Removed SubProcessItem");
}
}
}
[Serializable]
public class LimitingSubGraphMarker : GoRectangle
{
public LimitingSubGraphMarker()
{
this.Printable = false;
this.Resizable = false;
this.Deletable = false;
this.Copyable = false;
this.Brush = null;
this.PenColor = Color.Gray;
this.AutoRescales = false;
}
// can't get any selection handles
public override void AddSelectionHandles(GoSelection sel, GoObject selectedObj) { }
// only seen when the mouse is over it
public override bool OnEnterLeave(GoObject from, GoObject to, GoView view)
{
if (from == this)
this.Brush = null;
if (to == this)
this.BrushColor = Color.Gray;
return true;
}
}