[feature request] Section Plane - Cut View Context menu

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

[feature request] Section Plane - Cut View Context menu

Post by carlopav »

Hello! I'm using the arch section plane with great proficiency also while modelling with PartDesign. What I found great is the ability to cut the view to show the inside of the model while I'm modelling.
I think it would speed up things a lot to be able to activate and deactivate CutView property with a right click on the section plane entity on the treeview.
I think this is the right topic https://forum.freecadweb.org/viewtopic.php?t=10255 but i couldn't manage to understand how to correctly place inside the code.
I tried to add this code to the viewprovider section plane:

Code: Select all

    def setupContextMenu(self,vobj,menu):
        from PySide import QtCore,QtGui
        action1 = QtGui.QAction(QtGui.QIcon(":/icons/Draft_Edit.svg"),"Swich on/off Cutview",menu)
        QtCore.QObject.connect(action1,QtCore.SIGNAL("triggered()"),self.contextCutview(vobj))
        menu.addAction(action1)
    
    def contextCutview(self,vobj):
        if vobj.CutView:
            vobj.CutView = False
        else: vobj.CutView = True
but the result is that cutview is activated directly with right click rather than with left click on the menu option (this is super cool, but not the right behaviour i guess).
What am I doing wrong?
follow my experiments on BIM modelling for architecture design
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: [feature request] Section Plane - Cut View Context menu

Post by vocx »

carlopav wrote: Sun Oct 13, 2019 10:41 am ...
What am I doing wrong?
Your code doesn't look like the code from Werner in the cited thread, contextmenu for a viewprovider.

It seems like this should be enough.

Code: Select all

class ArchSectionPlaneViewProvider:
    def __init__(self, vobj):
    ...
    def setupContextMenu(self, vobj, menu):
        action = menu.addAction("Switch on/off cutview")
        action.triggered.connect(lambda f=self.contextCutview, arg=vobj:f(arg))

    def contextCutview(self, vobj):
        if vobj.CutView:
            vobj.CutView = False
        else:
            vobj.CutView = True
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: [feature request] Section Plane - Cut View Context menu

Post by carlopav »

Super thanks,
it works. What about if i PR this feature?
I find it really helpful.
follow my experiments on BIM modelling for architecture design
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: [feature request] Section Plane - Cut View Context menu

Post by vocx »

carlopav wrote: Sun Oct 13, 2019 10:41 am ...
What am I doing wrong?
By the way, I just realized that your previous attempt was just imitating the code in Draft.py. I didn't notice before. I guess it should work either way.

_ViewProviderWire, https://github.com/FreeCAD/FreeCAD/blob ... t.py#L5118

Code: Select all

    def setupContextMenu(self,vobj,menu):
        from PySide import QtCore,QtGui
        action1 = QtGui.QAction(QtGui.QIcon(":/icons/Draft_Edit.svg"),"Flatten this wire",menu)
        QtCore.QObject.connect(action1,QtCore.SIGNAL("triggered()"),self.flatten)
        menu.addAction(action1)
ViewProviderWorkingPlaneProxy, https://github.com/FreeCAD/FreeCAD/blob ... t.py#L6561

Code: Select all

    def setupContextMenu(self,vobj,menu):
        from PySide import QtCore,QtGui
        action1 = QtGui.QAction(QtGui.QIcon(":/icons/Draft_SelectPlane.svg"),"Write camera position",menu)
        QtCore.QObject.connect(action1,QtCore.SIGNAL("triggered()"),self.writeCamera)
        menu.addAction(action1)
        action2 = QtGui.QAction(QtGui.QIcon(":/icons/Draft_SelectPlane.svg"),"Write objects state",menu)
        QtCore.QObject.connect(action2,QtCore.SIGNAL("triggered()"),self.writeState)
        menu.addAction(action2)
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
furti
Posts: 344
Joined: Mon Nov 27, 2017 5:27 pm

Re: [feature request] Section Plane - Cut View Context menu

Post by furti »

@carlopav the problem was that you called self.contextCutView(vobj) directly in setupContextMenu.
Instead one has to pass the function to the connect call like @vocx showed in his samples.

This means "self.contextCutview" without the brackets.
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: [feature request] Section Plane - Cut View Context menu

Post by carlopav »

Thanks, probably I copy pasted something wrong from draft wire command. Now it seem to work.
follow my experiments on BIM modelling for architecture design
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: [feature request] Section Plane - Cut View Context menu

Post by carlopav »

I submitted a PR so also yorik can have a look at it:
https://github.com/FreeCAD/FreeCAD/pull/2618
follow my experiments on BIM modelling for architecture design
ABeton
Posts: 150
Joined: Tue Sep 03, 2019 6:39 pm

Re: [feature request] Section Plane - Cut View Context menu

Post by ABeton »

I am trying to figure out what you did here, but I only understand some bits :P So does this command allow you to turn on and off the cut view from the context menu when you right click the section plane in the tree view?
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: [feature request] Section Plane - Cut View Context menu

Post by carlopav »

ABeton wrote: Tue Oct 15, 2019 12:39 pm
Precisely what you wrote. Every viewprovider object have the possibility to add its own commands in the context menu with this lines.
This doesn't work on the 3d view, just on the treeview.
follow my experiments on BIM modelling for architecture design
ABeton
Posts: 150
Joined: Tue Sep 03, 2019 6:39 pm

Re: [feature request] Section Plane - Cut View Context menu

Post by ABeton »

carlopav wrote: Tue Oct 15, 2019 12:46 pm
ABeton wrote: Tue Oct 15, 2019 12:39 pm
Precisely what you wrote. Every viewprovider object have the possibility to add its own commands in the context menu with this lines.
This doesn't work on the 3d view, just on the treeview.
Ok I understand better now. So to do it in the 3D view i will have to use some different code, something like what vocx posted in the other thread.
Post Reply