Added one-level undo system and sticky trackmodes.

This commit is contained in:
Paolo Cignoni 2007-06-13 17:15:09 +00:00
parent 5ac1f6fe1a
commit 74d325979b
4 changed files with 116 additions and 6 deletions

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.19 2007/05/15 15:00:27 benedetti
Moved the drawing code to trackmodes, some other minor changes
Revision 1.18 2007/02/26 01:30:02 cignoni
Added reflection Name
@ -176,7 +179,7 @@ void Trackball::Translate(Point3f tr)
{
Matrix44f m;
track.rot.ToMatrix(m);
track.tra = last_track.tra + Inverse(m)*tr/track.sca;;
track.tra = last_track.tra + Inverse(m)*tr/track.sca;
}
/***************************************************************/
@ -293,6 +296,7 @@ void Trackball::DrawIcon() {
void Trackball::Reset() {
track.SetIdentity();
undo_track = track;
map<int, TrackMode *>::iterator i;
for(i = modes.begin(); i != modes.end(); i++){
TrackMode * mode=(*i).second;
@ -305,11 +309,13 @@ void Trackball::Reset() {
//interface
void Trackball::MouseDown(int button) {
undo_track = track;
current_button |= button;
SetCurrentAction();
Hits.clear();
}
void Trackball::MouseDown(int x, int y, int button) {
undo_track = track;
current_button |= button;
SetCurrentAction();
last_point = Point3f((float)x, (float)y, 0);
@ -322,16 +328,19 @@ void Trackball::MouseMove(int x, int y) {
last_point = Point3f((float)x, (float)y, 0);
return;
}
undo_track = track;
current_mode->Apply(this, Point3f(float(x), float(y), 0));
}
void Trackball::MouseUp(int /* x */, int /* y */, int button) {
undo_track = track;
current_button &= (~button);
SetCurrentAction();
}
// it assumes that a notch of 1.0 is a single step of the wheel
void Trackball::MouseWheel(float notch ) {
undo_track = track;
if(current_mode == NULL)
{
//SphereMode tm;
@ -345,6 +354,7 @@ void Trackball::MouseWheel(float notch ) {
void Trackball::MouseWheel (float notch, int button)
{
undo_track = track;
current_button |= button;
SetCurrentAction ();
if (current_mode == NULL) {
@ -358,15 +368,42 @@ void Trackball::MouseWheel (float notch, int button)
}
void Trackball::ButtonDown(Trackball::Button button) {
bool old_sticky=false, new_sticky=false;
assert (modes.count (0));
if ( ( modes.count (current_button) ) && ( modes[current_button] != NULL ) ) {
old_sticky = modes[current_button]->isSticky();
}
current_button |= button;
if ( ( modes.count (current_button) ) && ( modes[current_button] != NULL ) ) {
new_sticky = modes[current_button]->isSticky();
}
if ( old_sticky || new_sticky)
return;
SetCurrentAction();
}
void Trackball::ButtonUp(Trackball::Button button) {
bool old_sticky=false, new_sticky=false;
assert ( modes.count (0) );
if ( ( modes.count (current_button) ) && ( modes[current_button] != NULL ) ) {
old_sticky = modes[current_button]->isSticky();
}
current_button &= (~button);
if ( ( modes.count (current_button) ) && ( modes[current_button] != NULL ) ) {
new_sticky = modes[current_button]->isSticky();
}
if ( old_sticky || new_sticky)
return;
SetCurrentAction();
}
void Trackball::Undo(){
track = undo_track;
if(current_mode != NULL)
current_mode->Undo();
}
//spinning interface
void Trackball::SetSpinnable(bool /* on*/ ){}
bool Trackball::IsSpinnable() {

View File

@ -25,6 +25,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.14 2007/05/15 15:00:47 benedetti
Moved the drawing code to trackmodes, some other minor changes
Revision 1.13 2007/02/26 01:30:02 cignoni
Added reflection Name
@ -199,6 +202,7 @@ namespace vcg {
void MouseWheel (float notch, /*Button */ int button);
void ButtonUp(Button button);
void ButtonDown(Button button);
void Undo();
//default sensitivity 1
void SetSensitivity(float s);
@ -255,6 +259,10 @@ namespace vcg {
std::map<int, TrackMode *> modes;
Similarityf last_track;
// undo_track and last_track have different meanings..
Similarityf undo_track;
Similarityf last_view;
Point3f last_point;
std::vector<Point3f> Hits;

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.22 2007/05/28 08:10:47 fiorin
Removed type cast warnings
Revision 1.21 2007/05/16 08:44:05 ganovelli
added inclusion of glew.h
@ -91,7 +94,7 @@ Adding copyright.
#include <wrap/gui/trackball.h>
#include <wrap/gui/trackutils.h>
using namespace std;
using namespace vcg;
using namespace vcg::trackutils;
@ -133,6 +136,12 @@ void TrackMode::SetAction (){}
void TrackMode::Reset (){}
bool TrackMode::isSticky() {
return false;
}
void TrackMode::Undo(){}
// draw an inactive trackball
void InactiveMode::Draw(Trackball * tb){
DrawSphereIcon(tb,false);
@ -407,6 +416,9 @@ void PathMode::GetPoints(float state, Point3f & point, Point3f & prev_point, Poi
void PathMode::Apply (Trackball * tb, float WheelNotch)
{
undo_current_state=current_state;
undo_old_hitpoint=old_hitpoint;
const float STEP_COEFF = min_seg_length * 0.5f;
float delta=(WheelNotch*STEP_COEFF)/path_length;
Point3f old_point,new_point,prev_point,next_point;
@ -496,6 +508,9 @@ void PathMode::SetAction (){
void PathMode::Apply (Trackball * tb, Point3f new_point)
{
undo_current_state=current_state;
undo_old_hitpoint=old_hitpoint;
Ray3fN ray = line2ray(tb->camera.ViewLineFromWindow (new_point));
Point3f hit_point;
float delta_state=HitPoint(current_state,ray,hit_point);
@ -503,6 +518,15 @@ void PathMode::Apply (Trackball * tb, Point3f new_point)
tb->Translate (hit_point - old_hitpoint);
}
bool PathMode::isSticky() {
return true;
}
void PathMode::Undo(){
current_state=undo_current_state;
old_hitpoint=undo_old_hitpoint;
}
void PathMode::Draw(Trackball * tb){
DrawSphereIcon(tb,true );
Point3f current_point,prev_point,next_point;
@ -568,6 +592,13 @@ void AreaMode::Reset()
void AreaMode::Apply (Trackball * tb, Point3f new_point)
{
undo_begin_action=begin_action;
undo_status=status;
undo_delta_mouse=delta_mouse;
undo_old_status=old_status;
undo_rubberband_handle=rubberband_handle;
undo_path_index=path.size();
if(begin_action){
delta_mouse=tb->camera.Project(status)-new_point;
begin_action=false;
@ -588,8 +619,7 @@ void AreaMode::SetAction ()
{
begin_action=true;
old_status=status;
path.clear();
path.push_back(status);
rubberband_handle=status;
@ -698,6 +728,20 @@ Point3f AreaMode::SetStartNear(Point3f point)
return initial_status;
}
bool AreaMode::isSticky() {
return true;
}
void AreaMode::Undo(){
begin_action=undo_begin_action;
status=undo_status;
delta_mouse=undo_delta_mouse;
old_status=undo_old_status;
rubberband_handle=undo_rubberband_handle;
for(unsigned int i=path.size() - 1; i > undo_path_index; --i)
path.pop_back();
}
void AreaMode::Draw(Trackball * tb)
{
DrawSphereIcon(tb,true );

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.11 2007/05/15 14:59:10 benedetti
Main restructuring. added many new modes
Revision 1.10 2007/02/26 01:30:02 cignoni
Added reflection Name
@ -83,6 +86,8 @@ public:
return "TrackMode";
};
virtual void Draw (Trackball * trackball);
virtual bool isSticky();
virtual void Undo();
};
// Inactive mode.
@ -274,6 +279,8 @@ public:
void SetAction ();
void Reset ();
Point3f SetStartNear(Point3f p);
bool isSticky();
void Undo();
private:
void Init(const vector < Point3f > &points);
void GetPoints(float state, Point3f & point, Point3f & prev_point, Point3f & next_point);
@ -289,6 +296,8 @@ private:
float min_seg_length;
Point3f old_hitpoint;
float undo_current_state;
Point3f undo_old_hitpoint;
};
// Area mode.
@ -320,6 +329,8 @@ public:
void SetAction ();
void Reset ();
Point3f SetStartNear(Point3f p);
bool isSticky();
void Undo();
private:
void Init(const vector < Point3f > &pts);
bool Inside(Point3f point);
@ -330,12 +341,22 @@ private:
int first_coord_kept;
int second_coord_kept;
float min_side_length;
Point3f status,delta_mouse,old_status,initial_status;
Point3f status;
Point3f delta_mouse;
Point3f old_status;
Point3f initial_status;
Plane3f plane;
Point3f rubberband_handle ;
vector < Point3f > path;
bool undo_begin_action;
Point3f undo_status;
Point3f undo_delta_mouse;
Point3f undo_old_status;
Point3f undo_rubberband_handle ;
unsigned int undo_path_index;
};
}//namespace