Source: objects/RouteLine.js

import { Utils } from '../common/Utils';
import { MathUtils } from '../math/MathUtils';
import { BaseLine } from './BaseLine';

/**
 * @class RouteLine
 * The route line object.
 * @memberof THING
 * @extends THING.BaseLine
 * @public
 */
class RouteLine extends BaseLine {

	_width = 1;
	_cornerRadius = 0.3;
	_cornerSplit = 10;
	_arrow = false;

	static defaultTagArray = ['Line'];

	/**
	 * The route line object in scene.
	 * @param {Object} param The initial parameters.
	 */
	constructor(param = {}) {
		super(param);

		this._syncOptions(param);
	}

	// #region Private Functions

	_syncOptions(param) {
		this.begin();
		{
			super.onSyncOptions(param);

			Utils.syncOptions(this, [
				'width',
				'cornerRadius',
				'cornerSplit',
				'arrow'
			], param, param['extras'] || param['external']);
		}
		this.end();
	}

	// #endregion

	// #region Overrides

	onBeforeSetup(param) {
		param['renderableNode'] = param['renderableNode'] || Utils.createObject('RouteLine');

		super.onBeforeSetup(param);
	}

	onAfterSetup(param) {
		super.onAfterSetup(param);
	}

	onRefreshAttributes() {
		let bodyNode = this.bodyNode;
		bodyNode.setWidth(this._width);
		bodyNode.setCornerRadius(this._cornerRadius);
		bodyNode.setCornerSplit(this._cornerSplit);
		bodyNode.setArrow(this._arrow);
	}

	onImportExternalData(external, options) {
		super.onImportExternalData(external, options);
		if (external) {
			this._syncOptions(external);
		}
	}


	onExportExternalData() {
		let external = Object.assign({}, super.onExportExternalData());
		Utils.setAttributeIfExist(external, 'width', this);
		Utils.setAttributeIfExist(external, 'cornerRadius', this);
		Utils.setAttributeIfExist(external, 'cornerSplit', this);
		Utils.setAttributeIfExist(external, 'arrow', this);
		return external;
	}

	// #endregion

	// #region Accessor

	/**
	 * Get/Set the facing direction of self space.
	 * @type {Array<Number>}
	 * @public
	 */
	get facingDirection() {
		let target = [0, 0, 0];
		return this.bodyNode.getUpDirection(target);
	}
	set facingDirection(value) {
		this.bodyNode.setUpDirection(value);
	}

	/**
	 * Get/Set width.
	 * @type {Number}
	 * @public
	 */
	get width() {
		return this._width;
	}
	set width(value) {
		this._width = value;

		this.bodyNode.setWidth(this._width);
	}

	/**
	 * Get/Set radius of corner (Should be greater than half of width).
	 * @type {Number}
	 * @public
	 */
	get cornerRadius() {
		return this._cornerRadius;
	}
	set cornerRadius(value) {
		this._cornerRadius = value;

		this.bodyNode.setCornerRadius(this._cornerRadius);
	}

	/**
	 * Get/Set split of corner, only works with integer type.
	 * @type {Number}
	 * @public
	 */
	get cornerSplit() {
		return this._cornerSplit;
	}
	set cornerSplit(value) {
		this._cornerSplit = MathUtils.toInteger(value);

		this.bodyNode.setCornerSplit(this._cornerSplit);
	}

	/**
	 * Enable/Disable arrow.
	 * @type {Number}
	 * @public
	 */
	get arrow() {
		return this._arrow;
	}
	set arrow(value) {
		this._arrow = value;

		this.bodyNode.setArrow(this._arrow);
	}

	// #endregion

	get isRouteLine() {
		return true;
	}

}

export { RouteLine }