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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
find_package(SDL2 CONFIG REQUIRED)
find_package(SDL2_ttf CONFIG REQUIRED)

add_definitions(-DROOT_DIR="${CMAKE_SOURCE_DIR}")

add_subdirectory(extern/pugixml-1.13)
add_subdirectory(extern/lorina/lib)

Expand Down
Binary file added assets/img/gates.bmp
Binary file not shown.
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ target_link_libraries(main
SDL2::SDL2
SDL2_ttf::SDL2_ttf
pugixml::pugixml
Lorina)
Lorina
cli11)
46 changes: 35 additions & 11 deletions src/layout.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,11 @@ void addAllDummyNodes(
}
}

TreeNode::Id Net::addNode() {
TreeNode::Id Net::addNode(Type type) {
Id id = static_cast<Id>(nodes.size());
nodes.emplace_back();
nodes.back().id = id;
nodes.back().type = type;

return id;
}
Expand Down Expand Up @@ -363,13 +364,19 @@ enum {

void initPositionAndSize(
std::vector<TreeNode> &nodes,
std::vector<NormalizedElement> &normalizedElements,
float nCellSize) {
std::vector<Element> &normalizedElements,
float nCellSize,
bool initDummy) {
for (TreeNode &node : nodes) {
NormalizedElement nElement = {};
Element nElement = {};
nElement.id = node.id;
nElement.scrType.setType(node.type);

if (node.isDummy) {
if (!initDummy) {
continue;
}

NormalizedPoint nPoint = {};
nPoint.nX = nCellSize * node.number +
(nCellSize / ReductionWidth) / ReductionRelationToGap;
Expand All @@ -393,13 +400,26 @@ void initPositionAndSize(
}
}

static TreeNode::Id
traceVirtualNode(TreeNode::Id originId, const std::vector<TreeNode> &nodes) {
const TreeNode *node = nodes.data() + originId;
while (node->isDummy) {
node = nodes.data() + node->succ[0];
}
return node->id;
}

void initConnections(
std::vector<TreeNode> &nodes,
std::vector<NormalizedElement> &normalizedElements) {
const std::vector<TreeNode> &nodes,
std::vector<Element> &normalizedElements,
bool initDummy) {
int countConnections = 0;
for (size_t i = 0; i < nodes.size(); i++) {
for (size_t &succId : nodes[i].succ) {
NormalizedConnection connection = {};
if (nodes[i].isDummy && !initDummy) {
continue;
}
for (size_t succId : nodes[i].succ) {
Connection connection = {};

connection.id = countConnections;
connection.startElementId = nodes[i].id;
Expand All @@ -411,6 +431,9 @@ void initConnections(
nPointStart.nY = normalizedElements[i].nPoint.nY +
normalizedElements[i].nH;

if (!initDummy) {
succId = traceVirtualNode(succId, nodes);
}
NormalizedPoint nPointEnd = {};
nPointEnd.nX = normalizedElements[succId].nPoint.nX +
normalizedElements[succId].nW / GetMiddle;
Expand All @@ -427,7 +450,8 @@ void initConnections(
}

void Net::netTreeNodesToNormalizedElements(
std::vector<NormalizedElement> &normalizedElements) {
std::vector<Element> &normalizedElements,
bool showDummy) {
float maxNumber = -1, maxLayer = -1;
for (TreeNode &node : nodes) {
if (node.layer > maxLayer) {
Expand All @@ -445,7 +469,7 @@ void Net::netTreeNodesToNormalizedElements(
nCellSize = 1 / (maxNumber + 1);
}

initPositionAndSize(nodes, normalizedElements, nCellSize);
initPositionAndSize(nodes, normalizedElements, nCellSize, showDummy);

initConnections(nodes, normalizedElements);
initConnections(nodes, normalizedElements, showDummy);
}
6 changes: 4 additions & 2 deletions src/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct TreeNode {
std::vector<Id> succ = {};
std::vector<Id> pred = {};
Id id = 0;
Type type = NONE;
int layer = 0;
int number = 0;
bool isDummy = false;
Expand All @@ -42,7 +43,7 @@ struct Net {
const std::vector<Id> &getSuccessors(Id id) const;
const std::vector<Id> &getPredecessors(Id id) const;

Id addNode();
Id addNode(Type type);

TreeNode *getNode(Id id) {
const Net &net = *this;
Expand All @@ -53,7 +54,8 @@ struct Net {

void assignLayers();
void netTreeNodesToNormalizedElements(
std::vector<NormalizedElement> &normalizedElements);
std::vector<Element> &normalizedElements,
bool showDummy);

std::vector<std::vector<TreeNode::Id>> getNodesByLayer();
};
Expand Down
Loading