Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Feature Request: undo to rotate, flip, split, cut #3265
Maybe get up to speed with this feature by implementing it only to translate, rotate, flip, scale which would be only a case of changing coordinates and transformation matrices, and in the future try and extend that for for cut and split by saving the state before these transformations in a cache.
When you apply a transformation matrix, you also add their inverse to a stack. So every time the user selects undo or press ctrl-Z, the matrix on the stack is popped and applied to the object.
Just a random reference about inverse matrices: http://mathworld.wolfram.com/MatrixInverse.html
I was reading about rotation, translation, and scaling. We must be using composite transformation to do the various operations similarly we can use composite transformations to roll back the transformation that had already happened. We will keep on saving the instances of the models whenever the user changes something major in the model.
Now if the user requests for an undo we will go to the previous instance.
For example: Say a user applies a composite operation to the model in the following order.
Now the user wants to apply an undo command. Then these operations will happen:
We know the change matrix of these transformations, therefore the reapplying the negative matrix is not that difficult.
Can this work?
Yeah. We don't use matrices for transformation but we do like this:
I think you just need to create a class representing an undoable operation, holding all the relevant information (object and instance to apply the transformation, kind of operation, values). These objects would be added to a stack. Whenever an object or instance is removed from the plater, all the related undoable operations should be removed from the stack. That's it.
wxWidgets provides a built-in facility for undo, but I'm not sure we actually need it (and I'm not sure it's available in wxPerl).
I want to share the data structures using which we can implement: Please also refer to the pseudo code that I have written below. I have implemented it using the comments of @alexrj:
First of all, we will keep adding all the operations to the stack. An array in a class will save all the valid operations that can be undone. Whenever the user clicks the undo button it will request a subroutine to tell whether the operation is undone. If it returns true we can go forward and apply the reverse operations saved in the class.
Please share your views about this. I have tried to write it in perl but as my perl is week, please correct the syntax too if I am wrong somewhere.