<?xml version="1.0"?>
<robot name="dm_shelf_macros" xmlns:xacro="http://ros.org/wiki/xacro">

  <xacro:macro name="divider_link" params="parent name *origin">
    <link name="${name}_link">
      <visual>
        <geometry>
          <box size="0.004 0.65 0.05"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="0.004 0.65 0.05"/>
        </geometry>
      </collision>
    </link>

    <joint type="fixed" name="${name}_joint">
      <xacro:insert_block name="origin"/>
      <parent link="${parent}"/>
      <child link="${name}_link"/>
    </joint>
  </xacro:macro>

  <xacro:macro name="shelf_divider" params="parent name dist1 dist2 dist3 dist4 dist5 dist6 dist7 dist8 dist9">
    <divider_link parent="${parent}" name="${name}_divider_1">
      <origin xyz="-0.495 0 0.024"/>
    </divider_link>

    <divider_link parent="${parent}" name="${name}_divider_2">
      <origin xyz="${-0.495 + dist1} 0 0.024"/>
    </divider_link>

    <divider_link parent="${parent}" name="${name}_divider_3">
      <origin xyz="${-0.495 + dist1 + dist2} 0 0.024"/>
    </divider_link>

    <divider_link parent="${parent}" name="${name}_divider_4">
      <origin xyz="${-0.495 + dist1 + dist2 + dist3} 0 0.024"/>
    </divider_link>

    <divider_link parent="${parent}" name="${name}_divider_5">
      <origin xyz="${-0.495 + dist1 + dist2 + dist3 + dist4} 0 0.024"/>
    </divider_link>

    <divider_link parent="${parent}" name="${name}_divider_6">
      <origin xyz="${-0.495 + dist1 + dist2 + dist3 + dist4 + dist5} 0 0.024"/>
    </divider_link>

    <divider_link parent="${parent}" name="${name}_divider_7">
      <origin xyz="${-0.495 + dist1 + dist2 + dist3 + dist4 + dist5 + dist6} 0 0.024"/>
    </divider_link>

    <divider_link parent="${parent}" name="${name}_divider_8">
      <origin xyz="${-0.495 + dist1 + dist2 + dist3 + dist4 + dist5 + dist6 + dist7} 0 0.024"/>
    </divider_link>

    <divider_link parent="${parent}" name="${name}_divider_9">
      <origin xyz="${-0.495 + dist1 + dist2 + dist3 + dist4 + dist5 + dist6 + dist7 + dist8} 0 0.024"/>
    </divider_link>

    <divider_link parent="${parent}" name="${name}_divider_10">
      <origin xyz="${-0.495 + dist1 + dist2 + dist3 + dist4 + dist5 + dist6 + dist7 + dist8 + dist9} 0 0.024"/>
    </divider_link>
  </xacro:macro>


  <xacro:macro name="shelf_1_level" params="name parent *origin dist1 dist2 dist3 dist4 dist5 dist6 dist7 dist8 dist9">
    <link name="${name}_link">
      <visual>
        <geometry>
          <box size="0.988 0.65 0.043"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="0.988 0.65 0.043"/>
        </geometry>
      </collision>
    </link>

    <link name="${name}_left_support_link">
      <visual>
        <geometry>
          <box size="0.004 0.65 0.12"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="0.004 0.65 0.12"/>
        </geometry>
      </collision>
    </link>

    <link name="${name}_right_support_link">
      <visual>
        <geometry>
          <box size="0.004 0.65 0.12"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="0.004 0.65 0.12"/>
        </geometry>
      </collision>
    </link>


    <joint type="fixed" name="${name}_joint">
      <xacro:insert_block name="origin"/>
      <parent link="${parent}"/>
      <child link="${name}_link"/>
    </joint>

    <joint type="fixed" name="${name}_right_support_joint">
      <origin xyz="0.494 0 -0.06"/>
      <parent link="${name}_link"/>
      <child link="${name}_right_support_link"/>
    </joint>

    <joint type="fixed" name="${name}_left_support_joint">
      <origin xyz="-0.494 0 -0.06"/>
      <parent link="${name}_link"/>
      <child link="${name}_left_support_link"/>
    </joint>


    <shelf_divider parent="${name}_link" name="${name}" dist1="${dist1}" dist2="${dist2}" dist3="${dist3}" dist4="${dist4}" dist5="${dist5}" dist6="${dist6}" dist7="${dist7}" dist8="${dist8}" dist9="${dist9}" />
  </xacro:macro>





  <xacro:macro name="shelf_1" params="*origin parent name">
    <link name="${name}_base">
      <visual>
        <geometry>
          <box size="1.1 1.05 0.173"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="1.1 1.05 0.173"/>
        </geometry>
      </collision>
    </link>

    <joint type="fixed" name="${name}_joint">
      <xacro:insert_block name="origin"/>
      <parent link="${parent}"/>
      <child link="${name}_base"/>
    </joint>

    <link name="${name}_back">
      <visual>
        <geometry>
          <box size="1.04 0.12 2"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="1.04 0.12 2"/>
        </geometry>
      </collision>
    </link>

    <joint type="fixed" name="${name}_base_back_joint">
      <origin xyz="0 0.365 1"/>
      <parent link="${name}_base"/>
      <child link="${name}_back"/>
    </joint>

    <link name="${name}_level_0_link">
      <visual>
        <geometry>
          <box size="1 0.78 0.043"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="1 0.78 0.043"/>
        </geometry>
      </collision>
    </link>

    <joint type="fixed" name="${name}_level_0_joint">
      <origin xyz="0 -0.06 0.10665"/>
      <parent link="${name}_base"/>
      <child link="${name}_level_0_link"/>
    </joint>



    <shelf_1_level name="${name}_level_1" parent="${name}_base" dist1="0.15" dist2="0.133" dist3="0.082" dist4="0.167" dist5="0.095" dist6="0.148" dist7="0.095" dist8="0.125" dist9="0" >
      <origin xyz="0 0 0.50965" />
    </shelf_1_level>

    <shelf_1_level name="${name}_level_2" parent="${name}_base" dist1="0.177" dist2="0.208" dist3="0.147" dist4="0.20" dist5="0.124" dist6="0.14" dist7="0" dist8="0" dist9="0" >
      <origin xyz="0 0 0.84465" />
    </shelf_1_level>

    <shelf_1_level name="${name}_level_3" parent="${name}_base" dist1="0" dist2="0" dist3="0" dist4="0" dist5="0" dist6="0" dist7="0" dist8="0" dist9="0" >
      <origin xyz="0 0 1.22265" />
    </shelf_1_level>

    <shelf_1_level name="${name}_level_4" parent="${name}_base" dist1="0" dist2="0" dist3="0" dist4="0" dist5="0" dist6="0" dist7="0" dist8="0" dist9="0" >
      <origin xyz="0 0 1.53565" />
    </shelf_1_level>

    <shelf_1_level name="${name}_level_5" parent="${name}_base" dist1="0" dist2="0" dist3="0" dist4="0" dist5="0" dist6="0" dist7="0" dist8="0" dist9="0" >
      <origin xyz="0 0 1.86865" />
    </shelf_1_level>
  </xacro:macro>


  <!-- Shelf 2 -->
  <xacro:macro name="shelf_2_level" params="name parent *origin">
    <link name="shelf_2_${name}_link">
      <visual>
        <geometry>
          <box size="0.992 0.435 0.043"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="0.992 0.435 0.043"/>
        </geometry>
      </collision>
    </link>

    <joint type="fixed" name="shelf_2_${name}_joint">
      <xacro:insert_block name="origin"/>
      <parent link="${parent}"/>
      <child link="shelf_2_${name}_link"/>
    </joint>
  </xacro:macro>


  <xacro:macro name="shelf_2" params="*origin parent name">
    <link name="${name}_base">
      <visual>
        <geometry>
          <box size="1.1 0.8 0.145"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="1.1 0.8 0.145"/>
        </geometry>
      </collision>
    </link>

    <joint type="fixed" name="${name}_joint">
      <xacro:insert_block name="origin"/>
      <parent link="${parent}"/>
      <child link="${name}_base"/>
    </joint>

    <link name="${name}_left_side">
      <visual>
        <geometry>
          <box size="0.05 0.54 1.6"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="0.05 0.54 1.6"/>
        </geometry>
      </collision>
    </link>

    <joint type="fixed" name="${name}_base_left_joint">
      <origin xyz="-0.475 0 0.7225"/>
      <parent link="${name}_base"/>
      <child link="${name}_left_side"/>
    </joint>

    <link name="${name}_right_side">
      <visual>
        <geometry>
          <box size="0.05 0.54 1.6"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="0.05 0.54 1.6"/>
        </geometry>
      </collision>
    </link>

    <joint type="fixed" name="${name}_base_right_joint">
      <origin xyz="0.475 0 0.7225"/>
      <parent link="${name}_base"/>
      <child link="${name}_right_side"/>
    </joint>

    <link name="${name}_back">
      <visual>
        <geometry>
          <box size="1 0.05 1.45"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="1 0.05 1.45"/>
        </geometry>
      </collision>
    </link>

    <joint type="fixed" name="${name}_base_back_joint">
      <origin xyz="0 0.275 0.7725"/>
      <parent link="${name}_base"/>
      <child link="${name}_back"/>
    </joint>

    <link name="${name}_level_0_link">
      <visual>
        <geometry>
          <box size="0.992 0.54 0.043"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="0.992 0.54 0.043"/>
        </geometry>
      </collision>
    </link>

    <joint type="fixed" name="${name}_level_0_joint">
      <origin xyz="0 0 0.0925"/>
      <parent link="${name}_base"/>
      <child link="${name}_level_0_link"/>
    </joint>



    <shelf_2_level name="${name}_level_1" parent="${name}_base">
      <origin xyz="0 0.0 0.374"/>
    </shelf_2_level>

    <shelf_2_level name="${name}_level_2" parent="${name}_base">
      <origin xyz="0 0.0 0.624"/>
    </shelf_2_level>

    <shelf_2_level name="${name}_level_3" parent="${name}_base">
      <origin xyz="0 0.0 0.864"/>
    </shelf_2_level>

    <shelf_2_level name="${name}_level_4" parent="${name}_base">
      <origin xyz="0 0.0 1.17"/>
    </shelf_2_level>

    <shelf_2_level name="${name}_level_5" parent="${name}_base">
      <origin xyz="0 0.0 1.42"/>
    </shelf_2_level>
  </xacro:macro>


  <xacro:macro name="wall" params="parent name size *origin">
    <link name="${name}_link">
      <visual>
        <geometry>
          <box size="${size}"/>
        </geometry>
      </visual>
      <collision>
        <geometry>
          <box size="${size}"/>
        </geometry>
      </collision>
    </link>

    <joint type="fixed" name="${name}_joint">
      <xacro:insert_block name="origin"/>
      <parent link="${parent}"/>
      <child link="${name}_link"/>
    </joint>
  </xacro:macro>
</robot>
