sch_test/altium_sch.html

156 lines
3.8 KiB
HTML
Raw Normal View History

2022-11-06 03:37:52 +00:00
<html>
<head>
2024-02-25 16:34:35 +00:00
<script type="text/javascript" src="mxclient/js/mxClient.js"></script>
2022-11-06 03:37:52 +00:00
<script type="text/javascript" src="base64_binary.js"></script>
<script type="text/javascript" src="helper_extensions.js"></script>
<script type="text/javascript" src="u8stream.js"></script>
<script type="text/javascript" src="ole.js"></script>
<script type="text/javascript" src="altium_sch_document.js"></script>
<script type="text/javascript" src="altium_sch_renderer.js"></script>
<script type="text/javascript" src="test_schdoc.js"></script>
2024-02-11 05:08:35 +00:00
<script type="text/javascript" src="cfb.js"></script>
2022-11-06 03:37:52 +00:00
</head>
<body>
<div><input type="file" id="altium-file"></input></div>
2024-02-25 16:34:35 +00:00
<div id="graphContainer"
style="overflow:auto;position:relative;width:1500px;height:600px;border:1px solid gray;background:url('images/wires-grid.gif');background-position:-1px 0px;cursor:crosshair;">
</div>
<div>
<pre id="results"></pre>
</div>
2022-11-06 03:37:52 +00:00
<script type="text/javascript">
2024-02-11 05:08:35 +00:00
// renderSchematic(getTestFile());
2022-11-06 03:37:52 +00:00
2024-02-25 16:34:35 +00:00
function readSchematicFile(e) {
2024-03-02 01:40:02 +00:00
// console.log(e)
2022-11-06 03:37:52 +00:00
let file = e.target.files[0];
if (!file)
{
return;
}
let reader = new FileReader();
reader.onload = function(e)
{
let contents = e.target.result;
2024-02-11 05:08:35 +00:00
let cfbs = window.cfb
2024-03-02 01:40:02 +00:00
// console.log(contents)
2024-02-11 05:08:35 +00:00
var dec = new TextDecoder("utf-8");
let arr = Array.prototype.slice.call(new Uint8Array(contents ));
var ss = cfbs.read(arr,{type: 'binary'});
2024-02-25 16:34:35 +00:00
// console.log(ss)
2024-02-11 05:08:35 +00:00
var schdat = cfbs.find(ss, 'FileHeader');
var data = schdat.content;
let arrayBuffer = new Uint8Array(data).buffer;
console.log(dec.decode(arrayBuffer))
renderSchematic(arrayBuffer);
2022-11-06 03:37:52 +00:00
};
reader.readAsArrayBuffer(file);
}
document.getElementById('altium-file').addEventListener('change', readSchematicFile, false);
2024-02-11 05:08:35 +00:00
// ArrayBuffer转16进制字符串
function ab2hex(buffer) {
const hexArr = Array.prototype.map.call(
new Uint8Array(buffer),
function (bit) {
return (('00' + bit.toString(16)).slice(-2) + " ")
}
)
return hexArr.join('')
}
function doSave(value, type, name) {
var blob;
if (typeof window.Blob == "function") {
blob = new Blob([value], {
type: type
});
} else {
var BlobBuilder = window.BlobBuilder || window.MozBlobBuilder || window.WebKitBlobBuilder || window.MSBlobBuilder;
var bb = new BlobBuilder();
bb.append(value);
blob = bb.getBlob(type);
}
var URL = window.URL || window.webkitURL;
var bloburl = URL.createObjectURL(blob);
var anchor = document.createElement("a");
if ('download' in anchor) {
anchor.style.visibility = "hidden";
anchor.href = bloburl;
anchor.download = name;
document.body.appendChild(anchor);
var evt = document.createEvent("MouseEvents");
evt.initEvent("click", true, true);
anchor.dispatchEvent(evt);
document.body.removeChild(anchor);
} else if (navigator.msSaveBlob) {
navigator.msSaveBlob(blob, name);
} else {
location.href = bloburl;
}
}
function arrayToAscii(strArray) {
return strArray.flatMap(str => {
// 將每個字符串轉換為字符數組
return Array.from(str, char => {
// 取得字符的Unicode編碼
const charCode = char.charCodeAt(0);
// 判斷是否為ASCII字符0-127
if (charCode <= 127) {
// 如果是ASCII字符返回對應的ASCII值
return charCode;
} else {
// 如果不是ASCII字符返回null或undefined根據需要處理
return null;
}
});
});
}
2022-11-06 03:37:52 +00:00
function renderSchematic(data)
{
let canvas = document.getElementById("canvas");
2024-02-11 05:08:35 +00:00
// console.log(new TextDecoder('utf-8').decod*****************e(fhData))
let altiumDocument = new AltiumDocument(data);
2022-11-06 03:37:52 +00:00
window.altiumDocument = altiumDocument;
let renderer = new AltiumSchematicRenderer(canvas, altiumDocument);
renderer.render();
}
</script>
</body>
2024-02-25 16:34:35 +00:00
</html