Cancel handling issue with FEM constraint dialogs

About the development of the FEM module/workbench.

Moderator: bernd

wmayer
Site Admin
Posts: 16645
Joined: Thu Feb 19, 2009 10:32 am

Re: Cancel handling issue with FEM constraint dialogs

Post by wmayer » Thu Aug 27, 2020 3:47 pm

Here is a simplified example of a task dialog in Python:

Code: Select all

class TaskDialog:
  def __init__(self, doc):
    self.doc = doc
    doc.openTransaction("Add object")
    doc.addObject("Part::Box", "Box")
    doc.recompute()
  
  def accept(self):
    print ("Accept")
    self.doc.commitTransaction()
    return True
  
  def reject(self):
    print ("Reject")
    self.doc.abortTransaction()
    return True

Gui.Control.showDialog(TaskDialog(App.ActiveDocument))
When opening the dialog it opens a transaction and adds a box. If you press OK the transaction will be committed and the box stays, while when pressing Cancel the box will be removed again.

Here is a version using setActiveTransaction and closeActiveTransaction.

Code: Select all

class TaskDialog:
  def __init__(self, doc):
    self.doc = doc
    FreeCAD.setActiveTransaction("Add object")
    doc.addObject("Part::Box", "Box")
    doc.recompute()
  
  def accept(self):
    print ("Accept")
    FreeCAD.closeActiveTransaction()
    return True
  
  def reject(self):
    print ("Reject")
    FreeCAD.closeActiveTransaction(True)
    return True

Gui.Control.showDialog(TaskDialog(App.ActiveDocument))
User avatar
bernd
Posts: 10956
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Cancel handling issue with FEM constraint dialogs

Post by bernd » Thu Aug 27, 2020 6:02 pm

just to be sure ...

ATM in FEM C++ the objects are added in command.cpp in the specific commsnd class. In FEM Pythen the objects are added in the command class not in the task panel class.

In your exsmples the objects are added in the task panel class. But how do I start the task panel than? ATM the objects are added in the command class and the new object is set in edit modd an thus the task panel is opened.
User avatar
bernd
Posts: 10956
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Cancel handling issue with FEM constraint dialogs

Post by bernd » Thu Aug 27, 2020 6:41 pm

ahh found it ... the showDialog method is used to start the task panel.
User avatar
Kunda1
Posts: 8710
Joined: Thu Jan 05, 2017 9:03 pm

Re: Cancel handling issue with FEM constraint dialogs

Post by Kunda1 » Thu Aug 27, 2020 6:45 pm

bernd wrote:
Thu Aug 27, 2020 10:29 am

Code: Select all

$ grep -r "closeActiveTransaction(True)"
$
Try

Code: Select all

grep -iRn "closeActiveTransaction(True)"
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
bernd
Posts: 10956
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Cancel handling issue with FEM constraint dialogs

Post by bernd » Fri Aug 28, 2020 4:13 am

Kunda1 wrote:
Thu Aug 27, 2020 6:45 pm
Try

Code: Select all

grep -iRn "closeActiveTransaction(True)"
:)
Jee-Bee
Posts: 2145
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: Cancel handling issue with FEM constraint dialogs

Post by Jee-Bee » Fri Aug 28, 2020 9:49 am

Thanks @ bernd for you work
User avatar
Kunda1
Posts: 8710
Joined: Thu Jan 05, 2017 9:03 pm

Re: Cancel handling issue with FEM constraint dialogs

Post by Kunda1 » Fri Aug 28, 2020 11:28 am

bernd wrote:
Fri Aug 28, 2020 4:13 am
:)
;) :D
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest