|
@@ -1,11 +1,19 @@
|
|
|
package com.fdkankan.common.util;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.Builder;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.NoArgsConstructor;
|
|
|
+import lombok.ToString;
|
|
|
|
|
|
public class CreateHouseJsonUtil {
|
|
|
|
|
@@ -26,6 +34,113 @@ public class CreateHouseJsonUtil {
|
|
|
}
|
|
|
return house;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据floorplan_cad.json文件生成houseType.json
|
|
|
+ * @param filePath
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static JSONObject createHouseTypeJsonByCad(String filePath) {
|
|
|
+
|
|
|
+ JSONArray floors = readFloorJson(filePath);
|
|
|
+
|
|
|
+ JSONObject house = new JSONObject();
|
|
|
+ house.put("name", "houseType.json");
|
|
|
+ house.put("version", "2.1");
|
|
|
+
|
|
|
+ JSONArray targetFloors = new JSONArray();
|
|
|
+ house.put("floors", targetFloors);
|
|
|
+
|
|
|
+ for(int i = 0; i < floors.size(); i++){
|
|
|
+ JSONObject floor = (JSONObject)floors.get(i);
|
|
|
+ JSONArray[] pointsAndWalls = createHouseTypeJsonHandler(floor);
|
|
|
+ JSONArray points = pointsAndWalls[0];
|
|
|
+ JSONArray walls = pointsAndWalls[1];
|
|
|
+ JSONObject targetFloor = new JSONObject();
|
|
|
+ targetFloor.put("points", points);
|
|
|
+ targetFloor.put("walls", walls);
|
|
|
+ targetFloors.add(targetFloor);
|
|
|
+ }
|
|
|
+
|
|
|
+ return house;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static JSONArray[] createHouseTypeJsonHandler(JSONObject floor){
|
|
|
+
|
|
|
+ JSONArray[] result = new JSONArray[2];
|
|
|
+
|
|
|
+ //处理点
|
|
|
+ Map<Integer, VertexBean> vertexMap = new HashMap<>();
|
|
|
+ Map<String, PointBean> pointMap = new HashMap<>();
|
|
|
+ Map<Integer, String> vpMap = new HashMap<>();
|
|
|
+ JSONArray vertexArr = floor.getJSONArray("vertex-xy");
|
|
|
+ for(int i = 0; i < vertexArr.size(); i++){
|
|
|
+ Object o = vertexArr.get(i);
|
|
|
+
|
|
|
+ VertexBean vertexBean = JSON.parseObject(JSON.toJSONString(o), VertexBean.class);
|
|
|
+ Integer vertexId = vertexBean.getId();
|
|
|
+ vertexMap.put(vertexId, vertexBean);
|
|
|
+
|
|
|
+ String pointId = "Point" + i;
|
|
|
+ pointMap.put(pointId, PointBean.builder().vectorId(pointId).x(vertexBean.getX()).y(vertexBean.getY()).build());
|
|
|
+
|
|
|
+ vpMap.put(vertexId, pointId);
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理墙
|
|
|
+ Map<Integer, SegmentBean> segmentMap = new HashMap<>();
|
|
|
+ Map<String, WallBean> wallMap = new HashMap<>();
|
|
|
+ Map<Integer, String> swMap = new HashMap<>();
|
|
|
+ JSONArray segmentArr = floor.getJSONArray("segment");
|
|
|
+ Map<String, String> startMap = new HashMap<>();
|
|
|
+ Map<String, String> endMap = new HashMap<>();
|
|
|
+ for(int i = 0; i < segmentArr.size(); i++){
|
|
|
+ Object o = segmentArr.get(i);
|
|
|
+
|
|
|
+ SegmentBean segmentBean = JSON.parseObject(JSON.toJSONString(o), SegmentBean.class);
|
|
|
+ String startPointId = vpMap.get(segmentBean.getA());
|
|
|
+ String endPointId = vpMap.get(segmentBean.getB());
|
|
|
+ segmentBean.setStartPointId(startPointId);
|
|
|
+ segmentBean.setEndPointId(endPointId);
|
|
|
+
|
|
|
+ Integer segmentId = segmentBean.getId();
|
|
|
+ segmentMap.put(segmentId, segmentBean);
|
|
|
+
|
|
|
+ String wallId = "Wall" + i;
|
|
|
+ WallBean wallBean = WallBean.builder()
|
|
|
+ .vectorId(wallId)
|
|
|
+ .start(segmentBean.getStartPointId())
|
|
|
+ .end(segmentBean.getEndPointId())
|
|
|
+ .children(new String[]{})
|
|
|
+ .width(0.2d)
|
|
|
+ .build();
|
|
|
+ wallMap.put(wallId, wallBean);
|
|
|
+
|
|
|
+ startMap.put(wallBean.getStart(), wallBean.getVectorId());
|
|
|
+ endMap.put(wallBean.getEnd(), wallBean.getVectorId());
|
|
|
+
|
|
|
+ swMap.put(segmentId, wallId);
|
|
|
+ }
|
|
|
+
|
|
|
+ Collection<PointBean> pointBeans = pointMap.values();
|
|
|
+ for (PointBean pointBean : pointBeans) {
|
|
|
+ Map<String, String> parent = new HashMap<>();
|
|
|
+ String startParent = startMap.get(pointBean.getVectorId());
|
|
|
+ String endParent = endMap.get(pointBean.getVectorId());
|
|
|
+ parent.put(startParent, "start");
|
|
|
+ parent.put(endParent, "end");
|
|
|
+ pointBean.setParent(parent);
|
|
|
+ }
|
|
|
+ JSONArray pointArr = JSON.parseArray(JSON.toJSONString(pointBeans));
|
|
|
+ result[0] = pointArr;
|
|
|
+
|
|
|
+ Collection<WallBean> wallBeans = wallMap.values();
|
|
|
+ JSONArray wallArr = JSON.parseArray(JSON.toJSONString(wallBeans));
|
|
|
+ result[1] = wallArr;
|
|
|
+
|
|
|
+ return result;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
private static JSONObject init() {
|
|
|
JSONObject outContent = new JSONObject();
|
|
@@ -154,42 +269,45 @@ public class CreateHouseJsonUtil {
|
|
|
}
|
|
|
return _rooms;
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- /*
|
|
|
- //构件,包括:柱子,烟囱等
|
|
|
- private JSONObject convertComponents(JSONObject components) {
|
|
|
- JSONArray beams = new JSONArray();
|
|
|
- JSONArray flues = new JSONArray();
|
|
|
-
|
|
|
- JSONObject result = new JSONObject();
|
|
|
-
|
|
|
- for (Map.Entry<String, Object> entry: components.entrySet()) {
|
|
|
- JSONObject componentValue = (JSONObject)entry.getValue();
|
|
|
- JSONObject _componentValue = new JSONObject();
|
|
|
- String geoType = componentValue.getString("geoType");
|
|
|
-
|
|
|
-
|
|
|
- _componentValue.put("center", componentValue.getJSONObject("center"));
|
|
|
- _componentValue.put("angle", componentValue.getIntValue("angle"));
|
|
|
- _componentValue.put("vectorId", componentValue.getString("vectorId"));
|
|
|
- _componentValue.put("points2d", componentValue.getJSONArray("points2d"));
|
|
|
- _componentValue.put("geoType", componentValue.getString("geoType"));
|
|
|
- _componentValue.put("sideWidth", componentValue.getFloatValue("sideWidth"));
|
|
|
- _componentValue.put("sideThickness", componentValue.getFloatValue("sideThickness"));
|
|
|
- if(geoType.endsWith("Beam")) {
|
|
|
- beams.add(_componentValue);
|
|
|
- }
|
|
|
- else if(geoType.endsWith("Flue")) {
|
|
|
- flues.add(_componentValue);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- result.put("beams", beams);
|
|
|
- result.put("flues", flues);
|
|
|
- return result;
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
- //rooms
|
|
|
- //tags
|
|
|
+@Data
|
|
|
+class VertexBean {
|
|
|
+ private int id;
|
|
|
+ private float x;
|
|
|
+ private float y;
|
|
|
+}
|
|
|
+
|
|
|
+@Data
|
|
|
+@Builder
|
|
|
+@NoArgsConstructor
|
|
|
+@AllArgsConstructor
|
|
|
+@ToString
|
|
|
+class PointBean implements Serializable {
|
|
|
+ private String vectorId;
|
|
|
+ private float x;
|
|
|
+ private float y;
|
|
|
+ private Map<String, String> parent;
|
|
|
+}
|
|
|
+
|
|
|
+@Data
|
|
|
+class SegmentBean {
|
|
|
+ private int id;
|
|
|
+ private int a;
|
|
|
+ private int b;
|
|
|
+ private String startPointId;
|
|
|
+ private String endPointId;
|
|
|
+}
|
|
|
+
|
|
|
+@Data
|
|
|
+@Builder
|
|
|
+@NoArgsConstructor
|
|
|
+@AllArgsConstructor
|
|
|
+@ToString
|
|
|
+class WallBean implements Serializable {
|
|
|
+ private String vectorId;
|
|
|
+ private String start;
|
|
|
+ private String end;
|
|
|
+ private String[] children;
|
|
|
+ private Double width;
|
|
|
}
|