how do I record changes to undo/redo?

In Techdraw there is a major undo/redo problem that I want to fix: When changing the properties listed in the View Tab, these changes cannot be undone. But changing properties in the Data tab can be undone.

I searched around in FC’s code to learn how undo/redo is done but cannot find out a brief explanation, not why only the GUI part of Techdraw is affected. Does anybody please have a pointer for me where to look?

Another question: I noticed that the TechDraw dimension dialog does not store any changes so that undo cannot be performed. I thought I have to open a transaction to store the changes made in the dialog for undo, but I see that e.g. the Balloon dialog stores the changes for undo correctly and has no open transaction. So how do I record changes for a task dialog?

AFAIK changes to view properties are not places on the undo/redo stack (BTW I do not know if ‘stack’ is the right word). This applies to ALL workbenches.

Indeed. I see now that e.g. the sketcher WB is affected too.

@Werner, is this by design or a bug? If no bug, I will close 4553

Besides this, I am still not understanding why bug 4552 occurs. This one is definitely my mistake but I cannot find a way to fix it.


It’s not a bug but #4553 can be considered as feature request. In order to make undo/redo working for view properties there are needed only two minor changes in the source code.
In PropertyView.cpp there is this call:

propertyEditorView->setAutomaticDocumentUpdate(false);

We can add a parameter in the user config which by default is false, but can be overridden by the user.

In PropertyEditor.cpp there is the function

PropertyEditor::setupTransaction

which currently only handles App::DocumentObject but not Gui::ViewProviderDocumentObject. It’s straightforward to support the latter.

I have to look at the code, first…

EDIT: I can’t see any structural differences between the dialogs and their view providers.

This question reminds me of @ceremcem’s post Making projects resistant to breaking changes https://forum.freecadweb.org/viewtopic.php?f=8&t=54298

91435c96f7

So how do I record changes for a task dialog?

I don’t know why TaskBallon records changes while TaskDimension doesn’t. But both dialogs don’t work correctly because when clicking Cancel the changes must be reverted.

Thanks for having a look. I guess my “mistake” was to just use the existing Balloon dialog to create the dimension dialog. Therefore it inherits all Balloon dialog issues.
I will have a look tonight.

Many thanks. However, the View properties are still not recorded for undo:

  • select in the model tree a sketch
  • go to the View tab section “Object Style” and change there “Draw Style” to “Dashed”

result: this change cannot be undone.

It works. You must create the boolean parameter AutoTransactionView (under BaseApp/Preferences/PropertyView) and set it to true. It’s off by default.

Ah, thanks. Can we please have it turn this on by default since having the undo feature is an improvement for workflow. Or what would tbe the potential disadvantage?

But a bit different than with the Data properties:

  • I select a sketch in the model tree, then I change a Sketcher View property
  • I go/click on another property of the sketch

result: undo is not active

I first need to select another item in the model tree, then Undo becomes active
This is different to the Data properties whose changes can directly be undone without the need to select another item in the model tree first.

Ideally the properties should behave the same regarding undo, no matter if they are in the Data or View tab.

We had such discussions many years ago and we decided against to implement Undo/Redo for view changes as it can very quickly fill your undo list. Now that it’s possible I think it still shouldn’t be enabled by default.

I can’t confirm this. It works just fine for me.

But undo is already active for all Data properties. Thus I don’t understand why the View properties should be treated different.


I can’t confirm this. It works just fine for me.

That is strange, I have:

OS: Windows 10 Version 2009
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.23991 (Git)
Build type: Release
Branch: master
Hash: 15068d7dc68741c4650d856928d063cb02ff09ec
Python version: 3.8.6+
Qt version: 5.15.1
Coin version: 4.0.1
OCC version: 7.5.0
Locale: German/Germany (de_DE)

I will now start a complete recompilation and test again.

Here are two screenshots of what I see, now with a Version: 0.19.23992 (Git) and recompiled FreeCADGui library.

First after selecting another tree item, undo gets active:
kzy1Qey0Hn.gif
With Data properties, Undo is directly active and Undo is active by default. So on a fresh installation, undo is already on and this works fine:
zpuSstgblQ.gif

Here’s the PR to fix this: https://github.com/FreeCAD/FreeCAD/pull/4409

When enabling log messages then what I get is e.g. this when selecting a view property

11:26:06 PropertyEditor.cpp(184): current changed 14,1 -1,-1
11:26:06 PropertyItemDelegate.cpp(134): create editor 14,1
11:26:06 AutoTransaction.cpp(138): set active transaction ‘Bearbeiten Eigenschaft ShapeColor’
11:26:06 PropertyEditor.cpp(250): editor transaction Bearbeiten Eigenschaft ShapeColor

When I change the color I immediately get this

11:26:29 53.131 Document.cpp(1170): auto transaction (1513) 'Unbenannt#Box.ViewObject.ShapeColor

At this time I can already see that the undo button has a new entry.
After changing to another view property I then get this message

11:26:35 AutoTransaction.cpp(175): close transaction ‘Bearbeiten Eigenschaft ShapeColor’ 0

It’s exactly the same behaviour as when I change a data property instead.

OK, I think the problem is that the buttons of the toolbars are not updated. In the past we used a timer that regularly updated all commands after every 300ms or so and in v0.19 this timer has been removed and instead an update is triggered after changes to a document, activating the main window, …

Unfortunately, there are still cases where a command is not updated when it should be. So, to confirm this guess what happens if you switch to another application with ALT+TAB and then switch back to FreeCAD with ALT+TAB? This is supposed to trigger a GUI update and should then enable the undo button.

I realize the bug is there only with existing files. For new files and also existing files I saved as, the issue does not occur.
Just for the records, here is a recipe to reproduce:

Then there is no undo, it first appears after you select another item in the model tree.

However, it works now as soon as existing files are saved. The important thing for me is that Undo works by default for the View tab. For the Data tab this is already the case and obviously this has been proven useful.

The undo/redo is controlled by user settings only and not the content of project files. When you create a new document with a box, save, close and reload it and then change a view property you will see the same problem again.

The point is that after loading a project file the undo/redo buttons are disabled because nothing in the document has changed. If you now change a view property the undo button is not updated and thus it’s still disabled. If you switch to another application and back to FreeCAD an update is triggered and the button becomes active.

The reason why it fails for view properties but works with data properties is that for data properties a lot more things are done and at some point an update of the GUI is triggered.

To test

  • Create a new document and an object (e.g. a box). You will get an active undo button
  • Run this in the Python console
App.ActiveDocument.clearUndos()
Gui.Command.update()

The undo button will be disabled.

  • Now change a view property. You will see the button is still disabled.
  • Switch to the Python console and rerun
Gui.Command.update()

The button will be active now.

So, this means the undo/redo is working correctly and what’s missing is an explicit update of the GUI.