100% CPU when DragsRealtime is false

Hello

Here is another one.

Consider a GoView with DragsReltime = false and a custom group with PickableBackground = true;.

At runtime, make a custom group formed of two child objects.
Move the objects away from each other, in such a way the group becomes huge.

If you try to move the expanded group by dragging it directly, an image is built (because of dragsrealtime = false) and the image is moved instead.

If the group becomes huge (10000x10000 pixels for example) the move is intrerupted periodically and the cpu is 100%.

I suppose this is because a 10000x10000 image is created and moved.

Is there any way to overcome this problem? Maybe the new v2.3 beta?


Regards

Liviu

A 10000x10000 pixel bitmap would be about 400MB. In fact, trying to allocate such a Bitmap would probably cause an exception, which is why GoDiagram automatically limits the size of the bitmap, at the expense of fuzziness in the dragged image.
So we are already making the optimization I think you are suggesting.

Ok, I exagerated with 10000x10000. Anyway, starting from some point moving non realtime large expanded groups causes unacceptable delays observed during moving (about 1 second on a 1.8Ghz processor). (Note that the group contains a smal number of nodes so this is not the problem.)



So you say you are optimizing this in the last version of GoDiagram? If this is the case, can you tell me aproximatively when is scheduled to be released a stable version containing the optimizations?

That optimization is (already) in 2.2.
.NET drawing is known for not being particularly fast, so I suspect this is a limitation of System.Drawing.Graphics.DrawImage().

I insist a little on this problem as it is very important for us.



I think a better aproach would be to create a rectangle instead of a picture. As I know it right now, the image that is created when the user drags an object is totally controlled by GoView.



Is there any way (a hook or something) so we can create our object instead the default image? Do you have any other sugestions regarding this issue?



Thanks



Liviu









Sure, you can override GoToolDragging.CreateDragSelection to return a new GoSelection with whatever you want in it. Here’s the standard implementation:
public virtual GoSelection CreateDragSelection() {
GoSelection dropSel = new GoSelection(null);
GoRectangle currob = new GoRectangle();
currob.Bounds = this.CurrentObject.Bounds;
currob.Visible = false;
this.View.Layers.Default.Add(currob);
dropSel.Add(currob);
GoCollection coll = new GoCollection();
foreach (GoObject obj in (this.EffectiveSelection != null ? this.EffectiveSelection : this.Selection)) {
coll.Add(obj.DraggingObject);
}
RectangleF bounds = GoDocument.ComputeBounds(coll, this.View);
// limit bounds to reasonable maximum
float scale = this.View.WorldScale.Width;
if (bounds.Widthscale > 2000 || bounds.Heightscale > 2000) {
scale = scaleMath.Min(2000/(bounds.Widthscale), 2000/(bounds.Height*scale));
}
Bitmap bm = this.View.GetBitmapFromCollection(coll, bounds, scale, false);
GoImage img = new GoImage();
img.Image = bm;
img.Bounds = new RectangleF(bounds.X, bounds.Y, bm.Width/scale, bm.Height/scale);
// make sure it’s part of the view
this.View.Layers.Default.Add(img);
// add this view object to the drop selection
dropSel.Add(img);
return dropSel;
}

Instead of calling GetBitmapFromCollection and creating a GoImage displaying the resulting Bitmap, you could just allocate whatever GoObjects you wanted, and add them to the view and to this drag selection. Of course the fewer and the simpler the better.
Note how the first object needs to represent the CurrentObject, so that the GoToolDragging.MoveOffset works correctly. In the case of using a large GoImage, we had to add a GoRectangle for this reason, but it could be not Visible.
I hope this helps. I thought you had wanted DragsRealtime to be true.

Hi Walter,
I like to overwrite the method CreateDragSelection. But I do not understand this part:
float scale = this.View.<SPAN =highlight>WorldScale.Width;
What represent the property WorldScale?
This property is internal and so I can not use it in my code.
Thanks for your help!
Asterix

It’s the mapping of doc/view coordinates to pixels (typically 1 to 1).
// Gets or sets a horizontal and vertical scaling factor for converting document
// coordinates in other units to and from pixel units.
// The default value is 1.0f–document units have the same size as pixels

Jake

Oops, sorry about that. When I copied the code I didn’t simplify it to remove internal stuff. Just assume that value is 1.