sfg.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /*
  2. * Copyright t lefering
  3. * parts are (C) Universitaet Passau 1986-1991
  4. * parts are Copyright (C) 1998-2021 Free Software Foundation, Inc.
  5. * parts are Copyright (C) Felix von Leitner from dietlibc
  6. *
  7. * https://notabug.org/mooigraph/sfgraph
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * These are the four essential freedoms with GNU GPL software:
  23. * 1: freedom to run the program, for any purpose
  24. * 2: freedom to study how the program works, and change it to make it do what you wish
  25. * 3: freedom to redistribute copies to help your Free Software friends
  26. * 4: freedom to distribute copies of your modified versions to your Free Software friends
  27. * , ,
  28. * / \
  29. * ((__-^^-,-^^-__))
  30. * `-_---' `---_-'
  31. * `--|o` 'o|--'
  32. * \ ` /
  33. * ): :(
  34. * :o_o:
  35. * "-"
  36. *
  37. * SPDX-License-Identifier: GPL-3.0+
  38. * License-Filename: LICENSE
  39. */
  40. #ifndef SFG_H
  41. #define SFG_H 1
  42. #undef __BEGIN_DECLS
  43. #undef __END_DECLS
  44. #ifdef __cplusplus
  45. # define __BEGIN_DECLS extern "C" {
  46. # define __END_DECLS }
  47. #else
  48. # define __BEGIN_DECLS /* empty */
  49. # define __END_DECLS /* empty */
  50. #endif
  51. __BEGIN_DECLS
  52. /* at top of sfg.c the sfg_calloc() and sfg_free() can be edited for customized malloc/free */
  53. /* returns a version number as version 1.0 returns int 10 */
  54. extern int sfg_version(void);
  55. /* init
  56. * returns 0 if oke
  57. * returns -1 if already inited
  58. * returns -2 if other error
  59. */
  60. extern int sfg_init(void);
  61. /* de-init
  62. * returns 0 if oke
  63. * returns -1 if not inited
  64. */
  65. extern int sfg_deinit(void);
  66. /* add a node with uniq number starting at 1
  67. * with (tx,ty) as rectangle size for label text or (0,0)
  68. * before adding edges all node numbers must be defined
  69. * the data is optional and can be pointer too own structure
  70. * returns 0 if oke
  71. * returns -1 if not inited
  72. * returns -2 if number is lower then 1
  73. * returns -3 if tx number is lower then 0
  74. * returns -4 if ty number is lower then 0
  75. * returns -5 if layout already done
  76. * returns -6 if node already defined
  77. * returns -7 if other error
  78. */
  79. extern int sfg_addnode(int number, int tx, int ty);
  80. /* add a edge with uniq number starting at 1
  81. * the from-node number is in from, the to-node number is in to
  82. * self-edges are allowed but not with a label
  83. * with (tx,ty) as rectangle size for label text or (0,0)
  84. * the data is optional and can be pointer too own structure
  85. * returns 0 if oke
  86. * returns -1 if not inited
  87. * returns -2 if number is lower then 1
  88. * returns -3 if tx number is lower then 0
  89. * returns -4 if ty number is lower then 0
  90. * returns -5 if from-node number is not defined
  91. * returns -6 if to-node number is not defined
  92. * returns -7 if self-edge with a label
  93. * returns -8 if layout already done
  94. * returns -9 if other error
  95. */
  96. extern int sfg_addedge(int number, int from, int to, int tx, int ty);
  97. /* run sugiyama barycenter layout
  98. * returns 0 if oke
  99. * returns -1 if not inited
  100. * returns -2 if layout already done
  101. * returns -3 if no nodes in the graph
  102. */
  103. extern int sfg_layout(void);
  104. /* return edge crossings in the graph
  105. * returns crossings >= 0 if oke
  106. * returns -1 if layout is not done
  107. */
  108. extern int sfg_crossings(void);
  109. /* return initial edge crossings in the graph
  110. * returns crossings >= 0 if oke
  111. * returns -1 if not inited
  112. * returns -2 if layout not done
  113. */
  114. extern int sfg_initialcrossings(void);
  115. /* get min node number in use after layout
  116. * returns value if oke
  117. * returns -1 if not inited
  118. * returns -2 if layout not done
  119. * returns -3 if there are no nodes
  120. */
  121. extern int sfg_nodemin(void);
  122. /* get maxc node number in use after layout
  123. * returns value if oke
  124. * returns -1 if not inited
  125. * returns -2 if layout not done
  126. * returns -3 if there are no nodes
  127. */
  128. extern int sfg_nodemax(void);
  129. /* get min edge number in use after layout
  130. * returns value if oke
  131. * returns -1 if not inited
  132. * returns -2 if layout not done
  133. * returns -3 if there are no edges
  134. */
  135. extern int sfg_edgemin(void);
  136. /* get max edge number in use after layout
  137. * returns value if oke
  138. * returns -1 if not inited
  139. * returns -2 if layout not done
  140. * returns -3 if there are no edges
  141. */
  142. extern int sfg_edgemax(void);
  143. /* set 1 to add edgelabels, or 0 to remove edgelabels
  144. * returns crossings >= 0 if oke
  145. * returns -1 if not inited
  146. * returns -2 if layout not done
  147. */
  148. extern int sfg_edgelabels(int status);
  149. /* return x pos of node with uniq number
  150. * returns >= 0 if oke
  151. * returns -1 if not inited
  152. * returns -2 if layout not done
  153. * returns -3 if number < 1
  154. * returns -4 if node not found
  155. */
  156. extern int sfg_nodexpos(int num);
  157. /* return y pos of node with uniq number
  158. * returns >= 0 if oke
  159. * returns -1 if not inited
  160. * returns -2 if layout not done
  161. * returns -3 if number < 1
  162. * returns -4 if node not found
  163. */
  164. extern int sfg_nodeypos(int num);
  165. /* return relative x pos of node with uniq number
  166. * returns >= 0 if oke
  167. * returns -1 if not inited
  168. * returns -2 if layout not done
  169. * returns -3 if number < 1
  170. * returns -4 if node not found
  171. */
  172. extern int sfg_noderelxpos(int num);
  173. /* return relative y pos of node with uniq number
  174. * returns >= 0 if oke
  175. * returns -1 if not inited
  176. * returns -2 if layout not done
  177. * returns -3 if number < 1
  178. * returns -4 if node not found
  179. */
  180. extern int sfg_noderelypos(int num);
  181. /* return level y start pos of node with uniq number
  182. * returns >= 0 if oke
  183. * returns -1 if not inited
  184. * returns -2 if layout not done
  185. * returns -3 if number < 1
  186. * returns -4 if node not found
  187. */
  188. extern int sfg_nodely0(int num);
  189. /* return level y end pos of node with uniq number
  190. * returns >= 0 if oke
  191. * returns -1 if not inited
  192. * returns -2 if layout not done
  193. * returns -3 if number < 1
  194. * returns -4 if node not found
  195. */
  196. extern int sfg_nodely1(int num);
  197. /* return x size of node with uniq number
  198. * returns >= 0 if oke
  199. * returns -1 if not inited
  200. * returns -2 if layout not done
  201. * returns -3 if number < 1
  202. * returns -4 if node not found
  203. */
  204. extern int sfg_nodexsize(int num);
  205. /* return y size of node with uniq number
  206. * returns >= 0 if oke
  207. * returns -1 if not inited
  208. * returns -2 if layout not done
  209. * returns -3 if number < 1
  210. * returns -4 if node not found
  211. */
  212. extern int sfg_nodeysize(int num);
  213. /* set min. x spacing between nodes
  214. * returns 0 if oke
  215. * returns -1 if not inited
  216. * returns -2 if number is lower then 0
  217. * returns -3 if layout already done
  218. */
  219. extern int sfg_xspacing(int num);
  220. /* set min. y spacing between nodes
  221. * returns 0 if oke
  222. * returns -1 if not inited
  223. * returns -2 if number is lower then 0
  224. * returns -3 if layout already done
  225. */
  226. extern int sfg_yspacing(int num);
  227. /* return type of node with uniq number
  228. * returns type of node, 1=regular, 2=dummy, 3=edgelabel node
  229. * returns -1 not inited
  230. * returns -2 if layout not done
  231. * returns -3 if nodenumber is < 1
  232. * returns -4 if node not found
  233. */
  234. extern int sfg_nodetype(int num);
  235. /* return number of selfedges at node
  236. * returns number of selfedges if oke
  237. * returns -1 not inited
  238. * returns -2 if layout not done
  239. * returns -3 if nodenumber is < 1
  240. * returns -4 if node not found
  241. */
  242. extern int sfg_nodeselfedges(int num);
  243. /* return number of incoming edges to node
  244. * returns indegree number if oke
  245. * returns -1 not inited
  246. * returns -2 if layout not done
  247. * returns -3 if nodenumber is < 1
  248. * returns -4 if node not found
  249. */
  250. extern int sfg_nodeindegree(int num);
  251. /* return number of outgoing edges from node
  252. * returns outdegree number if oke
  253. * returns -1 not inited
  254. * returns -2 if layout not done
  255. * returns -3 if nodenumber is < 1
  256. * returns -4 if node not found
  257. */
  258. extern int sfg_nodeoutdegree(int num);
  259. /* return edge number of node if edgelabel node
  260. * returns number of original edge with edgelabel if oke
  261. * returns -1 not inited
  262. * returns -2 if layout not done
  263. * returns -3 if nodenumber is < 1
  264. * returns -4 if node not found
  265. * returns -5 if node is not edgelabel
  266. */
  267. extern int sfg_nodeenum(int num);
  268. /* get optional data pointer of node
  269. * returns data pointer if oke
  270. * returns NULL if not inited
  271. * returns NULL if layout not done
  272. * returns NULL if nodenumber is < 1
  273. * returns NULL if node not found
  274. */
  275. extern void *sfg_nodedata(int num);
  276. /* set optional data pointer of node
  277. * returns 0 if oke
  278. * returns -1 if not inited
  279. * returns -2 if layout not done
  280. * returns -3 if nodenumber is < 1
  281. * returns -4 if node not found
  282. */
  283. extern int sfg_setnodedata(int num, void *data);
  284. /* get from-node of edge
  285. * returns from-node number if oke
  286. * returns -1 not inited
  287. * returns -2 if layout not done
  288. * returns -3 if edgenumber is < 1
  289. * returns -4 if edge not found
  290. */
  291. extern int sfg_edgefrom(int num);
  292. /* get to-node of edge
  293. * returns to-node number if oke
  294. * returns -1 not inited
  295. * returns -2 if layout not done
  296. * returns -3 if edgenumber is < 1
  297. * returns -4 if edge not found
  298. */
  299. extern int sfg_edgeto(int num);
  300. /* get edge type
  301. * returns type if oke, 1=regular, 2=selfedge, 3=hor. edge
  302. * returns -1 not inited
  303. * returns -2 if layout not done
  304. * returns -3 if edgenumber is < 1
  305. * returns -4 if edge not found
  306. */
  307. extern int sfg_edgetype(int num);
  308. /* get edge reversed status
  309. * returns 1 if reversed edge or 0 if not
  310. * returns -1 not inited
  311. * returns -2 if layout not done
  312. * returns -3 if edgenumber is < 1
  313. * returns -4 if edge not found
  314. */
  315. extern int sfg_edgerev(int num);
  316. /* get max x pos in drawing
  317. * returns value if oke
  318. * returns -1 if not inited
  319. * returns -2 if layout not done
  320. */
  321. extern int sfg_maxx(void);
  322. /* get max y pos in drawing
  323. * returns value if oke
  324. * returns -1 if not inited
  325. * returns -2 if layout not done
  326. */
  327. extern int sfg_maxy(void);
  328. /* get number of levels
  329. * returns value if oke
  330. * returns -1 if not inited
  331. * returns -2 if layout not done
  332. */
  333. extern int sfg_nlevels(void);
  334. /* get number of nodes
  335. * returns value if oke
  336. * returns -1 if not inited
  337. * returns -2 if layout not done
  338. */
  339. extern int sfg_nnodes(void);
  340. /* get number of edges
  341. * returns value if oke
  342. * returns -1 if not inited
  343. * returns -2 if layout not done
  344. */
  345. extern int sfg_nedges(void);
  346. /* get node data and the calculated positions
  347. * the user must supply a pointer to the callback routine
  348. * this runs a supplied callback routine for every node
  349. * the callback routine gets the node number as supplied,
  350. * the level as supplied and the calculated pos position.
  351. * the data is the supplied data and can be used similar.
  352. * when the callback function needs to stop the iteration
  353. * over the node list then it must return a non-zero status
  354. * and that status is returned by sfg_node_foreach()
  355. * the parameters in the callback function are
  356. * int num, uniq node number
  357. * int level, relative vertical level
  358. * int pos, relative horizontal level
  359. * void *data, optional user data
  360. * int xpos, x-coord of upperleft node label area or 0 at no label
  361. * int ypos, y-coord of upperleft node label area or 0 at no label
  362. * int tx, x size of text area
  363. * int ty, y size of text area
  364. * int nselfedges, number of self-edges at this node
  365. * int type, type of node, 1=regular, 2=dummy, 3=edgelabel node
  366. * int indegree, number of incoming edges to the node
  367. * int outdegree, number of outgoing edges from the node
  368. * int ly0, start y of level of node
  369. * int ly1, end y of level of node
  370. * returns 0 from this routine if everything is oke or no data.
  371. * returns -1 if not inited
  372. * returns -2 if no layout is done
  373. * returns -3 if no callback routine
  374. */
  375. extern int sfg_node_foreach(int (*getnodedata)
  376. (int num, int level, int pos, int xpos, int ypos, int tx, int ty, int nselfedges, int type,
  377. int indegree, int outdegree, int ly0, int ly1));
  378. /* get edge data and the calculated position
  379. * the user must supply a pointer to the callback routine
  380. * this runs a supplied callback routine for every edge
  381. * when the callback function needs to stop the iteration
  382. * over the edge list then it must return a non-zero status
  383. * the parameters in the callback function are
  384. * int num, uniq edge number
  385. * int from, uniq from-node number
  386. * int to, uniq to-node number
  387. * void *data, optional user data
  388. * int type, 1=regular, 2=selfedge, 3=horizontal-edge
  389. * int rev, set if edge is reversed
  390. * returns 0 if oke
  391. * returns -1 if not inited
  392. * returns -2 if no layout is done
  393. * returns -3 if no callback routine
  394. */
  395. extern int sfg_edge_foreach(int (*getedgedata)(int num, int from, int to, int type, int rev));
  396. __END_DECLS
  397. #endif
  398. /* end */