//----------------------------------------------------------------------------//
//                                                                            //
//                          G l y p h S e c t i o n                           //
//                                                                            //
//  Copyright (C) Herve Bitteur 2000-2006. All rights reserved.               //
//  This software is released under the terms of the GNU General Public       //
//  License. Please contact the author at herve.bitteur@laposte.net           //
//  to report bugs & suggestions.                                             //
//----------------------------------------------------------------------------//
//
package omr.glyph;

import omr.check.SuccessResult;

import omr.lag.Section;

import omr.util.Implement;

import java.awt.Point;

/**
 * Class <code>GlyphSection</code> implements a specific class of section, meant
 * for easy glyph elaboration.
 *
 * Such sections are defined as naturally ordered, first on their position
 * (abscissa for vertical sections), then on their coordinate (ordinate for
 * vertical sections).
 *
 * @author Herv&eacute; Bitteur
 * @version $Id$
 */
public class GlyphSection
    extends Section<GlyphLag, GlyphSection>
    implements Comparable<GlyphSection>
{
    //~ Instance fields --------------------------------------------------------

    /**
     * Glyph this section belongs to
     */
    protected Glyph glyph;

    //~ Constructors -----------------------------------------------------------

    //--------------//
    // GlyphSection //
    //--------------//
    /**
     * Creates a new GlyphSection.
     */
    public GlyphSection ()
    {
    }

    //~ Methods ----------------------------------------------------------------

    //----------//
    // setGlyph //
    //----------//
    /**
     * Assign the containing glyph
     *
     * @param glyph the containing glyph
     */
    public void setGlyph (Glyph glyph)
    {
        this.glyph = glyph;

        // Update the glyphMap of the containing GlyphLag
        getGraph()
            .mapSection(this, glyph);
    }

    //----------//
    // getGlyph //
    //----------//
    /**
     * Report the glyph the section belongs to, if any
     *
     * @return the glyph, which may be null
     */
    public Glyph getGlyph ()
    {
        return glyph;
    }

    //---------------//
    // isGlyphMember //
    //---------------//
    /**
     * Checks whether the section is already a member of a glyph, whether this
     * glyph has been successfully recognized or not.
     *
     * @return the result of the test
     */
    public boolean isGlyphMember ()
    {
        return glyph != null;
    }

    //---------//
    // isKnown //
    //---------//
    /**
     * Check that the section at hand is a member section, aggregated to a known
     * glyph.
     *
     * @return true if member of a known glyph
     */
    public boolean isKnown ()
    {
        return isGlyphMember() &&
               (((glyph.getResult() != null) &&
                glyph.getResult() instanceof SuccessResult) ||
               glyph.isWellKnown());
    }

    //-----------//
    // compareTo //
    //-----------//
    /**
     * Needed to implement Comparable, sorting sections first by position, then
     * by coordinate.
     *
     * @param other the other section to compare to
     * @return the result of ordering
     */
    @Implement(Comparable.class)
    public int compareTo (GlyphSection other)
    {
        Point ref = this.getContourBox()
                        .getLocation();
        Point otherRef = other.getContourBox()
                              .getLocation();

        // Are x values different?
        int dx = ref.x - otherRef.x;

        if (dx != 0) {
            return dx;
        }

        // Vertically aligned, so use ordinates
        int dy = ref.y - otherRef.y;

        if (dy != 0) {
            return dy;
        }
        
        // Finally, use id ...
        return this.getId() - other.getId();
    }

    //----------//
    // toString //
    //----------//
    /**
     * A readable description of this entity
     *
     * @return the string
     */
    @Override
    public String toString ()
    {
        StringBuffer sb = new StringBuffer(256);

        sb.append(super.toString());

        if (glyph != null) {
            sb.append(" glyph#")
              .append(glyph.getId());
        }

        if (this.getClass()
                .getName()
                .equals(GlyphSection.class.getName())) {
            sb.append("}");
        }

        return sb.toString();
    }

    //-----------//
    // getPrefix //
    //-----------//
    /**
     * Report a distinct prefix
     *
     * @return a prefix string
     */
    @Override
    protected String getPrefix ()
    {
        return "GS";
    }
}

@@ -3017,62 +3017,14 @@
 urn 
-isGlyphMember() &&%0A               (((glyph.getResult()
+(glyph
  != 
@@ -3051,70 +3051,32 @@
     
- 
+(
 glyph.
-getResult() instanceof 
+is
 Success
-Result
+ful(
 ) %7C%7C
-%0A              
  gly
@@ -3908,24 +3908,16 @@
       %7D%0A
-        
 %0A       
@@ -4376,24 +4376,159 @@
 ph.getId());
+%0A%0A            if (glyph.getShape() != null) %7B%0A                sb.append(%22:%22)%0A                  .append(glyph.getShape());%0A            %7D
 %0A        %7D%0A%0A

Use of isSuccessful