Skip to content

Commit

Permalink
fixed delete all leaving selected object
Browse files Browse the repository at this point in the history
  • Loading branch information
pryvyd9 committed Feb 27, 2021
1 parent bb67a16 commit 39d3fe4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 46 deletions.
3 changes: 2 additions & 1 deletion CHANGE_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@
# 0.13.1
- introduced unique naming;
- fixed sine curve disappearing when rotation is nan;
- when switching between SinePen Step123 and Step132 the cross will move to the existant relevant point (optional);
- when switching between SinePen Step123 and Step132 the cross will move to the existant relevant point (optional);
- fixed delete all (Close) command leaving selected objects alive and rendered;
104 changes: 61 additions & 43 deletions StereoPlus2/DomainUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,56 @@ enum SelectPosition {
Rest = 0x10,
};

class ObjectSelection {
public:
using Selection = std::set<PON>;
private:
static Selection& selected() {
static Selection v;
return v;
}
static Event<const Selection&>& onChanged() {
static Event<const Selection&> v;
return v;
}
public:
static IEvent<const Selection&>& OnChanged() {
return onChanged();
}

static const Selection& Selected() {
return selected();
}
static const Selection** SelectedP() {
static const Selection* v = &selected();
return &v;
}

static void Set(SceneObject* o) {
selected().clear();
selected().emplace(o);
onChanged().Invoke(selected());
}
static void Set(const std::vector<SceneObject*>& os) {
selected().clear();
for (auto o : os)
selected().emplace(o);
onChanged().Invoke(selected());
}
static void Add(SceneObject* o) {
selected().emplace(o);
onChanged().Invoke(selected());
}
static void RemoveAll() {
selected().clear();
onChanged().Invoke(selected());
}
static void Remove(SceneObject* o) {
selected().erase(o);
onChanged().Invoke(selected());
}
};

class StateBuffer {
public:
// Buffer requires 1 additional state for saving current state.
Expand All @@ -22,6 +72,8 @@ class StateBuffer {
// Objects in their original order
std::vector<std::pair<SceneObject*, PON>> objects;

std::vector<SceneObject*> selection;

SceneObject* rootCopy;
};

Expand Down Expand Up @@ -57,6 +109,9 @@ class StateBuffer {
current->objects.push_back({ o.Get(), o });
current->copies[o.Get()] = o->Clone();
}

for (auto& o : ObjectSelection::Selected())
current->selection.push_back(o.Get());
}

// Erase saved copies.
Expand Down Expand Up @@ -102,6 +157,12 @@ class StateBuffer {
objects.push_back(b);
}

std::vector<SceneObject*> newSelection;
for (auto o : saved.selection)
newSelection.push_back(newCopies[o]);

ObjectSelection::Set(newSelection);

auto newRoot = saved.rootCopy->Clone();

newRoot->CallRecursive((SceneObject*)nullptr, std::function<SceneObject * (SceneObject*, SceneObject*)>([&](SceneObject* o, SceneObject* p) {
Expand Down Expand Up @@ -183,49 +244,6 @@ class StateBuffer {
}
};

class ObjectSelection {
public:
using Selection = std::set<PON>;
private:
static Selection& selected() {
static Selection v;
return v;
}
static Event<const Selection&>& onChanged() {
static Event<const Selection&> v;
return v;
}
public:
static IEvent<const Selection&>& OnChanged() {
return onChanged();
}

static const Selection& Selected() {
return selected();
}
static const Selection** SelectedP() {
static const Selection* v = &selected();
return &v;
}

static void Set(SceneObject* o) {
selected().clear();
selected().emplace(o);
onChanged().Invoke(selected());
}
static void Add(SceneObject* o) {
selected().emplace(o);
onChanged().Invoke(selected());
}
static void RemoveAll() {
selected().clear();
onChanged().Invoke(selected());
}
static void Remove(SceneObject* o) {
selected().erase(o);
onChanged().Invoke(selected());
}
};


class DragDropBuffer {
Expand Down
5 changes: 4 additions & 1 deletion StereoPlus2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ int main() {
});



ToolPool::Cross() = &cross;
ToolPool::Scene() = &scene;
ToolPool::KeyBinding() = &gui.keyBinding;
Expand All @@ -183,6 +182,10 @@ int main() {
if (!LocaleProvider::Init())
return false;

scene.OnDeleteAll() += [] {
ObjectSelection::RemoveAll();
};

// Position detector doesn't initialize itself
// so we need to help it.
positionDetector.onStartProcess = [&positionDetector] {
Expand Down
2 changes: 1 addition & 1 deletion StereoPlus2/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"language":"ua","ppi":92.56,"logFileName":"log.txt","stateBufferLength":100,"translationStep":1,"useDiscreteMovement":1,"rotationStep":1,"scalingStep":0.01,"mouseSensivity":0.01,"colorLeft":[1,0,0,1],"colorRight":[0,1,1,1],"dimmedColorLeft":[1,0,0,0.5],"dimmedColorRight":[0,1,1,0.5],"customRenderWindowAlpha":1,"shouldMoveCrossOnSinePenModeChange":1}
{"language":"ua","ppi":92.56,"logFileName":"log.txt","stateBufferLength":100,"translationStep":1,"useDiscreteMovement":1,"rotationStep":10,"scalingStep":0.01,"mouseSensivity":0.01,"colorLeft":[1,0,0,1],"colorRight":[0,1,1,1],"dimmedColorLeft":[1,0,0,0.5],"dimmedColorRight":[0,1,1,0.5],"customRenderWindowAlpha":1,"shouldMoveCrossOnSinePenModeChange":1}

0 comments on commit 39d3fe4

Please sign in to comment.