public static void send(RsProtocol protocol, RsPlan plan) throws IOException {

      DataOutputStream  output = protocol.output;   // merely to save some typing

      RsObject  [] object;
      RsWall       wall;
      RsTarget     target;
      RsPlacement  placement;
      RsNavNode    navNode;
      RsNavLink    navLink;
      RsPaint      paint;

      if(plan==null){
         output.writeInt(0);
         output.flush();
         return;
      }else{
         output.writeInt(1);
      }

      protocol.writeString(plan.getCaption());

      // send plan object specifications

      object = plan.getObjectArray();
      if(object == null)
         throw new IOException("Attempt to send an empty plan definition");

      output.writeInt(object.length);
      for(int i=0; i<object.length; i++){
         // send object-specific elements

         if(object[i] instanceof RsWall){
            wall = (RsWall)(object[i]);
            output.writeInt(RsProtocol.PLAN_WALL);
            protocol.writeString(object[i].getName());
            sendGeometry(output, wall.getGeometry());

         }else if(object[i] instanceof RsTarget){
            target = (RsTarget)(object[i]);
            output.writeInt(RsProtocol.PLAN_TARGET);
            protocol.writeString(object[i].getName());
            sendGeometry(output, target.getGeometry());

         }else if(object[i] instanceof RsPlacement){
            placement = (RsPlacement)(object[i]);
            output.writeInt(RsProtocol.PLAN_PLACEMENT);
            protocol.writeString(object[i].getName());
            sendGeometry(output, placement.getGeometry());

         }else if(object[i] instanceof RsNavNode){
            navNode = (RsNavNode)(object[i]);
            output.writeInt(RsProtocol.PLAN_NAV_NODE);
            protocol.writeString(navNode.getName());
            output.writeDouble(navNode.x);
            output.writeDouble(navNode.y);
            protocol.writeString(navNode.label);
            sendColor(output, navNode.lineColor);

         }else if(object[i] instanceof RsNavLink){
            navLink = (RsNavLink)(object[i]);
            output.writeInt(RsProtocol.PLAN_NAV_LINK);
            protocol.writeString(navLink.getName());
            protocol.writeString(navLink.n0.getName());
            protocol.writeString(navLink.n1.getName());
            protocol.writeString(navLink.label);
            sendColor(output, navLink.lineColor);

         }else if(object[i] instanceof RsPaint){
            paint = (RsPaint)(object[i]);
            output.writeInt(RsProtocol.PLAN_PAINT);
            protocol.writeString(object[i].getName());
            sendGeometry(output, paint.getGeometry());
            sendColor(output, paint.fillColor);
         }
      }


      output.flush();
   }