123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- /**
- * $Id: mxElectrical.js,v 1.0 2016/10/25 17:05:39 mate Exp $
- * Copyright (c) 2006-2016, JGraph Ltd
- */
- //**********************************************************************************************************************************************************
- //Test Point
- //**********************************************************************************************************************************************************
- /**
- * Extends mxShape.
- */
- function mxShapeElectricalTestPoint(bounds, fill, stroke, strokewidth)
- {
- mxShape.call(this);
- this.bounds = bounds;
- this.fill = fill;
- this.stroke = stroke;
- this.strokewidth = (strokewidth != null) ? strokewidth : 1;
- };
- /**
- * Extends mxShape.
- */
- mxUtils.extend(mxShapeElectricalTestPoint, mxShape);
- mxShapeElectricalTestPoint.prototype.cst = {
- SHAPE_TEST_POINT : 'mxgraph.electrical.transmission.testPoint'
- };
- /**
- * Function: paintVertexShape
- *
- * Paints the vertex shape.
- */
- mxShapeElectricalTestPoint.prototype.paintVertexShape = function(c, x, y, w, h)
- {
- c.translate(x, y);
- var strokeColor = mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, '#000000');
- var size = Math.min(w, h);
-
- c.setFillColor(strokeColor);
- c.begin();
- c.ellipse(w * 0.5 - size / 2, 0, size, size);
- c.fillAndStroke();
-
- if (h > w)
- {
- c.begin();
- c.moveTo(w * 0.5, size);
- c.lineTo(w * 0.5, h);
- c.stroke();
- }
- };
- mxCellRenderer.prototype.defaultShapes[mxShapeElectricalTestPoint.prototype.cst.SHAPE_TEST_POINT] = mxShapeElectricalTestPoint;
- mxShapeElectricalTestPoint.prototype.constraints = [
- new mxConnectionConstraint(new mxPoint(0.5, 0), true),
- new mxConnectionConstraint(new mxPoint(0.5, 1), true)
- ];
- //**********************************************************************************************************************************************************
- //Straight Bus
- //**********************************************************************************************************************************************************
- /**
- * Extends mxShape.
- */
- function mxShapeElectricalStraightBus(bounds, fill, stroke, strokewidth)
- {
- mxShape.call(this);
- this.bounds = bounds;
- this.fill = fill;
- this.stroke = stroke;
- this.strokewidth = (strokewidth != null) ? strokewidth : 1;
- };
- /**
- * Extends mxShape.
- */
- mxUtils.extend(mxShapeElectricalStraightBus, mxShape);
- mxShapeElectricalStraightBus.prototype.cst = {
- SHAPE_STRAIGHT_BUS : 'mxgraph.electrical.transmission.straightBus'
- };
- /**
- * Function: paintVertexShape
- *
- * Paints the vertex shape.
- */
- mxShapeElectricalStraightBus.prototype.paintVertexShape = function(c, x, y, w, h)
- {
- c.translate(x, y);
- var size = Math.min(w, h);
- var x1 = w * 0.2;
- var y1 = 0;
-
- if (w > h)
- {
- y1 = h * 0.5;
- }
- else
- {
- y1 = w / 2;
- }
-
- c.begin();
- c.moveTo(w - x1, 0);
- c.lineTo(w - x1, h - y1);
- c.lineTo(w, h - y1);
- c.lineTo(w * 0.5, h);
- c.lineTo(0, h - y1);
- c.lineTo(x1, h - y1);
- c.lineTo(x1, 0);
- c.fillAndStroke();
- };
- mxCellRenderer.prototype.defaultShapes[mxShapeElectricalStraightBus.prototype.cst.SHAPE_STRAIGHT_BUS] = mxShapeElectricalStraightBus;
- mxShapeElectricalStraightBus.prototype.constraints = [
- new mxConnectionConstraint(new mxPoint(0.5, 0), true),
- new mxConnectionConstraint(new mxPoint(0.5, 1), true)
- ];
- //**********************************************************************************************************************************************************
- //Two-Line Bus Elbow
- //**********************************************************************************************************************************************************
- /**
- * Extends mxShape.
- */
- function mxShapeElectricalTwoLineBusElbow(bounds, fill, stroke, strokewidth)
- {
- mxShape.call(this);
- this.bounds = bounds;
- this.fill = fill;
- this.stroke = stroke;
- this.strokewidth = (strokewidth != null) ? strokewidth : 1;
- this.notch = 0;
- };
- /**
- * Extends mxShape.
- */
- mxUtils.extend(mxShapeElectricalTwoLineBusElbow, mxShape);
- mxShapeElectricalTwoLineBusElbow.prototype.cst = {
- SHAPE_TWO_LINE_BUS_ELBOW : 'mxgraph.electrical.transmission.twoLineBusElbow'
- };
- /**
- * Function: paintVertexShape
- *
- * Paints the vertex shape.
- */
- mxShapeElectricalTwoLineBusElbow.prototype.paintVertexShape = function(c, x, y, w, h)
- {
- var notch = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'notch', this.notch))));
- c.translate(x, y);
- c.begin();
- c.moveTo(0, h);
- c.lineTo(w, h);
- c.lineTo(w, 0);
- c.stroke();
-
- var wn = Math.min(w, notch);
- var hn = Math.min(h, notch);
-
- c.begin();
- c.moveTo(0, h - hn);
- c.lineTo(w - wn, h - hn);
- c.lineTo(w - wn, 0);
- c.stroke();
- };
- mxCellRenderer.prototype.defaultShapes[mxShapeElectricalTwoLineBusElbow.prototype.cst.SHAPE_TWO_LINE_BUS_ELBOW] = mxShapeElectricalTwoLineBusElbow;
- mxShapeElectricalTwoLineBusElbow.prototype.constraints = null;
- Graph.handleFactory[mxShapeElectricalTwoLineBusElbow.prototype.cst.SHAPE_TWO_LINE_BUS_ELBOW] = function(state)
- {
- var handles = [Graph.createHandle(state, ['notch'], function(bounds)
- {
- var notch = Math.max(Math.min(bounds.height, parseFloat(mxUtils.getValue(this.state.style, 'notch', this.notch))), 0);
- return new mxPoint(bounds.x + bounds.width / 4, bounds.y + bounds.height - notch);
- }, function(bounds, pt)
- {
- this.state.style['notch'] = Math.round(0.2 * Math.max(0, bounds.width - pt.y + bounds.y)) / 0.2;
- })];
-
- return handles;
- }
- //**********************************************************************************************************************************************************
- //Three-Line Bus Elbow
- //**********************************************************************************************************************************************************
- /**
- * Extends mxShape.
- */
- function mxShapeElectricalThreeLineBusElbow(bounds, fill, stroke, strokewidth)
- {
- mxShape.call(this);
- this.bounds = bounds;
- this.fill = fill;
- this.stroke = stroke;
- this.strokewidth = (strokewidth != null) ? strokewidth : 1;
- this.notch = 0;
- };
- /**
- * Extends mxShape.
- */
- mxUtils.extend(mxShapeElectricalThreeLineBusElbow, mxShape);
- mxShapeElectricalThreeLineBusElbow.prototype.cst = {
- SHAPE_THREE_LINE_BUS_ELBOW : 'mxgraph.electrical.transmission.threeLineBusElbow'
- };
- /**
- * Function: paintVertexShape
- *
- * Paints the vertex shape.
- */
- mxShapeElectricalThreeLineBusElbow.prototype.paintVertexShape = function(c, x, y, w, h)
- {
- var notch = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'notch', this.notch))));
- c.translate(x, y);
- c.begin();
- c.moveTo(0, h);
- c.lineTo(w, h);
- c.lineTo(w, 0);
- c.stroke();
-
- var wn = Math.min(w, notch);
- var hn = Math.min(h, notch);
-
- c.begin();
- c.moveTo(0, h - hn);
- c.lineTo(w - wn, h - hn);
- c.lineTo(w - wn, 0);
- c.stroke();
-
- c.begin();
- c.moveTo(0, h - hn / 2);
- c.lineTo(w - wn / 2, h - hn / 2);
- c.lineTo(w - wn / 2, 0);
- c.stroke();
- };
- mxCellRenderer.prototype.defaultShapes[mxShapeElectricalThreeLineBusElbow.prototype.cst.SHAPE_THREE_LINE_BUS_ELBOW] = mxShapeElectricalThreeLineBusElbow;
- mxShapeElectricalThreeLineBusElbow.prototype.constraints = null;
- Graph.handleFactory[mxShapeElectricalThreeLineBusElbow.prototype.cst.SHAPE_THREE_LINE_BUS_ELBOW] = function(state)
- {
- var handles = [Graph.createHandle(state, ['notch'], function(bounds)
- {
- var notch = Math.max(Math.min(bounds.height, parseFloat(mxUtils.getValue(this.state.style, 'notch', this.notch))), 0);
- return new mxPoint(bounds.x + bounds.width / 4, bounds.y + bounds.height - notch);
- }, function(bounds, pt)
- {
- this.state.style['notch'] = Math.round(0.2 * Math.max(0, bounds.width - pt.y + bounds.y)) / 0.2;
- })];
-
- return handles;
- }
- //**********************************************************************************************************************************************************
- //Four-Line Bus Elbow
- //**********************************************************************************************************************************************************
- /**
- * Extends mxShape.
- */
- function mxShapeElectricalFourLineBusElbow(bounds, fill, stroke, strokewidth)
- {
- mxShape.call(this);
- this.bounds = bounds;
- this.fill = fill;
- this.stroke = stroke;
- this.strokewidth = (strokewidth != null) ? strokewidth : 1;
- this.notch = 0;
- };
- /**
- * Extends mxShape.
- */
- mxUtils.extend(mxShapeElectricalFourLineBusElbow, mxShape);
- mxShapeElectricalFourLineBusElbow.prototype.cst = {
- SHAPE_FOUR_LINE_BUS_ELBOW : 'mxgraph.electrical.transmission.fourLineBusElbow'
- };
- /**
- * Function: paintVertexShape
- *
- * Paints the vertex shape.
- */
- mxShapeElectricalFourLineBusElbow.prototype.paintVertexShape = function(c, x, y, w, h)
- {
- var notch = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'notch', this.notch))));
- c.translate(x, y);
- c.begin();
- c.moveTo(0, h);
- c.lineTo(w, h);
- c.lineTo(w, 0);
- c.stroke();
-
- var wn = Math.min(w, notch);
- var hn = Math.min(h, notch);
-
- c.begin();
- c.moveTo(0, h - hn);
- c.lineTo(w - wn, h - hn);
- c.lineTo(w - wn, 0);
- c.stroke();
-
- c.begin();
- c.moveTo(0, h - hn / 3);
- c.lineTo(w - wn / 3, h - hn / 3);
- c.lineTo(w - wn / 3, 0);
- c.stroke();
-
- c.begin();
- c.moveTo(0, h - hn * 2 / 3);
- c.lineTo(w - wn * 2 / 3, h - hn * 2 / 3);
- c.lineTo(w - wn * 2 / 3, 0);
- c.stroke();
- };
- mxCellRenderer.prototype.defaultShapes[mxShapeElectricalFourLineBusElbow.prototype.cst.SHAPE_FOUR_LINE_BUS_ELBOW] = mxShapeElectricalFourLineBusElbow;
- mxShapeElectricalFourLineBusElbow.prototype.constraints = null;
- Graph.handleFactory[mxShapeElectricalFourLineBusElbow.prototype.cst.SHAPE_FOUR_LINE_BUS_ELBOW] = function(state)
- {
- var handles = [Graph.createHandle(state, ['notch'], function(bounds)
- {
- var notch = Math.max(Math.min(bounds.height, parseFloat(mxUtils.getValue(this.state.style, 'notch', this.notch))), 0);
- return new mxPoint(bounds.x + bounds.width / 4, bounds.y + bounds.height - notch);
- }, function(bounds, pt)
- {
- this.state.style['notch'] = Math.round(0.2 * Math.max(0, bounds.width - pt.y + bounds.y)) / 0.2;
- })];
-
- return handles;
- }
- //**********************************************************************************************************************************************************
- //Four-Line Bus Elbow
- //**********************************************************************************************************************************************************
- /**
- * Extends mxShape.
- */
- function mxShapeElectricalEightLineBusElbow(bounds, fill, stroke, strokewidth)
- {
- mxShape.call(this);
- this.bounds = bounds;
- this.fill = fill;
- this.stroke = stroke;
- this.strokewidth = (strokewidth != null) ? strokewidth : 1;
- this.notch = 0;
- };
- /**
- * Extends mxShape.
- */
- mxUtils.extend(mxShapeElectricalEightLineBusElbow, mxShape);
- mxShapeElectricalEightLineBusElbow.prototype.cst = {
- SHAPE_EIGHT_LINE_BUS_ELBOW : 'mxgraph.electrical.transmission.eightLineBusElbow'
- };
- /**
- * Function: paintVertexShape
- *
- * Paints the vertex shape.
- */
- mxShapeElectricalEightLineBusElbow.prototype.paintVertexShape = function(c, x, y, w, h)
- {
- var notch = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'notch', this.notch))));
- c.translate(x, y);
- c.begin();
- c.moveTo(0, h);
- c.lineTo(w, h);
- c.lineTo(w, 0);
- c.stroke();
-
- var wn = Math.min(w, notch);
- var hn = Math.min(h, notch);
-
- c.begin();
- c.moveTo(0, h - hn);
- c.lineTo(w - wn, h - hn);
- c.lineTo(w - wn, 0);
- c.stroke();
-
- c.begin();
- c.moveTo(0, h - hn / 7);
- c.lineTo(w - wn / 7, h - hn / 7);
- c.lineTo(w - wn / 7, 0);
- c.stroke();
-
- c.begin();
- c.moveTo(0, h - hn * 2 / 7);
- c.lineTo(w - wn * 2 / 7, h - hn * 2 / 7);
- c.lineTo(w - wn * 2 / 7, 0);
- c.stroke();
-
- c.begin();
- c.moveTo(0, h - hn * 3 / 7);
- c.lineTo(w - wn * 3 / 7, h - hn * 3 / 7);
- c.lineTo(w - wn * 3 / 7, 0);
- c.stroke();
-
- c.begin();
- c.moveTo(0, h - hn * 4 / 7);
- c.lineTo(w - wn * 4 / 7, h - hn * 4 / 7);
- c.lineTo(w - wn * 4 / 7, 0);
- c.stroke();
-
- c.begin();
- c.moveTo(0, h - hn * 5 / 7);
- c.lineTo(w - wn * 5 / 7, h - hn * 5 / 7);
- c.lineTo(w - wn * 5 / 7, 0);
- c.stroke();
-
- c.begin();
- c.moveTo(0, h - hn * 6 / 7);
- c.lineTo(w - wn * 6 / 7, h - hn * 6 / 7);
- c.lineTo(w - wn * 6 / 7, 0);
- c.stroke();
-
- };
- mxCellRenderer.prototype.defaultShapes[mxShapeElectricalEightLineBusElbow.prototype.cst.SHAPE_EIGHT_LINE_BUS_ELBOW] = mxShapeElectricalEightLineBusElbow;
- mxShapeElectricalEightLineBusElbow.prototype.constraints = null;
- Graph.handleFactory[mxShapeElectricalEightLineBusElbow.prototype.cst.SHAPE_EIGHT_LINE_BUS_ELBOW] = function(state)
- {
- var handles = [Graph.createHandle(state, ['notch'], function(bounds)
- {
- var notch = Math.max(Math.min(bounds.height, parseFloat(mxUtils.getValue(this.state.style, 'notch', this.notch))), 0);
- return new mxPoint(bounds.x + bounds.width / 4, bounds.y + bounds.height - notch);
- }, function(bounds, pt)
- {
- this.state.style['notch'] = Math.round(0.2 * Math.max(0, bounds.width - pt.y + bounds.y)) / 0.2;
- })];
-
- return handles;
- }
|