Negative Coordinates

I’m using GoDiagram win 2.4.1 for .net 2.0.
I want the diagram layout to be in following scale.

  1. Right and Bottom can be scaled and scrollbar can be displayed.
  2. Left and Top should not be scaled.
    for this i set the property ShowsNegativeCoordinates = false.
    but in this case, i would be able to drag the objects and put in the negative coordinates, but then they are not visible, since the ShowsNegativeCoordinates is set to false.
    Pls, let me know how to restrict drag drop or move the objects in negative coordinates.

Well, you can either override behavior in GoObject or in GoToolDragging. It’s probably easiest to override GoObject.ComputeMove, as the LimitedNode example class does in Demo1.
Something like this should work:
public override PointF ComputeMove(PointF origLoc, PointF newLoc) {
PointF origPos = this.Position;
newLoc.X = Math.Max(newLoc.X, 10 + (origLoc.X-origPos.X));
newLoc.Y = Math.Max(newLoc.Y, 10 + (origLoc.Y-origPos.Y));
return newLoc;
The “10” there is just to provide a little margin so that the node won’t go all the way to be positioned at zero – you can adjust that as you see fit, of course.

It is working fine if i used for one object.
Here my scenario is, the screen would have 20 to 30 objects and if i select all objects and try to do a drag drop or move, the objects will get conjusted in top screen.
Let me know how to stop moving to behind top or left.

Upon re-reading this topic, it occurred to me that the definition of ComputeMove could have been written more clearly, while making the same computations. So I have updated that code.
What you want to do is more complicated, since you want to make dragging smarter, not just the movement of an individual object. One possibility is to override GoView.MoveSelection to do what you want. Another is to customize the dragging tool:
public class CustomDraggingTool : GoToolDragging {
public CustomDraggingTool(GoView view) : base(view) {}
public override void DoDragging(GoInputState evttype) {
if ((evttype == GoInputState.Continue || evttype == GoInputState.Finish) && this.CurrentObject != null && this.EffectiveSelection != null) {
// calculate the incremental move
SizeF diff = SubtractPoints(this.LastInput.DocPoint, this.CurrentObject.Position);
SizeF off = new SizeF(diff.Width - this.MoveOffset.Width, diff.Height - this.MoveOffset.Height);
if (off.Width < 0 || off.Height < 0) { // when moving left or up…
// find where the EffectiveSelection is
RectangleF bounds = GoDocument.ComputeBounds(this.EffectiveSelection, null);
if (bounds.X + off.Width < 10 || bounds.Y + off.Height < 10)
return; // don’t do the drag!
Install this tool in your view by:
goView1.ReplaceMouseTool(typeof(GoToolDragging), new CustomDraggingTool(goView1));
This assumes that GoView.DragsRealtime is true, of course.
So with this tool you won’t need to override GoObject.ComputeMove on all of your node classes.

Thank you for the clarifications.
This is working in general.
But there are some bugs. When i try to drag-drop selected object towards up or left, it is not allowing. working fine.
After this drag, if i drag the same selected objects towards right side or downside, in someway it is getting stopped. Dragging is not smooth. It is getting stopped for every inch.
In other case, if the selected objects are draged towards rightside (say 1000 pixels) and then stop the draging. Now select the same set of objects and try to drag towards left, it is not allowing me to drag it for same 1000 pixels in reverse.
Pls let me know fix for this.

Dear Walter,
Please update the code and let me know, how to proceed.
Thank You.

I did update the code, above, so that a drop wouldn’t succeed in negative coordinates.
I don’t experience any “rough” dragging. If you are dragging thousands of objects, I could see that being slower, and this custom dragging tool is indeed slower than the regular one, but that isn’t what you are talking about, is it?
Dragging way off to the right, dropping, and then dragging back to the left works fine for me too.

I have only some 25 objects. Roughness is not a problem.
If i moved all the 25 objects towards right side out of the screen, automatically scroll bar is comming and i’m able to drop it there. It is fine.
But, if again i moved back the same 25 objects from current place to the same place where it was previously, the system won’t allow.

Are those objects initially at negative coordinates? That would explain the behavior you see. I was assuming that in your application you wouldn’t position anything at negative coordinates (at least nothing that users would be able to select and move).

Dear Walter,
No, the objects are only in positive coordinates at initial time.
To provide more information about the problem, I did the following.
In my screen, i place 5 objects. All in positive coordinates.
By clicking CTRL+A, selected all the objects. Using mouse it is draged and droped somewhere around the screen. Now the objects are in visible coordinates.
Now, i captured the data for the respective variables in debug mode.
See below,
this.LastInput.DocPoint.x = 239
this.LastInput.DocPoint.y = 239
this.CurrentObject.Position.x = 214
this.CurrentObject.Position.y = 221
diff.Width = 24
this.MoveOffset.Width = 25
diff.Height = 17
this.MoveOffset.Height = 17
off.Width = -1
off.Height = 0
Hence the IF condition is now true ( if (off.Width < 0 || off.Height < 0) { // when moving left or up…)
The computed bound value is
bound.x = -2.3
bound.y = 68
Hence the DRAG is now denied by our code.
Based on the above data, it is clear that the objects are in only positive co-ordinates.

Dear Walter,
On further analysis, i found the solution for this issue.
Overriding GoView.MoveSelection() work fine.
Code snippet:
public override void MoveSelection(GoSelection sel, SizeF offset, bool grid) {
RectangleF selectionRectangle = GoDocument.ComputeBounds(sel, this);
if (selectionRectangle.Left < 10 && offset.Width < 0) {
offset.Width = 0;
if (selectionRectangle.Top < 10 && offset.Height < 0) {
offset.Height = 0;
base.MoveSelection(sel, offset, grid);

Yes, that’s an alternative strategy. One problem is that it might affect the behavior of GoView.MoveSelection in circumstances other than interactive dragging. But if it works for you, that’s good.
You might want to do a similar thing in GoView.CopySelection.

Dear Walter,
It is working fine for me.
Thank you for your guidance.