添加鼠标监听事件 解决rectangle 随着鼠标移动
parent
54b7322916
commit
8226dd09f8
|
@ -61,6 +61,9 @@ class AltiumSchematicRenderer
|
|||
}
|
||||
|
||||
initGraph() {
|
||||
|
||||
|
||||
|
||||
this.graph = new mxGraph(document.getElementById('graphContainer'));
|
||||
this.graph.setPanning(true);
|
||||
this.graph.setConnectable(true);
|
||||
|
@ -86,6 +89,13 @@ class AltiumSchematicRenderer
|
|||
|
||||
mxVertexHandler.prototype.rotationEnabled = true;
|
||||
|
||||
this.graph.addListener(mxEvent.DOUBLE_CLICK, function(sender, evt)
|
||||
{
|
||||
var cell = evt.getProperty('cell');
|
||||
// do something with the cell and consume the
|
||||
// event to prevent in-place editing from start
|
||||
});
|
||||
|
||||
// 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.
|
||||
|
@ -157,6 +167,29 @@ class AltiumSchematicRenderer
|
|||
}
|
||||
|
||||
render() {
|
||||
mxGraphHandler.prototype.mouseMove = function(sender, me){
|
||||
console.log(sender,me)
|
||||
// https://github.com/jgraph/mxgraph/blob/master/javascript/src/js/handler/mxGraphHandler.js#L901
|
||||
if (!this.livePreviewUsed && this.shape == null) {
|
||||
this.shape = this.createPreviewShape(this.bounds);
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/jgraph/mxgraph/blob/master/javascript/src/js/handler/mxGraphHandler.js#L1036
|
||||
mxGraphHandler.prototype.updatePreview = function(remote) {
|
||||
if (this.livePreviewUsed && !remote) {
|
||||
if (this.cells != null)
|
||||
{
|
||||
this.setHandlesVisibleForCells(this.graph.getSelectionCells(), false);
|
||||
this.updateLivePreview(this.currentDx, this.currentDy);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.updatePreviewShape();
|
||||
}
|
||||
};
|
||||
|
||||
this.graph = new mxGraph(document.getElementById('graphContainer'));
|
||||
this.graph.setPanning(true);
|
||||
this.graph.setConnectable(true);
|
||||
|
@ -180,6 +213,41 @@ class AltiumSchematicRenderer
|
|||
// Adds rubberband selection
|
||||
new mxRubberband(this.graph);
|
||||
|
||||
this.graph.addListener(mxEvent.CLICK, function(sender, evt)
|
||||
{
|
||||
var e = evt.getProperty('event'); // mouse event
|
||||
var cell = evt.getProperty('cell'); // cell may be null
|
||||
|
||||
if (cell != null)
|
||||
{
|
||||
// Do something useful with cell and consume the event
|
||||
// evt.consume();
|
||||
}
|
||||
});
|
||||
|
||||
var connectionHandlerMouseUp = this.graph.connectionHandler.mouseUp;
|
||||
this.graph.connectionHandler.mouseUp = function(sender, me)
|
||||
{
|
||||
if (this.first != null && this.previous != null)
|
||||
{
|
||||
var point = mxUtils.convertPoint(this.graph.container, me.getX(), me.getY());
|
||||
var dx = Math.abs(point.x - this.first.x);
|
||||
var dy = Math.abs(point.y - this.first.y);
|
||||
|
||||
if (dx < this.graph.tolerance && dy < this.graph.tolerance)
|
||||
{
|
||||
// Selects edges in non-wire mode for single clicks, but starts
|
||||
// connecting for non-edges regardless of wire-mode
|
||||
console.log("sss")
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
connectionHandlerMouseUp.apply(this, arguments);
|
||||
};
|
||||
|
||||
|
||||
mxVertexHandler.prototype.rotationEnabled = true;
|
||||
|
||||
// Alternative solution for implementing connection points without child cells.
|
||||
|
@ -344,29 +412,29 @@ class AltiumSchematicRenderer
|
|||
}
|
||||
results.innerText = bom.join("\n");
|
||||
|
||||
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 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)
|
||||
|
||||
console.log(obj1,obj2)
|
||||
// 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();
|
||||
}
|
||||
// // 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;
|
||||
|
@ -416,7 +484,6 @@ class AltiumSchematicRenderer
|
|||
// ctx.stroke();
|
||||
}
|
||||
let chips = {}
|
||||
var v1
|
||||
for (let obj of doc.objects.filter((o) => o instanceof AltiumRectangle))
|
||||
{
|
||||
obj.top = 840 - obj.top
|
||||
|
@ -424,7 +491,7 @@ class AltiumSchematicRenderer
|
|||
|
||||
console.log('verticalLabelPosition=top;verticalAlign=bottom;fillColor='
|
||||
+ this.#altiumColourToHex(obj.attributes.areacolor))
|
||||
v1 = this.graph.insertVertex(parent, null, '',
|
||||
let v1 = this.graph.insertVertex(parent, null, '',
|
||||
obj.left, obj.top,
|
||||
(obj.right - obj.left),
|
||||
(obj.bottom - obj.top),
|
||||
|
@ -434,9 +501,10 @@ class AltiumSchematicRenderer
|
|||
if(chips[obj.owner_record_index] == undefined){
|
||||
chips[obj.owner_record_index] = []
|
||||
}
|
||||
v1.geometry.relative = false
|
||||
chips[obj.owner_record_index].push(v1)
|
||||
|
||||
// if (!this.#shouldShow(obj))
|
||||
// if (!this.#shouldShow(obj))
|
||||
// continue;
|
||||
// ctx.fillStyle = this.#altiumColourToHex(obj.attributes.areacolor);
|
||||
|
||||
|
@ -530,6 +598,7 @@ class AltiumSchematicRenderer
|
|||
chips[obj.owner_record_index] = []
|
||||
}
|
||||
chips[obj.owner_record_index].push(v11)
|
||||
|
||||
// v11.geometry.offset = new mxPoint(-v11.geometry.width, 2); // ctx.strokeStyle = "#000000";
|
||||
// ctx.beginPath();
|
||||
// ctx.moveTo(obj.x, obj.y);
|
||||
|
@ -1104,9 +1173,7 @@ class AltiumSchematicRenderer
|
|||
}
|
||||
for (let i in chips){
|
||||
let chip = this.graph.groupCells(null,0,chips[i])
|
||||
chip.setStyle("border = 0")
|
||||
console.log(chip.getStyle())
|
||||
console.log(chip.getStyle())
|
||||
chip.setStyle("border=0;strokeColor=none")
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue