001/*
002
003Copyright (c) 2011-2018 The Regents of the University of California.
004All rights reserved.
005
006Permission is hereby granted, without written agreement and without
007license or royalty fees, to use, copy, modify, and distribute this
008software and its documentation for any purpose, provided that the above
009copyright notice and the following two paragraphs appear in all copies
010of this software.
011
012IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA LIABLE TO ANY PARTY
013FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
014ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
015THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
016SUCH DAMAGE.
017
018THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
019INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
020MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
021PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
022CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
023ENHANCEMENTS, OR MODIFICATIONS.
024
025PT_COPYRIGHT_VERSION_2
026COPYRIGHTENDKEY
027 */
028package ptolemy.vergil.basic.layout;
029
030import ptolemy.actor.parameters.DoubleRangeParameter;
031import ptolemy.data.expr.ChoiceParameter;
032import ptolemy.data.expr.Parameter;
033import ptolemy.data.expr.StringParameter;
034import ptolemy.data.type.BaseType;
035import ptolemy.kernel.util.Attribute;
036import ptolemy.kernel.util.IllegalActionException;
037import ptolemy.kernel.util.NameDuplicationException;
038import ptolemy.kernel.util.NamedObj;
039import ptolemy.kernel.util.Settable;
040
041/**
042 * An attribute for parameters of automatic layout. This is read by the KIELER
043 * layout action to generate a configuration for the layout algorithm.
044 *
045 * @see ptolemy.vergil.basic.layout.kieler.KielerLayoutAction
046 * @author Miro Spoenemann, Christoph Daniel Schulze, Ulf Rueegg
047 * @version $Id$
048 * @since Ptolemy II 11.0
049 * @Pt.ProposedRating Red (msp)
050 * @Pt.AcceptedRating Red (msp)
051 */
052public abstract class AbstractLayoutConfiguration extends Attribute {
053
054    /** Available modes of user interaction. */
055    public enum InteractionMode {
056    /** No user interaction: full automatic layout. */
057    None,
058    /** User positioning affects cycle detection. */
059    Cycles,
060    /** User positioning affects cycle detection and node layering. */
061    Columns,
062    /** User positioning affects cycle detection, node layering, and node order. */
063    Full;
064    }
065
066    /**
067     * Create and initialize a layout configuration.
068     *
069     *  @param container The container.
070     *  @param name The name of this attribute.
071     *  @exception IllegalActionException If the attribute is not of an
072     *   acceptable class for the container, or if the name contains a period.
073     *  @exception NameDuplicationException If the name coincides with
074     *   an attribute already in the container.
075     */
076    public AbstractLayoutConfiguration(NamedObj container, String name)
077            throws IllegalActionException, NameDuplicationException {
078        super(container, name);
079
080        useOldAlgorithm = new Parameter(this, "useOldAlgorithm");
081        useOldAlgorithm.setDisplayName("Use old algorithm");
082        useOldAlgorithm.setTypeEquals(BaseType.BOOLEAN);
083        useOldAlgorithm.setExpression(Boolean.toString(DEF_OLD_ALGORITHM));
084        useOldAlgorithm.setVisibility(Settable.EXPERT);
085
086        includeDecorations = new Parameter(this, "includeDecorations");
087        includeDecorations.setDisplayName("Include decorations");
088        includeDecorations.setTypeEquals(BaseType.BOOLEAN);
089        includeDecorations.setExpression(Boolean.toString(DEF_DECORATIONS));
090
091        spacing = new DoubleRangeParameter(this, "spacing");
092        spacing.setDisplayName("Object spacing");
093        spacing.min.setExpression("2.0");
094        spacing.max.setExpression("50.0");
095        spacing.setExpression(Double.toString(DEF_SPACING));
096        spacing.min.setVisibility(Settable.NONE);
097        spacing.max.setVisibility(Settable.NONE);
098        spacing.minLabel.setVisibility(Settable.NONE);
099        spacing.maxLabel.setVisibility(Settable.NONE);
100        spacing.precision.setVisibility(Settable.NONE);
101
102        logAspectRatio = new DoubleRangeParameter(this, "logAspectRatio");
103        logAspectRatio.setDisplayName("Aspect ratio");
104        logAspectRatio.min.setExpression("-1.0");
105        logAspectRatio.max.setExpression("1.0");
106        logAspectRatio
107                .setExpression(Double.toString(Math.log10(DEF_ASPECT_RATIO)));
108        logAspectRatio.minLabel.setExpression("Narrow");
109        logAspectRatio.maxLabel.setExpression("Wide");
110        logAspectRatio.min.setVisibility(Settable.NONE);
111        logAspectRatio.max.setVisibility(Settable.NONE);
112        logAspectRatio.minLabel.setVisibility(Settable.NONE);
113        logAspectRatio.maxLabel.setVisibility(Settable.NONE);
114        logAspectRatio.precision.setVisibility(Settable.NONE);
115
116        interactionMode = new ChoiceParameter(this, "interactionMode",
117                InteractionMode.class);
118        interactionMode.setDisplayName("Interaction mode");
119        interactionMode.setExpression(DEF_INTERACTION_MODE.toString());
120
121        helpURL = new StringParameter(this, "_helpURL");
122        helpURL.setExpression("ptolemy/vergil/basic/layout/layout.htm");
123        helpURL.setVisibility(Settable.NONE);
124    }
125
126    ///////////////////////////////////////////////////////////////////
127    ////                       public parameters                   ////
128
129    /** Whether to use Ptolemy's original layout algorithm. */
130    public Parameter useOldAlgorithm;
131
132    /** Whether to include unconnected nodes such as comments. */
133    public Parameter includeDecorations;
134
135    /** The overall spacing between graph elements. */
136    public DoubleRangeParameter spacing;
137
138    /** The aspect ratio for placement of connected components (logarithmic). */
139    public DoubleRangeParameter logAspectRatio;
140
141    /** Mode of user interaction: whether user positioning is allowed to affect the layout. */
142    public ChoiceParameter interactionMode;
143
144    /** Customized help file to be displayed by the layout configuration dialog. */
145    public StringParameter helpURL;
146
147    /** Default value for useOldAlgorithm. */
148    public static final boolean DEF_OLD_ALGORITHM = false;
149
150    /** Default value for includeDecorations. */
151    public static final boolean DEF_DECORATIONS = true;
152
153    /** Default value for spacing. */
154    public static final double DEF_SPACING = 10.0;
155
156    /** Default value for aspectRatio (non-logarithmic). */
157    public static final double DEF_ASPECT_RATIO = 1.6;
158
159    /** Default value for interaction mode. */
160    public static final InteractionMode DEF_INTERACTION_MODE = InteractionMode.None;
161
162}