diff --git a/altium_sch.html b/altium_sch.html index a4c2e7c..e47849d 100644 --- a/altium_sch.html +++ b/altium_sch.html @@ -25,7 +25,7 @@ style="overflow:auto;position:relative;width:1500px;height:600px;border:1px soli // renderSchematic(getTestFile()); function readSchematicFile(e) { - console.log(e) + // console.log(e) let file = e.target.files[0]; if (!file) { @@ -36,7 +36,7 @@ function readSchematicFile(e) { { let contents = e.target.result; let cfbs = window.cfb - console.log(contents) + // console.log(contents) var dec = new TextDecoder("utf-8"); let arr = Array.prototype.slice.call(new Uint8Array(contents )); diff --git a/altium_sch_document.js b/altium_sch_document.js index b320483..f3503f2 100644 --- a/altium_sch_document.js +++ b/altium_sch_document.js @@ -697,7 +697,7 @@ class AltiumDocument this.stream = new U8Stream(streams); this.records = []; let index = -1; // header comes first, so give it an index of -1 - console.log(this.stream.length) + // console.log(this.stream.length) while (this.stream.u8stream_position < this.stream.length) { this.records.push(new AltiumRecord(this.stream, index)); diff --git a/altium_sch_renderer.js b/altium_sch_renderer.js index 3e20a22..67185ad 100644 --- a/altium_sch_renderer.js +++ b/altium_sch_renderer.js @@ -24,7 +24,12 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - +mxConnectionHandler.prototype.movePreviewAway = false; +mxConnectionHandler.prototype.waypointsEnabled = true; +mxGraph.prototype.resetEdgesOnConnect = false; +mxConstants.SHADOWCOLOR = '#C0C0C0'; +var joinNodeSize = 7; +var strokeWidth = 2; class AltiumSchematicRenderer { @@ -32,6 +37,7 @@ class AltiumSchematicRenderer { this.canvas = canvas; this.document = document; + this.graph = null } #altiumColourToHex(colourInt) @@ -54,85 +60,194 @@ class AltiumSchematicRenderer return parent.current_part_id == object.owner_part_id; } - render() { - let graph = new mxGraph(document.getElementById('graphContainer')); - graph.setPanning(true); - graph.setConnectable(true); - graph.setConnectableEdges(true); - graph.setDisconnectOnMove(false); - graph.foldingEnabled = false; + initGraph() { + this.graph = new mxGraph(document.getElementById('graphContainer')); + this.graph.setPanning(true); + this.graph.setConnectable(true); + this.graph.setConnectableEdges(true); + this.graph.setDisconnectOnMove(false); + this.graph.foldingEnabled = false; //Maximum size - graph.maximumGraphBounds = new mxRectangle(0, 0, 800, 600) - graph.border = 50; + this.graph.maximumGraphBounds = new mxRectangle(0, 0, 1400, 600) + this.graph.border = 0; var fontColor = '#FFFFFF' ; var strokeColor = '#C0C0C0' ; var fillColor = '#C0C0C0'; // Panning handler consumed right click so this must be // disabled if right click should stop connection handler. - graph.panningHandler.isPopupTrigger = function() { return false; }; + this.graph.panningHandler.isPopupTrigger = function() { return false; }; // Enables return key to stop editing (use shift-enter for newlines) - graph.setEnterStopsCellEditing(true); + this.graph.setEnterStopsCellEditing(true); // Adds rubberband selection - new mxRubberband(graph); - - // Alternative solution for implementing connection points without child cells. - // This can be extended as shown in portrefs.html example to allow for per-port - // incoming/outgoing direction. - graph.getAllConnectionConstraints = function(terminal) { - var geo = (terminal != null) ? this.getCellGeometry(terminal.cell) : null; - console.log("getAllConnectionConstraints ") - if ((geo != null ? !geo.relative : false) && - this.getModel().isVertex(terminal.cell) && - this.getModel().getChildCount(terminal.cell) == 0) - { - return [new mxConnectionConstraint(new mxPoint(0, 0.5), false), - new mxConnectionConstraint(new mxPoint(1, 0.5), false)]; - } - - return null; - }; - - // Makes sure non-relative cells can only be connected via constraints - graph.connectionHandler.isConnectableCell = function(cell) { - console.log("isConnectableCell",cell) - if (this.graph.getModel().isEdge(cell)) - { - return true; - } - else - { - var geo = (cell != null) ? this.graph.getCellGeometry(cell) : null; - - return (geo != null) ? geo.relative : false; - } - }; - var parent = graph.getDefaultParent(); + new mxRubberband(this.graph); - graph.getModel().beginUpdate(); - try + mxVertexHandler.prototype.rotationEnabled = true; + + // Alternative solution for implementing connection points without child cells. + // This can be extended as shown in portrefs.html example to allow for per-port + // incoming/outgoing direction. + this.graph.getAllConnectionConstraints = function(terminal) { + var geo = (terminal != null) ? this.getCellGeometry(terminal.cell) : null; + console.log("getAllConnectionConstraints ") + if ((geo != null ? !geo.relative : false) && + this.getModel().isVertex(terminal.cell) && + this.getModel().getChildCount(terminal.cell) == 0) { - var v1 = graph.insertVertex(parent, null, 'J1', 80, 40, 40, 80, - 'verticalLabelPosition=top;verticalAlign=bottom;shadow=1;fillColor=' + fillColor); - v1.setConnectable(false); + return [new mxConnectionConstraint(new mxPoint(0, 0.5), false), + new mxConnectionConstraint(new mxPoint(1, 0.5), false)]; + } - var v11 = graph.insertVertex(v1, null, '1', 0, 0, 10, 16, - 'shape=line;align=left;verticalAlign=middle;fontSize=10;routingCenterX=-0.5;'+ - 'spacingLeft=12;fontColor=' + fontColor + ';strokeColor=' + strokeColor); - v11.geometry.relative = true; - v11.geometry.offset = new mxPoint(-v11.geometry.width, 2); - var v12 = v11.clone(); - v12.value = '2'; - v12.geometry.offset = new mxPoint(-v11.geometry.width, 22); - v1.insert(v12); + return null; + }; + + // Makes sure non-relative cells can only be connected via constraints + this.graph.connectionHandler.isConnectableCell = function(cell) { + console.log("isConnectableCell",cell) + if (this.graph.getModel().isEdge(cell)) + { + return true; } - finally{ - graph.getModel().endUpdate(); - + else + { + var geo = (cell != null) ? this.graph.getCellGeometry(cell) : null; + + return (geo != null) ? geo.relative : false; } + }; + + var parent = this.graph.getDefaultParent(); + mxVertexHandler.prototype.livePreview = true; + mxVertexHandler.prototype.rotationEnabled = true; + + var labelBackground = (false) ? '#000000' : '#FFFFFF'; + var fontColor = (false) ? '#FFFFFF' : '#000000'; + var strokeColor = (false) ? '#C0C0C0' : '#000000'; + var fillColor = (false) ? 'none' : '#FFFFFF'; + + var style = this.graph.getStylesheet().getDefaultEdgeStyle(); + delete style['endArrow']; + style['strokeColor'] = strokeColor; + style['labelBackgroundColor'] = labelBackground; + style['edgeStyle'] = 'wireEdgeStyle'; + style['fontColor'] = fontColor; + style['fontSize'] = '9'; + style['movable'] = '0'; + style['strokeWidth'] = strokeWidth; + style['rounded'] = '0'; + + // Sets join node size + style['startSize'] = joinNodeSize; + style['endSize'] = joinNodeSize; + + style = this.graph.getStylesheet().getDefaultVertexStyle(); + //style['gradientColor'] = '#909090'; + style['strokeColor'] = strokeColor; + //style['fillColor'] = '#e0e0e0'; + style['fillColor'] = 'none'; + style['fontColor'] = fontColor; + style['fontStyle'] = '1'; + style['fontSize'] = '12'; + style['resizable'] = '0'; + style['strokeWidth'] = strokeWidth; + + } + + render() { + this.graph = new mxGraph(document.getElementById('graphContainer')); + this.graph.setPanning(true); + this.graph.setConnectable(true); + this.graph.setConnectableEdges(true); + this.graph.setDisconnectOnMove(false); + this.graph.foldingEnabled = false; + this.graph.gridSize = 1 + //Maximum size + this.graph.maximumGraphBounds = new mxRectangle(0, 0, 1920, 800) + this.graph.border = 20; + var fontColor = '#FFFFFF' ; + var strokeColor = '#C0C0C0' ; + var fillColor = '#C0C0C0'; + // Panning handler consumed right click so this must be + // disabled if right click should stop connection handler. + this.graph.panningHandler.isPopupTrigger = function() { return false; }; + + // Enables return key to stop editing (use shift-enter for newlines) + this.graph.setEnterStopsCellEditing(true); + + // Adds rubberband selection + new mxRubberband(this.graph); + + mxVertexHandler.prototype.rotationEnabled = true; + + // Alternative solution for implementing connection points without child cells. + // This can be extended as shown in portrefs.html example to allow for per-port + // incoming/outgoing direction. + this.graph.getAllConnectionConstraints = function(terminal) { + var geo = (terminal != null) ? this.getCellGeometry(terminal.cell) : null; + console.log("getAllConnectionConstraints ") + if ((geo != null ? !geo.relative : false) && + this.getModel().isVertex(terminal.cell) && + this.getModel().getChildCount(terminal.cell) == 0) + { + return [new mxConnectionConstraint(new mxPoint(0, 0.5), false), + new mxConnectionConstraint(new mxPoint(1, 0.5), false)]; + } + + return null; + }; + + // Makes sure non-relative cells can only be connected via constraints + this.graph.connectionHandler.isConnectableCell = function(cell) { + if (this.graph.getModel().isEdge(cell)) + { + return true; + } + else + { + var geo = (cell != null) ? this.graph.getCellGeometry(cell) : null; + + return (geo != null) ? geo.relative : false; + } + }; + + var parent = this.graph.getDefaultParent(); + mxVertexHandler.prototype.livePreview = true; + mxVertexHandler.prototype.rotationEnabled = true; + + var labelBackground = (false) ? '#000000' : '#FFFFFF'; + var fontColor = (false) ? '#FFFFFF' : '#000000'; + var strokeColor = (false) ? '#C0C0C0' : '#000000'; + var fillColor = (false) ? 'none' : '#FFFFFF'; + + + var style = this.graph.getStylesheet().getDefaultEdgeStyle(); + delete style['endArrow']; + style['strokeColor'] = strokeColor; + style['labelBackgroundColor'] = labelBackground; + style['edgeStyle'] = 'wireEdgeStyle'; + style['fontColor'] = fontColor; + style['fontSize'] = '9'; + style['movable'] = '0'; + style['strokeWidth'] = strokeWidth; + style['rounded'] = '0'; + + // Sets join node size + style['startSize'] = joinNodeSize; + style['endSize'] = joinNodeSize; + + style = this.graph.getStylesheet().getDefaultVertexStyle(); + //style['gradientColor'] = '#909090'; + style['strokeColor'] = strokeColor; + //style['fillColor'] = '#e0e0e0'; + style['fillColor'] = 'none'; + style['fontColor'] = fontColor; + style['fontStyle'] = '1'; + style['fontSize'] = '12'; + style['resizable'] = '0'; + style['strokeWidth'] = strokeWidth; // let canvas = this.canvas; let doc = this.document; @@ -208,702 +323,800 @@ class AltiumSchematicRenderer ctx.textAlign = "left"; */ - let bom = []; - bom.push("\"designator\", \"part\", \"description\""); - for (let obj of doc.objects.filter((o) => o instanceof AltiumDesignator)) - { - if (!this.#shouldShow(obj)) continue; - - let bomLine = ""; - //let designator = doc.objects.find((des) => des instanceof AltiumDesignator && des.owner_part_id == obj.current_part_id); - let component = doc.object_from_record_index(obj.owner_record_index); - if (component != null && component instanceof AltiumComponent) + this.graph.getModel().beginUpdate(); + try{ + let bom = []; + bom.push("\"designator\", \"part\", \"description\""); + for (let obj of doc.objects.filter((o) => o instanceof AltiumDesignator)) { - bomLine += "\"" + obj.text + "\", \"" + component.design_item_id + "\", \"" + component.description.replaceAll("\"", "'") + "\""; - bom.push(bomLine); + if (!this.#shouldShow(obj)) continue; + + let bomLine = ""; + //let designator = doc.objects.find((des) => des instanceof AltiumDesignator && des.owner_part_id == obj.current_part_id); + let component = doc.object_from_record_index(obj.owner_record_index); + if (component != null && component instanceof AltiumComponent) + { + bomLine += "\"" + obj.text + "\", \"" + component.design_item_id + "\", \"" + component.description.replaceAll("\"", "'") + "\""; + bom.push(bomLine); + } + //bomLine += obj.description; + } - //bomLine += obj.description; - - } - results.innerText = bom.join("\n"); + results.innerText = bom.join("\n"); - for (let obj of doc.objects.filter((o) => o instanceof AltiumWire)) - { - // if (!this.#shouldShow(obj)) continue; - - // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); - // ctx.lineWidth = obj.width; - // ctx.beginPath(); - // ctx.moveTo(obj.points[0].x, obj.points[0].y); - // for (let i = 1; i < obj.points.length; i++) - // { - // ctx.lineTo(obj.points[i].x, obj.points[i].y); - // } - // ctx.stroke(); - } - for (let obj of doc.objects.filter((o) => o instanceof AltiumBus)) - { - // if (!this.#shouldShow(obj)) continue; - - // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); - // ctx.lineWidth = obj.width; - // ctx.beginPath(); - // ctx.moveTo(obj.points[0].x, obj.points[0].y); - // for (let i = 1; i < obj.points.length; i++) - // { - // ctx.lineTo(obj.points[i].x, obj.points[i].y); - // } - // ctx.stroke(); - } + for (let obj of doc.objects.filter((o) => o instanceof AltiumWire)) + { + // for (let i = 1; i < obj.points.length; i++) + // { + // obj.points[i].y = 840 - obj.points[i].y + // } + var obj1 = this.graph.getCellAt(obj.points[0].x,obj.points[0].y,parent) + var obj2 = this.graph.getCellAt(obj.points[obj.points.length - 1].x, + obj.points[obj.points.length - 1].y,parent) - for (let obj of doc.objects.filter((o) => o instanceof AltiumSheetSymbol)) - { - // if (!this.#shouldShow(obj)) continue; + console.log(obj1,obj2) + // if (!this.#shouldShow(obj)) continue; + + // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); + // ctx.lineWidth = obj.width; + // ctx.beginPath(); + // ctx.moveTo(obj.points[0].x, obj.points[0].y); + // for (let i = 1; i < obj.points.length; i++) + // { + // ctx.lineTo(obj.points[i].x, obj.points[i].y); + // } + // ctx.stroke(); + } + for (let obj of doc.objects.filter((o) => o instanceof AltiumBus)) + { + // if (!this.#shouldShow(obj)) continue; + + // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); + // ctx.lineWidth = obj.width; + // ctx.beginPath(); + // ctx.moveTo(obj.points[0].x, obj.points[0].y); + // for (let i = 1; i < obj.points.length; i++) + // { + // ctx.lineTo(obj.points[i].x, obj.points[i].y); + // } + // ctx.stroke(); + } + + for (let obj of doc.objects.filter((o) => o instanceof AltiumSheetSymbol)) + { + // if (!this.#shouldShow(obj)) continue; + // ctx.fillStyle = this.#altiumColourToHex(obj.attributes.areacolor); + + // ctx.fillRect(obj.attributes.location_x, + // obj.attributes.location_y- obj.attributes.ysize, + // obj.attributes.xsize, obj.attributes.ysize); + // ctx.stroke(); + // ctx.strokeStyle = this.#altiumColourToHex(obj.attributes.color); + // ctx.strokeRect(obj.attributes.location_x, + // obj.attributes.location_y- obj.attributes.ysize, + // obj.attributes.xsize, obj.attributes.ysize); + + + // ctx.strokeStyle = "#000080"; + // ctx.lineWidth = obj.width; + // ctx.beginPath(); + // ctx.moveTo(obj.attributes.location_x, obj.attributes.location_y); + // ctx.lineTo(obj.attributes.location_x + obj.attributes.xsize, + // obj.attributes.location_y + obj.attributes.ysize); + // ctx.stroke(); + + // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); + // ctx.lineWidth = obj.width; + // ctx.beginPath(); + // ctx.moveTo(obj.points[0].x, obj.points[0].y); + // for (let i = 1; i < obj.points.length; i++) + // { + // ctx.lineTo(obj.points[i].x, obj.points[i].y); + // } + // ctx.stroke(); + } + + var v1 + for (let obj of doc.objects.filter((o) => o instanceof AltiumRectangle)) + { + obj.top = 840 - obj.top + obj.bottom = 840 - obj.bottom + + console.log('verticalLabelPosition=top;verticalAlign=bottom;fillColor=' + + this.#altiumColourToHex(obj.attributes.areacolor)) + v1 = this.graph.insertVertex(parent, null, '', + obj.left, obj.top, + (obj.right - obj.left), + (obj.bottom - obj.top), + 'verticalLabelPosition=top;verticalAlign=bottom;fillColor=' + + this.#altiumColourToHex(obj.attributes.areacolor)); + v1.setConnectable(false); + + // if (!this.#shouldShow(obj)) + // continue; // ctx.fillStyle = this.#altiumColourToHex(obj.attributes.areacolor); // ctx.fillRect(obj.attributes.location_x, - // obj.attributes.location_y- obj.attributes.ysize, - // obj.attributes.xsize, obj.attributes.ysize); + // obj.attributes.location_y, + // obj.attributes.corner_x - obj.attributes.location_x, obj.attributes.corner_y - obj.attributes.location_y); // ctx.stroke(); // ctx.strokeStyle = this.#altiumColourToHex(obj.attributes.color); // ctx.strokeRect(obj.attributes.location_x, - // obj.attributes.location_y- obj.attributes.ysize, - // obj.attributes.xsize, obj.attributes.ysize); + // obj.attributes.location_y, + // obj.attributes.corner_x - obj.attributes.location_x, obj.attributes.corner_y - obj.attributes.location_y); + + } - - // ctx.strokeStyle = "#000080"; - // ctx.lineWidth = obj.width; - // ctx.beginPath(); - // ctx.moveTo(obj.attributes.location_x, obj.attributes.location_y); - // ctx.lineTo(obj.attributes.location_x + obj.attributes.xsize, - // obj.attributes.location_y + obj.attributes.ysize); - // ctx.stroke(); - - // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); - // ctx.lineWidth = obj.width; - // ctx.beginPath(); - // ctx.moveTo(obj.points[0].x, obj.points[0].y); - // for (let i = 1; i < obj.points.length; i++) - // { - // ctx.lineTo(obj.points[i].x, obj.points[i].y); - // } - // ctx.stroke(); - } - for (let obj of doc.objects.filter((o) => o instanceof AltiumRectangle)) - { - // if (!this.#shouldShow(obj)) - // continue; - // ctx.fillStyle = this.#altiumColourToHex(obj.attributes.areacolor); - - // ctx.fillRect(obj.attributes.location_x, - // obj.attributes.location_y, - // obj.attributes.corner_x - obj.attributes.location_x, obj.attributes.corner_y - obj.attributes.location_y); - // ctx.stroke(); - // ctx.strokeStyle = this.#altiumColourToHex(obj.attributes.color); - // ctx.strokeRect(obj.attributes.location_x, - // obj.attributes.location_y, - // obj.attributes.corner_x - obj.attributes.location_x, obj.attributes.corner_y - obj.attributes.location_y); - - } - // todo undo - for (let obj of doc.objects.filter((o) => o instanceof AltiumSheetEntry)) - { - if (!this.#shouldShow(obj)) continue; - - // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); - // ctx.lineWidth = obj.width; - // ctx.beginPath(); - // ctx.moveTo(obj.points[0].x, obj.points[0].y); - // for (let i = 1; i < obj.points.length; i++) - // { - // ctx.lineTo(obj.points[i].x, obj.points[i].y); - // } - // ctx.stroke(); - } - - for (let obj of doc.objects.filter((o) => o instanceof AltiumTextFrame)) - { - // if (!this.#shouldShow(obj)) continue; - - // if (!obj.transparent) - // { - // ctx.fillStyle = this.#altiumColourToHex(obj.fill_colour); - // ctx.fillRect(obj.left, obj.top, obj.right - obj.left, - // obj.bottom - obj.top); - // } - // if (obj.show_border) - // { - // ctx.strokeStyle = this.#altiumColourToHex(obj.border_colour); - // ctx.strokeRect(obj.left, obj.top, obj.right - obj.left, - // obj.bottom - obj.top); - // } - } - - for (let obj of doc.objects.filter((o) => o instanceof AltiumEllipse)) - { - // if (!this.#shouldShow(obj)) continue; - - // if (!obj.transparent) - // { - // ctx.fillStyle = this.#altiumColourToHex(obj.fill_colour); - // } - // ctx.strokeStyle = this.#altiumColourToHex(obj.line_colour); - // ctx.beginPath(); - // ctx.ellipse(obj.x, obj.y, obj.radius_x, obj.radius_y, 0, 0, Math.PI*2); - // ctx.stroke(); - // if (!obj.transparent) - // ctx.fill(); - } - - for (let obj of doc.objects.filter((o) => o instanceof AltiumPin)) - { - // if (!this.#shouldShow(obj)) continue; - - // ctx.strokeStyle = "#000000"; - // ctx.beginPath(); - // ctx.moveTo(obj.x, obj.y); - // ctx.lineTo(obj.x + obj.angle_vec[0] * obj.length, obj.y + obj.angle_vec[1] * obj.length); - // ctx.stroke(); - - // ctx.fillStyle = this.#altiumColourToHex(obj.colour); - // ctx.beginPath(); - // ctx.ellipse(obj.x + obj.angle_vec[0] * obj.length, obj.y + obj.angle_vec[1] * obj.length, 5, 4, 0, 0, 2*Math.PI); - // ctx.fill(); - } - - for (let obj of doc.objects.filter((o) => o instanceof AltiumLine)) - { - // if (!this.#shouldShow(obj)) continue; - - // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); - // ctx.beginPath(); - // ctx.moveTo(obj.x1, obj.y1); - // ctx.lineTo(obj.x2, obj.y2); - // ctx.stroke(); - } - - for (let obj of doc.objects.filter((o) => o instanceof AltiumArc)) - { - // if (!this.#shouldShow(obj)) continue; - - // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); - // ctx.lineWidth = obj.width; - // ctx.beginPath(); - // ctx.arc(obj.x, obj.y, obj.radius, obj.start_angle * Math.PI/180, obj.end_angle * Math.PI/180); - // ctx.stroke(); - // ctx.lineWidth = 1; - } - - for (let obj of doc.objects.filter((o) => o instanceof AltiumPolyline)) - { - // if (!this.#shouldShow(obj)) continue; - - // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); - // ctx.fillStyle = this.#altiumColourToHex(obj.colour); - // ctx.lineWidth = obj.width; - - // switch (obj.line_style) - // { - // case 1: - // ctx.setLineDash([4, 4]); - // break; - // case 2: - // ctx.setLineDash([2, 2]); - // break; - // case 3: - // ctx.setLineDash([4, 2, 2, 4]); - // break; - // } - - // ctx.beginPath(); - // ctx.moveTo(obj.points[0].x, obj.points[0].y); - // for (let i = 1; i < obj.points.length; i++) - // { - // ctx.lineTo(obj.points[i].x, obj.points[i].y); - // } - // ctx.stroke(); - - // ctx.setLineDash([]); - - // let pa = null; - // let pb = null; - // let shapeSize = obj.shape_size + 1; - // ctx.lineWidth = shapeSize; - // if (obj.start_shape > 0) - // { - // let pa = obj.points[1]; - // let pb = obj.points[0]; - // let dx = pb.x - pa.x; - // let dy = pb.y - pa.y; - // let angle = Math.atan2(dy, dx); - // const baseSize = 3 + shapeSize; - // let tax = pb.x - Math.cos(angle - Math.PI/6) * baseSize; - // let tay = pb.y - Math.sin(angle - Math.PI/6) * baseSize; - // let tbx = pb.x - Math.cos(angle + Math.PI/6) * baseSize; - // let tby = pb.y - Math.sin(angle + Math.PI/6) * baseSize; - // ctx.beginPath(); - // ctx.moveTo(tax, tay); - // ctx.lineTo(pb.x + Math.cos(angle) * 0.5, pb.y + Math.sin(angle) * 0.5); - // ctx.lineTo(tbx, tby); - // ctx.stroke(); - // if (obj.start_shape == 2 || obj.start_shape == 4) - // ctx.fill(); - // } - // if (obj.end_shape > 0) - // { - // let pa = obj.points[obj.points.length - 2]; - // let pb = obj.points[obj.points.length - 1]; - // let dx = pb.x - pa.x; - // let dy = pb.y - pa.y; - // let angle = Math.atan2(dy, dx); - // const baseSize = 3 + shapeSize; - // let tax = pb.x - Math.cos(angle - Math.PI/6) * baseSize; - // let tay = pb.y - Math.sin(angle - Math.PI/6) * baseSize; - // let tbx = pb.x - Math.cos(angle + Math.PI/6) * baseSize; - // let tby = pb.y - Math.sin(angle + Math.PI/6) * baseSize; - // ctx.beginPath(); - // ctx.moveTo(tax, tay); - // ctx.lineTo(pb.x + Math.cos(angle) * 0.5, pb.y + Math.sin(angle) * 0.5); - // ctx.lineTo(tbx, tby); - // ctx.stroke(); - // if (obj.end_shape == 2 || obj.end_shape == 4) - // ctx.fill(); - // } - // ctx.lineWidth = 1; - } - - for (let obj of doc.objects.filter((o) => o instanceof AltiumPolygon)) - { - // if (!this.#shouldShow(obj)) continue; - - // ctx.strokeStyle = this.#altiumColourToHex(obj.line_colour); - // ctx.fillStyle = this.#altiumColourToHex(obj.fill_colour); - // ctx.lineWidth = obj.width; - // ctx.beginPath(); - // ctx.moveTo(obj.points[0].x, obj.points[0].y); - // for (let i = 1; i < obj.points.length; i++) - // { - // ctx.lineTo(obj.points[i].x, obj.points[i].y); - // } - // ctx.closePath(); - // ctx.stroke(); - // ctx.fill(); - // ctx.lineWidth = 1; - } - - for (let obj of doc.objects.filter((o) => o instanceof AltiumJunction)) - { - // if (!this.#shouldShow(obj)) continue; - - // ctx.fillStyle = this.#altiumColourToHex(obj.colour); - // ctx.beginPath(); - // ctx.ellipse(obj.x, obj.y, 5, 4, 0, 0, 2*Math.PI); - // ctx.fill(); - } - - for (let obj of doc.objects.filter((o) => o instanceof AltiumPowerPort)) - { - // if (!this.#shouldShow(obj)) continue; - - // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); - // ctx.fillStyle = this.#altiumColourToHex(obj.colour); - // ctx.lineWidth = 1; - // if (!obj.is_off_sheet_connector) - // { - // switch (obj.style) - // { - // case 2: - // ctx.beginPath(); - // ctx.moveTo(obj.x, obj.y); - // ctx.lineTo(obj.x, obj.y + 10); - // ctx.stroke(); - // ctx.beginPath(); - // ctx.moveTo(obj.x - 5, obj.y + 10); - // ctx.lineTo(obj.x + 5, obj.y + 10); - // ctx.stroke(); - // break; - // case 4: - // ctx.beginPath(); - // ctx.moveTo(obj.x - 10, obj.y); - // ctx.lineTo(obj.x + 10, obj.y); - // ctx.stroke(); - // ctx.beginPath(); - // ctx.moveTo(obj.x - 7.5, obj.y - 2); - // ctx.lineTo(obj.x + 7.5, obj.y - 2); - // ctx.stroke(); - // ctx.beginPath(); - // ctx.moveTo(obj.x - 5, obj.y - 4); - // ctx.lineTo(obj.x + 5, obj.y - 4); - // ctx.stroke(); - // ctx.beginPath(); - // ctx.moveTo(obj.x - 2.5, obj.y - 6); - // ctx.lineTo(obj.x + 2.5, obj.y - 6); - // ctx.stroke(); - // break; - // case 6: - // ctx.beginPath(); - // ctx.moveTo(obj.x, obj.y); - // ctx.lineTo(obj.x, obj.y - 5); - // ctx.stroke(); - // ctx.beginPath(); - // ctx.moveTo(obj.x - 5, obj.y - 5); - // ctx.lineTo(obj.x + 5, obj.y - 5); - // ctx.stroke(); - // for (let g = -1; g < 2; g++) - // { - // ctx.beginPath(); - // ctx.moveTo(obj.x + (g * 5), obj.y - 5); - // ctx.lineTo(obj.x + (g * 5) - 3, obj.y - 10); - // ctx.stroke(); - // } - // break; - // default: - // ctx.fillRect(obj.x - 10, obj.y, 20, (obj.orientation == 1) ? 10 : -10); - // break; - // } - // } - // else - // { - // ctx.save(); - // ctx.translate(obj.x, obj.y); - // ctx.rotate((obj.orientation - 1) * Math.PI/2); + // todo undo + for (let obj of doc.objects.filter((o) => o instanceof AltiumSheetEntry)) + { + if (!this.#shouldShow(obj)) continue; - // ctx.beginPath(); - // ctx.moveTo(0, 0); - // ctx.lineTo(-5, 5); - // ctx.stroke(); - // ctx.beginPath(); - // ctx.moveTo(0, 0); - // ctx.lineTo(5, 5); - // ctx.stroke(); - // ctx.beginPath(); - // ctx.moveTo(0, 5); - // ctx.lineTo(-5, 10); - // ctx.stroke(); - // ctx.beginPath(); - // ctx.moveTo(0, 5); - // ctx.lineTo(5, 10); - // ctx.stroke(); + // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); + // ctx.lineWidth = obj.width; + // ctx.beginPath(); + // ctx.moveTo(obj.points[0].x, obj.points[0].y); + // for (let i = 1; i < obj.points.length; i++) + // { + // ctx.lineTo(obj.points[i].x, obj.points[i].y); + // } + // ctx.stroke(); + } + + for (let obj of doc.objects.filter((o) => o instanceof AltiumTextFrame)) + { + // if (!this.#shouldShow(obj)) continue; - // ctx.restore(); - // } - //ctx.fillText(obj.style.toString(), obj.x, obj.y); - } + // if (!obj.transparent) + // { + // ctx.fillStyle = this.#altiumColourToHex(obj.fill_colour); + // ctx.fillRect(obj.left, obj.top, obj.right - obj.left, + // obj.bottom - obj.top); + // } + // if (obj.show_border) + // { + // ctx.strokeStyle = this.#altiumColourToHex(obj.border_colour); + // ctx.strokeRect(obj.left, obj.top, obj.right - obj.left, + // obj.bottom - obj.top); + // } + } - // store the transform for recovery later - // let savedTransform = ctx.getTransform(); - // ctx.resetTransform(); + for (let obj of doc.objects.filter((o) => o instanceof AltiumEllipse)) + { + // if (!this.#shouldShow(obj)) continue; + + // if (!obj.transparent) + // { + // ctx.fillStyle = this.#altiumColourToHex(obj.fill_colour); + // } + // ctx.strokeStyle = this.#altiumColourToHex(obj.line_colour); + // ctx.beginPath(); + // ctx.ellipse(obj.x, obj.y, obj.radius_x, obj.radius_y, 0, 0, Math.PI*2); + // ctx.stroke(); + // if (!obj.transparent) + // ctx.fill(); + } + console.log(doc.objects) + for (let obj of doc.objects.filter((o) => o instanceof AltiumPin)) + { + var style = 'shape=line;fontColor=#000000;strokeColor=#000000;' + if(obj.angle == 90){ + style += 'rotation=90' + obj.y = obj.y + obj.length/2 + obj.x = obj.x - obj.length/2 + } + if(obj.angle == 180){ + obj.x = obj.x - obj.length + } + if(obj.angle == 270){ + style += 'rotation=90' + obj.y = obj.y - obj.length/2 + obj.x = obj.x - obj.length/2 - for (let obj of doc.objects.filter((o) => o instanceof AltiumLabel)) - { - // if (!this.#shouldShow(obj)) continue; - - // if (obj.hidden) - // continue; - // ctx.textAlign = ["left", "center", "right"][obj.justification]; - // ctx.textBaseline = ["bottom", "bottom", "top", "top"][obj.orientation]; - // ctx.fillStyle = this.#altiumColourToHex(obj.colour); - // ctx.save(); - // ctx.translate(obj.x, canvas.height - obj.y); - // ctx.rotate(obj.orientation * -Math.PI/2); - // ctx.fillText(obj.text, 0, 0); - // ctx.restore(); - } - // ctx.textAlign = "left"; - // ctx.textBaseline = "bottom"; + } + obj.y = 840 - obj.y - for (let obj of doc.objects.filter((o) => o instanceof AltiumDesignator)) - { - // if (!this.#shouldShow(obj)) continue; - - // if (obj.hidden) - // continue; - // ctx.textAlign = ["left", "left", "right", "right"][obj.orientation]; - // ctx.textBaseline = ["bottom", "bottom", "top", "top"][obj.orientation]; - // ctx.fillStyle = this.#altiumColourToHex(obj.colour); - // ctx.fillText(obj.full_designator, obj.x, canvas.height - obj.y); - } - // ctx.textAlign = "left"; - // ctx.textBaseline = "bottom"; + // console.log(style) + var v11 = this.graph.insertVertex(parent, null, '', obj.x, obj.y, + obj.length, 1, + style); + v11.geometry.relative = false; + v11.setConnectable(true); + // v11.geometry.offset = new mxPoint(-v11.geometry.width, 2); // ctx.strokeStyle = "#000000"; + // ctx.beginPath(); + // ctx.moveTo(obj.x, obj.y); + // ctx.lineTo(obj.x + obj.angle_vec[0] * obj.length, obj.y + obj.angle_vec[1] * obj.length); + // ctx.stroke(); - for (let obj of doc.objects.filter((o) => o instanceof AltiumParameter)) - { - // if (!this.#shouldShow(obj)) continue; - - // if (obj.hidden || obj.is_implementation_parameter) - // continue; - - // ctx.textAlign = ["left", "left", "right", "right"][obj.orientation]; - // ctx.textBaseline = ["bottom", "bottom", "top", "top"][obj.orientation]; - // ctx.fillStyle = this.#altiumColourToHex(obj.colour); - // if (obj.orientation == 1) - // { - // ctx.save(); - // ctx.translate(obj.x, canvas.height - obj.y); - // ctx.rotate(-Math.PI/2); - // ctx.fillText(obj.text, 0, 0); - // ctx.restore(); - // } - // else if (obj.orientation == 3) - // { - // ctx.save(); - // ctx.translate(obj.x, canvas.height - obj.y); - // ctx.rotate(Math.PI/2); - // ctx.fillText(obj.text, 0, 0); - // ctx.restore(); - // } - // else - // { - // ctx.fillText(obj.text, obj.x, canvas.height - obj.y); - // } - } - // ctx.textAlign = "left"; - // ctx.textBaseline = "bottom"; + // ctx.fillStyle = this.#altiumColourToHex(obj.colour); + // ctx.beginPath(); + // ctx.ellipse(obj.x + obj.angle_vec[0] * obj.length, obj.y + obj.angle_vec[1] * obj.length, 5, 4, 0, 0, 2*Math.PI); + // ctx.fill(); + } - for (let obj of doc.objects.filter((o) => o instanceof AltiumNetLabel)) - { - // if (!this.#shouldShow(obj)) continue; - // if (obj.hidden) - // continue; - // ctx.textAlign = ["left", "center", "right"][obj.justification]; - // ctx.textBaseline = ["bottom", "bottom", "top", "top"][obj.orientation]; - // ctx.fillStyle = this.#altiumColourToHex(obj.colour); - // if (obj.orientation == 1) - // { - // ctx.save(); - // ctx.translate(obj.x, canvas.height - obj.y); - // ctx.rotate(-Math.PI/2); - // ctx.fillText(obj.text, 0, 0); - // ctx.restore(); - // } - // else if (obj.orientation == 3) - // { - // ctx.save(); - // ctx.translate(obj.x, canvas.height - obj.y); - // ctx.rotate(Math.PI/2); - // ctx.fillText(obj.text, 0, 0); - // ctx.restore(); - // } - // else - // { - // ctx.fillText(obj.text, obj.x, canvas.height - obj.y); - // } - } - // ctx.textAlign = "left"; - // ctx.textBaseline = "bottom"; + for (let obj of doc.objects.filter((o) => o instanceof AltiumLine)) + { - for (let obj of doc.objects.filter((o) => o instanceof AltiumPin)) - { - // if (!this.#shouldShow(obj)) continue; + // if (!this.#shouldShow(obj)) continue; + + // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); + // ctx.beginPath(); + // ctx.moveTo(obj.x1, obj.y1); + // ctx.lineTo(obj.x2, obj.y2); + // ctx.stroke(); + } + + for (let obj of doc.objects.filter((o) => o instanceof AltiumArc)) + { + // if (!this.#shouldShow(obj)) continue; + + // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); + // ctx.lineWidth = obj.width; + // ctx.beginPath(); + // ctx.arc(obj.x, obj.y, obj.radius, obj.start_angle * Math.PI/180, obj.end_angle * Math.PI/180); + // ctx.stroke(); + // ctx.lineWidth = 1; + } + + for (let obj of doc.objects.filter((o) => o instanceof AltiumPolyline)) + { + // if (!this.#shouldShow(obj)) continue; + + // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); + // ctx.fillStyle = this.#altiumColourToHex(obj.colour); + // ctx.lineWidth = obj.width; + + // switch (obj.line_style) + // { + // case 1: + // ctx.setLineDash([4, 4]); + // break; + // case 2: + // ctx.setLineDash([2, 2]); + // break; + // case 3: + // ctx.setLineDash([4, 2, 2, 4]); + // break; + // } + + // ctx.beginPath(); + // ctx.moveTo(obj.points[0].x, obj.points[0].y); + // for (let i = 1; i < obj.points.length; i++) + // { + // ctx.lineTo(obj.points[i].x, obj.points[i].y); + // } + // ctx.stroke(); + + // ctx.setLineDash([]); + + // let pa = null; + // let pb = null; + // let shapeSize = obj.shape_size + 1; + // ctx.lineWidth = shapeSize; + // if (obj.start_shape > 0) + // { + // let pa = obj.points[1]; + // let pb = obj.points[0]; + // let dx = pb.x - pa.x; + // let dy = pb.y - pa.y; + // let angle = Math.atan2(dy, dx); + // const baseSize = 3 + shapeSize; + // let tax = pb.x - Math.cos(angle - Math.PI/6) * baseSize; + // let tay = pb.y - Math.sin(angle - Math.PI/6) * baseSize; + // let tbx = pb.x - Math.cos(angle + Math.PI/6) * baseSize; + // let tby = pb.y - Math.sin(angle + Math.PI/6) * baseSize; + // ctx.beginPath(); + // ctx.moveTo(tax, tay); + // ctx.lineTo(pb.x + Math.cos(angle) * 0.5, pb.y + Math.sin(angle) * 0.5); + // ctx.lineTo(tbx, tby); + // ctx.stroke(); + // if (obj.start_shape == 2 || obj.start_shape == 4) + // ctx.fill(); + // } + // if (obj.end_shape > 0) + // { + // let pa = obj.points[obj.points.length - 2]; + // let pb = obj.points[obj.points.length - 1]; + // let dx = pb.x - pa.x; + // let dy = pb.y - pa.y; + // let angle = Math.atan2(dy, dx); + // const baseSize = 3 + shapeSize; + // let tax = pb.x - Math.cos(angle - Math.PI/6) * baseSize; + // let tay = pb.y - Math.sin(angle - Math.PI/6) * baseSize; + // let tbx = pb.x - Math.cos(angle + Math.PI/6) * baseSize; + // let tby = pb.y - Math.sin(angle + Math.PI/6) * baseSize; + // ctx.beginPath(); + // ctx.moveTo(tax, tay); + // ctx.lineTo(pb.x + Math.cos(angle) * 0.5, pb.y + Math.sin(angle) * 0.5); + // ctx.lineTo(tbx, tby); + // ctx.stroke(); + // if (obj.end_shape == 2 || obj.end_shape == 4) + // ctx.fill(); + // } + // ctx.lineWidth = 1; + } + + for (let obj of doc.objects.filter((o) => o instanceof AltiumPolygon)) + { + // if (!this.#shouldShow(obj)) continue; + + // ctx.strokeStyle = this.#altiumColourToHex(obj.line_colour); + // ctx.fillStyle = this.#altiumColourToHex(obj.fill_colour); + // ctx.lineWidth = obj.width; + // ctx.beginPath(); + // ctx.moveTo(obj.points[0].x, obj.points[0].y); + // for (let i = 1; i < obj.points.length; i++) + // { + // ctx.lineTo(obj.points[i].x, obj.points[i].y); + // } + // ctx.closePath(); + // ctx.stroke(); + // ctx.fill(); + // ctx.lineWidth = 1; + } + + for (let obj of doc.objects.filter((o) => o instanceof AltiumJunction)) + { + // if (!this.#shouldShow(obj)) continue; + + // ctx.fillStyle = this.#altiumColourToHex(obj.colour); + // ctx.beginPath(); + // ctx.ellipse(obj.x, obj.y, 5, 4, 0, 0, 2*Math.PI); + // ctx.fill(); + } + + for (let obj of doc.objects.filter((o) => o instanceof AltiumPowerPort)) + { + // if (!this.#shouldShow(obj)) continue; + + // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); + // ctx.fillStyle = this.#altiumColourToHex(obj.colour); + // ctx.lineWidth = 1; + // if (!obj.is_off_sheet_connector) + // { + // switch (obj.style) + // { + // case 2: + // ctx.beginPath(); + // ctx.moveTo(obj.x, obj.y); + // ctx.lineTo(obj.x, obj.y + 10); + // ctx.stroke(); + // ctx.beginPath(); + // ctx.moveTo(obj.x - 5, obj.y + 10); + // ctx.lineTo(obj.x + 5, obj.y + 10); + // ctx.stroke(); + // break; + // case 4: + // ctx.beginPath(); + // ctx.moveTo(obj.x - 10, obj.y); + // ctx.lineTo(obj.x + 10, obj.y); + // ctx.stroke(); + // ctx.beginPath(); + // ctx.moveTo(obj.x - 7.5, obj.y - 2); + // ctx.lineTo(obj.x + 7.5, obj.y - 2); + // ctx.stroke(); + // ctx.beginPath(); + // ctx.moveTo(obj.x - 5, obj.y - 4); + // ctx.lineTo(obj.x + 5, obj.y - 4); + // ctx.stroke(); + // ctx.beginPath(); + // ctx.moveTo(obj.x - 2.5, obj.y - 6); + // ctx.lineTo(obj.x + 2.5, obj.y - 6); + // ctx.stroke(); + // break; + // case 6: + // ctx.beginPath(); + // ctx.moveTo(obj.x, obj.y); + // ctx.lineTo(obj.x, obj.y - 5); + // ctx.stroke(); + // ctx.beginPath(); + // ctx.moveTo(obj.x - 5, obj.y - 5); + // ctx.lineTo(obj.x + 5, obj.y - 5); + // ctx.stroke(); + // for (let g = -1; g < 2; g++) + // { + // ctx.beginPath(); + // ctx.moveTo(obj.x + (g * 5), obj.y - 5); + // ctx.lineTo(obj.x + (g * 5) - 3, obj.y - 10); + // ctx.stroke(); + // } + // break; + // default: + // ctx.fillRect(obj.x - 10, obj.y, 20, (obj.orientation == 1) ? 10 : -10); + // break; + // } + // } + // else + // { + // ctx.save(); + // ctx.translate(obj.x, obj.y); + // ctx.rotate((obj.orientation - 1) * Math.PI/2); + + // ctx.beginPath(); + // ctx.moveTo(0, 0); + // ctx.lineTo(-5, 5); + // ctx.stroke(); + // ctx.beginPath(); + // ctx.moveTo(0, 0); + // ctx.lineTo(5, 5); + // ctx.stroke(); + // ctx.beginPath(); + // ctx.moveTo(0, 5); + // ctx.lineTo(-5, 10); + // ctx.stroke(); + // ctx.beginPath(); + // ctx.moveTo(0, 5); + // ctx.lineTo(5, 10); + // ctx.stroke(); + + // ctx.restore(); + // } + //ctx.fillText(obj.style.toString(), obj.x, obj.y); + } + + // store the transform for recovery later + // let savedTransform = ctx.getTransform(); + // ctx.resetTransform(); + + for (let obj of doc.objects.filter((o) => o instanceof AltiumLabel)) + { + // if (!this.#shouldShow(obj)) continue; + + // if (obj.hidden) + // continue; + // ctx.textAlign = ["left", "center", "right"][obj.justification]; + // ctx.textBaseline = ["bottom", "bottom", "top", "top"][obj.orientation]; + // ctx.fillStyle = this.#altiumColourToHex(obj.colour); + // ctx.save(); + // ctx.translate(obj.x, canvas.height - obj.y); + // ctx.rotate(obj.orientation * -Math.PI/2); + // ctx.fillText(obj.text, 0, 0); + // ctx.restore(); + } + // ctx.textAlign = "left"; + // ctx.textBaseline = "bottom"; + + for (let obj of doc.objects.filter((o) => o instanceof AltiumDesignator)) + { + // if (!this.#shouldShow(obj)) continue; + + // if (obj.hidden) + // continue; + // ctx.textAlign = ["left", "left", "right", "right"][obj.orientation]; + // ctx.textBaseline = ["bottom", "bottom", "top", "top"][obj.orientation]; + // ctx.fillStyle = this.#altiumColourToHex(obj.colour); + // ctx.fillText(obj.full_designator, obj.x, canvas.height - obj.y); + } + // ctx.textAlign = "left"; + // ctx.textBaseline = "bottom"; + + for (let obj of doc.objects.filter((o) => o instanceof AltiumParameter)) + { + // if (!this.#shouldShow(obj)) continue; + + // if (obj.hidden || obj.is_implementation_parameter) + // continue; + + // ctx.textAlign = ["left", "left", "right", "right"][obj.orientation]; + // ctx.textBaseline = ["bottom", "bottom", "top", "top"][obj.orientation]; + // ctx.fillStyle = this.#altiumColourToHex(obj.colour); + // if (obj.orientation == 1) + // { + // ctx.save(); + // ctx.translate(obj.x, canvas.height - obj.y); + // ctx.rotate(-Math.PI/2); + // ctx.fillText(obj.text, 0, 0); + // ctx.restore(); + // } + // else if (obj.orientation == 3) + // { + // ctx.save(); + // ctx.translate(obj.x, canvas.height - obj.y); + // ctx.rotate(Math.PI/2); + // ctx.fillText(obj.text, 0, 0); + // ctx.restore(); + // } + // else + // { + // ctx.fillText(obj.text, obj.x, canvas.height - obj.y); + // } + } + // ctx.textAlign = "left"; + // ctx.textBaseline = "bottom"; + + for (let obj of doc.objects.filter((o) => o instanceof AltiumNetLabel)) + { + // if (!this.#shouldShow(obj)) continue; + + // if (obj.hidden) + // continue; + // ctx.textAlign = ["left", "center", "right"][obj.justification]; + // ctx.textBaseline = ["bottom", "bottom", "top", "top"][obj.orientation]; + // ctx.fillStyle = this.#altiumColourToHex(obj.colour); + // if (obj.orientation == 1) + // { + // ctx.save(); + // ctx.translate(obj.x, canvas.height - obj.y); + // ctx.rotate(-Math.PI/2); + // ctx.fillText(obj.text, 0, 0); + // ctx.restore(); + // } + // else if (obj.orientation == 3) + // { + // ctx.save(); + // ctx.translate(obj.x, canvas.height - obj.y); + // ctx.rotate(Math.PI/2); + // ctx.fillText(obj.text, 0, 0); + // ctx.restore(); + // } + // else + // { + // ctx.fillText(obj.text, obj.x, canvas.height - obj.y); + // } + } + // ctx.textAlign = "left"; + // ctx.textBaseline = "bottom"; + + for (let obj of doc.objects.filter((o) => o instanceof AltiumPin)) + { + // if (!this.#shouldShow(obj)) continue; + + // if (!obj.show_name) + // continue; + // ctx.textAlign = ["right", "right", "left", "right"][obj.orientation]; + // ctx.textBaseline = "middle"; + // let objName = obj.name; + // let inverted = false; + // if (obj.name.includes("\\")) + // { + // objName = obj.name.replaceAll("\\", ""); + // inverted = true; + // } + // if (obj.name_orientation != 0) + // { + // ctx.textBaseline = ["middle", "top", "middle", "bottom"][obj.orientation]; + // if (obj.name_orientation <= 3) + // ctx.textAlign = ["left", "center", "right"][obj.name_orientation-1]; + // else + // ctx.textAlign = "center"; + // } + // let margin_x = [-1, 0, 1, 0][obj.orientation] * 2; + // let margin_y = [0, -1, 0, 1][obj.orientation] * 2; + // ctx.fillStyle = this.#altiumColourToHex(obj.colour); + // ctx.strokeStyle = ctx.fillStyle; + // ctx.lineWidth = 1; + // if (obj.orientation == 1 && obj.name_orientation == 0) + // { + // ctx.save(); + // ctx.translate(obj.x + margin_x, canvas.height - (obj.y + margin_y)); + // ctx.rotate(-Math.PI/2); + // ctx.fillText(objName, 0, 0); + // if (inverted) + // { + // // todo: test this + // let textSize = ctx.measureText(objName); + // ctx.beginPath(); + // ctx.moveTo(0, textSize.actualBoundingBoxAscent + 2); + // ctx.lineTo(textSize.width, textSize.actualBoundingBoxAscent + 2); + // ctx.stroke(); + // } + // ctx.restore(); + // } + // else if (obj.orientation == 3 && obj.name_orientation == 0) + // { + // ctx.save(); + // ctx.translate(obj.x + margin_x, canvas.height - (obj.y + margin_y)); + // ctx.rotate(Math.PI/2); + // ctx.fillText(objName, 0, 0); + // if (inverted) + // { + // // todo: test this + // let textSize = ctx.measureText(objName); + // ctx.beginPath(); + // ctx.moveTo(0, textSize.actualBoundingBoxAscent + 2); + // ctx.lineTo(textSize.width, textSize.actualBoundingBoxAscent + 2); + // ctx.stroke(); + // } + // ctx.restore(); + // } + // else + // { + // ctx.fillText(objName, obj.x + margin_x, canvas.height - (obj.y + margin_y)); + // if (inverted) + // { + // let textSize = ctx.measureText(objName); + // let offset = 0; + // switch (ctx.textAlign) + // { + // case "center": + // offset = -(textSize.width/2); + // break; + // case "right": + // offset = -textSize.width; + // break; + // case "left": + // offset = 0; + // break; + // default: + // offset = 0; + // break; + // } + // ctx.beginPath(); + // ctx.moveTo(obj.x + margin_x + offset, canvas.height - (obj.y + margin_y + textSize.actualBoundingBoxAscent + 2)); + // ctx.lineTo(obj.x + margin_x + offset + textSize.width, canvas.height - (obj.y + margin_y + textSize.actualBoundingBoxAscent + 2)); + // ctx.stroke(); + // } + // } + + // ctx.setLineDash([]); + } + // ctx.textAlign = "left"; + // ctx.textBaseline = "bottom"; + + for (let obj of doc.objects.filter((o) => o instanceof AltiumPowerPort)) + { + // if (!this.#shouldShow(obj)) continue; + + // if (!obj.show_text) + // continue; + // ctx.fillStyle = this.#altiumColourToHex(obj.colour); + // ctx.textBaseline = ["middle", "top", "middle", "bottom"][obj.orientation]; + // ctx.textAlign = ["left", "center", "right", "center"][obj.orientation]; + // let offset_x = [12, 0, -12, 0][obj.orientation]; + // let offset_y = [0, 20, 0, -20][obj.orientation]; + // ctx.fillText(obj.text, obj.x + offset_x, canvas.height - (obj.y + offset_y)); + } - // if (!obj.show_name) - // continue; - // ctx.textAlign = ["right", "right", "left", "right"][obj.orientation]; + // ctx.textAlign = "left"; // ctx.textBaseline = "middle"; - // let objName = obj.name; - // let inverted = false; - // if (obj.name.includes("\\")) - // { - // objName = obj.name.replaceAll("\\", ""); - // inverted = true; - // } - // if (obj.name_orientation != 0) - // { - // ctx.textBaseline = ["middle", "top", "middle", "bottom"][obj.orientation]; - // if (obj.name_orientation <= 3) - // ctx.textAlign = ["left", "center", "right"][obj.name_orientation-1]; - // else - // ctx.textAlign = "center"; - // } - // let margin_x = [-1, 0, 1, 0][obj.orientation] * 2; - // let margin_y = [0, -1, 0, 1][obj.orientation] * 2; - // ctx.fillStyle = this.#altiumColourToHex(obj.colour); - // ctx.strokeStyle = ctx.fillStyle; - // ctx.lineWidth = 1; - // if (obj.orientation == 1 && obj.name_orientation == 0) - // { - // ctx.save(); - // ctx.translate(obj.x + margin_x, canvas.height - (obj.y + margin_y)); - // ctx.rotate(-Math.PI/2); - // ctx.fillText(objName, 0, 0); - // if (inverted) - // { - // // todo: test this - // let textSize = ctx.measureText(objName); - // ctx.beginPath(); - // ctx.moveTo(0, textSize.actualBoundingBoxAscent + 2); - // ctx.lineTo(textSize.width, textSize.actualBoundingBoxAscent + 2); - // ctx.stroke(); - // } - // ctx.restore(); - // } - // else if (obj.orientation == 3 && obj.name_orientation == 0) - // { - // ctx.save(); - // ctx.translate(obj.x + margin_x, canvas.height - (obj.y + margin_y)); - // ctx.rotate(Math.PI/2); - // ctx.fillText(objName, 0, 0); - // if (inverted) - // { - // // todo: test this - // let textSize = ctx.measureText(objName); - // ctx.beginPath(); - // ctx.moveTo(0, textSize.actualBoundingBoxAscent + 2); - // ctx.lineTo(textSize.width, textSize.actualBoundingBoxAscent + 2); - // ctx.stroke(); - // } - // ctx.restore(); - // } - // else - // { - // ctx.fillText(objName, obj.x + margin_x, canvas.height - (obj.y + margin_y)); - // if (inverted) - // { - // let textSize = ctx.measureText(objName); - // let offset = 0; - // switch (ctx.textAlign) - // { - // case "center": - // offset = -(textSize.width/2); - // break; - // case "right": - // offset = -textSize.width; - // break; - // case "left": - // offset = 0; - // break; - // default: - // offset = 0; - // break; - // } - // ctx.beginPath(); - // ctx.moveTo(obj.x + margin_x + offset, canvas.height - (obj.y + margin_y + textSize.actualBoundingBoxAscent + 2)); - // ctx.lineTo(obj.x + margin_x + offset + textSize.width, canvas.height - (obj.y + margin_y + textSize.actualBoundingBoxAscent + 2)); - // ctx.stroke(); - // } - // } - - // ctx.setLineDash([]); - } - // ctx.textAlign = "left"; - // ctx.textBaseline = "bottom"; + // let savedFont = ctx.font; + for (let obj of doc.objects.filter((o) => o instanceof AltiumTextFrame)) + { + // if (!this.#shouldShow(obj)) continue; + + // if (obj.font_id > 0 && doc.sheet.fonts[obj.font_id] != null) + // { + // const frameFont = doc.sheet.fonts[obj.font_id]; + // const fontStr = (frameFont.size - 1).toString() + "px " + frameFont.name; + // if (fontStr.includes(":") || fontStr.includes("/") || !document.fonts.check(fontStr)) + // { + // ctx.font = savedFont; + // } + // else + // { + // ctx.font = fontStr; + // } + // } + + // ctx.fillStyle = this.#altiumColourToHex(obj.text_colour); + // ctx.textAlign = ["center", "left", "right"][obj.alignment]; + // let offset_x = [(obj.right-obj.left)/2, obj.text_margin, (obj.right-obj.left) - obj.text_margin][obj.alignment]; + // if (!obj.word_wrap) + // { + // ctx.fillText(obj.text.replaceAll("~1", "\n"), obj.left + offset_x, canvas.height - (obj.top + (obj.bottom-obj.top)/2)); + // } + // else + // { + // // todo: refactor this so that an initial pass figures out all the line splits, then a second pass writes the text, so that vertical alignment can be supported. + // const text = obj.text.replaceAll("~1", "\n"); + // const lines = text.split("\n"); + // let ypos = 0; + // if (lines.length > 1) + // { + // // this is a total hack, but if there are multiple lines in the text then we can make a rough guess at how far up we need to shift the text to center it vertically + // // this doesn't correct for line wraps (see todo above for refactoring approach) but it's at least something I guess! + // const roughMeasure = ctx.measureText(text); + // ypos = ((roughMeasure.fontBoundingBoxDescent + roughMeasure.fontBoundingBoxAscent) * -lines.length) / 2; + // } + // const maxWidth = (obj.right - obj.left) + (obj.text_margin * 2); + // for (let line of lines) + // { + // const lineMeasure = ctx.measureText(line); + // if (lineMeasure.width <= maxWidth) + // { + // ctx.fillText(line, obj.left + offset_x, (canvas.height - (obj.top + (obj.bottom-obj.top)/2)) + ypos); + // ypos += lineMeasure.fontBoundingBoxDescent + lineMeasure.fontBoundingBoxAscent; + // } + // else + // { + // let words = line.split(" "); + // while (words.length > 0) + // { + // if (words.length == 1) + // { + // // we only have one word, either because that's just how many we had or because the final word is super long + // const lastWord = words[0]; + // const lastWordMeasure = ctx.measureText(lastWord); + // ctx.fillText(lastWord, obj.left + offset_x, (canvas.height - (obj.top + (obj.bottom-obj.top)/2)) + ypos); + // ypos += lastWordMeasure.fontBoundingBoxDescent + lineMeasure.fontBoundingBoxAscent; + // words = []; + // break; + // } + // for (let wc = words.length; wc > 0; wc--) + // { + // const partialLine = words.slice(0, wc - 1).join(" "); + // const partialMeasure = ctx.measureText(partialLine); + // if (partialMeasure.width <= maxWidth || wc == 1) + // { + // ctx.fillText(partialLine, obj.left + offset_x, (canvas.height - (obj.top + (obj.bottom-obj.top)/2)) + ypos); + // ypos += partialMeasure.fontBoundingBoxDescent + lineMeasure.fontBoundingBoxAscent; + // words = words.slice(wc - 1); + // break; + // } + // } + // } + // } + // } + // } + } - for (let obj of doc.objects.filter((o) => o instanceof AltiumPowerPort)) - { - // if (!this.#shouldShow(obj)) continue; - - // if (!obj.show_text) - // continue; - // ctx.fillStyle = this.#altiumColourToHex(obj.colour); - // ctx.textBaseline = ["middle", "top", "middle", "bottom"][obj.orientation]; - // ctx.textAlign = ["left", "center", "right", "center"][obj.orientation]; - // let offset_x = [12, 0, -12, 0][obj.orientation]; - // let offset_y = [0, 20, 0, -20][obj.orientation]; - // ctx.fillText(obj.text, obj.x + offset_x, canvas.height - (obj.y + offset_y)); - } - - // ctx.textAlign = "left"; - // ctx.textBaseline = "middle"; - // let savedFont = ctx.font; - for (let obj of doc.objects.filter((o) => o instanceof AltiumTextFrame)) - { - // if (!this.#shouldShow(obj)) continue; - - // if (obj.font_id > 0 && doc.sheet.fonts[obj.font_id] != null) - // { - // const frameFont = doc.sheet.fonts[obj.font_id]; - // const fontStr = (frameFont.size - 1).toString() + "px " + frameFont.name; - // if (fontStr.includes(":") || fontStr.includes("/") || !document.fonts.check(fontStr)) - // { - // ctx.font = savedFont; - // } - // else - // { - // ctx.font = fontStr; - // } - // } - - // ctx.fillStyle = this.#altiumColourToHex(obj.text_colour); - // ctx.textAlign = ["center", "left", "right"][obj.alignment]; - // let offset_x = [(obj.right-obj.left)/2, obj.text_margin, (obj.right-obj.left) - obj.text_margin][obj.alignment]; - // if (!obj.word_wrap) - // { - // ctx.fillText(obj.text.replaceAll("~1", "\n"), obj.left + offset_x, canvas.height - (obj.top + (obj.bottom-obj.top)/2)); - // } - // else - // { - // // todo: refactor this so that an initial pass figures out all the line splits, then a second pass writes the text, so that vertical alignment can be supported. - // const text = obj.text.replaceAll("~1", "\n"); - // const lines = text.split("\n"); - // let ypos = 0; - // if (lines.length > 1) - // { - // // this is a total hack, but if there are multiple lines in the text then we can make a rough guess at how far up we need to shift the text to center it vertically - // // this doesn't correct for line wraps (see todo above for refactoring approach) but it's at least something I guess! - // const roughMeasure = ctx.measureText(text); - // ypos = ((roughMeasure.fontBoundingBoxDescent + roughMeasure.fontBoundingBoxAscent) * -lines.length) / 2; - // } - // const maxWidth = (obj.right - obj.left) + (obj.text_margin * 2); - // for (let line of lines) - // { - // const lineMeasure = ctx.measureText(line); - // if (lineMeasure.width <= maxWidth) - // { - // ctx.fillText(line, obj.left + offset_x, (canvas.height - (obj.top + (obj.bottom-obj.top)/2)) + ypos); - // ypos += lineMeasure.fontBoundingBoxDescent + lineMeasure.fontBoundingBoxAscent; - // } - // else - // { - // let words = line.split(" "); - // while (words.length > 0) - // { - // if (words.length == 1) - // { - // // we only have one word, either because that's just how many we had or because the final word is super long - // const lastWord = words[0]; - // const lastWordMeasure = ctx.measureText(lastWord); - // ctx.fillText(lastWord, obj.left + offset_x, (canvas.height - (obj.top + (obj.bottom-obj.top)/2)) + ypos); - // ypos += lastWordMeasure.fontBoundingBoxDescent + lineMeasure.fontBoundingBoxAscent; - // words = []; - // break; - // } - // for (let wc = words.length; wc > 0; wc--) - // { - // const partialLine = words.slice(0, wc - 1).join(" "); - // const partialMeasure = ctx.measureText(partialLine); - // if (partialMeasure.width <= maxWidth || wc == 1) - // { - // ctx.fillText(partialLine, obj.left + offset_x, (canvas.height - (obj.top + (obj.bottom-obj.top)/2)) + ypos); - // ypos += partialMeasure.fontBoundingBoxDescent + lineMeasure.fontBoundingBoxAscent; - // words = words.slice(wc - 1); - // break; - // } - // } - // } - // } - // } - // } - } - // ctx.font = savedFont; - - // ctx.textAlign = "left"; - // ctx.textBaseline = "bottom"; + for (let obj of doc.objects.filter((o) => o instanceof AltiumWire)) + { + let poi = [] + for (let i = 0; i < obj.points.length; i++) { + obj.points[i].y = 840 - obj.points[i].y + if((i != 0) &&(i != obj.points.length)){ + poi.push(new mxPoint(obj.points[i].x , obj.points[i].y)) + } + } - // ctx.setTransform(savedTransform); + var e6 = this.graph.insertEdge(parent, null, '') + e6.geometry.points = poi - // savedFont = ctx.font; - // ctx.textAlign = "left"; - // ctx.font = "bold 33px sans-serif"; - // ctx.fillStyle = "#000000"; - // ctx.globalAlpha = 0.2; - // ctx.save(); - // ctx.scale(1,-1); - // ctx.fillText("Preview generated by altium.js", 10, -(canvas.height - 50)); - // ctx.font = "bold 15px sans-serif"; - // ctx.fillText("for reference purposes only. schematic accuracy not guaranteed.", 12, -(canvas.height - 75)); - // ctx.restore(); - // ctx.globalAlpha = 1; - // ctx.font = savedFont; + e6.geometry.setTerminalPoint(new mxPoint(obj.points[0].x, obj.points[0].y), true) + + e6.geometry.setTerminalPoint(new mxPoint(obj.points[obj.points.length - 1].x, + obj.points[obj.points.length - 1].y), false) + + var obj1 = this.graph.getCellAt(obj.points[0].x,obj.points[0].y,parent) + var obj2 = this.graph.getCellAt(obj.points[obj.points.length - 1].x, + obj.points[obj.points.length - 1].y,parent) + for (let i in this.graph.model.cells){ + if(this.graph.model.cells[i].geometry != undefined){ + // + if((this.graph.model.cells[i].geometry['x'] == obj.points[0].x) + &&(this.graph.model.cells[i].geometry['y'] == obj.points[0].y)){ + console.log("find first") + console.log(this.graph.model.cells[i].geometry) + } + } + } + // if (!this.#shouldShow(obj)) continue; + + // ctx.strokeStyle = this.#altiumColourToHex(obj.colour); + // ctx.lineWidth = obj.width; + // ctx.beginPath(); + // ctx.moveTo(obj.points[0].x, obj.points[0].y); + // for (let i = 1; i < obj.points.length; i++) + // { + // ctx.lineTo(obj.points[i].x, obj.points[i].y); + // } + // ctx.stroke(); + } + } + finally{ + this.graph.getModel().endUpdate(); + } + // ctx.font = savedFont; + + // ctx.textAlign = "left"; + // ctx.textBaseline = "bottom"; + + // ctx.setTransform(savedTransform); + + // savedFont = ctx.font; + // ctx.textAlign = "left"; + // ctx.font = "bold 33px sans-serif"; + // ctx.fillStyle = "#000000"; + // ctx.globalAlpha = 0.2; + // ctx.save(); + // ctx.scale(1,-1); + // ctx.fillText("Preview generated by altium.js", 10, -(canvas.height - 50)); + // ctx.font = "bold 15px sans-serif"; + // ctx.fillText("for reference purposes only. schematic accuracy not guaranteed.", 12, -(canvas.height - 75)); + // ctx.restore(); + // ctx.globalAlpha = 1; + // ctx.font = savedFont; } } \ No newline at end of file