Skip to main content



      Home
Home » Eclipse Projects » Sirius » Get and set Text size in any DNode and DEdge
Get and set Text size in any DNode and DEdge [message #1743160] Mon, 12 September 2016 15:01 Go to next message
Eclipse UserFriend
Hi,

I intended to set programmatically the size of the font used in all the labels of all DNode and DEdge of a given DRepresentation.

The code below is where I got so far, but it doesn't seem to modify the representations at all. Actually even description.getLabelSize() doesn't return the correct size value when I set it manually in the Properties view, see screenshot.

Any idea what I might be doing wrong ????

many thanks in advance for a quick feedback,
Benoît

***************
"rep" is of type DRepresentation

for (DRepresentationElement repElt: rep.getRepresentationElements()) {
if (repElt instanceof DNode || repElt instanceof DNodeContainer || repElt instanceof DNodeList || repElt instanceof DNodeListElement) {
if (repElt.getStyle().getDescription() instanceof NodeStyleDescription) {
NodeStyleDescription desc = (NodeStyleDescription) repElt.getStyle().getDescription();
desc.setLabelSize(fontSize);
repElt.getStyle().setDescription(desc);
} else if (repElt.getStyle().getDescription() instanceof ContainerStyleDescription) {
ContainerStyleDescription desc = (ContainerStyleDescription) repElt.getStyle().getDescription();
desc.setLabelSize(fontSize);
repElt.getStyle().setDescription(desc);
}
} else if (repElt instanceof DEdge) {
EdgeStyleDescription desc = (EdgeStyleDescription)repElt.getStyle().getDescription();
if (desc.getBeginLabelStyleDescription() != null) {
desc.getBeginLabelStyleDescription().setLabelSize(fontSize);
}
if (desc.getCenterLabelStyleDescription() != null) {
desc.getCenterLabelStyleDescription().setLabelSize(fontSize);
}
if (desc.getEndLabelStyleDescription() != null) {
desc.getEndLabelStyleDescription().setLabelSize(fontSize);
}
repElt.getStyle().setDescription(desc);
}
Re: Get and set Text size in any DNode and DEdge [message #1743163 is a reply to message #1743160] Mon, 12 September 2016 15:53 Go to previous messageGo to next message
Eclipse UserFriend
*Decription elements are part of the VSM (.odesign), not part of the representations (.aird). They should be treated as immutable, as any change to them will not persist (in particular when the VSM is loaded from a plug-in).

If you want to customize the style of the elements from a representation, you need to update directly their style. However this is not enough by itself, because any change on a Style will by default be overridden by the next Sirius refresh (it's the whole point of the refresh to synchronize the state of the representation according to the definitions from the VSM). To tell Sirius not to apply the synchronization for the features you customized explicitly, you need to add the corresponding EStructuralFeature to the style's customFeatures references.

In pseudo-code:

Node node = ...;
node.getStyle().setLabelSize(16);
node.getCustomFeatures().add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_SIZE);

Regards,
Pierre-Charles David
Re: Get and set Text size in any DNode and DEdge [message #1743186 is a reply to message #1743163] Tue, 13 September 2016 02:13 Go to previous messageGo to next message
Eclipse UserFriend
Thanks a lot Pierre-Charles, I got the point and it is now working Smile
Re: Get and set Text size in any DNode and DEdge [message #1743204 is a reply to message #1743186] Tue, 13 September 2016 05:43 Go to previous messageGo to next message
Eclipse UserFriend
What about for the Font Name....? it seems to be a complete different story...?

If I modify manually using the Sirius UI the default font of a given node, there is no custom features added, so I guess that programmatically it is a different strategy ?

as a first step, I can't find any description.setLabelFont()

[Updated on: Tue, 13 September 2016 05:44] by Moderator

Re: Get and set Text size in any DNode and DEdge [message #1743303 is a reply to message #1743204] Wed, 14 September 2016 04:48 Go to previous message
Eclipse UserFriend
The font used is not defined in the VSM, it's a GMF-only attribute. You'll need to update the FontStyle element of the underlying GMF Notation View object. It's a little indirect to obtain it, you'll need something like view.getStyle(NotationPackage.eINSTANCE.getFontStyle()), where 'view' is a GMF view.

If you have the edit part, it looks like this:

FontStyle fontStyle = (FontStyle) part.getNotationView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
Previous Topic:How to use navigations in Tables
Next Topic:Multi-directional connections; or: How to model electrical wires?
Goto Forum:
  


Current Time: Tue Mar 25 02:11:43 EDT 2025

Powered by FUDForum. Page generated in 3.90739 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top