Rene Just Nielsen
Rene Just Nielsen

Reputation: 3413

Stretch component, not connector

Sometimes when a component is stretched we don't want the connector(s) to be stretched because it looks ugly. See for example the instances of Modelica.Blocks.Sources.RealExpression below

Is it possible to add a graphical annotation when instantiating a connector (or other compent) in a model to avoid this?

enter image description here

Upvotes: 2

Views: 101

Answers (2)

marco
marco

Reputation: 6655

I am not aware of a solution which allows to use the existing RealExpression block. As a workaround you could create new versions of this block - either by extending it or by duplicating it.

Option 1: Extend RealExpression and set fixed size

You could create a new, broader real expression which extends the original real expression, hides the original icon and draws a new one.

Drawback: This requires one model per size, but if a size is used freqently this should be fine.

model RealExpression_600x200
  extends Modelica.Blocks.Sources.RealExpression annotation (
      IconMap(extent={{100,-100},{300,100}}, primitivesVisible=false),
      DiagramMap(extent={{100,-100},{300,100}}, primitivesVisible=false));

equation 

  annotation (
    Diagram(coordinateSystem(extent={{-300,-100},{300,100}})),
    Icon(coordinateSystem(extent={{-300,-100},{300,100}}), graphics={
        Rectangle(
          extent={{-300,40},{300,-40}},
          lineColor={0,0,0},
          lineThickness=5.0,
          fillColor={235,235,235},
          fillPattern=FillPattern.Solid,
          borderPattern=BorderPattern.Raised),
        Text(
          extent={{-300,100},{300,60}},
          textString="%name",
          lineColor={0,0,255}),
        Text(
          extent={{-296,15},{296,-15}},
          lineColor={0,0,0},
          textString="%y")}),
    uses(Modelica(version="3.2.2")));
end RealExpression_600x200;

Screenshot of new RealExpression with fixed size

Option 2: Duplicate RealExpression and set size via parameter

You could also duplicate the RealExpression and introduce a parameter which controls the width of the graphical annotations. Common sizes can be added as a choice. You should not re-scale the component, but select the size with the parameter width instead.

block RealExpression "Real expression with varying size, set via parameter"
  parameter Integer width = 10 
    annotation(choices(choice=20 "Regular", 
                       choice=40 "Wide", 
                       choice=80 "Wiiiiiiide"));

  Modelica.Blocks.Interfaces.RealOutput y=0.0 "Value of Real output"
    annotation (
      Dialog(group="Time varying output signal"), 
      Placement(transformation(extent={{10*width/2,-10},{10*width/2+20,10}})));

  annotation (
    Icon(
      coordinateSystem(
        preserveAspectRatio=true, 
        extent={{-100,-100},{100,100}}), 
      graphics={
        Rectangle(
          extent={{-10*width/2,40},{10*width/2,-40}},
          lineColor={0,0,0},
          lineThickness=5.0,
          fillColor={235,235,235},
          fillPattern=FillPattern.Solid,
          borderPattern=BorderPattern.Raised),
        Text(
          extent={{-10*width/2+4,15},{10*width/2-4,-15}},
          lineColor={0,0,0},
          textString="%y"),
        Text(
          extent={{-10*width/2,90},{10*width/2,50}},
          textString="%name",
          lineColor={0,0,255})}),
    uses(Modelica(version="3.2.2")));
end RealExpression;

Screenshot of realExpressions with variable size, set via parameter

Upvotes: 4

Hans Olsson
Hans Olsson

Reputation: 12517

I don't see any way to do exactly what you want at the moment.

Note that it is possible to prevent stretching of the entire realExpression, using

annotation (Icon(coordinateSystem(preserveAspectRatio=true),...),
  Diagram(coordinateSystem(preserveAspectRatio=true),...),

However, it is not specified that using this in a connector of RealExpression should prevent stretching of the connector - while still allowing stretching of the component.

Upvotes: 3

Related Questions