Browse Source

Add undo operation with MoveSurfaceVertexCommand

master
Krisjanis Rijnieks 10 years ago
parent
commit
ce6588d296
  1. 6
      example/example.xcodeproj/project.pbxproj
  2. 2
      src/Commands/MoveSurfaceCommand.cpp
  3. 31
      src/Commands/MoveSurfaceVertexCommand.cpp
  4. 34
      src/Commands/MoveSurfaceVertexCommand.h
  5. 12
      src/Surfaces/SurfaceManagerGui.cpp
  6. 1
      src/Surfaces/SurfaceManagerGui.h
  7. 4
      src/UserInterface/ProjectionEditor.cpp
  8. 1
      src/UserInterface/ProjectionEditor.h

6
example/example.xcodeproj/project.pbxproj

@ -25,6 +25,7 @@
39A9AAE01B04E78600AA83BC /* RemoveSurfaceCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A9AADE1B04E78600AA83BC /* RemoveSurfaceCommand.cpp */; };
39A9AAE91B0518FC00AA83BC /* MoveSurfaceCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A9AAE71B0518FC00AA83BC /* MoveSurfaceCommand.cpp */; };
39A9AAEC1B053B4200AA83BC /* SelectSurfaceCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A9AAEA1B053B4200AA83BC /* SelectSurfaceCommand.cpp */; };
39A9AAF21B054FC300AA83BC /* MoveSurfaceVertexCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A9AAF01B054FC300AA83BC /* MoveSurfaceVertexCommand.cpp */; };
39C1243319EE9589005DF557 /* lz4.c in Sources */ = {isa = PBXBuildFile; fileRef = 39C123EA19EE9589005DF557 /* lz4.c */; };
39C1243419EE9589005DF557 /* Base64Encoding.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39C1241219EE9589005DF557 /* Base64Encoding.cpp */; };
39C1243519EE9589005DF557 /* ByteBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39C1241319EE9589005DF557 /* ByteBuffer.cpp */; };
@ -156,6 +157,8 @@
39A9AAE81B0518FC00AA83BC /* MoveSurfaceCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MoveSurfaceCommand.h; path = Commands/MoveSurfaceCommand.h; sourceTree = "<group>"; };
39A9AAEA1B053B4200AA83BC /* SelectSurfaceCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SelectSurfaceCommand.cpp; path = Commands/SelectSurfaceCommand.cpp; sourceTree = "<group>"; };
39A9AAEB1B053B4200AA83BC /* SelectSurfaceCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SelectSurfaceCommand.h; path = Commands/SelectSurfaceCommand.h; sourceTree = "<group>"; };
39A9AAF01B054FC300AA83BC /* MoveSurfaceVertexCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MoveSurfaceVertexCommand.cpp; path = Commands/MoveSurfaceVertexCommand.cpp; sourceTree = "<group>"; };
39A9AAF11B054FC300AA83BC /* MoveSurfaceVertexCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MoveSurfaceVertexCommand.h; path = Commands/MoveSurfaceVertexCommand.h; sourceTree = "<group>"; };
39C123E719EE9589005DF557 /* alphanum.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = alphanum.hpp; sourceTree = "<group>"; };
39C123EA19EE9589005DF557 /* lz4.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lz4.c; sourceTree = "<group>"; };
39C123EB19EE9589005DF557 /* lz4.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lz4.h; sourceTree = "<group>"; };
@ -651,6 +654,8 @@
39FDD9E81AC0076200262205 /* Commands */ = {
isa = PBXGroup;
children = (
39A9AAF01B054FC300AA83BC /* MoveSurfaceVertexCommand.cpp */,
39A9AAF11B054FC300AA83BC /* MoveSurfaceVertexCommand.h */,
39A9AAEA1B053B4200AA83BC /* SelectSurfaceCommand.cpp */,
39A9AAEB1B053B4200AA83BC /* SelectSurfaceCommand.h */,
39A9AAE71B0518FC00AA83BC /* MoveSurfaceCommand.cpp */,
@ -877,6 +882,7 @@
39C1243919EE9589005DF557 /* COBSEncoding.cpp in Sources */,
39C1244919EE9589005DF557 /* snappy-sinksource.cc in Sources */,
39C1248819F1EB75005DF557 /* SurfaceManager.cpp in Sources */,
39A9AAF21B054FC300AA83BC /* MoveSurfaceVertexCommand.cpp in Sources */,
39C1244319EE9589005DF557 /* LinkFilter.cpp in Sources */,
39C1245919F086A9005DF557 /* BaseSource.cpp in Sources */,
39C1244019EE9589005DF557 /* FileExtensionFilter.cpp in Sources */,

2
src/Commands/MoveSurfaceCommand.cpp

@ -12,11 +12,13 @@ namespace ofx{
}
void MoveSurfaceCommand::exec(){
ofLogNotice("MoveSurfaceCommand", "exec");
_previousVertices = _surface->getVertices();
_surface->setMoved(false);
}
void MoveSurfaceCommand::undo(){
ofLogNotice("MoveSurfaceCommand", "undo");
_surface->moveBy(_previousVertices[0] - _surface->getVertices()[0]);
_projectionEditor->updateJoints();
_previousVertices.clear();

31
src/Commands/MoveSurfaceVertexCommand.cpp

@ -0,0 +1,31 @@
#include "MoveSurfaceVertexCommand.h"
namespace ofx{
namespace piMapper{
MoveSurfaceVertexCommand::MoveSurfaceVertexCommand(
int vertIndex,
BaseSurface * surface,
ProjectionEditor * projectionEditor){
_vertIndex = vertIndex;
_surface = surface;
_projectionEditor = projectionEditor;
}
void MoveSurfaceVertexCommand::exec(){
ofLogNotice("MoveJointCommand", "exec");
_prevVertPos = _surface->getVertices()[_vertIndex];
}
void MoveSurfaceVertexCommand::undo(){
ofLogNotice("MoveJointCommand", "undo");
_surface->setVertex(_vertIndex, _prevVertPos);
_projectionEditor->updateJoints();
_projectionEditor = 0;
_surface = 0;
}
} // namespace piMapper
} // namespace ofx

34
src/Commands/MoveSurfaceVertexCommand.h

@ -0,0 +1,34 @@
// MoveSurfaceVertexCommand
// Provides with option to undo move surface vertex operation.
// Created by Krisjanis Rijnieks 2015-05-15
#pragma once
#include "BaseCommand.h"
#include "BaseSurface.h"
#include "ProjectionEditor.h"
#include "BaseJoint.h"
namespace ofx{
namespace piMapper{
class MoveSurfaceVertexCommand : public BaseUndoableCommand{
public:
MoveSurfaceVertexCommand(
int vertIndex,
BaseSurface * surface,
ProjectionEditor * projectionEditor);
void exec();
void undo();
private:
int _vertIndex;
ofVec2f _prevVertPos;
BaseSurface * _surface;
ProjectionEditor * _projectionEditor;
};
} // namespace piMapper
} // namespace ofx

12
src/Surfaces/SurfaceManagerGui.cpp

@ -87,7 +87,6 @@ namespace ofx {
return;
} else if (guiMode == GuiMode::TEXTURE_MAPPING) {
bool bSurfaceSelected = false;
CircleJoint* hitJoint =
textureEditor.hitTestJoints(ofVec2f(args.x, args.y));
if (hitJoint != NULL) {
@ -117,6 +116,17 @@ namespace ofx {
projectionEditor.unselectAllJoints();
hitJoint->select();
hitJoint->startDrag();
int jointVertIndex = 0;
for (auto i = 0; i < projectionEditor.getJoints()->size(); i++) {
if ((*projectionEditor.getJoints())[i] == hitJoint) {
jointVertIndex = i;
break;
}
}
_commandManager->exec(new MoveSurfaceVertexCommand(
jointVertIndex,
surfaceManager->getSelectedSurface(),
&projectionEditor));
bSurfaceSelected = true;
}

1
src/Surfaces/SurfaceManagerGui.h

@ -14,6 +14,7 @@
#include "CommandManager.h"
#include "MoveSurfaceCommand.h"
#include "SelectSurfaceCommand.h"
#include "MoveSurfaceVertexCommand.h"
namespace ofx {
namespace piMapper {

4
src/UserInterface/ProjectionEditor.cpp

@ -254,6 +254,10 @@ CircleJoint* ProjectionEditor::hitTestJoints(ofVec2f pos) {
return NULL;
}
vector<CircleJoint *> * ProjectionEditor::getJoints(){
return &joints;
}
void ProjectionEditor::drawJoints() {
for (int i = 0; i < joints.size(); i++) {
joints[i]->draw();

1
src/UserInterface/ProjectionEditor.h

@ -37,6 +37,7 @@ class ProjectionEditor {
void moveSelection(ofVec2f by);
void setSnapDistance(float newSnapDistance);
CircleJoint* hitTestJoints(ofVec2f pos);
vector<CircleJoint *> * getJoints();
private:
SurfaceManager* surfaceManager;

Loading…
Cancel
Save