Skip to content

Commit

Permalink
Implement spline and fix timeout to jaguar
Browse files Browse the repository at this point in the history
  • Loading branch information
VovaStelmashchuk committed Aug 9, 2024
1 parent 38ba237 commit 4aeddc5
Show file tree
Hide file tree
Showing 15 changed files with 229 additions and 277 deletions.
7 changes: 7 additions & 0 deletions backend/src/main/java/com/nestapp/RestController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.nestapp.nest.nestRestApi
import com.nestapp.project.ProjectMaker
import com.nestapp.project.projectsRestController
import io.ktor.client.HttpClient
import io.ktor.client.plugins.HttpTimeout
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.serialization.kotlinx.json.json
Expand All @@ -24,6 +25,7 @@ import io.ktor.server.routing.get
import io.ktor.server.routing.route
import io.ktor.server.routing.routing
import kotlinx.serialization.json.Json
import java.util.concurrent.TimeUnit

fun createHttpClient(): HttpClient {
return HttpClient {
Expand All @@ -35,6 +37,11 @@ fun createHttpClient(): HttpClient {
}
)
}
install(HttpTimeout) {
requestTimeoutMillis = TimeUnit.MINUTES.toMillis(3)
connectTimeoutMillis = TimeUnit.MINUTES.toMillis(1)
socketTimeoutMillis = TimeUnit.MINUTES.toMillis(3)
}
}
}

Expand Down
11 changes: 0 additions & 11 deletions backend/src/main/java/com/nestapp/files/dxf/reader/Arc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ internal class Arc(type: String?) : Entity(type!!), AutoPop {
path.append(arc, true)
}

override fun translate(x: Double, y: Double): Entity {
val translatedArc = Arc(type)
translatedArc.cx = this.cx + x
translatedArc.cy = this.cy + y
translatedArc.radius = this.radius
translatedArc.startAngle = this.startAngle
translatedArc.endAngle = this.endAngle
translatedArc.close()
return translatedArc
}

override fun toWriterEntity(placement: Placement): DXFEntity {
val center = RealPoint(cx, cy)

Expand Down
13 changes: 0 additions & 13 deletions backend/src/main/java/com/nestapp/files/dxf/reader/Circle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,4 @@ internal class Circle(type: String?) : Entity(type!!), AutoPop {
radius
)
}

override fun translate(x: Double, y: Double): Entity {
val newX = cx + x
val newY = cy + y
val originRadius = radius

return Circle(type).apply {
cx = newX
cy = newY
radius = originRadius
close()
}
}
}
106 changes: 0 additions & 106 deletions backend/src/main/java/com/nestapp/files/dxf/reader/DXFReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,45 +335,6 @@ class Hatch extends Entity implements AutoPop {
}
}

class Insert extends Entity implements AutoPop {
private String blockHandle, blockName;
private double ix, iy, xScale = 1.0, yScale = 1.0, zScale = 1.0, rotation;

Insert(String type) {
super(type);
}

@Override
public void addParam(int gCode, String value) {
switch (gCode) {
case 2: // Name of Block to insert
blockName = value;
break;
case 5: // Handle of Block to insert
blockHandle = value;
break;
case 10: // Insertion X
ix = Double.parseDouble(value);
break;
case 20: // Insertion Y
iy = Double.parseDouble(value);
break;
case 41: // X scaling
xScale = Double.parseDouble(value);
break;
case 42: // Y scaling
yScale = Double.parseDouble(value);
break;
case 43: // Z Scaling (affects x coord and rotation)
zScale = Double.parseDouble(value);
break;
case 50: // Rotation angle (degrees)
rotation = Double.parseDouble(value);
break;
}
}
}

/*
* Note: code for "DIMENSION" is incomplete
*/
Expand Down Expand Up @@ -478,66 +439,6 @@ public void close() {
}
}

class Spline extends Entity implements AutoPop {
Path2D.Double path = new Path2D.Double();
List<Point2D.Double> cPoints = new ArrayList<>();
private double xCp, yCp;
private boolean hasXcp, hasYcp;
private boolean closed;
private int numCPs;
private int degree;

Spline(String type) {
super(type);
}

@Override
public void addParam(int gCode, String value) {
switch (gCode) {
case 10: // Control Point X
xCp = Double.parseDouble(value);
hasXcp = true;
break;
case 20: // Control Point Y
yCp = Double.parseDouble(value);
hasYcp = true;
break;
case 70: // Flags (bitfield)
// bit 0: Closed spline, bit 1: Periodic spline, bit 2: Rational spline, bit 3: Planar, bit 4: Linear (planar bit is also set)
// Examples:
// 10 = Closed, Periodic, Planar Spline
//
int flags = Integer.parseInt(value);
closed = (flags & 0x01) != 0;
break;
case 71: // Degree of the spline curve
degree = Integer.parseInt(value);
break;
case 73: // Number of Control Points
numCPs = Integer.parseInt(value);
break;
}
if (hasXcp && hasYcp) {
cPoints.add(new Point2D.Double(xCp, yCp));
hasXcp = hasYcp = false;
if (cPoints.size() == numCPs) {
if (degree == 3) {
Point2D.Double[] points = cPoints.toArray(new Point2D.Double[0]);
path.moveTo(points[0].x, points[0].y);
for (int ii = 1; ii < points.length; ii += 3) {
path.curveTo(points[ii].x, points[ii].y, points[ii + 1].x, points[ii + 1].y, points[ii + 2].x, points[ii + 2].y);
}
}
} else if (degree == 2) {
Point2D.Double[] points = cPoints.toArray(new Point2D.Double[0]);
path.moveTo(points[0].x, points[0].y);
for (int ii = 1; ii < points.length; ii += 2) {
path.quadTo(points[ii].x, points[ii].y, points[ii + 1].x, points[ii + 1].y);
}
}
}
}
}

private void push() {
stack.add(cEntity);
Expand Down Expand Up @@ -585,13 +486,6 @@ private void debugPrint(String value) {
System.out.println(value);
}

public void parseFile(File file) throws IOException {
stack = new ArrayList<>();
cEntity = null;
Scanner lines = new Scanner(Files.newInputStream(file.toPath()));
parseFile(lines);
}

public void parseFile(InputStream stream) {
stack = new ArrayList<>();
cEntity = null;
Expand Down
4 changes: 0 additions & 4 deletions backend/src/main/java/com/nestapp/files/dxf/reader/Entity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,4 @@ open class Entity internal constructor(@JvmField var type: String) {
open fun toWriterEntity(placement: Placement = NotMovedPlacement): DXFEntity {
throw UnsupportedOperationException("Not implemented in ${this.javaClass.simpleName}")
}

open fun translate(x: Double, y: Double): Entity {
throw UnsupportedOperationException("Not implemented in ${this.javaClass.simpleName}")
}
}
40 changes: 40 additions & 0 deletions backend/src/main/java/com/nestapp/files/dxf/reader/Insert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.nestapp.files.dxf.reader;

public class Insert extends Entity implements AutoPop {
private String blockHandle, blockName;
private double ix, iy, xScale = 1.0, yScale = 1.0, zScale = 1.0, rotation;

Insert(String type) {
super(type);
}

@Override
public void addParam(int gCode, String value) {
switch (gCode) {
case 2: // Name of Block to insert
blockName = value;
break;
case 5: // Handle of Block to insert
blockHandle = value;
break;
case 10: // Insertion X
ix = Double.parseDouble(value);
break;
case 20: // Insertion Y
iy = Double.parseDouble(value);
break;
case 41: // X scaling
xScale = Double.parseDouble(value);
break;
case 42: // Y scaling
yScale = Double.parseDouble(value);
break;
case 43: // Z Scaling (affects x coord and rotation)
zScale = Double.parseDouble(value);
break;
case 50: // Rotation angle (degrees)
rotation = Double.parseDouble(value);
break;
}
}
}
24 changes: 0 additions & 24 deletions backend/src/main/java/com/nestapp/files/dxf/reader/Line.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,4 @@ class Line internal constructor(type: String) : Entity(type), AutoPop {

return DXFLine(start.transform(placement), end.transform(placement))
}

override fun translate(x: Double, y: Double): Entity {
val originStartX = xStart
val originStartY = yStart
val originEndX = xEnd
val originEndY = yEnd

return Line(type).apply {
this.xStart = originStartX + x
this.yStart = originStartY + y
this.xEnd = originEndX + x
this.yEnd = originEndY + y
this.close()
}
}

override fun toString(): String {
return "Line{" +
"xStart=" + xStart +
", yStart=" + yStart +
", xEnd=" + xEnd +
", yEnd=" + yEnd +
'}'
}
}
10 changes: 0 additions & 10 deletions backend/src/main/java/com/nestapp/files/dxf/reader/LwPolyline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,6 @@ class LwPolyline internal constructor(type: String) : Entity(type), AutoPop {
closed = true
)
}

override fun translate(x: Double, y: Double): Entity {
return LwPolyline(type).also {
it.segments =
segments.map { segment -> LSegment(dx = segment.dx + x, dy = segment.dy + y, bulge = segment.bulge) }
.toMutableList()
it.close = close
it.close()
}
}
}


23 changes: 1 addition & 22 deletions backend/src/main/java/com/nestapp/files/dxf/reader/Polyline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ internal class Polyline(type: String?) : Entity(type!!) {
}

override fun isClose(): Boolean {
return points.isNotEmpty() && points.first().let { firstPoint ->
points.last().let { lastPoint -> firstPoint.xx == lastPoint.xx && firstPoint.yy == lastPoint.yy }
}
return close
}

override fun toWriterEntity(placement: Placement): DXFEntity {
Expand All @@ -84,25 +82,6 @@ internal class Polyline(type: String?) : Entity(type!!) {
)
}

override fun translate(x: Double, y: Double): Entity {
return Polyline(type).also {
it.points = points.map { vertex ->
val newVertex = Vertex(type)
newVertex.xx = vertex.xx + x
newVertex.yy = vertex.yy + y
newVertex.bulge = vertex.bulge
newVertex
}.toMutableList()
it.close = close
it.firstX = firstX + x
it.firstY = firstY + y
it.lastX = lastX + x
it.lastY = lastY + y
it.firstPoint = firstPoint
it.close()
}
}

/**
* See: http://darrenirvine.blogspot.com/2015/08/polylines-radius-bulge-turnaround.html
*
Expand Down
Loading

0 comments on commit 4aeddc5

Please sign in to comment.