FixedShape2

model FixedShape2 "Visualizing an elementary shape with dynamically varying shape attributes (has two frame connectors)"
    import Modelica.Mechanics.MultiBody.Frames;
    import Modelica.Mechanics.MultiBody.Types;
    import Modelica.SIunits.Conversions.to_unit1;

    Interfaces.Frame_a frame_a "Coordinate system a (all shape definition vectors are resolved in this frame)"
        annotation (Placement(transformation(extent = {
            {-116, -16}, 
            {-84, 16}})));
    Interfaces.Frame_b frame_b "Coordinate system b"
        annotation (Placement(transformation(extent = {
            {84, -16}, 
            {116, 16}})));
    parameter Boolean animation = true "= true, if animation shall be enabled";
    parameter Types.ShapeType shapeType = "box" "Type of shape"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input SI.Position r[3] = {1, 0, 0} "Vector from frame_a to frame_b resolved in frame_a";
    input SI.Position r_shape[3] = {0, 0, 0} "Vector from frame_a to shape origin, resolved in frame_a"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input Types.Axis lengthDirection = to_unit1(r - r_shape) "Vector in length direction of shape, resolved in frame_a"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input Types.Axis widthDirection = {0, 1, 0} "Vector in width direction of shape, resolved in frame_a"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input SI.Length length = Modelica.Math.Vectors.length(r - r_shape) "Length of shape"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input SI.Distance width = 0.1 "Width of shape"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input SI.Distance height = width "Height of shape"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input Types.ShapeExtra extra = 0 "Additional data for cylinder, cone, pipe, gearwheel and spring"
        annotation (Dialog(
            group = "if animation = true",
            enable = animation));
    input Types.Color color = {0, 128, 255} "Color of shape"
        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));
protected
    outer MultiBody.World world;
    Advanced.Shape shape(shapeType = shapeType, r_shape = r_shape, lengthDirection = lengthDirection, widthDirection = widthDirection, length = length, width = width, height = height, extra = extra, color = color, specularCoefficient = specularCoefficient, r = frame_a.r_0, R = frame_a.R) if world.enableAnimation and animation;
equation
    assert(0 < cardinality(frame_a) or 0 < cardinality(frame_b), "Neither connector frame_a nor frame_b of\nMultiBody.Visualizers.FixedShape2 object is connected");
    Connections.branch(frame_a.R, frame_b.R);
    frame_b.R = frame_a.R;
    frame_b.r_0 = frame_a.r_0 + Frames.resolve1(frame_a.R, r);
    zeros(3) = frame_a.t + frame_b.t + cross(r, frame_b.f);
    zeros(3) = frame_a.f + frame_b.f;

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Text(
                    extent = {
                        {-150, 115}, 
                        {150, 75}},
                    textString = "%name",
                    lineColor = {0, 0, 255}), 
                Text(
                    extent = {
                        {150, -90}, 
                        {-150, -60}},
                    textString = "r=%r"), 
                Polygon(
                    points = {
                        {-100, 50}, 
                        {-66, 62}, 
                        {0, 46}, 
                        {100, 70}, 
                        {80, 50}, 
                        {-10, 28}, 
                        {-100, 50}},
                    lineColor = {255, 255, 255},
                    fillColor = {160, 160, 164},
                    fillPattern = FillPattern.Solid), 
                Polygon(
                    points = {
                        {100, 70}, 
                        {80, 50}, 
                        {80, -44}, 
                        {100, -16}, 
                        {100, 70}},
                    lineColor = {255, 255, 255},
                    fillColor = {160, 160, 164},
                    fillPattern = FillPattern.Solid), 
                Polygon(
                    points = {
                        {-100, 50}, 
                        {-100, -44}, 
                        {-10, -24}, 
                        {80, -44}, 
                        {80, 50}, 
                        {-10, 28}, 
                        {-100, 50}},
                    lineColor = {215, 215, 215},
                    fillColor = {0, 127, 255},
                    fillPattern = FillPattern.Solid), 
                Text(
                    extent = {
                        {-86, 15}, 
                        {-50, -10}},
                    textString = "a"), 
                Text(
                    extent = {
                        {37, 15}, 
                        {73, -10}},
                    textString = "b")}),
        Documentation(info = "<html>\n<p>\nModel <strong>FixedShape2</strong> defines a visual shape that is\nshown at the location of its frame_a. This model is identical\nto <strong>FixedShape</strong> with the only difference that an\nadditional frame_b is present which is parallel to frame_a.\nThis makes it more convenient to connect several visual\nshapes together when building up more complex visual\nobjects. All describing data such as size and color can vary dynamically by\nproviding appropriate expressions in the input fields of the\nparameter menu. The only exception is parameter shapeType\nthat cannot be changed during simulation.\nThe following shapes are currently supported via\nparameter <strong>shapeType</strong> (e.g., shapeType=\"box\"):<br>&nbsp;\n</p>\n\n<p>\n<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Shape.png\" alt=\"model Visualizers.FixedShape2\">\n</p>\n\n<p>&nbsp;<br>\nThe dark blue arrows in the figure above are directed along\nvariable <strong>lengthDirection</strong>. The light blue arrows are directed\nalong variable <strong>widthDirection</strong>. The <strong>coordinate systems</strong>\nin the figure represent frame_a of the FixedShape component.\n</p>\n\n<p>\nAdditionally, <strong>external shapes</strong> can be specified as (not all options might be supported by all tools):\n</p>\n\n<ul>\n<li> <strong>\"1\", \"2\", ...</strong><br>\n     define external shapes specified in DXF format in files \"1.dxf\", \"2.dxf\", ...\n     The DXF-files must be found either in the current directory or in the directory where\n     the Shape instance is stored that references the DXF file.\n     This (very limited) option should not be used for new models. Example:<br>\n    shapeType=\"1\".<br></li>\n\n<li> \"<strong>modelica:</strong>//&lt;Modelica-name&gt;/&lt;relative-path-file-name&gt;\"<br>\n     characterizes the file that is stored under the location of the\n     &lt;Modelica-name&gt; library path with the given relative file name.\n     Example:<br> shapeType = \"modelica://Modelica/Resources/Data/Shapes/Engine/piston.dxf\".<br></li>\n\n<li> \"<strong>file:</strong>//&lt;absolute-file-name&gt;\"<br>\n     characterizes an absolute file name in the file system. Example:<br>\n     shapeType=\"file://C:/users/myname/shapes/piston.dxf\".</li>\n</ul>\n\n<p>\nThe supported file formats are tool dependent. Most tools support at least DXF-files\nbut may support other format as well (such as stl, obj, 3ds).\nSince visualization files contain color and other data, the corresponding\ninformation in the model is usually ignored.\nFor information about DXF files, see <a href=\"https://en.wikipedia.org/wiki/AutoCAD_DXF\">Wikipedia</a>.\nAs a default it is assumed that the DXF coordinates are in the \"frame_a\"-system and in meters, and that the 3dfaces are two-sided.\nSome tools support only 3dface (for geometry) and layer (for advanced coloring).\n</p>\n\n<p>\nThe sizes of any of the above components are specified by the\n<strong>length</strong>, <strong>width</strong> and <strong>height</strong> variables.\nVia variable <strong>extra</strong> additional data can be defined:\n</p>\n<table border=1 cellspacing=0 cellpadding=2>\n<tr><th><strong>shapeType</strong></th><th>Meaning of parameter <strong>extra</strong></th></tr>\n<tr>\n  <td>\"cylinder\"</td>\n  <td>if extra&nbsp;&gt;&nbsp;0, a black line is included in the\n      cylinder to show the rotation of it.</td>\n</tr>\n<tr>\n  <td>\"cone\"</td>\n  <td>extra = diameter-left-side / diameter-right-side, i.e.,<br>\n      extra = 1: cylinder<br>\n      extra = 0: \"real\" cone.</td>\n</tr>\n<tr>\n  <td>\"pipe\"</td>\n  <td>extra = outer-diameter / inner-diameter, i.e,<br>\n      extra = 1: cylinder that is completely hollow<br>\n      extra = 0: cylinder without a hole.</td>\n</tr>\n<tr>\n  <td>\"gearwheel\"</td>\n  <td>extra is the number of teeth of the (external) gear.\nIf extra&nbsp;&lt;&nbsp;0, an internal gear is visualized with |extra| teeth.\nThe axis of the gearwheel is along \"lengthDirection\", and usually:\nwidth = height = 2*radiusOfGearWheel.</td>\n</tr>\n<tr>\n  <td>\"spring\"</td>\n  <td>extra is the number of windings of the spring.\n      Additionally, \"height\" is <strong>not</strong> the \"height\" but\n      2*coil-width.</td>\n</tr>\n<tr>\n  <td>external shape</td>\n  <td>extra = 0: Visualization from file is not scaled.<br>\n                     extra = 1: Visualization from file is scaled with \"length\", \"width\" and \"height\"\n                                of the shape</td>\n</tr>\n</table>\n<p>\nParameter <strong>color</strong> is a vector with 3 elements,\n{r,&nbsp;g,&nbsp;b}, and specifies the color of the shape.\n{r,&nbsp;g,&nbsp;b} are the \"red\", \"green\" and \"blue\" color parts.\nNote, r, g, b are given as Integer[3] in the ranges 0&nbsp;..&nbsp;255,\nrespectively. The predefined type\n<a href=\"modelica://Modelica.Mechanics.MultiBody.Types.Color\">MultiBody.Types.Color</a> contains a menu\ndefinition of the colors used in the MultiBody library together with a color editor.\n</p>\n<p>\nIn the following figure the relationships between\nframe_a and frame_b are shown. The origin of frame_b\nwith respect to frame_a is specified via parameter\nvector&nbsp;<strong>r</strong>.\n</p>\n\n<p>\n<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/FixedTranslation.png\" alt=\"Parts.FixedTranslation\">\n</p>\n</html>"));
end FixedShape2;