SignalArrow

model SignalArrow "Visualizing an arrow with dynamically varying size in frame_a based on input signal"
    import Modelica.Mechanics.MultiBody.Types;

    extends Modelica.Mechanics.MultiBody.Interfaces.PartialVisualizer;

    parameter Boolean animation = true "= true, if animation shall be enabled";
    input SI.Position r_tail[3] = {0, 0, 0} "Vector from frame_a to arrow tail, resolved in frame_a"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input SI.Diameter diameter = world.defaultArrowDiameter "Diameter of arrow line"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input Modelica.Mechanics.MultiBody.Types.Color color = {0, 0, 255} "Color of arrow"
        annotation (Dialog(
            colorSelector = true,
            group = "if animation = true",
            enable = animation));
    input Types.SpecularCoefficient specularCoefficient = world.defaultSpecularCoefficient "Reflection of ambient light (= 0: light is completely absorbed)"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    Modelica.Blocks.Interfaces.RealInput r_head[3](each final quantity = "Length", each final unit = "m") "Position vector from origin of frame_a to head of arrow, resolved in frame_a"
        annotation (Placement(transformation(
            origin = {0, -120},
            extent = {
                {-20, -20}, 
                {20, 20}},
            rotation = 90)));
protected
    Visualizers.Advanced.Arrow arrow(R = frame_a.R, r = frame_a.r_0, r_tail = r_tail, r_head = r_head, diameter = diameter, color = color, specularCoefficient = specularCoefficient) if world.enableAnimation and animation;
equation
    frame_a.f = zeros(3);
    frame_a.t = zeros(3);

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Line(
                    points = {
                        {0, -102}, 
                        {0, -28}},
                    color = {0, 0, 127}), 
                Rectangle(
                    extent = {
                        {-100, 28}, 
                        {20, -28}},
                    lineColor = {128, 128, 128},
                    fillColor = {128, 128, 128},
                    fillPattern = FillPattern.Solid), 
                Polygon(
                    points = {
                        {20, 60}, 
                        {100, 0}, 
                        {20, -60}, 
                        {20, 60}},
                    lineColor = {128, 128, 128},
                    fillColor = {128, 128, 128},
                    fillPattern = FillPattern.Solid), 
                Text(
                    extent = {
                        {-150, 105}, 
                        {150, 65}},
                    textString = "%name",
                    lineColor = {0, 0, 255})}),
        Documentation(info = "<html>\n<p>\nModel <strong>SignalArrow</strong> defines an arrow that is dynamically visualized\nat the location where its frame_a is attached. The\nposition vector from the tail to the head of the arrow,\nresolved in frame_a, is defined via the signal vector of\nthe connector <strong>r_head</strong> (Real r_head[3]):<br>&nbsp;\n</p>\n\n<p>\n<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Visualizers/Arrow.png\" alt=\"model Visualizers.SignalArrow\">\n</p>\n<p>\nThe tail of the arrow is defined with parameter <strong>r_tail</strong>\nwith respect to frame_a (vector from the origin of frame_a to the arrow tail).\n</p>\n</html>"));
end SignalArrow;