Skip to content

Commit 0ad6e3e

Browse files
committed
Adding current probe
1 parent f9ab345 commit 0ad6e3e

11 files changed

Lines changed: 448 additions & 150 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var shapeIprobe = draw2d.SVGFigure.extend({
2+
init: function (attr) {
3+
this._super(extend({ width: 64, height: 32 }, attr));
4+
this.ressvgs = `
5+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-1 -1 139 71">
6+
<path stroke-linecap="round" fill="none" stroke="#000" stroke-miterlimit="10" stroke-width="10" d="M2,60h48m32,0h48m-80,-16v16m32,-16v16" pointer-events="stroke"/>
7+
<path stroke-linecap="round" fill="#FFF" stroke="#000" stroke-width="10" d="M26,0h80v44h-80z" pointer-events="all"/>
8+
</svg>
9+
`;
10+
},
11+
getSVG: function () {
12+
return this.ressvgs;
13+
},
14+
});

circuitSolver/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<script src="images/shapeVin.js"></script>
3838
<script src="images/shapeIin.js"></script>
3939
<script src="images/shapeVout.js"></script>
40+
<script src="images/shapeIprobe.js"></script>
4041
<script src="images/shapeInductor.js"></script>
4142
<script src="images/opAmp.js"></script>
4243
<link href="style.css" rel="stylesheet" />

circuitSolver/js/draw2d.js

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

circuitSolver/js/startupSchematic.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
var startupSchematic =[
22
{
33
"type": "component",
4-
"firstLetter": "v",
4+
"id": "vin",
55
"x": 128,
66
"y": 144
77
},
88
{
99
"type": "component",
10-
"firstLetter": "L",
10+
"id": "L0",
1111
"x": 192,
1212
"y": 80
1313
},
1414
{
1515
"type": "component",
16-
"firstLetter": "R",
16+
"id": "R0",
1717
"x": 352,
1818
"y": 80
1919
},
2020
{
2121
"type": "component",
22-
"firstLetter": "C",
22+
"id": "C0",
2323
"x": 416,
2424
"y": 112
2525
},
2626
{
2727
"type": "component",
28-
"firstLetter": "g",
28+
"id": "gnd",
2929
"x": 416,
3030
"y": 192
3131
},
3232
{
3333
"type": "component",
34-
"firstLetter": "x",
34+
"id": "xvout",
3535
"x": 352,
3636
"y": 16
3737
},

circuitSolver/modules/View.js

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class View extends draw2d.Canvas {
2121
this.rCounter = 0;
2222
this.cCounter = 0;
2323
this.lCounter = 0;
24+
this.iprbCounter = 0;
2425
this.elements = [];
2526
this.dropCb = dropCB;
2627
this.getElements = getElements;
@@ -58,7 +59,7 @@ export class View extends draw2d.Canvas {
5859
} else return name;
5960
}
6061

61-
addShapeToSchem(type, x, y) {
62+
addShapeToSchem(type, x, y, id) {
6263
// console.log(type, x, y)
6364
// console.log(this.getElements());
6465

@@ -82,6 +83,17 @@ export class View extends draw2d.Canvas {
8283
},
8384
});
8485

86+
if (id) {
87+
if ((type == "res") || (type == "cap") || (type == "ind") || (type == "iprobe") || (type == "op")) {
88+
var newCount = parseInt(id.slice(1))
89+
if (type == "res") this.rCounter = Math.max(this.rCounter, newCount);
90+
if (type == "cap") this.cCounter = Math.max(this.cCounter, newCount);
91+
if (type == "ind") this.lCounter = Math.max(this.lCounter, newCount);
92+
if (type == "iprobe") this.iprbCounter = Math.max(this.iprbCounter, newCount);
93+
if (type == "op") this.opCounter = Math.max(this.opCounter, newCount);
94+
}
95+
}
96+
8597
// console.log(x, y)
8698
x = 16 * Math.round(x / 16);
8799
y = 16 * Math.round(y / 16);
@@ -92,7 +104,8 @@ export class View extends draw2d.Canvas {
92104
var outputLocator = new MyInputPortLocator(48, 16);
93105
e.createPort("hybrid", inputLocator);
94106
e.createPort("hybrid", outputLocator);
95-
e.id = `R${this.rCounter}`;
107+
if (id) e.id = id;
108+
else e.id = `R${this.rCounter}`;
96109
e.add(new draw2d.shape.basic.Text({ text: this.getName(e.id, this.getElements()), stroke: 0 }), new draw2d.layout.locator.TopLocator());
97110
this.rCounter = this.rCounter + 1;
98111
e.installEditPolicy(new SelectionMenuPolicy());
@@ -102,7 +115,8 @@ export class View extends draw2d.Canvas {
102115
var outputLocator = new MyInputPortLocator(16, 48);
103116
e.createPort("hybrid", inputLocator);
104117
e.createPort("hybrid", outputLocator);
105-
e.id = `C${this.cCounter}`;
118+
if (id) e.id = id;
119+
else e.id = `C${this.cCounter}`;
106120
e.add(new draw2d.shape.basic.Text({ text: this.getName(e.id, this.getElements()), stroke: 0 }), new draw2d.layout.locator.RightLocator());
107121
this.cCounter = this.cCounter + 1;
108122
e.installEditPolicy(new SelectionMenuPolicy());
@@ -112,7 +126,8 @@ export class View extends draw2d.Canvas {
112126
var outputLocator = new MyInputPortLocator(65, 16);
113127
e.createPort("hybrid", inputLocator);
114128
e.createPort("hybrid", outputLocator);
115-
e.id = `L${this.lCounter}`;
129+
if (id) e.id = id;
130+
else e.id = `L${this.lCounter}`;
116131
e.add(new draw2d.shape.basic.Text({ text: this.getName(e.id, this.getElements()), stroke: 0 }), new draw2d.layout.locator.TopLocator());
117132
this.lCounter = this.lCounter + 1;
118133
e.installEditPolicy(new SelectionMenuPolicy());
@@ -139,6 +154,17 @@ export class View extends draw2d.Canvas {
139154
e.createPort("hybrid", inputLocator);
140155
// e.createPort("hybrid",outputLocator);
141156
e.id = `xvout`;
157+
} else if (type == "iprobe") {
158+
var e = new shapeIprobe({ x: x, y: y });
159+
var inputLocator = new MyInputPortLocator(0, 32);
160+
e.createPort("hybrid", inputLocator);
161+
e.createPort("hybrid", new MyInputPortLocator(64, 32));
162+
// e.createPort("hybrid",outputLocator);
163+
if (id) e.id = id;
164+
else e.id = `Y${this.iprbCounter}`;
165+
e.add(new draw2d.shape.basic.Text({ text: this.getName(`iPrb${this.iprbCounter}`, this.getElements()), stroke: 0 }), new draw2d.layout.locator.TopLocator());
166+
this.iprbCounter = this.iprbCounter + 1;
167+
142168
} else if (type == "op") {
143169
var e = new shapeOpamp({ x: x, y: y });
144170
var inputALocator = new MyInputPortLocator(0, 32);
@@ -147,16 +173,17 @@ export class View extends draw2d.Canvas {
147173
e.createPort("hybrid", inputALocator);
148174
e.createPort("hybrid", inputBLocator);
149175
e.createPort("hybrid", outputLocator);
150-
e.id = `op${this.opCounter}`;
176+
if (id) e.id = id;
177+
else e.id = `op${this.opCounter}`;
151178
this.opCounter = this.opCounter + 1;
152179
} else console.log("ERROR: You gave a bad type: ", type);
153180

154181
this.x = x;
155182
this.y = y;
156183
e.resizeable = false;
184+
// console.log('add', add);
157185
var add = this.dropCb(e, (a) => this.addToSchematic(a));
158186
// add = true;
159-
// console.log('add', add);
160187

161188
// if (add) {
162189
// e.resizeable = false;
@@ -175,6 +202,7 @@ export class View extends draw2d.Canvas {
175202
this.cCounter = 0;
176203
this.lCounter = 0;
177204
this.opCounter = 0;
205+
this.iprbCounter = 0;
178206
console.log("cleared, now adding this", startupSchematic);
179207

180208
var connections = [];
@@ -188,18 +216,22 @@ export class View extends draw2d.Canvas {
188216
connections.push(newConn);
189217
id = id + 1;
190218
} else {
219+
// console.log(item)
191220
var type;
192-
var firstLetter = item.firstLetter;
221+
var firstLetter = Array.from(item.id)[0];
222+
223+
// var firstLetter = item.firstLetter;
193224
if (firstLetter == "R") type = "res";
194225
else if (firstLetter == "C") type = "cap";
195226
else if (firstLetter == "L") type = "ind";
196227
else if (firstLetter == "g") type = "gnd";
197228
else if (firstLetter == "v") type = "vin";
198229
else if (firstLetter == "i") type = "iin";
199230
else if (firstLetter == "x") type = "xvout";
231+
else if (firstLetter == "Y") type = "iprobe";
200232
// console.log(item, type)
201233

202-
this.addShapeToSchem(type, item.x, item.y);
234+
this.addShapeToSchem(type, item.x, item.y, item.id);
203235
}
204236
});
205237

0 commit comments

Comments
 (0)