Read Vertex position in a view

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Stq_Niko
Posts: 24
Joined: Fri Jun 14, 2019 7:07 pm
Location: France

Read Vertex position in a view

Post by Stq_Niko »

Hello Wandererfan,

During this confinement period I try to learn a little about Python and TechDraw
So I did a short ("and silly") python macro to read vertexes position from a view and create CosmeticVertex from this positions :

Code: Select all

import FreeCAD
import TechDraw

ft = App.ActiveDocument.ProjItem
dvp = App.ActiveDocument.ProjItem

i = 0
while (i < 7):
	vect = ft.getVertexByIndex(i).Point
	org = App.Vector(vect)
	dvp.makeCosmeticVertex(org)
	i = i+1
So, Vertexes from the view and CosmeticVertex should be at the same position. I get this :
Image

CosmeticVertexes are well positionned for the rectangle shape, but not for the triangle shape !?
Is it normal ?
I did something wrong ?


OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.20738 (Git)
Build type: Release
Branch: master
Hash: 0c96f77184edc0a6747483b2ff1462fc6dae46ff
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: French/France (fr_FR)
Attachments
Résultat_Macro
Résultat_Macro
Capture_FC1.PNG (21.84 KiB) Viewed 1527 times
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Read Vertex position in a view

Post by wandererfan »

Stq_Niko wrote: Sun Apr 26, 2020 3:26 pm During this confinement period I try to learn a little about Python and TechDraw
Good for you! I'm eating too much and exercising too little. Your plan is better.
So, Vertexes from the view and CosmeticVertex should be at the same position.
I would bet that if you inverted the Y coordinate of the vector you pass to makeCosmeticVertex, you'd get the right picture.
The square is symmetric about the Y axis, so you won't notice the problem here.

In the graphics space, +Y is down, so this a common problem in TD. makeCosmeticVertex is either doing 1 too many Y inversions, or 1 too few. I'll have a look.

Thanks for the feedback.
Stq_Niko
Posts: 24
Joined: Fri Jun 14, 2019 7:07 pm
Location: France

Re: Read Vertex position in a view

Post by Stq_Niko »

Yes, not enought exercice for me too ...

Indeed, It's the Y axis which is reversed, I change my test macro, and it works now.
These is a way to check the Y direction ?

My next step is to try to do something with edges ...

Thank for your help
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Read Vertex position in a view

Post by wandererfan »

Stq_Niko wrote: Sun Apr 26, 2020 3:26 pm CosmeticVertexes are well positionned for the rectangle shape, but not for the triangle shape !?
Is it normal ?
I did something wrong ?
Should be fixed by git commit f2f7d22b8e.

Thanks for reporting!
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Read Vertex position in a view

Post by reox »

My chain measure macro broke with that change and I thought it might be easy to fix, however I'm a little bit confused right now.

Here is an example: I select the dimension and create cosmetic vertices at the points of the dimension:
screenshot-20200509_11361589016985.png
screenshot-20200509_11361589016985.png (10.59 KiB) Viewed 1361 times
The cosmetic vertices are obviously not at the location of the line's vertices.
However, the conversion using

Code: Select all

view.makeCosmeticVertex(App.Vector(p.x, -p.y, 0) / view.Scale)
still works.

Back then you said that:
wandererfan wrote: Mon Sep 02, 2019 11:57 am Model space uses garden variety 3d coords. Paper space uses Qt's 2d coords that have (0,0) at the upper left, +X pointing to the right, but +Y pointing down the screen/page.
So that means
* makeCosmeticVertex has to be in paper space.
* getLinearPoints is in model space

But:
* What does Dimension.X and Y now return? No matter how I try to convert it, i can set the cosmetic Vertex at the point where the dimension text is. I checked back in the old Version and I could create the vertex right at the point using Vector(d.X, d.Y, 0) - this does not work anymore.
edit: oh, ok Dimension.X and Y has to be divided by the scale to get the paper space coordinate now:

Code: Select all

view.makeCosmeticVertex(App.Vector(d.X, d.Y, 0) / view.Scale)
btw I saw that there is now makeCosmeticCircleArc and other fancy methods :o that is awesome!
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Read Vertex position in a view

Post by wandererfan »

reox wrote: Sat May 09, 2020 9:46 am * What does Dimension.X and Y now return?
For top level Views, X & Y are position on the page in mm with conventional axes (+X to Right, +Y up).
If the view has a parent (like Dimension or Leader), X & Y are relative to parent.X and parent.Y.
For Dimensions, X & Y is the center of the dimension text baseline.

makeCosmeticVertex((d.X, d.Y, 0.0)) should put the CV right at the dim text, but as you point out the position of the CV has Scale applied to it. This is wrong and should be fixed.
btw I saw that there is now makeCosmeticCircleArc and other fancy methods :o that is awesome!
If you use them, please provide bug reports. These methods have not had much exercise.
Post Reply