Style file for drawing timing diagrams in LaTeX, forked from https://github.com/glipari/rtsched
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

rtsched.sty 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. \NeedsTeXFormat{LaTeX2e}[1995/12/01]
  2. \ProvidesPackage{rtsched}[2005/01/01]
  3. \typeout{'rtsched' style for Latex and PSTricks}
  4. \typeout{Easily draw real-time schedules in TeX/Latex.}
  5. \typeout{(c) 2005, Giuseppe Lipari, Pisa, Italy (g.lipari@sssup.it)}
  6. \typeout{Version 1.0}
  7. \RequirePackage{multido}
  8. \RequirePackage{pstricks}
  9. \RequirePackage{keyval}
  10. %%
  11. %% These can be changed at any time
  12. %%
  13. \def\RTWindowLength{10cm} % window length
  14. \def\RTWindowHeight{0cm} % window height
  15. \def\RTNullWindowHeight{0cm} % nullwindow height
  16. \def\RTTaskLabelSize{10pt} % Size in pt of the task label
  17. \def\RTNumberLabelSize{10pt} % Size in pt of the number labels
  18. \def\RTDefTaskSymbol{\tau}
  19. \def\RTDefNumberOffset{0}
  20. \def\RTDefTaskFill{solid}
  21. \def\RTDefTaskColor{gray}
  22. \def\RTDefLineColor{black}
  23. \def\RTDefXScale{1}
  24. \def\RTDefWriteSymbols{0}
  25. \def\RTDefGridInvisible{0}
  26. \def\RTDefNumbersInvisible{0}
  27. \def\RTDefRowLabelOffset{0pt}
  28. \def\RTExecLabel{\ }
  29. \def\RTTaskSymbol{\RTDefTaskSymbol}
  30. \def\RTTaskFill{\RTDefTaskFill}
  31. \def\RTTaskColor{\RTDefTaskColor}
  32. \def\RTLineColor{\RTDefLineColor}
  33. \def\RTXScale{\RTDefXScale}
  34. \def\RTWriteSymbols{\RTDefWriteSymbols}
  35. \def\RTNumberOffset{\RTDefNumberOffset}
  36. \def\RTNumberOffset{\RTDefNumberOffset}
  37. \def\RTGridInvisible{\RTDefGridInvisible}
  38. \def\RTNumbersInvisible{\RTDefGridInvisible}
  39. \def\RTRowLabelOffset{\RTDefRowLabelOffset}
  40. \define@key{RT}{height}[\RTNullWindowHeight]{\def\RTWindowHeight{#1}}
  41. \define@key{RT}{width}[10cm]{\def\RTWindowLength{#1}}
  42. \define@key{RT}{labelsize}[10pt]{\def\RTTaskLabelSize{#1}}
  43. \define@key{RT}{numbersize}[10pt]{\def\RTNumberLabelSize{#1}}
  44. \define@key{RT}{color}[\RTDefTaskColor]{\def\RTTaskColor{#1}}
  45. \define@key{RT}{linecolor}[\RTDefLineColor]{\def\RTLineColor{#1}}
  46. \define@key{RT}{execlabel}[\ ]{\def\RTExecLabel{#1}}
  47. \define@key{RT}{fillstyle}[\RTDefTaskFill]{\def\RTTaskFill{#1}}
  48. \define@key{RT}{nocommand}{}
  49. \define@key{RT}{xscale}[\RTDefXScale]{\def\RTXScale{#1}}
  50. \define@key{RT}{symbol}[{\tau}]{\def\RTTaskSymbol{#1}}
  51. \define@key{RT}{nosymbols}[\RTDefWriteSymbols]{\def\RTWriteSymbols{#1}}
  52. \define@key{RT}{numoffset}[\RTDefNumberOffset]{\def\RTNumberOffset{#1}}
  53. \define@key{RT}{nogrid}[\RTDefGridInvisible]{\def\RTGridInvisible{#1}}
  54. \define@key{RT}{nonumbers}[\RTDefNumbersInvisible]{\def\RTNumbersInvisible{#1}}
  55. \define@key{RT}{labeloffset}[\RTDefRowLabelOffset]{\def\RTRowLabelOffset{#1}}
  56. %%
  57. %% temporaries
  58. \newdimen\sx % slot length
  59. \newdimen\sy % slot height
  60. \newdimen\hy % frame height
  61. \newdimen\xx % x position
  62. \newdimen\yy % y position
  63. \newdimen\xxx % x position
  64. \newdimen\yyy % y position
  65. \newcount\nsx % number of horizontal slots
  66. \newcount\nsy % number of vertical slots
  67. \newcount\nhl % number of horizonatal lines
  68. \newcount\nvl % number of vertical lines
  69. \newcount\tmp % temp
  70. \newcounter{myLabel}
  71. \def\RTGrid{\@ifnextchar[\@mygrid@begin{\@mygrid@begin[]}}
  72. \def\RTGridBegin{\@ifnextchar[\@mygrid@begin{\@mygrid@begin[]}}
  73. \def\@mygrid@begin[#1]#2#3{\setkeys{RT}{#1}%
  74. %% number of horizontal steps in the grid
  75. \nsx = #3 \advance \nsx by 2 %
  76. %% real lenght of the window (approx)
  77. \nvl = \nsx \advance \nvl by 1 %
  78. %% compute lenght of a step
  79. \sx = \RTWindowLength \divide \sx by \nsx %
  80. %% number of vertical steps in the grid
  81. \nsy = #2 \multiply \nsy by 3 \advance \nsy by 1 %
  82. %% compute lenght of a vertical step (if height is null, \sy is the
  83. %% same as \sx)
  84. \ifx\RTWindowHeight\RTNullWindowHeight%
  85. \sy = \sx%
  86. \hy = \sy \multiply \hy by \nsy \advance \hy by \sy%
  87. \else
  88. \sy = \RTWindowHeight \divide \sy by \nsy %
  89. \hy = \RTWindowHeight \advance \hy by \sy %
  90. \fi
  91. %% compute real height
  92. \nhl = \nsy \advance \nhl by 1 %
  93. \advance \nsy by -1 \advance \nsx by -1
  94. %% the picture
  95. \begin{pspicture}(0,0)(\RTWindowLength,\hy) %
  96. %% draw grid (if not invisible)
  97. \if\RTGridInvisible\RTDefGridInvisible
  98. \multips(0,\sy)(0,\sy){\nsy}{\psline[linecolor=lightgray]{-}(0,\sy)(\RTWindowLength,\sy)}%
  99. \multips(\sx,0)(\sx,0){\nsx}{\psline[linecolor=lightgray]{-}(0,\sy)(0,\hy)}%
  100. \psframe(0,\sy)(\RTWindowLength,\hy)%
  101. \else\relax
  102. \fi
  103. %% draw numbers (if not invisible)
  104. \if\RTNumbersInvisible\RTDefNumbersInvisible
  105. \tmp = #3 \divide \tmp by 2 \advance \tmp by 1%
  106. \pssetlength{\xx}{\sx}%
  107. \setcounter{myLabel}{\RTNumberOffset}
  108. \multido{\n=0+1}{\tmp}{%
  109. \uput{4pt}[d](\xx,\sy){%
  110. \usefont{T1}{phv}{m}{n}%
  111. \fontsize{\RTNumberLabelSize}{\RTNumberLabelSize}%
  112. \selectfont{\arabic{myLabel}}}%
  113. \psaddtolength{\xx}{\sx}%
  114. \psaddtolength{\xx}{\sx}%
  115. \addtocounter{myLabel}{2}
  116. }
  117. \else\relax
  118. \fi
  119. %
  120. %% Task Names
  121. \setcounter{myLabel}{1}
  122. \pssetlength{\yy}{\hy}%
  123. \psaddtolength{\yy}{-\sy}
  124. \multido{\n=0+1}{#2}{%
  125. \uput{4pt}[d](-\sx,\yy){
  126. \usefont{T1}{phv}{m}{n}
  127. \fontsize{\RTTaskLabelSize}{\RTTaskLabelSize}
  128. \if\RTWriteSymbols\RTDefWriteSymbols\selectfont{$\RTTaskSymbol_{\arabic{myLabel}}$}
  129. \else\relax
  130. \fi
  131. }%
  132. \psaddtolength{\yy}{-3\sy}%
  133. \addtocounter{myLabel}{1}
  134. }%
  135. %% Horizontal axes
  136. \xx = \sx \xxx = \RTWindowLength \advance \xxx by -\sx
  137. \yy = 2\sy
  138. \multido{\n=0+1}{#2}{
  139. \psline{->}(\xx,\yy)(\xxx,\yy)
  140. \advance \yy by 3\sy
  141. }
  142. }
  143. \def\@RTDefaultValues{%
  144. \setkeys{RT}{height}%
  145. \setkeys{RT}{width}%
  146. \setkeys{RT}{labelsize}%
  147. \setkeys{RT}{numbersize}%
  148. \setkeys{RT}{symbol}%
  149. \setkeys{RT}{fillstyle}%
  150. \setkeys{RT}{color}
  151. \setkeys{RT}{linecolor}%
  152. \setkeys{RT}{xscale}%
  153. \setkeys{RT}{nosymbols}%
  154. }
  155. \def\@RTExecDefaultValues{
  156. \setkeys{RT}{color}%
  157. \setkeys{RT}{execlabel}%
  158. \setkeys{RT}{linecolor}%
  159. }
  160. \def\RTGridEnd{
  161. \end{pspicture}%
  162. \@RTDefaultValues%
  163. }
  164. \def\endRTGrid{
  165. \end{pspicture}%
  166. \@RTDefaultValues%
  167. }
  168. \newcommand{\RTSet}[1]{
  169. \setkeys{RT}{#1}
  170. }
  171. \newcommand{\RTSetDefault}{
  172. \@RTDefaultValues
  173. }
  174. %% internal
  175. \newcommand{\@compute@xx}[1]{
  176. \xx = #1\sx
  177. \divide \xx by \RTXScale
  178. \advance \xx by \sx
  179. }
  180. \newcommand{\@compute@xxx}[1]{
  181. \xxx = #1\sx
  182. \divide \xxx by \RTXScale
  183. \advance \xxx by \sx
  184. }
  185. \newcommand{\@compute@yy}[1]{
  186. \yy = -3\sy \multiply \yy by #1
  187. \advance \yy by \hy
  188. }
  189. %% Task Arrival: draws an up arrow at the specified slot
  190. %% #1 : task number from 1 to n
  191. %% #2 : slot number from 0 to l-1
  192. \newcommand{\TaskArrival}[3][nocommand=1]{%
  193. \setkeys{RT}{#1}%
  194. \@compute@yy{#2}
  195. \@compute@xx{#3}
  196. \yyy = \yy \advance \yyy by 2\sy%
  197. \psline[linecolor=\RTLineColor]{->}(\xx,\yy)(\xx,\yyy)%
  198. \@RTExecDefaultValues%
  199. }
  200. %% Task Arrival and deadline: draws an up arrow and a down arrow at the specified slots
  201. %% #1 : task number from 1 to n
  202. %% #2 : slot number from 0 to l-1
  203. %% #3 : relative deadline
  204. \newcommand{\TaskArrDead}[4][nocommand=1]{
  205. \setkeys{RT}{#1}%
  206. \@compute@yy{#2}
  207. \@compute@xx{#3}
  208. \yyy = \yy \advance \yyy by 2\sy
  209. \psline[linecolor=\RTLineColor]{->}(\xx,\yy)(\xx,\yyy)
  210. \advance \xx by #4\sx
  211. \psline[linecolor=\RTLineColor]{->}(\xx,\yyy)(\xx,\yy)
  212. \@RTExecDefaultValues
  213. }
  214. %% Task Deadline: draws a down arrow at the specified slot
  215. %% #1 : task number from 1 to n
  216. %% #2 : slot number from 0 to l-1
  217. \newcommand{\TaskDeadline}[3][nocommand=1]{
  218. \setkeys{RT}{#1}%
  219. \@compute@yy{#2}
  220. \@compute@xx{#3}
  221. \yyy = \yy \advance \yyy by 2\sy
  222. \psline[linecolor=\RTLineColor]{<-}(\xx,\yy)(\xx,\yyy)
  223. \@RTExecDefaultValues
  224. }
  225. \newcommand{\TaskExecution}[4][nocommand=1]{
  226. \setkeys{RT}{#1}%
  227. \@compute@yy{#2}
  228. \@compute@xx{#3}
  229. \yyy = \yy \advance \yyy by \sy
  230. \@compute@xxx{#4}
  231. \psframe[fillstyle=\RTTaskFill,fillcolor=\RTTaskColor,linecolor=\RTLineColor](\xx,\yy)(\xxx,\yyy)
  232. \advance \xx by \xxx \xx = .5\xx
  233. \uput{2pt}[u](\xx,\yy){%
  234. \usefont{T1}{phv}{m}{n}%
  235. \fontsize{\RTNumberLabelSize}{\RTNumberLabelSize}%
  236. \selectfont{\RTExecLabel}%
  237. }
  238. \@RTExecDefaultValues
  239. }
  240. % Task Lock
  241. % par 1: task
  242. % par 2: time
  243. % par 3: resource
  244. %
  245. \newcommand{\TaskLock}[4][nocommand=1]{
  246. \setkeys{RT}{#1}%
  247. \@compute@yy{#2}
  248. \@compute@xx{#3}
  249. \yyy = \yy \advance \yyy by \sy
  250. \uput{2pt}[u](\xx,\yyy){%
  251. \usefont{T1}{phv}{m}{n}%
  252. \fontsize{\RTNumberLabelSize}{\RTNumberLabelSize}%
  253. \selectfont{L(#4)}%
  254. }
  255. \@RTExecDefaultValues
  256. }
  257. % \TaskUnlock
  258. % par 1: task
  259. % par 2: time
  260. % par 3: resource
  261. %
  262. \newcommand{\TaskUnlock}[4][nocommand=1]{
  263. \setkeys{RT}{#1}%
  264. \@compute@yy{#2}
  265. \@compute@xx{#3}
  266. \yyy = \yy \advance \yyy by \sy
  267. \uput{2pt}[u](\xx,\yyy){%
  268. \usefont{T1}{phv}{m}{n}%
  269. \fontsize{\RTNumberLabelSize}{\RTNumberLabelSize}%
  270. \selectfont{U(#4)}%
  271. }
  272. \@RTExecDefaultValues
  273. }
  274. %
  275. % par 1: number of vertical slot
  276. % par 2: time
  277. % par 3: label
  278. %
  279. \newcommand{\Label}[4][nocommand=1]{
  280. \setkeys{RT}{#1}%
  281. %\@compute@yy{#2}
  282. \@compute@xx{#3}
  283. \yy = -\sy \multiply \yy by #2
  284. \advance \yy by \hy
  285. \yyy = \yy \advance \yyy by \sy
  286. \uput{2pt}[u](\xx,\yyy){%
  287. \psshadowbox{
  288. \usefont{T1}{phv}{m}{n}%
  289. \fontsize{\RTNumberLabelSize}{\RTNumberLabelSize}%
  290. \selectfont{{#4}}}%
  291. }
  292. \@RTExecDefaultValues
  293. }
  294. %
  295. % par 1: higher priority task (from)
  296. % par 2: lower priority task (to)
  297. % par 3: time
  298. %
  299. \newcommand{\Inherit}[4][nocommand=1]{
  300. \setkeys{RT}{#1}%
  301. \@compute@yy{#2}
  302. \@compute@xx{#4}
  303. \yyy = -3\sy \multiply \yyy by #3 \advance \yyy by \sy
  304. \advance \yyy by \hy \advance \yyy by -\sy % \RTWindowHeight
  305. \psline[linestyle=dashed,linewidth=1.5pt]{->}(\xx,\yy)(\xx,\yyy)
  306. \@RTExecDefaultValues
  307. }
  308. %
  309. % par 1: activating task (from)
  310. % par 2: signal start time
  311. % par 3: activated task (to)
  312. % par 4: signal arrival time
  313. %
  314. \newcommand{\Activation}[5][nocommand=1]{
  315. \setkeys{RT}{#1}%
  316. \@compute@yy{#2}
  317. \@compute@xx{#3}
  318. \yyy = -3\sy \multiply \yyy by #4 %\advance \yyy by \sy
  319. \advance \yyy by \hy %\advance \yyy by -\sy %\RTWindowHeight
  320. \xxx = #5\sx \advance \xxx by \sx
  321. \psline[linestyle=dashed,linewidth=1pt]{->}(\xx,\yy)(\xxx,\yyy)
  322. }
  323. %
  324. % par 1: time1
  325. % par 2: time2
  326. %
  327. \newcommand{\RTBox}[3][nocommand=1]{
  328. \setkeys{RT}{#1}%
  329. \yy = 0cm
  330. \advance \yy by \hy
  331. \yyy = \sy
  332. \@compute@xx{#2}
  333. \@compute@xxx{#3}
  334. \psframe[fillstyle=crosshatch,hatchwidth=.2pt,hatchsep=2pt,hatchcolor=lightgray,linewidth=0pt,framearc=.2](\xx,\yy)(\xxx,\yyy)
  335. \@RTExecDefaultValues
  336. }
  337. % %
  338. % % par 1: task
  339. % % par 2: first instant (arrival)
  340. % % par 3: second instant (deadline)
  341. % %
  342. % \newcommand{\Interval}[4][nocommand=1]{
  343. % \setkeys{RT}{#1}%
  344. % \@compute@yy{#2}
  345. % \advance \yy by 2.5\sy
  346. % \@compute@xx{#3}
  347. % \@compute@xxx{#4}
  348. % % da cambiare con psarc
  349. % \pscurve*[linecolor=\RTLineColor]{-}(\xx,\yy)(\xxx,\yy)
  350. % \@RTExecDefaultValues
  351. % }
  352. \newcommand{\RowLabel}[3][nocommand=1]{
  353. \setkeys{RT}{#1}%
  354. \@compute@yy{#2}
  355. \advance \yy by 1.5\sy
  356. \xx = \RTRowLabelOffset %\advance \xx by \sx
  357. \uput{4pt}[dl](-\xx,\yy){
  358. \usefont{T1}{phv}{m}{n}
  359. \fontsize{\RTTaskLabelSize}{\RTTaskLabelSize}
  360. \selectfont{#3}
  361. }%
  362. }
  363. \newcommand{\TaskExecDelta}[4][nocommand=1]{
  364. \setkeys{RT}{#1}%
  365. \@compute@yy{#2}
  366. \@compute@xx{#3}
  367. \yyy = \yy \advance \yyy by \sy
  368. %\@compute@xxx{#4}
  369. \xxx = \xx \advance \xxx by #4\sx
  370. \psframe[fillstyle=\RTTaskFill,fillcolor=\RTTaskColor,linecolor=\RTLineColor](\xx,\yy)(\xxx,\yyy)
  371. \advance \xx by \xxx \xx = .5\xx
  372. \uput{2pt}[u](\xx,\yy){%
  373. \usefont{T1}{phv}{m}{n}%
  374. \fontsize{\RTNumberLabelSize}{\RTNumberLabelSize}%
  375. \selectfont{\RTExecLabel}%
  376. }
  377. \@RTExecDefaultValues
  378. }
  379. \newcommand{\TaskRespTime}[4][nocommand=1]{
  380. \setkeys{RT}{#1}
  381. \@compute@yy{#2}
  382. \@compute@xx{#3}
  383. \yyy = \yy \advance \yyy by \sy
  384. \xxx = \xx \advance \xxx by #4\sx
  385. \psframe[fillstyle=crosshatch*,hatchcolor=white,
  386. hatchwidth=.4pt,hatchsep=1pt,
  387. linestyle=none,fillcolor=\RTTaskColor](\xx,\yy)(\xxx,\yyy)
  388. \@RTExecDefaultValues
  389. }
  390. \@ifclassloaded{beamer}{
  391. \renewcommand<>{\TaskArrival}[3][nocommand=1]{
  392. \only#4{\beameroriginal{\TaskArrival}[#1]{#2}{#3}}
  393. }
  394. \renewcommand<>{\TaskArrDead}[4][nocommand=1]{
  395. \only#5{\beameroriginal{\TaskArrDead}[#1]{#2}{#3}{#4}}
  396. }
  397. \renewcommand<>{\TaskDeadline}[3][nocommand=1]{
  398. \only#4{\beameroriginal{\TaskDeadline}[#1]{#2}{#3}}
  399. }
  400. \renewcommand<>{\TaskExecution}[4][nocommand=1]{
  401. \only#5{\beameroriginal{\TaskExecution}[#1]{#2}{#3}{#4}}
  402. }
  403. \renewcommand<>{\TaskExecDelta}[4][nocommand=1]{
  404. \only#5{\beameroriginal{\TaskExecDelta}[#1]{#2}{#3}{#4}}
  405. }
  406. \renewcommand<>{\TaskRespTime}[4][nocommand=1]{
  407. \only#5{\beameroriginal{\TaskRespTime}[#1]{#2}{#3}{#4}}
  408. }
  409. \renewcommand<>{\TaskLock}[4][nocommand=1]{
  410. \only#5{\beameroriginal{\TaskLock}[#1]{#2}{#3}{#4}}
  411. }
  412. \renewcommand<>{\TaskUnlock}[4][nocommand=1]{
  413. \only#5{\beameroriginal{\TaskUnlock}[#1]{#2}{#3}{#4}}
  414. }
  415. \renewcommand<>{\Label}[4][nocommand=1]{
  416. \only#5{\beameroriginal{\Label}[#1]{#2}{#3}{#4}}
  417. }
  418. \renewcommand<>{\Inherit}[4][nocommand=1]{
  419. \only#5{\beameroriginal{\Inherit}[#1]{#2}{#3}{#4}}
  420. }
  421. \renewcommand<>{\Activation}[5][nocommand=1]{
  422. \only#6{\beameroriginal{\Activation}[#1]{#2}{#3}{#4}{#5}}
  423. }
  424. \renewcommand<>{\RTBox}[3][nocommand=1]{
  425. \only#4{\beameroriginal{\RTBox}[#1]{#2}{#3}}
  426. }
  427. }
  428. {
  429. \typeout{beamer not loaded}
  430. }
  431. \endinput