[Solved] Mimic FPS info on FullScreen

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

[Solved] Mimic FPS info on FullScreen

Post by DorinDXN »

Hello,
Nice to meet you :)
First post here.

I want to display some info on FullScreen, via Python, just like the FPS does,
info which will stay and will not rotate with camera.

I didn't had success so far, but most likely I don't know where to look for examples.
I'll appreciate any help.

So far I used Annotation, which is great and I like it, except it rotates with camera :?
so at each new view I had to re-position it.

cheers,
Dorin
Last edited by DorinDXN on Sun Nov 01, 2020 9:39 am, edited 2 times in total.
chrisb
Veteran
Posts: 54201
Joined: Tue Mar 17, 2015 9:14 am

Re: Mimic FPS info on FullScreen

Post by chrisb »

Hi and welcome to the forum!

Please explain what FPS is. I know it as FramesPerSecond, which makes no sense here.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

Re: Mimic FPS info on FullScreen

Post by DorinDXN »

Hi, thanks for quick reply :)

In FreeCAD, when at Preferences/3D View
[x] Show counter of frames per second
is enabled
In the bottom/left corner of Full Screen the FramesPerSecond info is shown
In the same way I want to show other properties, not FPS, say, the object rotation instead of FPS

I guess, must be a way, to display some info in Full Screen, info which will stay in that position regardless of camera rotation.

cheers,
Dorin
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

Re: Mimic FPS info on FullScreen

Post by DorinDXN »

Maybe if I'll add a video for better understanding.


phpBB [video]


In this one I used annotation to display the rotation of the cylinder.
The annotation is fine except when I rotate the camera, the annotation is moving along,
I need for that info to stay in that place of the Full Screen regardless of camera position.

I used this code for this video.

Code: Select all

from PySide import QtCore
import FreeCADGui as Gui

i=0
def update():
	global i
	FreeCAD.ActiveDocument.getObject("Cylinder").Placement = App.Placement(App.Vector(0,-10,-10),App.Rotation(App.Vector(0,1,0),-i), App.Vector(0,0,10))
	App.ActiveDocument.getObject("Annotation").LabelText=[str(i)+"°"]
	Gui.updateGui()
	i+=0.1
	if i>360:
		i=0

timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(1)
So what to use instead of annotation, I tried without success to have the annotation fixed, I guess I need a different approach.

cheers,
Dorin
User avatar
Chris_G
Veteran
Posts: 2598
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Mimic FPS info on FullScreen

Post by Chris_G »

Here is a possible solution, using SuperImposition of coin3d :

Code: Select all

from pivy import coin

textSep = coin.SoSeparator()
cam = coin.SoOrthographicCamera()
cam.aspectRatio = 1
cam.viewportMapping = coin.SoCamera.LEAVE_ALONE

trans = coin.SoTranslation()
trans.translation = (-0.98, 0.90, 0)

myFont = coin.SoFont()
myFont.name = "FreeMono,FreeSans,sans"
size = 24
myFont.size.setValue(size)
SoText2 = coin.SoText2()
SoText2.string = "Hello World"
color = coin.SoBaseColor()
color.rgb = (0, 0, 0)

textSep.addChild(cam)
textSep.addChild(trans)
textSep.addChild(color)
textSep.addChild(myFont)
textSep.addChild(SoText2)

activeDoc = FreeCADGui.ActiveDocument
view = activeDoc.ActiveView
sg = view.getSceneGraph()
viewer = view.getViewer()
render = viewer.getSoRenderManager()
sup = render.addSuperimposition(textSep)

# remove the Superimposition layer with :
# render.removeSuperimposition(sup)
Here is the coin3d doc : https://coin3d.github.io/Coin/html/annotated.html
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

Re: Mimic FPS info on FullScreen

Post by DorinDXN »

Thank you very much!

Solved :)

phpBB [video]


Code: Select all


from pivy import coin
from PySide import QtCore
import FreeCADGui as Gui


textSep = coin.SoSeparator()
cam = coin.SoOrthographicCamera()
cam.aspectRatio = 1
cam.viewportMapping = coin.SoCamera.LEAVE_ALONE

trans = coin.SoTranslation()
trans.translation = (-0.98, -0.35, 0)

myFont = coin.SoFont()
myFont.name = "Arial"
size = 135
myFont.size.setValue(size)
SoText2 = coin.SoText2()
SoText2.string = "0°"
color = coin.SoBaseColor()
color.rgb = (0, 0, 0)

textSep.addChild(cam)
textSep.addChild(trans)
textSep.addChild(color)
textSep.addChild(myFont)
textSep.addChild(SoText2)

activeDoc = FreeCADGui.ActiveDocument
view = activeDoc.ActiveView
sg = view.getSceneGraph()
viewer = view.getViewer()
render = viewer.getSoRenderManager()
sup = render.addSuperimposition(textSep)


i=0
def update():
	global i
	FreeCAD.ActiveDocument.getObject("Cylinder").Placement = App.Placement(App.Vector(0,-10,-10),App.Rotation(App.Vector(0,1,0),-i), App.Vector(0,0,10))
	SoText2.string=str(i)+"°"
	Gui.updateGui()
	i+=0.1
	if i>360:
		i=0

timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(1)


# remove the Superimposition layer with :
# render.removeSuperimposition(sup)

cheers,
Dorin
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

Re: [Solved] Mimic FPS info on FullScreen

Post by DorinDXN »

One more thing :)

I thought it will be easy..
how to have a multi-line string

tried

Code: Select all

SoText2.string = "line1\r\nline2"
but it doesn't work

From Coin3D docu
---8<------------------
SoMFString SoText2::string
The set of strings to render. Each string in the multiple value field will be rendered on its own line.
---8<------------------

It looks like a multi-line text needs to be given as a set of strings, but how?

Appreciate any help.

cheers,
Dorin
User avatar
Chris_G
Veteran
Posts: 2598
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: [Solved] Mimic FPS info on FullScreen

Post by Chris_G »

Code: Select all

SoText2.string.setValues(0,3,["Hello", "World", "!!!!"])
Doc : https://coin3d.bitbucket.io/Coin/classS ... addd232008
If you want to reduce the number of items of a multifield node, you may need to reset the field beforehand:

Code: Select all

SoText2.string.setValues(0,0,0)
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

Re: [Solved] Mimic FPS info on FullScreen

Post by DorinDXN »

Again thank you very much!

Makes perfect sense, tested, worked!

BTW, I noticed that after

Code: Select all

render.removeSuperimposition(sup)
it doesn't disappear automatically all the times,

Code: Select all

render.render()
and

Code: Select all

SoText2.string=""
render.render()
seems to help but still are cases when the text stay, though it disappear at mouse click or hover (sometimes).
Tested on single line text only
This is not so important, I'm, maybe, yet to find how to force a redraw after render.remove.

thanks again,
Dorin

L.E.
Just thought, maybe I need to have a delay before render.render(), could be windows message queue issue.
Last edited by DorinDXN on Mon Nov 02, 2020 11:28 am, edited 2 times in total.
User avatar
Chris_G
Veteran
Posts: 2598
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: [Solved] Mimic FPS info on FullScreen

Post by Chris_G »

Maybe the touch() function of the scenegraph will work better ?

Code: Select all

sg.touch()
Post Reply