Center of Document

Hi, I would like to place a node in the center of the document. I understand that I can find the center of the document from GoView.Document.Size property. However, since the GoObjects can have negative values, setting the top and left coordinate of the goObject to GoView.Document.Size.Height/2 and GoView.Document.Size.Width/2 may not exactly yield correct results. For eg I have a GoObject whose top coordinate is -1200. The GoView.Document.Height is 3000. When I set the GoObject's top coordinate to GoView.Document.Height/2, it takes the GoObject to the bottom of the Document (since actually the Document extends from -1500 to 1500) By doing some math, I can find the correct center however is there some easier way to achive this, given the possibility that the document may or may not have negative coordinates and the GoObject to be placed at the center of the doument may or may not have negative coordinates. I mean that there may be objects in the Document with negative coordinates, bu the GoObject that I want to place at the center may have positive (top, left) coordinate values. Thanks, Rafique P.S. I had sent you an email related to this topic, but I got a timeout notification from our server. Please ignore this message if you have got the email.

You’re quite right about objects at negative coordinate positions. That’s why there’s the GoDocument.TopLeft property in addition to the GoDocument.Size property.
That talks about the “static” bounds of the document. You can also find the “dynamic” area covered by the actual objects in the document by calling GoDocument.ComputeBounds. That will return the union of the GoObject.Bounds for everything that’s visible in the document.

So is the logic of the code (used to find the center of the GoDocument) below proper…
//Vertical center of the GoDocument
float verticalCenterOfDocument = View.Document.Size.Height/2;
//Horizontal center of the GoDocument
float horizontalCenterOfDocument = View.Document.Size.Width/2;
//Get the bounds of the GoDocument
RectangleF documentBounds = View.ComputeDocumentBounds();
//If the GoDocument extends in negative Y direction then add the
// (or rather subtract or translate) by that amount…
if(document.Bounds.Y < 0)
{
verticalCenterOfDocument += document.B ounds.Y ;
}
//If the GoDocument extends in negative X direction then add the
// (or rather subtract or translate) by that amount…
if(document.Bounds.X < 0)
{
horizontalCenterOfDocument += document.Bounds.X ;
}
GoText objToPlaceAtTheCenterOfDoc = new GoText();
…//intialize the GoText etc
objToPlaceAtTheCenterOfDoc.Top = verticalCenterOfDocument ;
objToPlaceAtTheCenterOfDoc.Left = horizontalCenterOfDocument ;
Can you please give me your inputs as to whether this code will work properly or not.
-Rafique

obj.Center = new PointF(doc.TopLeft.X + doc.Size.Width/2, doc.TopLeft.Y + doc.Size.Height/2)

Tried this but doesnt always work, especially when the GoView’s DisplayRectangle/DocExtentSize’s Height and Width are more than that of the Document.Size
Any ideas as to how I can resolve this issue.
Thanks,
Rafique

Then I don’t understand what you want. By definition the expression I just posted will place an object at the center of a document.
If you are trying to put an object in the center of a view, then:
RectangleF r = view.DocExtent;
obj.Center = new PointF(r.X + r.Width/2, r.Y + r.Height/2);

Yes I would like to find the center of the Document, but the Document.Size is not considering blank spaces, between the smallest rectangle enclosing all the GoObjects and the edges of the display rectangle. For eg if the Document extends is from 100,100 to 720,720
and the display rectangle is 100, then to display the entire document it will take minimum 9 windows ie there will be a blank window intially, then as u start scrolling u will see goObjects and then when the scroll bar reaches the max position ie on the last window u will be empty space from 720 to 800.
In such a scenario the center, is at the center of the 5th window (ie 4.5),and the entire space required by the document is (900,900) and not (820,820) as will be given by Document.TopLeft.X (or Y ) + Document.Size.Width (or Height respectively)
Hope this makes sense

Thanks for the explanation, but I still don’t get it. In your scenario, at what PointF should the center of the object be?
What happens when the user changes the size of the GoView? Zooms in or out? Shows a second GoView on the same GoDocument?

A-------------------------------------------------------B
P------------------------Q
| | W-----------X
S-------------------------R | |
Y------------Z
D--------------------------------------------------------C

Consider a rectangle ABCD represnting the entire document. There is a smaller rectangle PQRS, within rectangle ABCD and is much smalller then ABCD. All the GoObjects in the document are located within this rectangle PQRS (this rectangle will be returned by View.ComputeDocumentBounds()).
Suppose there is another rectangle WXYZ within ABCD and much smaller then ABCD and PQRS. This rectangle is the portion of the Document that is being displayed in the view (ie View.DocExtent)
I would like to find the center of rectangle ABCD

OK, so in your illustration the view is currently blank, because there are no objects in the document inside WXYZ.
Wouldn’t ABCD just be defined by the GoDocument.TopLeft and .Size?
If you are concerned about the view being larger than the document, either because the document is “small” or the GoView.DocScale is small, then you could just use the union of the document’s bounds and the view’s DocExtent.

Yes that was my primary concern…To resolve it I was using the maximum of DocExtentSize and Document.Size to find the center