添加polygon shape
parent
254d4df203
commit
aec7de62d4
|
@ -63,10 +63,12 @@ class AltiumSchematicRenderer
|
||||||
render() {
|
render() {
|
||||||
let oldMove = mxGraphHandler.prototype.mouseMove
|
let oldMove = mxGraphHandler.prototype.mouseMove
|
||||||
mxGraphHandler.prototype.mouseMove = function(sender, me){
|
mxGraphHandler.prototype.mouseMove = function(sender, me){
|
||||||
// console.log("mouse move",sender,me)
|
console.log("mouse move",sender,me)
|
||||||
// https://github.com/jgraph/mxgraph/blob/master/javascript/src/js/handler/mxGraphHandler.js#L901
|
// https://github.com/jgraph/mxgraph/blob/master/javascript/src/js/handler/mxGraphHandler.js#L901
|
||||||
if (!this.livePreviewUsed && this.shape == null) {
|
if (!this.livePreviewUsed && this.shape == null) {
|
||||||
this.shape = this.createPreviewShape(this.bounds);
|
this.shape = this.createPreviewShape(this.bounds);
|
||||||
|
}else if(this.shape != null){
|
||||||
|
console.log("mouseMove",this)
|
||||||
}
|
}
|
||||||
oldMove.call(this, sender, me);
|
oldMove.call(this, sender, me);
|
||||||
}
|
}
|
||||||
|
@ -108,7 +110,7 @@ class AltiumSchematicRenderer
|
||||||
this.graph.foldingEnabled = false;
|
this.graph.foldingEnabled = false;
|
||||||
this.graph.gridSize = 1
|
this.graph.gridSize = 1
|
||||||
//Maximum size
|
//Maximum size
|
||||||
this.graph.maximumGraphBounds = new mxRectangle(0, 0, 1920, 800)
|
this.graph.maximumGraphBounds = new mxRectangle(0, 0, 1920, 1024)
|
||||||
this.graph.border = 0;
|
this.graph.border = 0;
|
||||||
var fontColor = '#FFFFFF' ;
|
var fontColor = '#FFFFFF' ;
|
||||||
var strokeColor = '#C0C0C0' ;
|
var strokeColor = '#C0C0C0' ;
|
||||||
|
@ -153,12 +155,10 @@ class AltiumSchematicRenderer
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connectionHandlerMouseUp.apply(this, arguments);
|
connectionHandlerMouseUp.apply(this, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mxVertexHandler.prototype.rotationEnabled = false;
|
||||||
mxVertexHandler.prototype.rotationEnabled = true;
|
|
||||||
|
|
||||||
// Alternative solution for implementing connection points without child cells.
|
// Alternative solution for implementing connection points without child cells.
|
||||||
// This can be extended as shown in portrefs.html example to allow for per-port
|
// This can be extended as shown in portrefs.html example to allow for per-port
|
||||||
|
@ -191,7 +191,6 @@ class AltiumSchematicRenderer
|
||||||
|
|
||||||
var parent = this.graph.getDefaultParent();
|
var parent = this.graph.getDefaultParent();
|
||||||
mxVertexHandler.prototype.livePreview = true;
|
mxVertexHandler.prototype.livePreview = true;
|
||||||
mxVertexHandler.prototype.rotationEnabled = true;
|
|
||||||
|
|
||||||
var labelBackground = (false) ? '#000000' : '#FFFFFF';
|
var labelBackground = (false) ? '#000000' : '#FFFFFF';
|
||||||
var fontColor = (false) ? '#FFFFFF' : '#000000';
|
var fontColor = (false) ? '#FFFFFF' : '#000000';
|
||||||
|
@ -476,7 +475,6 @@ class AltiumSchematicRenderer
|
||||||
// if (!obj.transparent)
|
// if (!obj.transparent)
|
||||||
// ctx.fill();
|
// ctx.fill();
|
||||||
}
|
}
|
||||||
console.log(doc.objects)
|
|
||||||
for (let obj of doc.objects.filter((o) => o instanceof AltiumPin))
|
for (let obj of doc.objects.filter((o) => o instanceof AltiumPin))
|
||||||
{
|
{
|
||||||
var style = 'shape=line;fontColor=#000000;strokeColor=#000000;'
|
var style = 'shape=line;fontColor=#000000;strokeColor=#000000;'
|
||||||
|
@ -492,7 +490,6 @@ class AltiumSchematicRenderer
|
||||||
style += 'rotation=90'
|
style += 'rotation=90'
|
||||||
obj.y = obj.y - obj.length/2
|
obj.y = obj.y - obj.length/2
|
||||||
obj.x = obj.x - obj.length/2
|
obj.x = obj.x - obj.length/2
|
||||||
|
|
||||||
}
|
}
|
||||||
obj.y = 840 - obj.y
|
obj.y = 840 - obj.y
|
||||||
|
|
||||||
|
@ -521,19 +518,35 @@ class AltiumSchematicRenderer
|
||||||
|
|
||||||
|
|
||||||
for (let obj of doc.objects.filter((o) => o instanceof AltiumLine)) {
|
for (let obj of doc.objects.filter((o) => o instanceof AltiumLine)) {
|
||||||
|
mxCellRenderer.registerShape('polyline', mxPolyline);
|
||||||
obj.x2 = 840 - obj.x2
|
obj.x2 = 840 - obj.x2
|
||||||
obj.y2 = 840 - obj.y2
|
obj.y2 = 840 - obj.y2
|
||||||
const cell = new mxCell('', new mxGeometry(), 'strokeWidth=1;');
|
style = 'shape=polyline;strokeColor=#0000ff;'
|
||||||
|
// console.log(style)
|
||||||
|
var v11 = this.graph.insertVertex(parent, null, '', obj.x1, obj.x2,
|
||||||
|
1,1,style);
|
||||||
|
v11.points = [new mxPoint(obj.y1 - obj.x1,obj.y2 - obj.x2)]
|
||||||
|
v11.geometry.relative = false;
|
||||||
|
if(chips[obj.owner_record_index] == undefined){
|
||||||
|
chips[obj.owner_record_index] = []
|
||||||
|
}
|
||||||
|
if(chips[obj.owner_record_index] == undefined){
|
||||||
|
chips[obj.owner_record_index] = []
|
||||||
|
}
|
||||||
|
v11.setConnectable(false);
|
||||||
|
|
||||||
|
chips[obj.owner_record_index].push(v11)
|
||||||
|
|
||||||
// 将cell设定为线段
|
// 将cell设定为线段
|
||||||
// cell.edge = true;
|
// cell.edge = true;
|
||||||
|
|
||||||
|
|
||||||
// 设置起始点
|
// 设置起始点
|
||||||
cell.geometry.setTerminalPoint(new mxPoint(obj.x1, obj.x2), true);
|
// cell.geometry.setTerminalPoint(new mxPoint(obj.x1, obj.x2), true);
|
||||||
// 设置终结点
|
// 设置终结点
|
||||||
cell.geometry.setTerminalPoint(new mxPoint(obj.y1, obj.y2), false);
|
// cell.geometry.setTerminalPoint(new mxPoint(obj.y1, obj.y2), false);
|
||||||
// 使用 points 定义多个中间节点
|
// 使用 points 定义多个中间节点
|
||||||
this.graph.model.root.insert(cell);
|
// this.graph.model.root.insert(cell);
|
||||||
|
|
||||||
// this.graph.model.root.insert(cell);
|
// this.graph.model.root.insert(cell);
|
||||||
// chips[obj.owner_record_index].push(cell)
|
// chips[obj.owner_record_index].push(cell)
|
||||||
|
@ -559,86 +572,10 @@ class AltiumSchematicRenderer
|
||||||
// ctx.lineWidth = 1;
|
// 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))
|
for (let obj of doc.objects.filter((o) => o instanceof AltiumPolygon))
|
||||||
{
|
{
|
||||||
|
|
||||||
// if (!this.#shouldShow(obj)) continue;
|
// if (!this.#shouldShow(obj)) continue;
|
||||||
|
|
||||||
// ctx.strokeStyle = this.#altiumColourToHex(obj.line_colour);
|
// ctx.strokeStyle = this.#altiumColourToHex(obj.line_colour);
|
||||||
|
@ -658,6 +595,7 @@ class AltiumSchematicRenderer
|
||||||
|
|
||||||
for (let obj of doc.objects.filter((o) => o instanceof AltiumJunction))
|
for (let obj of doc.objects.filter((o) => o instanceof AltiumJunction))
|
||||||
{
|
{
|
||||||
|
|
||||||
// if (!this.#shouldShow(obj)) continue;
|
// if (!this.#shouldShow(obj)) continue;
|
||||||
|
|
||||||
// ctx.fillStyle = this.#altiumColourToHex(obj.colour);
|
// ctx.fillStyle = this.#altiumColourToHex(obj.colour);
|
||||||
|
@ -668,6 +606,7 @@ class AltiumSchematicRenderer
|
||||||
|
|
||||||
for (let obj of doc.objects.filter((o) => o instanceof AltiumPowerPort))
|
for (let obj of doc.objects.filter((o) => o instanceof AltiumPowerPort))
|
||||||
{
|
{
|
||||||
|
|
||||||
// if (!this.#shouldShow(obj)) continue;
|
// if (!this.#shouldShow(obj)) continue;
|
||||||
|
|
||||||
// ctx.strokeStyle = this.#altiumColourToHex(obj.colour);
|
// ctx.strokeStyle = this.#altiumColourToHex(obj.colour);
|
||||||
|
@ -761,6 +700,15 @@ class AltiumSchematicRenderer
|
||||||
|
|
||||||
for (let obj of doc.objects.filter((o) => o instanceof AltiumLabel))
|
for (let obj of doc.objects.filter((o) => o instanceof AltiumLabel))
|
||||||
{
|
{
|
||||||
|
obj.y = 840 - obj.y
|
||||||
|
var v11 = this.graph.insertVertex(parent, null, obj.text, obj.x, obj.y,
|
||||||
|
0, 0,
|
||||||
|
"shape=label");
|
||||||
|
v11.geometry.relative = false;
|
||||||
|
v11.setConnectable(false);
|
||||||
|
if(obj.owner_record_index != 1)
|
||||||
|
chips[obj.owner_record_index].push(v11)
|
||||||
|
|
||||||
// if (!this.#shouldShow(obj)) continue;
|
// if (!this.#shouldShow(obj)) continue;
|
||||||
|
|
||||||
// if (obj.hidden)
|
// if (obj.hidden)
|
||||||
|
@ -791,8 +739,7 @@ class AltiumSchematicRenderer
|
||||||
// ctx.textAlign = "left";
|
// ctx.textAlign = "left";
|
||||||
// ctx.textBaseline = "bottom";
|
// ctx.textBaseline = "bottom";
|
||||||
|
|
||||||
for (let obj of doc.objects.filter((o) => o instanceof AltiumParameter))
|
for (let obj of doc.objects.filter((o) => o instanceof AltiumParameter)) {
|
||||||
{
|
|
||||||
// if (!this.#shouldShow(obj)) continue;
|
// if (!this.#shouldShow(obj)) continue;
|
||||||
|
|
||||||
// if (obj.hidden || obj.is_implementation_parameter)
|
// if (obj.hidden || obj.is_implementation_parameter)
|
||||||
|
@ -825,8 +772,8 @@ class AltiumSchematicRenderer
|
||||||
// ctx.textAlign = "left";
|
// ctx.textAlign = "left";
|
||||||
// ctx.textBaseline = "bottom";
|
// ctx.textBaseline = "bottom";
|
||||||
|
|
||||||
for (let obj of doc.objects.filter((o) => o instanceof AltiumNetLabel))
|
for (let obj of doc.objects.filter((o) => o instanceof AltiumNetLabel)) {
|
||||||
{
|
obj = obj
|
||||||
// if (!this.#shouldShow(obj)) continue;
|
// if (!this.#shouldShow(obj)) continue;
|
||||||
|
|
||||||
// if (obj.hidden)
|
// if (obj.hidden)
|
||||||
|
@ -862,8 +809,8 @@ class AltiumSchematicRenderer
|
||||||
// ctx.textAlign = "left";
|
// ctx.textAlign = "left";
|
||||||
// ctx.textBaseline = "bottom";
|
// ctx.textBaseline = "bottom";
|
||||||
|
|
||||||
for (let obj of doc.objects.filter((o) => o instanceof AltiumPowerPort))
|
for (let obj of doc.objects.filter((o) => o instanceof AltiumPowerPort)) {
|
||||||
{
|
obj = obj
|
||||||
// if (!this.#shouldShow(obj)) continue;
|
// if (!this.#shouldShow(obj)) continue;
|
||||||
|
|
||||||
// if (!obj.show_text)
|
// if (!obj.show_text)
|
||||||
|
@ -879,8 +826,7 @@ class AltiumSchematicRenderer
|
||||||
// ctx.textAlign = "left";
|
// ctx.textAlign = "left";
|
||||||
// ctx.textBaseline = "middle";
|
// ctx.textBaseline = "middle";
|
||||||
// let savedFont = ctx.font;
|
// let savedFont = ctx.font;
|
||||||
for (let obj of doc.objects.filter((o) => o instanceof AltiumTextFrame))
|
for (let obj of doc.objects.filter((o) => o instanceof AltiumTextFrame)) {
|
||||||
{
|
|
||||||
// if (!this.#shouldShow(obj)) continue;
|
// if (!this.#shouldShow(obj)) continue;
|
||||||
|
|
||||||
// if (obj.font_id > 0 && doc.sheet.fonts[obj.font_id] != null)
|
// if (obj.font_id > 0 && doc.sheet.fonts[obj.font_id] != null)
|
||||||
|
@ -1005,7 +951,6 @@ class AltiumSchematicRenderer
|
||||||
for (let i in chips){
|
for (let i in chips){
|
||||||
let chip = this.graph.groupCells(null,0,chips[i])
|
let chip = this.graph.groupCells(null,0,chips[i])
|
||||||
chip.setStyle("border=0;strokeColor=none")
|
chip.setStyle("border=0;strokeColor=none")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally{
|
finally{
|
||||||
|
|
|
@ -1253,7 +1253,8 @@ mxConnectionHandler.prototype.mouseMove = function(sender, me)
|
||||||
var tr = view.translate;
|
var tr = view.translate;
|
||||||
var point = new mxPoint(me.getGraphX(), me.getGraphY());
|
var point = new mxPoint(me.getGraphX(), me.getGraphY());
|
||||||
this.error = null;
|
this.error = null;
|
||||||
|
|
||||||
|
// 修正到grid
|
||||||
if (this.graph.isGridEnabledEvent(me.getEvent()))
|
if (this.graph.isGridEnabledEvent(me.getEvent()))
|
||||||
{
|
{
|
||||||
point = new mxPoint((this.graph.snap(point.x / scale - tr.x) + tr.x) * scale,
|
point = new mxPoint((this.graph.snap(point.x / scale - tr.x) + tr.x) * scale,
|
||||||
|
|
|
@ -74,7 +74,6 @@ mxPolyline.prototype.paintEdgeShape = function(c, pts)
|
||||||
{
|
{
|
||||||
var prev = c.pointerEventsValue;
|
var prev = c.pointerEventsValue;
|
||||||
c.pointerEventsValue = 'stroke';
|
c.pointerEventsValue = 'stroke';
|
||||||
|
|
||||||
if (this.style == null || this.style[mxConstants.STYLE_CURVED] != 1)
|
if (this.style == null || this.style[mxConstants.STYLE_CURVED] != 1)
|
||||||
{
|
{
|
||||||
this.paintLine(c, pts, this.isRounded);
|
this.paintLine(c, pts, this.isRounded);
|
||||||
|
@ -130,3 +129,14 @@ mxPolyline.prototype.paintCurvedLine = function(c, pts)
|
||||||
c.quadTo(p0.x, p0.y, p1.x, p1.y);
|
c.quadTo(p0.x, p0.y, p1.x, p1.y);
|
||||||
c.stroke();
|
c.stroke();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 修改 polyline原本无法渲染vertex类型,只能渲染edge
|
||||||
|
//
|
||||||
|
mxPolyline.prototype.paintVertexShape = function(c, x, y, w, h)
|
||||||
|
{
|
||||||
|
console.log("paintVertexShape",this.state.cell.geometry.x,this.state.cell.geometry.y,this.state.cell.points[0])
|
||||||
|
c.begin();
|
||||||
|
c.moveTo(x,y);
|
||||||
|
c.lineTo(x + this.state.cell.points[0].x,y + this.state.cell.points[0].y);
|
||||||
|
c.stroke();
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue