|
@@ -0,0 +1,195 @@
|
|
|
|
+package com.fdkankan.common.util;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+
|
|
|
|
+public class CreateHouseJsonUtil {
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据用户上传的户型图json文件生成houseType.json
|
|
|
|
+ * @param filePath
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static JSONObject createHouseTypeJsonByUser(String filePath) {
|
|
|
|
+ JSONObject house = init();
|
|
|
|
+ JSONArray floors = house.getJSONArray("floors");
|
|
|
|
+
|
|
|
|
+ JSONArray floorJson = readFloorJson(filePath);
|
|
|
|
+ for(int i=0;i<floorJson.size();++i) {
|
|
|
|
+ JSONObject floor = floorJson.getJSONObject(i);
|
|
|
|
+ JSONObject floorData = convert(floor,i);
|
|
|
|
+ floors.add(floorData);
|
|
|
|
+ }
|
|
|
|
+ return house;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static JSONObject init() {
|
|
|
|
+ JSONObject outContent = new JSONObject();
|
|
|
|
+ outContent.put("name", "houseType.json");
|
|
|
|
+ outContent.put("version", "2.1");
|
|
|
|
+
|
|
|
|
+ outContent.put("floors", new JSONArray());
|
|
|
|
+ outContent.put("newVectorId", null);
|
|
|
|
+ outContent.put("setting", null);
|
|
|
|
+ outContent.put("boundingBox", null);
|
|
|
|
+ return outContent;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static JSONArray readFloorJson(String filePath) {
|
|
|
|
+ try {
|
|
|
|
+ JSONObject floorplan = FileUtil.readJson(filePath);
|
|
|
|
+ JSONArray floors = floorplan.getJSONArray("floors");
|
|
|
|
+ return floors;
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static JSONObject convert(JSONObject floorJson,int floor) {
|
|
|
|
+ JSONArray rooms = floorJson.getJSONArray("rooms");
|
|
|
|
+ JSONObject walls = floorJson.getJSONObject("walls");
|
|
|
|
+ JSONObject points = floorJson.getJSONObject("points");
|
|
|
|
+ JSONObject symbols = floorJson.getJSONObject("symbols");
|
|
|
|
+
|
|
|
|
+ JSONArray _points = convertPoints(points);
|
|
|
|
+ JSONArray _walls = convertPoints(walls);
|
|
|
|
+ JSONArray _symbols = convertSymbols(symbols,floor);
|
|
|
|
+ JSONArray _rooms = convertRooms(rooms,floor);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ JSONObject floorData = new JSONObject();
|
|
|
|
+ floorData.put("points", points);
|
|
|
|
+ floorData.put("walls", walls);
|
|
|
|
+ floorData.put("symbols", symbols);
|
|
|
|
+ floorData.put("rooms", rooms);
|
|
|
|
+ return floorData;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static JSONArray convertPoints(JSONObject points) {
|
|
|
|
+
|
|
|
|
+ JSONArray _points = new JSONArray();
|
|
|
|
+ for (Map.Entry<String, Object> entry: points.entrySet()) {
|
|
|
|
+ JSONObject pointValue = (JSONObject)entry.getValue();
|
|
|
|
+ JSONObject _pointValue = new JSONObject();
|
|
|
|
+ _pointValue.put("x", pointValue.getFloat("x"));
|
|
|
|
+ _pointValue.put("y", pointValue.getFloat("y"));
|
|
|
|
+ _pointValue.put("parent", pointValue.getJSONObject("parent"));
|
|
|
|
+ _pointValue.put("vectorId", pointValue.getString("vectorId"));
|
|
|
|
+
|
|
|
|
+ _points.add(_pointValue);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return _points;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static JSONArray convertWalls(JSONObject walls) {
|
|
|
|
+
|
|
|
|
+ JSONArray _walls = new JSONArray();
|
|
|
|
+ for (Map.Entry<String, Object> entry: walls.entrySet()) {
|
|
|
|
+ JSONObject wallValue = (JSONObject)entry.getValue();
|
|
|
|
+ JSONObject _wallValue = new JSONObject();
|
|
|
|
+ _wallValue.put("start", wallValue.getString("start"));
|
|
|
|
+ _wallValue.put("end", wallValue.getString("end"));
|
|
|
|
+ _wallValue.put("children", wallValue.getJSONArray("children"));
|
|
|
|
+ _wallValue.put("vectorId", wallValue.getString("vectorId"));
|
|
|
|
+ _wallValue.put("width", 0.2);
|
|
|
|
+ //leftEdgeId
|
|
|
|
+ //rightEdgeId
|
|
|
|
+ _walls.add(_wallValue);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return _walls;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //门/窗
|
|
|
|
+ private static JSONArray convertSymbols(JSONObject symbols,int floor) {
|
|
|
|
+ JSONArray _symbols = new JSONArray();
|
|
|
|
+ for (Map.Entry<String, Object> entry: symbols.entrySet()) {
|
|
|
|
+ JSONObject symbolValue = (JSONObject)entry.getValue();
|
|
|
|
+ JSONObject _symbolValue = new JSONObject();
|
|
|
|
+ _symbolValue.put("start", symbolValue.getJSONObject("startPoint"));
|
|
|
|
+ _symbolValue.put("end", symbolValue.getJSONObject("endPoint"));
|
|
|
|
+ _symbolValue.put("parent", symbolValue.getString("parent"));
|
|
|
|
+ _symbolValue.put("openSide", symbolValue.getString("openSide"));
|
|
|
|
+ _symbolValue.put("vectorId", symbolValue.getString("vectorId"));
|
|
|
|
+ _symbolValue.put("points2d", symbolValue.getJSONArray("points2d"));
|
|
|
|
+ _symbolValue.put("geoType", symbolValue.getString("geoType"));
|
|
|
|
+ _symbolValue.put("floor", floor);
|
|
|
|
+
|
|
|
|
+ //"groundClearance": -0.7,
|
|
|
|
+ //"height": 1.3,
|
|
|
|
+
|
|
|
|
+ _symbols.add(_symbolValue);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return _symbols;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static JSONArray convertRooms(JSONArray rooms,int floor) {
|
|
|
|
+ JSONArray _rooms = new JSONArray();
|
|
|
|
+
|
|
|
|
+ for(int i=0;i<rooms.size();++i) {
|
|
|
|
+ JSONObject room = rooms.getJSONObject(i);
|
|
|
|
+ String name = room.getString("name");
|
|
|
|
+ JSONObject center = room.getJSONObject("center");
|
|
|
|
+ String roomId = room.getString("roomId");
|
|
|
|
+ JSONArray wallIds = room.getJSONArray("wallIds");
|
|
|
|
+ JSONArray wallPointIDs = room.getJSONArray("wallPointIDs");
|
|
|
|
+ String parent = room.getString("parent");
|
|
|
|
+
|
|
|
|
+ JSONObject _room = new JSONObject();
|
|
|
|
+ _room.put("name", name);
|
|
|
|
+ _room.put("roomId", roomId);
|
|
|
|
+ _room.put("center", center);
|
|
|
|
+ _room.put("wallIds", wallIds);
|
|
|
|
+ _room.put("wallPointIDs", wallPointIDs);
|
|
|
|
+ _room.put("parent", parent);
|
|
|
|
+
|
|
|
|
+ _rooms.add(_room);
|
|
|
|
+ }
|
|
|
|
+ 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
|
|
|
|
+}
|