Keyboard shortcut, View toolbar - Wireframe

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!
User avatar
openfablab
Posts: 20
Joined: Wed Nov 02, 2016 4:42 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby openfablab » Tue Jan 17, 2017 8:19 am

Hello!

I looked through this forum topic but could not understand, will there be ability to directly add keyboard wireframe shortcut in Edit>Preferences in future FreeCAD releases or not? If not, may be one would post a ticket about this?
triplus
Posts: 9278
Joined: Mon Dec 12, 2011 4:45 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby triplus » Tue Jan 17, 2017 11:01 am

openfablab wrote:Hello!

I looked through this forum topic but could not understand, will there be ability to directly add keyboard wireframe shortcut in Edit>Preferences in future FreeCAD releases or not? If not, may be one would post a ticket about this?
Hi @openfablab.

If you will follow this procedure:

http://www.freecadweb.org/wiki/index.ph ... e_Toolbars

You should end up with the ability to add keyboard shortcut. I didn't add keyboard shortcut directly to the macro as all sensible keyboard shortcut (combinations) already do something else in FreeCAD. And if there is a shortcut clash introduced all involved shortcuts stop working.
User avatar
openfablab
Posts: 20
Joined: Wed Nov 02, 2016 4:42 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby openfablab » Thu Jan 26, 2017 4:06 pm

Thank you, @triplus, it works good. But my question was not about this, but about adding to future FreeCAD releases this functionality without needing a macros. Wireframe toggle does not need to be associated with shortcut on FreeCAD install, but let's give users this opportunity.
triplus
Posts: 9278
Joined: Mon Dec 12, 2011 4:45 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby triplus » Thu Jan 26, 2017 6:13 pm

Well in theory creating a Python based FreeCAD View related command out of the macro shouldn’t be that hard. But after that things start to be counter productive as the command would likely need to be a global command and entry to View menu would need to be added from C++. Things like that reduce the chance for this to happen anytime soon.

P.S. But as i said above you can still assign a custom shortcut to Python based macro if you follow the procedure on the link.
mario52
Posts: 2857
Joined: Wed May 16, 2012 2:13 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby mario52 » Fri Jan 27, 2017 12:09 pm

hi
i try add schortcut but if one shortcut is existant you can replace if not impossible to create shortcut the button stay hidden
ShortCut00.png
ShortCut00.png (26.88 KiB) Viewed 744 times
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
mario52
Posts: 2857
Joined: Wed May 16, 2012 2:13 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby mario52 » Wed Aug 28, 2019 1:48 pm

hi

@triplus

i create a wiki page for the tree macros Macro_Toggle_Drawstyle_Optimized for listed in AddonManager the all language version

if not selection , not work with

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.17877 (Git)
Build type: Release
Branch: master
Hash: 1e19ef5be4735f4200eaf99ce9e487d2be6f4151
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
User avatar
clel
Posts: 39
Joined: Mon Jun 13, 2016 10:30 am

Re: Keyboard shortcut, View toolbar - Wireframe

Postby clel » Thu Dec 05, 2019 12:55 pm

Already a bit outdated, but after a short search I found this Wiki page: https://www.freecadweb.org/wiki/Std_DrawStyle

You can change the style with

Code: Select all

Gui.runCommand('Std_DrawStyle', 1)
for example.

This is an easy solution and also the other solutions mentioned here which I tested did not work for me.
triplus
Posts: 9278
Joined: Mon Dec 12, 2011 4:45 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby triplus » Wed Jan 29, 2020 10:56 pm

mario52 wrote:
Wed Aug 28, 2019 1:48 pm
hi

@triplus

i create a wiki page for the tree macros Macro_Toggle_Drawstyle_Optimized for listed in AddonManager the all language version

if not selection , not work with
Hi Mario.

I updated the macros and have tested them with FreeCAD 0.18 and above. Preserving FreeCAD 0.16 support would be possible, but i don't feel it makes sense to make them more complex. A link to a working FreeCAD 0.16 version can be preserved on the Wiki?

Toggle global display mode:

Code: Select all

# triplus @ 2016, 2020
# Toggle global display mode
# ==============================

# 0 = "As is"
# 1 = "Flat lines"
# 2 = "Shaded
# 3 = "Wireframe"
# 4 = "Points"
# 5 = "Hidden line"
# 6 = "No shading"

styleA = 0
styleB = 3

# ==============================

from PySide import QtGui
import FreeCADGui as Gui

mw = Gui.getMainWindow()


act = {
    0: mw.findChild(QtGui.QAction, "Std_DrawStyleAsIs"),
    1: mw.findChild(QtGui.QAction, "Std_DrawStyleFlatLines"),
    2: mw.findChild(QtGui.QAction, "Std_DrawStyleShaded"),
    3: mw.findChild(QtGui.QAction, "Std_DrawStyleWireframe"),
    4: mw.findChild(QtGui.QAction, "Std_DrawStylePoints"),
    5: mw.findChild(QtGui.QAction, "Std_DrawStyleHiddenLine"),
    6: mw.findChild(QtGui.QAction, "Std_DrawStyleNoShading"),
}


actionA = act[styleA]
actionB = act[styleB]


if actionA.isChecked():
    actionB.trigger()
else:
    actionA.trigger()
Toggle selected object(s) display mode. Global display mode is automatically set to As is:

Code: Select all

# triplus @ 2016, 2020
# Toggle selected object(s) display mode
# ==============================

a = "Flat Lines"
b = "Shaded"
c = "Wireframe"
d = "Points"

styleA = a
styleB = c

# ==============================

from PySide import QtGui
import FreeCADGui as Gui

obj = []
mw = Gui.getMainWindow()
sel = Gui.Selection.getSelectionEx()
mw.findChild(QtGui.QAction, "Std_DrawStyleAsIs").trigger()


for s in sel:
    if s.Object.TypeId == "App::Link":
        if s.Object.LinkedObject not in obj:
            obj.append(s.Object.LinkedObject)
    elif s.Object not in obj:
        obj.append(s.Object)
    else:
        pass


for o in obj:
    if o.ViewObject.DisplayMode == styleA:
        o.ViewObject.DisplayMode = styleB
    else:
        o.ViewObject.DisplayMode = styleA
Combination that toggles global display mode when nothing is selected and/or toggles selected objects display mode if objects are selected. When objects are selected global display mode is automatically set to As is:

Code: Select all

# triplus @ 2016, 2020
# Toggle object/global display mode
# ==============================

# 0 = "As is"
# 1 = "Flat lines"
# 2 = "Shaded
# 3 = "Wireframe"
# 4 = "Points"
# 5 = "Hidden line"
# 6 = "No shading"

globalA = 0
globalB = 3

a = "Flat Lines"
b = "Shaded"
c = "Wireframe"
d = "Points"

objectA = a
objectB = c

# ==============================

from PySide import QtGui
import FreeCADGui as Gui

mw = Gui.getMainWindow()
sel = Gui.Selection.getSelectionEx()


act = {
    0: mw.findChild(QtGui.QAction, "Std_DrawStyleAsIs"),
    1: mw.findChild(QtGui.QAction, "Std_DrawStyleFlatLines"),
    2: mw.findChild(QtGui.QAction, "Std_DrawStyleShaded"),
    3: mw.findChild(QtGui.QAction, "Std_DrawStyleWireframe"),
    4: mw.findChild(QtGui.QAction, "Std_DrawStylePoints"),
    5: mw.findChild(QtGui.QAction, "Std_DrawStyleHiddenLine"),
    6: mw.findChild(QtGui.QAction, "Std_DrawStyleNoShading"),
}


default = act[0]
actionA = act[globalA]
actionB = act[globalB]


if sel:
    obj = []
    default.trigger()
    for s in sel:
        if s.Object.TypeId == "App::Link":
            if s.Object.LinkedObject not in obj:
                obj.append(s.Object.LinkedObject)
        elif s.Object not in obj:
            obj.append(s.Object)
        else:
            pass

    for o in obj:
        if o.ViewObject.DisplayMode == objectA:
            o.ViewObject.DisplayMode = objectB
        else:
            o.ViewObject.DisplayMode = objectA
else:
    if actionA.isChecked():
        actionB.trigger()
    else:
        actionA.trigger()
P.S. Note that i added support for selected App::Link features. Current limitation of the App::Link features being, you can't toggle the display mode of only the selected Link feature, its parent and sibling App::Link features display mode will change too. I used an approach, where the menu on toolbar gets updated, using the Std_DrawStyle command doesn't do that. Over the years more people show interest in this set of macros, that was my motivation to bring them up to speed again. Thank you for taking good care on the Wiki side of things, making them more accessible and discoverable.
mario52
Posts: 2857
Joined: Wed May 16, 2012 2:13 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby mario52 » Fri Jan 31, 2020 5:39 pm

hi triplus

thanks for upgrade

the link is already there , and the links for the other modes is accessible in the AddonManager title (see AddonManager "Toggle Drawstyle Optimized")

or is you want i make 3 new separate page for this set 0.18.. (AddonManader see only the first code in the wiki page) then give three name of macro and description and 3 icon

(PS:i use "Combination that toggles global display" she works as my Macro Toggle Visibility)

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
triplus
Posts: 9278
Joined: Mon Dec 12, 2011 4:45 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby triplus » Fri Jan 31, 2020 10:35 pm

mario52 wrote:
Fri Jan 31, 2020 5:39 pm
thanks for upgrade
You're welcome.
the link is already there
I was thinking if a description could be added, saying if you are searching for FreeCAD 0.16 compatible version, click on this link. As i guess the current Wiki page will get updated with the latest revision of the macros. They are not compatible with FreeCAD 0.16 anymore.
or is you want i make 3 new separate page for this set 0.18.. (AddonManader see only the first code in the wiki page) then give three name of macro and description and 3 icon
No special need for that. I did notice there are two Wiki pages:

https://www.freecadweb.org/wiki/Macro_Toggle_Drawstyle
https://www.freecadweb.org/wiki/Macro_T ... _Optimized

Does that make sense or best to merge them?