rtwhilite.js 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091
  1. // Copyright 2006-2019 The MathWorks, Inc.
  2. // Class RTW_Hash ------------------------------------------------------------
  3. // Internal web browser doesn't change window.location.hash if the link points
  4. // to the same page.
  5. // RTW_Hash remembers the hash value when the page is loaded in the first time
  6. // or a link is clicked.
  7. // removeHiliteByHash cleans the high lighted elements according to the stored
  8. // hash value
  9. function RTW_Hash(aHash) {
  10. if (aHash == null) {
  11. this.fHash = "";
  12. } else {
  13. this.fHash = aHash;
  14. };
  15. this.getHash = function() {
  16. return this.fHash;
  17. }
  18. this.setHash = function(aHash) {
  19. this.fHash = aHash;
  20. }
  21. }
  22. RTW_Hash.instance = null;
  23. // Class RTW_TraceInfo --------------------------------------------------------
  24. function RTW_TraceInfo(aFileLinks) {
  25. this.fFileLinks = aFileLinks;
  26. this.fLines = new Array();
  27. this.fTotalLines = 0; // total number of highlighted lines
  28. this.fNumLines = new Array();
  29. this.fFileIdxCache = new Array();
  30. this.fDisablePanel = false;
  31. this.fCurrFileIdx = -1;
  32. this.fCurrLineIdx = -1;
  33. this.fCurrCodeNode = null;
  34. this.getHtmlFileName = function(aIndex) {
  35. if (aIndex < this.fFileLinks.length) {
  36. var href = this.fFileLinks[aIndex].href;
  37. return href.substring(href.lastIndexOf('/')+1);
  38. }
  39. }
  40. this.getSrcFileName = function(aIndex) {
  41. var name = this.getHtmlFileName(aIndex);
  42. if (name)
  43. name = RTW_TraceInfo.toSrcFileName(name);
  44. return name;
  45. }
  46. this.getNumFileLinks = function() {
  47. return this.fFileLinks.length;
  48. }
  49. this.setFileLinkColor = function(aIndex, aColor) {
  50. var link = this.fFileLinks[aIndex];
  51. if (link && link.parentNode && link.parentNode.style)
  52. link.parentNode.style.backgroundColor = aColor;
  53. }
  54. this.highlightFileLink = function(aIndex, aColor) {
  55. for (var i = 0; i < this.fFileLinks.length; ++i) {
  56. this.setFileLinkColor(i, i == aIndex ? aColor : "");
  57. }
  58. }
  59. this.highlightCurrFileLink = function(aColor) {
  60. this.highlightFileLink(this.fCurrFileIdx);
  61. }
  62. this.highlightLines = function(aCodeNode,aColor) {
  63. this.fCurrCodeNode = aCodeNode;
  64. var lines = this.fLines[this.getHtmlFileName(this.fCurrFileIdx)];
  65. if (lines && aCodeNode) {
  66. for (var i = 0; i < lines.length; ++i) {
  67. var lineObj = aCodeNode.childNodes[lines[i]-1];
  68. if (lineObj)
  69. lineObj.style.backgroundColor=aColor;
  70. }
  71. }
  72. }
  73. this.getFileIdx = function(aFile) {
  74. if (this.fFileIdxCache[aFile] != null)
  75. return this.fFileIdxCache[aFile];
  76. for (var i = 0; i < this.fFileLinks.length; ++i) {
  77. if (this.getHtmlFileName(i) == aFile) {
  78. this.fFileIdxCache[aFile] = i;
  79. return i;
  80. }
  81. }
  82. return null;
  83. }
  84. this.getCurrFileIdx = function() { return this.fCurrFileIdx; }
  85. this.setNumHighlightedLines = function(aFileIdx, aNumLines) {
  86. this.fNumLines[aFileIdx] = aNumLines;
  87. updateNumHighlightedLines(this.fFileLinks[aFileIdx], aNumLines);
  88. }
  89. this.getNumLines = function(aFileIdx) {
  90. return this.fNumLines[aFileIdx] != null ? this.fNumLines[aFileIdx] : 0;
  91. }
  92. this.getNumLinesAll = function() {
  93. var sum = 0;
  94. var len = this.fNumLines.length;
  95. for (var i = 0; i < len; ++i) {
  96. sum += this.getNumLines(i);
  97. }
  98. return sum;
  99. }
  100. this.getPrevButton = function() {
  101. var aFrame = getNavFrame();
  102. if (typeof aFrame !== "undefined" && aFrame !== null)
  103. return aFrame.document.getElementById("rtwIdButtonPrev");
  104. else
  105. return document.getElementById("rtwIdButtonPrev");
  106. }
  107. this.getNextButton = function() {
  108. var aFrame = getNavFrame();
  109. if (typeof aFrame !== "undefined" && aFrame !== null)
  110. return aFrame.document.getElementById("rtwIdButtonNext");
  111. else
  112. return document.getElementById("rtwIdButtonNext");
  113. }
  114. this.getPanel = function() {
  115. var aFrame = getNavFrame();
  116. if (typeof aFrame !== "undefined" && aFrame !== null)
  117. return aFrame.document.getElementById("rtwIdTracePanel");
  118. else
  119. return document.getElementById("rtwIdTracePanel");
  120. }
  121. this.removeHighlighting = function() {
  122. for (var i = 0; i < this.fFileLinks.length; ++i) {
  123. this.setFileLinkColor(i, "");
  124. this.setNumHighlightedLines(i, 0);
  125. }
  126. // remove highlight and reset current code node
  127. try {
  128. if (this.fCurrCodeNode != null)
  129. this.highlightLines(getCodeNode(),"");
  130. } catch (e) {};
  131. this.fCurrCodeNode = null;
  132. if (this.getPrevButton()) { this.getPrevButton().disabled = true; }
  133. if (this.getNextButton()) { this.getNextButton().disabled = true; }
  134. if (this.getPanel()) { this.getPanel().style.display = "none"; }
  135. this.fCurrFileIdx = -1;
  136. this.fCurrLineIdx = -1;
  137. }
  138. this.setCurrLineIdx = function(aLineIdx) {
  139. this.fCurrLineIdx = aLineIdx;
  140. }
  141. this.getCurrLineIdx = function() { return this.fCurrLineIdx; }
  142. this.setCurrent = function(aFileIdx, aLineIdx) {
  143. this.fCurrFileIdx = aFileIdx;
  144. var numLines = this.getNumLines(aFileIdx);
  145. if (!numLines || aLineIdx >= numLines)
  146. this.fCurrLineIdx = -1;
  147. else
  148. this.fCurrLineIdx = aLineIdx;
  149. var allNumLines = this.getNumLinesAll();
  150. if (this.getPrevButton()) {
  151. this.getPrevButton().disabled = (allNumLines <= 1 || !this.hasPrev());
  152. }
  153. if (this.getNextButton()) {
  154. this.getNextButton().disabled = (allNumLines <= 1 || !this.hasNext());
  155. }
  156. if (this.getPanel() && !this.fDisablePanel) {
  157. this.getPanel().style.display = 'block';
  158. }
  159. }
  160. this.setDisablePanel = function(aDisable) {
  161. this.fDisablePanel = aDisable;
  162. }
  163. this.getPrevFileIdx = function() {
  164. if (this.fCurrLineIdx > 0)
  165. return this.fCurrFileIdx;
  166. for (var i = this.fCurrFileIdx - 1; i >= 0; --i)
  167. if (this.fNumLines[i] > 0)
  168. return i;
  169. return null;
  170. }
  171. // update the navigation bar state
  172. this.updateNavState = function() {
  173. if (this.getPrevButton())
  174. this.getPrevButton().disabled = !this.hasPrev();
  175. if (this.getNextButton())
  176. this.getNextButton().disabled = !this.hasNext();
  177. setTraceNumber();
  178. }
  179. this.hasPrev = function() {
  180. return this.getPrevFileIdx() != null;
  181. }
  182. this.getFirstFileIdx = function() {
  183. for (var i = 0; i < this.getNumFileLinks(); ++i)
  184. if (this.fNumLines[i] > 0)
  185. return i;
  186. }
  187. this.getLastFileIdx = function() {
  188. for (var i = this.getNumFileLinks(); i >= 0; --i)
  189. if (this.fNumLines[i] > 0)
  190. return i;
  191. }
  192. this.goFirst = function() {
  193. this.fCurrFileIdx = this.getFirstFileIdx();
  194. this.fCurrLineIdx = 0;
  195. this.updateNavState();
  196. }
  197. this.goLast = function() {
  198. this.fCurrFileIdx = this.getLastFileIdx();;
  199. this.fCurrLineIdx = this.getNumLines(this.fCurrFileIdx) - 1;
  200. this.updateNavState();
  201. }
  202. this.goPrev = function() {
  203. var fileIdx = this.getPrevFileIdx();
  204. if (fileIdx == null)
  205. return;
  206. if (fileIdx == this.fCurrFileIdx)
  207. --this.fCurrLineIdx;
  208. else {
  209. this.fCurrFileIdx = fileIdx;
  210. this.fCurrLineIdx = this.getNumLines(fileIdx) - 1;
  211. }
  212. this.updateNavState();
  213. }
  214. this.getNextFileIdx = function() {
  215. if (this.fCurrLineIdx < this.getNumLines(this.fCurrFileIdx) - 1 && this.getNumLines(this.fCurrFileIdx) > 0)
  216. return this.fCurrFileIdx;
  217. for (var i = this.fCurrFileIdx + 1; i < this.getNumFileLinks(); ++i)
  218. if (this.fNumLines[i] > 0)
  219. return i;
  220. return null;
  221. }
  222. this.hasNext = function() {
  223. return this.getNextFileIdx() != null;
  224. }
  225. this.goNext = function() {
  226. var fileIdx = this.getNextFileIdx();
  227. if (fileIdx == null)
  228. return;
  229. if (fileIdx == this.fCurrFileIdx)
  230. ++this.fCurrLineIdx;
  231. else {
  232. this.fCurrFileIdx = fileIdx;
  233. this.fCurrLineIdx = 0;
  234. }
  235. this.updateNavState();
  236. }
  237. this.setTotalLines = function(num) {
  238. this.fTotalLines = num;
  239. }
  240. this.getTotalLines = function() { return this.fTotalLines;}
  241. this.setLines = function(aFile, aLines) {
  242. this.fLines[aFile] = aLines;
  243. var index = this.getFileIdx(aFile);
  244. if (index != null)
  245. this.setNumHighlightedLines(index,aLines.length);
  246. }
  247. this.getLines = function(aFile) {
  248. return this.fLines[aFile];
  249. }
  250. // get current on focus line number
  251. this.getCurrLine = function() {
  252. var file = this.getHtmlFileName(this.getCurrFileIdx());
  253. var lines = this.fLines[file];
  254. var line = null;
  255. if (lines) {
  256. var line = lines[this.fCurrLineIdx];
  257. }
  258. return line;
  259. }
  260. this.getHRef = function(aFileIdx, aLineIdx, offset) {
  261. var file = this.getHtmlFileName(aFileIdx);
  262. var lines = this.fLines[file];
  263. if (lines) {
  264. var line = lines[aLineIdx];
  265. line = offset_line(line, offset);
  266. file = file+"#"+line;
  267. }
  268. return file;
  269. }
  270. this.getCurrentHRef = function(offset) {
  271. return this.getHRef(this.fCurrFileIdx, this.fCurrLineIdx, offset);
  272. }
  273. this.setInitLocation = function(aFile, aLine) {
  274. var fileIdx = this.getFileIdx(aFile);
  275. var lineIdx = null;
  276. if (fileIdx != null && aLine) {
  277. var lines = this.getLines(aFile);
  278. for (var i = 0; i < lines.length; ++i) {
  279. if (lines[i] == aLine) {
  280. lineIdx = i;
  281. break;
  282. }
  283. }
  284. }
  285. if (fileIdx == null || lineIdx == null)
  286. this.setCurrent(-1,-1);
  287. else
  288. this.setCurrent(fileIdx,lineIdx);
  289. }
  290. }
  291. // Static methods in RTW_TraceInfo
  292. RTW_TraceInfo.getFileLinks = function(docObj) {
  293. var links;
  294. if (docObj && docObj.getElementsByName)
  295. links = docObj.getElementsByName("rtwIdGenFileLinks");
  296. return links ? links : new Array();
  297. }
  298. RTW_TraceInfo.toSrcFileName = function(aHtmlFileName) {
  299. aHtmlFileName = aHtmlFileName.replace(/_c.html$/,".c");
  300. aHtmlFileName = aHtmlFileName.replace(/_h.html$/,".h");
  301. aHtmlFileName = aHtmlFileName.replace(/_cpp.html$/,".cpp");
  302. aHtmlFileName = aHtmlFileName.replace(/_hpp.html$/,".hpp");
  303. aHtmlFileName = aHtmlFileName.replace(/_cc.html$/,".hpp");
  304. return aHtmlFileName;
  305. }
  306. RTW_TraceInfo.instance = null;
  307. // Class RTW_TraceArgs --------------------------------------------------------
  308. // file.c:10,20,30&file.h:10,20,30[&color=value] or
  309. // sid=model:1[&color=value]
  310. RTW_TraceArgs = function(aHash) {
  311. this.fColor = null;
  312. this.fFontSize = null;
  313. this.fInitFile = null;
  314. this.fInitLine = null;
  315. this.fSID = null;
  316. this.fFiles = new Array();
  317. this.fLines = new Array();
  318. this.fMessage = null;
  319. this.fBlock = null;
  320. this.fNumBlocks = 0;
  321. this.fUseExternalBrowser = true;
  322. this.fInStudio = false;
  323. this.fModel2CodeSrc = null;
  324. this.fInCodeTrace = false;
  325. this.fTraceData = null;
  326. this.fFileIdx = []; // filename to fileId
  327. this.fRows = []; // highlighted rows indexed by fileId
  328. this.fIDs = []; // highlighted IDs indexed by fileId
  329. this.hasSid = function() {
  330. return !(this.fSID == null);
  331. }
  332. this.parseCommand = function(aHash) {
  333. var args = new Array();
  334. args = aHash.split('&');
  335. for (var i = 0; i < args.length; ++i) {
  336. var arg = args[i];
  337. sep = arg.indexOf('=');
  338. if (sep != -1) {
  339. var cmd = arg.substring(0,sep);
  340. var opt = arg.substring(sep+1);
  341. switch (cmd.toLowerCase()) {
  342. case "color":
  343. this.fColor = opt;
  344. break;
  345. case "fontsize":
  346. this.fFontSize = opt;
  347. break;
  348. case "initfile":
  349. this.fInitFile = RTW_TraceArgs.toHtmlFileName(opt);
  350. break;
  351. case "initline":
  352. this.fInitLine = opt;
  353. break;
  354. case "msg":
  355. this.fMessage = opt;
  356. break;
  357. case "block":
  358. this.fBlock = unescape(opt);
  359. break;
  360. case "numblocks":
  361. this.fNumBlocks = parseInt(opt);
  362. break;
  363. case "sid":
  364. this.fSID = opt;
  365. // convert sid to code location
  366. break;
  367. case "model2code_src":
  368. // model2code_src from model or webview
  369. this.fModel2CodeSrc = opt;
  370. break;
  371. case "useexternalbrowser":
  372. this.fUseExternalBrowser = (opt=="true");
  373. break;
  374. case "instudio":
  375. this.fInStudio = (opt=="true");
  376. break;
  377. case "incodetrace":
  378. this.fInCodeTrace = (opt=="true");
  379. break;
  380. case "tracedata":
  381. this.fTraceData = decodeURI(opt);
  382. break;
  383. }
  384. }
  385. }
  386. }
  387. this.parseUrlHash = function(aHash) {
  388. var rows, sep, assignSep;
  389. if (aHash) {
  390. args = aHash.split('&');
  391. for (var i = 0; i < args.length; ++i) {
  392. var arg = args[i];
  393. sep = arg.indexOf(':');
  394. assignSep = arg.indexOf('=');
  395. if (sep !== -1 && assignSep === -1) {
  396. var fileLines = arg.split(':');
  397. var htmlFileName = RTW_TraceArgs.toHtmlFileName(fileLines[0]);
  398. this.fFileIdx[htmlFileName] = i;
  399. this.fFiles.push(htmlFileName);
  400. if (fileLines[1]) {
  401. rows = fileLines[1].split(',');
  402. rows = uniqueRows(rows);
  403. this.fLines.push(rows);
  404. this.fRows[i] = rows;
  405. }
  406. }
  407. }
  408. if (this.fInitFile == null && this.fFiles.length > 0) {
  409. this.fInitFile = this.fFiles[0];
  410. this.fInitLine = (this.fLines[0] == null ? -1 : this.fLines[0][0]);
  411. }
  412. }
  413. }
  414. this.parseUrlHash2 = function(aHash) {
  415. aHash = decodeURI(aHash);
  416. var rows;
  417. var ids;
  418. if (aHash && aHash.length > 0 && aHash[0] === "[") {
  419. var input = eval(aHash);
  420. var i;
  421. var j;
  422. // set highlight files from url
  423. for (i=0; i<input.length;i++) {
  424. rows = new Array();
  425. ids = new Array();
  426. this.fFileIdx[input[i].file] = i;
  427. this.fFiles.push(input[i].file);
  428. ids = input[i].id;
  429. for (j=0; j<ids.length;j++) {
  430. // get row number
  431. if (ids[j].indexOf("c") !== -1)
  432. rows.push(Number(ids[j].substring(0,ids[j].indexOf("c"))));
  433. else
  434. rows.push(Number(ids[j]));
  435. }
  436. rows = uniqueRows(rows);
  437. this.fRows[i] = rows;
  438. this.fIDs[i] = ids;
  439. }
  440. } else {
  441. // reset all states
  442. this.fFiles = [];
  443. this.fRows = [];
  444. this.fIDs = [];
  445. }
  446. return;
  447. }
  448. this.getFileIdx = function(aFileName) {
  449. if (aFileName) {
  450. return this.fFileIdx[aFileName];
  451. } else {
  452. // return the fileIdx of the current display file
  453. var pathname = top.rtwreport_document_frame.location.pathname;
  454. pathname = pathname.substr(pathname.lastIndexOf("/")+1);
  455. // find the highlight file name
  456. return this.getFileIdx(pathname);
  457. }
  458. }
  459. this.getColor = function() { return this.fColor; }
  460. this.getFontSize = function() { return this.fFontSize; }
  461. this.getInitFile = function() { return this.fInitFile; }
  462. this.getInitLine = function() { return this.fInitLine; }
  463. this.getNumFiles = function() { return this.fFiles.length; }
  464. this.getSID = function() { return this.fSID; }
  465. this.getFile = function(aIdx) { if (isNaN(aIdx)) return this.fFiles; return this.fFiles[aIdx];}
  466. this.getLines = function(aIdx) { return this.fLines[aIdx]; }
  467. this.getUseExternalBrowser = function() { return this.fUseExternalBrowser; }
  468. this.getInStudio = function() { return this.fInStudio; }
  469. this.getInCodeTrace = function() { return this.fInCodeTrace; }
  470. this.getTraceData = function() { return this.fTraceData; }
  471. this.getModel2CodeSrc = function() { return this.fModel2CodeSrc; }
  472. this.setUseExternalBrowser = function(val) { this.fUseExternalBrowser = val; }
  473. this.setInCodeTrace = function(val) { this.fInCodeTrace = val; }
  474. this.setTraceData = function(val) { this.fTraceData = val; }
  475. this.setModel2CodeSrc = function(val) { this.fModel2CodeSrc = val; }
  476. this.getRows = function(aIdx) { return this.fRows[aIdx];}
  477. this.getIDs = function(aIdx) { return this.fIDs[aIdx]; }
  478. this.getBlock = function() { return this.fBlock; }
  479. this.getNumBlocks = function() { return this.fNumBlocks; }
  480. // constructor
  481. this.parseCommand(aHash);
  482. }
  483. // Static methods in RTW_TraceArgs
  484. RTW_TraceArgs.toHtmlFileName = function(aFile) {
  485. f = aFile;
  486. aFile = f.substring(0,f.lastIndexOf('.')) + '_' + f.substring(f.lastIndexOf('.')+1) + ".html";
  487. return aFile;
  488. }
  489. RTW_TraceArgs.instance = null;
  490. RTW_MessageWindow = function(aWindow, aParagraph) {
  491. this.fWindow = aWindow;
  492. this.fParagraph = aParagraph;
  493. this.print = function(msg) {
  494. this.fParagraph.innerHTML = msg;
  495. if (msg)
  496. this.fWindow.style.display = "block";
  497. else
  498. this.fWindow.style.display = "none";
  499. }
  500. this.clear = function() {
  501. this.print("");
  502. }
  503. }
  504. // RTW_MessageWindow factory
  505. RTW_MessageWindowFactory = function(aDocObj) {
  506. this.fDocObj = aDocObj;
  507. this.fInstance = null;
  508. this.getInstance = function() {
  509. if (this.fInstance)
  510. return this.fInstance;
  511. if (!this.fDocObj)
  512. return;
  513. var table = this.fDocObj.getElementById("rtwIdMsgWindow");
  514. var paragraph = this.fDocObj.getElementById("rtwIdMsg");
  515. var button = this.fDocObj.getElementById("rtwIdButtonMsg");
  516. if (!table || !paragraph || !button)
  517. return null;
  518. obj = new RTW_MessageWindow(table,paragraph);
  519. button.onclick = function() { obj.clear(); }
  520. this.fInstance = obj;
  521. return this.fInstance;
  522. }
  523. }
  524. RTW_MessageWindowFactory.instance = null;
  525. RTW_MessageWindow.factory = function(aDocObj) {
  526. if (!RTW_MessageWindowFactory.instance)
  527. RTW_MessageWindowFactory.instance = new RTW_MessageWindowFactory(aDocObj);
  528. return RTW_MessageWindowFactory.instance.getInstance();
  529. }
  530. // Callbacks and helper functions ---------------------------------------------
  531. // Helper functions
  532. function getCodeNode() {
  533. return rtwSrcFrame().document.getElementById("RTWcode");
  534. }
  535. function rtwMidFrame() {
  536. return top.document.getElementById('rtw_midFrame');
  537. }
  538. function rtwSrcFrame() {
  539. return top.rtwreport_document_frame;
  540. }
  541. function rtwTocFrame() {
  542. return top.rtwreport_contents_frame;
  543. }
  544. function rtwNavToolbarFrame() {
  545. return top.rtwreport_navToolbar_frame; // return rtwTocFrame();
  546. }
  547. function rtwInspectFrame() {
  548. return top.rtwreport_inspect_frame; // return rtwTocFrame();
  549. }
  550. function rtwGetFileName(url) {
  551. var slashIdx = url.lastIndexOf('/');
  552. var hashIdx = url.indexOf('#', slashIdx);
  553. if (hashIdx == -1)
  554. return url.substring(slashIdx+1)
  555. else
  556. return url.substring(slashIdx+1,hashIdx);
  557. }
  558. // Help function to expand the file group
  559. function expandFileGroup(docObj, tagID) {
  560. if (docObj.getElementById) {
  561. var obj_table = docObj.getElementById(tagID);
  562. var o;
  563. while (obj_table.nodeName != "TABLE") {
  564. if (obj_table.parentNode) {
  565. obj_table = obj_table.parentNode;
  566. } else {
  567. return;
  568. }
  569. }
  570. if (obj_table.style.display == "none") {
  571. var category_table = obj_table.parentNode;
  572. while (category_table.nodeName != "TABLE") {
  573. if (category_table.parentNode) {
  574. category_table = category_table.parentNode;
  575. } else {
  576. return;
  577. }
  578. }
  579. var o = category_table.id + "_button";
  580. o = docObj.getElementById(o);
  581. if (o && top.rtwreport_contents_frame.rtwFileListShrink) {
  582. top.rtwreport_contents_frame.rtwFileListShrink(o, category_table.id,
  583. category_table.getAttribute('label'), 0);
  584. }
  585. }
  586. }
  587. }
  588. // Help function to set the background color based on Element's Id in a document
  589. // object
  590. function setBGColorByElementId(docObj, tagID, bgColor) {
  591. var status = false;
  592. if (bgColor == "") {
  593. bgColor = "TRANSPARENT";
  594. }
  595. if (docObj.getElementById) {
  596. var obj2Hilite = docObj.getElementById(tagID);
  597. if (obj2Hilite && obj2Hilite.parentNode) {
  598. obj2Hilite.parentNode.style.backgroundColor = bgColor;
  599. status = true;
  600. }
  601. }
  602. return status;
  603. }
  604. // Help function to set the background color based on Element's name in a document
  605. // object
  606. function setBGColorByElementsName(docObj, tagName, bgColor) {
  607. if (bgColor == "") {
  608. bgColor = "TRANSPARENT";
  609. }
  610. if (docObj.getElementsByName) {
  611. var objs2Hilite = docObj.getElementsByName(tagName);
  612. for (var objIndex = 0; objIndex < objs2Hilite.length; ++objIndex) {
  613. if (objs2Hilite[objIndex].parentNode)
  614. objs2Hilite[objIndex].parentNode.style.backgroundColor = bgColor;
  615. }
  616. }
  617. }
  618. // Help function to highlight lines in source file based on Element's name
  619. // Note: Name of docHiliteByElementsName would be better
  620. function hiliteByElementsName(winObj, tagName) {
  621. var hiliteColor = "#aaffff";
  622. if (winObj.document)
  623. setBGColorByElementsName(winObj.document, tagName, hiliteColor);
  624. }
  625. // Help function to remove the highlight of lines in source file based on Element's name
  626. function removeHiliteByElementsName(winObj, tagName) {
  627. if (winObj.document)
  628. setBGColorByElementsName(winObj.document, tagName, "");
  629. }
  630. // Help function to set the background color based on the URL's hash
  631. function setBGColorByHash(docObj, bgColor) {
  632. if (docObj.location) {
  633. var tagName = docObj.location.hash;
  634. // Use the stored hash value if it exists because the location.hash
  635. // may be wrong in internal web browser
  636. if (RTW_Hash.instance)
  637. tagName = RTW_Hash.instance.getHash();
  638. if (tagName != null)
  639. tagName = tagName.substring(1);
  640. var codeNode = docObj.getElementById("RTWcode");
  641. if (tagName != null && tagName != "") {
  642. if (!isNaN(tagName))
  643. tagName = Number(tagName) + 10;
  644. setBGColorByElementsName(docObj, tagName, bgColor);
  645. }
  646. }
  647. }
  648. // Highlight the lines in document frame based on the URL's hash
  649. function hiliteByHash(docObj) {
  650. var hiliteColor = "#aaffff";
  651. setBGColorByHash(docObj, hiliteColor);
  652. }
  653. // Remove highlight of lines in document frame based on the URL's hash
  654. function removeHiliteByHash(winObj) {
  655. if (winObj.document)
  656. setBGColorByHash(winObj.document, "");
  657. }
  658. // Highlight the filename Element in TOC frame based on the URL's filename
  659. function hiliteByFileName(aHref) {
  660. var status = false;
  661. if (!top.rtwreport_contents_frame)
  662. return status;
  663. var hiliteColor = GlobalConfig.fileLinkHiliteColor;
  664. var fileName = rtwGetFileName(aHref);
  665. if (top.rtwreport_contents_frame.document) {
  666. removeHiliteFileList(top.rtwreport_contents_frame);
  667. status = setBGColorByElementId(top.rtwreport_contents_frame.document, fileName, hiliteColor);
  668. if (status)
  669. expandFileGroup(top.rtwreport_contents_frame.document, fileName);
  670. }
  671. return status;
  672. }
  673. // Clear the highlights in the code navigation frame.
  674. function removeHiliteCodeNav(winObj) {
  675. removeHiliteTOC(winObj);
  676. removeHiliteFileList(winObj);
  677. }
  678. // Clear the highlights in TOC frame. TOC links are named TOC_List
  679. function removeHiliteTOC(winObj) {
  680. removeHiliteByElementsName(winObj, "TOC_List");
  681. }
  682. // Clear the highlights in Generated File List.
  683. // The filename links are named rtwIdGenFileLinks,
  684. function removeHiliteFileList(winObj) {
  685. removeHiliteByElementsName(winObj, "rtwIdGenFileLinks");
  686. }
  687. // Highlight TOC hyperlinks by their Ids.
  688. function tocHiliteById(id) {
  689. hiliteColor = GlobalConfig.fileLinkHiliteColor;
  690. if (top && top.rtwreport_contents_frame && top.rtwreport_contents_frame.document) {
  691. removeHiliteCodeNav(top.rtwreport_contents_frame);
  692. setBGColorByElementId(top.rtwreport_contents_frame.document, id, hiliteColor);
  693. }
  694. }
  695. // onClick function to highlight the link itself
  696. function tocHiliteMe(winObj, linkObj, bCleanTrace) {
  697. hiliteColor = GlobalConfig.fileLinkHiliteColor;
  698. // remove the trace info (previous highlighted source code and the navigate
  699. // panel)
  700. // Clean Trace info only when links in TOC clicked. Links of filenames won't
  701. // clean trace info.
  702. if (bCleanTrace) {
  703. if (RTW_TraceInfo.instance) {
  704. RTW_TraceInfo.instance.setDisablePanel(true);
  705. rtwRemoveHighlighting();
  706. }
  707. closeInspectWindow();
  708. }
  709. removeHiliteCodeNav(winObj);
  710. if (linkObj.parentNode) {
  711. linkObj.parentNode.style.backgroundColor= hiliteColor;
  712. }
  713. }
  714. // onClick function to clean the currently highlighed lines in document frame
  715. // based on URL's hash
  716. // Then highlight lines in document frame based on Element's name
  717. // It works for links to some elements in the same page, otherwise,
  718. // rtwFileOnLoad() in loading page does the job.
  719. function docHiliteMe(winObj, elementName) {
  720. // First, remove the highlighted elements by stored hash value
  721. removeHiliteByHash(winObj);
  722. // Store the new hash value defined by elementName
  723. if (RTW_Hash.instance) {
  724. RTW_Hash.instance.setHash("#"+elementName);
  725. } else {
  726. RTW_Hash.instance = new RTW_Hash("#"+elementName);
  727. }
  728. hiliteByElementsName(winObj, elementName);
  729. }
  730. // Callback for generated file load callback
  731. function rtwFileOnLoad(docObj) {
  732. if (!docObj.location || !docObj.location.href)
  733. return;
  734. // Save the hash value when file is loaded in the first time
  735. if (!RTW_Hash.instance) {
  736. RTW_Hash.instance = new RTW_Hash(docObj.location.hash);
  737. } else {
  738. RTW_Hash.instance.setHash(docObj.location.hash);
  739. }
  740. updateHyperlinks();
  741. // highlight lines in source code file according to the URL hash
  742. hiliteByHash(docObj);
  743. // highlight the filename in the TOC frame
  744. if (top.rtwreport_contents_frame) {
  745. if (hiliteByFileName(docObj.location.href)) {
  746. // remove the highlights in the TOC frame if filename is hilite successfully
  747. removeHiliteTOC(top.rtwreport_contents_frame);
  748. }
  749. }
  750. if (!RTW_TraceInfo.instance)
  751. return;
  752. if (!docObj.getElementById)
  753. return;
  754. if (rtwSrcFrame())
  755. rtwSrcFrame().focus();
  756. var fileName = rtwGetFileName(docObj.location.href);
  757. var fileIdx = RTW_TraceInfo.instance.getFileIdx(fileName);
  758. if (fileIdx != null) {
  759. if (fileIdx != RTW_TraceInfo.instance.getCurrFileIdx())
  760. RTW_TraceInfo.instance.setCurrent(fileIdx,-1);
  761. var codeNode = docObj.getElementById("RTWcode");
  762. var hiliteColor = RTW_TraceArgs.instance.getColor();
  763. if (!hiliteColor) {
  764. hiliteColor = "#aaffff";
  765. }
  766. var fontSize = RTW_TraceArgs.instance.getFontSize();
  767. if (fontSize) {
  768. codeNode.style.fontSize = fontSize;
  769. }
  770. RTW_TraceInfo.instance.highlightLines(codeNode,hiliteColor);
  771. RTW_TraceInfo.instance.highlightFileLink(fileIdx, GlobalConfig.fileLinkHiliteColor);
  772. }
  773. }
  774. function Nav(fileIdx1, fileIdx2) {
  775. var filename = top.rtwreport_document_frame.location.pathname.split(/\//);
  776. filename = filename[filename.length-1];
  777. var currentFileIdx = RTW_TraceInfo.instance.getFileIdx(filename);
  778. if (fileIdx1 === currentFileIdx) {
  779. top.rtwreport_document_frame.document.location.href = RTW_TraceInfo.instance.getCurrentHRef();
  780. top.initLine = top.rtwreport_document_frame.document.location.hash.substr(1);
  781. addTagToCurrentLine();
  782. if (top.rtwreport_contents_frame) {
  783. if (hiliteByFileName(top.rtwreport_document_frame.location.href))
  784. removeHiliteTOC(top.rtwreport_contents_frame);
  785. }
  786. } else {
  787. var aUrl = RTW_TraceInfo.instance.getCurrentHRef();
  788. if (hasWebviewFrame()) {
  789. top.rtwreport_document_frame.document.location.href=aUrl;
  790. } else {
  791. top.rtwreport_document_frame.document.location.href=aUrl + "+newPage";
  792. }
  793. }
  794. }
  795. // Callback for "Prev" button
  796. function rtwGoPrev() {
  797. if (RTW_TraceInfo.instance && top.rtwreport_document_frame) {
  798. var prevfileIdx = RTW_TraceInfo.instance.getPrevFileIdx();
  799. var currfileIdx = RTW_TraceInfo.instance.fCurrFileIdx;
  800. rmTagToCurrentLine();
  801. RTW_TraceInfo.instance.goPrev();
  802. Nav(prevfileIdx, currfileIdx);
  803. }
  804. }
  805. // Callback for "First" button
  806. function rtwGoFirst() {
  807. if (RTW_TraceInfo.instance && top.rtwreport_document_frame) {
  808. var prevfileIdx = RTW_TraceInfo.instance.getFirstFileIdx();
  809. var currfileIdx = RTW_TraceInfo.instance.fCurrFileIdx;
  810. rmTagToCurrentLine();
  811. RTW_TraceInfo.instance.goFirst();
  812. Nav(prevfileIdx, currfileIdx);
  813. }
  814. }
  815. // Callback for navigation button onclick
  816. var navButtonStatus = (function() {
  817. var isclicked = false;
  818. return {
  819. clicked: function () {
  820. isclicked = true;
  821. return false;
  822. },
  823. reset: function () {
  824. isclicked = false;
  825. },
  826. isClicked: function () {
  827. return isclicked;
  828. }
  829. };
  830. })();
  831. // Callback for "Next" button
  832. function rtwGoNext() {
  833. if (RTW_TraceInfo.instance && top.rtwreport_document_frame) {
  834. var nextfileIdx = RTW_TraceInfo.instance.getNextFileIdx();
  835. var currfileIdx = RTW_TraceInfo.instance.fCurrFileIdx;
  836. rmTagToCurrentLine();
  837. RTW_TraceInfo.instance.goNext();
  838. Nav(nextfileIdx, currfileIdx);
  839. }
  840. }
  841. // Callback for "Last" button
  842. function rtwGoLast() {
  843. if (RTW_TraceInfo.instance && top.rtwreport_document_frame) {
  844. var nextfileIdx = RTW_TraceInfo.instance.getLastFileIdx();
  845. var currfileIdx = RTW_TraceInfo.instance.fCurrFileIdx;
  846. rmTagToCurrentLine();
  847. RTW_TraceInfo.instance.goLast();
  848. Nav(nextfileIdx, currfileIdx);
  849. }
  850. }
  851. function addTagToCurrentLine() {
  852. rmHiliteClickedToken();
  853. tagCurrentLine(true);
  854. }
  855. function rmTagToCurrentLine() {
  856. tagCurrentLine(false);
  857. }
  858. // tag current line by changing the bacgkround color of the line
  859. function tagCurrentLine(addColor) {
  860. if (RTW_TraceInfo.instance) {
  861. var o = top.rtwreport_document_frame.document.getElementById(RTW_TraceInfo.instance.getCurrLine());
  862. if (o) {
  863. if (addColor) {
  864. o.className = "hiliteCurrentLine";
  865. } else {
  866. o.className = "hilite";
  867. }
  868. }
  869. }
  870. }
  871. // Helper function for main document load callback
  872. function rtwMainOnLoadFcn(topDocObj,aLoc,aPanel,forceReload) {
  873. var loc;
  874. var aHash="";
  875. var lastArgs = null;
  876. var tocDocObj = top.rtwreport_contents_frame.document;
  877. if (typeof forceReload === "undefined") {
  878. forceReload = false;
  879. }
  880. // get the hash value from location.
  881. if (!aLoc) {
  882. loc = topDocObj.location;
  883. if (loc.search || loc.hash) {
  884. if (loc.search)
  885. aHash = loc.search.substring(1);
  886. else
  887. aHash = loc.hash.substring(1);
  888. }
  889. } else {
  890. aHash = aLoc;
  891. if (RTW_TraceArgs.instance)
  892. lastArgs = RTW_TraceArgs.instance;
  893. }
  894. // parse URL hash value
  895. RTW_TraceArgs.instance = new RTW_TraceArgs(aHash);
  896. // load metrics
  897. load_metrics();
  898. // hide content panel if in studio
  899. if (RTW_TraceArgs.instance.getInStudio()) {
  900. setupInStudio();
  901. }
  902. // use incode traceability
  903. if (RTW_TraceArgs.instance.getInCodeTrace()) {
  904. RTW_TraceArgs.instance.parseUrlHash2(RTW_TraceArgs.instance.getTraceData());
  905. inCodeTraceOnload();
  906. return;
  907. }
  908. if (lastArgs !== null) {
  909. RTW_TraceArgs.instance.setUseExternalBrowser(lastArgs.getUseExternalBrowser());
  910. RTW_TraceArgs.instance.setModel2CodeSrc(lastArgs.getModel2CodeSrc());
  911. }
  912. // get highlight url using sid
  913. if (RTW_TraceArgs.instance.hasSid()) {
  914. aHash = getCodeLines();
  915. }
  916. // parse hash to look for msg=...&block=... pattern
  917. RTW_TraceArgs.instance.parseCommand(aHash);
  918. // parse hash to look for file.c:10,12&file.h:10,12
  919. RTW_TraceArgs.instance.parseUrlHash(aHash);
  920. // hide navigation buttons if not in MATLAB
  921. if (RTW_TraceArgs.instance.getUseExternalBrowser() && tocDocObj.getElementById) {
  922. var o = tocDocObj.getElementById("nav_buttons");
  923. if (o != null) {
  924. o.style.display = "none";
  925. }
  926. }
  927. // hide web view frameset if model2code_src is model
  928. if (RTW_TraceArgs.instance.getModel2CodeSrc() === "model") {
  929. var o = top.document.getElementById('rtw_webviewMidFrame');
  930. if (o) {
  931. o.rows = "100%,0%";
  932. }
  933. }
  934. // stop onload when it has been loaded
  935. if (window.location.search.indexOf("loaded=true") > 0
  936. && top.rtwreport_document_frame.location.href !== "about:blank" && forceReload !== true) {
  937. updateHyperlinks();
  938. return;
  939. }
  940. // modify modelref links
  941. update_modelref_report_link(top.rtwreport_contents_frame.document);
  942. try {
  943. // ignore browser security error
  944. update_modelref_report_link(top.rtwreport_document_frame.document);
  945. } catch(e) {};
  946. // redirect the page based on the url
  947. var initPage = null;
  948. if (RTW_TraceArgs.instance.getNumFiles()) {
  949. var fileLinks = RTW_TraceInfo.getFileLinks(tocDocObj);
  950. RTW_TraceInfo.instance = new RTW_TraceInfo(fileLinks);
  951. RTW_TraceInfo.instance.removeHighlighting()
  952. var numFiles = RTW_TraceArgs.instance.getNumFiles();
  953. var tLines = 0;
  954. for (var i = 0; i < numFiles; ++i) {
  955. RTW_TraceInfo.instance.setLines(RTW_TraceArgs.instance.getFile(i),RTW_TraceArgs.instance.getLines(i));
  956. tLines += RTW_TraceArgs.instance.getLines(i).length;
  957. }
  958. RTW_TraceInfo.instance.setTotalLines(tLines);
  959. if (aPanel == false) {
  960. RTW_TraceInfo.instance.setDisablePanel(true);
  961. }
  962. var initFile = RTW_TraceArgs.instance.getInitFile();
  963. RTW_TraceInfo.instance.setInitLocation(initFile,RTW_TraceArgs.instance.getInitLine());
  964. if (!hasInCodeTrace()) {
  965. initPage = RTW_TraceInfo.instance.getCurrentHRef();
  966. } else {
  967. initPage = initFile;
  968. }
  969. } else {
  970. // catch error that document frame is in another domain
  971. try {
  972. var fileDocObj = top.rtwreport_document_frame.document;
  973. if (fileDocObj.location && (!fileDocObj.location.href || fileDocObj.location.href == "about:blank")) {
  974. var summaryPage = tocDocObj.getElementById("rtwIdSummaryPage");
  975. var tracePage = tocDocObj.getElementById("rtwIdTraceability");
  976. if (summaryPage) {
  977. initPage = summaryPage.href;
  978. } else if (tracePage) {
  979. initPage = tracePage;
  980. }
  981. }
  982. } catch(e) {};
  983. }
  984. if (RTW_TraceArgs.instance && RTW_TraceArgs.instance.fMessage) {
  985. // display diagnostic message
  986. var linkId = "rtwIdMsgFileLink";
  987. var msgFile = tocDocObj.getElementById(linkId);
  988. if (msgFile && msgFile.style) {
  989. msgFile.style.display = "block";
  990. // Highlight the background of msg link
  991. tocHiliteById(linkId);
  992. }
  993. initPage = "rtwmsg.html";
  994. }
  995. if (initPage) {
  996. var is_same_page = false;
  997. try {
  998. var fileDocObj = top.rtwreport_document_frame.document;
  999. is_same_page = isSamePage(fileDocObj.location.href, initPage);
  1000. } catch(e) {};
  1001. if (document.getElementById("rtwreport_document_frame")) {
  1002. document.getElementById("rtwreport_document_frame").setAttribute("src", initPage);
  1003. } else {
  1004. top.rtwreport_document_frame.location.href = initPage;
  1005. }
  1006. if (is_same_page) {
  1007. // Goto the same page won't trigger onload function.
  1008. // Call it manuelly to highligh new code location.
  1009. rtwFileOnLoad(top.rtwreport_document_frame.document);
  1010. }
  1011. }
  1012. }
  1013. // Compare if href1(i.e. file:///path/file1.html#222) and href2(i.e.file2.html) are same pages.
  1014. // isSamePage return true if file1 == file2.
  1015. function isSamePage(href1, href2) {
  1016. var page1 = href1.substring(href1.lastIndexOf('/')+1,href1.lastIndexOf('.html'));
  1017. var page2 = href2.substring(href2.lastIndexOf('/')+1,href2.lastIndexOf('.html'));
  1018. return (page1 == page2);
  1019. }
  1020. // Callback for main document loading
  1021. function rtwMainOnLoad() {
  1022. rtwMainOnLoadFcn(document,null,true, false);
  1023. var newUrl;
  1024. // modify history state to avoid reload from pressing back
  1025. if (RTW_TraceArgs.instance && !RTW_TraceArgs.instance.getUseExternalBrowser() &&
  1026. typeof window.history.replaceState === "function") {
  1027. if (window.location.search.length > 0) {
  1028. if (window.location.search.indexOf("loaded=true") === -1) {
  1029. newUrl = document.location.pathname + window.location.search + '&loaded=true';
  1030. } else {
  1031. newUrl = document.location.pathname + window.location.search;
  1032. }
  1033. } else {
  1034. newUrl = document.location.pathname + window.location.search + '?loaded=true';
  1035. }
  1036. window.history.replaceState("","",newUrl);
  1037. }
  1038. }
  1039. // Helper function for traceability report
  1040. function rtwMainReload(location) {
  1041. // remove highlight filename and lines before reloading the page
  1042. if (RTW_TraceInfo.instance)
  1043. RTW_TraceInfo.instance.removeHighlighting();
  1044. rtwMainOnLoadFcn(document,location,true,true);
  1045. }
  1046. function rtwMainReloadNoPanel(location) {
  1047. rtwMainOnLoadFcn(document,location,false,true);
  1048. }
  1049. // Callback for hyperlink "Remove Highlighting"
  1050. function rtwRemoveHighlighting() {
  1051. if (RTW_TraceInfo.instance)
  1052. RTW_TraceInfo.instance.removeHighlighting();
  1053. if (rtwSrcFrame()) {
  1054. rtwSrcFrame().focus();
  1055. }
  1056. if (hasInCodeTrace()) {
  1057. removeInCodeTraceHighlight();
  1058. }
  1059. }
  1060. // Display diagnostic message in document frame
  1061. function rtwDisplayMessage() {
  1062. var docObj = top.rtwreport_document_frame.document;
  1063. var msg = docObj.getElementById(RTW_TraceArgs.instance.fMessage);
  1064. if (!msg) {
  1065. msg = docObj.getElementById("rtwMsg_notTraceable");
  1066. }
  1067. if (msg && msg.style) {
  1068. msg.style.display = "block"; // make message visible
  1069. var msgstr = msg.innerHTML;
  1070. // replace '%s' in message with block name
  1071. if (top.RTW_TraceArgs.instance) {
  1072. var sid = top.RTW_TraceArgs.instance.getBlock();
  1073. if (sid) {
  1074. var block = sid;
  1075. if (top.RTW_rtwnameSIDMap && top.RTW_rtwnameSIDMap.instance && top.RTW_rtwnameSIDMap.instance.getRtwname(sid)) {
  1076. block = top.RTW_rtwnameSIDMap.instance.getRtwname(sid).rtwname;
  1077. block = block.replace("<", "&lt;").replace(">", "&gt;");
  1078. } else {
  1079. block = sid;
  1080. }
  1081. if (block) {
  1082. msgstr = msgstr.replace("%s", block);
  1083. }
  1084. }
  1085. }
  1086. msg.innerHTML = msgstr;
  1087. }
  1088. }
  1089. function updateHyperlinks() {
  1090. docObj = top.rtwreport_document_frame;
  1091. if (docObj && docObj.document) {
  1092. if (RTW_TraceArgs.instance === null || !RTW_TraceArgs.instance.getUseExternalBrowser()) {
  1093. var plain_link = docObj.document.getElementById("linkToText_plain");
  1094. if (plain_link && plain_link.href && plain_link.href.indexOf("matlab:coder.internal.editUrlTextFile") === -1 ) {
  1095. plain_link.href = "matlab:coder.internal.editUrlTextFile('" + str2StrVar(plain_link.href) + "')";
  1096. }
  1097. var alink = docObj.document.getElementById("linkToCS");
  1098. var linkCmd = "matlab:coder.internal.viewCodeConfigsetFromReport";
  1099. if (alink && alink.href && alink.href.indexOf(linkCmd) === -1) {
  1100. alink.href = linkCmd+ "('" + str2StrVar(alink.href) + "');";
  1101. if(alink.style) {
  1102. alink.style.display = "";
  1103. hidden_link = docObj.document.getElementById("linkToCS_disabled");
  1104. if (hidden_link) {
  1105. hidden_link.style.display = "none";
  1106. }
  1107. }
  1108. }
  1109. } else {
  1110. var alink = docObj.document.getElementById("linkToCS");
  1111. if (alink && alink.style) {
  1112. alink.style.display = "none";
  1113. hidden_link = docObj.document.getElementById("linkToCS_disabled");
  1114. if (hidden_link)
  1115. hidden_link.style.display = "";
  1116. }
  1117. if (typeof docObj.document.getElementsByClassName === "function") {
  1118. alinks = docObj.document.getElementsByClassName("callMATLAB");
  1119. } else if (typeof docObj.document.getElementsByName === "function") {
  1120. alinks = docObj.document.getElementsByName("callMATLAB");
  1121. } else {
  1122. alinks = [];
  1123. }
  1124. alink = docObj.document.getElementById("CodeGenAdvCheck");
  1125. if (alink && alink.href && alink.href.indexOf("externalweb=true")===-1) {
  1126. alink.href = alink.href + "?externalweb=true";
  1127. }
  1128. if (typeof docObj.document.getElementsByName === "function")
  1129. var objs = docObj.document.getElementsByName("MATLAB_link");
  1130. else
  1131. objs = [];
  1132. for (var objIndex = 0; objIndex < objs.length; ++objIndex) {
  1133. objs[objIndex].style.display = "none";
  1134. }
  1135. }
  1136. }
  1137. updateCode2ModelLinks(docObj.document);
  1138. // modify modelref links
  1139. update_modelref_report_link(top.rtwreport_contents_frame.document);
  1140. try {
  1141. // ignore browser security error
  1142. update_modelref_report_link(top.rtwreport_document_frame.document);
  1143. } catch(e) {};
  1144. }
  1145. function update_modelref_report_link(docObj) {
  1146. if (docObj.getElementsByName) {
  1147. var arg = "";
  1148. if (RTW_TraceArgs.instance && !RTW_TraceArgs.instance.getUseExternalBrowser()) {
  1149. arg = "?useExternalBrowser=false";
  1150. }
  1151. if (RTW_TraceArgs && RTW_TraceArgs.instance && RTW_TraceArgs.instance.getModel2CodeSrc() != null) {
  1152. if (arg.length > 0)
  1153. arg = arg + "&model2code_src=" + RTW_TraceArgs.instance.getModel2CodeSrc();
  1154. else
  1155. arg = "?model2code_src=" + RTW_TraceArgs.instance.getModel2CodeSrc();
  1156. }
  1157. if (arg.length > 0) {
  1158. links = docObj.getElementsByName('external_link');
  1159. for (var link_idx = 0; link_idx < links.length; ++link_idx) {
  1160. links[link_idx].href = links[link_idx].href + arg;
  1161. }
  1162. }
  1163. }
  1164. }
  1165. function rtwResizeFrame(f) {
  1166. if (f) {
  1167. f.style.height = f.contentWindow.document.body.scrollHeight + "px";
  1168. }
  1169. }
  1170. function rtwPageOnLoad(id) {
  1171. // highlight toc entry
  1172. tocHiliteById(id);
  1173. // restore elements state
  1174. if (top && top.restoreState) {
  1175. if (top.rtwreport_contents_frame && top.rtwreport_contents_frame.document)
  1176. top.restoreState(top.rtwreport_contents_frame.document);
  1177. if (top.rtwreport_document_frame && top.rtwreport_document_frame.document) {
  1178. top.restoreState(top.rtwreport_document_frame.document);
  1179. rtwResizeFrame(top.rtwreport_document_frame.document.getElementById("rtwIdContentsIframe"));
  1180. }
  1181. }
  1182. updateHyperlinks();
  1183. }
  1184. // highlight code after changeSys
  1185. function rtwChangeSysCallback(sid) {
  1186. if (sid == "" || typeof RTW_Sid2UrlHash == "undefined" || !RTW_Sid2UrlHash.instance)
  1187. return false;
  1188. urlHash = RTW_Sid2UrlHash.instance.getUrlHash(sid);
  1189. if (urlHash != undefined) {
  1190. if (RTW_TraceArgs && RTW_TraceArgs.instance &&
  1191. !RTW_TraceArgs.instance.getUseExternalBrowser())
  1192. urlHash = (urlHash == "")? "?useExternalBrowser=false" :
  1193. urlHash+"&useExternalBrowser=false";
  1194. rtwMainReload(urlHash, true);
  1195. return true;
  1196. } else {
  1197. // remove highlighting from traceinfo
  1198. rtwRemoveHighlighting();
  1199. return false;
  1200. }
  1201. }
  1202. function emlFileOnload(docObj) {
  1203. var loc = docObj.location;
  1204. if (loc.hash) {
  1205. var line = loc.hash.substring(1);
  1206. hiliteEmlLine(docObj, line);
  1207. }
  1208. }
  1209. function hiliteEmlLine(docObj, line) {
  1210. var bgColor;
  1211. if (top.HiliteCodeStatus)
  1212. bgColor = "#66CCFF";
  1213. else
  1214. bgColor = "#E8D152";
  1215. // unhighlight
  1216. if (typeof docObj.HiliteLine != "undefined") {
  1217. trObj = docObj.getElementById("LN_"+docObj.HiliteLine);
  1218. if (trObj != null) {
  1219. trObj.style.backgroundColor = "";
  1220. }
  1221. }
  1222. // hilighlight
  1223. trObj = docObj.getElementById("LN_"+line);
  1224. if (trObj != null) {
  1225. trObj.style.backgroundColor = bgColor;
  1226. docObj.HiliteLine = line;
  1227. }
  1228. }
  1229. function emlLineOnClick(docObj,sid,line) {
  1230. if (top) {
  1231. top.HiliteCodeStatus = top.rtwChangeSysCallback(sid);
  1232. }
  1233. hiliteEmlLine(docObj, line);
  1234. }
  1235. function updateCode2ModelLinks(docObj) {
  1236. var webviewFrame = top.document.getElementById('rtw_webviewMidFrame');
  1237. var link2model = false;
  1238. var isTestHarness = false;
  1239. if (top.testHarnessInfo && top.testHarnessInfo.IsTestHarness === "1") {
  1240. isTestHarness = true;
  1241. }
  1242. if (webviewFrame || isTestHarness) {
  1243. if (webviewFrame && RTW_TraceArgs.instance &&
  1244. (RTW_TraceArgs.instance.getModel2CodeSrc() !== "model" ||
  1245. RTW_TraceArgs.instance.getUseExternalBrowser())
  1246. ) {
  1247. hiliteCmd = "javascript:top.rtwHilite(";
  1248. } else {
  1249. hiliteCmd = "matlab:coder.internal.code2model(";
  1250. link2model = true;
  1251. }
  1252. var objs = docObj.getElementsByName('code2model');
  1253. var o = null;
  1254. var str = '';
  1255. var sid = '';
  1256. var pattern = "'code2model',";
  1257. for (var objIndex = 0; objIndex < objs.length; ++objIndex) {
  1258. o = objs[objIndex];
  1259. str = o.href.substring(o.href.indexOf('(')+1);
  1260. if (str.indexOf(pattern) > -1) {
  1261. str = str.substring(str.indexOf(pattern) + pattern.length);
  1262. }
  1263. o.href = hiliteCmd + str;
  1264. if (link2model && isTestHarness) {
  1265. sid = str.substring(0, str.indexOf(")"));
  1266. o.href = hiliteCmd + sid + ",'" +
  1267. top.testHarnessInfo.HarnessName+ "','" +
  1268. top.testHarnessInfo.HarnessOwner+ "','" +
  1269. top.testHarnessInfo.OwnerFileName + "');";
  1270. }
  1271. }
  1272. }
  1273. }
  1274. function rtwHilite(aBlock,aParentSID) {
  1275. if (aBlock.indexOf('-') !== -1) {
  1276. // remove sid range: model:sid:2-10 => model:sid
  1277. var s;
  1278. s = aBlock.split(':');
  1279. if (s.length > 0) {
  1280. s = s[s.length-1];
  1281. if (s.indexOf('-') != -1) {
  1282. aBlock = aBlock.substring(0, aBlock.lastIndexOf(':'));
  1283. }
  1284. }
  1285. }
  1286. if (typeof aParentSID === "undefined") {
  1287. if (top.RTW_SidParentMap && top.RTW_SidParentMap.instance)
  1288. aParentSID = top.RTW_SidParentMap.instance.getParentSid(aBlock);
  1289. else
  1290. aParentSID = aBlock;
  1291. }
  1292. top.HiliteCodeStatus = true;
  1293. // webview 2 defines an interface api, call slwebview.
  1294. if (top.slwebview) {
  1295. // webview 2.x
  1296. if (top.codeToWebView(aBlock, aParentSID) === -1) {
  1297. alert("Cannot highlight block in model Web view. It may not be exported.");
  1298. }
  1299. } else {
  1300. // webview 1.x
  1301. if (hiliteBlockForRTWReport(aBlock,aParentSID) === false) {
  1302. if (hiliteBlockForRTWReport(aBlock, aBlock) === false) {
  1303. rtwHilite(aParentSID);
  1304. }
  1305. }
  1306. }
  1307. }
  1308. function rtwHiliteMultiple(sids, action) {
  1309. //For new Code Gen report
  1310. if (top.slwebview) {
  1311. // webview 2.x
  1312. if (top.codeToWebViewArray(sids, action) === -1) {
  1313. alert("Cannot highlight block(s) in model Web view. It may not be exported.");
  1314. }
  1315. }
  1316. }
  1317. function str2StrVar(str) {
  1318. return str.replace(/'/g,"''");
  1319. }
  1320. window.onload=rtwMainOnLoad;
  1321. // handle incode traceability highlighting
  1322. function inCodeTraceOnload() {
  1323. var tocDocObj = top.rtwreport_contents_frame.document;
  1324. if (!top.RTW_TraceArgs.instance) {
  1325. var summaryPage = tocDocObj.getElementById("rtwIdSummaryPage");
  1326. top.rtwreport_document_frame.location.href = summaryPage.href;
  1327. return;
  1328. }
  1329. var files = top.RTW_TraceArgs.instance.getFile();
  1330. if (files.length === 0) {
  1331. if (top.RTW_TraceArgs.instance) {
  1332. var block = top.RTW_TraceArgs.instance.getBlock();
  1333. block = block.replace("<", "&lt;").replace(">", "&gt;");
  1334. }
  1335. top.rtwreport_document_frame.document.write("<pre>No traceability information for block " + block + ".</pre>");
  1336. return;
  1337. };
  1338. var fileLinks = RTW_TraceInfo.getFileLinks(tocDocObj);
  1339. RTW_TraceInfo.instance = new RTW_TraceInfo(fileLinks);
  1340. // update filelist with num of highlighted lines
  1341. var tocDoc = top.rtwreport_contents_frame.document;
  1342. var tLines = 0;
  1343. for (var i=0; i<files.length;i++) {
  1344. var fileIdx = top.RTW_TraceArgs.instance.getFileIdx(files[i]);
  1345. if (typeof fileIdx !== "undefined") {
  1346. var rows = top.RTW_TraceArgs.instance.getRows(fileIdx);
  1347. var linkNode = tocDoc.getElementById(files[i]);
  1348. updateNumHighlightedLines(linkNode, rows.length);
  1349. RTW_TraceInfo.instance.setLines(files[i], rows);
  1350. tLines += rows.length;
  1351. }
  1352. }
  1353. // set number of total lines
  1354. RTW_TraceInfo.instance.setTotalLines(tLines);
  1355. // update highligthed from
  1356. if (RTW_TraceArgs.instance.getNumBlocks() === 1) {
  1357. var node = tocDoc.getElementById("rtwIdTraceBlock");
  1358. if (node) node.textContent = RTW_TraceArgs.instance.getBlock();
  1359. }
  1360. // set the initial file and line
  1361. fileIdx = top.RTW_TraceArgs.instance.getFileIdx(files[0]);
  1362. rows = top.RTW_TraceArgs.instance.getRows(fileIdx);
  1363. RTW_TraceInfo.instance.setInitLocation(files[0],rows[0]);
  1364. // highlight first file
  1365. top.rtwreport_document_frame.location.href = files[0];
  1366. return;
  1367. }
  1368. function updateNumHighlightedLines(linkObj, aNumLines) {
  1369. var parent = linkObj.parentNode;
  1370. if (parent && parent.childNodes && parent.childNodes.length > 1) {
  1371. var spanNodes = parent.getElementsByTagName('span');
  1372. var len = spanNodes.length;
  1373. if (len > 0) {
  1374. if (aNumLines > 0) {
  1375. /* display number of matches */
  1376. spanNodes.item(len-1).innerHTML = "&nbsp;("+aNumLines+")";
  1377. } else {
  1378. /* clear number of matches */
  1379. spanNodes.item(len-1).innerHTML = "";
  1380. }
  1381. }
  1382. }
  1383. }
  1384. function setupInStudio() {
  1385. if (top.whole) {
  1386. var tmp = top.whole.rows.split(",");
  1387. tmp[0] = "35px";
  1388. top.whole.rows = tmp.join();
  1389. }
  1390. if (top.main) {
  1391. var tmp = top.main.cols.split(",");
  1392. tmp[0] = "0";
  1393. top.main.cols = tmp.join();
  1394. }
  1395. // add file list to source file
  1396. if (top.Html2SrcLink && top.Html2SrcLink.instance && top.fileSelector) {
  1397. var myDoc = top.fileSelector.document;
  1398. var fileSelector = myDoc.createElement("select");
  1399. fileSelector.id = "fileSelector";
  1400. fileSelector.onchange = top.fileSelectorOnChange;
  1401. var filename;
  1402. var filelink;
  1403. fileSelector.innerHTML += "<option value='" +
  1404. top.rtwreport_contents_frame.document.getElementById('rtwIdSummaryPage').href +
  1405. "'>Summary</option>";
  1406. for (var i=0; i < top.fileList.length; i++) {
  1407. filename = top.fileList[i];
  1408. filelink = top.Html2SrcLink.instance.getLink2Src(filename);
  1409. fileSelector.innerHTML += "<option value='" + filename + "'>" + filelink.substring(filelink.lastIndexOf('/')+1); + "</option>";
  1410. }
  1411. var bodyNode = myDoc.body;
  1412. bodyNode.insertBefore(fileSelector, bodyNode.firstElementChild);
  1413. var textNode = myDoc.createElement("span");
  1414. textNode.innerHTML = "Goto: ";
  1415. bodyNode.insertBefore(textNode, fileSelector);
  1416. var myCss = myDoc.createElement("link");
  1417. myCss.type = "text/css";
  1418. myCss.rel = "stylesheet";
  1419. myCss.href = "rtwreport.css";
  1420. myDoc.getElementsByTagName("head")[0].appendChild(myCss);
  1421. }
  1422. }
  1423. function toggleNavSideBar(val) {
  1424. if (top.main) {
  1425. var tmp = top.main.cols.split(",");
  1426. if (val === "on") {
  1427. tmp[tmp.length-1] = "15px";
  1428. } else {
  1429. tmp[tmp.length-1] = "0";
  1430. }
  1431. top.main.cols = tmp.join();
  1432. if (top.rtwreport_nav_frame)
  1433. top.rtwreport_nav_frame.location.href = "nav.html";
  1434. }
  1435. };
  1436. function toggleNavToolBar(val)
  1437. {
  1438. var midFrame = rtwMidFrame();
  1439. if (midFrame) {
  1440. var tmp1 = midFrame.rows.split(",");
  1441. var frameIdx = getNavToolbarFrameIdx();
  1442. if (val === "on") {
  1443. tmp1[frameIdx] = "40px";
  1444. } else {
  1445. tmp1[frameIdx] = "0";
  1446. }
  1447. midFrame.rows = tmp1.join();
  1448. if (top.rtwreport_navToolbar_frame) {
  1449. top.rtwreport_navToolbar_frame.location.href = "navToolbar.html";
  1450. }
  1451. }
  1452. };
  1453. var GlobalConfig = {
  1454. navHiliteColor: "#0000ff",
  1455. fileLinkHiliteColor: "#ffff99",
  1456. navToolbarBgcolor: "ivory",
  1457. offset: 10,
  1458. hiliteToken: false
  1459. };
  1460. var NavSideBarState = {
  1461. calLineHeight: 0,
  1462. overLink: false,
  1463. linkTarget: null,
  1464. lastLinkTarget: null,
  1465. linkTargetIdx: 0
  1466. }
  1467. function drawNavSideBar() {
  1468. var rectHeight = 1;
  1469. if (!top || !top.rtwreport_document_frame || !top.rtwreport_nav_frame) return;
  1470. if (!top.RTW_TraceArgs.instance) return;
  1471. var fileIdx = top.RTW_TraceArgs.instance.getFileIdx();
  1472. if (fileIdx === undefined) return;
  1473. var rows = top.RTW_TraceArgs.instance.getRows(fileIdx);
  1474. if (rows.length === 0) return; // no highlighted line
  1475. var codeTbl = top.rtwreport_document_frame.document.getElementById("codeTbl");
  1476. if (!codeTbl) return; // no code table
  1477. var nRows = codeTbl.rows.length + 1;
  1478. var canvas = top.rtwreport_nav_frame.document.getElementById("canvas");
  1479. canvas.width = top.rtwreport_nav_frame.innerWidth;
  1480. canvas.height = top.rtwreport_nav_frame.innerHeight-2;
  1481. NavSideBarState.calLineHeight = canvas.height/nRows;
  1482. if (canvas.getContext) {
  1483. var ctx = canvas.getContext("2d");
  1484. ctx.clearRect(0, 0, canvas.width, canvas.height);
  1485. // fill background
  1486. ctx.fillStyle = GlobalConfig.navToolbarBgcolor;
  1487. ctx.fillRect(0, 0, canvas.width, canvas.height);
  1488. ctx.fillStyle = GlobalConfig.navHiliteColor;
  1489. for (var i=0;i<rows.length;i++) {
  1490. ctx.fillRect(0, Number(rows[i])*NavSideBarState.calLineHeight, canvas.width, rectHeight);
  1491. }
  1492. if (canvas.addEventListener) {
  1493. canvas.addEventListener("mousemove", navBarOnMousemove, false);
  1494. canvas.addEventListener("click", navBarOnClick, false);
  1495. } else if (canvas.attachEvent) {
  1496. canvas.attachEvent("mousemove", navBarOnMousemove);
  1497. canvas.attachEvent("click", navBarOnClick);
  1498. }
  1499. }
  1500. }
  1501. function navBarOnMousemove(e) {
  1502. var y = e.clientY;
  1503. var tolerable_range = 5;
  1504. if (!top.RTW_TraceArgs.instance || !top.rtwreport_nav_frame) return;
  1505. var fileIdx = top.RTW_TraceArgs.instance.getFileIdx();
  1506. var rows = top.RTW_TraceArgs.instance.getRows(fileIdx);
  1507. var lineLoc,nextLineLoc;
  1508. top.rtwreport_nav_frame.document.body.style.cursor="";
  1509. NavSideBarState.overLink = false;
  1510. NavSideBarState.linkTarget = null;
  1511. NavSideBarState.linkTargetIdx = null;
  1512. for (var i=0;i<rows.length;i++) {
  1513. loc = rows[i]*NavSideBarState.calLineHeight;
  1514. // if within the tolerable range
  1515. if (Math.abs(y-loc) <= tolerable_range) {
  1516. top.rtwreport_nav_frame.document.body.style.cursor="pointer";
  1517. var canvas = top.rtwreport_nav_frame.document.getElementById("canvas");
  1518. canvas.title = "navigate to line " + rows[i];
  1519. NavSideBarState.overLink = true;
  1520. NavSideBarState.linkTarget = rows[i];
  1521. NavSideBarState.linkTargetIdx = i;
  1522. break;
  1523. }
  1524. }
  1525. }
  1526. function navBarOnClick(e) {
  1527. if (NavSideBarState.overLink && top.rtwreport_document_frame) {
  1528. rmTagToCurrentLine(); // remove current line tag
  1529. top.RTW_TraceInfo.instance.setCurrLineIdx(NavSideBarState.linkTargetIdx);
  1530. top.rtwreport_document_frame.document.location.href=RTW_TraceInfo.instance.getCurrentHRef();
  1531. top.addTagToCurrentLine(); // add current line tag
  1532. RTW_TraceInfo.instance.updateNavState();
  1533. }
  1534. }
  1535. function removeInCodeTraceHighlight() {
  1536. var docObj = top.rtwreport_document_frame.document;
  1537. toggleNavSideBar("off");
  1538. toggleNavToolBar("off");
  1539. var nodes = docObj.getElementsByClassName("hilite");
  1540. // nodes is a live nodeList. Changing className modifies the list.
  1541. while(nodes.length) {
  1542. nodes[0].className = nodes[0].className.replace("hilite", "");
  1543. }
  1544. var nodes = docObj.getElementsByClassName("hiliteCurrentLine");
  1545. // nodes is a live nodeList. Changing className modifies the list.
  1546. while(nodes.length) {
  1547. nodes[0].className = nodes[0].className.replace("hiliteCurrentLine", "");
  1548. }
  1549. // reset RTW_TraceArgs.instance
  1550. RTW_TraceArgs.instance = null;
  1551. // remove highlight in content panel except the filelink
  1552. if (RTW_TraceInfo && RTW_TraceInfo.instance) {
  1553. var currFileIdx = RTW_TraceInfo.instance.getCurrFileIdx();
  1554. RTW_TraceInfo.instance.removeHighlighting();
  1555. RTW_TraceInfo.instance.highlightFileLink(currFileIdx);
  1556. }
  1557. }
  1558. function getInspectWindow() {
  1559. var divObj = document.createElement("div");
  1560. divObj.id = "popup_window";
  1561. return divObj;
  1562. }
  1563. function getInspectData(file, anchorObj) {
  1564. var metricsData = null;
  1565. var propObj = null;
  1566. var type = null;
  1567. var size = null;
  1568. var cm;
  1569. var srcFileName = RTW_TraceInfo.toSrcFileName(file);
  1570. if (top.rtwreport_nav_frame && top.rtwreport_nav_frame.CodeMetrics &&
  1571. top.rtwreport_nav_frame.CodeMetrics.instance &&
  1572. top.RTW_TraceArgs && top.RTW_TraceArgs.instance &&
  1573. !top.RTW_TraceArgs.instance.getUseExternalBrowser()) {
  1574. cm = top.rtwreport_nav_frame.CodeMetrics.instance;
  1575. }
  1576. if (cm && cm.getMetrics) {
  1577. metricsData = cm.getMetrics(anchorObj.text);
  1578. if (!metricsData) {
  1579. // try static token
  1580. metricsData = cm.getMetrics(srcFileName + ":" + anchorObj.text);
  1581. }
  1582. if (metricsData) {
  1583. type = metricsData.type;
  1584. if (type === "var") {
  1585. type = "Global Variable";
  1586. size = "(" + metricsData.size + " byte)";
  1587. } else if (type === "fcn") {
  1588. type = "Function";
  1589. if (metricsData.stackTotal === -1) {
  1590. size = "(stack: " + metricsData.stack + " byte, total stack: recursion)";
  1591. } else {
  1592. size = "(stack: " + metricsData.stack + " byte, total stack: "
  1593. + metricsData.stackTotal + " byte)";
  1594. }
  1595. }
  1596. }
  1597. }
  1598. if (type === null) {
  1599. var defObj;
  1600. if (top.CodeDefine.instance.def[srcFileName + ":" + anchorObj.text]) {
  1601. defObj = top.CodeDefine.instance.def[srcFileName + ":" + anchorObj.text];
  1602. } else if (top.CodeDefine.instance.def[anchorObj.text]) {
  1603. defObj = top.CodeDefine.instance.def[anchorObj.text];
  1604. }
  1605. if (defObj) {
  1606. type = defObj.type;
  1607. if (type === "var") {
  1608. type = "Variable";
  1609. } else if (type === "fcn") {
  1610. type = "Function";
  1611. } else if (type === "type") {
  1612. type = "Type";
  1613. }
  1614. size = "";
  1615. }
  1616. }
  1617. var propObj = document.createElement("div");
  1618. propObj.id = "token_property";
  1619. var ulObj = document.createElement("ul");
  1620. ulObj.className = "popup_attrib_list";
  1621. if (type === null) {
  1622. ulObj.innerHTML = "Navigate to model";
  1623. } else {
  1624. ulObj.innerHTML = "<li>" + type + ": <var>" + anchorObj.text + "</var></li><li>"+
  1625. size + "</li>";
  1626. }
  1627. propObj.appendChild(ulObj);
  1628. return propObj;
  1629. }
  1630. function getInspectLink(file, pathname, anchorObj) {
  1631. var model = top.reportModel;
  1632. var tokenId = anchorObj.id;
  1633. var navObj = document.createElement("div");
  1634. navObj.id = "token_usage_nav";
  1635. ulObj = document.createElement("ul");
  1636. ulObj.id = "token_nav_links";
  1637. ulObj.className="popup_attrib_list";
  1638. var srcFileName = RTW_TraceInfo.toSrcFileName(file);
  1639. var defObj;
  1640. if (top.CodeDefine.instance.def[srcFileName + ":" + anchorObj.text]) {
  1641. defObj = top.CodeDefine.instance.def[srcFileName + ":" + anchorObj.text];
  1642. } else if (top.CodeDefine.instance.def[anchorObj.text]) {
  1643. defObj = top.CodeDefine.instance.def[anchorObj.text];
  1644. }
  1645. var line = anchorObj.id.substring(0,anchorObj.id.indexOf("c"));
  1646. // link to model
  1647. if (top.TraceInfoFlag && top.TraceInfoFlag.instance &&
  1648. top.TraceInfoFlag.instance.traceFlag[srcFileName+":"+anchorObj.id]) {
  1649. return null;
  1650. }
  1651. // link to def/decl
  1652. if (defObj) {
  1653. var filename = defObj.file.split(/\//);
  1654. filename = filename[filename.length-1];
  1655. ulObj.innerHTML += "<li><i>" + anchorObj.text + "</i> defined at <a target='rtwreport_document_frame' onclick=\"top.tokenLinkOnClick(event)\" href='" + defObj.file + "#" + defObj.line +
  1656. "'>" + RTW_TraceInfo.toSrcFileName(filename) + " line " + defObj.line + "</a></li>";
  1657. }
  1658. navObj.appendChild(ulObj);
  1659. return navObj;
  1660. }
  1661. var LastHiliteTokenId = null;
  1662. function rmHiliteClickedToken() {
  1663. if (LastHiliteTokenId) {
  1664. var o = top.rtwreport_document_frame.document.getElementById(LastHiliteTokenId);
  1665. if (o) {
  1666. o.className = o.className.replace("hiliteToken", "");
  1667. }
  1668. }
  1669. }
  1670. function hiliteClickedToken(elem) {
  1671. rmHiliteClickedToken();
  1672. LastHiliteTokenId = elem.id;
  1673. elem.className += " hiliteToken";
  1674. }
  1675. var initLine = null;
  1676. function scrollToInitLine() {
  1677. if (initLine) {
  1678. var lineElem = top.rtwreport_document_frame.document.getElementById(initLine);
  1679. if (lineElem) {
  1680. lineElem.scrollIntoView();
  1681. }
  1682. }
  1683. }
  1684. function scrollToLineBasedOnHash(hashValue) {
  1685. // move to the current highlight line if the hash is not empty
  1686. if (hashValue === "") {
  1687. if (top.RTW_TraceInfo.instance && top.RTW_TraceInfo.instance.getCurrLine() !== null) {
  1688. top.rtwreport_document_frame.document.location.href=top.RTW_TraceInfo.instance.getCurrentHRef();
  1689. top.initLine = top.rtwreport_document_frame.document.location.hash.substr(1);
  1690. }
  1691. } else {
  1692. // scroll and hilite line
  1693. hashValue = hashValue.substr(1);
  1694. if (isNaN(hashValue)) {
  1695. // #fcn_name
  1696. var pattern = "+newPage";
  1697. if (hashValue.indexOf(pattern) != -1) {
  1698. hashValue = hashValue.replace(pattern, '');
  1699. var lineElem = top.rtwreport_document_frame.document.getElementById(hashValue);
  1700. initLine = hashValue; // save initLine in case the dom is updated later by anootation
  1701. if (lineElem) {
  1702. lineElem.scrollIntoView();
  1703. addTagToCurrentLine();
  1704. }
  1705. } else {
  1706. var token = null;
  1707. pattern = ["var_", "fcn_", "type_"];
  1708. for (var i =0; i < pattern.length; i++) {
  1709. if (hashValue.indexOf(pattern[i]) === 0) {
  1710. token = hashValue.substr(pattern[i].length);
  1711. break;
  1712. }
  1713. }
  1714. if (token !== null && top.CodeDefine && top.CodeDefine.instance) {
  1715. var addr;
  1716. var filename = location.pathname.split(/\//);
  1717. filename = filename[filename.length-1];
  1718. var srcFileName;
  1719. if (top.RTW_TraceInfo) {
  1720. srcFileName = top.RTW_TraceInfo.toSrcFileName(filename);
  1721. }
  1722. if (top.CodeDefine.instance.def[srcFileName + ":" + token]) {
  1723. addr = top.CodeDefine.instance.def[srcFileName + ":" + token];
  1724. } else {
  1725. addr = top.CodeDefine.instance.def[token];
  1726. }
  1727. if (addr) {
  1728. hilite_line(addr.line);
  1729. }
  1730. } else { // token id like #line"c"#col
  1731. if (hashValue.indexOf("c") !== -1) {
  1732. hilite_line(hashValue.substr(0, hashValue.indexOf("c")), hashValue);
  1733. }
  1734. }
  1735. }
  1736. } else { // #line
  1737. hilite_line(hashValue);
  1738. }
  1739. }
  1740. return false;
  1741. // hilite line number and scroll with an offset
  1742. function hilite_line(line, tokenId) {
  1743. if (isNaN(line)) return;
  1744. if (!tokenId) {
  1745. tokenId = line;
  1746. }
  1747. var elem = top.rtwreport_document_frame.document.getElementById(tokenId);
  1748. hiliteClickedToken(elem);
  1749. initLine = offset_line(line);
  1750. scrollToInitLine();
  1751. }
  1752. }
  1753. function tokenLinkOnClick(event) {
  1754. var alink = event.currentTarget;
  1755. if (alink.pathname === top.rtwreport_document_frame.location.pathname) {
  1756. event.preventDefault();
  1757. scrollToLineBasedOnHash(alink.hash);
  1758. }
  1759. return false;
  1760. }
  1761. function inspectToken(file, pathname, event) {
  1762. var height = "70px";
  1763. // show inspect data
  1764. if (top.rtwreport_inspect_frame) {
  1765. var windowObj = getInspectWindow();
  1766. var propObj = getInspectData(file, event.currentTarget);
  1767. var navObj = getInspectLink(file, pathname, event.currentTarget);
  1768. if (navObj === null) {
  1769. closeInspectWindow();
  1770. return false;
  1771. }
  1772. if (propObj === null) {
  1773. height = "50px";
  1774. } else {
  1775. windowObj.appendChild(propObj);
  1776. }
  1777. windowObj.appendChild(navObj);
  1778. var data = top.rtwreport_inspect_frame.document.getElementById("popup_window");
  1779. if (data) {
  1780. data.parentNode.replaceChild(windowObj.cloneNode(true), data);
  1781. }
  1782. }
  1783. var offsetHeight = 0;
  1784. var docHeight = 0;
  1785. if (typeof(top.rtwInspectFrame().document.body.offsetHeight) === "number") {
  1786. offsetHeight = top.rtwInspectFrame().document.body.offsetHeight;
  1787. }
  1788. if (typeof(top.rtwInspectFrame().document.height) === "number") {
  1789. docHeight = top.rtwInspectFrame().document.height;
  1790. }
  1791. if (offsetHeight > 0) {
  1792. height = ""+offsetHeight+"px";
  1793. } else if (docHeight > 0) {
  1794. height = ""+docHeight+"px";
  1795. }
  1796. setInspectWindow(height);
  1797. return false;
  1798. }
  1799. function setInspectWindow(height) {
  1800. // show inspect code frame
  1801. var midFrame = rtwMidFrame();
  1802. if (midFrame) {
  1803. var tmp = midFrame.rows.split(",");
  1804. tmp[getInspectFrameIdx()] = height;
  1805. midFrame.rows = tmp.join();
  1806. }
  1807. }
  1808. function closeInspectWindow() {
  1809. setInspectWindow(0);
  1810. return false;
  1811. }
  1812. // set the trace number in the navigation toolbar
  1813. function setTraceNumber() {
  1814. if (RTW_TraceInfo.instance) {
  1815. var aFrame = rtwNavToolbarFrame();
  1816. if (aFrame) {
  1817. var node = aFrame.document.getElementById("rtwIdTraceNumber");
  1818. // calculate current line index over total highlighted lines
  1819. var currNum = RTW_TraceInfo.instance.getCurrLineIdx();
  1820. for (var idx=0;idx<RTW_TraceInfo.instance.getCurrFileIdx();idx++) {
  1821. currNum += RTW_TraceInfo.instance.getNumLines(idx);
  1822. }
  1823. if (node) {
  1824. node.innerHTML = String(currNum+1) + " of " + String(RTW_TraceInfo.instance.getTotalLines());
  1825. }
  1826. }
  1827. }
  1828. }
  1829. function offset_line(line, offset) {
  1830. if (offset == undefined)
  1831. offset = GlobalConfig.offset;
  1832. if (offset > 0)
  1833. line = (line > GlobalConfig.offset ? line - GlobalConfig.offset : 1);
  1834. return line;
  1835. }
  1836. function load_js(frame, file) {
  1837. var h = frame.document.getElementsByTagName("head")[0];
  1838. var o = h.getElementsByTagName('script');
  1839. for (var i=0;i<o.length;++i) {
  1840. if (o[i].getAttribute("src") === file) {
  1841. h.removeChild(o[i]);
  1842. }
  1843. }
  1844. var s = top.document.createElement("script");
  1845. s.type = "text/javascript";
  1846. s.src = file;
  1847. h.appendChild(s);
  1848. }
  1849. function reqOnClick(event) {
  1850. top.hiliteClickedToken(event.currentTarget);
  1851. return true;
  1852. }
  1853. function resize_NavToolbar_frame() {
  1854. resize_frame(getNavToolbarFrameIdx(), rtwNavToolbarFrame().document.height);
  1855. }
  1856. function resize_frame(id, height) {
  1857. if (height) {
  1858. var midFrame = top.rtwMidFrame();
  1859. var tmp = midFrame.rows.split(",");
  1860. if (tmp[id] !== "0%" && tmp[id] !== "0") {
  1861. tmp[id] = "" + height - 8 + "px";
  1862. midFrame.rows = tmp.join();
  1863. }
  1864. }
  1865. }
  1866. function getNavToolbarFrameIdx() {
  1867. return 0;
  1868. }
  1869. function getInspectFrameIdx() {
  1870. return 2;
  1871. }
  1872. function load_metrics() {
  1873. var alink = top.document.createElement("a");
  1874. alink.href = "metrics.js";
  1875. if (top.RTW_TraceArgs && top.RTW_TraceArgs.instance && !top.RTW_TraceArgs.instance.getUseExternalBrowser()) {
  1876. try {
  1877. load_js(top.rtwreport_nav_frame, alink.href);
  1878. } catch (err) {};
  1879. }
  1880. }
  1881. function getNavFrame() {
  1882. if (hasWebviewFrame()) {
  1883. return rtwTocFrame();
  1884. } else {
  1885. return rtwNavToolbarFrame();
  1886. }
  1887. }
  1888. function hasWebviewFrame() {
  1889. if (top.document.getElementById('rtw_webviewMidFrame')) {
  1890. return true;
  1891. } else {
  1892. return false;
  1893. }
  1894. }
  1895. function hasInCodeTrace() {
  1896. return (typeof(Html2SrcLink) === "function") && !hasWebviewFrame();
  1897. }
  1898. function uniqueRows(rows) {
  1899. return rows.sort(function(a,b) {return a-b}).filter(
  1900. function(el,idx, arr) {
  1901. if (idx===arr.indexOf(el)) return true; return false;
  1902. }
  1903. );
  1904. }
  1905. function fileSelectorOnChange(event) {
  1906. var o = top.Html2SrcLink.instance.getLinkFromRoot(event.currentTarget.value)
  1907. if (o) {
  1908. top.rtwreport_document_frame.location.href = o;
  1909. } else {
  1910. top.rtwreport_document_frame.location.href = event.currentTarget.value;
  1911. }
  1912. }
  1913. function getBuildDir() {
  1914. var relPathToBuildDir = top.relPathToBuildDir.substr(0,top.relPathToBuildDir.lastIndexOf('/')+1);
  1915. var a = document.createElement('a');
  1916. a.href = relPathToBuildDir;
  1917. var ret = decodeURI(a.pathname);
  1918. if (top.isPC && ret[0] === "/") {
  1919. ret = ret.substr(1);
  1920. }
  1921. ret = ret.replace(new RegExp("/", 'g'), top.fileSep);
  1922. return ret;
  1923. }
  1924. function getCodeLocation() {
  1925. var codeLocation = getBuildDir();
  1926. // make build dir link in report visible by clearing 'display' style
  1927. docObj = top.rtwreport_document_frame;
  1928. var alinkTitle = docObj.document.getElementById("sourceLocationTitle");
  1929. if (alinkTitle && alinkTitle.style) {
  1930. alinkTitle.style.display = "";
  1931. }
  1932. var alink = docObj.document.getElementById("sourceLocation");
  1933. if (alink && alink.style) {
  1934. alink.style.display = "";
  1935. }
  1936. return codeLocation;
  1937. }
  1938. // get code lines for the input SIDs
  1939. function getCodeLines()
  1940. {
  1941. var codeLocs = "";
  1942. var sid = RTW_TraceArgs.instance.getSID();
  1943. sid = sid.split(",");
  1944. if(sid.length == 1) {
  1945. codeLocs = RTW_Sid2UrlHash.instance.getUrlHash(sid[0]);
  1946. }
  1947. else {
  1948. var fileLocs = [];
  1949. for(var i=0; i < sid.length; ++i) {
  1950. var locstr = RTW_Sid2UrlHash.instance.getUrlHash(sid[i]);
  1951. var locs = locstr.split("&");
  1952. for(var j=0; j< locs.length; ++j) {
  1953. locElems = locs[j].split(":");
  1954. if(fileLocs[locElems[0]] == null) {
  1955. fileLocs[locElems[0]] = locElems[1];
  1956. }
  1957. else {
  1958. fileLocs[locElems[0]] = fileLocs[locElems[0]].concat(",", locElems[1]);
  1959. }
  1960. }
  1961. }
  1962. // join all locations
  1963. Object.keys(fileLocs).forEach(function(key) {
  1964. if(codeLocs.length != 0) {
  1965. codeLocs = codeLocs.concat("&", key, ":", fileLocs[key]);
  1966. } else {
  1967. codeLocs = codeLocs.concat(key, ":", fileLocs[key]);
  1968. }
  1969. });
  1970. }
  1971. return codeLocs;
  1972. }
  1973. //add source to frame when _codegen_rpt openend from outisde matlab
  1974. function loadDocFrameSource(modelName) {
  1975. const urlParams = new URLSearchParams(window.location.search);
  1976. const opendInExtBrowser = urlParams.get('useExternalBrowser');
  1977. if (opendInExtBrowser === null) {
  1978. document.getElementById('rtwreport_document_frame').src = modelName.concat('_survey.html');
  1979. }
  1980. }