FreeCAD new tree functionality for drag elements to sub-tree

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Dani
Posts: 8
Joined: Sun Oct 03, 2021 5:19 pm

FreeCAD new tree functionality for drag elements to sub-tree

Post by Dani »

Hello,

I would like to create a new FreeCAD functinality wich is similar to Catia's tree manipulation. It functionality will pop a new window with a sub-tree from selected element and allows drag an element from main tree to the created sub-tree.

I am showing an image with the Catia's funtionality for better understanding.

Image

If someone knows if it funtionality already exists in FreeCAD or someone has programed, please let me know.

cheers,
Dani.
chrisb
Veteran
Posts: 54144
Joined: Tue Mar 17, 2015 9:14 am

Re: FreeCAD new tree functionality for drag elements to sub-tree

Post by chrisb »

Please elaborate on the semantics of such actions
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
bleber
Posts: 259
Joined: Thu Jun 30, 2016 5:12 pm

Re: FreeCAD new tree functionality for drag elements to sub-tree

Post by bleber »

My proposed vehavior:
Raight click to element, menú select move, appear a second Window with tree, Clik on destination container on the new Window. T'he element Moves to new destination, you can select destination on new Window and elements to move on t'he Otger Window.
Dani
Posts: 8
Joined: Sun Oct 03, 2021 5:19 pm

Re: FreeCAD new tree functionality for drag elements to sub-tree

Post by Dani »

Thank you for answer.

The functionality aims to solve the problem of moving objects in tree when it is very large. It will be very useful if yo have several windows with diferent portions of tree and can move objets in order to have all in the correct place.

The proposed behavior is a valid one. For my Python skills the question will be if there are enough code out there for reuse in this question.

I am analyzing some macros like this: https://gist.github.com/mario52a/67517e ... dcfd8c9190 writed by mario52a for reuse some ideas.

Best regards,
Dani
chrisb
Veteran
Posts: 54144
Joined: Tue Mar 17, 2015 9:14 am

Re: FreeCAD new tree functionality for drag elements to sub-tree

Post by chrisb »

Dani wrote: Wed Nov 17, 2021 3:13 pm The functionality aims to solve the problem of moving objects in tree when it is very large.
That would indeed be helpful. There is already the possibility to open a TreeView in addition to the ComboView; alas, it is not possible to drag objects from one view to the other.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
freedman
Veteran
Posts: 3464
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: FreeCAD new tree functionality for drag elements to sub-tree

Post by freedman »

I don't want to pile on but;
It would cool if we could open a library view in a new window, where we could drag items in/out into the main tree view. I wouldn't really care about sub-features, I would like to use it as a model object item holder.

Also want to thing about the logic of saving changes on a close.
Dani
Posts: 8
Joined: Sun Oct 03, 2021 5:19 pm

Re: FreeCAD new tree functionality for drag elements to sub-tree

Post by Dani »

Hello, I have a very preliminary version of the macro.

It works with some files but fails on others. The problem is that I can`t get an ordered list of objects with FreeCAD Name as same order as FreeCAD's tree.

I tried this diferent ways:
1. Using qtreewidget:
I can get the FreeCAD's qtreewidget used in treeview by:

Code: Select all

mw = Gui.getMainWindow()
self.tw = mw.findChildren(QtGui.QTreeWidget)
self.tw0 = self.tw[0]
self.FCtreeitems = self.tw0.findItems('*', Qt.MatchWrap | Qt.MatchWildcard  | Qt.MatchRecursive)[0]
The object self.FVtreeitems contains a list of qtreewidgetitems which property .text() is the FreeCAD Label. In this way the objects are listed in the correct order but I have no the Name property.

2. I can use the property OutList of a FreeCAD object like so:

Code: Select all

App.ActiveDocument.getObject('ObjectName').OutList
This returns a list of objects that are below 'ObjectName' in the FreeCAD's tree but not always in the correct order.

I can not find a piece of code for achieve the solution. I put my very preliminary code on github: https://github.com/iinjdpa/TreeHelper

Thanks,
Dani.
User avatar
Pauvres_honteux
Posts: 728
Joined: Sun Feb 16, 2014 12:05 am
Location: Far side of the moon

Re: FreeCAD new tree functionality for drag elements to sub-tree

Post by Pauvres_honteux »

Any chance of getting this into master? Or at least into AddonManager?
Dani
Posts: 8
Joined: Sun Oct 03, 2021 5:19 pm

Re: FreeCAD new tree functionality for drag elements to sub-tree

Post by Dani »

Hello,

I found the functionality for getting the macro working. I used the method object.ViewObject.claimChildren() for get the true children of an object in the FreeCAD's tree.

I am working in some litle errors and new funcionalities for pass objects between different sub-trees.

I created a youtube video with an easy example about macro working.

https://www.youtube.com/watch?v=f32JEWJefAE
Dani
Posts: 8
Joined: Sun Oct 03, 2021 5:19 pm

Re: FreeCAD new tree functionality for drag elements to sub-tree

Post by Dani »

Hello,

I finish some bugs fixed and now I can move objects between sub-trees.

Youtube vídeo: https://www.youtube.com/watch?v=mzuLPpF64tY&t=2s
Post Reply