Esempio n. 1
0
    // TODO FIX-TEST
    public final void NtestRead() {
      final DebriefXMLReaderWriter reader = new DebriefXMLReaderWriter(null);
      final Layers res = new Layers();
      final String fName = "../org.mwc.debrief.legacy/src/test_tma_read_write.xml";

      final java.io.File fileTest = new File(fName);
      assertTrue("Test file not found:" + fName, fileTest.exists());

      try {
        final java.io.FileInputStream fis = new java.io.FileInputStream(fName);
        reader.importThis(fName, fis, res);

        // right, now check it contains our data
        final Layer layer = res.findLayer("TOMATO");
        assertNotNull("found tomato track");

        final TrackWrapper tw = (TrackWrapper) layer;
        final Enumeration<Editable> solutions = tw.getSolutions().elements();
        assertNotNull("found solutions", solutions);

        // find our solution track
        while (solutions.hasMoreElements()) {
          final TMAWrapper wrapper = (TMAWrapper) solutions.nextElement();
          assertEquals("found our solution", "TRACK_060", wrapper.getName());

          final Enumeration<Editable> contacts = wrapper.elements();
          while (contacts.hasMoreElements()) {
            final TMAContactWrapper contactWrapper = (TMAContactWrapper) contacts.nextElement();
            assertEquals("found first contact", "Trial label", contactWrapper.getLabel());
            assertEquals("correct symbol set", "Submarine", contactWrapper.getSymbol());
            assertEquals("correct vis set", true, contactWrapper.getVisible());
            assertEquals("correct label vis", true, contactWrapper.getLabelVisible());
            assertEquals("correct colour set", new Color(230, 200, 20), contactWrapper.getColor());
            assertEquals("correct ellipse vis", true, contactWrapper.getEllipseVisible());
            assertEquals("correct symbol vis", true, contactWrapper.getSymbolVisible());
            assertEquals("correct line vis", true, contactWrapper.getLineVisible());
            assertEquals(
                "correct label loc",
                new Integer(MWC.GUI.Properties.LocationPropertyEditor.RIGHT),
                contactWrapper.getLabelLocation());
            assertEquals("correct line course", 50, contactWrapper.getTargetCourse(), 0d);
            assertEquals("correct line speed", 12.4, contactWrapper.getSpeed(), 0d);
            assertEquals("correct line depth", 100, contactWrapper.getDepth(), 0d);
            final EllipseShape es = contactWrapper.buildGetEllipse();
            assertEquals("correct orientation", 45, es.getOrientation(), 0d);
            assertEquals(
                "correct maxima", 4000, es.getMaxima().getValueIn(WorldDistance.YARDS), 0.00001d);
            assertEquals(
                "correct minima", 2000, es.getMinima().getValueIn(WorldDistance.YARDS), 0.0001d);
          }
        }
      } catch (final FileNotFoundException e) {
        e.printStackTrace(); // To change body of catch statement use Options |
        // File Templates.
      }
    }
Esempio n. 2
0
  public static void exportSolution(
      final Debrief.Wrappers.TMAContactWrapper contact, final Element parent, final Document doc) {
    /*
     *
     * <!ELEMENT tma_solution (colour?, centre?)> <!ATTLIST tma_solution Dtg
     * CDATA #REQUIRED Bearing CDATA #IMPLIED Range CDATA #IMPLIED Visible (TRUE
     * | FALSE) "TRUE" Label CDATA #REQUIRED LabelShowing (TRUE | FALSE) "TRUE"
     * LineShowing (TRUE | FALSE) "TRUE" EllipseShowing (TRUE | FALSE) "TRUE"
     * SymbolShowing (TRUE | FALSE) "TRUE" LabelLocation (Top | Left | Bottom |
     * Centre | Right) "Left" Course CDATA #REQUIRED Speed CDATA #REQUIRED Depth
     * CDATA #REQUIRED Orientation CDATA #REQUIRED Maxima CDATA #REQUIRED Minima
     * CDATA #REQUIRED >
     */
    final Element eFix = doc.createElement(MY_NAME);

    // note, we are accessing the "actual" colour for this fix, we are not using
    // the
    // normal getColor method which may return the track colour
    final java.awt.Color fCol = contact.getActualColor();
    if (fCol != null) ColourHandler.exportColour(fCol, eFix, doc);

    // are we absolute or relative?
    final WorldLocation origin = contact.buildGetOrigin();
    if (origin != null) {
      // so, absolute - output it
      LocationHandler.exportLocation(origin, "centre", eFix, doc);
    } else {
      // so, relative - output it
      eFix.setAttribute("Bearing", writeThis(contact.getBearing()));

      // don't do range by hand, automate it
      WorldDistanceHandler.exportDistance(RANGE, contact.getRange(), eFix, doc);
    }

    // carry on with the common parameters
    eFix.setAttribute("Dtg", writeThis(contact.getDTG()));
    eFix.setAttribute("Visible", writeThis(contact.getVisible()));

    // now the label/visibility
    eFix.setAttribute("Symbol", contact.getSymbol());
    eFix.setAttribute("Label", toXML(contact.getLabel()));
    eFix.setAttribute("LabelShowing", writeThis(contact.getLabelVisible()));

    final Boolean lineVis = contact.getRawLineVisible();
    // is this the same as the parent?
    if (lineVis != null) {
      // only output the line visibility if it is different to the parent.
      eFix.setAttribute("LineShowing", writeThis(lineVis.booleanValue()));
    }

    eFix.setAttribute("EllipseShowing", writeThis(contact.getEllipseVisible()));
    eFix.setAttribute("SymbolShowing", writeThis(contact.getSymbolVisible()));

    // where is the label?
    lp.setValue(contact.getLabelLocation());
    final String val = lp.getAsText();
    if (val != null) eFix.setAttribute("LabelLocation", lp.getAsText());
    else System.out.println("WRONG LABEL VALUE!!!");

    // and the target vector
    eFix.setAttribute("Course", writeThis(contact.getTargetCourse()));
    eFix.setAttribute("Speed", writeThis(contact.getSpeed()));
    eFix.setAttribute("Depth", writeThis(contact.getDepth()));

    // and ellipse shape
    final EllipseShape ellipse = contact.buildGetEllipse();
    final double maxima = ellipse.getMaxima().getValueIn(WorldDistance.YARDS);
    final double minima = ellipse.getMinima().getValueIn(WorldDistance.YARDS);

    // did we find ellipse data?
    if ((maxima > 0.0001d) && (minima > 0.0001d)) {
      // yes, write it out
      eFix.setAttribute("Orientation", writeThis(ellipse.getOrientation()));

      WorldDistanceHandler.exportDistance(MAXIMA, ellipse.getMaxima(), eFix, doc);
      WorldDistanceHandler.exportDistance(MINIMA, ellipse.getMinima(), eFix, doc);
    }

    // done
    parent.appendChild(eFix);
  }