Help to implement #2060 : Create object directly in a group

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
rockn
Posts: 1578
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Help to implement #2060 : Create object directly in a group

Postby rockn » Mon May 25, 2015 1:49 pm

Hello,
I am starting implementing issue #2060. The aim of this feature is to be able to create object directly in a group or visgroup. So I have added a combobox in the draft tray tool bar and a button to refresh the items in combobox according to groups present in current document.
I have modified the function formatObject in Draft.py to add the created object in group if there is one set in the combobox.
https://github.com/wood-galaxy/FreeCAD_ ... -drafttray
draftraytb.png
draftraytb.png (6.02 KiB) Viewed 1035 times
I have already done the trick in an easy way but there is two things where I need advice :
1 - I want to update the new combobox in draft tray toolbar in a more elegant way than adding a new button. But all signals of a QCombobox take effect on item. I am wondering if there is a signal like onClick that take effect only when I hit the combobox ?

2 - It's more a question for Yorik. Currently, if I draw a line with a VisGroup set in the combobox, the line is added to the visgroup but don't get the visgroup properties instantly. But as soon as I start to draw a second line the first take visgroup property. There is a way to apply visgroup property instantly ?

Sorry for my english :oops:
Best regards
Last edited by rockn on Mon May 25, 2015 3:05 pm, edited 1 time in total.
Formations et tutoriels FreeCAD en Français, soutenez moi : https://www.tipeee.com/formations-freecad
danielfalck
Posts: 395
Joined: Fri Oct 07, 2011 8:58 pm
Location: Beaverton,Oregon, USA
Contact:

Re: Help to implement #2060 : Create object directly in a group

Postby danielfalck » Mon May 25, 2015 1:57 pm

This might not be exactly what you are looking for, but in our Path workbench, we insert objects into groups like this:

https://github.com/danielfalck/FreeCAD/ ... re.py#L138

Yorik showed us how to do that.
User avatar
rockn
Posts: 1578
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: Help to implement #2060 : Create object directly in a group

Postby rockn » Mon May 25, 2015 1:59 pm

Oh, interesting ! I will look at this.
Thank you :)
Formations et tutoriels FreeCAD en Français, soutenez moi : https://www.tipeee.com/formations-freecad
User avatar
yorik
Site Admin
Posts: 11565
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Help to implement #2060 : Create object directly in a group

Postby yorik » Mon May 25, 2015 2:41 pm

Cool! I'll be away from my computer the whole week, when I'm back I have a look at this.

For the visgroup to be triggered when a new object is added to it, I suppose it can happen automatically (changing its "Group" property should normally trigger its execute() function, but maybe the code that updates the children colors is in the view provider and therefore something must be added to updateData(), I don't remember well.

For the combobox, I can't tell without seeing, but certainly it has a clicked signal...
User avatar
rockn
Posts: 1578
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: Help to implement #2060 : Create object directly in a group

Postby rockn » Mon May 25, 2015 2:50 pm

Cool,
Thanks for the hint about visgroup i will investigate.

According to the pyside doc : https://srinikom.github.io/pyside-docs/ ... boBox.html# there is no clicked signal, but I am wondering if there is way to get the signal from a parent of this object like Qwidget but I don't know how to catch it if it's possible.
Formations et tutoriels FreeCAD en Français, soutenez moi : https://www.tipeee.com/formations-freecad
User avatar
marcvs
Posts: 21
Joined: Tue Feb 18, 2014 6:44 am
Location: Paris, France

Re: Help to implement #2060 : Create object directly in a group

Postby marcvs » Thu May 28, 2015 2:30 pm

rockn, I cannot help you with FreeCAD internals, but I've got some PySide (and Python/numpy) skills...

it's not clear if you want to update the combo when a new group appears or if you want to change something else thant the combo when you select a new index in it.

Each time you change the ComboBox you can catch the new index signal: currentIndexChanged(int).
The point is that signal name should have the same arg type as the one which is fired by Qt (which can be awesome as Python has no type on args).
for example, if you get the GUI from Qt Designer, your child class would use such a signal setting (more or less) with a combo box named 'cGroup':

Code: Select all

class MyCombo(Ui_ComboFromDesigner):
  def __init__(self):
    super(Ui_ComboFromDesigner, self).__init__(None)
    self.setupUi(self)
    QObject.connect(self.cGroup,SIGNAL("currentIndexChanged(int)"),self.getGroup)
  def getGroup(self):
    g=self.cGroup.currentText()
    # update now something else using g
the signal editTextChanged(str) is also fired from the combo if you have an editable text entry as item.

The other way, you just have to catch a modification signal from the target object an update the combo.
if FreeCAD is using Qt model/view for the object tree the code gets more complex, anyway if you have some addNewGroup somewhere you can add:

Code: Select all

class SomeWhereManageTreeModel(TheRightBaseClass):
  def addGroup(self,groupname):
      # do something as usual
      # assume combo can be reached from the current object as cGroup attribute
      self.cGroup.addItem(groupname)
      ix=self.cGroup.findText(groupname) # two lines to reuse in another update from name
      self.cGroup.setCurrentIndex(ix)
hope it helps, then I'll balance the amount of help you already gave me on FreeCAD ;)
--- marcvs ---

"Architecture, logiciel et musique... ce sont les mêmes métiers."