diff --git a/openBeken_win32_mvsc2017.vcxproj b/openBeken_win32_mvsc2017.vcxproj
index 3af536e94..cec773bd8 100644
--- a/openBeken_win32_mvsc2017.vcxproj
+++ b/openBeken_win32_mvsc2017.vcxproj
@@ -536,6 +536,7 @@
+
@@ -572,6 +573,7 @@
+
true
diff --git a/openBeken_win32_mvsc2017.vcxproj.filters b/openBeken_win32_mvsc2017.vcxproj.filters
index 003f66d3a..5587103ce 100644
--- a/openBeken_win32_mvsc2017.vcxproj.filters
+++ b/openBeken_win32_mvsc2017.vcxproj.filters
@@ -396,6 +396,9 @@
Simulator
+
+ Simulator
+
@@ -470,6 +473,9 @@
Simulator
+
+ Simulator
+
diff --git a/src/sim/Junction.h b/src/sim/Junction.h
index 2c8b53d55..ca7102cee 100644
--- a/src/sim/Junction.h
+++ b/src/sim/Junction.h
@@ -81,7 +81,7 @@ public:
void setPosLinked(const Coord &o);
void rotateDegreesAround_internal(float f, const Coord &p);
void unlink(class CJunction *o);
- bool isWireJunction() const;
+ virtual bool isWireJunction() const;
void clearLinks() {
linked.clear();
}
diff --git a/src/sim/Object.h b/src/sim/Object.h
index 6c251132f..3f74b9a38 100644
--- a/src/sim/Object.h
+++ b/src/sim/Object.h
@@ -2,14 +2,3 @@
#include "sim_local.h"
#include "Shape.h"
-class CObject : public CShape {
-public:
- CObject() {
-
- }
- CObject(CShape *s) {
- addShape(s);
- }
- virtual CShape *cloneShape();
- class CObject *cloneObject();
-};
diff --git a/src/sim/PrefabManager.cpp b/src/sim/PrefabManager.cpp
index 48ba5410e..db22c9387 100644
--- a/src/sim/PrefabManager.cpp
+++ b/src/sim/PrefabManager.cpp
@@ -8,16 +8,16 @@
#include "Controller_SimulatorLink.h"
#include "Junction.h"
-class CObject *PrefabManager::generateVDD() {
- CObject *o = new CObject();
+class CShape *PrefabManager::generateVDD() {
+ CShape *o = new CShape();
o->setName("VDD");
o->addJunction(0, 0, "VDD");
o->addLine(0, -20, 0, 0);
o->addCircle(0, -30, 10);
return o;
}
-class CObject *PrefabManager::generateGND() {
- CObject *o = new CObject();
+class CShape *PrefabManager::generateGND() {
+ CShape *o = new CShape();
o->setName("GND");
o->addJunction(0, -20, "GND");
o->addLine(0, -20, 0, 0);
@@ -27,8 +27,8 @@ class CObject *PrefabManager::generateGND() {
o->addLine(-4, 6, 4, 6);
return o;
}
-class CObject *PrefabManager::generateButton() {
- CObject *o = new CObject();
+class CShape *PrefabManager::generateButton() {
+ CShape *o = new CShape();
o->setName("Button");
CJunction *a = o->addJunction(-40, -10, "pad_a");
CJunction *b = o->addJunction(40, -10, "pad_b");
@@ -53,9 +53,9 @@ class CObject *PrefabManager::generateButton() {
o->translateEachChild(0, 10);
return o;
}
-class CObject *PrefabManager::generateTest() {
+class CShape *PrefabManager::generateTest() {
- CObject *o = new CObject();
+ CShape *o = new CShape();
o->setName("Test");
o->addLine(50, 10, -50, 10);
o->addLine(50, -10, -50, -10);
@@ -63,8 +63,8 @@ class CObject *PrefabManager::generateTest() {
o->addLine(-50, 10, -50, -10);
return o;
}
-class CObject *PrefabManager::generateWB3S() {
- CObject *o = new CObject();
+class CShape *PrefabManager::generateWB3S() {
+ CShape *o = new CShape();
o->setName("WB3S");
CControllerSimulatorLink *link = new CControllerSimulatorLink();
o->setController(link);
@@ -109,10 +109,10 @@ class CObject *PrefabManager::generateWB3S() {
}
return o;
}
-class CObject *PrefabManager::generateLED_CW() {
+class CShape *PrefabManager::generateLED_CW() {
float bulb_radius = 20.0f;
- CObject *o = new CObject();
+ CShape *o = new CShape();
o->setName("LED_CW");
o->addText(-40, -25, "CW");
//CShape *filler = o->addCircle(0, 0, bulb_radius);
@@ -135,10 +135,10 @@ class CObject *PrefabManager::generateLED_CW() {
o->addLine(-bulb_radius * mul, bulb_radius * mul, bulb_radius * mul, -bulb_radius * mul);
return o;
}
-class CObject *PrefabManager::generateLED_RGB() {
+class CShape *PrefabManager::generateLED_RGB() {
float bulb_radius = 20.0f;
- CObject *o = new CObject();
+ CShape *o = new CShape();
o->addText(-40, -25, "RGB");
o->setName("LED_RGB");
//CShape *filler = o->addCircle(0, 0, bulb_radius);
@@ -165,10 +165,10 @@ class CObject *PrefabManager::generateLED_RGB() {
return o;
}
-class CObject *PrefabManager::generateBulb() {
+class CShape *PrefabManager::generateBulb() {
float bulb_radius = 20.0f;
- CObject *o = new CObject();
+ CShape *o = new CShape();
o->addText(-40, -25, "Bulb");
o->setName("Bulb");
CShape *filler = o->addCircle(0, 0, bulb_radius);
@@ -191,21 +191,21 @@ class CObject *PrefabManager::generateBulb() {
}
-void PrefabManager::addPrefab(CObject *o) {
+void PrefabManager::addPrefab(CShape *o) {
prefabs.add_unique(o);
}
-CObject *PrefabManager::findPrefab(const char *name) {
+CShape *PrefabManager::findPrefab(const char *name) {
for (int i = 0; i < prefabs.size(); i++) {
if (prefabs[i]->hasName(name))
return prefabs[i];
}
return 0;
}
-CObject *PrefabManager::instantiatePrefab(const char *name) {
- CObject *ret = findPrefab(name);
+CShape *PrefabManager::instantiatePrefab(const char *name) {
+ CShape *ret = findPrefab(name);
if (ret == 0)
return 0;
- return ret->cloneObject();
+ return ret->cloneShape();
}
void PrefabManager::createDefaultPrefabs() {
diff --git a/src/sim/PrefabManager.h b/src/sim/PrefabManager.h
index c83035573..7481b8016 100644
--- a/src/sim/PrefabManager.h
+++ b/src/sim/PrefabManager.h
@@ -6,24 +6,24 @@
class PrefabManager {
class CSimulator *sim;
- TArray prefabs;
+ TArray prefabs;
- class CObject *generateLED_CW();
- class CObject *generateLED_RGB();
- class CObject *generateBulb();
- class CObject *generateWB3S();
- class CObject *generateButton();
- class CObject *generateTest();
- class CObject *generateGND();
- class CObject *generateVDD();
+ class CShape *generateLED_CW();
+ class CShape *generateLED_RGB();
+ class CShape *generateBulb();
+ class CShape *generateWB3S();
+ class CShape *generateButton();
+ class CShape *generateTest();
+ class CShape *generateGND();
+ class CShape *generateVDD();
public:
PrefabManager(CSimulator *ps) {
sim = ps;
}
void createDefaultPrefabs();
- void addPrefab(CObject *o);
- CObject *findPrefab(const char *name);
- CObject *instantiatePrefab(const char *name);
+ void addPrefab(CShape *o);
+ CShape *findPrefab(const char *name);
+ CShape *instantiatePrefab(const char *name);
};
#endif
diff --git a/src/sim/SaveLoad.cpp b/src/sim/SaveLoad.cpp
index 57a8d0249..6712e7643 100644
--- a/src/sim/SaveLoad.cpp
+++ b/src/sim/SaveLoad.cpp
@@ -60,7 +60,7 @@ class CSimulation *CSaveLoad::loadSimulationFromFile(const char *fname) {
int rotInteger = rot->valuedouble;
rotInteger %= 360;
- CObject *o = sim->getPfbs()->instantiatePrefab(jName->valuestring);
+ CShape *o = sim->getPfbs()->instantiatePrefab(jName->valuestring);
o->setPosition(jX->valuedouble, jY->valuedouble);
s->addObject(o);
o->rotateDegreesAroundSelf(rotInteger);
@@ -84,7 +84,7 @@ void CSaveLoad::saveSimulationToFile(class CSimulation *simToSave, const char *f
cJSON *main_sim = cJSON_AddObjectToObject(root_sim, "simulation");
cJSON *main_objects = cJSON_AddObjectToObject(main_sim, "objects");
for (int i = 0; i < simToSave->getObjectsCount(); i++) {
- CObject *obj = simToSave->getObject(i);
+ CShape *obj = simToSave->getObject(i);
cJSON *j_obj = cJSON_AddObjectToObject(main_objects, "object");
const Coord &pos = obj->getPosition();
float rot = obj->getRotationAccum();
diff --git a/src/sim/Shape.h b/src/sim/Shape.h
index 7a7a9f156..ddea4af16 100644
--- a/src/sim/Shape.h
+++ b/src/sim/Shape.h
@@ -43,6 +43,9 @@ public:
void snapToGrid();
void cloneShapeTo(CShape *o);
virtual CShape *cloneShape();
+ virtual bool isWireJunction() const {
+ return false;
+ }
void setFill(bool b) {
bFill = b;
}
diff --git a/src/sim/Simulation.cpp b/src/sim/Simulation.cpp
index 4899bb3f0..815d58a8a 100644
--- a/src/sim/Simulation.cpp
+++ b/src/sim/Simulation.cpp
@@ -4,6 +4,7 @@
#include "Object.h"
#include "Wire.h"
#include "Junction.h"
+#include "Text.h"
#include "Simulator.h"
#include "PrefabManager.h"
@@ -97,7 +98,12 @@ void CSimulation::registerJunctions(class CShape *s) {
registerJunctions(s2);
}
}
-CObject * CSimulation::addObject(CObject *o) {
+class CText *CSimulation::addText(const class Coord &p, const char *txt) {
+ CText *txtObject = new CText(p, txt);
+ addObject(txtObject);
+ return txtObject;
+}
+CShape * CSimulation::addObject(CShape *o) {
if (o == 0) {
return 0;
}
@@ -106,13 +112,13 @@ CObject * CSimulation::addObject(CObject *o) {
return o;
}
void CSimulation::createDemoOnlyWB3S() {
- CObject *wb3s = addObject(sim->getPfbs()->instantiatePrefab("WB3S"));
+ CShape *wb3s = addObject(sim->getPfbs()->instantiatePrefab("WB3S"));
wb3s->setPosition(300, 200);
matchAllJunctions();
recalcBounds();
}
void CSimulation::createDemo() {
- CObject *wb3s = addObject(sim->getPfbs()->instantiatePrefab("WB3S"));
+ CShape *wb3s = addObject(sim->getPfbs()->instantiatePrefab("WB3S"));
wb3s->setPosition(300, 200);
addObject(sim->getPfbs()->instantiatePrefab("Button"))->setPosition(500, 260)->rotateDegreesAroundSelf(180);
addObject(sim->getPfbs()->instantiatePrefab("Test"))->setPosition(500, 400);
@@ -133,8 +139,8 @@ void CSimulation::createDemo() {
addWire(Coord(640, 240), Coord(700, 240));
addWire(Coord(700, 400), Coord(700, 240));
addObject(sim->getPfbs()->instantiatePrefab("GND"))->setPosition(700, 420);
- //addObject(new CObject(new CCircle(800, 500, 100)));
- CObject *bulb2 = addObject(sim->getPfbs()->instantiatePrefab("Bulb"));
+ //addObject(new CShape(new CCircle(800, 500, 100)));
+ CShape *bulb2 = addObject(sim->getPfbs()->instantiatePrefab("Bulb"));
bulb2->setPosition(440, 140)->rotateDegreesAroundSelf(90);
addObject(sim->getPfbs()->instantiatePrefab("LED_CW"))->setPosition(560, 140)->rotateDegreesAroundSelf(90);
@@ -145,12 +151,12 @@ void CSimulation::createDemo() {
addWire(Coord(440, 200), Coord(380, 200));
addObject(sim->getPfbs()->instantiatePrefab("VDD"))->setPosition(440, 60);
- CObject *bulb2_copy = bulb2->cloneObject();
+ CShape *bulb2_copy = bulb2->cloneShape();
bulb2_copy->setPosition(640, 140);
addObject(bulb2_copy);
if (0) {
- CObject *wb3s_copy = wb3s->cloneObject();
+ CShape *wb3s_copy = wb3s->cloneShape();
wb3s_copy->setPosition(640, 440);
addObject(wb3s_copy);
}
@@ -158,15 +164,6 @@ void CSimulation::createDemo() {
matchAllJunctions();
recalcBounds();
}
-CShape *CObject::cloneShape() {
- CObject *no = new CObject();
- this->cloneShapeTo(no);
- return no;
-}
-class CObject *CObject::cloneObject() {
- CShape *sh = cloneShape();
- return dynamic_cast(sh);
-}
void CSimulation::matchAllJunctions() {
for (int i = 0; i < wires.size(); i++) {
CWire *w = wires[i];
@@ -243,13 +240,13 @@ void CSimulation::destroyObject(CShape *s) {
}
ed = dynamic_cast(s);
if (ed) {
- delete w;
- wires.remove(w);
}
+ delete w;
+ wires.remove(w);
}
else {
removeJunctions(s);
- CObject *o = dynamic_cast(s);
+ CShape *o = dynamic_cast(s);
if (o != 0) {
delete o;
objects.remove(o);
diff --git a/src/sim/Simulation.h b/src/sim/Simulation.h
index c88f74c7e..35844f6da 100644
--- a/src/sim/Simulation.h
+++ b/src/sim/Simulation.h
@@ -6,7 +6,7 @@
class CSimulation {
class CSimulator *sim;
// all allocated objects (must be fried later)
- TArray objects;
+ TArray objects;
// all allocated wires (must be fried later)
TArray wires;
// only pointers to junctions that belongs to allocated objects or wires
@@ -25,7 +25,7 @@ public:
int getObjectsCount() const {
return objects.size();
}
- class CObject *getObject(int i) {
+ class CShape *getObject(int i) {
return objects[i];
}
int getWiresCount() const {
@@ -46,7 +46,8 @@ public:
void createDemoOnlyWB3S();
void matchAllJunctions();
void drawSim();
- class CObject *addObject(class CObject *o);
+ class CShape *addObject(class CShape *o);
+ class CText *addText(const class Coord &p, const char *txt);
class CWire *addWire(const class Coord &a, const class Coord &b);
class CWire *addWire(float x0, float y0, float x1, float y1);
class CShape *findShapeByBoundsPoint(const class Coord &p);
diff --git a/src/sim/Simulator.cpp b/src/sim/Simulator.cpp
index c4ed254bc..d0a4d7625 100644
--- a/src/sim/Simulator.cpp
+++ b/src/sim/Simulator.cpp
@@ -12,6 +12,7 @@
#include "Tool_Move.h"
#include "Tool_Info.h"
#include "Tool_Copy.h"
+#include "Tool_Text.h"
#include "Simulation.h"
#include "CursorManager.h"
#include "PrefabManager.h"
@@ -344,6 +345,9 @@ void CSimulator::onKeyDown(int keyCode) {
if (keyCode == '6') {
setTool(new Tool_Info());
}
+ if (keyCode == '7') {
+ setTool(new Tool_Text());
+ }
//SDL_Cursor* cursor;
//cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR);
//SDL_SetCursor(cursor);
diff --git a/src/sim/Text.h b/src/sim/Text.h
index b2c33e0b7..0ed494ded 100644
--- a/src/sim/Text.h
+++ b/src/sim/Text.h
@@ -11,6 +11,10 @@ class CText : public CShape {
public:
CText() {
+ }
+ CText(const Coord &np, const char *s) {
+ this->setPosition(np);
+ this->txt = s;
}
CText(int _x, int _y, const char *s) {
this->setPosition(_x, _y);
diff --git a/src/sim/Tool_Copy.cpp b/src/sim/Tool_Copy.cpp
index 53778f5bb..7f5052344 100644
--- a/src/sim/Tool_Copy.cpp
+++ b/src/sim/Tool_Copy.cpp
@@ -21,9 +21,11 @@ Tool_Copy::~Tool_Copy() {
void Tool_Copy::onMouseDown(const Coord &pos, int button) {
if (copyingObject == 0) {
CShape *s = sim->getShapeUnderCursor();
- CObject *o = dynamic_cast(s);
- if (o != 0) {
- copyingObject = o->cloneObject();
+ if (s != 0) {
+ // can it be copied? you can't copy wires
+ if (s->isWireJunction() == false && s->isWire() == false) {
+ copyingObject = s->cloneShape();
+ }
}
}
else {
diff --git a/src/sim/Tool_Copy.h b/src/sim/Tool_Copy.h
index 734dc7732..c7c4935d7 100644
--- a/src/sim/Tool_Copy.h
+++ b/src/sim/Tool_Copy.h
@@ -6,7 +6,7 @@
#include "Coord.h"
class Tool_Copy : public Tool_Base {
- class CObject *copyingObject;
+ class CShape *copyingObject;
Coord prevMousePos;
public:
Tool_Copy();
diff --git a/src/sim/Tool_Text.cpp b/src/sim/Tool_Text.cpp
new file mode 100644
index 000000000..d32daa573
--- /dev/null
+++ b/src/sim/Tool_Text.cpp
@@ -0,0 +1,33 @@
+#ifdef WINDOWS
+#include "Tool_Text.h"
+#include "Simulator.h"
+#include "Simulation.h"
+#include "Shape.h"
+#include "CursorManager.h"
+
+Tool_Text::Tool_Text() {
+ currentTarget = 0;
+}
+void Tool_Text::onMouseUp(const Coord &pos, int button) {
+
+}
+void Tool_Text::onEnd() {
+}
+int Tool_Text::drawTextStats(int h) {
+ return h;
+}
+void Tool_Text::onMouseDown(const Coord &pos, int button) {
+ currentTarget = sim->getSim()->addText(pos, "TEXT");
+
+}
+void Tool_Text::drawTool() {
+
+
+}
+
+
+
+#endif
+
+
+
diff --git a/src/sim/Tool_Text.h b/src/sim/Tool_Text.h
new file mode 100644
index 000000000..f737d08d3
--- /dev/null
+++ b/src/sim/Tool_Text.h
@@ -0,0 +1,23 @@
+#ifndef __TOOL_TEXT_H__
+#define __TOOL_TEXT_H__
+
+#include "sim_local.h"
+#include "Tool_Base.h"
+#include "Coord.h"
+
+class Tool_Text : public Tool_Base {
+ class CText *currentTarget;
+public:
+ Tool_Text();
+ virtual const char *getName() const {
+ return "Text";
+ }
+ virtual int drawTextStats(int h);
+ virtual void onEnd();
+ virtual void drawTool();
+ virtual void onMouseDown(const Coord &pos, int button);
+ virtual void onMouseUp(const Coord &pos, int button);
+};
+
+
+#endif // __TOOL_TEXT_H__