sch_test/altium_sch.html

156 lines
3.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<html>
<head>
<script type="text/javascript" src="mxclient/js/mxClient.js"></script>
<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>
<script type="text/javascript" src="cfb.js"></script>
</head>
<body>
<div><input type="file" id="altium-file"></input></div>
<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>
<script type="text/javascript">
// renderSchematic(getTestFile());
function readSchematicFile(e) {
// console.log(e)
let file = e.target.files[0];
if (!file)
{
return;
}
let reader = new FileReader();
reader.onload = function(e)
{
let contents = e.target.result;
let cfbs = window.cfb
// console.log(contents)
var dec = new TextDecoder("utf-8");
let arr = Array.prototype.slice.call(new Uint8Array(contents ));
var ss = cfbs.read(arr,{type: 'binary'});
// console.log(ss)
var schdat = cfbs.find(ss, 'FileHeader');
var data = schdat.content;
let arrayBuffer = new Uint8Array(data).buffer;
console.log(dec.decode(arrayBuffer))
renderSchematic(arrayBuffer);
};
reader.readAsArrayBuffer(file);
}
document.getElementById('altium-file').addEventListener('change', readSchematicFile, false);
// 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;
}
});
});
}
function renderSchematic(data)
{
let canvas = document.getElementById("canvas");
// console.log(new TextDecoder('utf-8').decod*****************e(fhData))
let altiumDocument = new AltiumDocument(data);
window.altiumDocument = altiumDocument;
let renderer = new AltiumSchematicRenderer(canvas, altiumDocument);
renderer.render();
}
</script>
</body>
</html