Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/com/lushprojects/circuitjs1/client/BetterStringTokenizer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright (C) Paul Falstad and Iain Sharp

This file is part of CircuitJS1.

CircuitJS1 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

CircuitJS1 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with CircuitJS1. If not, see <http://www.gnu.org/licenses/>.
*/

package com.lushprojects.circuitjs1.client;

public class BetterStringTokenizer {

String delim;
String text;
int pos;
int tlen;
String token, tokenPreserveCase;

public BetterStringTokenizer(String text_, String delim_) {
text = text_;
delim = delim_;
pos = 0;
tlen = text.length();
while (pos < tlen && (text.charAt(pos) == ' ' || text.charAt(pos) == '\t'))
pos++;
}

String nextToken() {
if (pos == tlen) {
token = tokenPreserveCase = "";
return token;
}
int i = pos + 1;
int c = text.charAt(pos);
if (delim.indexOf(c) < 0) {
while (i < tlen && delim.indexOf(text.charAt(i)) < 0)
i++;
}
tokenPreserveCase = text.substring(pos, i);
token = tokenPreserveCase.toLowerCase();
pos = i;
while (pos < tlen && (text.charAt(pos) == ' ' || text.charAt(pos) == '\t'))
pos++;
return token;
}

String nextTokenPreserveCase() {
nextToken();
return tokenPreserveCase;
}

void setDelimiters(String d) {
delim = d;
}

boolean hasMoreTokens() {
return pos < tlen;
}
}
2 changes: 2 additions & 0 deletions src/com/lushprojects/circuitjs1/client/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public void menuPerformed(String menu, String item) {
app.imageExporter.doExportAsSVG();
if (item=="createsubcircuit")
doCreateSubcircuit();
if (item=="importfromspice")
new ImportFromSpiceDialog();
if (item=="dcanalysis")
doDCAnalysis();
if (item=="print")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class ExtListEntry {
ExtListEntry(String s, int n) { name = s; node = n; side = ChipElm.SIDE_W; }
ExtListEntry(String s, int n, int p, int sd) { name = s; node = n; pos = p; side = sd; }
void setName(String s) { name = s; }
String name;
int node, pos, side;
int busWidth = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,49 @@ public EditCompositeModelDialog() {
TextBox modelNameTextBox = null;
Choice scopeChoice = null;
Checkbox labelCheck = null;
public String defaultName;

// load an externally-built model (e.g. from SPICE import)
boolean loadModel(CustomCompositeModel m) {
model = m;
if (model.extList.size() == 0) {
Window.alert(Locale.LS("Device has no external inputs/outputs!"));
return false;
}
HashSet<Integer> nodeSet = new HashSet<Integer>();
Collections.sort(model.extList, new Comparator<ExtListEntry>() {
public int compare(ExtListEntry a, ExtListEntry b) {
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
}
});
int i;
int postCount = model.extList.size();
int sideCounts[] = new int[] { 0, 0, 0, 0 };
for (i = 0; i != postCount; i++) {
ExtListEntry pin = model.extList.get(i);
sideCounts[pin.side] += 1;
if (nodeSet.contains(pin.node)) {
Window.alert(Locale.LS("Can't have two input/output nodes connected!"));
return false;
}
nodeSet.add(pin.node);
}
int xOffsetLeft = (sideCounts[ChipElm.SIDE_W] > 0) ? 1 : 0;
int xOffsetRight = (sideCounts[ChipElm.SIDE_E] > 0) ? 1 : 0;
for (i = 0; i != postCount; i++) {
ExtListEntry pin = model.extList.get(i);
if (pin.side == ChipElm.SIDE_N || pin.side == ChipElm.SIDE_S) {
pin.pos += xOffsetLeft;
}
}
int minHeight = (sideCounts[ChipElm.SIDE_N] > 0 && sideCounts[ChipElm.SIDE_S] > 0) ? 2 : 1;
int minWidth = 2;
int pinsNS = Math.max(sideCounts[ChipElm.SIDE_N], sideCounts[ChipElm.SIDE_S]);
int pinsWE = Math.max(sideCounts[ChipElm.SIDE_W], sideCounts[ChipElm.SIDE_E]);
model.sizeX = Math.max(minWidth, pinsNS + xOffsetLeft + xOffsetRight);
model.sizeY = Math.max(minHeight, pinsWE);
return true;
}

static final int SCOPE_THIS_CIRCUIT = 0;
static final int SCOPE_THIS_SESSION = 1;
Expand Down Expand Up @@ -155,13 +198,14 @@ void createDialog() {
vp.add(new Label(Locale.LS("Model Name")));
modelNameTextBox = new TextBox();
vp.add(modelNameTextBox);
if (defaultName != null)
modelNameTextBox.setText(defaultName);
modelNameTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {
@Override
public void onValueChange(ValueChangeEvent<String> event) {
drawChip();
}
});
// modelNameTextBox.setText(model.name);
}

HorizontalPanel hp = new HorizontalPanel();
Expand Down
Loading
Loading