From 7786ed776fbf49ddfc69a3e0199451c6e85ca856 Mon Sep 17 00:00:00 2001 From: openshwprojects Date: Sat, 26 Nov 2022 13:23:28 +0100 Subject: [PATCH] sim: translate fix, VDD symbol --- src/sim/Junction.cpp | 8 +++++++- src/sim/Junction.h | 3 ++- src/sim/Simulation.cpp | 21 +++++++++++++++++++-- src/sim/Simulation.h | 2 ++ src/sim/Tool_Move.cpp | 17 ++++++++++++++++- src/sim/Tool_Move.h | 2 ++ src/sim/Wire.cpp | 2 +- 7 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/sim/Junction.cpp b/src/sim/Junction.cpp index 98faf5cdd..6b6227e7b 100644 --- a/src/sim/Junction.cpp +++ b/src/sim/Junction.cpp @@ -32,10 +32,16 @@ void CJunction::translateLinked(const Coord &o) { oj->setPosition(oj->getPosition() + o); } } +void CJunction::setPosLinked(const Coord &o) { + for (int i = 0; i < linked.size(); i++) { + CJunction *oj = linked[i]; + oj->setPosition(o); + } +} void CJunction::translate(const Coord &o) { if (hasLinkedOnlyWires()) { CShape::translate(o); - translateLinked(o); + setPosLinked(this->getPosition()); } } void CJunction::drawShape() { diff --git a/src/sim/Junction.h b/src/sim/Junction.h index fc71bb5af..d4d3db5f3 100644 --- a/src/sim/Junction.h +++ b/src/sim/Junction.h @@ -34,6 +34,8 @@ public: return "CJunction"; } virtual ~CJunction(); + void translateLinked(const Coord &o); + void setPosLinked(const Coord &o); void rotateDegreesAround_internal(float f, const Coord &p); void unlink(class CJunction *o); bool isWireJunction() const; @@ -45,7 +47,6 @@ public: } bool hasLinkedOnlyWires() const; virtual void translate(const Coord &o); - void translateLinked(const Coord &o); void addLink(CJunction *j) { linked.push_back(j); } diff --git a/src/sim/Simulation.cpp b/src/sim/Simulation.cpp index 205b5e964..a3d78d1a8 100644 --- a/src/sim/Simulation.cpp +++ b/src/sim/Simulation.cpp @@ -53,7 +53,7 @@ void CSimulation::createDemo() { addObject(generateWB3S())->setPosition(300, 200); addObject(generateButton())->setPosition(500, 260)->rotateDegreesAroundSelf(180); addObject(generateTest())->setPosition(500, 400); - addObject(generateGND())->setPosition(600, 400); + addObject(generateGND())->setPosition(600, 420); addWire(Coord(460, 260), Coord(380, 260)); addWire(Coord(540, 260), Coord(600, 260)); addWire(Coord(600, 400), Coord(600, 260)); @@ -63,17 +63,32 @@ void CSimulation::createDemo() { addObject(generateButton())->setPosition(600, 220)->rotateDegreesAroundSelf(180); addWire(Coord(640, 220), Coord(700, 220)); addWire(Coord(700, 400), Coord(700, 220)); - addObject(generateGND())->setPosition(700, 400); + addObject(generateGND())->setPosition(700, 420); //addObject(new CObject(new CCircle(800, 500, 100))); addObject(generateBulb())->setPosition(440, 140)->rotateDegreesAroundSelf(90); addWire(Coord(440, 60), Coord(440, 120)); addWire(Coord(440, 200), Coord(440, 160)); addWire(Coord(440, 200), Coord(380, 200)); + addObject(generateVDD())->setPosition(440, 60); + matchAllJunctions(); recalcBounds(); } +void CSimulation::matchAllJunctions() { + for (int i = 0; i < wires.size(); i++) { + CWire *w = wires[i]; + matchJunction(w); + } +} +class CObject *CSimulation::generateVDD() { + CObject *o = new CObject(); + o->addJunction(0, 0, "pad_a"); + o->addLine(0, -20, 0, 0); + o->addCircle(0, -30, 10); + return o; +} class CObject *CSimulation::generateGND() { CObject *o = new CObject(); o->addJunction(0, -20, "pad_a"); @@ -193,6 +208,8 @@ void CSimulation::tryMatchJunction(class CJunction *jn, class CJunction *oj) { return; if (oj == jn) return; + // cannot connect two objects directly without wire + // (in Eagle, such connection will automatically create wire, but let's keep it simple) if (oj->isWireJunction() == false && jn->isWireJunction() == false) return; if (oj->absPositionDistance(jn) < 1) { diff --git a/src/sim/Simulation.h b/src/sim/Simulation.h index 5ef9f10f5..50f708c50 100644 --- a/src/sim/Simulation.h +++ b/src/sim/Simulation.h @@ -15,7 +15,9 @@ public: class CObject *generateButton(); class CObject *generateTest(); class CObject *generateGND(); + class CObject *generateVDD(); void createDemo(); + void matchAllJunctions(); void drawSim(); class CObject *addObject(CObject *o); class CWire *addWire(const class Coord &a, const class Coord &b); diff --git a/src/sim/Tool_Move.cpp b/src/sim/Tool_Move.cpp index 74c6ab49d..d10c864b8 100644 --- a/src/sim/Tool_Move.cpp +++ b/src/sim/Tool_Move.cpp @@ -15,6 +15,20 @@ void Tool_Move::onMouseUp(const Coord &pos, int button) { void Tool_Move::onEnd() { sim->getCursorMgr()->setCursor(SDL_SYSTEM_CURSOR_ARROW); } +int Tool_Move::drawTextStats(int h) { + if (currentTarget) { + if (bMovingButtonHeld) { + h = drawText(20, h, "Moving %s", currentTarget->getClassName()); + } + else { + h = drawText(20, h, "Last target %s", currentTarget->getClassName()); + } + } + else { + h = drawText(20, h, "No target"); + } + return h; +} void Tool_Move::onMouseDown(const Coord &pos, int button) { if (button == SDL_BUTTON_LEFT) { currentTarget = sim->getShapeUnderCursor(); @@ -35,7 +49,8 @@ void Tool_Move::onMouseDown(const Coord &pos, int button) { } void Tool_Move::drawTool() { - if (sim->isMouseButtonHold(SDL_BUTTON_LEFT)) { + bMovingButtonHeld = sim->isMouseButtonHold(SDL_BUTTON_LEFT); + if (bMovingButtonHeld) { if (currentTarget != 0) { Coord nowPos = GetMousePos(); nowPos = roundToGrid(nowPos); diff --git a/src/sim/Tool_Move.h b/src/sim/Tool_Move.h index ea6c1c889..a304b8f90 100644 --- a/src/sim/Tool_Move.h +++ b/src/sim/Tool_Move.h @@ -6,6 +6,7 @@ #include "Coord.h" class Tool_Move : public Tool_Base { + bool bMovingButtonHeld; class CShape *currentTarget; Coord prevPos; public: @@ -13,6 +14,7 @@ public: virtual const char *getName() const { return "Move"; } + virtual int drawTextStats(int h); virtual void onEnd(); virtual void drawTool(); virtual void onMouseDown(const Coord &pos, int button); diff --git a/src/sim/Wire.cpp b/src/sim/Wire.cpp index a0813bb16..8dffede8a 100644 --- a/src/sim/Wire.cpp +++ b/src/sim/Wire.cpp @@ -16,7 +16,7 @@ CWire::~CWire() { } class CShape* CWire::findSubPart(const Coord &p) { for (int i = 0; i < junctions.size(); i++) { - if (p.isWithinDist(junctions[i]->getPosition(), 5)) + if (p.isWithinDist(junctions[i]->getPosition(), 15)) { return junctions[i]; }