Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic getNodeAt (Read 5407 times)
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
getNodeAt
Jan 3rd, 2016 at 5:25pm
Print Post  
Hi,
I have a problem with the method getNodeAt of Diagram, I have this code, where outLink is a DiagramLink:

PointF pt1 = outLink.getControlPoints().get(0);
PointF pt2 = outLink.getControlPoints().get(1);
PointF m = new PointF((pt1.x + pt2.x) / 2, (pt1.y + pt2.y) / 2);

if(diagram.getItemAt(m, false) != null)

Running it, it gives me this exception at line if(diagram.getItemAt(m, false) != null):

01-03 18:21:17.221 24562-24562/com.example.silvia.er E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.silvia.er, PID: 24562
java.lang.NullPointerException: Attempt to invoke virtual method 'double[] com.mindfusion.diagramming.ShapeData.getData(int)' on a null object reference
at com.mindfusion.diagramming.Shape.a(SourceFile:359)
at com.mindfusion.diagramming.ShapeNode.containsPoint(SourceFile:659)
at com.mindfusion.diagramming.Diagram.getItemAt(SourceFile:6788)
at com.mindfusion.diagramming.Diagram.getItemAt(SourceFile:6762)
at com.example.silvia.er.MainActivity.ReconstructER(MainActivity.java:6258)
at com.example.silvia.er.MainActivity$6.itemAdded(MainActivity.java:2547)
at com.mindfusion.diagramming.DiagramBase$65.a(SourceFile:127)
at com.mindfusion.diagramming.DiagramBase$65.a(SourceFile:1)
at com.mindfusion.diagramming.Diagram.a(SourceFile:416)
at com.mindfusion.diagramming.Diagram.a(SourceFile:9156)
at com.mindfusion.diagramming.Diagram.loadFrom(SourceFile:8864)
at com.mindfusion.diagramming.Diagram.b(SourceFile:1751)
at com.mindfusion.diagramming.Diagram.loadFrom(SourceFile:1744)
at com.example.silvia.er.MainActivity$2$1.onItemClick(MainActivity.java:321)
at android.widget.AdapterView.performItemClick(AdapterView.java:334)
at android.widget.AbsListView.performItemClick(AbsListView.java:1536)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3683)
at android.widget.AbsListView$3.run(AbsListView.java:5604)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6134)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

I need a way by looking at a saved diagram to know if there is a node attached to a link, how can I do?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: getNodeAt
Reply #1 - Jan 4th, 2016 at 1:18pm
Print Post  
Hi,

It seems unsafe to call getItemAt while the diagram is still loading because some items might not be fully loaded yet. You might get incorrect results anyway if there are overlapping nodes at that location; call outLink.getSubordinateGroup().getAttachedNodes() instead.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: getNodeAt
Reply #2 - Jan 6th, 2016 at 10:27am
Print Post  
Thank you but the problem is that I have the diagram in the attachment and I want to get the black node that there is in the middle of the link after having loaded the diagram that I have saved before, how can I do? I don't have a group.
  

esempio.png ( 2 KB | 158 Downloads )
esempio.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: getNodeAt
Reply #3 - Jan 6th, 2016 at 10:43am
Print Post  
Groups are automatically created by attachTo method which you were using at some point (http://mindfusion.eu/Forum/YaBB.pl?num=1441963426) and you can access nodes attached to a link through its SubordinateGroup property. If you no longer use attachTo, getItemAt will wok if you move it to a loop executing after loadFrom completes, but it's still unreliable if nodes overlap.
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: getNodeAt
Reply #4 - Jan 6th, 2016 at 10:50am
Print Post  
I used this: if(outLink.getSubordinateGroup().getAttachedNodes().get(0) != null)

but he gives me this exception:

01-06 11:50:35.932  31523-31523/com.example.silvia.er E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.silvia.er, PID: 31523
    java.lang.NullPointerException: Attempt to invoke virtual method 'com.mindfusion.diagramming.DiagramNodeList com.mindfusion.diagramming.Group.getAttachedNodes()' on a null object reference
            at com.example.silvia.er.MainActivity.ReconstructER(MainActivity.java:6255)
            at com.example.silvia.er.MainActivity$6.itemAdded(MainActivity.java:2547)
            at com.mindfusion.diagramming.DiagramBase$65.a(SourceFile:127)
            at com.mindfusion.diagramming.DiagramBase$65.a(SourceFile:1)
            at com.mindfusion.diagramming.Diagram.a(SourceFile:416)
            at com.mindfusion.diagramming.Diagram.a(SourceFile:9156)
            at com.mindfusion.diagramming.Diagram.loadFrom(SourceFile:8864)
            at com.mindfusion.diagramming.Diagram.b(SourceFile:1751)
            at com.mindfusion.diagramming.Diagram.loadFrom(SourceFile:1744)
            at com.example.silvia.er.MainActivity$2$1.onItemClick(MainActivity.java:321)
            at android.widget.AdapterView.performItemClick(AdapterView.java:334)
            at android.widget.AbsListView.performItemClick(AbsListView.java:1536)
            at android.widget.AbsListView$PerformClick.run(AbsListView.java:3683)
            at android.widget.AbsListView$3.run(AbsListView.java:5604)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:6134)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)

            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: getNodeAt
Reply #5 - Jan 6th, 2016 at 11:45am
Print Post  
You will need to call that too after loadFrom completes.
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: getNodeAt
Reply #6 - Jan 6th, 2016 at 3:04pm
Print Post  
But I did it after having loaded the diagram but getSubordinateGroup() is null, is there another way to get the node in the middle of the link?
I tried this way:
for(PointF p : outLink.getControlPoints()) {
           if(p != null) {
               if (diagram.getNodeAt(p) != null) {
                
               }
           }
}

but I have this problem:

01-06 16:31:42.042  12218-12218/com.example.silvia.er E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.silvia.er, PID: 12218
    java.lang.NullPointerException: Attempt to invoke virtual method 'double[] com.mindfusion.diagramming.ShapeData.getData(int)' on a null object reference
            at com.mindfusion.diagramming.Shape.a(SourceFile:359)
            at com.mindfusion.diagramming.ShapeNode.containsPoint(SourceFile:659)
            at com.mindfusion.diagramming.Diagram.getNodeAt(SourceFile:6553)
            at com.example.silvia.er.MainActivity.ReconstructER(MainActivity.java:6254)
            at com.example.silvia.er.MainActivity$6.itemAdded(MainActivity.java:2547)
            at com.mindfusion.diagramming.DiagramBase$65.a(SourceFile:127)
            at com.mindfusion.diagramming.DiagramBase$65.a(SourceFile:1)
            at com.mindfusion.diagramming.Diagram.a(SourceFile:416)
            at com.mindfusion.diagramming.Diagram.a(SourceFile:9156)
            at com.mindfusion.diagramming.Diagram.loadFrom(SourceFile:8864)
            at com.mindfusion.diagramming.Diagram.b(SourceFile:1751)
            at com.mindfusion.diagramming.Diagram.loadFrom(SourceFile:1744)
            at com.example.silvia.er.MainActivity$2$1.onItemClick(MainActivity.java:321)
            at android.widget.AdapterView.performItemClick(AdapterView.java:334)
            at android.widget.AbsListView.performItemClick(AbsListView.java:1536)
            at android.widget.AbsListView$PerformClick.run(AbsListView.java:3683)
            at android.widget.AbsListView$3.run(AbsListView.java:5604)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:6134)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)

            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
}
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: getNodeAt
Reply #7 - Jan 6th, 2016 at 3:56pm
Print Post  
The callstack shown still contains loadFrom method. Move whatever code you are running in itemAdded callback to a loop after loadFrom is executed and it will work. getSubordinateGroup returns null if you haven't attached anything so probably you have some links without attachments. Just check for null before trying to access the Group.attachedNodes list.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint