Why is FreeCAD so slow in redrawing?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
MRx
Posts: 319
Joined: Wed Jul 08, 2020 5:59 am
Location: Tainan / Taiwan

Re: Why is FreeCAD so slow in redrawing?

Post by MRx »

can you try putting your operation commands into a simple python script for simulation without that particular workbench?
So other ones can simulate it just by running the script (on a cube)?
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Why is FreeCAD so slow in redrawing?

Post by mariwan »

MRx wrote: Tue Nov 23, 2021 3:29 pm can you try putting your operation commands into a simple python script for simulation without that particular workbench?
So other ones can simulate it just by running the script (on a cube)?
Believe me it is difficult to separate the code. Since you need something that the mouse interact with, you need my FR_WIDGETS which is a COIN library to draw the arrows and interact with them. I used that part on many other tools .. it is not the problem
Download my WB and change to devbranch ..
the file is located at ..\Roaming\FreeCAD\Mod\Design456\DirectModeling
called Design456_manipulate.py
The part that is doing the job called :

Code: Select all

    def recreateObject(self):
and thanks ..
But it is not complete .. I need to disable redrawing faces that didn't change during using the tool. For the cube it is only 2 faces that won't be changed.
MRx
Posts: 319
Joined: Wed Jul 08, 2020 5:59 am
Location: Tainan / Taiwan

Re: Why is FreeCAD so slow in redrawing?

Post by MRx »

try to separate the functions.

-- is it the mouse handling that is generating the lag (I don't think so I have just quickly checked your workbench and the values updated quickly)
-- is calling the functions expensive (add some timer / profiling information to it). eg. how much does one resizing object cost how many milliseconds? how many do you try to perform in a second? Break it down to the smallest easy to test example.
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Why is FreeCAD so slow in redrawing?

Post by mariwan »

MRx wrote: Wed Nov 24, 2021 12:41 am try to separate the functions.

-- is it the mouse handling that is generating the lag (I don't think so I have just quickly checked your workbench and the values updated quickly)
-- is calling the functions expensive (add some timer / profiling information to it). eg. how much does one resizing object cost how many milliseconds? how many do you try to perform in a second? Break it down to the smallest easy to test example.
Thanks for your advice. I will try that.
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Why is FreeCAD so slow in redrawing?

Post by mariwan »

It is clear that the recreate is costing too much.
I must dig into the function and find out exactly which part.
but the time is in ns not ms .. I will fix that
Attachments
test.JPG
test.JPG (64.18 KiB) Viewed 1377 times
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Why is FreeCAD so slow in redrawing?

Post by mariwan »

I removed all recompute() from my tool. Surprisingly the redrawing is still working .. So there is something else triggering the recompute and redrawing the whole document.
In this video, you see that the 4 faces object is definitely more responsive. So, the recreating of the face is the cause of the issue.
The problem is that you cannot recreate the whole object only one time.. I think each time I add or remove a face a recompute trigger automatically without my intention. So, I have no control over that .. i.e I cannot fix this issue at all.
Definitely, the recreate of the object is the most expensive component in the tool and thinking in direct modeling .. It is about recreating the objects continuously.

I am quite depressed how this issue can make an end of my project. I should try some more things before I give up totally.

phpBB [video]
User avatar
adrianinsaval
Veteran
Posts: 5547
Joined: Thu Apr 05, 2018 5:15 pm

Re: Why is FreeCAD so slow in redrawing?

Post by adrianinsaval »

can you explain maybe in pseudo code how your tool works? not how it's used but how does it work internally, the steps
for example: take an edge -> translate using example_function -> create face using example_function2 -> etc
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Why is FreeCAD so slow in redrawing?

Post by mariwan »

adrianinsaval wrote: Wed Nov 24, 2021 7:01 pm can you explain maybe in pseudo code how your tool works? not how it's used but how does it work internally, the steps
for example: take an edge -> translate using example_function -> create face using example_function2 -> etc
Hi,
Simply it is like here :
1-Copy the edge -- Make it moving with the mouse.
2-Save the vertexes of the edge in it's origin position.. when the copied edges moves change the Placement.Base to be equal to the Wheel (coin wheel) and keep saving the new vertexes
3-Vertexes were shared with some faces. Keep vertexes of the faces and just change the vertexes of the two points that are moving.
4-Remove the original 3D object.
5-Continously recreate the faces from vertexes as far as the movement of the mouse is >=1 mm
Planned/not implemented yet:
-Recreate the 3D object by the faces created earlier when user presses the OK button.
-Check the object if it is not ok .. make it solid, and fix it so it is correct.

That is how this tool should work or works.
User avatar
adrianinsaval
Veteran
Posts: 5547
Joined: Thu Apr 05, 2018 5:15 pm

Re: Why is FreeCAD so slow in redrawing?

Post by adrianinsaval »

are you creating a shell/solid from the faces with every movement? do you recreate all faces or only the ones that share a vertex with the selected edge?
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Why is FreeCAD so slow in redrawing?

Post by mariwan »

adrianinsaval wrote: Wed Nov 24, 2021 7:47 pm are you creating a shell/solid from the faces with every movement? do you recreate all faces or only the ones that share a vertex with the selected edge?

Code: Select all

 newPolygon = Part.makePolygon(_Newvertices, True)
                newFace = Part.makeFilledFace(newPolygon.Edges)
                if newFace.isNull():
                    raise RuntimeError('Failed to create face')
That is what I redo every time.
No the shell should be in the end when user presses the OK
Post Reply