New Inventor node SoLabel

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

New Inventor node SoLabel

Post by wmayer »

Hi all,

I have implemented a new Inventor node called SoLabel which allows to use the fonts that comes with Qt4. The behaviour of this node is the same as the original node SoText2.

To test this node you can use the python script below:

Code: Select all

from pivy import coin,sogui
s=coin.SoType.fromName("SoLabel").createInstance()
s.string="Hey, the label is working :)"
App.newDocument()
ano=coin.SoAnnotation()
ano.addChild(s)
Gui.ActiveDocument.ActiveView.getViewer().getSceneGraph().addChild(ano)
With s.name you can set the used font name, e.g. s.name="Wingdings". If this font is available on your system it changes it otherwise it falls back to a default font.

Cheers,
Werner
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: New Inventor node SoLabel

Post by wmayer »

I just have realized that SoLabel is already occupied by Inventor. I have renamed it to SoStringLabel now...
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: New Inventor node SoLabel

Post by yorik »

Wow, this works very well, extremely cool!!! It takes all of my systems font without problems, being system-wide or user-wide. Great job!
Now I'll play a bit with that :)
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: New Inventor node SoLabel

Post by yorik »

I just discovered that standard coin text nodes (SoText2, SoText3, SoAsciiText) all can make use of TTF fonts... I only tested on linux so far, but it's pretty nice... It finds all my fonts (system fonts in /usr/share and user fonts in ~/.fonts)... Only some very specific or complicated fonts (script-like, etc...) won't work. But in any case, if the font name you choose doesn't work or doesn't exist, it falls back on a default one. And you can also specify "generic" font names (sans, serif or mono) and the system chooses a default corresponding font.

Here is a python snippet to test that:

Code: Select all

from pivy import coin
sg = Gui.ActiveDocument.ActiveView.getSceneGraph()
sp = coin.SoSeparator()
fn = coin.SoFont()
fn.name = "Arial"
fn.size = 20
te = coin.SoText2
te.string = "Hello world"
sp.addChild(fn)
sp.addChild(te)
sg.addChild(sp)
Then you can change the font by doing anything like:

Code: Select all

fn.name = "Webdings"
I think I could add a property to the Document::Annotation object to specify a fontname... Okay for you?
Post Reply