Commit fa8af94e authored by Nico Mack's avatar Nico Mack

Implement first version of PositionWidget using SpatialVariables

parent 5fb3b4da
......@@ -19,6 +19,7 @@ MAINTAIN_ASPECT_RATIO_NODE=maintainAspectRatio
MAXIMUM_VALUE_NODE=maximumValue
MINIMUM_VALUE_NODE=minimumValue
MODIFY_VALUE_ON_ROTATION_NODE=modifyValueOnRotation
MODIFY_VALUE_ON_TRANSLATION_NODE=modifyValueOnTranslation
MULTITURN_NODE=multiTurn
POSITIONS_NODE=positions
RANGE_SEPARATOR_ATTRIBUTE=rangeSeparator
......
......@@ -27,7 +27,7 @@ import org.eclipse.osgi.util.NLS;
* @since 1.0
* @version 1.3.0
*/
@SuppressWarnings({"javadoc", "nls"})
@SuppressWarnings({"nls", "squid:S3008"})
public class EquationSystemBundle extends NLS {
private static final String BUNDLE_NAME = "equationsystem";
......
......@@ -22,7 +22,7 @@ import org.eclipse.osgi.util.NLS;
* @since 2.2
* @version 2.5.0
*/
@SuppressWarnings({"javadoc", "squid:S3008"})
@SuppressWarnings({"squid:S3008"})
public class CpsNamespace extends NLS {
private static final String BUNDLE_NAME = "CpsNamespace"; //$NON-NLS-1$
......@@ -54,6 +54,7 @@ public class CpsNamespace extends NLS {
public static String MAXIMUM_VALUE_NODE;
public static String MINIMUM_VALUE_NODE;
public static String MODIFY_VALUE_ON_ROTATION_NODE;
public static String MODIFY_VALUE_ON_TRANSLATION_NODE;
public static String MULTITURN_NODE;
public static String POSITIONS_NODE;
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2019. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.widget;
import lu.list.itis.dkd.tui.adapter.TangibleObject;
import lu.list.itis.dkd.tui.content.InformationProvider;
import lu.list.itis.dkd.tui.cps.system.VariableBased;
import lu.list.itis.dkd.tui.cps.variable.SpatialVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.utility.CoordinateState;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.builder.BasePositionWidgetBuilder;
import lu.list.itis.dkd.tui.widget.state.StateManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class PositionWidget extends PointingWidget implements InformationProvider<Point>, VariableBased {
private SpatialVariable variable;
protected boolean modifyValueOnRotation = false;
protected boolean modifyValueOnTranslation = false;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Constructor
*
* @param builder
*/
// ---------------------------------------------------------------------------
public PositionWidget(BasePositionWidgetBuilder<?> builder) {
super(builder);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private void updateFromMove(Point newPosition) {
if (this.variable != null) {
Point position = this.variable.getValue();
if (position != null) {
CoordinateState coordinates = position.getState();
newPosition = newPosition.toCoordinates(coordinates.getClass());
if (modifyValueOnRotation) {
position.setAngle(newPosition.getAngle());
}
if (modifyValueOnTranslation) {
position.setLocation(newPosition.x, newPosition.y);
}
this.variable.setValue(position);
} else {
this.variable.setValue(newPosition);
}
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public void actionDrop(TangibleObject tuioObject) {
super.actionDrop(tuioObject);
Point position = this.getPointingLocation(tuioObject.getPosition());
this.updateFromMove(position);
}
// ---------------------------------------------------------------------------
@Override
public void actionMove(TangibleObject tuioObject) {
super.actionMove(tuioObject);
StateManager manager = objectStates.get(tuioObject.getObjectId());
if (manager.wasRotating() || manager.wasMoving()) {
Point position = this.getPointingLocation(tuioObject.getPosition());
this.updateFromMove(position);
}
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public List<Variable<?>> connectWithSystemVariables(Map<String, Variable<?>> systemVariables) {
List<Variable<?>> connected = new ArrayList<>();
if ((systemVariables != null) && systemVariables.containsKey(this.variable.getName())) {
SpatialVariable spatial = Variable.castTo(systemVariables.get(this.variable.getName()), SpatialVariable.class);
if (spatial != null) {
this.variable = spatial;
connected.add(spatial);
}
}
return connected;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public List<Variable<?>> getDeclaredVariables() {
List<Variable<?>> declared = new ArrayList<>();
declared.add(variable);
return declared;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public Point getInformation(Point position) {
return (this.variable != null) ? this.variable.getValue() : null;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public Point getInformation() {
return (this.variable != null) ? this.variable.getValue() : null;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.widget.builder;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.bootstrapping.VariableBootstrapper;
import lu.list.itis.dkd.tui.cps.variable.SpatialVariable;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.CpsNamespace;
import lu.list.itis.dkd.tui.widget.PositionWidget;
import org.jdom2.Element;
/**
* @author nmack
* @param <B>
* @date 4 Jan 2019
*
* <br>
* $Log: BasePositionWidgetBuilder.java,v $
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public abstract class BasePositionWidgetBuilder<B extends BasePositionWidgetBuilder<B>> extends BasePointingWidgetBuilder<B> {
/** */
public SpatialVariable variable;
public boolean modifyValueOnRotation;
public boolean modifyValueOnTranslation;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
protected BasePositionWidgetBuilder() {}
// ---------------------------------------------------------------------------
protected BasePositionWidgetBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
protected BasePositionWidgetBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
this.variable = (SpatialVariable) VariableBootstrapper.buildVariableFromElement(rootElement.getChild(CpsNamespace.VARIABLE_NODE), context, callback);
this.modifyValueOnRotation = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.MODIFY_VALUE_ON_ROTATION_NODE, BootstrappingUtils.OPTIONAL, true, context);
this.modifyValueOnTranslation = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.MODIFY_VALUE_ON_TRANSLATION_NODE, BootstrappingUtils.OPTIONAL, true, context);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public abstract PositionWidget build();
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
\ No newline at end of file
/**
* Copyright Luxembourg Institute of Science and Technology, 2016.
*
* This file is part of TULIP.
*
* TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3,
* as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST
* proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license.
*
* For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, version 3 of the License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.widget.builder;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.widget.PositionWidget;
import lu.list.itis.dkd.tui.widget.ValueWidget;
import org.jdom2.Element;
/**
* The concrete builder that will build a new instance of {@link ValueWidget} with each call to
* {@link #build()}.
*
* @author Nico Mack [nico.mack@list.lu]
* @since 1.5
* @version 1.0.0
*/
public class PositionWidgetBuilder extends BasePositionWidgetBuilder<PositionWidgetBuilder> {
/**
* Simple no-arg constructor initializing all fields.
*/
public PositionWidgetBuilder() {
super();
}
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all the
* information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all fields
* of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
public PositionWidgetBuilder(Element rootElement) throws BuildException {
super(rootElement);
}
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all the
* information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all fields
* of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
public PositionWidgetBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
/** {@inheritDoc} */
@Override
public PositionWidget build() {
return new PositionWidget(this);
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment