sfg.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. /* returns a version number as version 1.0 returns int 10 */
  43. extern int sfg_version(void);
  44. /* init
  45. * returns 0 if oke
  46. * returns -1 if already inited
  47. * returns -2 if other error
  48. */
  49. extern int sfg_init(void);
  50. /* de-init
  51. * returns 0 if oke
  52. * returns -1 if not inited
  53. */
  54. extern int sfg_deinit(void);
  55. /* add a node with uniq number starting at 1
  56. * with (tx,ty) as rectangle size for label text or (0,0)
  57. * before adding edges all node numbers must be defined
  58. * the data is optional and can be pointer too own structure
  59. * returns 0 if oke
  60. * returns -1 if not inited
  61. * returns -2 if number is lower then 1
  62. * returns -3 if tx number is lower then 0
  63. * returns -4 if ty number is lower then 0
  64. * returns -5 if layout already done
  65. * returns -6 if node already defined
  66. * returns -7 if other error
  67. */
  68. extern int sfg_addnode(int number, int tx, int ty);
  69. /* add a edge with uniq number starting at 1
  70. * the from-node number is in from, the to-node number is in to
  71. * self-edges are allowed but not with a label
  72. * with (tx,ty) as rectangle size for label text or (0,0)
  73. * the data is optional and can be pointer too own structure
  74. * returns 0 if oke
  75. * returns -1 if not inited
  76. * returns -2 if number is lower then 1
  77. * returns -3 if tx number is lower then 0
  78. * returns -4 if ty number is lower then 0
  79. * returns -5 if from-node number is not defined
  80. * returns -6 if to-node number is not defined
  81. * returns -7 if self-edge with a label
  82. * returns -8 if layout already done
  83. * returns -9 if other error
  84. */
  85. extern int sfg_addedge(int number, int from, int to, int tx, int ty);
  86. /* run sugiyama barycenter layout
  87. * returns 0 if oke
  88. * returns -1 if not inited
  89. * returns -2 if layout already done
  90. * returns -3 if no nodes in the graph
  91. */
  92. extern int sfg_layout(void);
  93. /* return edge crossings in the graph
  94. * returns crossings >= 0 if oke
  95. * returns -1 if layout is not done
  96. */
  97. extern int sfg_crossings(void);
  98. /* return initial edge crossings in the graph
  99. * returns crossings >= 0 if oke
  100. * returns -1 if not inited
  101. * returns -2 if layout not done
  102. */
  103. extern int sfg_initialcrossings(void);
  104. /* get min node number in use after layout
  105. * returns value if oke
  106. * returns -1 if not inited
  107. * returns -2 if layout not done
  108. * returns -3 if there are no nodes
  109. */
  110. extern int sfg_nodemin(void);
  111. /* get maxc node number in use after layout
  112. * returns value if oke
  113. * returns -1 if not inited
  114. * returns -2 if layout not done
  115. * returns -3 if there are no nodes
  116. */
  117. extern int sfg_nodemax(void);
  118. /* get min edge number in use after layout
  119. * returns value if oke
  120. * returns -1 if not inited
  121. * returns -2 if layout not done
  122. * returns -3 if there are no edges
  123. */
  124. extern int sfg_edgemin(void);
  125. /* get max edge number in use after layout
  126. * returns value if oke
  127. * returns -1 if not inited
  128. * returns -2 if layout not done
  129. * returns -3 if there are no edges
  130. */
  131. extern int sfg_edgemax(void);
  132. /* set 1 to add edgelabels, or 0 to remove edgelabels
  133. * returns crossings >= 0 if oke
  134. * returns -1 if not inited
  135. * returns -2 if layout not done
  136. */
  137. extern int sfg_edgelabels(int status);
  138. /* return x pos of node with uniq number
  139. * returns >= 0 if oke
  140. * returns -1 if not inited
  141. * returns -2 if layout not done
  142. * returns -3 if number < 1
  143. * returns -4 if node not found
  144. */
  145. extern int sfg_nodexpos(int num);
  146. /* return y pos of node with uniq number
  147. * returns >= 0 if oke
  148. * returns -1 if not inited
  149. * returns -2 if layout not done
  150. * returns -3 if number < 1
  151. * returns -4 if node not found
  152. */
  153. extern int sfg_nodeypos(int num);
  154. /* return relative x pos of node with uniq number
  155. * returns >= 0 if oke
  156. * returns -1 if not inited
  157. * returns -2 if layout not done
  158. * returns -3 if number < 1
  159. * returns -4 if node not found
  160. */
  161. extern int sfg_noderelxpos(int num);
  162. /* return relative y pos of node with uniq number
  163. * returns >= 0 if oke
  164. * returns -1 if not inited
  165. * returns -2 if layout not done
  166. * returns -3 if number < 1
  167. * returns -4 if node not found
  168. */
  169. extern int sfg_noderelypos(int num);
  170. /* return level y start pos of node with uniq number
  171. * returns >= 0 if oke
  172. * returns -1 if not inited
  173. * returns -2 if layout not done
  174. * returns -3 if number < 1
  175. * returns -4 if node not found
  176. */
  177. extern int sfg_nodely0(int num);
  178. /* return level y end pos of node with uniq number
  179. * returns >= 0 if oke
  180. * returns -1 if not inited
  181. * returns -2 if layout not done
  182. * returns -3 if number < 1
  183. * returns -4 if node not found
  184. */
  185. extern int sfg_nodely1(int num);
  186. /* return x size of node with uniq number
  187. * returns >= 0 if oke
  188. * returns -1 if not inited
  189. * returns -2 if layout not done
  190. * returns -3 if number < 1
  191. * returns -4 if node not found
  192. */
  193. extern int sfg_nodexsize(int num);
  194. /* return y size of node with uniq number
  195. * returns >= 0 if oke
  196. * returns -1 if not inited
  197. * returns -2 if layout not done
  198. * returns -3 if number < 1
  199. * returns -4 if node not found
  200. */
  201. extern int sfg_nodeysize(int num);
  202. /* set min. x spacing between nodes
  203. * returns 0 if oke
  204. * returns -1 if not inited
  205. * returns -2 if number is lower then 0
  206. * returns -3 if layout already done
  207. */
  208. extern int sfg_xspacing(int num);
  209. /* set min. y spacing between nodes
  210. * returns 0 if oke
  211. * returns -1 if not inited
  212. * returns -2 if number is lower then 0
  213. * returns -3 if layout already done
  214. */
  215. extern int sfg_yspacing(int num);
  216. /* return type of node with uniq number
  217. * returns type of node, 1=regular, 2=dummy, 3=edgelabel node
  218. * returns -1 not inited
  219. * returns -2 if layout not done
  220. * returns -3 if nodenumber is < 1
  221. * returns -4 if node not found
  222. */
  223. extern int sfg_nodetype(int num);
  224. /* return number of selfedges at node
  225. * returns number of selfedges if oke
  226. * returns -1 not inited
  227. * returns -2 if layout not done
  228. * returns -3 if nodenumber is < 1
  229. * returns -4 if node not found
  230. */
  231. extern int sfg_nodeselfedges(int num);
  232. /* return number of incoming edges to node
  233. * returns indegree number if oke
  234. * returns -1 not inited
  235. * returns -2 if layout not done
  236. * returns -3 if nodenumber is < 1
  237. * returns -4 if node not found
  238. */
  239. extern int sfg_nodeindegree(int num);
  240. /* return number of outgoing edges from node
  241. * returns outdegree number if oke
  242. * returns -1 not inited
  243. * returns -2 if layout not done
  244. * returns -3 if nodenumber is < 1
  245. * returns -4 if node not found
  246. */
  247. extern int sfg_nodeoutdegree(int num);
  248. /* return edge number of node if edgelabel node
  249. * returns number of original edge with edgelabel if oke
  250. * returns -1 not inited
  251. * returns -2 if layout not done
  252. * returns -3 if nodenumber is < 1
  253. * returns -4 if node not found
  254. * returns -5 if node is not edgelabel
  255. */
  256. extern int sfg_nodeenum(int num);
  257. /* get optional data pointer of node
  258. * returns data pointer if oke
  259. * returns NULL if not inited
  260. * returns NULL if layout not done
  261. * returns NULL if nodenumber is < 1
  262. * returns NULL if node not found
  263. */
  264. extern void *sfg_nodedata(int num);
  265. /* set optional data pointer of node
  266. * returns 0 if oke
  267. * returns -1 if not inited
  268. * returns -2 if layout not done
  269. * returns -3 if nodenumber is < 1
  270. * returns -4 if node not found
  271. */
  272. extern int sfg_setnodedata(int num, void *data);
  273. /* get from-node of edge
  274. * returns from-node number if oke
  275. * returns -1 not inited
  276. * returns -2 if layout not done
  277. * returns -3 if edgenumber is < 1
  278. * returns -4 if edge not found
  279. */
  280. extern int sfg_edgefrom(int num);
  281. /* get to-node of edge
  282. * returns to-node number if oke
  283. * returns -1 not inited
  284. * returns -2 if layout not done
  285. * returns -3 if edgenumber is < 1
  286. * returns -4 if edge not found
  287. */
  288. extern int sfg_edgeto(int num);
  289. /* get edge type
  290. * returns type if oke, 1=regular, 2=selfedge, 3=hor. edge
  291. * returns -1 not inited
  292. * returns -2 if layout not done
  293. * returns -3 if edgenumber is < 1
  294. * returns -4 if edge not found
  295. */
  296. extern int sfg_edgetype(int num);
  297. /* get edge reversed status
  298. * returns 1 if reversed edge or 0 if not
  299. * returns -1 not inited
  300. * returns -2 if layout not done
  301. * returns -3 if edgenumber is < 1
  302. * returns -4 if edge not found
  303. */
  304. extern int sfg_edgerev(int num);
  305. /* get max x pos in drawing
  306. * returns value if oke
  307. * returns -1 if not inited
  308. * returns -2 if layout not done
  309. */
  310. extern int sfg_maxx(void);
  311. /* get max y pos in drawing
  312. * returns value if oke
  313. * returns -1 if not inited
  314. * returns -2 if layout not done
  315. */
  316. extern int sfg_maxy(void);
  317. /* get number of levels
  318. * returns value if oke
  319. * returns -1 if not inited
  320. * returns -2 if layout not done
  321. */
  322. extern int sfg_nlevels(void);
  323. /* get number of nodes
  324. * returns value if oke
  325. * returns -1 if not inited
  326. * returns -2 if layout not done
  327. */
  328. extern int sfg_nnodes(void);
  329. /* get number of edges
  330. * returns value if oke
  331. * returns -1 if not inited
  332. * returns -2 if layout not done
  333. */
  334. extern int sfg_nedges(void);
  335. /* get node data and the calculated positions
  336. * the user must supply a pointer to the callback routine
  337. * this runs a supplied callback routine for every node
  338. * the callback routine gets the node number as supplied,
  339. * the level as supplied and the calculated pos position.
  340. * the data is the supplied data and can be used similar.
  341. * when the callback function needs to stop the iteration
  342. * over the node list then it must return a non-zero status
  343. * and that status is returned by sfg_node_foreach()
  344. * the parameters in the callback function are
  345. * int num, uniq node number
  346. * int level, relative vertical level
  347. * int pos, relative horizontal level
  348. * void *data, optional user data
  349. * int xpos, x-coord of upperleft node label area or 0 at no label
  350. * int ypos, y-coord of upperleft node label area or 0 at no label
  351. * int tx, x size of text area
  352. * int ty, y size of text area
  353. * int nselfedges, number of self-edges at this node
  354. * int type, type of node, 1=regular, 2=dummy, 3=edgelabel node
  355. * int indegree, number of incoming edges to the node
  356. * int outdegree, number of outgoing edges from the node
  357. * int ly0, start y of level of node
  358. * int ly1, end y of level of node
  359. * returns 0 from this routine if everything is oke or no data.
  360. * returns -1 if not inited
  361. * returns -2 if no layout is done
  362. * returns -3 if no callback routine
  363. */
  364. extern int sfg_node_foreach(int (*getnodedata)
  365. (int num, int level, int pos, int xpos, int ypos, int tx, int ty, int nselfedges, int type,
  366. int indegree, int outdegree, int ly0, int ly1));
  367. /* get edge data and the calculated position
  368. * the user must supply a pointer to the callback routine
  369. * this runs a supplied callback routine for every edge
  370. * when the callback function needs to stop the iteration
  371. * over the edge list then it must return a non-zero status
  372. * the parameters in the callback function are
  373. * int num, uniq edge number
  374. * int from, uniq from-node number
  375. * int to, uniq to-node number
  376. * void *data, optional user data
  377. * int type, 1=regular, 2=selfedge, 3=horizontal-edge
  378. * int rev, set if edge is reversed
  379. * returns 0 if oke
  380. * returns -1 if not inited
  381. * returns -2 if no layout is done
  382. * returns -3 if no callback routine
  383. */
  384. extern int sfg_edge_foreach(int (*getedgedata)(int num, int from, int to, int type, int rev));
  385. #endif
  386. /* end */