[Solved] 0.19pre PartWB, Attachment >Apply, donnot work

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
fc_tofu
Posts: 519
Joined: Sun Jan 05, 2020 4:56 pm

[Solved] 0.19pre PartWB, Attachment >Apply, donnot work

Post by fc_tofu » Sun Mar 22, 2020 6:15 pm

I tried it many times and read the wiki, but found nothing useful.
Could somebody show me some tips?
fsc_2020-03-23_014852b.jpg
fsc_2020-03-23_014852b.jpg (94.58 KiB) Viewed 285 times
OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.20052 (Git)
Build type: Release
Branch: master
Hash: 6291921e9abe737e4440ff5814ca58547defadef
Python version: 3.8.2
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: Chinese/China (zh_CN)
Last edited by fc_tofu on Tue Mar 31, 2020 7:25 am, edited 4 times in total.
chrisb
Posts: 24399
Joined: Tue Mar 17, 2015 9:14 am

Re: PartWB >Attachment, What's the usage of "Apply" button?

Post by chrisb » Sun Mar 22, 2020 7:17 pm

I can confirm, that it does nothing visible.

Test use case:
Initial state - Change things - Apply! - change further things - Cancel

Expected behaviour:
The state after the Apply is restored.

Observed behaviour: Attachment is reset to the initial state.
fc_tofu
Posts: 519
Joined: Sun Jan 05, 2020 4:56 pm

Re: PartWB >Attachment, What's the usage of "Apply" button?

Post by fc_tofu » Sun Mar 22, 2020 8:00 pm

chrisb wrote:
Sun Mar 22, 2020 7:17 pm
I can confirm, that it does nothing visible.

Test use case:
Initial state - Change things - Apply! - change further things - Cancel

Expected behaviour:
The state after the Apply is restored.

Observed behaviour: Attachment is reset to the initial state.
Thank you.
New test on 0.18.4/Win10x64, same result as 0.19pre.
openBrain
Posts: 3979
Joined: Fri Nov 09, 2018 5:38 pm

Re: 0.19pre PartWB, Attachment >Apply, donnot work

Post by openBrain » Sun Mar 22, 2020 9:09 pm

Guys, I feel a bit idiot, but I don't have this Apply button on the attachment editor... Only OK and Cancel. What exactly are you doing to get this dialog ? :oops:
TheMarkster
Posts: 1392
Joined: Thu Apr 05, 2018 1:53 am

Re: 0.19pre PartWB, Attachment >Apply, donnot work

Post by TheMarkster » Sun Mar 22, 2020 10:04 pm

openBrain wrote:
Sun Mar 22, 2020 9:09 pm
Guys, I feel a bit idiot, but I don't have this Apply button on the attachment editor... Only OK and Cancel. What exactly are you doing to get this dialog ? :oops:
I think they're using the one in the Part workbench menu.
My FreeCAD video series on youtube: https://www.youtube.com/c/mwganson
openBrain
Posts: 3979
Joined: Fri Nov 09, 2018 5:38 pm

Re: 0.19pre PartWB, Attachment >Apply, donnot work

Post by openBrain » Sun Mar 22, 2020 10:42 pm

TheMarkster wrote:
Sun Mar 22, 2020 10:04 pm
I think they're using the one in the Part workbench menu.
I also don't have the Apply button there... :?
chrisb
Posts: 24399
Joined: Tue Mar 17, 2015 9:14 am

Re: 0.19pre PartWB, Attachment >Apply, donnot work

Post by chrisb » Mon Mar 23, 2020 1:11 am

It is indeed the Attachment dialog available via Menu->Part->Attachment. I cannot see any reason why it is different from the Attachment dialog which comes up when you raise it from a Part object via MapMode property.

And no, you have not yet proven to be an idiout.
vocx
Posts: 4073
Joined: Thu Oct 18, 2018 9:18 pm

Re: 0.19pre PartWB, Attachment >Apply, donnot work

Post by vocx » Mon Mar 23, 2020 1:30 am

It seems the command Part_Attachment should actually be called Part_EditAttachment. That is how it is defined in the code.

https://github.com/FreeCAD/FreeCAD/blob ... #L300-L324

The "clicked" method contains the code for the Apply button, the "accept" method contains the code for the OK button, and the reject method contains the code for the "Cancel" button.

As we can see, both the Apply and the OK button write the new Placement properties to the object. However, the OK button also runs the commitTransaction() method from the document. Maybe this is what is missing from Apply.

Code: Select all

    def clicked(self,button):
        if button == QtGui.QDialogButtonBox.Apply:
            if self.obj_is_attachable:
                self.writeParameters()
            self.updatePreview()
            if self.callback_Apply:
                self.callback_Apply()

    def accept(self):
        if self.obj_is_attachable:
            self.writeParameters()
        if self.create_transaction:
            self.obj.Document.commitTransaction()
        self.cleanUp()
        Gui.Control.closeDialog()
        if self.callback_OK:
            self.callback_OK()

    def reject(self):
        if self.create_transaction:
            self.obj.Document.abortTransaction()
        self.cleanUp()
        Gui.Control.closeDialog()
        if self.callback_Cancel:
            self.callback_Cancel()
So this is what could be added. We commit the transaction, but we don't close the entire dialog like OK and Cancel do.

Code: Select all

    def clicked(self,button):
        if button == QtGui.QDialogButtonBox.Apply:
            if self.obj_is_attachable:
                self.writeParameters()
            if self.create_transaction:
                self.obj.Document.commitTransaction()
            self.updatePreview()
            if self.callback_Apply:
                self.callback_Apply()
I am unsure if this is a clean solution, as there is some code that sets up a transaction. This transaction is comitted with the OK button, or aborted with the Cancel button. But if we commit it with the Apply button, then I think we need to start a new commit.

Code: Select all

    def clicked(self,button):
        if button == QtGui.QDialogButtonBox.Apply:
            if self.obj_is_attachable:
                self.writeParameters()
            if self.create_transaction:
                self.obj.Document.commitTransaction()
            self.updatePreview()
            if self.callback_Apply:
                self.callback_Apply()
            if self.create_transaction:
                self.obj.Document.openTransaction(_translate('AttachmentEditor',"Edit attachment of {feat}",None).format(feat= self.obj.Name))
DeepSOIC wrote: ping
Always add the important information to your posts if you need help.
To support the documentation effort, and code development, your donation is appreciated: paypal.
vocx
Posts: 4073
Joined: Thu Oct 18, 2018 9:18 pm

Re: 0.19pre PartWB, Attachment >Apply, donnot work

Post by vocx » Mon Mar 23, 2020 1:49 am

chrisb wrote:
Mon Mar 23, 2020 1:11 am
... I cannot see any reason why it is different from the Attachment dialog which comes up when you raise it from a Part object via MapMode property.
There seems to be two "Part Attachments", one defined in C++ and the other in Python.

The one from the menu seems to be made in Python. The command is called Part_EditAttachment, under src/Mod/Part/AttachmentEditor/Commands.py and TaskAttachmentEditor.py.

But separately, there is another TaskAttacher located in src/Mod/Part/Gui/TaskAttacher.{h, cpp, ui}

The Python version defines three buttons.

Code: Select all

def getStandardButtons(self):
        return int(QtGui.QDialogButtonBox.Ok) | int(QtGui.QDialogButtonBox.Cancel)| int(QtGui.QDialogButtonBox.Apply)
But the C++ version seems to define only two.

Code: Select all

/// returns for Close and Help button 
    virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const
    { return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
So, it seems they basically implement the same functionality, although in slightly different ways.
Always add the important information to your posts if you need help.
To support the documentation effort, and code development, your donation is appreciated: paypal.
chrisb
Posts: 24399
Joined: Tue Mar 17, 2015 9:14 am

Re: 0.19pre PartWB, Attachment >Apply, donnot work

Post by chrisb » Mon Mar 23, 2020 5:57 am

Thanks for this profound analysis. It always seems a bit radical to throw things away, but I still would vote for only a single implementation. I would like to know from Part workbench power users
- if they ever used the menu dialog
- if they ever missed an Apply button.

I will ask in the German forum too, where we seem to have the most Part workbench power users.
Post Reply

Who is online

Users browsing this forum: fc_tofu and 12 guests