Graph Editor ! (V0.3.6)

User projects written in or related to FreeBASIC.
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Post by AGS »

Hezad wrote:UPDATE :

Uploaded a new version (V0.1):
- Floyd algorithm is partially implemented (Works only on Non oriented Graph for now. Using it on an oriented Graph can make the program to crash)

What's next ?
- Find a way to make Floyd algorithm to work on oriented Graphs
- Implement Prim's algorithm
- I'm thinking about using a gfx library for visualisation screen like some people advised. Just in brain for now ^^
I compiled the program and used
http://luaforge.net/frs/download.php/24 ... ll_lib.zip

Or rather: I used the file iup.dll (it's inside the .zip). And you will need it to run the program.

What you've made thus far Looks nice, Hezad.

I took a look at your source - code and I think the file - loading - routine does not take into account the number of vertices and/or arcs read. The arrays you are reading the strings into are limited in size and sooner or later the arrays might become full. What if the array is filled up before eof?

I made myself a nice shortcutkey (so I can use the program without the mouse) by putting an & in front of the Update Graph - button. Doesn't look nice (the "&" gets printed) but it works.

Now if only those keys on the drawing - canvas (F5/F6) could be put inside
the frame on the left....... that would be perfect :) Because if I start the program now three windows get opened. If those could somehow be combined into one that would be something.

To round my post of a last comment on the file format. It seems there is more then one graph - format called tgf. There is the trivial graph format (the one used in this project ) and there is the treegraph - format (mentioned in an earlier post). Neither of these tgf - formats is a proprietary - format.
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Post by AGS »

I succesfully opened all sorts of files with the load button :) Ranging from .exe -files to .pdf - files. And one of the .pdf - files even loaded more or less 'all right' (a graph appeared). All of this was possible because in the file - dialog I can fill the dialog with a wildcard ('*').

Perhaps checking the file - format would help (validating). What I did was of course a bit 'strange' (no user of the graph - program is going to load a .exe - file with it) but what if there is a file, with a .tgf - extension, on the disk that isn't a tgf - file after all? A message like 'not a tgf - file' would be nice.

Validation of a file - format like tgf shouldn't be too hard.

None of the 'illegal' tgf - files broke the application though. It kept on going. I guess a string is a string is a string so even if the loaded data isn't a valid graph the program keeps on going. And since strings can be quite lengthy the program does not crash.

When I entered a very large, 'legal' graph and asked the program to "Update graph" the vertices started flying off - screen :) After looking at the vertices moving around the screen for some time I asked to "Get from graph". 127 vertices was all that I got (the rest had vanished into thin air).
Hezad
Posts: 469
Joined: Dec 17, 2006 23:37
Contact:

Post by Hezad »

Wow thanks a lot for your feedback, it's really helpful !

1st post :
1)
I used the file iup.dll (it's inside the .zip). And you will need it to run the program.
So the dll is the only needed file in the library for the program to work? If yes, i'll put the dll in the next update zip.

2)
I took a look at your source - code and I think the file - loading - routine does not take into account the number of vertices and/or arcs read. The arrays you are reading the strings into are limited in size and sooner or later the arrays might become full. What if the array is filled up before eof?
Do you advise me to put dynamic arrays? or the possibility to specify the max vertices and max arcs in GraphConf.txt?

3) I like the idea of shortcut keys, i'll think about that !

4)
Now if only those keys on the drawing - canvas (F5/F6) could be put inside
the frame on the left....... that would be perfect :) Because if I start the program now three windows get opened. If those could somehow be combined into one that would be something.
Yeah I thought about it, adding buttons on the "menu" dialog and keeping F5/F6 only as shortcut keys. I'll think about that too :)

5) Thanks for the precision about the format :)

2nd Post :

1) Concerning the pdf/exe's loaded i'll just say "oO", I really didn't thought about checking if file is a "good" file or not. I'll try to add some lines in the loading routing to check the file in the next update :)

2) Vertices flying off screen : Yeah that's a problem with the "pseudo-nice looking routine". I should fix it but I don't know yet if i'll keep this routine or write a new/better one. Anyway, I'll implement an option to set the vertices radius. A big/complicated graph can't fit in screen with this radius ^^

3)
127 vertices was all that I got (the rest had vanished into thin air).
Hum .. Weird it surely has to do with 2)


I thought about drawing graph in an IUP canvas instead of the fb graphics screen too but it'd need a total rewriting of the rendering / user input routines. I'll surely code it someday but I really don't know when.

Thanks again for your post ! It will make Graph Editor better and better.
Hezad
Posts: 469
Joined: Dec 17, 2006 23:37
Contact:

Post by Hezad »

UPDATE !
There are Major changes in this version :)

V0.1.1 changes :
Major :
- FULLY WORKING KRUSKAL ALGORITHM (Covering Tree) !
- FULLY WORKING FLOYD ALGORITHM ! On both oriented and non oriented Graphs !
- Switching Oriented/Non oriented and Weighted/Non weighted can be made by the menu Dialog

Minor :
- Added ReadMe File (Incomplete)

Fixed :
- A message box will appear if no path exists between specified vertices (Floyd)
- Iup.dll provided with the package
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Post by AGS »

Hezad wrote: 1) So the dll is the only needed file in the library for the program to work? If yes, i'll put the dll in the next update zip.
Yes, the dll (iup.dll) is the only needed file.
Hezad wrote: 2)Do you advise me to put dynamic arrays? or the possibility to specify the max vertices and max arcs in GraphConf.txt?
No, I think things are okay as they are. But you'll have to check bounds when loading a file (or when the user cuts and pastes a large graph into the text - area) and you'll have to check something else as well.

When I compiled the program with the option -exx and tried to load too big a file I got a runtime error.

Aborting due to runtime error 6 (out of bounds array access) at line 436 of D:/Program Files/FreeBASIC/GraphLib.bi::LOADTGFFILE()

I got another one when trying to "Update the graph" from an empty graph (text - area was empty):

Aborting due to runtime error 6 (out of bounds array access) at line 111 of D:/Program Files/FreeBAS IC/GraphLib.bi::RENDERGRAPH()
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Post by AGS »

Hezad wrote:UPDATE !
There are Major changes in this version :)

V0.1.1 changes :
Major :
- FULLY WORKING KRUSKAL ALGORITHM (Covering Tree) !
- FULLY WORKING FLOYD ALGORITHM ! On both oriented and non oriented Graphs !
- Switching Oriented/Non oriented and Weighted/Non weighted can be made by the menu Dialog

Minor :
- Added ReadMe File (Incomplete)

Fixed :
- A message box will appear if no path exists between specified vertices (Floyd)
- Iup.dll provided with the package
Splendid, another update! O yes, there is something not right with the "Get from graph - button" (manual). The graph that was already in the text - area does not get cleaned up afetr getting the graph. If I enter the following graph:

1
2
3
4
5
6
7
8
9
#

and then push "Update graph" followed by "Get from graph" I get

1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
#

in the text area.
Hezad
Posts: 469
Joined: Dec 17, 2006 23:37
Contact:

Post by Hezad »

Hum okay, then i'll check if Graph is in Array limits when loading !
I got another one when trying to "Update the graph" from an empty graph (text - area was empty):

Aborting due to runtime error 6 (out of bounds array access) at line 111 of D:/Program Files/FreeBAS IC/GraphLib.bi::RENDERGRAPH()
Hum this one one is weird, i'll check it

thanks for feedback again
Hezad
Posts: 469
Joined: Dec 17, 2006 23:37
Contact:

Post by Hezad »

UPDATE !

--> V0.1.2 Changes :

Graph Editor :
- File Checking Routine (Warning, added pseudo-header to Tgf Files, old ones won't load anymore. To avoid this, add ;/ to the first line of the file.

Fixed :
- ACTIVE/NOT ACTIVE elements of GUI
- "Get from Graph"-in-Manual-Refresh-Mode's bug fixed

ISSUE : Hum .. I tried to increase max_vertex and max_arcs values to build bigger graphs but then the program crash while running the Kruskal routine. I don't know why so for now, MAX_VERTEX is limited to 150 and MAX_ARC to 200 and it works perfectly.
Hezad
Posts: 469
Joined: Dec 17, 2006 23:37
Contact:

Post by Hezad »

UPDATE V0.2 !

--> V0.2

Graph Editor :
- Better Looking GUI
- (New Setting) Vertices Radius
- (New Setting) Degree Relative Radius
- Added Settings Dialog (Automatically updates GraphConf.txt)
- Added Infos Section

Fixed :
- AddArcToGraph() won't add Arc between vertices if they are already adjacent
Hezad
Posts: 469
Joined: Dec 17, 2006 23:37
Contact:

Post by Hezad »

Hum .. I'm beginning to code rendering in an IUP Canvas instead of fb's GFX screen BUT :

Er .. I created a canvas, no problem. How do I draw on it ?! In the official IUP doc, all the examples files are using instructions starting with "cd****" to draw something but I can't find anything like this in the FB's headers.

Once i'll know how to do this, Graph Editor will render, edit, analyse, etc.. in the same window :p

So, any idea ?
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Post by AGS »

Hezad wrote:Hum .. I'm beginning to code rendering in an IUP Canvas instead of fb's GFX screen BUT :

Er .. I created a canvas, no problem. How do I draw on it ?! In the official IUP doc, all the examples files are using instructions starting with "cd****" to draw something but I can't find anything like this in the FB's headers.

Once i'll know how to do this, Graph Editor will render, edit, analyse, etc.. in the same window :p

So, any idea ?
You can get extra controls for IUP. There is, for instance, an IupGLCanvas, that can be used for drawing things on using GL (GLX - screen?).

All the extra controls can be found in one file called iupcontrols.dll that is available here:
http://luaforge.net/frs/download.php/24 ... l8_lib.zip

Inside the .zip - file is a file called iupcontrols.dll that you can use. But how to use it in FreeBASIC? There is an include - file for this dll inside the FreeBASIC - distribution (called iupcontrols.bi) but it lacks the declarations you'll need to build a IupGLcanvas.

I could think of two ways to get past this problem:

1. Create a new import - library for the dll containing the extra controls.
2. Call the functions inside the DLL using a combination of Dim function .. As ....., dylibload and dylibsymbol. You'd have to redo the .bi - include file a bit to use this option.

Option 1 is of course the preferred option but do you know how to build an import - library (a .dll.a?) I don't. That's why I use option 2.

It is an option I've used myself and it works. First you have to (partly) redo the original include - file (.bi). Inside the original include - file you see a lot of lines that look like this:

declare function [name] (arguments) as result

To use such a line inside the new include - file you could simply do one big find - and - replace (of course you have given the new include - file a differenct name than the orginial include - file?) replacing

'declare' with 'dim' and replacing
'function' with 'function as'

And there you go, a new include -file. Do not forget to remove the lines "extern c"
"end extern"

from the new include - file.

How to use this include - file?

Just include the new .bi - file inside the .bas - file where you want to use the dll - functions . Inside that .bas - file you put this:

Dim hndl As Any Ptr

hndl=DyLibLoad("dllname.dll")

and for every function declared inside the .bi that you want to use you do:

functionname = DyLibSymbol( hndl, "functionname" )

Of course you could get a lot of these last lines automatically from the .bi - file by using a regular - expression find-and-replace. However, you usually just need a couple of functions from the dll so that is not really needed.

For instance, I myself have used zlib1.dll and only needed two functions. I didn't even write an include - file for this (two Dim function... As were enough).

Now a vital point: can you read c - header - files? If so, all is well because you just make a copy of the include - library that is already there (iupcontrols.bi), change that in the way I suggested and then add some lines from the c - header - file. Those lines have to be changed to FreeBASIC - syntax.

Since the entire iupgl.h is missing from the freebasic include - library you'll need to add that. Luckily there is not much inside that header - file (and most of it is almost in FreeBASIC - syntax :) ).

If you have any problem reading the c - header - files or getting IUP to work just let me know. And if you somehow find out how to build include - libraries yourself please post it here. I am sure somewhere on this forum the info on building import - libraries can be found but I haven't found this information yet (for instance, where is the swig - fb - file?).

Hope this post was of some help to you. Will be testing the last version of the graph - editor soon...
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Post by AGS »

Just adding a bit to my last post. Just in case you were wondering where the c - header - files are: the c - header - files are inside iup2_6_rc2_Win32_dll8_lib.zip\include\

The iupgl.h file contains only six functions. You can use any function you can use with a 'normal' IupCanvas with a IupGLCanvas and, in addition to that, any GL - function.

There are some examples (in C) on using an IupGLCanvas inside

http://luaforge.net/frs/download.php/23 ... amples.zip

The examples are written in C and in Lua. Lua - source looks a bit like FreeBASIC - source though.

Can't wait for you to finish the GUI :)
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Post by AGS »

I've been playing around with import - libraries and I think I've solved the problem. You can get the latest .dll and build a .dll.a from that.

How to do it can be found on the forum:
http://www.freebasic.net/forum/viewtopic.php?t=1739

You basically do this:

- get the iupcontrols.dll
- start a command-shell and enter this:
pexports iupcontrols.dll iupcontrols.def <enter>
dlltool -d iupcontrols.def iupcontrols.dll.a <enter>

Then you should have the import - library that you put inside the directory /lib/ (replacing the old import - libary). If you are wondering what pexports is or where to get it, you can get it from sourceforge using the following link:

http://downloads.sourceforge.net/mingw/ ... g_mirror=1

The program dlltool is not inside mingw - utils but you should already have dlltool in the bin - directory of the FreeBASIC - distribution.

dlltool by the way needs as (as is in the FreeBASIC - distribution so no problem there).

To get a .bi - file (in order to be able to do an #include) you
create a text - file called iupcontrols.i and put this inside it:

%module iupcontrols
%include iupcontrols.h

Then, using swig freebasic, you do this (from a commandshell):
swig iupcontrols.i

which should result in the creation of a file called iupcontrols.bi. That file should be put inside the directory where all the other IUP - files can be found (/inc/IUP/).

Now you can use iupcontrols.dll (#include iupcontrols.bi)

Iupcontrols, however, does not contain IUpGLCanvas: de GL - canvas is inside iupgl.dll. The above procedure should be followed for iupgl.dll as well.

A link to swig - FreeBASIC (in case you cannot find it):
http://www.freebasic.net/temp/swig_fb.zip
Hezad
Posts: 469
Joined: Dec 17, 2006 23:37
Contact:

Post by Hezad »

THAT is an explanation ^^ I can't say you how much I thank you for all those informations !! I can't code for now : I'm not at home. But once i'll be home, i'll post a real answer to your posts and start to code :)

thanks again !!!
Hezad
Posts: 469
Joined: Dec 17, 2006 23:37
Contact:

Post by Hezad »

Re edit :

Everything's fine ! IupGl is now imported and I added IupGL.bi directly in Iup.bi
I can start to code a new GL render engine :D

Problem (yeah, again :p) :
(Solved)
Post Reply