1 |
|
2 |
|
3 |
|
4 | (function (factory) {
|
5 | if (typeof module === "object" && typeof module.exports === "object") {
|
6 | var v = factory(require, exports);
|
7 | if (v !== undefined) module.exports = v;
|
8 | }
|
9 | else if (typeof define === "function" && define.amd) {
|
10 | define(["require", "exports", "../release/go.js", "./GeometryReshapingTool.js", "./PolygonDrawingTool.js"], factory);
|
11 | }
|
12 | })(function (require, exports) {
|
13 | "use strict";
|
14 | Object.defineProperty(exports, "__esModule", { value: true });
|
15 | exports.allowRotating = exports.allowReshaping = exports.allowResizing = exports.cancelDrawing = exports.finishDrawing = exports.drawPolyline = exports.drawPolygon = exports.select = exports.load = exports.save = exports.updateAllAdornments = exports.undo = exports.finish = exports.mode = exports.init = void 0;
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var go = require("../release/go.js");
|
24 | var GeometryReshapingTool_js_1 = require("./GeometryReshapingTool.js");
|
25 | var PolygonDrawingTool_js_1 = require("./PolygonDrawingTool.js");
|
26 | var myDiagram;
|
27 | function init() {
|
28 | if (window.goSamples)
|
29 | window.goSamples();
|
30 | var $ = go.GraphObject.make;
|
31 | myDiagram =
|
32 | $(go.Diagram, 'myDiagramDiv');
|
33 | myDiagram.toolManager.mouseDownTools.insertAt(3, new GeometryReshapingTool_js_1.GeometryReshapingTool());
|
34 | myDiagram.nodeTemplateMap.add('PolygonDrawing', $(go.Node, { locationSpot: go.Spot.Center },
|
35 | new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify), {
|
36 | selectionAdorned: true, selectionObjectName: 'SHAPE',
|
37 | selectionAdornmentTemplate:
|
38 | $(go.Adornment, 'Auto', $(go.Shape, { stroke: 'dodgerblue', fill: null }), $(go.Placeholder, { margin: -1 }))
|
39 | }, { resizable: true, resizeObjectName: 'SHAPE' }, { rotatable: true, rotateObjectName: 'SHAPE' }, { reshapable: true },
|
40 | $(go.Shape, { name: 'SHAPE', fill: 'lightgray', strokeWidth: 1.5 }, new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify), new go.Binding('angle').makeTwoWay(), new go.Binding('geometryString', 'geo').makeTwoWay(), new go.Binding('fill'), new go.Binding('stroke'), new go.Binding('strokeWidth'))));
|
41 |
|
42 | var tool = new PolygonDrawingTool_js_1.PolygonDrawingTool();
|
43 |
|
44 | tool.archetypePartData = { fill: 'yellow', stroke: 'blue', strokeWidth: 3, category: 'PolygonDrawing' };
|
45 | tool.isPolygon = true;
|
46 | tool.isEnabled = false;
|
47 |
|
48 | myDiagram.toolManager.mouseDownTools.insertAt(0, tool);
|
49 | load();
|
50 | }
|
51 | exports.init = init;
|
52 | function mode(draw, polygon) {
|
53 |
|
54 | var tool = myDiagram.toolManager.mouseDownTools.elt(0);
|
55 | tool.isEnabled = draw;
|
56 | tool.isPolygon = polygon;
|
57 | tool.archetypePartData.fill = (polygon ? 'yellow' : null);
|
58 | tool.temporaryShape.fill = (polygon ? 'yellow' : null);
|
59 | if (draw)
|
60 | myDiagram.currentTool = tool;
|
61 | }
|
62 | exports.mode = mode;
|
63 |
|
64 | function finish(commit) {
|
65 | var tool = myDiagram.currentTool;
|
66 | if (commit && tool instanceof PolygonDrawingTool_js_1.PolygonDrawingTool) {
|
67 | var lastInput = myDiagram.lastInput;
|
68 | if (lastInput.event instanceof MouseEvent)
|
69 | tool.removeLastPoint();
|
70 | tool.finishShape();
|
71 | }
|
72 | else {
|
73 | tool.doCancel();
|
74 | }
|
75 | }
|
76 | exports.finish = finish;
|
77 |
|
78 | function undo() {
|
79 | var tool = myDiagram.currentTool;
|
80 | if (tool instanceof PolygonDrawingTool_js_1.PolygonDrawingTool) {
|
81 | var lastInput = myDiagram.lastInput;
|
82 | if (lastInput.event instanceof MouseEvent)
|
83 | tool.removeLastPoint();
|
84 | tool.undo();
|
85 | }
|
86 | }
|
87 | exports.undo = undo;
|
88 | function updateAllAdornments() {
|
89 | myDiagram.selection.each(function (p) { p.updateAdornments(); });
|
90 | }
|
91 | exports.updateAllAdornments = updateAllAdornments;
|
92 |
|
93 | function save() {
|
94 | var str = '{ "position": "' + go.Point.stringify(myDiagram.position) + '",\n "model": ' + myDiagram.model.toJson() + ' }';
|
95 | document.getElementById('mySavedDiagram').value = str;
|
96 | myDiagram.isModified = false;
|
97 | }
|
98 | exports.save = save;
|
99 | function load() {
|
100 | var str = document.getElementById('mySavedDiagram').value;
|
101 | try {
|
102 | var json = JSON.parse(str);
|
103 | myDiagram.initialPosition = go.Point.parse(json.position || '0 0');
|
104 | myDiagram.model = go.Model.fromJson(json.model);
|
105 | myDiagram.model.undoManager.isEnabled = true;
|
106 | }
|
107 | catch (ex) {
|
108 | alert(ex);
|
109 | }
|
110 | }
|
111 | exports.load = load;
|
112 | function select() {
|
113 | mode(false, false);
|
114 | }
|
115 | exports.select = select;
|
116 | function drawPolygon() {
|
117 | mode(true, true);
|
118 | }
|
119 | exports.drawPolygon = drawPolygon;
|
120 | function drawPolyline() {
|
121 | mode(true, false);
|
122 | }
|
123 | exports.drawPolyline = drawPolyline;
|
124 | function finishDrawing() {
|
125 | finish(true);
|
126 | }
|
127 | exports.finishDrawing = finishDrawing;
|
128 | function cancelDrawing() {
|
129 | finish(false);
|
130 | }
|
131 | exports.cancelDrawing = cancelDrawing;
|
132 | function allowResizing() {
|
133 | myDiagram.allowResize = !myDiagram.allowResize;
|
134 | updateAllAdornments();
|
135 | }
|
136 | exports.allowResizing = allowResizing;
|
137 | function allowReshaping() {
|
138 | myDiagram.allowReshape = !myDiagram.allowReshape;
|
139 | updateAllAdornments();
|
140 | }
|
141 | exports.allowReshaping = allowReshaping;
|
142 | function allowRotating() {
|
143 | myDiagram.allowRotate = !myDiagram.allowRotate;
|
144 | updateAllAdornments();
|
145 | }
|
146 | exports.allowRotating = allowRotating;
|
147 | });
|