Feature Request: undo to rotate, flip, split, cut #3265
Comments
I agree. Cut would be more complicated to undo because it's a destructive operation and the only way to get back to the previous state would require keeping the previous mesh in memory. |
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 suggest to put the actual operations in the stack, and only calculate the inverse when the Undo command is actually called. |
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. |
* * Add UndoOperations package in Plater.pm * Add undo/redo options to the plater menu with their icons. * Add the 2 undo/redo stacks to Slic3r::GUI::Plater package. * Add add_undo_operation, undo & redo sub routines to Slic3r::GUI::Plater. * Add objet identifier variable to each newly created Slic3r::GUI::Plater::Object to keep track of objects referenced in the stacks of undo/redo. * Add undo/redo to rotate, mirror, increase, remove. * * Add undo/redo to cut operation. * * Add undo/redo to split, decrease, change scale and reset. * Fix pop and push error.a * * Refactoring undo/redo functions. * * Some fixes to undo/redo for reset and decrease functions * Some Fixes to undo/redo split, reset and cut operations. * Improve undo/redo menu items sync. * * limit the undo stack operations to save RAM. * Remove debugging lines. * Add undo/redo to Add models. * Some Refactoring and some fixes. * Some Refactoring. Fixes #3265
@lordofhyphens The reference made there to is wrong. I have no hand in this PR. |
Sometimes I hit the wrong button/menu entry or more often give the wrong angle on rotation and then have to figure out what the reverse action is to undo. Or delete and re-add the object. It would be ncie if there were an undo button for this.
The text was updated successfully, but these errors were encountered: