package com.persagy.adm.diagram.core.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.gson.annotations.Expose;
import com.persagy.adm.diagram.core.model.base.XY;
import com.persagy.adm.diagram.core.model.legend.Anchor;
import com.persagy.adm.diagram.core.model.template.MainPipe;

/**
 * 线和图例的连接点
 * @author zhaoyk
 */
public class ConnectPoint {

	/**
	 * 连接对象的类型，equipmentNode, dataPanelNode, mainPipe
	 */
	@Expose
	private String hostType;

	/**
	 * 连接对象的id
	 */
	@Expose
	private String hostId;

	/**
	 * 连接对象为equipmentNode时，连接的锚点编码
	 */
	@Expose
	private String anchorCode;

	/**
	 * 连接对象为mainPipe时，干管上的定位点
	 * TODO 定位点模型
	 */
	@Expose
	private Object mainPipePoint;

	/**
	 * 连接点绝对坐标
	 */
	private XY location;

	/**
	 * 连接对象，运行时
	 */
	@JsonIgnore
	private Object hostObj;

	/**
	 * 如果hostObj为EquipmentNode类型，则返回
	 */
	public EquipmentNode getEquipmentNode(){
		if(hostObj instanceof EquipmentNode) {
			return (EquipmentNode) hostObj;
		}
		return null;
	}

	/**
	 * 如果hostObj为MainPipe类型，则返回
	 */
	public MainPipe getMainPipe(){
		if(hostObj instanceof MainPipe) {
			return (MainPipe) hostObj;
		}
		return null;
	}

	public void layout() {
		if(hostObj instanceof EquipmentNode) {
			EquipmentNode en = (EquipmentNode)hostObj;
			location = en.locationToRoot();
			XY anchorLocation = en.getAnchorLocations().get(anchorCode);
			location.x += anchorLocation.x;
			location.y += anchorLocation.y;
		}
	}

	public String getHostType() {
		return hostType;
	}

	public void setHostType(String hostType) {
		this.hostType = hostType;
	}

	public String getHostId() {
		return hostId;
	}

	public void setHostId(String hostId) {
		this.hostId = hostId;
	}

	public String getAnchorCode() {
		return anchorCode;
	}

	public void setAnchorCode(String anchorCode) {
		this.anchorCode = anchorCode;
	}

	public Object getMainPipePoint() {
		return mainPipePoint;
	}

	public void setMainPipePoint(Object mainPipePoint) {
		this.mainPipePoint = mainPipePoint;
	}

	public XY getLocation() {
		return location;
	}

	public void setLocation(XY location) {
		this.location = location;
	}

	public Object getHostObj() {
		return hostObj;
	}

	public void setHostObj(Object hostObj) {
		this.hostObj = hostObj;
	}

}
