Select what you want to see in the Document Tree

Info about new implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
mlampert
Posts: 965
Joined: Fri Sep 16, 2016 9:28 pm

Re: Select what you want to see in the Document Tree

Postby mlampert » Wed Sep 12, 2018 9:39 pm

easyw-fc wrote:
Wed Sep 12, 2018 3:16 pm
very good addition!
Is there a way to expand the tree of the document through python command?
I don't think there is. The TreeWidget is not exposed into Python (AFAIK).

The whole feature relies on a new parameter Preferences->View->TreeViewDocument which takes an integer value 0/1/2 corresponding to the 3 different modes. I used an integer so it can be extended if somebody comes up with another mode. Anyhow, once the value is set there needs to be a trigger, the simplest way is calling App::setActiveDocument - although the Python version might check if there is a change and shortcut the logic if you're setting the same document (Gui::setActiveDocument does that for sure).
User avatar
easyw-fc
Posts: 1919
Joined: Thu Jul 09, 2015 9:34 am

Re: Select what you want to see in the Document Tree

Postby easyw-fc » Wed Sep 12, 2018 9:47 pm

mlampert wrote:
Wed Sep 12, 2018 9:39 pm
I don't think there is. The TreeWidget is not exposed into Python (AFAIK).
There is a nice macro to expand tree objects, but it doesn't work with the doc root atm...
https://forum.freecadweb.org/viewtopic. ... 34#p255085
mlampert
Posts: 965
Joined: Fri Sep 16, 2016 9:28 pm

Re: Select what you want to see in the Document Tree

Postby mlampert » Wed Sep 12, 2018 10:00 pm

chrisb wrote:
Wed Sep 12, 2018 2:23 pm
I used the new default visibility to switch between two models in order to compare the properties of some objects. I realized that the properties are not cleared when switching between documents.
This is something I wasn't sure of. Currently the TreeWidget doesn't mess with the selection - it's probably not trivial and I wasn't brave enough to make a call on this behaviour. There are a few use cases which would not be possible in "Single Document" view. Also there is the question how "Collapse/Expand" should work. I figured maybe give everyone a little while to get used to this and figure out what works and what doesn't.
mlampert
Posts: 965
Joined: Fri Sep 16, 2016 9:28 pm

Re: Select what you want to see in the Document Tree

Postby mlampert » Thu Sep 13, 2018 12:15 am

easyw-fc wrote:
Wed Sep 12, 2018 9:47 pm
There is a nice macro to expand tree objects, but it doesn't work with the doc root atm...
https://forum.freecadweb.org/viewtopic. ... 34#p255085
Wow - that is quite some code sorcery right there.

The top item (document) cannot be selected, which is why the script doesn't work to expand the document. I've added the bottom 4 lines which do expand the document - but, it expands the document regardless if the document is currently visible or not. So even if you are in "Single Document" mode, it will still expand the hidden documents as well (you'll see when you activate them):

Code: Select all

# todo:  * ActiveDocument > 1 
#        * encoding

import FreeCAD
from PySide import QtGui

def visi(item):
  txt = item.text(0).encode('ascii', 'replace')
  objs = FreeCAD.ActiveDocument.getObjectsByLabel(txt)
  return objs and obj[0].ViewObject.Visibility

def expandAll(tree, item):
  tree.expandItem(item)
  for i in range(item.childCount()):
        if visi(item.child(i)):
            expandAll(tree, item.child(i))

mw=Gui.getMainWindow()
trees=mw.findChildren(QtGui.QTreeWidget)

for tree in trees:
  item=tree.selectedItems()

  for i in item:
    if visi(i):
      expandAll(tree, i)

  root=tree.itemAt(0,0)
  if root and tree.isActiveWindow():
    for i in range(root.childCount()):
      tree.expandItem(root.child(i))
Thanks for the script, this is awesome :ugeek:
chrisb
Posts: 10339
Joined: Tue Mar 17, 2015 9:14 am

Re: Select what you want to see in the Document Tree

Postby chrisb » Thu Sep 13, 2018 4:48 am

mlampert wrote:
Wed Sep 12, 2018 10:00 pm
I figured maybe give everyone a little while to get used to this and figure out what works and what doesn't.
Of course! I guess restoring the old view is a considerable amount of work. If there is a chance to get this, there is no urgent need to do anything. Before it is postponed too far in t he future I would appreciate having the property panel cleared, because currently it is still possible to change a value in the not selected document.
User avatar
bitacovir
Posts: 333
Joined: Sat Apr 19, 2014 6:23 am
Contact:

Re: Select what you want to see in the Document Tree

Postby bitacovir » Thu Sep 13, 2018 11:03 am

mlampert wrote:
Tue Sep 11, 2018 6:31 pm
As of last night the Document Tree widget has 3 options for what is being displayed:
* Only the currently active document
* All documents as it used to be
* Expand the active document and collapse all others

Due to the challenges and confusion by novice users the default behaviour has changed to only show the currently active document. If you want to change the behaviour, go to the menu "View" -> "Document Tree".
Thanks. This resolves one of the "5 Ways FreeCAD will Annoy You" https://www.youtube.com/watch?v=R9KIa3_dJu8
:)
::bitacovir::
===================================
One must be absolutely modern.
Arthur Rimbaud (A Season in Hell -1873)

My Blog
Mini Airflow Tunnel Project
mlampert
Posts: 965
Joined: Fri Sep 16, 2016 9:28 pm

Re: Select what you want to see in the Document Tree

Postby mlampert » Thu Sep 13, 2018 7:04 pm

chrisb wrote:
Thu Sep 13, 2018 4:48 am
mlampert wrote:
Wed Sep 12, 2018 10:00 pm
I figured maybe give everyone a little while to get used to this and figure out what works and what doesn't.
Of course! I guess restoring the old view is a considerable amount of work. If there is a chance to get this, there is no urgent need to do anything. Before it is postponed too far in t he future I would appreciate having the property panel cleared, because currently it is still possible to change a value in the not selected document.
Clearing the proper panel means messing with the selection. OTOH, editing the properties of a "Body" in the other document would have made my top 10 of annoying "I can't believe I just did that" list. So I thought about disabling the property panel (setting read-only), which should give us the best of both worlds.
chrisb
Posts: 10339
Joined: Tue Mar 17, 2015 9:14 am

Re: Select what you want to see in the Document Tree

Postby chrisb » Fri Sep 14, 2018 8:09 am

mlampert wrote:
Thu Sep 13, 2018 7:04 pm
"I can't believe I just did that"
Been there,done that :lol:
User avatar
NormandC
Posts: 16566
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Select what you want to see in the Document Tree

Postby NormandC » Sat Sep 15, 2018 9:32 pm

chrisb wrote:
Wed Sep 12, 2018 12:14 am
pablogil wrote:
Tue Sep 11, 2018 9:36 pm
It’s really a nice feature for newbies
And for oldies as well.
Thanks!!
+1, although I'm not sure I like to identify myself as an oldie :D

Thanks for adding this. 90% of the time I prefer to see only the active document in the tree, but it is nice to know I can switch it back to the old behaviour for the other 10%.

This is one of the many little improvements that makes v0.18 worthwhile.
freedman
Posts: 332
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Select what you want to see in the Document Tree

Postby freedman » Tue Sep 18, 2018 8:41 pm

One thing I have noticed is the small indentation (by design) in the tree. When I have a Body expanded that runs half way down the page it's kind of hard to find where the next Body starts especially if the next Body is disabled. I have to visually scan down thru the features until I find the next Body in the list. Not sure if there's something simple to do, maybe a thin horizontal line between bodies as a thought or maybe some highlight.

Thanks