Skip to content

Commit

Permalink
Remove Scala code.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody82 committed Jun 11, 2017
1 parent 2231328 commit de6b6eb
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 126 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ and in `grblgui-gcode` next to `grblgui.jar`.

## Development
For compiling you need:
* Eclipse 3.6(?)
* Eclipse Scala plugin with Scala 2.10
* Or: Scala IDE from http://scala-ide.org/
* Eclipse >= 3.6
1 change: 0 additions & 1 deletion grblgui-desktop/.classpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/grblgui"/>
<classpathentry kind="lib" path="/grblgui-lib/src/jssc/jssc.jar"/>
Expand Down
3 changes: 1 addition & 2 deletions grblgui-desktop/.project
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
</projects>
<buildSpec>
<buildCommand>
<name>org.scala-ide.sdt.core.scalabuilder</name>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.scala-ide.sdt.core.scalanature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
20 changes: 0 additions & 20 deletions grblgui-desktop/src/cody/grblgui/ScalaSimulationConverter.java

This file was deleted.

79 changes: 0 additions & 79 deletions grblgui-desktop/src/cody/grblgui/Simulation.scala

This file was deleted.

6 changes: 0 additions & 6 deletions grblgui-desktop/src/cody/grblgui/ToolType.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import cody.grbl.GrblFactory;
import cody.grbl.GrblStreamFactory;
import cody.grblgui.Main;
import cody.grblgui.ScalaSimulationConverter;
import cody.grblgui.SimulationConverter;

import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
Expand Down Expand Up @@ -34,7 +33,7 @@ public static void main (String[] argv) {
}

GrblStreamFactory.instance = new GrblFactory();
SimulationConverter.instance = new ScalaSimulationConverter();
SimulationConverter.instance = new SimulationConverter();

Main main = new Main(dir, port);
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
Expand Down
99 changes: 99 additions & 0 deletions grblgui/src/cody/grblgui/Simulation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package cody.grblgui;

import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;

public class Simulation {
public int count_x, count_y;
float map[][];
Vector2 zero;
final float precision;

public Simulation(float size_x, float size_y, float size_z, float precision) {
this.precision = precision;
count_x = (int)(size_x / precision);
count_y = (int)(size_y / precision);

map = new float[count_x][count_y];
zero = new Vector2(-size_x / 2f,-size_y / 2f);
}

public Vector2 indexToPosition(int x, int y) {
return new Vector2(zero.x + x * precision, zero.y + y * precision);
}

public GridPoint2 positionToIndex(Vector2 v) {
return new GridPoint2((int)((v.x - zero.x) / precision), (int)((v.y - zero.y) / precision));
}

public GridPoint2 positionToIndex(float x, float y) {
return new GridPoint2((int)((x - zero.x) / precision), (int)((y - zero.y) / precision));
}

public int lengthToCount(float l) {
return (int)(l/precision);
}

public float getZ(int x, int y) {
return map[x][y];
}

public Vector2 getZminmax() {
float min = Float.MAX_VALUE;
float max = Float.MIN_VALUE;
for(int x = 0; x <= count_x - 1; ++x) {
for(int y = 0; y <= count_y - 1; ++y) {
float z = getZ(x,y);
min = Math.min(z, min);
max = Math.max(z, max);
}
}
return new Vector2(min, max);
}

void mill(int x, int y, float z) {
if(x >= 0 && y >= 0 && x < count_x && y < count_y)
map[x][y] = Math.min(map[x][y], z);
}

void mill(Vector3 pos, ToolInfo tool) {
GridPoint2 center = positionToIndex(pos.x, pos.y);
int count = lengthToCount(tool.getRadius());

for(int x = center.x - count; x <= center.x + count; ++x) {
for(int y = center.y - count; y <= center.y + count; ++y) {
Vector2 p = indexToPosition(x,y);
p = new Vector2(p.x - pos.x, p.y - pos.y);

float dist = p.len();
if(dist < tool.getRadius()) {
//println("mill " + pos.x + " " + pos.y + " " + pos.z + " " + x + " " + y)
mill(x, y, pos.z);
}
}
}
}

void simulate(Toolpath path, ToolInfo tool) {
Vector3 cur = path.path.get(0);

for(int i=1;i<=path.path.size() - 1;++i) {
Vector3 next = path.path.get(i);
if(next.z < 0 || cur.z < 0){
Vector3 d = next.cpy();
d.sub(cur);
//println("line " + cur.toString() + " -> " + next.toString())
int segments = Math.max(1,(int)(d.len() / precision));
for(int j = 0; j <= segments - 1; ++j) {
Vector3 p = d.cpy();
p.scl(j);
p.scl(1.0f/segments);
p.add(cur);
mill(new Vector3(p.x,p.y,p.z), tool);
}
}
cur = next;
}
}
}
10 changes: 8 additions & 2 deletions grblgui/src/cody/grblgui/SimulationConverter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cody.grblgui;

public abstract class SimulationConverter {
public class SimulationConverter {
public static SimulationConverter instance;

public static Part convert(Toolpath path, ToolInfo info){
Expand All @@ -11,6 +11,12 @@ public static Part convert(Toolpath path, ToolInfo info){
}

public Part convertImpl(Toolpath path, ToolInfo info){
return null;
Simulation sim = new Simulation(300, 400, 50, 1f);
sim.simulate(path, info);
//Tuple2<Object, Object> tmp = sim.getZminmax();
//float min = (float)tmp._1;
//float max = (float)tmp._2;

return new SimulationPart(sim);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.io.FileNotFoundException;

import scala.Tuple2;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Mesh;
Expand All @@ -12,6 +10,7 @@
import com.badlogic.gdx.graphics.Texture.TextureWrap;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector2;

import cody.grblgui.Part;
Expand All @@ -20,28 +19,28 @@ public class SimulationPart extends Part {


Mesh generateMesh(Simulation sim) {
float[] verts = new float[(sim.count_x() + 1) * 2 * (sim.count_y() - 1) * (3 + 1)];
float[] verts = new float[(sim.count_x + 1) * 2 * (sim.count_y - 1) * (3 + 1)];
System.out.println(verts.length / (3 + 1));

Tuple2<Object, Object> tmp = sim.getZminmax();
final float min = (float)tmp._1;
final float max = (float)tmp._2;
Vector2 tmp = sim.getZminmax();
final float min = (float)tmp.x;
final float max = (float)tmp.y;

int index = 0;

for(int y = 0; y < sim.count_y() - 1; ++y) {
for(int x = 0; x < sim.count_x(); ++x) {
for(int y = 0; y < sim.count_y - 1; ++y) {
for(int x = 0; x < sim.count_x; ++x) {

float pz = sim.getZ(x, y);
Vector2 v = sim.index_to_position(x, y);
Vector2 v = sim.indexToPosition(x, y);
float px = v.x;
float py = v.y;
float c1 = (max - pz) / (max - min);
if(pz != max)
c1 = Math.max(0.2f, c1);

float pz2 = sim.getZ(x, y + 1);
Vector2 v2 = sim.index_to_position(x, y + 1);
Vector2 v2 = sim.indexToPosition(x, y + 1);
float px2 = v2.x;
float py2 = v2.y;
float c2 = (max - pz2) / (max - min);
Expand All @@ -66,7 +65,7 @@ Mesh generateMesh(Simulation sim) {
verts[index++] = pz2;
verts[index++] = new Color(0,0,c2,1).toFloatBits();

if(x == sim.count_x() - 1) {
if(x == sim.count_x - 1) {
for(int i=0;i<4;++i) {
verts[index] = verts[index-4];
index++;
Expand Down

0 comments on commit de6b6eb

Please sign in to comment.