|
@@ -7,21 +7,18 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fdkankan.common.util.FileUtils;
|
|
|
-import com.fdkankan.model.bean.PointBean;
|
|
|
-import com.fdkankan.model.bean.SegmentBean;
|
|
|
-import com.fdkankan.model.bean.VertexBean;
|
|
|
-import com.fdkankan.model.bean.WallBean;
|
|
|
+import com.fdkankan.model.bean.*;
|
|
|
|
|
|
+import java.awt.geom.Point2D;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
public class FloorPlanUserUtil {
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- JSONObject floorPlanUserJson = FloorPlanUserUtil.createFloorPlanUserJson("D:\\Downloads\\floorplan_cad.json");
|
|
|
- FileUtil.writeUtf8String(floorPlanUserJson.toJSONString(), "D:\\Downloads\\floorplan.json");
|
|
|
+ JSONObject floorPlanUserJson = FloorPlanUserUtil.createFloorPlanUserJson("D:\\Downloads\\floorplan_cad(3).json");
|
|
|
+ FileUtil.writeUtf8String(floorPlanUserJson.toJSONString(), "D:\\Downloads\\demo.json");
|
|
|
|
|
|
}
|
|
|
|
|
@@ -53,10 +50,12 @@ public class FloorPlanUserUtil {
|
|
|
Map<String, Object> result = createFloorHandler(floor, currentId);
|
|
|
JSONArray points = (JSONArray)result.get("pointArr");
|
|
|
JSONArray walls = (JSONArray)result.get("wallArr");
|
|
|
+ JSONArray symbols = (JSONArray)result.get("symbols");
|
|
|
currentId = (int)result.get("currentId");
|
|
|
JSONObject targetFloor = new JSONObject();
|
|
|
targetFloor.put("points", convertArrToMap(points));
|
|
|
targetFloor.put("walls", convertArrToMap(walls));
|
|
|
+ targetFloor.put("symbols", convertArrToMap(symbols));
|
|
|
targetFloor.put("id", floor.getInteger("id"));
|
|
|
targetFloor.put("name",floor.getString("name"));
|
|
|
targetFloor.put("subgroup", floor.getInteger("subgroup"));
|
|
@@ -68,6 +67,7 @@ public class FloorPlanUserUtil {
|
|
|
return house;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private static Map<String, JSONObject> convertArrToMap(JSONArray arr){
|
|
|
Map<String, JSONObject> result = new HashMap<>();
|
|
|
if(CollUtil.isEmpty(arr)){
|
|
@@ -133,7 +133,7 @@ public class FloorPlanUserUtil {
|
|
|
.vectorId(wallId)
|
|
|
.start(segmentBean.getStartPointId())
|
|
|
.end(segmentBean.getEndPointId())
|
|
|
- .children(new String[]{})
|
|
|
+ .children(new HashSet<>())
|
|
|
.width(0.2d)
|
|
|
.build();
|
|
|
wallMap.put(wallId, wallBean);
|
|
@@ -146,6 +146,82 @@ public class FloorPlanUserUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //处理门窗
|
|
|
+ Map<String, SymbolBean> symbolMap = new HashMap<>();
|
|
|
+ JSONArray shapesArr = floor.getJSONArray("shapes");
|
|
|
+ if(CollUtil.isNotEmpty(shapesArr)){
|
|
|
+ List<JSONObject> windowAndDoors = shapesArr.stream().filter(v->{
|
|
|
+ JSONObject obj = (JSONObject) v;
|
|
|
+ String category = obj.getString("category");
|
|
|
+ if(StrUtil.isNotEmpty(category) && (category.contains("Window") || category.contains("Door"))){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }).map(v->(JSONObject)v).collect(Collectors.toList());
|
|
|
+ if(CollUtil.isNotEmpty(windowAndDoors)){
|
|
|
+ for (int i = 0; i < windowAndDoors.size(); i++){
|
|
|
+
|
|
|
+ JSONObject jsonObject = windowAndDoors.get(i);
|
|
|
+ String category = jsonObject.getString("category");
|
|
|
+ String geoType = null;
|
|
|
+ String name = null;
|
|
|
+ String openSide = null;
|
|
|
+ if(category.contains("Window")){
|
|
|
+ geoType = "SingleWindow";
|
|
|
+ name = "单开窗";
|
|
|
+ openSide = "RIGHT";
|
|
|
+ }
|
|
|
+ if(category.contains("Door")){
|
|
|
+ geoType = "SingleDoor";
|
|
|
+ name = "单开门";
|
|
|
+ openSide = "LEFT";
|
|
|
+ }
|
|
|
+
|
|
|
+ //vectorId
|
|
|
+ String symbolId = geoType + currentId;
|
|
|
+
|
|
|
+ JSONObject line = jsonObject.getJSONObject("line");
|
|
|
+ String openSideAi = line.getString("openSide");
|
|
|
+ if(StrUtil.isNotEmpty(openSideAi)){
|
|
|
+ if("L".equals(openSideAi)){
|
|
|
+ openSide = "LEFT";
|
|
|
+ }
|
|
|
+ if("R".equals(openSideAi)){
|
|
|
+ openSide = "RIGHT";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject point0 = line.getJSONObject("point_0");
|
|
|
+ Integer segmentId0 = point0.getInteger("segment_id");
|
|
|
+ point0.remove("segment_id");
|
|
|
+
|
|
|
+ JSONObject point1 = line.getJSONObject("point_1");
|
|
|
+ Integer segmentId1 = point1.getInteger("segment_id");
|
|
|
+ point1.remove("segment_id");
|
|
|
+
|
|
|
+ //求两点之间的距离
|
|
|
+ Point2D p0 = new Point2D.Double(point0.getDouble("x"), point0.getDouble("y"));
|
|
|
+ Point2D p1 = new Point2D.Double(point1.getDouble("x"), point1.getDouble("y"));
|
|
|
+ double distance = p0.distance(p1);
|
|
|
+
|
|
|
+ //设置墙的children
|
|
|
+ String wall0 = swMap.get(segmentId0);
|
|
|
+ String wall1 = swMap.get(segmentId1);
|
|
|
+ WallBean wallBean0 = wallMap.get(wall0);
|
|
|
+ wallBean0.getChildren().add(symbolId);
|
|
|
+ WallBean wallBean1 = wallMap.get(wall1);
|
|
|
+ wallBean1.getChildren().add(symbolId);
|
|
|
+
|
|
|
+ SymbolBean symbolBean = SymbolBean.builder().name(name).geoType(geoType)
|
|
|
+ .vectorId(symbolId).openSide(openSide).startPoint(point0).endPoint(point1).len(distance)
|
|
|
+ .parent(wall0).build();
|
|
|
+ symbolMap.put(symbolId, symbolBean);
|
|
|
+
|
|
|
+ ++currentId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
Collection<PointBean> pointBeans = pointMap.values();
|
|
|
for (PointBean pointBean : pointBeans) {
|
|
|
Map<String, String> parent = new HashMap<>();
|
|
@@ -166,12 +242,18 @@ public class FloorPlanUserUtil {
|
|
|
JSONArray wallArr = JSON.parseArray(JSON.toJSONString(wallBeans));
|
|
|
result.put("wallArr", wallArr);
|
|
|
|
|
|
+ if(CollUtil.isNotEmpty(symbolMap)){
|
|
|
+ JSONArray symbolArr = JSON.parseArray(JSON.toJSONString(symbolMap.values()));
|
|
|
+ result.put("symbols", symbolArr);
|
|
|
+ }
|
|
|
+
|
|
|
result.put("currentId", currentId);
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private static JSONArray readFloorJson(String filePath) {
|
|
|
try {
|
|
|
JSONObject floorplan = FileUtils.readJson(filePath);
|