Skip to content

Commit

Permalink
Merge pull request #733 from TimRudy/Issue729
Browse files Browse the repository at this point in the history
#729: Hide or enable tri-state so it only appears for "advanced" users
  • Loading branch information
cavearr authored Apr 22, 2024
2 parents 66a221a + 4a858b4 commit d933c50
Show file tree
Hide file tree
Showing 13 changed files with 578 additions and 325 deletions.
27 changes: 9 additions & 18 deletions app/scripts/controllers/design.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,14 @@ angular
}
};

function loadSelectedGraph() {
utils.beginBlockingTask();
setTimeout(function(){
_decoupledLoadSelectedGraph();
},500);
}

function _decoupledLoadSelectedGraph() {


var n = graph.breadcrumbs.length;
var opt = { disabled: true };
var design = false;
Expand All @@ -166,8 +171,7 @@ angular
graph.resetView();
graph.loadDesign(design, opt, function () {
$scope.isNavigating = false;
graph.fitContent();

utils.endBlockingTask();
});
$scope.topModule = true;
}
Expand All @@ -191,24 +195,13 @@ angular
graph.fitContent();
graph.resetView();
graph.loadDesign(dependency.design, opt, function () {
graph.fitContent();
$scope.isNavigating = false;

utils.endBlockingTask();
});
$scope.information = dependency.package;
}
}



function loadSelectedGraph() {

utils.beginBlockingTask();
setTimeout(function(){
_decoupledLoadSelectedGraph();
},500);
}

$rootScope.$on('navigateProject', function (event, args) {
var opt = { disabled: true };
if (typeof args.submodule !== 'undefined') {
Expand All @@ -230,9 +223,7 @@ angular
graph.resetView();
project.update({ deps: false }, function () {
graph.loadDesign(args.project.design, opt, function () {

utils.endBlockingTask();

});

});
Expand Down
11 changes: 11 additions & 0 deletions app/scripts/controllers/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,17 @@ angular
}
};

$scope.toggleInoutPorts = function () {
const newState = !profile.get("allowInoutPorts");
profile.set("allowInoutPorts", newState);
if (newState) {
alertify.success(gettextCatalog.getString("Tri-state connections (inout ports) enabled"));
} else {
common.allowProjectInoutPorts = true; // if tri-state in current design, keep behaviour unchanged
alertify.success(gettextCatalog.getString("Tri-state connections (inout ports) disabled"));
}
};

$(document).on("langChanged", function (evt, lang) {
$scope.selectLanguage(lang);
});
Expand Down
83 changes: 58 additions & 25 deletions app/scripts/services/blockforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,18 @@ angular.module('icestudio')
//-- the OK button and all the data is ok.
//-- -cells: Array of blocks passed as arguments
//-------------------------------------------------------------------------
function newBasic(type, callback) {
function newBasic(type, allowInoutPorts, callback) {

let name = ''; //-- Port name by default
let clock = false; //-- Clock checkbox not checked by default
let inoutDefault;
let form;

//-- If inside a module, the FPGA-pin option is disabled
//-- The pins are always virtual
let disabled = common.isEditingSubmodule;

//-- The pins are always virtual
let virtual = disabled;
let clock = false; //-- Clock checkbox no checked by default
let name = ''; //-- Port name by default

//-- Create the block by calling the corresponding function
//-- according to the given type
Expand All @@ -72,14 +74,24 @@ angular.module('icestudio')
//-- Input port
case blocks.BASIC_INPUT:

form = new forms.FormBasicInput(name, virtual, clock, disabled);
//-- InOut-pin option is present or not, and if present, it defaults to false
if (allowInoutPorts) {
inoutDefault = false;
}

form = new forms.FormBasicInput(name, virtual, clock, disabled, inoutDefault);
newBasicPort(form, callback);
break;

//-- Output port
case blocks.BASIC_OUTPUT:

form = new forms.FormBasicOutput(name, virtual, disabled);
//-- InOut-pin option is present or not, and if present, it defaults to false
if (allowInoutPorts) {
inoutDefault = false;
}

form = new forms.FormBasicOutput(name, virtual, disabled, inoutDefault);
newBasicPort(form, callback);
break;

Expand Down Expand Up @@ -115,7 +127,12 @@ angular.module('icestudio')
//-- Code block
case blocks.BASIC_CODE:

form = new forms.FormBasicCode();
//-- Inout ports are present or not, and if present, the value is just initialized to empty string
if (allowInoutPorts) {
inoutDefault = '';
}

form = new forms.FormBasicCode('', '', '', inoutDefault, inoutDefault);
newBasicCode(form, callback);
break;

Expand Down Expand Up @@ -720,6 +737,7 @@ angular.module('icestudio')
}
for (o in instance.data.ports.inoutRight) {
port = instance.data.ports.inoutRight[o];
// (there's no port default rule for the right side, output)
rightPorts.push({
id: port.name,
name: port.name,
Expand Down Expand Up @@ -912,7 +930,7 @@ angular.module('icestudio')
//-- * cellView: Access to the graphics library
//-- * callback: Function to call when the block is Edited
//-----------------------------------------------------------------------
function editBasic(type, cellView, callback) {
function editBasic(type, allowInoutPorts, cellView, callback) {

//-- Get information from the joint graphics library
let block = cellView.model.attributes;
Expand All @@ -921,7 +939,7 @@ angular.module('icestudio')
let name = block.data.name + (block.data.range || '');
let virtual = block.data.virtual;
let clock = block.data.clock;
let inout = (typeof block.data.inout === 'undefined') ? false : block.data.inout;
let inoutValue;
let form;
let color = block.data.blockColor;

Expand All @@ -933,22 +951,27 @@ angular.module('icestudio')
virtual = true;
}

//-- InOut-pin option is present or not
if (allowInoutPorts) {
inoutValue = (typeof block.data.inout === 'undefined') ? false : !!block.data.inout;
}

//-- Call the corresponding function depending on the type of block
switch (type) {

//-- Input port
case blocks.BASIC_INPUT:

//-- Build the form, and pass the actual block data
form = new forms.FormBasicInput(name, virtual, clock, disabled, inout);
form = new forms.FormBasicInput(name, virtual, clock, disabled, inoutValue);
editBasicPort(form, cellView, callback);
break;

//-- Output port
case blocks.BASIC_OUTPUT:

//-- Build the form, and pass the actual block data
form = new forms.FormBasicOutput(name, virtual, disabled, inout);
form = new forms.FormBasicOutput(name, virtual, disabled, inoutValue);
editBasicPort(form, cellView, callback);
break;

Expand Down Expand Up @@ -977,7 +1000,7 @@ angular.module('icestudio')
break;

case blocks.BASIC_CODE:
editBasicCode(cellView, callback);
editBasicCode(allowInoutPorts, cellView, callback);
break;

case blocks.BASIC_INFO:
Expand Down Expand Up @@ -1380,33 +1403,43 @@ angular.module('icestudio')
}


function editBasicCode(cellView, callback) {
function editBasicCode(allowInoutPorts, cellView, callback) {

let inPortNames = '';
let outPortNames = '';
let inoutLeftPortNames;
let inoutRightPortNames;

//-- Get information from the joint graphics library
let block = cellView.model.attributes;

// Backward compatibility
// Compatibility between tri-state/non-tri-state project formats
if (typeof block.data.ports.inoutLeft === 'undefined') {
block.data.ports.inoutLeft = [];
block.data.ports.inoutRight = [];
}
//-- Get the input port names as a string
let inPortNames = blocks.portsInfo2Str(block.data.ports.in);

//-- Get the input port names as a string
if (block.data.ports.in) {
inPortNames = blocks.portsInfo2Str(block.data.ports.in);
}
//-- Get the output port names as a string
let outPortNames = blocks.portsInfo2Str(block.data.ports.out);
if (block.data.ports.out) {
outPortNames = blocks.portsInfo2Str(block.data.ports.out);
}

//-- Get the input param names as a string
let inParamNames = blocks.portsInfo2Str(block.data.params);

//-- Get the optional left/right InputOutput port names as strings
//-- InputOutput port name fields are present or not, and if present, are initialized to strings
if (allowInoutPorts) {
//-- Get the left side InputOutput port names as a string
inoutLeftPortNames = blocks.portsInfo2Str(block.data.ports.inoutLeft);


//-- Get the input/output port names at left side of block as a string
let inoutLeftPortNames = blocks.portsInfo2Str(block.data.ports.inoutLeft);

//-- Get the input/output port names at right side of block as a string
let inoutRightPortNames = blocks.portsInfo2Str(block.data.ports.inoutRight);

//-- Get the right side InputOutput port names as a string
inoutRightPortNames = blocks.portsInfo2Str(block.data.ports.inoutRight);
}

//-- Create the form
let form = new forms.FormBasicCode(
Expand Down Expand Up @@ -1467,7 +1500,7 @@ angular.module('icestudio')
//-- Get all the wires of the current block
let connectedWires = graph.getConnectedLinks(cellView.model);

//---------- Chage the block
//---------- Change the block
graph.startBatch('change');

//-- Remove the current block
Expand Down
54 changes: 33 additions & 21 deletions app/scripts/services/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ angular.module('icestudio')
//-- * Particular information:
//-- -clock: (bool). If the port is a clock or not
//-- * true: It is a clock signal
//-- * False: Normal signal
//-- * false: Normal signal
//-- -inout: (bool). If the port is inout or normal
//-- * true: It is tri-state
//-- * false: It is normal two-state
//-------------------------------------------------------------------------
class InputPortBlock extends PortBlock {

Expand All @@ -118,7 +121,6 @@ angular.module('icestudio')

//-- Particular information
this.data.clock = clock; //-- Optional. Is the port a clock input?

this.data.inout = inout;
}
}
Expand All @@ -128,7 +130,10 @@ angular.module('icestudio')
//-- Class: Output port. The information goes from the FPGA to the
//-- outside. Or from one block to another the upper level
//--
//-- NO particular information
//-- * Particular information:
//-- -inout: (bool). If the port is inout or normal
//-- * true: It is tri-state
//-- * false: It is normal two-state
//-------------------------------------------------------------------------
class OutputPortBlock extends PortBlock {

Expand Down Expand Up @@ -230,6 +235,8 @@ angular.module('icestudio')
//-- * inPortsInfo: Array of PortInfos
//-- * outPortsInfo: Array of PortInfos
//-- * inParamsInfo: Array of PortInfos
//-- * inoutLeftPortsInfo: Optional Array of PortInfos
//-- * inoutRightPortsInfo: Optional Array of PortInfos
//--
//-- PortInfos:
//-- * name: String
Expand Down Expand Up @@ -297,28 +304,33 @@ angular.module('icestudio')
this.data.params.push(info);

});
//-- Insert the InputOutput portInfo
inoutLeftPortsInfo.forEach(portInfo => {

let info = {
name: portInfo.name,
range: portInfo.rangestr,
size: portInfo.size > 1 ? portInfo.size : undefined
};
//-- Insert the InputOutput portInfo, left and/or right
if (inoutLeftPortsInfo) {
inoutLeftPortsInfo.forEach(portInfo => {

this.data.ports.inoutLeft.push(info);
});
//-- Insert the InputOutput portInfo
inoutRightPortsInfo.forEach(portInfo => {
let info = {
name: portInfo.name,
range: portInfo.rangestr,
size: portInfo.size > 1 ? portInfo.size : undefined
};

let info = {
name: portInfo.name,
range: portInfo.rangestr,
size: portInfo.size > 1 ? portInfo.size : undefined
};
this.data.ports.inoutLeft.push(info);
});
}

this.data.ports.inoutRight.push(info);
});
if (inoutRightPortsInfo) {
inoutRightPortsInfo.forEach(portInfo => {

let info = {
name: portInfo.name,
range: portInfo.rangestr,
size: portInfo.size > 1 ? portInfo.size : undefined
};

this.data.ports.inoutRight.push(info);
});
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions app/scripts/services/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ angular

// Project status: Has it change from the previous build or not?
this.hasChangesSinceBuild = false;
// Tri-state ports: Are they present in any opened designs or blocks, and is this approved?
// (User profile "allowInoutPorts" is false)
this.allowProjectInoutPorts = false;

// All project dependencies
this.allDependencies = {};
Expand Down
Loading

0 comments on commit d933c50

Please sign in to comment.