Compare commits

..

2 Commits

Author SHA1 Message Date
zcy 4d4ac37e73 添加polygon 2024-03-08 00:28:47 +08:00
zcy abfa05d9d8 添加label和polygon 2024-03-08 00:28:17 +08:00
3 changed files with 125 additions and 13 deletions

View File

@ -63,12 +63,12 @@ class AltiumSchematicRenderer
render() {
let oldMove = mxGraphHandler.prototype.mouseMove
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
if (!this.livePreviewUsed && this.shape == null) {
this.shape = this.createPreviewShape(this.bounds);
}else if(this.shape != null){
console.log("mouseMove",this)
// console.log("mouseMove",this)
}
oldMove.call(this, sender, me);
}
@ -103,6 +103,9 @@ class AltiumSchematicRenderer
};
this.graph = new mxGraph(document.getElementById('graphContainer'));
this.graph.setPanning(true);
this.graph.setConnectable(true);
this.graph.setConnectableEdges(true);
@ -208,6 +211,8 @@ class AltiumSchematicRenderer
style['movable'] = '0';
style['strokeWidth'] = strokeWidth;
style['rounded'] = '0';
style[mxConstants.STYLE_FONTSIZE] = '11';
// Sets join node size
style['startSize'] = joinNodeSize;
@ -220,7 +225,7 @@ class AltiumSchematicRenderer
style['fillColor'] = 'none';
style['fontColor'] = fontColor;
style['fontStyle'] = '1';
style['fontSize'] = '12';
style['fontSize'] = '6';
style['resizable'] = '0';
style['strokeWidth'] = strokeWidth;
// let canvas = this.canvas;
@ -444,6 +449,7 @@ class AltiumSchematicRenderer
for (let obj of doc.objects.filter((o) => o instanceof AltiumTextFrame))
{
obj = obj
// if (!this.#shouldShow(obj)) continue;
// if (!obj.transparent)
@ -462,6 +468,8 @@ class AltiumSchematicRenderer
for (let obj of doc.objects.filter((o) => o instanceof AltiumEllipse))
{
obj = obj
// if (!this.#shouldShow(obj)) continue;
// if (!obj.transparent)
@ -478,12 +486,20 @@ class AltiumSchematicRenderer
for (let obj of doc.objects.filter((o) => o instanceof AltiumPin))
{
var style = 'shape=line;fontColor=#000000;strokeColor=#000000;'
let name = ''
if(obj.show_name){
name = obj.name
}
if(obj.angle == 0){
style = style + 'labelPosition=left;'
}
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){
style = style + 'labelPosition=right;'
obj.x = obj.x - obj.length
}
if(obj.angle == 270){
@ -494,7 +510,7 @@ class AltiumSchematicRenderer
obj.y = 840 - obj.y
// console.log(style)
var v11 = this.graph.insertVertex(parent, null, '', obj.x, obj.y,
var v11 = this.graph.insertVertex(parent, null, name, obj.x, obj.y,
obj.length, 1,
style);
v11.geometry.relative = false;
@ -562,6 +578,8 @@ class AltiumSchematicRenderer
for (let obj of doc.objects.filter((o) => o instanceof AltiumArc))
{
obj = obj
// if (!this.#shouldShow(obj)) continue;
// ctx.strokeStyle = this.#altiumColourToHex(obj.colour);
@ -575,7 +593,26 @@ class AltiumSchematicRenderer
for (let obj of doc.objects.filter((o) => o instanceof AltiumPolygon))
{
obj = obj
mxCellRenderer.registerShape('polygon', mxPolygon);
obj.x2 = 840 - obj.x2
obj.y2 = 840 - obj.y2
style = 'shape=polygon;strokeColor=#0000ff;'
// console.log(style)
var v11 = this.graph.insertVertex(parent, null, '', obj.points[0], obj.points[0],
1,1,style);
v11.points = obj.obj.points
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)
// if (!this.#shouldShow(obj)) continue;
// ctx.strokeStyle = this.#altiumColourToHex(obj.line_colour);
@ -595,6 +632,7 @@ class AltiumSchematicRenderer
for (let obj of doc.objects.filter((o) => o instanceof AltiumJunction))
{
obj = obj
// if (!this.#shouldShow(obj)) continue;
@ -701,13 +739,17 @@ class AltiumSchematicRenderer
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");
if(obj.text != undefined){
console.log(obj.text.length)
var v11 = this.graph.insertVertex(parent, null, obj.text, obj.x, obj.y - 4,
obj.text.length*9/2, 0,
"shape=label;fontSize=9;");
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;
@ -727,6 +769,18 @@ class AltiumSchematicRenderer
for (let obj of doc.objects.filter((o) => o instanceof AltiumDesignator))
{
obj = obj
obj.y = 840 - obj.y
if(obj.text != undefined){
console.log(obj.text.length)
var v11 = this.graph.insertVertex(parent, null, obj.text, obj.x, obj.y - 4,
obj.text.length*9/2, 0,
"shape=label;fontSize=9;");
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 (obj.hidden)
@ -919,7 +973,6 @@ class AltiumSchematicRenderer
e6.geometry.points = poi
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)

View File

@ -693,6 +693,8 @@ if (mxForceIncludes || !(typeof module === 'object' && module.exports != null))
mxClient.include(mxClient.basePath+'/js/shape/mxStencilRegistry.js');
mxClient.include(mxClient.basePath+'/js/shape/mxMarker.js');
mxClient.include(mxClient.basePath+'/js/shape/mxActor.js');
mxClient.include(mxClient.basePath+'/js/shape/mxPolygon.js');
mxClient.include(mxClient.basePath+'/js/shape/mxCloud.js');
mxClient.include(mxClient.basePath+'/js/shape/mxRectangleShape.js');
mxClient.include(mxClient.basePath+'/js/shape/mxEllipse.js');

View File

@ -0,0 +1,57 @@
/**
* Copyright (c) 2006-2015, JGraph Ltd
* Copyright (c) 2006-2015, Gaudenz Alder
*/
/**
* Class: mxTriangle
*
* Implementation of the triangle shape.
*
* Constructor: mxTriangle
*
* Constructs a new triangle shape.
*/
function mxPolygon()
{
mxActor.call(this);
};
/**
* Extends mxActor.
*/
mxUtils.extend(mxPolygon, mxActor);
/**
* Function: isRoundable
*
* Adds roundable support.
*/
mxPolygon.prototype.isRoundable = function()
{
return true;
};
// /**
// * Function: redrawPath
// *
// * Draws the path for this shape.
// */
// mxPolygon.prototype.redrawPath = function(c, x, y, w, h)
// {
// var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
// this.addPoints(c, [new mxPoint(0, 0), new mxPoint(w, 0.5 * h), new mxPoint(0, h)], this.isRounded, 23, true);
// };
mxPolygon.prototype.paintVertexShape = function(c, x, y, w, h)
{
console.log(this.state.cell)
let poi = this.state.cell.points
c.begin();
c.moveTo(x,y);
for(let i = 0;i < poi.length;i++){
c.lineTo(poi[i].x,poi[i].y);
}
c.lineTo(x,y);
c.close()
c.fillAndStroke();
};