Pull request: added recompute() function to reflect changes in the GUI

Merged, abandoned or rejected pull requests are moved here to clear the main Pull Requests forum.
Post Reply
User avatar
amrit3701
Posts: 343
Joined: Mon Jun 13, 2016 5:37 pm

Pull request: added recompute() function to reflect changes in the GUI

Post by amrit3701 »

Hi,

I have use Arch.makeRebar() function in my Python script and suddenly noticed one bug present in that function.

Detail description of bug:
When passing all parameters to Arch.makeRebar(baseobj, sketch, diameter, amount, offset), properties of an object is changed but changes are not reflected in GUI. For eg, if we pass amount=6 and diameter=12 property value of rebar object is change but in the GUI it will show only one rebar of default diameter. So, by adding recompute() function this problem is solved.

Pull request: https://github.com/FreeCAD/FreeCAD/pull/677

Regards,
Amritpal Singh
Github, Like my work, sponsor me!
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Pull request: added recompute() function to reflect changes in the GUI

Post by DeepSOIC »

one recompute in the end would have probably been sufficient... why did you add so many?
User avatar
amrit3701
Posts: 343
Joined: Mon Jun 13, 2016 5:37 pm

Re: Pull request: added recompute() function to reflect changes in the GUI

Post by amrit3701 »

DeepSOIC wrote:one recompute in the end would have probably been sufficient... why did you add so many?
Yes, I know but when I have added recompute in the end then again changes like amount and diameter are not reflected in the GUI. That's why I have added five recompute functions and it's working fine now in all situations.

Regards,
Amritpal Singh
Github, Like my work, sponsor me!
User avatar
yorik
Founder
Posts: 13659
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Pull request: added recompute() function to reflect changes in the GUI

Post by yorik »

I also don't understand why the 5 recomputes? The makeRebar function can be called only once with all its parameters, to creat a rebar object. To change the parameters of the created rebar, you won't call this function again, but rather manipulate directly the properties of the created object...

Can you explain better what is the problem you encountered?
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Pull request: added recompute() function to reflect changes in the GUI

Post by wmayer »

Another issue here is that App.ActiveDocument doesn't necessarily need to be the document this object is part of. The correct way would be

Code: Select all

obj.Document.recompute()
or if you only want to recompute the object itself but not the whole document

Code: Select all

obj.recompute()
User avatar
amrit3701
Posts: 343
Joined: Mon Jun 13, 2016 5:37 pm

Re: Pull request: added recompute() function to reflect changes in the GUI

Post by amrit3701 »

yorik wrote:I also don't understand why the 5 recomputes? The makeRebar function can be called only once with all its parameters, to creat a rebar object. To change the parameters of the created rebar, you won't call this function again, but rather manipulate directly the properties of the created object...

Can you explain better what is the problem you encountered?
Yes, sure.
reinforcement.png
reinforcement.png (241.92 KiB) Viewed 2778 times
You see in the above image when I passed parameters to Arch.makeRebar(structure_base, sketch, 11, 7, 20), values of Rebar object are changed (i.e. amount=7, diameter=11 and offset=20) but in the GUI only one rebar with default diameter is shown. It will also shown same behaviour if I add recompute() in the end of makeRebar() function.

Steps to reproduce this error:

1. Copy and paste code in the FreeCAD python console.

Code: Select all

import Arch
s = Arch.makeStructure(length=1000.0,width=800.0,height=200.0)
s.Placement.Base = FreeCAD.Vector(0.0,0.0,0.0)
FreeCAD.ActiveDocument.recompute()
2. Then, select face1 of the structure and after that again copy and paste the given below code.

Code: Select all

class Rebar_shapes():
    def __init__(self, sketch, side_cover, front_cover, bottom_cover, amount, diameter, offset):
        selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
        face = selected_obj.SubElementNames[0]
        face_obj = selected_obj.SubObjects[0]
        sketch.MapMode = "FlatFace"
        structure_base = App.ActiveDocument.getObject(str(selected_obj.Object.Label))
        sketch.Support = [(structure_base, face)]
        if face_obj.normalAt(0,0).y == -1:
            sketch.addGeometry(Part.LineSegment(App.Vector(face_obj.Vertexes[0].X+side_cover, face_obj.Vertexes[0].Z+bottom_cover,0),App.Vector(face_obj.Vertexes[1].X-side_cover,face_obj.Vertexes[1].Z+bottom_cover,0)),False)
        structure = Arch.makeRebar(structure_base, sketch, diameter, amount, offset)
        FreeCAD.ActiveDocument.recompute()

s=App.activeDocument().addObject('Sketcher::SketchObject','Sketch')
Rebar_shapes(s,100,10,50,7,11,20)
3. At the end, you will noticed that value of amount, diameter and offset are changed but in the GUI it will shown only one rebar with default diameter. Now if I changed a value of amount, diameter in the property table only then changes are reflected in the GUI. By taking the above example, amount=7 shown only one rebar and if changed the value of amount to any value (say amount=8) then FreeCAD GUI will shown 8 rebars.

By adding recompute() after every initializing of property solved the above problem.

Regards,
Amritpal Singh
Github, Like my work, sponsor me!
User avatar
amrit3701
Posts: 343
Joined: Mon Jun 13, 2016 5:37 pm

Re: Pull request: added recompute() function to reflect changes in the GUI

Post by amrit3701 »

wmayer wrote:Another issue here is that App.ActiveDocument doesn't necessarily need to be the document this object is part of. The correct way would be

Code: Select all

obj.Document.recompute()
[/quote]

Yeah, I got your point and updated my pull request. Now, I used only one [mono]obj.Document.recompute()[/mono] instead of five [mono]FreeCAD.ActiveDocument.recompute()[/mono] and it's working fine.

Regards,
Amritpal Singh
Github, Like my work, sponsor me!
Post Reply