Moveafter/ MoveBefore

Hi
I have been trying to impleament the feature to move nodes back or infront of each other, but with no luck. None of the sample applications show how this is done, is there a samble of this issue someware else? Or can anyone explay how this is done?, it was quite easy in the MFC version.
I found the following in the FAQ but I dont get this.

Have your GoDocument use GoLayers to organize your objects into layers. You will typically create them by calling:

aDocument.Layers.CreateNewLayerAfter(aDoc.DefaultLayer)

to create a layer that appears in front of the default document layer. Use the CreateNewLayerBefore method to insert new layer behind existing ones. Each layer can be made invisible by setting the GoLayer.AllowView property to false. You can re-order the layers by calling GoLayerCollection.MoveAfter or MoveBefore

The issue is that at present the objects within one layer are not guaranteed to be in any particular order. However, the layers in a GoLayerCollection are ordered, and the child objects in a GoGroup are ordered, so you can use either of those structures to implement Z-ordering. The passage on layers that you quote just talks about how to use layers.
If your application can get away with just a few layers, then using GoLayers would make sense. Otherwise you might want to consider using a (non-Selectable, unbordered, non-Handled, non-Labeled) GoSubGraph to hold all of your objects, including any new objects that are added to your document.
We are adding support for Z-ordering within a layer in version 3. (Coincidentally, we have been implementing that support this week.) It’s interesting that we have rarely received any requests for this functionality.

okay I will often have several hundred objects in a view so using layers is probably not the solution.
In the MFC version when I wanted to move a object in front of any other objects, all I had to do was the following:

CGoDocument* pDoc = GetDocument();
for (POSITION pos = m_pSelection->GetFirstSelectedPos(); pos != NULL; ) {
CGoObject* pObject = m_pSelection->GetNextSelected(pos);
pDoc->BringObjectToFront(pObject);
}
So this was quite easy, will it be working the same way in version 3? And when will version 3 be out?
If there is a long time before version 3 is ready, is there a sample showing how to move objects in front or behind each other?

Hi,
We are interested in this functionality as well. Does the functionality exist in 2.4.1 or do you have an estimate when 3.0 will be released.
thanks,
Jake

Yes, MoveAfter and MoveBefore are now methods on GoLayer in version 2.4.
Also useful is the GoLayer.NextObject method, and the GoLayerCollection.SortByZOrder method, when you have a bunch of objects and want to figure out what’s on top or bottom.

Thanks for the reply.
If I want to move an object to the top of a layer, I assume I should do something like this:
GoObject[] sortedArray = topLayer.CopyArray();
Document.Layers.SortByZOrder(sortedArray);
topLayer.MoveAfter(sortedArray[sortedArray.Length - 1], goObject);
Will the layer always be sorted so I can skip the copy array and sort methods? If so, I couldn’t find a way to treat the goLayer as a collection.
-Jake

No, just do:
anObject.Layer.MoveAfter(null, anObject)

Thanks.

Has there been a change in this functionality?

I’ve resurrected some old code that used this:
//bring to front
this.myOwner.Layer.MoveAfter(null, this.myOwner);
Basically to display a node in front of others when it is expanded ( The class ExpandingLinkLabel : GoBoxNode, IGoCollapsible is used as a MidLabel on a link derived class).
But I get :
System.ArgumentException was unhandled
Message=“Cannot change Z-order of a child object; call GoGroup.InsertBefore instead”

This doesn’t achieve what I want:
this.myOwner.InsertBefore(this.myOwner, null);

I was using 2.4.x when I originally wrote the code but now under 2.5.1 it fails.
Sorry, if I’ve missed something obvious.

Martin

No, there hasn’t been any change in either GoLayer or in GoGroup. From the code it appears you have a valid error there – i.e. it ought to be raising an exception.
However, that error message has a typo in it – it ought to be suggesting the use of GoGroup.InsertAfter instead of suggesting GoGroup.InsertBefore. Sorry for the confusion.