Skip to content

Commit da37b4f

Browse files
committed
more powerful bus creation ui
1 parent 1f25729 commit da37b4f

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

src/backend/blockData/blockDataManager.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,19 @@ void BlockDataManager::initializeDefaults() {
252252
}
253253

254254
BlockType BlockDataManager::getBusBlock(unsigned int bitWidth) {
255+
return getBusBlock(bitWidth, 1);
256+
}
257+
258+
BlockType BlockDataManager::getBusBlock(unsigned int numInputs, unsigned int inputBitwidth) {
255259
std::vector<BusConnectionData> busConnections;
256-
for (unsigned int i = 0; i < bitWidth; i++) {
257-
busConnections.emplace_back(Vector(0, i), std::vector<unsigned int>{ i });
260+
for (unsigned int i = 0; i < numInputs; i++) {
261+
std::vector<unsigned int> bitConfig;
262+
for (unsigned int j = 0; j < inputBitwidth; j++) {
263+
bitConfig.push_back(i * inputBitwidth + j);
264+
}
265+
busConnections.emplace_back(Vector(0, i), bitConfig);
258266
}
259-
busConnections.emplace_back(Vector(1, 0), bitWidth);
267+
busConnections.emplace_back(Vector(1, 0), numInputs * inputBitwidth);
260268
return getBusBlock(busConnections);
261269
}
262270

src/backend/blockData/blockDataManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class BlockDataManager {
140140
}
141141

142142
BlockType getBusBlock(unsigned int bitwith);
143+
BlockType getBusBlock(unsigned int numInputs, unsigned int inputBitwidth);
143144
struct BusConnectionData {
144145
Vector positionOnBlock;
145146
std::variant<unsigned int, std::vector<unsigned int>> bitConfiguration = static_cast<unsigned int>(1);

src/gui/mainWindow/sideBar/selector/selectorWindow.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,21 @@ SelectorWindow::SelectorWindow(
5656
this->toolManagerManager->setBlock(selectedProceduralCircuit->getBlockType(proceduralCircuitParameters));
5757
} else if (selectedBus) {
5858
Rml::Element* parametersElement = parameterMenu->GetElementById("parameter-menu-parameters");
59-
assert(parametersElement->GetNumChildren() == 1);
59+
assert(parametersElement->GetNumChildren() == 2);
6060
Rml::ElementList elements;
61-
parametersElement->GetFirstChild()->GetElementsByClassName(elements, "parameter-input");
62-
Rml::ElementFormControlInput* parameterInput = rmlui_dynamic_cast<Rml::ElementFormControlInput*>(elements[0]);
63-
std::string str = parameterInput->GetValue();
61+
parametersElement->GetChild(0)->GetElementsByClassName(elements, "parameter-input");
62+
Rml::ElementFormControlInput* numInputsInput = rmlui_dynamic_cast<Rml::ElementFormControlInput*>(elements[0]);
63+
elements.clear();
64+
parametersElement->GetChild(1)->GetElementsByClassName(elements, "parameter-input");
65+
Rml::ElementFormControlInput* inputBitWidthInput = rmlui_dynamic_cast<Rml::ElementFormControlInput*>(elements[0]);
66+
std::string numInputsStr = numInputsInput->GetValue();
67+
std::string inputBitWidthStr = inputBitWidthInput->GetValue();
6468
try {
65-
int value = std::stoi(str);
66-
67-
this->toolManagerManager->setBlock(this->blockDataManager->getBusBlock(value));
69+
int numInputs = std::stoi(numInputsStr);
70+
int inputBitWidth = std::stoi(inputBitWidthStr);
71+
this->toolManagerManager->setBlock(this->blockDataManager->getBusBlock(numInputs, inputBitWidth));
6872
} catch (std::exception const& ex) {
69-
logError("Invalid bus bit width {}. {}", "", str, ex.what());
73+
logError("Invalid bus parameters: {} inputs of {} bits each. {}", "", numInputsStr, inputBitWidthStr, ex.what());
7074
return;
7175
}
7276
}
@@ -239,7 +243,8 @@ void SelectorWindow::setupBusParameterMenu() {
239243
return;
240244
}
241245
ProceduralCircuitParameters parameters;
242-
parameters.parameters.emplace("Bit Width", 8);
246+
parameters.parameters.emplace("Number of Ports", 8);
247+
parameters.parameters.emplace("Port Bit Widths", 1);
243248
addParametersToParameterMenu(parameters, "Bus");
244249
}
245250

0 commit comments

Comments
 (0)