|
@@ -9,8 +9,11 @@ import com.fdkankan.dxf.fdjson.vo.FdWalls;
|
|
import com.fdkankan.dxf.generate.DxfDocWriter;
|
|
import com.fdkankan.dxf.generate.DxfDocWriter;
|
|
import com.fdkankan.dxf.generate.Vector3;
|
|
import com.fdkankan.dxf.generate.Vector3;
|
|
import com.fdkankan.dxf.generate.enums.LineWidthEnum;
|
|
import com.fdkankan.dxf.generate.enums.LineWidthEnum;
|
|
|
|
+import com.fdkankan.dxf.generate.model.DxfArc;
|
|
import com.fdkankan.dxf.generate.model.DxfLine;
|
|
import com.fdkankan.dxf.generate.model.DxfLine;
|
|
|
|
+import com.fdkankan.dxf.generate.model.DxfLwPolyLine;
|
|
import com.fdkankan.dxf.generate.model.base.Color;
|
|
import com.fdkankan.dxf.generate.model.base.Color;
|
|
|
|
+import com.fdkankan.dxf.math.MathArcUtil;
|
|
import com.fdkankan.dxf.parse.ParseDXF;
|
|
import com.fdkankan.dxf.parse.ParseDXF;
|
|
import com.fdkankan.dxf.parse.model.entities.GeometricLine;
|
|
import com.fdkankan.dxf.parse.model.entities.GeometricLine;
|
|
import com.fdkankan.dxf.parse.resolver.DxfResolver;
|
|
import com.fdkankan.dxf.parse.resolver.DxfResolver;
|
|
@@ -18,6 +21,7 @@ import com.fdkankan.dxf.parse.resolver.DxfResolver;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.Paths;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -32,15 +36,17 @@ public class FdJsonToDxfUtil {
|
|
*/
|
|
*/
|
|
public static void fdJsonToDxf(String fdJsonPath,String dxfPath,Integer subgroup) {
|
|
public static void fdJsonToDxf(String fdJsonPath,String dxfPath,Integer subgroup) {
|
|
try {
|
|
try {
|
|
|
|
+ DxfDocWriter dxfDocWriter = new DxfDocWriter();
|
|
String msg = new String(Files.readAllBytes(Paths.get(fdJsonPath)));
|
|
String msg = new String(Files.readAllBytes(Paths.get(fdJsonPath)));
|
|
JSONObject jsonObject = JSONObject.parseObject(msg);
|
|
JSONObject jsonObject = JSONObject.parseObject(msg);
|
|
JSONArray floors = jsonObject.getJSONArray("floors");
|
|
JSONArray floors = jsonObject.getJSONArray("floors");
|
|
for (Object obj : floors) {
|
|
for (Object obj : floors) {
|
|
JSONObject floor = (JSONObject) (obj);
|
|
JSONObject floor = (JSONObject) (obj);
|
|
if(floor.getInteger("subgroup") != null && floor.getInteger("subgroup").equals(subgroup)){
|
|
if(floor.getInteger("subgroup") != null && floor.getInteger("subgroup").equals(subgroup)){
|
|
- plantWall(dxfPath,floor);
|
|
|
|
|
|
+ plantWall(dxfPath,dxfDocWriter,floor);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ dxfDocWriter.save(dxfPath, true);
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
@@ -54,13 +60,17 @@ public class FdJsonToDxfUtil {
|
|
*/
|
|
*/
|
|
public static void fdJsonToDxf(String fdJsonPath,String dxfPath) {
|
|
public static void fdJsonToDxf(String fdJsonPath,String dxfPath) {
|
|
try {
|
|
try {
|
|
|
|
+ DxfDocWriter dxfDocWriter = new DxfDocWriter();
|
|
|
|
+
|
|
String msg = new String(Files.readAllBytes(Paths.get(fdJsonPath)));
|
|
String msg = new String(Files.readAllBytes(Paths.get(fdJsonPath)));
|
|
JSONObject jsonObject = JSONObject.parseObject(msg);
|
|
JSONObject jsonObject = JSONObject.parseObject(msg);
|
|
JSONArray floors = jsonObject.getJSONArray("floors");
|
|
JSONArray floors = jsonObject.getJSONArray("floors");
|
|
for (Object obj : floors) {
|
|
for (Object obj : floors) {
|
|
JSONObject floor = (JSONObject) (obj);
|
|
JSONObject floor = (JSONObject) (obj);
|
|
- plantWall(dxfPath,floor);
|
|
|
|
|
|
+ plantWall(dxfPath,dxfDocWriter,floor);
|
|
|
|
+ plantSymbols(dxfPath,dxfDocWriter,floor);
|
|
}
|
|
}
|
|
|
|
+ dxfDocWriter.save(dxfPath, true);
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
@@ -70,7 +80,7 @@ public class FdJsonToDxfUtil {
|
|
/**
|
|
/**
|
|
* 墙,根据起始点画线
|
|
* 墙,根据起始点画线
|
|
*/
|
|
*/
|
|
- private static void plantWall(String filePath, JSONObject fools) {
|
|
|
|
|
|
+ private static void plantWall(String filePath, DxfDocWriter dxfDocWriter,JSONObject fools) {
|
|
HashMap<String, FdPoints> wallMap= new HashMap<>();
|
|
HashMap<String, FdPoints> wallMap= new HashMap<>();
|
|
|
|
|
|
JSONObject walls = fools.getJSONObject("walls");
|
|
JSONObject walls = fools.getJSONObject("walls");
|
|
@@ -80,7 +90,7 @@ public class FdJsonToDxfUtil {
|
|
FdPoints point = new FdPoints(obj.getDouble("x") * 100, obj.getDouble("y") * 100);
|
|
FdPoints point = new FdPoints(obj.getDouble("x") * 100, obj.getDouble("y") * 100);
|
|
wallMap.put(key,point);
|
|
wallMap.put(key,point);
|
|
}
|
|
}
|
|
- DxfDocWriter dxfDocWriter = new DxfDocWriter();
|
|
|
|
|
|
+
|
|
for (String key : walls.keySet()) {
|
|
for (String key : walls.keySet()) {
|
|
JSONObject wall = walls.getJSONObject(key);
|
|
JSONObject wall = walls.getJSONObject(key);
|
|
String start = wall.getString("start");
|
|
String start = wall.getString("start");
|
|
@@ -88,9 +98,21 @@ public class FdJsonToDxfUtil {
|
|
Boolean out = wall.getBoolean("out");
|
|
Boolean out = wall.getBoolean("out");
|
|
drawLinePoint(filePath,wallMap.get(start),wallMap.get(end),dxfDocWriter,out);
|
|
drawLinePoint(filePath,wallMap.get(start),wallMap.get(end),dxfDocWriter,out);
|
|
}
|
|
}
|
|
- dxfDocWriter.save(filePath, true);
|
|
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 门,根据起始点画线
|
|
|
|
+ */
|
|
|
|
+ private static void plantSymbols(String filePath,DxfDocWriter dxfDocWriter, JSONObject fools) {
|
|
|
|
+ JSONObject symbols = fools.getJSONObject("symbols");
|
|
|
|
+ for (String key : symbols.keySet()) {
|
|
|
|
+ JSONArray points2d = symbols.getJSONObject(key).getJSONArray("points2d");
|
|
|
|
+ String openSide = symbols.getJSONObject(key).getString("openSide");
|
|
|
|
+ drawDoor(points2d, openSide.equals("LEFT"),dxfDocWriter);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
public static void drawLinePoint(String filePath,FdPoints point,FdPoints point2,DxfDocWriter dxfDocWriter,Boolean out){
|
|
public static void drawLinePoint(String filePath,FdPoints point,FdPoints point2,DxfDocWriter dxfDocWriter,Boolean out){
|
|
DxfLine dxfLine = new DxfLine();
|
|
DxfLine dxfLine = new DxfLine();
|
|
dxfLine.setStartPoint(new Vector3(point.getX(), point.getY(), 0));
|
|
dxfLine.setStartPoint(new Vector3(point.getX(), point.getY(), 0));
|
|
@@ -102,7 +124,42 @@ public class FdJsonToDxfUtil {
|
|
dxfDocWriter.addEntity(dxfLine);
|
|
dxfDocWriter.addEntity(dxfLine);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static void drawLinePoint(Vector3 point,Vector3 point2,DxfDocWriter dxfDocWriter){
|
|
|
|
+ DxfLine dxfLine = new DxfLine();
|
|
|
|
+ dxfLine.setStartPoint(new Vector3(point.getX(), point.getY(), 0));
|
|
|
|
+ dxfLine.setEndPoint(new Vector3(point2.getX(), point2.getY(), 0));
|
|
|
|
+ dxfLine.setColor(new Color(0, 120, 32));
|
|
|
|
+ dxfDocWriter.addEntity(dxfLine);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void drawArc(Vector3 point,Vector3 point2,DxfDocWriter dxfDocWriter,Boolean isLeft){
|
|
|
|
+ DxfArc dxfArc = new DxfArc();
|
|
|
|
+ dxfArc.setCenter(point);
|
|
|
|
+ dxfArc.setColor(Color.green);
|
|
|
|
+ //勾股定理
|
|
|
|
+ Double a = Math.abs(point.getX() - point2.getX()) * Math.abs(point.getX() - point2.getX());
|
|
|
|
+ Double b = Math.abs(point.getY() - point2.getY()) * Math.abs(point.getY() - point2.getY());
|
|
|
|
+ dxfArc.setRadius(Math.sqrt(a + b));
|
|
|
|
+ //角度
|
|
|
|
+ Double atan = Math.atan((point2.getY()-point.getY()) / (point2.getX()-point.getX())) / 3.14 * 180;
|
|
|
|
+ dxfArc.setStartAngle(atan);
|
|
|
|
+ dxfArc.setEndAngle(atan + 90);
|
|
|
|
+ if(isLeft){
|
|
|
|
+ dxfArc.setStartAngle(atan + 90);
|
|
|
|
+ dxfArc.setEndAngle(-(180 - atan));
|
|
|
|
+ }
|
|
|
|
+ dxfDocWriter.addEntity(dxfArc);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ public static void drawDoor(JSONArray points2d,Boolean isLeft,DxfDocWriter dxfDocWriter){
|
|
|
|
+ List<Vector3> vector3List = new ArrayList<>();
|
|
|
|
+ for (Object object : points2d) {
|
|
|
|
+ JSONObject jso = (JSONObject) object;
|
|
|
|
+ vector3List.add( new Vector3(jso.getDouble("x") * 100,jso.getDouble("y") * 100,jso.getDouble("z")==null?0:jso.getDouble("z") * 100));
|
|
|
|
+ }
|
|
|
|
+ drawLinePoint(vector3List.get(0),vector3List.get(3),dxfDocWriter);
|
|
|
|
+ drawArc(vector3List.get(0),vector3List.get(3),dxfDocWriter,isLeft);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -158,8 +215,8 @@ public class FdJsonToDxfUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
- String inPath ="D:\\cad\\work\\111\\floorplan.json";
|
|
|
|
- String outPath ="D:\\cad\\work\\111\\test1.dxf";
|
|
|
|
|
|
+ String inPath ="D:\\cad\\work\\111\\test.json";
|
|
|
|
+ String outPath ="D:\\cad\\work\\111\\test.dxf";
|
|
FdJsonToDxfUtil.fdJsonToDxf(inPath,outPath);
|
|
FdJsonToDxfUtil.fdJsonToDxf(inPath,outPath);
|
|
}
|
|
}
|
|
}
|
|
}
|