4

I want to create an icon for a model that combines two components from the Modelica standard library. These two components are Modelica.Blocks.Sources.Sine and Modelica.Electrical.Analog.Sources.SignalVoltage. I have connected the two components so that the code looks like this:

model test
 Modelica.Blocks.Sources.Sine sine1(freqHz = 5, amplitude = 1, offset = 10) annotation(Placement(visible = true, transformation(origin = {-51.0325,-0.884933}, extent = {{-12,-12},{12,12}}, rotation = 0)));
 Modelica.Electrical.Analog.Sources.SignalVoltage signalvoltage1 annotation(Placement(visible = true, transformation(origin = {-4.12979,-1.17994}, extent = {{12,-12},{-12,12}}, rotation = 90)));
equation
 connect(sine1.y,signalvoltage1.v) annotation(Line(points = {{-37.8325,-0.884933},{-12.9794,-0.884933},{-12.9794,-1.17994},{-12.5298,-1.17994}}));
end test;

The annotation is done automatically by OMEdit.

Now I want to achieve the following: I want to create an icon that

  • contains the Pins of signalvoltage1
  • that gives access to the properties of sine1 by double clicking.

I know about the annotation(Icon(...)) and annotation(Placement(...)) commands but I don't know how to bring signalvoltage1.p and signalvoltage1.n to the icon layer. And I don't know how to access the properties of sine1 by double clicking onto, e.g., a rectangle that I can easily draw using OMEdit.

Thanks in advance.

1 Answers1

5

Now I want to achieve the following: I want to create an icon that

contains the Pins of signalvoltage1 that gives access to the properties of sine1 by double clicking.

OK for the pins: Normally the graphical editor should give you a choice to create the fitting connector automatically whenever you root from an existing connector to a blank spot on your diagram. However OMEdit doesn't so (yet?). So therefore you need to drag and drop the respective connectors from the MSL into the diagram view of your model. In your case Modelica.Electrical.Analog.Interfaces.NegativePin and Modelica.Electrical.Analog.Interfaces.PositivePin and then connect them appropriately. A component of type connector will (should) automatically appear on the diagram AND icon layer so it can be connected "from the outside".

As for the access. you create a new parameter on the level of your model and let the components inside your new model use those parameters. Probably best explained by taking your example from above:

model Test
  parameter Real myfreqHz = 5 "Frequency of the sinewave";
  parameter Real myamplitude = 1 "Amplitude of the sinewave";    
  parameter Real myoffset = 1 "Offset of the sinewave";
  Modelica.Blocks.Sources.Sine sine1(freqHz = myfreqHz, 
                               amplitude = myamplitude, offset = myoffset);
  Modelica.Electrical.Analog.Sources.SignalVoltage signalvoltage1;
equation
...
end Test;
Dietmar Winkler
  • 942
  • 5
  • 11
  • @Diemtar Winkler Nice answer! That's what I was looking for, thank you! Indeed, it will be more elegant, if OMEdit supports the feature you mentioned so that one doesn't need to insert those dummy pins. – user2083291 Feb 19 '13 at 08:13
  • The term "propagate" is often used to describe this process. The idea is that when you build a sub-system of components, you need to propagate *some* of the information in the sub-system (connectors and parameters mainly) up to the next higher level in the hierarchy. As Dietmar points out, this is such a common process that most tools have "shortcuts" of some kind that help you do this propagation. – Michael Tiller Feb 19 '13 at 13:47