001/*
002 *   GenScreenNote  -- Partial implementation of a note is displayed at a fixed size on the screen.
003 *
004 *   Copyright (C) 2014-2015, Joseph A. Huwaldt
005 *   All rights reserved.
006 *   
007 *   This library is free software; you can redistribute it and/or
008 *   modify it under the terms of the GNU Lesser General Public
009 *   License as published by the Free Software Foundation; either
010 *   version 2.1 of the License, or (at your option) any later version.
011 *   
012 *   This library is distributed in the hope that it will be useful,
013 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
014 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015 *   Lesser General Public License for more details.
016 *
017 *   You should have received a copy of the GNU Lesser General Public License
018 *   along with this program; if not, write to the Free Software
019 *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020 *   Or visit:  http://www.gnu.org/licenses/lgpl.html
021 */
022package geomss.geom;
023
024import static java.util.Objects.nonNull;
025import static java.util.Objects.requireNonNull;
026import javolution.text.Text;
027import javolution.text.TextBuilder;
028
029/**
030 * Partial implementation of a textual note located at a point in nD space, but is
031 * displayed at a fixed size on the screen and oriented such that it is always face-on to
032 * the user.
033 *
034 * <p> Modified by: Joseph A. Huwaldt </p>
035 *
036 * @author Joseph A. Huwaldt, Date: February 5, 2014
037 * @version November 24, 2015
038 */
039@SuppressWarnings({"serial", "CloneableImplementsClone"})
040public abstract class GenScreenNote extends AbstractNote<GenScreenNote> implements Transformable<GenScreenNote> {
041
042    /**
043     * Return an immutable version of this note.
044     *
045     * @return An immutable version of this note.
046     */
047    public abstract Note immutable();
048
049    /**
050     * Returns the number of child-elements that make up this geometry element. This
051     * implementation always returns 1 as a GenScreenNote is located at a single point in
052     * model space.
053     */
054    @Override
055    public int size() {
056        return 1;
057    }
058
059    /**
060     * Return the coordinate point representing the minimum bounding box corner (e.g.: min
061     * X, min Y, min Z).
062     *
063     * @return The minimum bounding box coordinate for this geometry element.
064     */
065    @Override
066    public Point getBoundsMin() {
067        return getLocation();
068    }
069
070    /**
071     * Return the coordinate point representing the maximum bounding box corner (e.g.: max
072     * X, max Y, max Z).
073     *
074     * @return The maximum bounding box coordinate for this geometry element.
075     */
076    @Override
077    public Point getBoundsMax() {
078        return getLocation();
079    }
080
081    /**
082     * Returns the most extreme point, either minimum or maximum, in the specified
083     * coordinate direction on this geometry element. This implementation always returns
084     * this note location coordinate.
085     *
086     * @param dim An index indicating the dimension to find the min/max point for
087     *            (0=X,1=Y, 2=Z, etc).
088     * @param max Set to <code>true</code> to return the maximum value, <code>false</code>
089     *            to return the minimum.
090     * @param tol Fractional tolerance to refine the min/max point position to if
091     *            necessary.
092     * @return The point found on this element that is the min or max in the specified
093     *         coordinate direction.
094     * @see #getBoundsMin
095     * @see #getBoundsMax
096     */
097    @Override
098    public Point getLimitPoint(int dim, boolean max, double tol) {
099        return getLocation();
100    }
101
102    /**
103     * Returns transformed version of this element. The returned object implements
104     * {@link GeomTransform} and contains this element as a child.
105     *
106     * @param transform The transformation to apply to this geometry. May not be null.
107     * @return A new triangle that is identical to this one with the specified
108     *         transformation applied.
109     * @throws DimensionException if this point is not 3D.
110     */
111    @Override
112    public NoteTrans getTransformed(GTransform transform) {
113        return NoteTrans.newInstance(this, requireNonNull(transform));
114    }
115
116    /**
117     * Returns the text representation of this geometry element that consists of the text
118     * string followed by the coordinate position. For example:
119     * <pre>
120     *   {aNote = {"A text string.",{10 ft, -3 ft, 4.56 ft}}}
121     * </pre>
122     * If there is no name, then the output looks like this:
123     * <pre>
124     *   {"A text string.",{10 ft, -3 ft, 4.56 ft}}
125     * </pre>
126     *
127     * @return the text representation of this geometry element.
128     */
129    @Override
130    public Text toText() {
131        TextBuilder tmp = TextBuilder.newInstance();
132        tmp.append('{');
133        String nameStr = getName();
134        boolean hasName = nonNull(nameStr);
135        if (hasName) {
136            tmp.append(nameStr);
137            tmp.append(" = {");
138        }
139        tmp.append("\"");
140        tmp.append(getNote());
141        tmp.append("\",");
142        tmp.append(getLocation().toText());
143        if (hasName)
144            tmp.append('}');
145        tmp.append('}');
146        Text txt = tmp.toText();
147        TextBuilder.recycle(tmp);
148        return txt;
149    }
150
151}