1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | import * as go from '../release/go-module.js';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | export class DimensioningLink extends go.Link {
|
31 | private _direction: number = 0;
|
32 | private _extension: number = 30;
|
33 | private _inset: number = 10;
|
34 | private _gap: number = 10;
|
35 |
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | constructor() {
|
43 | super();
|
44 | this.isLayoutPositioned = false;
|
45 | this.isTreeLink = false;
|
46 | this.routing = go.Link.Orthogonal;
|
47 | }
|
48 |
|
49 | |
50 |
|
51 |
|
52 | public cloneProtected(copy: this): void {
|
53 | super.cloneProtected(copy);
|
54 | copy._direction = this._direction;
|
55 | copy._extension = this._extension;
|
56 | copy._inset = this._inset;
|
57 | copy._gap = this._gap;
|
58 | }
|
59 |
|
60 | |
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | get direction(): number { return this._direction; }
|
69 | set direction(val: number) {
|
70 | if (isNaN(val) || val === 0 || val === 90 || val === 180 || val === 270) {
|
71 | this._direction = val;
|
72 | } else {
|
73 | throw new Error('DimensioningLink: invalid new direction: ' + val);
|
74 | }
|
75 | }
|
76 |
|
77 | |
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | get extension(): number { return this._extension; }
|
85 | set extension(val: number) { this._extension = val; }
|
86 |
|
87 | |
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | get inset(): number { return this._inset; }
|
94 | set inset(val: number) {
|
95 | if (val >= 0) {
|
96 | this._inset = val;
|
97 | } else {
|
98 | throw new Error('DimensionLink: invalid new inset: ' + val);
|
99 | }
|
100 | }
|
101 |
|
102 | |
103 |
|
104 |
|
105 |
|
106 |
|
107 | get gap(): number { return this._gap; }
|
108 | set gap(val: number) {
|
109 | if (val >= 0) {
|
110 | this._gap = val;
|
111 | } else {
|
112 | throw new Error('DimensionLink: invalid new gap: ' + val);
|
113 | }
|
114 | }
|
115 |
|
116 | |
117 |
|
118 |
|
119 |
|
120 | public computePoints(): boolean {
|
121 | const fromnode = this.fromNode;
|
122 | if (!fromnode) return false;
|
123 | const fromport = this.fromPort;
|
124 | const fromspot = this.computeSpot(true);
|
125 | const tonode = this.toNode;
|
126 | if (!tonode) return false;
|
127 | const toport = this.toPort;
|
128 | const tospot = this.computeSpot(false);
|
129 | const frompoint = this.getLinkPoint(fromnode, fromport, fromspot, true, true, tonode, toport);
|
130 | if (!frompoint.isReal()) return false;
|
131 | const topoint = this.getLinkPoint(tonode, toport, tospot, false, true, fromnode, fromport);
|
132 | if (!topoint.isReal()) return false;
|
133 |
|
134 | this.clearPoints();
|
135 |
|
136 | let ang = this.direction;
|
137 | if (isNaN(ang)) {
|
138 | ang = frompoint.directionPoint(topoint);
|
139 | const p = new go.Point(this.extension, 0);
|
140 | p.rotate(ang + 90);
|
141 | const q = new go.Point(this.extension - this.inset, 0);
|
142 | q.rotate(ang + 90);
|
143 | const g = new go.Point(this.gap, 0);
|
144 | g.rotate(ang + 90);
|
145 | this.addPointAt(frompoint.x + g.x, frompoint.y + g.y);
|
146 | this.addPointAt(frompoint.x + p.x, frompoint.y + p.y);
|
147 | this.addPointAt(frompoint.x + q.x, frompoint.y + q.y);
|
148 | this.addPointAt(topoint.x + q.x, topoint.y + q.y);
|
149 | this.addPointAt(topoint.x + p.x, topoint.y + p.y);
|
150 | this.addPointAt(topoint.x + g.x, topoint.y + g.y);
|
151 | } else {
|
152 | const dist = this.extension;
|
153 | let r = 0.0;
|
154 | let s = 0.0;
|
155 | let t0 = 0.0;
|
156 | let t1 = 0.0;
|
157 | if (ang === 0 || ang === 180) {
|
158 | if (ang === 0) {
|
159 | r = Math.min(frompoint.y, topoint.y) - this.extension;
|
160 | s = r + this.inset;
|
161 | t0 = frompoint.y - this.gap;
|
162 | t1 = topoint.y - this.gap;
|
163 | } else {
|
164 | r = Math.max(frompoint.y, topoint.y) + this.extension;
|
165 | s = r - this.inset;
|
166 | t0 = frompoint.y + this.gap;
|
167 | t1 = topoint.y + this.gap;
|
168 | }
|
169 | this.addPointAt(frompoint.x, t0);
|
170 | this.addPointAt(frompoint.x + 0.01, r);
|
171 | this.addPointAt(frompoint.x, s);
|
172 | this.addPointAt(topoint.x, s);
|
173 | this.addPointAt(topoint.x - 0.01, r);
|
174 | this.addPointAt(topoint.x, t1);
|
175 | } else if (ang === 90 || ang === 270) {
|
176 | if (ang === 90) {
|
177 | r = Math.max(frompoint.x, topoint.x) + this.extension;
|
178 | s = r - this.inset;
|
179 | t0 = frompoint.x + this.gap;
|
180 | t1 = topoint.x + this.gap;
|
181 | } else {
|
182 | r = Math.min(frompoint.x, topoint.x) - this.extension;
|
183 | s = r + this.inset;
|
184 | t0 = frompoint.x - this.gap;
|
185 | t1 = topoint.x - this.gap;
|
186 | }
|
187 | this.addPointAt(t0, frompoint.y);
|
188 | this.addPointAt(r, frompoint.y + 0.01);
|
189 | this.addPointAt(s, frompoint.y);
|
190 | this.addPointAt(s, topoint.y);
|
191 | this.addPointAt(r, topoint.y - 0.01);
|
192 | this.addPointAt(t1, topoint.y);
|
193 | }
|
194 | }
|
195 |
|
196 | return true;
|
197 | }
|
198 | }
|