Skip to content

Commit

Permalink
Clock and polarity markings.
Browse files Browse the repository at this point in the history
  • Loading branch information
tilk committed Aug 21, 2018
1 parent f448df5 commit 6298da2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
20 changes: 18 additions & 2 deletions src/cells/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ joint.shapes.digital.WireView = joint.dia.LinkView.extend({
joint.shapes.digital.Gate.define('digital.Box', {
attrs: {
'text.iolabel': { fill: 'black', 'y-alignment': 'middle', ref: '.body' },
'path.decor': { stroke: 'black', fill: 'transparent' }
}
}, {
addLabelledWire: function(args, lblmarkup, side, loc, port) {
Expand All @@ -215,8 +216,23 @@ joint.shapes.digital.Gate.define('digital.Box', {
const textattrs = {
'ref-y': loc, 'x-alignment': side, text: 'label' in port ? port.label : port.id
};
if (side == 'left') textattrs['ref-x'] = 5;
else if (side == 'right') textattrs['ref-dx'] = -5;
const dist = port.clock ? 10 : 5;
if (side == 'left') textattrs['ref-x'] = dist;
else if (side == 'right') textattrs['ref-dx'] = -dist;
if (port.polarity === false) textattrs['text-decoration'] = 'overline';
if (port.clock) {
console.assert(side == 'left');
let vpath = [
[0, -6],
[6, 0],
[0, 6]
];
const path = 'M' + vpath.map(l => l.join(' ')).join(' L');
lblmarkup.push('<path class="decor port_' + port.id + '" d="' + path + '" />');
_.set(args, ['attrs', 'path.decor.port_' + port.id], {
ref: '.body', 'ref-x': 0, 'ref-y': loc
});
}
_.set(args, ['attrs', 'text.iolabel.port_' + port.id], textattrs);
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions src/cells/dff.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ joint.shapes.digital.Box.define('digital.Dff', {
let num = 0;
markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'in', dir: 'in', bits: args.bits, label: 'D' }));
if ('clock' in args.polarity)
markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'clk', dir: 'in', bits: 1 }));
markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'clk', dir: 'in', bits: 1, polarity: args.polarity.clock, clock: true }));
if ('arst' in args.polarity)
markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'arst', dir: 'in', bits: 1 }));
markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'arst', dir: 'in', bits: 1, polarity: args.polarity.arst }));
if ('enable' in args.polarity)
markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'en', dir: 'in', bits: 1 }));
markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'en', dir: 'in', bits: 1, polarity: args.polarity.enable }));
markup.push('<g class="scalable"><rect class="body"/></g><text class="label"/>');
markup.push(lblmarkup.join(''));
markup.push('</g>');
Expand Down
8 changes: 4 additions & 4 deletions src/cells/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ joint.shapes.digital.Box.define('digital.Memory', {
markup.push(this.addLabelledWire(args, lblmarkup, 'right', num_y(num), { id: portname + 'data', dir: 'out', bits: args.bits, label: 'data' }));
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'addr', dir: 'in', bits: args.abits, label: 'addr' }));
if ('enable_polarity' in port)
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'en', dir: 'in', bits: 1, label: 'en' }));
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'en', dir: 'in', bits: 1, label: 'en', polarity: port.enable_polarity }));
if ('clock_polarity' in port) {
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'clk', dir: 'in', bits: 1, label: 'clk' }));
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'clk', dir: 'in', bits: 1, label: 'clk', polarity: port.clock_polarity, clock: true }));
this.last_clk[portname + 'clk'] = 0;
} else {
port.transparent = true;
Expand All @@ -51,9 +51,9 @@ joint.shapes.digital.Box.define('digital.Memory', {
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'data', dir: 'in', bits: args.bits, label: 'data' }));
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'addr', dir: 'in', bits: args.abits, label: 'addr' }));
if ('enable_polarity' in port)
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'en', dir: 'in', bits: args.bits, label: 'en' }));
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'en', dir: 'in', bits: args.bits, label: 'en', polarity: port.enable_polarity }));
if ('clock_polarity' in port) {
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'clk', dir: 'in', bits: 1, label: 'clk' }));
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'clk', dir: 'in', bits: 1, label: 'clk', polarity: port.clock_polarity, clock: true }));
this.last_clk[portname + 'clk'] = 0;
}
portsplits.push(num);
Expand Down

0 comments on commit 6298da2

Please sign in to comment.