Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save different instances of subcircuits separately #74

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions src/cells/subcircuit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export const Subcircuit = Box.define('Subcircuit', {
}
}, {
initialize() {
this.bindAttrToProp('text.type/text', 'celltype');
if (!this.get('disp_celltype'))
this.set('disp_celltype', this.get('celltype'))
this.bindAttrToProp('text.type/text', 'disp_celltype');

const graph = this.get('graph');
console.assert(graph instanceof joint.dia.Graph);
Expand Down Expand Up @@ -102,7 +104,7 @@ export const Subcircuit = Box.define('Subcircuit', {
selector: 'type'
}
], Box.prototype.markupZoom),
_gateParams: Box.prototype._gateParams.concat(['celltype']),
_gateParams: Box.prototype._gateParams.concat(['celltype', 'disp_celltype']),
_unsupportedPropChanges: Box.prototype._unsupportedPropChanges.concat(['celltype'])
});

Expand Down
53 changes: 50 additions & 3 deletions src/circuit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,19 @@ export class HeadlessCircuit {
for (const elem of graph.getElements()) {
const args = ret.devices[elem.get('id')] = elem.getGateParams(layout);
if (!laid_out) delete args.position;
if (elem instanceof this._cells.Subcircuit && !subcircuits[elem.get('celltype')]) {
subcircuits[elem.get('celltype')] = fromGraph(elem.get('graph'));
if (elem instanceof this._cells.Subcircuit) {
const celltype = elem.get('celltype');
const subcircuit = {
dev: args,
graph: fromGraph(elem.get('graph'))
};
const prev_sub = subcircuits[celltype];
if (!prev_sub) {
subcircuits[celltype] = [subcircuit];
}
else {
prev_sub.push(subcircuit);
}
}
}
for (const elem of graph.getLinks()) {
Expand All @@ -302,7 +313,43 @@ export class HeadlessCircuit {
return ret;
}
const ret = fromGraph(this._graph);
ret.subcircuits = subcircuits;
ret.subcircuits = {};
for (const celltype in subcircuits) {
const subs = subcircuits[celltype];
const nsubs = subs.length;
if (nsubs == 1) {
// We check for conflict of generated names with
// both the original names and the new names
// so it's guaranteed that none of the original names conflict
// with the generated names
console.assert(!(celltype in ret.subcircuits));
ret.subcircuits[celltype] = subs[0].graph;
continue;
}
let cnt = -1;
const gen_name = () => {
while (true) {
const id = cnt++;
// Use the original name for the first one to keep the file closer
// to the old one.
if (id == -1)
return celltype;
const name = `${celltype}$${id}`;
if (name in subcircuits || name in ret.subcircuits)
continue;
return name;
}
};
for (let i = 0; i < nsubs; i++) {
const sub = subs[i];
// Rename, assign to return value, and fix the reference (celltype)
// in the device tree.
sub.dev.celltype = gen_name();
if (!sub.dev.disp_celltype && sub.dev.celltype !== celltype)
sub.dev.disp_celltype = celltype;
ret.subcircuits[sub.dev.celltype] = sub.graph;
}
}
return ret;
}
waitForWire(wire, trigger) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class Circuit extends HeadlessCircuit {
// subcircuit display
this.listenTo(paper, 'open:subcircuit', (model) => {
const div = $('<div>', {
title: model.get('celltype') + ' ' + model.get('label')
title: model.get('disp_celltype') + ' ' + model.get('label')
}).appendTo('html > body');
const pdiv = $('<div>').appendTo(div);
const graph = model.get('graph');
Expand Down