Skip to content

Commit

Permalink
Add support for importing DXF polylines (#2612)
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler authored Sep 16, 2024
1 parent bf09d7a commit c0630e5
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.willwinder.ugs.nbp.designer.io.dxf;

import com.willwinder.ugs.nbp.designer.entities.Entity;
import com.willwinder.ugs.nbp.designer.entities.cuttable.CutType;
import com.willwinder.ugs.nbp.designer.entities.cuttable.Ellipse;
import com.willwinder.ugs.nbp.designer.entities.cuttable.Group;
import com.willwinder.ugs.nbp.designer.entities.cuttable.Path;
import com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle;
import com.willwinder.ugs.nbp.designer.io.DesignReader;
import com.willwinder.ugs.nbp.designer.io.DesignReaderException;
import com.willwinder.ugs.nbp.designer.model.Design;
Expand All @@ -20,14 +18,15 @@
import org.kabeja.dxf.DXFLayer;
import org.kabeja.dxf.DXFLine;
import org.kabeja.dxf.DXFPoint;
import org.kabeja.dxf.DXFPolyline;
import org.kabeja.dxf.DXFVertex;
import org.kabeja.dxf.helpers.Point;
import org.kabeja.parser.DXFParser;
import org.kabeja.parser.ParseException;
import org.kabeja.parser.Parser;
import org.kabeja.parser.ParserBuilder;

import java.awt.geom.Arc2D;
import java.awt.geom.Point2D;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -72,7 +71,7 @@ public Optional<Design> read(InputStream resourceAsStream) {
DXFLayer layer = (DXFLayer) layerIterator.next();
parseAndAddLayerGroup(group, layer);
}

Design design = new Design();
List<Entity> entities = new ArrayList<>();
if (!group.getChildren().isEmpty()) {
Expand Down Expand Up @@ -112,11 +111,37 @@ private void parseAndAddLayerGroup(Group group, DXFLayer layer) {
layerGroup.addChild(arcsGroup);
}

Group polylinesGroup = new Group();
polylinesGroup.setName("Polyline");
parsePolylines(layer, polylinesGroup);
if (!polylinesGroup.getChildren().isEmpty()) {
layerGroup.addChild(polylinesGroup);
}

if (!layerGroup.getChildren().isEmpty()) {
group.addChild(layerGroup);
}
}

private void parsePolylines(DXFLayer layer, Group polylinesGroup) {
List<DXFPolyline> polylines = layer.getDXFEntities(DXFConstants.ENTITY_TYPE_POLYLINE);
if (polylines == null) {
return;
}

for (DXFPolyline polyline : polylines) {
Path path = new Path();
DXFVertex vertex = polyline.getVertex(0);
path.moveTo(convertCoordinate(vertex.getX()), convertCoordinate(vertex.getY()));
for(int i = 1; i < polyline.getVertexCount(); i++) {
vertex = polyline.getVertex(i);
path.lineTo(convertCoordinate(vertex.getX()), convertCoordinate(vertex.getY()));
}
path.close();

polylinesGroup.addChild(path);
}
}


private void parseArcs(DXFLayer layer, Group arcsGroup) {
Expand Down

0 comments on commit c0630e5

Please sign in to comment.