package com.fdkankan.dxf.parse.utils;

import com.fdkankan.dxf.parse.enums.entities.*;
import com.fdkankan.dxf.parse.model.GeometricModel;
import com.fdkankan.dxf.parse.transformation.DxfLineTransformation;
import com.fdkankan.dxf.parse.transformation.impl.DxfLineTransformationImpl;
import com.fdkankan.dxf.parse.transformation.model.DxfLine;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class DxfLineTransformUtil {

    /**
     * 具体的进行转换的实现类
     */
    private static DxfLineTransformation transformation = new DxfLineTransformationImpl();

    /**
     * 几何数据转换为点线数据
     *
     * @param map 需要转换的map数据
     * @return 转换后的点线数据
     */
    public static List<DxfLine> geometricTransform(Map<String, List<GeometricModel>> map) {
        List<DxfLine> dxfLineList = new ArrayList<>();

        //将获取的几何数据转换为适配RTAS的点线数据
        List<DxfLine> arcList = transformation.arcTransform(map.get(ArcEnum.ARC_NAME.getCode()));
        List<DxfLine> circleList = transformation.circleTransform(map.get(CircleEnum.CIRCLE_NAME.getCode()));
        List<DxfLine> lineList = transformation.lineTransform(map.get(LineEnum.LINE_NAME.getCode()));
        List<DxfLine> pointList = transformation.pointTransform(map.get(PointEnum.POINT_NAME.getCode()));
        List<DxfLine> polyLineList = transformation.polyLineTransform(map.get(PolyLineEnum.POLYLINE_NAME.getCode()));
        List<DxfLine> textList = transformation.textTransform(map.get(TextEnum.TEXT_NAME.getCode()));

        //将获取的数据添加到一个总的集合中
        if (!(arcList == null || arcList.isEmpty())) {
            dxfLineList.addAll(arcList);
        }
        if (!(circleList == null || circleList.isEmpty())) {
            dxfLineList.addAll(circleList);
        }
        if (!(lineList == null || lineList.isEmpty())) {
            dxfLineList.addAll(lineList);
        }
        if (!(pointList == null || pointList.isEmpty())) {
            dxfLineList.addAll(pointList);
        }
        if (!(polyLineList == null || polyLineList.isEmpty())) {
            dxfLineList.addAll(polyLineList);
        }
        if (!(textList == null || textList.isEmpty())) {
            dxfLineList.addAll(textList);
        }
        return dxfLineList;
    }


}
