Skip to content

Commit 8a27bd3

Browse files
committed
estimateCenter
1 parent 0cf160f commit 8a27bd3

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

src/backend/circuit/circuit.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ void Circuit::clear(bool clearUndoTree) {
2424
}
2525
}
2626

27+
Position Circuit::estimateCenter() const {
28+
for (auto& pair : blockContainer) {
29+
if (pair.second.getPosition().x != stackBottom.x) {
30+
return pair.second.getPosition();
31+
}
32+
}
33+
return Position();
34+
}
35+
2736
void Circuit::connectListener(void* object, CircuitDiffListenerFunction func, unsigned int priority) {
2837
listenerFunctions.emplace_back(object, priority, func);
2938
std::sort(listenerFunctions.begin(), listenerFunctions.end(), [](const CircuitDiffListenerData& a, const CircuitDiffListenerData& b) { return a.priority < b.priority; });
@@ -614,6 +623,9 @@ void Circuit::popOffStack(Position position, Orientation transformAmount, bool r
614623
const Block* block = blockContainer.getBlock(stackTop);
615624
if (!block) {
616625
logError("Can't find block on stack, this should never happen", "Circuit");
626+
if (stackTop.y > stackBottom.y) {
627+
stackTop.y--; // take one off the stack to try to save what I can
628+
}
617629
return;
618630
}
619631
stackTop.y -= block->size().h-1;

src/backend/circuit/circuit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class Circuit {
3737
bool isEditable() { return editable; }
3838
void setEditable(bool isEditable) { editable = isEditable; }
3939

40+
Position estimateCenter() const;
41+
4042
/* ----------- listener ----------- */
4143
// subject to change
4244
void connectListener(void* object, CircuitDiffListenerFunction func, unsigned int priority = 100);

src/backend/container/blockContainer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class BlockContainer {
117117
void removeBlockCells(const Block* block);
118118
block_id_t getNewId() { return ++lastId; }
119119

120+
120121
BlockType selfBlockType = BlockType::NONE;
121122
CircuitManager* circuitManager;
122123
BlockDataManager* blockDataManager;

src/gui/viewportManager/circuitView/viewManager/viewManager.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#include "viewManager.h"
22

3-
#include "backend/circuit/circuit.h"
4-
#include "../events/customEvents.h"
5-
#include "../events/eventRegister.h"
63
#include "backend/position/position.h"
4+
#include "../events/eventRegister.h"
5+
#include "../events/customEvents.h"
76

87
void ViewManager::setUpEvents(EventRegister& eventRegister) {
98
this->eventRegister = &eventRegister;

src/gui/viewportManager/circuitView/viewManager/viewManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef viewManager_h
22
#define viewManager_h
33

4-
#include "backend/circuit/circuit.h"
54
#include "backend/position/position.h"
5+
#include "backend/circuit/circuit.h"
66
#include "util/vec2.h"
77

88
class EventRegister;

0 commit comments

Comments
 (0)