Skip to content

Commit

Permalink
Merge pull request #496 from frg-fossee/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
fresearchgroup committed Mar 15, 2023
2 parents 416090f + 9a55bd7 commit 0c18d51
Show file tree
Hide file tree
Showing 47 changed files with 1,133 additions and 209 deletions.
34 changes: 32 additions & 2 deletions ArduinoFrontend/src/app/Libs/CircuitElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,12 @@ export abstract class CircuitElement {
* Add Drag listener to the components
*/
setDragListeners() {
// let tmpx = 0;
// let tmpy = 0;

let fdx = 0;
let fdy = 0;
let tmpar = [];
this.elements.drag((dx, dy) => {

this.elements.transform(`t${this.tx + dx},${this.ty + dy}`);
// tmpx = this.tx + dx;
// tmpy = this.ty + dy;
Expand Down Expand Up @@ -450,6 +450,36 @@ export abstract class CircuitElement {
* Return the Name of the component.Can be inheriter to return custom name.
*/
getName() { return this.title; }
/**
* Function to move/transform an element
* @param fdx relative x position to move
* @param fdy relative y position to move
*/
getNodesCoord(): number[] {
const tmpar = [];
for (const node of this.nodes) {
tmpar.push(
[node.x, node.y]
);
}
return tmpar;
}
dragAlong(tmpar: any, fdx: number, fdy: number): any {
this.elements.transform(`t${this.tx + fdx},${this.ty + fdy}`);
for (const node of this.nodes) {
tmpar.push(
[node.x, node.y]
);
}
for (let i = 0; i < this.nodes.length; ++i) {
this.nodes[i].move(tmpar[i][0] + fdx, tmpar[i][1] + fdy);
}
}
dragAlongStop(x: number, y: number): void {
this.tx = x;
this.ty = y;
}


/**
* Function to move/transform an element
Expand Down
145 changes: 140 additions & 5 deletions ArduinoFrontend/src/app/Libs/General.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ export class Resistor extends CircuitElement {
*/
closeSimulation(): void {
}

/**
* Get resistance value of resistor
*/
getResistance() {
return this.value;
}
/**
* Get ID of the resistor
* TODO: Add this function inside CircuitElements.ts instead
*/
getID() {
return this.id;
}
}

/**
Expand Down Expand Up @@ -323,6 +337,7 @@ export class BreadBoard extends CircuitElement {
*/
public sameYNodes: { [key: string]: Point[] } = {};


/**
* Breadboard constructor
* @param canvas Raphael Canvas (Paper)
Expand Down Expand Up @@ -585,10 +600,12 @@ export class BreadBoard extends CircuitElement {
/** init is called when the component is complety drawn to the canvas */
init() {
this.sortedNodes = _.sortBy(this.nodes, ['x', 'y']);

if (BreadBoard.groupings.length === 0) {
BreadBoard.groupings = this.data.groupings;
}

// initialise sameX and sameY node sets
for (const node of this.nodes) {
// create the set for x
this.sameXNodes[node.x] = this.sameXNodes[node.x] || [];
Expand All @@ -604,9 +621,14 @@ export class BreadBoard extends CircuitElement {
node.connectCallback = (item) => {
this.joined.push(item);
};
node.disconnectCallback = (item) => {
const index = this.joined.indexOf(item);
if (index > -1) {
this.joined.splice(index, 1);
}
};
}
this.elements.toBack();

// Remove the drag event
this.elements.undrag();
let tmpx = 0;
Expand All @@ -615,6 +637,10 @@ export class BreadBoard extends CircuitElement {
let fdy = 0;
let tmpar = [];
let tmpar2 = [];
let ConnEleList = [];
let NodeList = [];
let tmpx2 = [];
let tmpy2 = [];
// Create Custom Drag event
this.elements.drag((dx, dy) => {
this.elements.transform(`t${this.tx + dx},${this.ty + dy}`);
Expand All @@ -625,6 +651,11 @@ export class BreadBoard extends CircuitElement {
for (let i = 0; i < this.joined.length; ++i) {
this.joined[i].move(tmpar[i][0] + dx, tmpar[i][1] + dy);
}
for (let i = 0; i < ConnEleList.length; ++i) {
ConnEleList[i].dragAlong(NodeList[i], dx, dy);
tmpx2[i] = ConnEleList[i].tx + dx;
tmpy2[i] = ConnEleList[i].ty + dy;
}
}, () => {
fdx = 0;
fdy = 0;
Expand All @@ -637,10 +668,48 @@ export class BreadBoard extends CircuitElement {
node.remainHidden();
}
for (const node of this.joined) {
let ElementFlag = false;
tmpar.push(
[node.x, node.y]
);
node.remainShow();
if (node.connectedTo != null) {
const ConnElement1 = node.connectedTo.start.parent;
const ConnElement2 = node.connectedTo.end.parent;
console.log(ConnElement1.keyName);
console.log(ConnElement2.keyName);
if (ConnElement1.keyName !== 'BreadBoard') {
for (const ele of ConnEleList) {
if (ele === ConnElement1) {
ElementFlag = true;
break;
}
}
const PlaceableCheck = 'isBreadBoardPlaceable' in ConnElement1.info.properties;
const isBreadBoardPlaceable = ConnElement1.info.properties.isBreadBoardPlaceable;
if (!ElementFlag && PlaceableCheck && isBreadBoardPlaceable === 1) {
ConnEleList.push(ConnElement1);
tmpx2.push(0);
tmpy2.push(0);
NodeList.push(ConnElement1.getNodesCoord());
}
} else {
for (const ele of ConnEleList) {
if (ele === ConnElement1) {
ElementFlag = true;
break;
}
}
const PlaceableCheck = 'isBreadBoardPlaceable' in ConnElement2.info.properties;
const isBreadBoardPlaceable = ConnElement2.info.properties.isBreadBoardPlaceable;
if (!ElementFlag && PlaceableCheck && isBreadBoardPlaceable === 1) {
ConnEleList.push(ConnElement2);
tmpx2.push(0);
tmpy2.push(0);
NodeList.push(ConnElement2.getNodesCoord());
}
}
}
}

}, () => {
Expand All @@ -651,9 +720,18 @@ export class BreadBoard extends CircuitElement {
this.nodes[i].remainShow();
}
tmpar2 = [];

this.tx = tmpx;
this.ty = tmpy;
// reBuild SameNodeObject after drag stop
for (let i = 0; i < ConnEleList.length; i++) {
ConnEleList[i].dragAlongStop(tmpx2[i], tmpy2[i]);
}
ConnEleList = [];
NodeList = [];
tmpx2 = [];
tmpy2 = [];
tmpar = [];
this.reBuildSameNodes();
});
}
Expand All @@ -670,7 +748,10 @@ export class BreadBoard extends CircuitElement {
let tmpy = 0;
let ffdx = 0;
let ffdy = 0;

let ConnEleList = [];
let NodeList = [];
let tmpx2 = [];
let tmpy2 = [];
ffdx = 0;
ffdy = 0;
tmpar = [];
Expand All @@ -686,6 +767,41 @@ export class BreadBoard extends CircuitElement {
[node.x, node.y]
);
node.remainShow();
const ConnElement1 = node.connectedTo.start.parent;
const ConnElement2 = node.connectedTo.end.parent;
console.log(ConnElement1.keyName);
console.log(ConnElement2.keyName);
let ElementFlag = false;
if (ConnElement1.keyName !== 'BreadBoard') {

for (const ele of ConnEleList) {
if (ele === ConnElement1) {
ElementFlag = true;
break;
}
}
if (!ElementFlag && ConnElement1.info.properties.isBreadBoardPlaceable === 1) {
ConnEleList.push(ConnElement1);
tmpx2.push(0);
tmpy2.push(0);
NodeList.push(ConnElement1.getNodesCoord());
}
} else {
for (const ele of ConnEleList) {
if (ele === ConnElement1) {
ElementFlag = true;
break;
}
}
if (!ElementFlag && ConnElement2.info.properties.isBreadBoardPlaceable === 1) {
ConnEleList.push(ConnElement2);
tmpx2.push(0);
tmpy2.push(0);
NodeList.push(ConnElement2.getNodesCoord());
}
}


}

this.elements.transform(`t${this.tx + fdx},${this.ty + fdy}`);
Expand All @@ -697,14 +813,28 @@ export class BreadBoard extends CircuitElement {
this.joined[i].move(tmpar[i][0] + fdx, tmpar[i][1] + fdy);
}

for (let i = 0; i < ConnEleList.length; ++i) {
ConnEleList[i].dragAlong(NodeList[i], fdx, fdy);
tmpx2[i] = ConnEleList[i].tx + fdx;
tmpy2[i] = ConnEleList[i].ty + fdy;
}

for (let i = 0; i < this.nodes.length; ++i) {
this.nodes[i].move(tmpar2[i][0] + ffdx, tmpar2[i][1] + ffdy);
this.nodes[i].remainShow();
}

this.tx = tmpx;
this.ty = tmpy;

for (let i = 0; i < ConnEleList.length; i++) {
ConnEleList[i].dragAlongStop(tmpx2[i], tmpy2[i]);
}
ConnEleList = [];
NodeList = [];
tmpx2 = [];
tmpy2 = [];
tmpar = [];
this.reBuildSameNodes();
}

/**
Expand Down Expand Up @@ -820,7 +950,13 @@ export class BreadBoard extends CircuitElement {
&& (labelCalledBy.charCodeAt(0) !== labelParent.charCodeAt(0) || labelCalledBy === labelParent)) {
return;
}
if (node.label === '+' || node.label === '-') {
if (node.label === '-') {
for (const neigh of ytemp[node.y]) {
if (neigh.x !== node.x && value <= 0) {
neigh.setValue(value, neigh);
}
}
} else if (node.label === '+') {
for (const neigh of ytemp[node.y]) {
if (neigh.x !== node.x) {
neigh.setValue(value, neigh);
Expand Down Expand Up @@ -853,7 +989,6 @@ export class BreadBoard extends CircuitElement {
closeSimulation(): void {
BreadBoard.visitedNodesv2.clear();
}

/**
* Returns groupings
*/
Expand Down
27 changes: 13 additions & 14 deletions ArduinoFrontend/src/app/Libs/Point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CircuitElement } from './CircuitElement';
import { isNull } from 'util';
import { BoundingBox } from './Geometry';
import _ from 'lodash';
import { BreadBoard } from './General';


/**
Expand Down Expand Up @@ -62,6 +63,10 @@ export class Point {
* Callback called when we connect wire.
*/
connectCallback: any = null;
/*
Callback called on disconnecting a wire.
*/
disconnectCallback: any = null;
/**
* The Value of the node
*/
Expand Down Expand Up @@ -121,20 +126,14 @@ export class Point {
// Check if showBubbleBool is enabled
if (Point.showBubbleBool) {
// Check if callback is present if it is then call it

if (this.hoverCallback) {
this.hoverCallback(this.x, this.y);
}
window.showBubble(this.label, evt.clientX, evt.clientY);
if (this.parent.keyName === 'BreadBoard') {

let ref: any = {};
const ref = this.parent as BreadBoard;

for (const obj of window.scope['BreadBoard']) {
if (obj.id === this.parent.id) {
ref = obj;
}
}
if (this.label === '+' || this.label === '-') {
for (const point of ref.sameYNodes[this.y]) {
if (this.id === point.id) {
Expand Down Expand Up @@ -173,12 +172,9 @@ export class Point {
window.hideBubble();

if (this.parent.keyName === 'BreadBoard') {
let ref: any = {};
for (const obj of window.scope['BreadBoard']) {
if (obj.id === this.parent.id) {
ref = obj;
}
}

const ref = this.parent as BreadBoard;

if (this.label === '+' || this.label === '-') {
for (const point of ref.sameYNodes[this.y]) {
if (this.id === point.id) {
Expand Down Expand Up @@ -281,6 +277,10 @@ export class Point {
this.soldered = false;
const newClass = this.body.node.getAttribute('class').replace(' solder-highlight', '');
this.body.node.setAttribute('class', newClass);

if (this.disconnectCallback) {
this.disconnectCallback(this);
}
}

connectWire(wire, pushToUndo = true) {
Expand Down Expand Up @@ -339,7 +339,6 @@ export class Point {
const newClass = this.body.node.getAttribute('class').replace(' highlight', '');
this.body.node.setAttribute('class', newClass);
}

outline() {
const newClass = `${this.body.node.getAttribute('class')} outline`;
this.body.node.setAttribute('class', newClass);
Expand Down
4 changes: 3 additions & 1 deletion ArduinoFrontend/src/app/Libs/UndoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,12 @@ export abstract class UndoUtils {
existing.transformPosition(-ele.dragJson.dx, -ele.dragJson.dy);
}
} else {
existing.transformPosition(ele.dragJson.dx, ele.dragJson.dy);
if (ele.keyName !== 'BreadBoard') {
existing.transformPosition(ele.dragJson.dx, ele.dragJson.dy);
Workspace.onDragEvent(existing);
Workspace.onDragStopEvent(existing);
} else {
existing.transformBoardPosition(ele.dragJson.dx, ele.dragJson.dy);
}
}
for (const ec in window.scope['wires']) {
Expand Down
Loading

0 comments on commit 0c18d51

Please sign in to comment.