Skip to content

Commit d2aaabd

Browse files
Merge pull request #213 from frg-fossee/develop
Merge develop to master
2 parents 6ad3a8d + c9cd369 commit d2aaabd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5185
-249
lines changed

ArduinoFrontend/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
"@angular/platform-browser": "~7.2.0",
2424
"@angular/platform-browser-dynamic": "~7.2.0",
2525
"@angular/router": "~7.2.0",
26+
"chroma-js": "^1.3.5",
2627
"core-js": "^2.5.4",
2728
"is-promise": "2.2.2",
29+
"lodash": "^4.17.19",
30+
"lodash-transpose": "^0.2.1",
2831
"ngx-monaco-editor": "^7.0.0",
2932
"rxjs": "~6.3.3",
3033
"tslib": "^1.9.0",

ArduinoFrontend/src/app/Libs/CircuitElement.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Point } from './Point';
22
import { Wire } from './Wire';
33
import { isNull } from 'util';
4+
import { BoundingBox } from './Geometry';
45

56
/**
67
* Abstract Class Circuit Elements
@@ -110,6 +111,14 @@ export abstract class CircuitElement {
110111
});
111112
}
112113
}
114+
115+
/**
116+
* Returns bounding box of the circuit element
117+
*/
118+
getBoundingBox(): BoundingBox {
119+
return BoundingBox.loadFromRaphaelBbox(this.elements.getBBox());
120+
}
121+
113122
/**
114123
* Draws circuit nodes
115124
* @param canvas Raphael Canvas
@@ -136,26 +145,23 @@ export abstract class CircuitElement {
136145
* @param drawData Draw Data
137146
*/
138147
DrawElement(canvas: any, drawData: any) {
148+
const elementsDrawn = [];
139149
for (const item of drawData) {
150+
let element;
140151
// Draw image
141152
if (item.type === 'image') {
142-
this.elements.push(
143-
canvas.image(
153+
element = canvas.image(
144154
item.url,
145155
this.x + item.x,
146156
this.y + item.y,
147157
item.width,
148158
item.height
149-
)
150-
);
159+
);
151160
} else if (item.type === 'path') {
152-
this.elements.push(
153-
this.DrawPath(canvas, item)
154-
);
161+
element = this.DrawPath(canvas, item);
155162
} else if (item.type === 'rectangle') {
156163
// Draw rectangle
157-
this.elements.push(
158-
canvas.rect(
164+
element = canvas.rect(
159165
this.x + item.x,
160166
this.y + item.y,
161167
item.width,
@@ -164,24 +170,24 @@ export abstract class CircuitElement {
164170
).attr({
165171
fill: item.fill || 'none',
166172
stroke: item.stroke || 'none'
167-
})
168-
);
173+
});
169174
} else if (item.type === 'circle') {
170175
// Draw a circle
171-
this.elements.push(
172-
canvas.circle(
176+
element = canvas.circle(
173177
this.x + item.x,
174178
this.y + item.y,
175179
item.radius,
176180
).attr({
177181
fill: item.fill || 'none',
178182
stroke: item.stroke || 'none'
179-
})
180-
);
183+
});
181184
} else if (item.type === 'polygon') {
182-
this.DrawPolygon(canvas, item);
185+
element = this.DrawPolygon(canvas, item);
183186
}
187+
this.elements.push(element);
188+
elementsDrawn.push(element);
184189
}
190+
return elementsDrawn;
185191
}
186192
/**
187193
* Draws an Polygon
@@ -198,13 +204,11 @@ export abstract class CircuitElement {
198204
tmp += `${this.x + point[0]},${this.y + point[1]}L`;
199205
}
200206
tmp = tmp.substr(0, tmp.length - 1) + 'z';
201-
this.elements.push(
202-
canvas.path(tmp)
203-
.attr({
204-
fill: item.fill || 'none',
205-
stroke: item.stroke || 'none'
206-
})
207-
);
207+
return canvas.path(tmp)
208+
.attr({
209+
fill: item.fill || 'none',
210+
stroke: item.stroke || 'none'
211+
});
208212
}
209213
/**
210214
* Draw a Path
@@ -227,13 +231,11 @@ export abstract class CircuitElement {
227231
str = this.calcRelative(str, horizontal, canvas);
228232
str = this.calcRelative(str, vertical, canvas);
229233
str = this.calcRelative(str, sCurve, canvas);
230-
this.elements.push(
231-
canvas.path(str)
232-
.attr({
233-
fill: item.fill || 'none',
234-
stroke: item.stroke || 'none'
235-
})
236-
);
234+
return canvas.path(str)
235+
.attr({
236+
fill: item.fill || 'none',
237+
stroke: item.stroke || 'none'
238+
});
237239
}
238240
/**
239241
* Draw path relative to the component
@@ -291,6 +293,7 @@ export abstract class CircuitElement {
291293
for (let i = 0; i < this.nodes.length; ++i) {
292294
this.nodes[i].move(tmpar[i][0] + dx, tmpar[i][1] + dy);
293295
}
296+
window['onDragEvent'](this);
294297
}, () => {
295298
fdx = 0;
296299
fdy = 0;
@@ -308,6 +311,7 @@ export abstract class CircuitElement {
308311
// }
309312
this.tx += fdx;
310313
this.ty += fdy;
314+
window['onDragStopEvent'](this);
311315
});
312316
}
313317
/**

0 commit comments

Comments
 (0)