Hi,
Sure – that’s easy to implement by customizing the GoToolRubberBanding tool. Instead of just calling GoView.SelectInRectangle, we sort the objects to be selected before adding them to the GoView.Selection.
public class SortedRubberBandTool : GoToolRubberBanding {
public SortedRubberBandTool(GoView view) : base(view) { }
public override void DoRubberBand(Rectangle box) {
if (!IsBeyondDragSize()) { // not really a drag, but a click
// handle any selection side-effects due to this "click"
DoSelect(this.LastInput);
// whether or not we found and/or selected anything, call DoClick
DoClick(this.LastInput);
} else {
RectangleF docRect = this.View.ConvertViewToDoc(box);
// instead of calling this.View.SelectInRectangle(docRect),
// call our own version of SelectInRectangle that sorts the objects by position
SelectInRectangle(docRect);
}
}
public virtual void SelectInRectangle(RectangleF rect) {
GoView view = this.View;
if (!view.CanSelectObjects()) return;
// selection changes the selection...
GoCollection coll = new GoCollection();
foreach (GoLayer layer in view.Layers) {
if (!layer.IsInDocument) continue;
layer.PickObjectsInRectangle(rect, view.SelectInRectangleStyle, coll, 999999);
}
// now everything's in COLL -- sort by position
GoObject[] arr = coll.CopyArray();
Array.Sort(arr, new PositionComparer());
// and then add them all to the selection, in order
GoSelection sel = view.Selection;
view.RaiseSelectionStarting();
for (int i = 0; i < arr.Length; i++) sel.Add(arr[i]);
view.RaiseSelectionFinished();
}
public class PositionComparer : System.Collections.IComparer {
public PositionComparer() { }
GoObject a = (GoObject)x;
GoObject b = (GoObject)y;
if (a.Left < b.Left) return -1;
else if (a.Left > b.Left) return 1;
else return 0;
}
}
}
Walter,
pShifted.Person.LocationX = (int)rect.X;
pShifted.Person.LocationY = (int)rect.Y;
pShifted.Position = new PointF(pShifted.Person.LocationX, pShifted.Person.LocationY);
PersonHash[pShifted.Person.NodeID].LocationX = pShifted.Person.LocationX;
DataRow[] row = this.persons.Select(“Family_Member_CD=” + pShifted.Person.NodeID);
PersonCollection.PersonsRow prow = (PersonCollection.PersonsRow)row[0];
prow.LocationX = pShifted.Person.LocationX;
prow.LocationY = pShifted.Person.LocationY;
IsOccupied(pExisting, pShifted, ref rect, pShifted.Person.LocationX);
}
//In a scenario where we hit a node that is not biologically related to the newly placed node the existing node gets shifted.
else
{
pShifted = pExisting;
rect.X += 32;
pExisting = pDoc.PickObject(rect.Location, true) as PersonNode; //Get a reference to the node at the new location.
pShifted.Person.LocationX = (int)rect.X;
pShifted.Person.LocationY = (int)rect.Y;
pShifted.Position = new PointF(pShifted.Person.LocationX, pShifted.Person.LocationY);
PersonHash[pShifted.Person.NodeID].LocationX = pShifted.Person.LocationX;
DataRow[] row = this.persons.Select(“Family_Member_CD=” + pShifted.Person.NodeID);
PersonCollection.PersonsRow prow = (PersonCollection.PersonsRow)row[0];
prow.LocationX = pShifted.Person.LocationX;
prow.LocationY = pShifted.Person.LocationY;
IsOccupied(pExisting, pShifted, ref rect, pShifted.Person.LocationX);
}
}
return false;
}