Macro: Version 3: helper tools to improve TechDraw documents

Discussions about the development of the TechDraw workbench
edi
Posts: 296
Joined: Fri Jan 17, 2020 1:32 pm

Re: Macro: Version 3: helper tools to improve TechDraw documents

Postby edi » Tue Mar 23, 2021 4:23 pm

Hi ngocminhdao88,
see in the right picture the solution I could find. It's not perfect.
TechDraw08.png
TechDraw08.png (18.08 KiB) Viewed 1554 times
Workflow:
- create a temporary centerline using the "Draw one centerline" tool of TechDrawTools macro (see left picture)
- create intersection vertexes with arcs using "Create vertex(es) at intersection" tool of TechDrawTools macro
- delete the temporary centerline
- create the 3 centerlines between vertexes using TechDraw's "Add cosmetic line" icon

A problem is, that TechDraw's "Add a centerline between two lines" has an issue if the lines are slanted.

I will try to create a helper tool: "Extend cosmetic line", which will enable to plot centerlines having a protrusion.
ngocminhdao88
Posts: 23
Joined: Wed Nov 11, 2020 10:43 am

Re: Macro: Version 3: helper tools to improve TechDraw documents

Postby ngocminhdao88 » Tue Mar 23, 2021 7:48 pm

Hi edi,

thank you for the tips. I was able to created a view showed below.
Image

I don't get what you meant by
A problem is, that TechDraw's "Add a centerline between two lines" has an issue if the lines are slanted.
I was able to create the center line between two slanted lines using the TechDraw's function fine.

A tool to extent cosmetic lines interactively (to the left, to the right by some amount) could be useful in some use case.
edi
Posts: 296
Joined: Fri Jan 17, 2020 1:32 pm

Re: Macro: Version 3: helper tools to improve TechDraw documents

Postby edi » Wed Mar 24, 2021 8:59 am

ngocminhdao88 wrote: Tue Mar 23, 2021 7:48 pm I was able to create the center line between two slanted lines using the TechDraw's function fine.
how did you do it ?
If I selcet the two parallel lines and use the "Adds a Centerline between 2 Lines" icon, no line is created. I get the message: "Endpoints are equal".

Maybe your two lines by a fortunate coincidence have the same direction (e.g. startpoint left, endpoint right). Try to create the slot using the polyline command in the sketcher (using the M key). If the two lines have opposite directions (in memory) the issue will occur.

If you publish the file I can check this.

PS: try attached file, having two slanted slots.
- Left slot: centerline can be created, because the two parallel lines have the same direction.
- Right slot: issue occures, because the two parallel lines have different directions.
- TechDrawTools.Macro: both slots are OK.
CenterLineTest.FCStd
(16.95 KiB) Downloaded 32 times
ngocminhdao88
Posts: 23
Joined: Wed Nov 11, 2020 10:43 am

Re: Macro: Version 3: helper tools to improve TechDraw documents

Postby ngocminhdao88 » Wed Mar 24, 2021 5:36 pm

Hi edi,

you were faster than me to upload sample file.

If the two lines have opposite directions (in memory) the issue will occur.
Indeed, it doesn't work, when the draw direction of both lines are not the same. Since i am right handed, i always draw from left to right :D.
openBrain
Posts: 5935
Joined: Fri Nov 09, 2018 5:38 pm

Re: Macro: Version 3: helper tools to improve TechDraw documents

Postby openBrain » Thu May 06, 2021 1:03 pm

edi wrote: Tue Mar 02, 2021 8:49 am Attached the Version 3 of the TechDrawTools-Macro.
Hi, had a quick look at your macro.
For some reasons, this is not advised to use a QMainWindow with StayOnTopHint for this kind of purposes.
The preferred way is to use a QDialog with Tool flag.
I started a tutorial to demonstrate. Unfortunately only the code is available now, wiki page isn't started yet. However it can probably explain by itself : https://github.com/0penBrain/FreeCAD-ma ... og.FCMacro

Another good way is to use a QDockWidget. It can be very practical for this usage as user can dock it (eg. on the right of the screen) or keep it floating.
Feel free to ask if more information needed.
edi
Posts: 296
Joined: Fri Jan 17, 2020 1:32 pm

Re: Macro: Version 3: helper tools to improve TechDraw documents

Postby edi » Fri May 07, 2021 3:46 pm

Hi openBrain,
thank you very much for your post.

The goal of TechDrawTools.FCMacro was, to create a container which stays active - whatever is done in FC - until it is closed by the user. chrisb gave me a hint to Macro_FCCamera.FCMacro published by mario52, which I used as guide. I adopted your method which is using PySide2. It is working. Compared with the old method (using PySide) the difference is, that the window disappeares if the user swaps from FreeCAD to another program, and is back if the user returns to FreeCAD again. In PySide2 many methods changed from QtGui to QtWidgets.

To your macro: I am far away from appreciating it in detail, but tested the selection observer using a TechDraw document.

the Following behavior occured:

- If selecting a TechDraw view or section view: The view (as a string) is returned in obj, that is OK
- If selecting a TechDraw dimension: The dimension (as a string) is returned in obj, that is OK
- If selecting a TechDraw geometric element (vertex or line) then addselection is called twice:
at "mouse DOWN" the selected view is returned in obj, an empty string in sub is returned
at "mouse UP" the selected view is returned in obj and the selected vertex or line is returned in sub
pnt is allways returned as (0.0,0.0,0.0)

I guess it is a problem of defining the type of the event in addEventCallback. Is it possible to obtain the mouse status (UP, DOWN, LEFT, RIGHT) ?
openBrain
Posts: 5935
Joined: Fri Nov 09, 2018 5:38 pm

Re: Macro: Version 3: helper tools to improve TechDraw documents

Postby openBrain » Fri May 07, 2021 4:04 pm

edi wrote: Fri May 07, 2021 3:46 pm The goal of TechDrawTools.FCMacro was, to create a container which stays active - whatever is done in FC - until it is closed by the user. chrisb gave me a hint to Macro_FCCamera.FCMacro published by mario52, which I used as guide.
Unfortunately this (wrong) usage of QMainWindow+StayOnTopHint is present a lot in FreeCAD wiki and probably had spread itself in the past. That's why I started the tutorial (WIP). ;)
I adopted your method which is using PySide2. It is working. In PySide2 many methods changed from QtGui to QtWidgets.
You may actually have kept PySide. The important thing is to use QDialog+Tool.
Compared with the old method (using PySide) the difference is, that the window disappeares if the user swaps from FreeCAD to another program, and is back if the user returns to FreeCAD again.
That's it. Which is far better (IMO) particularly if you have only one screen. I don't want to go doing some web browsing and get the TechDrawTools window over my browser. :lol:
Also there are other differences you may not have seen :
* With new method, you have only one FC window in the OS task bar. With old QMainWindow, you had 2 which is a bit weird
* With new method you keep only one Qt event loop. QMainWindow creates a second independent event loop, which may lead to issues if you close FC main window while TechDrawTools dialog is open. Now it's clean. :)
To your macro: I am far away from appreciating it in detail, but tested the selection observer using a TechDraw document.
Not sure this is a good idea. There is some specific things with selection in TechDraw and maybe SelectionObserver isn't really friend with them. :)
- If selecting a TechDraw geometric element (vertex or line) then addselection is called twice:
at "mouse DOWN" the selected view is returned in obj, an empty string in sub is returned
at "mouse UP" the selected view is returned in obj and the selected vertex or line is returned in sub
pnt is allways returned as (0.0,0.0,0.0)

I guess it is a problem of defining the type of the event in addEventCallback.
My guess is that you maybe found a bug in TechDraw. ;)
Is it possible to obtain the mouse status (UP, DOWN, LEFT, RIGHT) ?
No it isn't. The selection observer is just propagating the 'addSelection' to a custom class. It ignores the way/reason 'addSelection' has been originally called.
User avatar
uwestoehr
Posts: 2743
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany

Re: Macro: Version 3: helper tools to improve TechDraw documents

Postby uwestoehr » Fri May 28, 2021 5:02 pm

Hi Edi, cool work!

I contributed a lot to Techdraw the last time and one of the issues I could not yet solve is that Techdraw does not recognize threaded holes. With FC 0.20 we have now a completely reworked hole tool to make threaded holes. The task is now to make Techdraw aware of these parameters. Despite I am the author of the reworked hole tool, I have no clue on how to teach Techdraw to recognize the threads :oops: .
Could you please have a look, if you find an approach to get this to work?
CM 2000
Posts: 6
Joined: Fri Feb 19, 2021 4:12 pm

Re: Macro: Version 3: helper tools to improve TechDraw documents

Postby CM 2000 » Sun May 30, 2021 8:44 am

Hallo edi,
thanks for this great tool. But one question: how can I undo a selection made? I have to close the document without saving and reopen it again. Very awkward. Or did I not notice a button due to my poor English skills? :? Thank you CM
User avatar
M4x
Posts: 376
Joined: Sat Mar 11, 2017 9:23 am
Location: Germany

Re: Macro: Version 3: helper tools to improve TechDraw documents

Postby M4x » Mon May 31, 2021 7:31 pm

Wow, this looks awesome! I'm going to check it out :D