Positioning new vertex from beginning

Jul 13, 2009 at 5:58 PM

Hey guys!

Im trying to create a funtion where I click with the right button on a blank space of the application and I try to create a new node of the Graph exactly in the point where I clicked, but I dont know how to work with positioning vertex through code. Can anyone give me a hand with that?

Coordinator
Jul 13, 2009 at 10:06 PM

If you have the VertexControl then you just set the GraphLayout.X and GraphLayout.Y attached properties on the VertexControls.

Jul 14, 2009 at 8:38 AM

Im confused... the  VertexControl Class doesnt have any "GraphLayout" or "X" or "Y", property or member. :S

<UserControl x:Class="PFCEditor.Diagram"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
             xmlns:zoom="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
             xmlns:myns="clr-namespace:PFCEditor"
             Height="300" Width="300"
             x:Name="root">
    <Grid MouseUp="Grid_MouseUp">
        <zoom:ZoomControl>
            <graphsharp:GraphLayout x:Name="graphLayout"
                                    Graph="{Binding ElementName=root,Path=GraphToVisualize}"
                                    LayoutAlgorithmType="KK"
                                    OverlapRemovalAlgorithmType="FSA">
            </graphsharp:GraphLayout>
        </zoom:ZoomControl>
        <Grid.ContextMenu>
            <ContextMenu>
                <MenuItem Header="Add new state" Click="addNewState_cm"/>
            </ContextMenu>
        </Grid.ContextMenu>
    </Grid>
</UserControl>

private void addNewState_cm(object sender, RoutedEventArgs e)
{
      GraphSharp.Controls.VertexControl x = CreateNewVertex();
      ???
}

Coordinator
Jul 15, 2009 at 2:02 PM

using GraphSharp.Controls;


VertexControl vc = graphLayout.GetVertexControl(myVertex);

//setting the mentioned attached properties
GraphCanvas.SetX(vc, the x coordinate);
GraphCanvas.SetY(vc, the y coordinate);

Aug 11, 2009 at 8:15 PM

There's no such thing as ".GetVertexControl" in a GraphLayout object :S

Developer
Aug 12, 2009 at 8:44 AM

Are you sure that you have the latest version of the library?

Aug 12, 2009 at 8:50 AM

Positive!

Aug 22, 2009 at 2:12 PM

I don't think GetVertexControl is in the binary download, but its there if you build from source: http://graphsharp.codeplex.com/SourceControl/ListDownloadableCommits.aspx

Jan 25, 2010 at 4:37 PM
Edited Jan 25, 2010 at 4:37 PM

Hi there.

Even if all this was long ago, I am answering on this discussion since I am experiencing the same problem.

I want to make my own layout, basically if should result in a double tree. Since i have a rather simple graph, this should not be a problem at all.

But I did not make it to change the Vertex position so far. GetVertexControl() is not present, no matter whether I compile graph# on my own or  use the precompiled version from the download section.

 

Can somebody give some hints on this topic, please?

Oct 20, 2011 at 3:28 PM

hey,

same problem here. I know that the topic is pretty old but anyway: Is there any way to get actual positions and set them without GetVertexControl() method, since none is present?

Feb 16, 2012 at 11:29 AM
Edited Feb 16, 2012 at 11:29 AM

Hi guys, i am not an expert, i just have been working with graph# for a while. I am going to explain what works for me.

If you want to set de position of a vertex at the moment that is loaded, you just need to do it on Loaded event, i will show in code.

 

private void vertex_Loaded(object sender, RoutedEventArgs e)
{
            VertexControl aux = new VertexControl();
            aux = ((VertexControl)sender);

            double posx, posy;

            posx = "x position of vertex";
            posy = "y position of vertex";

            GraphCanvas.SetX(aux, posx);
            GraphCanvas.SetY(aux, posy);
                                                  
            e.Handled = true;
}

I hope it helps.

Apr 6, 2012 at 11:19 AM

hi dmartel, where do yuo declare your event handler? can you post the code?

 

thanks