Revision: 2939
http://reprap.svn.sourceforge.net/reprap/?rev=2939&view=rev
Author: kintel
Date: 2009-05-10 02:54:52 +0000 (Sun, 10 May 2009)
Log Message:
-----------
minor reorganization and cleanup
Modified Paths:
--------------
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADContext.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADEvaluatorDialog.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADEvaluatorEngine.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjectHelper.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ParsedTree.java
Added Paths:
-----------
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/BooleanObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/CSObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/CubeObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/CylinderObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ExtrudeObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ForObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/InsetObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/JoinCurvesObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/LatheObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/MacroObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/MeshObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/MetaCADObject.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/NativeObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ObjFactory.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ObjFactoryException.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/PolygonObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/SphereObj.java
Removed Paths:
-------------
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/BooleanObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CSObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CubeObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CylinderObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ExtrudeObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ForObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/InsetObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/JoinCurvesObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/LatheObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MacroObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MeshObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADObject.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/NativeObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjFactory.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjFactoryException.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/PolygonObj.java
trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/SphereObj.java
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/BooleanObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/BooleanObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/BooleanObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,31 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import artofillusion.object.ObjectInfo;
-
-
-public class BooleanObj extends MetaCADObject {
- int type;
-
- public BooleanObj(int type) {
- this.type = type;
- }
-
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- List<ObjectInfo> result = new LinkedList<ObjectInfo>();
-
- CSGHelper helper = new CSGHelper(this.type);
- helper.addAll(ParsedTree.evaluate(ctx, children).iterator());
-
- if (helper.GetObjectInfo() != null)
- result.add(helper.GetObjectInfo());
- return result;
-
- }
-
-}
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CSObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CSObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CSObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,39 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.Iterator;
-import java.util.List;
-
-import artofillusion.math.CoordinateSystem;
-import artofillusion.math.Vec3;
-import artofillusion.object.ObjectInfo;
-
-public class CSObj extends MetaCADObject {
-
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- assert(children.size() == 1);
- List<ObjectInfo> chlist = ParsedTree.evaluate(ctx, children);
-
- CoordinateSystem coordsys = new CoordinateSystem();
- if (parameters.size() >= 3) {
- coordsys.setOrigin(new Vec3(ctx.evaluateExpression(parameters.get(0)),
- ctx.evaluateExpression(parameters.get(1)),
- ctx.evaluateExpression(parameters.get(2))));
- }
- if (parameters.size() >= 6) {
- coordsys.setOrientation(ctx.evaluateExpression(parameters.get(3)),
- ctx.evaluateExpression(parameters.get(4)),
- ctx.evaluateExpression(parameters.get(5)));
- }
-
- Iterator<ObjectInfo> iter = chlist.iterator();
- while (iter.hasNext()) {
- ObjectInfo info = iter.next();
- info.coords.transformCoordinates(coordsys.fromLocal());
- }
- return chlist;
- }
-
-}
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CubeObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CubeObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CubeObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,35 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import artofillusion.math.CoordinateSystem;
-import artofillusion.math.Vec3;
-import artofillusion.object.Cube;
-import artofillusion.object.Object3D;
-import artofillusion.object.ObjectInfo;
-
-public class CubeObj extends MetaCADObject {
-
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- List<ObjectInfo> result = new LinkedList<ObjectInfo>();
-
- double mainparam = 1.0f;
- if (parameters.size() >= 1) {
- mainparam = ctx.evaluateExpression(parameters.get(0));
- }
- Vec3 dims = new Vec3(mainparam, mainparam, mainparam);
- if (parameters.size() >= 3) {
- dims.set(mainparam,
- ctx.evaluateExpression(parameters.get(1)),
- ctx.evaluateExpression(parameters.get(2)));
- }
- Object3D obj3D = new artofillusion.object.Sphere(dims.x, dims.y, dims.z);
- obj3D = new Cube(dims.x, dims.y, dims.z);
- result.add(new ObjectInfo(obj3D, new CoordinateSystem(), "dummy"));
- return result;
- }
-}
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CylinderObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CylinderObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CylinderObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,44 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import artofillusion.math.CoordinateSystem;
-import artofillusion.object.Cylinder;
-import artofillusion.object.Object3D;
-import artofillusion.object.ObjectInfo;
-
-public class CylinderObj extends MetaCADObject {
-
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- List<ObjectInfo> result = new LinkedList<ObjectInfo>();
-
- double mainparam = 1.0f;
- if (parameters.size() >= 1) {
- mainparam = ctx.evaluateExpression(parameters.get(0));
- }
- // First (main) parameter is height
- double height = mainparam;
- double rx = mainparam;
- double ry = mainparam;
- double ratio = 1;
-
- // Second parameter is radius
- if (parameters.size() >= 2) rx = ry = ctx.evaluateExpression(parameters.get(1));
- // Third parameter define separate y radius
- if (parameters.size() >= 3) ry = ctx.evaluateExpression(parameters.get(2));
- // Fourth parameter define top/bottom radius ratio
- // Cylinder takes an optional fourth parameter
- if (parameters.size() >= 4) {
- ratio = ctx.evaluateExpression(parameters.get(3));
- if (ratio > 1) ratio = 1.0;
- if (ratio < 0) ratio = 0.0;
- }
- Object3D obj3D = new Cylinder(height, rx, ry, ratio);
- result.add(new ObjectInfo(obj3D, new CoordinateSystem(), "dummy"));
- return result;
- }
-}
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ExtrudeObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ExtrudeObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ExtrudeObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,109 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import artofillusion.math.CoordinateSystem;
-import artofillusion.math.Vec3;
-import artofillusion.object.Curve;
-import artofillusion.object.Mesh;
-import artofillusion.object.Object3D;
-import artofillusion.object.ObjectInfo;
-import artofillusion.object.TriangleMesh;
-import artofillusion.tools.ExtrudeTool;
-
-public class ExtrudeObj extends MetaCADObject
-{
-
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- List<ObjectInfo> result = new LinkedList<ObjectInfo>();
-
- // Three first parameters define the extrusion vector
- Vec3 dir = Vec3.vz();
- if (parameters.size() >= 3) {
- dir = new Vec3(ctx.evaluateExpression(parameters.get(0)),
- ctx.evaluateExpression(parameters.get(1)),
- ctx.evaluateExpression(parameters.get(2)));
- }
- // 4. parameter is num segments
- int numsegments = 1;
- if (parameters.size() >= 4) {
- numsegments = (int)ctx.evaluateExpression(parameters.get(3));
- if (numsegments < 2) numsegments = 1;
- }
- // 5. parameter is twist degrees
- double twist = 0.0;
- if (parameters.size() >= 5) {
- twist = ctx.evaluateExpression(parameters.get(4));
- }
-
- result.addAll(extrude(ParsedTree.evaluate(ctx, children), dir, numsegments, twist));
- return result;
- }
-
- /**
- *
- * Extrudes the given profiles using the given parameters and returns the result object.
- *
- * @param objects
- * @param dir
- * @param numsegments
- * @param twist
- * @return a list of ObjectInfos. The coordsys in the object infos are just there to move
- * the objects back to their original positions since the extrusion operation always
- * centers the result in the origin.
- */
- public List<ObjectInfo> extrude(List<ObjectInfo> objects, Vec3 dir, int numsegments, double twist)
- {
- // Build extrusion curve from vector and segments
- Vec3 v[] = new Vec3[numsegments+1];
- float smooth[] = new float[v.length];
- for (int i = 0; i < v.length; i++) {
- v[i] = new Vec3(dir);
- v[i].scale(1.0*i/numsegments);
- smooth[i] = 1.0f;
- }
- Curve path = new Curve(v, smooth, Mesh.APPROXIMATING, false);
- CoordinateSystem pathCS = new CoordinateSystem();
-
- // FIXME: Support specifying extrusion curves
- // Extrude each extrudable child object
- List<ObjectInfo> resultobjects = new LinkedList<ObjectInfo>();
- Iterator<ObjectInfo> iter = objects.iterator();
- while (iter.hasNext()) {
- ObjectInfo profile = iter.next();
- Object3D profileobj = profile.getObject();
-
- Object3D obj3D = null;
- if (profileobj instanceof TriangleMesh) {
- obj3D = ExtrudeTool.extrudeMesh((TriangleMesh)profileobj, path, profile.getCoords(), pathCS, twist*Math.PI/180.0, true);
- }
- else if (profileobj instanceof Curve) {
- obj3D = ExtrudeTool.extrudeCurve((Curve)profileobj, path, profile.getCoords(), pathCS, twist*Math.PI/180.0, true);
- }
- if (obj3D != null) {
- // Since the result is centered in the origin, offset the extruded object to
- // move it back to its original position
- // FIXME: Combine this with the user-specified coordinate system
- CoordinateSystem coordsys = new CoordinateSystem(new Vec3(), Vec3.vz(), Vec3.vy());
- Vec3 offset = profile.getCoords().fromLocal().times(((Mesh)profileobj).getVertices()[0].r).
- minus(coordsys.fromLocal().times(((Mesh)obj3D).getVertices()[0].r));
- coordsys.setOrigin(offset);
- ObjectInfo objinfo = new ObjectInfo(obj3D, coordsys, "tmp");
- resultobjects.add(objinfo);
- }
- profile.setVisible(false);
- }
- // FIXME: Undo support?
- return resultobjects;
-}
-
-
-
-
-
-}
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ForObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ForObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ForObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,31 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import artofillusion.object.ObjectInfo;
-
-public class ForObj extends MetaCADObject {
-
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- List<ObjectInfo> result = new LinkedList<ObjectInfo>();
-
- // evaluate first part of for loop i.e. i=0
- ctx.evaluateAssignment(parameters.get(0));
-
- // security count to exit loop even if we fuck up exit condition
- int count = 0;
- // condition loop evaluate the condition i.e. i < 10
- while (ctx.evaluateExpression(parameters.get(1)) != 0 && count < 100) {
- result.addAll(ParsedTree.evaluate(ctx, children));
- // "increment" evaluate 3rd for parameter i.e. i=i+1
- ctx.evaluateAssignment(parameters.get(2));
- count++;
- }
- return result;
- }
-
-}
\ No newline at end of file
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/InsetObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/InsetObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/InsetObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,202 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import artofillusion.math.CoordinateSystem;
-import artofillusion.math.Vec2;
-import artofillusion.math.Vec3;
-import artofillusion.object.Curve;
-import artofillusion.object.Mesh;
-import artofillusion.object.Object3D;
-import artofillusion.object.ObjectInfo;
-
-public class InsetObj extends MetaCADObject
-{
-
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- double inset = 1.0;
- if (parameters.size() > 0) {
- inset = ctx.evaluateExpression(parameters.get(0));
- }
-
- List<ObjectInfo> result = new LinkedList<ObjectInfo>();
-
- Iterator<ObjectInfo> iter = ParsedTree.evaluate(ctx, children).iterator();
-
- while (iter.hasNext()) {
- ObjectInfo chinfo = iter.next();
- Object3D obj3D = chinfo.object;
- if (obj3D instanceof Curve) {
- Curve curve = (Curve)obj3D;
- Vec3[] newvec = insetPoly(curve.getVertexPositions(), inset);
- obj3D = PolygonObj.createPolygon(newvec);
- result.add(new ObjectInfo(obj3D, new CoordinateSystem(), "dummy"));
- }
- }
- return result;
- }
-
- Vec3[] createRoll(int n, double big, double small, double small2) {
- Vec3[] v;
- v = new Vec3[n];
- int index = 0;
- for (int i = 0; i < n; i++)
- {
- double biga=(2*Math.PI*i)/n;
- double len = big*biga;
- double smalla=len/small;
- double x,y;
-
- x = (big+small)*Math.cos(biga) + (small2)*Math.cos(smalla);
- y = (big+small)*Math.sin(biga) + (small2)*Math.sin(smalla);
-
- v[index] = new Vec3(x, y, 0 );
-
- index++;
- }
- return v;
- }
-
- Vec3[] createRegular(int n, double radiusx, double radiusy) {
- Vec3[] v;
- v = new Vec3[n];
- int index = 0;
- for (int i = 0; i < n; i++)
- {
- v[index] = new Vec3( radiusx*Math.cos( 2*Math.PI * index / (double) n ),
- radiusy*Math.sin(2*Math.PI * index / (double) n ), 0 );
- index++;
- }
- return v;
- }
-
- Vec3[] createStar(int n, double inner, double outer) {
- Vec3[] v;
- v = new Vec3[2*n];
- int index = 0;
- for (int i = 0; i < n; i++) {
- v[index] = new Vec3(Math.cos(Math.PI * index / (double) n),
- Math.sin(Math.PI * index / (double) n), 0);
- v[index].scale(inner);
- v[index+1] = new Vec3(Math.cos(Math.PI * (index + 1) / (double) n),
- Math.sin(Math.PI * (index + 1) / (double) n), 0);
- v[index+1].scale(outer);
- index += 2;
- }
- return v;
- }
-
- Object3D createPolygon(Vec3[] v) {
- Object3D obj3D;
- float smoothness[] = new float[v.length];
- Arrays.fill(smoothness, 0.0f);
- obj3D = new Curve(v, smoothness, Mesh.NO_SMOOTHING, true).convertToTriangleMesh(0);
- return obj3D;
- }
-
-///////////////////////////////////////////
-//math helpers
-
- // solves system of 2 linear equations in 2 unknown
- class LinearSolve2
- {
- public boolean error;
- public double x1, x2;
-
- // matrix looks like this
- // a b
- // c d
- public double det(double a,double b, double c, double d)
- {
- return a*d-b*c;
- }
- // the equations look like thsi looks like this
- // x1*a + x2*b = r1
- // x1*c + x2*d = r2
- public LinearSolve2(double a,double b, double c, double d, double r1, double r2)
- {
- double q;
-
- q=det(a,b,c,d);
- if (Math.abs(q) < 0.00000001)
- {
- this.error = true;
- }
- else
- {
- this.error = false;
- this.x1=det(r1,b,r2,d)/q;
- this.x2=det(a,r1,c,r2)/q;
- }
- }
- }
-
- class MetaCADLine {
- protected Vec2 start,end, dir;
- protected Vec2 normal;
-
- public MetaCADLine(Vec3 s,Vec3 e)
- {
- this.start = new Vec2(s.x,s.y);
- this.end = new Vec2(e.x, e.y);
- this.dir = this.end.minus(this.start);
- this.normal = new Vec2(this.dir);
- this.normal.normalize();
- this.normal.set(-this.normal.y, this.normal.x);
- }
-
- public void parallelMove(double d)
- {
- this.start.add(this.normal.times(d));
- }
-
- public Vec3 intersect3(MetaCADLine l)
- {
- LinearSolve2 solve = new LinearSolve2(l.dir.x, -this.dir.x, l.dir.y, -this.dir.y, this.start.x-l.start.x, this.start.y-l.start.y);
- if (solve.error)
- {
- return null;
- }
- else
- {
- Vec2 point = this.start.plus(this.dir.times(solve.x2));
- return new Vec3(point.x,point.y, 0);
- }
- }
- }
-
- Vec3[] insetPoly(Vec3[] poly, double inset)
- {
- //List<MetaCADLine> lines = new ArrayList<MetaCADLine>();
- List<Vec3> points = new ArrayList<Vec3>();
-
- for (int i = 0; i < poly.length; i++)
- {
- int iprev = (i+poly.length-1)%poly.length;
- int inext = (i+1)%poly.length;
-
- MetaCADLine prev = new MetaCADLine(poly[iprev], poly[i]);
- MetaCADLine next = new MetaCADLine(poly[i], poly[inext]);
-
- prev.parallelMove(inset);
- next.parallelMove(inset);
-
- Vec3 intersect=prev.intersect3(next);
- if (intersect == null)
- {
- intersect = new Vec3(0,0,0);
- }
- points.add(intersect);
- }
-
- return points.toArray(new Vec3[1]);
- }
-
-}
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/JoinCurvesObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/JoinCurvesObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/JoinCurvesObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,158 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import artofillusion.math.CoordinateSystem;
-import artofillusion.math.Mat4;
-import artofillusion.math.Vec3;
-import artofillusion.object.Curve;
-import artofillusion.object.MeshVertex;
-import artofillusion.object.ObjectInfo;
-
-public class JoinCurvesObj extends MetaCADObject
-{
-
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- List<ObjectInfo> result = new LinkedList<ObjectInfo>();
-
- List<ObjectInfo> ch = ParsedTree.evaluate(ctx, children);
-
- // FIXME: Check that # children >= 2
- // FIXME: Check that all children are curves
-
- Vec3[][] ends = new Vec3[ch.size()][2];
-
- float tol = 0.1f;
- int smoothtype = 0;
- float smoothness = 1.0f;
- Boolean joinends = true;
-
- // get total number of curve points and start/end vertices of each curve
- int num = 0;
- int idx = 0;
- ObjectInfo[] curves = new ObjectInfo[ch.size()];
- curves = ch.toArray(curves);
- for (idx=0;idx<curves.length;idx++) {
- Mat4 mat = curves[idx].coords.fromLocal();
- MeshVertex[] verts = ((Curve)curves[idx].object).getVertices();
- num = num + verts.length;
- ends[idx][0] = mat.times(verts[0].r);
- ends[idx][1] = mat.times(verts[verts.length-1].r);
- }
-
- int end0found = 0;
- int end1found = 0;
- int i;
- // find ends
- for (i=0;i<curves.length;i++) {
- end0found = 0;
- end1found = 0;
- for (int j=0;j<curves.length;j++) {
- if (j == i) continue;
- for (int k=0;k<2;k++) {
- if (ends[i][0].distance(ends[j][k]) < tol) end0found = 1;
- if (ends[i][1].distance(ends[j][k]) < tol) end1found = 1;
- }
- }
- if (end0found + end1found < 2) break;
- }
- if (end0found + end1found == 0) {
- // FIXME: Throw exception
-// new MessageDialog(window, "One or more of the curves are not within selected Proximity - either increase Proximity or move curves");
- return result;
- }
-
- //
- Boolean loop;
- int firstCurve;
- if (i == curves.length) {
- loop = true;
- firstCurve = 0; // if no ends found, then must be a loop so choose any starting curve
- }
- else {
- loop = false;
- firstCurve = i; // otherwise curve i is at one end
- }
-
- // assemble the joined curve
- int[] curvesUsed = new int[curves.length];
- int curvesUsedIdx = 0;
- curvesUsed[curvesUsedIdx] = firstCurve;
- curvesUsedIdx++;
- Vec3[] curvePoints;
- int numCurvePoints = num - curves.length;
- if (!loop) numCurvePoints++;
- curvePoints = new Vec3[numCurvePoints];
-
- // add first curve
- int counter = 0;
- Mat4 mat = curves[firstCurve].coords.fromLocal();
- MeshVertex[] verts = ((Curve)curves[firstCurve].object).getVertices();
- if (end1found == 1) {
- for (int v=0;v<verts.length;v++) {
- curvePoints[v+counter]=mat.times(verts[v].r); // update position in world space
- }
- }
- if (end0found == 1) { // reverse order of vertices so curve starts at end
- for (int v=0;v<verts.length;v++) {
- curvePoints[verts.length-1-v+counter]=mat.times(verts[v].r); // update position in world space
- }
- }
- counter = counter + verts.length;
- if (joinends) counter--;
-
- // assembly joined curve
- while (curvesUsedIdx < curves.length) {
- int c;
- for (c=0;c<curves.length;c++) { //cycle through the selected curves
- if (c == curvesUsed[curvesUsedIdx-1]) continue; // skip if the same curve
- int pointToCheck;
- if (joinends) pointToCheck = counter;
- else pointToCheck = counter - 1;
- //
- if (curvePoints[pointToCheck].distance(ends[c][0])<tol) { // if start of curve c is close to end
- mat= curves[c].coords.fromLocal();
- verts = ((Curve)curves[c].object).getVertices();
- for (int v=0;v<verts.length;v++) {
- curvePoints[v+counter]=mat.times(verts[v].r);
- }
- curvesUsed[curvesUsedIdx]=c; // add curve to list of those used
- curvesUsedIdx++; //update number of curves used
- counter=counter+verts.length;
- if (joinends) counter--;
- break;
- }
- if (curvePoints[pointToCheck].distance(ends[c][1])<tol) { // if end of curve c is close to end
- mat = curves[c].coords.fromLocal();
- verts = ((Curve)curves[c].object).getVertices();
- for (int v=0;v<verts.length;v++) {
- curvePoints[verts.length-1-v+counter]=mat.times(verts[v].r);
- }
- curvesUsed[curvesUsedIdx]=c; // add curve to list of those used
- curvesUsedIdx++; //update number of curves used
- counter=counter+verts.length;
- if (joinends) counter--;
- break;
- }
- }
- if (c == curves.length) {
- // FIXME: Throw exception
-// new MessageDialog(window, "One or more of the curves are not within selected Proximity - either increase Proximity or move curves");
- return result;
- }
- }
-// create new curve
- float[] smooth = new float[num];
- for (i=0;i<num;i++) {
- smooth[i]=smoothness;
- }
-
- Curve curve = new Curve(curvePoints, smooth, smoothtype, joinends || loop);
- result.add(new ObjectInfo(curve, new CoordinateSystem(), "dummy"));
- return result;
- }
-}
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/LatheObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/LatheObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/LatheObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,78 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import artofillusion.math.CoordinateSystem;
-import artofillusion.math.Vec3;
-import artofillusion.object.CSGObject;
-import artofillusion.object.Curve;
-import artofillusion.object.Mesh;
-import artofillusion.object.Object3D;
-import artofillusion.object.ObjectInfo;
-import artofillusion.object.TriangleMesh;
-import artofillusion.tools.ExtrudeTool;
-import artofillusion.tools.LatheTool;
-
-public class LatheObj extends MetaCADObject
-{
-
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- List<ObjectInfo> result = new LinkedList<ObjectInfo>();
-
- // First parameter define the lathe axis (X, Y or Z)
- int axis = LatheTool.X_AXIS;
- if (parameters.size() >= 1) {
- String dir = parameters.get(0);
- if (dir.equals("Y")) axis = LatheTool.Y_AXIS;
- else if (dir.equals("Z")) axis = LatheTool.Z_AXIS;
- }
-
- // 2. parameter is sweep angle
- double sweepang = 360;
- if (parameters.size() >= 2) {
- sweepang = ctx.evaluateExpression(parameters.get(1));
- }
-
- // 3. parameter is radius
- double radius = 0.0;
- if (parameters.size() >= 3) {
- radius = ctx.evaluateExpression(parameters.get(2));
- }
-
- result.addAll(lathe(ParsedTree.evaluate(ctx, children), axis, sweepang, radius));
- return result;
- }
-
- /**
- *
- * Lathes the given profiles using the given parameters and returns the result object.
- *
- */
- public List<ObjectInfo> lathe(List<ObjectInfo> objects, int axis, double sweepang, double radius)
- {
- // Lathe each lathable child object
- List<ObjectInfo> resultobjects = new LinkedList<ObjectInfo>();
- Iterator<ObjectInfo> iter = objects.iterator();
- while (iter.hasNext()) {
- ObjectInfo profile = iter.next();
- Object3D profileobj = profile.getObject();
- Object3D obj3D = null;
- if (profileobj instanceof Curve) {
- Mesh mesh = LatheTool.latheCurve((Curve)profileobj, axis, 16, sweepang, radius);
- if (mesh instanceof Object3D) obj3D = (Object3D)mesh;
- }
- if (obj3D != null) {
- ObjectInfo objinfo = new ObjectInfo(obj3D, new CoordinateSystem(), "tmp");
- resultobjects.add(objinfo);
- }
- profile.setVisible(false);
- }
- // FIXME: Undo support?
- return resultobjects;
- }
-}
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MacroObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MacroObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MacroObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,54 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.cheffo.jeplite.ASTVarNode;
-import org.reprap.artofillusion.language.MacroPrototype;
-
-import artofillusion.object.ObjectInfo;
-
-public class MacroObj extends MetaCADObject {
- protected MacroPrototype prototype;
-
- public MacroObj(MacroPrototype prototype)
- {
- this.prototype = prototype;
- }
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- if (parameters.size() >= prototype.variables.size())
- {
- int n = prototype.variables.size();
- ASTVarNode[] backup = new ASTVarNode[n];
- double[] values = new double[n];
- // backup variables
- for (int i = 0; i < n; i++)
- {
- backup[i] = ctx.jep.getVarNode(prototype.variables.get(i));
- values[i] = ctx.evaluateExpression(parameters.get(i));
- }
- // replace variables
- for (int i = 0; i < n; i++)
- {
- ctx.jep.setVarNode(prototype.variables.get(i), null);
- ctx.jep.addVariable(prototype.variables.get(i), values[i]);
- }
- // evaluate
- List<ObjectInfo> result = ParsedTree.evaluate(ctx, prototype.children);
- // restore previous variables
- for (int i = 0; i < n; i++)
- {
- ctx.jep.setVarNode(prototype.variables.get(i), backup[i]);
- }
- return result;
- }
- else
- {
- throw new Exception("Not enough parameters given to Macro Call: " + prototype.name);
- }
- }
-
-}
\ No newline at end of file
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MeshObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MeshObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MeshObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,40 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import artofillusion.object.Curve;
-import artofillusion.object.Object3D;
-import artofillusion.object.ObjectInfo;
-import artofillusion.object.TriangleMesh;
-
-public class MeshObj extends MetaCADObject
-{
-
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- double tolerance = 0.2;
- if (parameters.size() > 0) {
- tolerance = ctx.evaluateExpression(parameters.get(0));
- }
-
- List<ObjectInfo> results = new LinkedList<ObjectInfo>();
-
- Iterator<ObjectInfo> iter = ParsedTree.evaluate(ctx, children).iterator();
- while(iter.hasNext()) {
- ObjectInfo chinfo = iter.next();
- Object3D obj3D = chinfo.getObject();
- if (obj3D instanceof Curve) {
- assert(obj3D.canConvertToTriangleMesh() != Object3D.CANT_CONVERT);
- TriangleMesh mesh = obj3D.convertToTriangleMesh(tolerance);
- ObjectInfo newinfo = new ObjectInfo(mesh, chinfo.getCoords(), "dummy");
- newinfo.setTexture(ctx.scene.getDefaultTexture(), ctx.scene.getDefaultTexture().getDefaultMapping(mesh));
- results.add(newinfo);
- }
- }
- return results;
- }
-}
Modified: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADContext.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADContext.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADContext.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -21,7 +21,7 @@
// Evaluates an Expression like 3*x+sin(a) and returns the value of it or 0 if
// any error occurred
- double evaluateExpression(String expr) throws Exception {
+ public double evaluateExpression(String expr) throws Exception {
try {
this.jep.parseExpression(expr);
return this.jep.getValue();
@@ -34,7 +34,7 @@
// Evaluates Expressions like x=2*radius and assigns the value to the given
// variable
- void evaluateAssignment(String curLine) throws Exception {
+ public void evaluateAssignment(String curLine) throws Exception {
try {
int mark = curLine.indexOf("=");
String name = curLine.substring(0, mark).trim();
Modified: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADEvaluatorDialog.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADEvaluatorDialog.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADEvaluatorDialog.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -87,16 +87,16 @@
}
// Parameters tab
- paramtab=new BTextArea(this.engine.getParameters(), 10, 20) {
+ this.paramtab=new BTextArea(this.engine.getParameters(), 10, 20) {
@Override
protected void textChanged() {
super.textChanged();
MetaCADEvaluatorDialog.this.engine.setParameters(this.getText());
}
};
- engine.addParameterChangedListener(this);
+ this.engine.addParameterChangedListener(this);
- BScrollPane scrollpane = new BScrollPane(paramtab);
+ BScrollPane scrollpane = new BScrollPane(this.paramtab);
tabcontainer.add(scrollpane, "Parameters");
// CAD tab
@@ -161,14 +161,14 @@
}
public void textChanged(Object source) {
- final String newText = engine.getParameters();
- if (!newText.equals(paramtab.getText()))
+ final String newText = this.engine.getParameters();
+ if (!newText.equals(this.paramtab.getText()))
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
- paramtab.setText(newText);
+ MetaCADEvaluatorDialog.this.paramtab.setText(newText);
}
});
Modified: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADEvaluatorEngine.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADEvaluatorEngine.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADEvaluatorEngine.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -88,7 +88,7 @@
public void setParameters(String text) {
this.window.getScene().setMetadata(
MetaCADEvaluatorEngine.class.getName() + "Parameters", text);
- Iterator<TextChangedListener> iter = parameterListeners.iterator();
+ Iterator<TextChangedListener> iter = this.parameterListeners.iterator();
while (iter.hasNext())
{
@@ -585,7 +585,6 @@
ObjectInfo resultinfo;
try {
- Scene theScene = this.window.getScene();
resultinfo = new ObjectInfo(new Sphere(1,1,1), new CoordinateSystem(), defstr);
// Inherit texture color from the first source object
@@ -789,6 +788,6 @@
protected List<TextChangedListener> parameterListeners=new LinkedList<TextChangedListener>();
public void addParameterChangedListener(TextChangedListener listener)
{
- parameterListeners.add(listener);
+ this.parameterListeners.add(listener);
}
}
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADObject.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADObject.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADObject.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,13 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.List;
-
-import artofillusion.object.ObjectInfo;
-
-public abstract class MetaCADObject {
-
- public abstract List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception;
-
-}
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/NativeObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/NativeObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/NativeObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,17 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.List;
-
-import artofillusion.object.ObjectInfo;
-
-
-public class NativeObj extends MetaCADObject {
-
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- return null;
- }
-
-}
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjFactory.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjFactory.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjFactory.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,72 +0,0 @@
-package org.reprap.artofillusion;
-
-import org.reprap.artofillusion.language.MacroPrototype;
-
-import artofillusion.object.CSGObject;
-
-public class ObjFactory {
- public static MetaCADObject create(MetaCADContext ctx, String name) throws ObjFactoryException {
- name = name.toLowerCase();
-
- if (name.equals("native")) {
- return new NativeObj();
- }
- else if (name.startsWith("sphere")) {
- return new SphereObj();
- }
- else if (name.startsWith("cube")) {
- return new CubeObj();
- }
- else if (name.startsWith("cylinder")) {
- return new CylinderObj();
- }
- else if (name.startsWith("cs")) {
- return new CSObj();
- }
- else if (name.startsWith("union") || name.startsWith("+")) {
- return new BooleanObj(CSGObject.UNION);
- }
- else if (name.startsWith("difference") || name.startsWith("-")) {
- return new BooleanObj(CSGObject.DIFFERENCE12);
- }
- else if (name.startsWith("intersection") || name.startsWith("/")) {
- return new BooleanObj(CSGObject.INTERSECTION);
- }
- else if (name.startsWith("star")) {
- return new PolygonObj(PolygonObj.STAR);
- }
- else if (name.startsWith("reg")) {
- return new PolygonObj(PolygonObj.REG);
- }
- else if (name.startsWith("roll")) {
- return new PolygonObj(PolygonObj.ROLL);
- }
- else if (name.startsWith("extrude")) {
- return new ExtrudeObj();
- }
- else if (name.startsWith("for")) {
- return new ForObj();
- }
- else if (name.startsWith("inset")) {
- return new InsetObj();
- }
- else if (name.startsWith("mesh")) {
- return new MeshObj();
- }
- else if (name.startsWith("joincurves")) {
- return new JoinCurvesObj();
- }
- else if (name.startsWith("lathe")) {
- return new LatheObj();
- }
- else {
- MacroPrototype macroPrototype = ctx.macros.get(name.toLowerCase());
- if (macroPrototype != null)
- {
- return new MacroObj(macroPrototype);
- }
- }
-
- throw new ObjFactoryException("ObjFactory: Unknown Object type: " + name);
- }
-}
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjFactoryException.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjFactoryException.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjFactoryException.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,12 +0,0 @@
-package org.reprap.artofillusion;
-
-import org.reprap.artofillusion.parser.ParseException;
-
-public class ObjFactoryException extends ParseException {
-
- private static final long serialVersionUID = -5731809677962819119L;
-
- public ObjFactoryException(String message) {
- super(message);
- }
-}
Modified: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjectHelper.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjectHelper.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjectHelper.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,16 +1,12 @@
package org.reprap.artofillusion;
-import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import artofillusion.MeshViewer;
import artofillusion.math.CoordinateSystem;
import artofillusion.math.Mat4;
import artofillusion.math.Vec3;
import artofillusion.object.Cube;
import artofillusion.object.MeshVertex;
-import artofillusion.object.Object3D;
import artofillusion.object.ObjectInfo;
import artofillusion.object.TriangleMesh;
import artofillusion.object.TriangleMesh.Edge;
Modified: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ParsedTree.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ParsedTree.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ParsedTree.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -5,6 +5,10 @@
import java.util.LinkedList;
import java.util.List;
+import org.reprap.artofillusion.objects.MetaCADObject;
+import org.reprap.artofillusion.objects.ObjFactory;
+import org.reprap.artofillusion.objects.ObjFactoryException;
+
import artofillusion.object.ObjectInfo;
import artofillusion.texture.Texture;
import artofillusion.texture.TextureMapping;
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/PolygonObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/PolygonObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/PolygonObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,153 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-
-import artofillusion.math.CoordinateSystem;
-import artofillusion.math.Vec3;
-import artofillusion.object.Curve;
-import artofillusion.object.Mesh;
-import artofillusion.object.Object3D;
-import artofillusion.object.ObjectInfo;
-
-public class PolygonObj extends MetaCADObject
-{
- public static final int STAR = 0;
- public static final int REG = 1;
- public static final int ROLL = 2;
- int type;
-
- public PolygonObj(int type) {
- this.type = type;
- }
-
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- List<ObjectInfo> result = new LinkedList<ObjectInfo>();
-
- Vec3[] v=null;
- switch (this.type) {
- case STAR: {
- int n = 6;
- double inner = 3;
- double outer = 5;
- if (parameters.size() >= 1) {
- n = (int)ctx.evaluateExpression(parameters.get(0));
- }
- if (parameters.size() >= 3) {
- inner = ctx.evaluateExpression(parameters.get(1));
- outer = ctx.evaluateExpression(parameters.get(2));
- }
-
- v = createStar(n, inner, outer);
- break;
- }
- case REG: {
- int n = 6;
- double radiusx = 4;
- double radiusy = 4;
- if (parameters.size() >= 1) {
- n = (int)ctx.evaluateExpression(parameters.get(0));
- }
- if (parameters.size() >= 2) {
- radiusy = radiusx = ctx.evaluateExpression(parameters.get(1));
- }
- if (parameters.size() >= 3) {
- radiusy = ctx.evaluateExpression(parameters.get(2));
- }
-
- v = createRegular(n, radiusx, radiusy);
- break;
- }
- case ROLL: {
- int n = 30;
- double big = 5;
- double small = 1;
- double small2 = 0.8;
- if (parameters.size() >= 1) {
- n = (int)ctx.evaluateExpression(parameters.get(0));
- }
- if (parameters.size() >= 3) {
- big = ctx.evaluateExpression(parameters.get(1));
- small2 = small = ctx.evaluateExpression(parameters.get(2));
- }
- if (parameters.size() == 4) {
- small2 = ctx.evaluateExpression(parameters.get(3));
- }
-
- v = createRoll(n, big, small, small2);
- break;
- }
- }
-
- if (v != null) {
- Object3D obj3D = createPolygon(v);
- result.add(new ObjectInfo(obj3D, new CoordinateSystem(), "dummy"));
- return result;
- }
- return null;
- }
-
- Vec3[] createRoll(int n, double big, double small, double small2) {
- Vec3[] v;
- v = new Vec3[n];
- int index = 0;
- for (int i = 0; i < n; i++)
- {
- double biga=(2*Math.PI*i)/n;
- double len = big*biga;
- double smalla=len/small;
- double x,y;
-
- x = (big+small)*Math.cos(biga) + (small2)*Math.cos(smalla);
- y = (big+small)*Math.sin(biga) + (small2)*Math.sin(smalla);
-
- v[index] = new Vec3(x, y, 0 );
-
- index++;
- }
- return v;
- }
-
- Vec3[] createRegular(int n, double radiusx, double radiusy) {
- Vec3[] v;
- v = new Vec3[n];
- int index = 0;
- for (int i = 0; i < n; i++)
- {
- v[index] = new Vec3( radiusx*Math.cos( 2*Math.PI * index / (double) n ),
- radiusy*Math.sin(2*Math.PI * index / (double) n ), 0 );
- index++;
- }
- return v;
- }
-
- Vec3[] createStar(int n, double inner, double outer) {
- Vec3[] v;
- v = new Vec3[2*n];
- int index = 0;
- for (int i = 0; i < n; i++) {
- v[index] = new Vec3(Math.cos(Math.PI * index / (double) n),
- Math.sin(Math.PI * index / (double) n), 0);
- v[index].scale(inner);
- v[index+1] = new Vec3(Math.cos(Math.PI * (index + 1) / (double) n),
- Math.sin(Math.PI * (index + 1) / (double) n), 0);
- v[index+1].scale(outer);
- index += 2;
- }
- return v;
- }
-
- static public Object3D createPolygon(Vec3[] v) {
- Object3D obj3D;
- float smoothness[] = new float[v.length];
- Arrays.fill(smoothness, 0.0f);
- obj3D = new Curve(v, smoothness, Mesh.NO_SMOOTHING, true);
- return obj3D;
- }
-
-
-}
Deleted: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/SphereObj.java
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/SphereObj.java 2009-05-10 02:42:08 UTC (rev 2938)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/SphereObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -1,35 +0,0 @@
-package org.reprap.artofillusion;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import artofillusion.math.CoordinateSystem;
-import artofillusion.math.Vec3;
-import artofillusion.object.Object3D;
-import artofillusion.object.ObjectInfo;
-
-public class SphereObj extends MetaCADObject {
-
- public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
- List<String> parameters,
- List<ParsedTree> children) throws Exception {
-
- List<ObjectInfo> result = new LinkedList<ObjectInfo>();
-
- double mainparam = 1.0f;
- if (parameters.size() >= 1) {
- mainparam = ctx.evaluateExpression(parameters.get(0));
- }
- Vec3 dims = new Vec3(mainparam, mainparam, mainparam);
- if (parameters.size() >= 3) {
- dims.set(mainparam,
- ctx.evaluateExpression(parameters.get(1)),
- ctx.evaluateExpression(parameters.get(2)));
- }
- Object3D obj3D = new artofillusion.object.Sphere(dims.x, dims.y, dims.z);
-
- result.add(new ObjectInfo(obj3D, new CoordinateSystem(), "dummy"));
-
- return result;
- }
-}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/BooleanObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/BooleanObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/BooleanObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/BooleanObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,35 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.reprap.artofillusion.CSGHelper;
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.object.ObjectInfo;
+
+
+public class BooleanObj extends MetaCADObject {
+ int type;
+
+ public BooleanObj(int type) {
+ this.type = type;
+ }
+
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ List<ObjectInfo> result = new LinkedList<ObjectInfo>();
+
+ CSGHelper helper = new CSGHelper(this.type);
+ helper.addAll(ParsedTree.evaluate(ctx, children).iterator());
+
+ if (helper.GetObjectInfo() != null)
+ result.add(helper.GetObjectInfo());
+ return result;
+
+ }
+
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/CSObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CSObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/CSObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/CSObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,42 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.math.CoordinateSystem;
+import artofillusion.math.Vec3;
+import artofillusion.object.ObjectInfo;
+
+public class CSObj extends MetaCADObject {
+
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ assert(children.size() == 1);
+ List<ObjectInfo> chlist = ParsedTree.evaluate(ctx, children);
+
+ CoordinateSystem coordsys = new CoordinateSystem();
+ if (parameters.size() >= 3) {
+ coordsys.setOrigin(new Vec3(ctx.evaluateExpression(parameters.get(0)),
+ ctx.evaluateExpression(parameters.get(1)),
+ ctx.evaluateExpression(parameters.get(2))));
+ }
+ if (parameters.size() >= 6) {
+ coordsys.setOrientation(ctx.evaluateExpression(parameters.get(3)),
+ ctx.evaluateExpression(parameters.get(4)),
+ ctx.evaluateExpression(parameters.get(5)));
+ }
+
+ Iterator<ObjectInfo> iter = chlist.iterator();
+ while (iter.hasNext()) {
+ ObjectInfo info = iter.next();
+ info.coords.transformCoordinates(coordsys.fromLocal());
+ }
+ return chlist;
+ }
+
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/CubeObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CubeObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/CubeObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/CubeObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,38 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.math.CoordinateSystem;
+import artofillusion.math.Vec3;
+import artofillusion.object.Cube;
+import artofillusion.object.Object3D;
+import artofillusion.object.ObjectInfo;
+
+public class CubeObj extends MetaCADObject {
+
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ List<ObjectInfo> result = new LinkedList<ObjectInfo>();
+
+ double mainparam = 1.0f;
+ if (parameters.size() >= 1) {
+ mainparam = ctx.evaluateExpression(parameters.get(0));
+ }
+ Vec3 dims = new Vec3(mainparam, mainparam, mainparam);
+ if (parameters.size() >= 3) {
+ dims.set(mainparam,
+ ctx.evaluateExpression(parameters.get(1)),
+ ctx.evaluateExpression(parameters.get(2)));
+ }
+ Object3D obj3D = new artofillusion.object.Sphere(dims.x, dims.y, dims.z);
+ obj3D = new Cube(dims.x, dims.y, dims.z);
+ result.add(new ObjectInfo(obj3D, new CoordinateSystem(), "dummy"));
+ return result;
+ }
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/CylinderObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/CylinderObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/CylinderObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/CylinderObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,47 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.math.CoordinateSystem;
+import artofillusion.object.Cylinder;
+import artofillusion.object.Object3D;
+import artofillusion.object.ObjectInfo;
+
+public class CylinderObj extends MetaCADObject {
+
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ List<ObjectInfo> result = new LinkedList<ObjectInfo>();
+
+ double mainparam = 1.0f;
+ if (parameters.size() >= 1) {
+ mainparam = ctx.evaluateExpression(parameters.get(0));
+ }
+ // First (main) parameter is height
+ double height = mainparam;
+ double rx = mainparam;
+ double ry = mainparam;
+ double ratio = 1;
+
+ // Second parameter is radius
+ if (parameters.size() >= 2) rx = ry = ctx.evaluateExpression(parameters.get(1));
+ // Third parameter define separate y radius
+ if (parameters.size() >= 3) ry = ctx.evaluateExpression(parameters.get(2));
+ // Fourth parameter define top/bottom radius ratio
+ // Cylinder takes an optional fourth parameter
+ if (parameters.size() >= 4) {
+ ratio = ctx.evaluateExpression(parameters.get(3));
+ if (ratio > 1) ratio = 1.0;
+ if (ratio < 0) ratio = 0.0;
+ }
+ Object3D obj3D = new Cylinder(height, rx, ry, ratio);
+ result.add(new ObjectInfo(obj3D, new CoordinateSystem(), "dummy"));
+ return result;
+ }
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ExtrudeObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ExtrudeObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ExtrudeObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ExtrudeObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,112 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.math.CoordinateSystem;
+import artofillusion.math.Vec3;
+import artofillusion.object.Curve;
+import artofillusion.object.Mesh;
+import artofillusion.object.Object3D;
+import artofillusion.object.ObjectInfo;
+import artofillusion.object.TriangleMesh;
+import artofillusion.tools.ExtrudeTool;
+
+public class ExtrudeObj extends MetaCADObject
+{
+
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ List<ObjectInfo> result = new LinkedList<ObjectInfo>();
+
+ // Three first parameters define the extrusion vector
+ Vec3 dir = Vec3.vz();
+ if (parameters.size() >= 3) {
+ dir = new Vec3(ctx.evaluateExpression(parameters.get(0)),
+ ctx.evaluateExpression(parameters.get(1)),
+ ctx.evaluateExpression(parameters.get(2)));
+ }
+ // 4. parameter is num segments
+ int numsegments = 1;
+ if (parameters.size() >= 4) {
+ numsegments = (int)ctx.evaluateExpression(parameters.get(3));
+ if (numsegments < 2) numsegments = 1;
+ }
+ // 5. parameter is twist degrees
+ double twist = 0.0;
+ if (parameters.size() >= 5) {
+ twist = ctx.evaluateExpression(parameters.get(4));
+ }
+
+ result.addAll(extrude(ParsedTree.evaluate(ctx, children), dir, numsegments, twist));
+ return result;
+ }
+
+ /**
+ *
+ * Extrudes the given profiles using the given parameters and returns the result object.
+ *
+ * @param objects
+ * @param dir
+ * @param numsegments
+ * @param twist
+ * @return a list of ObjectInfos. The coordsys in the object infos are just there to move
+ * the objects back to their original positions since the extrusion operation always
+ * centers the result in the origin.
+ */
+ public List<ObjectInfo> extrude(List<ObjectInfo> objects, Vec3 dir, int numsegments, double twist)
+ {
+ // Build extrusion curve from vector and segments
+ Vec3 v[] = new Vec3[numsegments+1];
+ float smooth[] = new float[v.length];
+ for (int i = 0; i < v.length; i++) {
+ v[i] = new Vec3(dir);
+ v[i].scale(1.0*i/numsegments);
+ smooth[i] = 1.0f;
+ }
+ Curve path = new Curve(v, smooth, Mesh.APPROXIMATING, false);
+ CoordinateSystem pathCS = new CoordinateSystem();
+
+ // FIXME: Support specifying extrusion curves
+ // Extrude each extrudable child object
+ List<ObjectInfo> resultobjects = new LinkedList<ObjectInfo>();
+ Iterator<ObjectInfo> iter = objects.iterator();
+ while (iter.hasNext()) {
+ ObjectInfo profile = iter.next();
+ Object3D profileobj = profile.getObject();
+
+ Object3D obj3D = null;
+ if (profileobj instanceof TriangleMesh) {
+ obj3D = ExtrudeTool.extrudeMesh((TriangleMesh)profileobj, path, profile.getCoords(), pathCS, twist*Math.PI/180.0, true);
+ }
+ else if (profileobj instanceof Curve) {
+ obj3D = ExtrudeTool.extrudeCurve((Curve)profileobj, path, profile.getCoords(), pathCS, twist*Math.PI/180.0, true);
+ }
+ if (obj3D != null) {
+ // Since the result is centered in the origin, offset the extruded object to
+ // move it back to its original position
+ // FIXME: Combine this with the user-specified coordinate system
+ CoordinateSystem coordsys = new CoordinateSystem(new Vec3(), Vec3.vz(), Vec3.vy());
+ Vec3 offset = profile.getCoords().fromLocal().times(((Mesh)profileobj).getVertices()[0].r).
+ minus(coordsys.fromLocal().times(((Mesh)obj3D).getVertices()[0].r));
+ coordsys.setOrigin(offset);
+ ObjectInfo objinfo = new ObjectInfo(obj3D, coordsys, "tmp");
+ resultobjects.add(objinfo);
+ }
+ profile.setVisible(false);
+ }
+ // FIXME: Undo support?
+ return resultobjects;
+}
+
+
+
+
+
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ForObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ForObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ForObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ForObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,34 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.object.ObjectInfo;
+
+public class ForObj extends MetaCADObject {
+
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ List<ObjectInfo> result = new LinkedList<ObjectInfo>();
+
+ // evaluate first part of for loop i.e. i=0
+ ctx.evaluateAssignment(parameters.get(0));
+
+ // security count to exit loop even if we fuck up exit condition
+ int count = 0;
+ // condition loop evaluate the condition i.e. i < 10
+ while (ctx.evaluateExpression(parameters.get(1)) != 0 && count < 100) {
+ result.addAll(ParsedTree.evaluate(ctx, children));
+ // "increment" evaluate 3rd for parameter i.e. i=i+1
+ ctx.evaluateAssignment(parameters.get(2));
+ count++;
+ }
+ return result;
+ }
+
+}
\ No newline at end of file
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/InsetObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/InsetObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/InsetObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/InsetObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,205 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.math.CoordinateSystem;
+import artofillusion.math.Vec2;
+import artofillusion.math.Vec3;
+import artofillusion.object.Curve;
+import artofillusion.object.Mesh;
+import artofillusion.object.Object3D;
+import artofillusion.object.ObjectInfo;
+
+public class InsetObj extends MetaCADObject
+{
+
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ double inset = 1.0;
+ if (parameters.size() > 0) {
+ inset = ctx.evaluateExpression(parameters.get(0));
+ }
+
+ List<ObjectInfo> result = new LinkedList<ObjectInfo>();
+
+ Iterator<ObjectInfo> iter = ParsedTree.evaluate(ctx, children).iterator();
+
+ while (iter.hasNext()) {
+ ObjectInfo chinfo = iter.next();
+ Object3D obj3D = chinfo.object;
+ if (obj3D instanceof Curve) {
+ Curve curve = (Curve)obj3D;
+ Vec3[] newvec = insetPoly(curve.getVertexPositions(), inset);
+ obj3D = PolygonObj.createPolygon(newvec);
+ result.add(new ObjectInfo(obj3D, new CoordinateSystem(), "dummy"));
+ }
+ }
+ return result;
+ }
+
+ Vec3[] createRoll(int n, double big, double small, double small2) {
+ Vec3[] v;
+ v = new Vec3[n];
+ int index = 0;
+ for (int i = 0; i < n; i++)
+ {
+ double biga=(2*Math.PI*i)/n;
+ double len = big*biga;
+ double smalla=len/small;
+ double x,y;
+
+ x = (big+small)*Math.cos(biga) + (small2)*Math.cos(smalla);
+ y = (big+small)*Math.sin(biga) + (small2)*Math.sin(smalla);
+
+ v[index] = new Vec3(x, y, 0 );
+
+ index++;
+ }
+ return v;
+ }
+
+ Vec3[] createRegular(int n, double radiusx, double radiusy) {
+ Vec3[] v;
+ v = new Vec3[n];
+ int index = 0;
+ for (int i = 0; i < n; i++)
+ {
+ v[index] = new Vec3( radiusx*Math.cos( 2*Math.PI * index / (double) n ),
+ radiusy*Math.sin(2*Math.PI * index / (double) n ), 0 );
+ index++;
+ }
+ return v;
+ }
+
+ Vec3[] createStar(int n, double inner, double outer) {
+ Vec3[] v;
+ v = new Vec3[2*n];
+ int index = 0;
+ for (int i = 0; i < n; i++) {
+ v[index] = new Vec3(Math.cos(Math.PI * index / (double) n),
+ Math.sin(Math.PI * index / (double) n), 0);
+ v[index].scale(inner);
+ v[index+1] = new Vec3(Math.cos(Math.PI * (index + 1) / (double) n),
+ Math.sin(Math.PI * (index + 1) / (double) n), 0);
+ v[index+1].scale(outer);
+ index += 2;
+ }
+ return v;
+ }
+
+ Object3D createPolygon(Vec3[] v) {
+ Object3D obj3D;
+ float smoothness[] = new float[v.length];
+ Arrays.fill(smoothness, 0.0f);
+ obj3D = new Curve(v, smoothness, Mesh.NO_SMOOTHING, true).convertToTriangleMesh(0);
+ return obj3D;
+ }
+
+///////////////////////////////////////////
+//math helpers
+
+ // solves system of 2 linear equations in 2 unknown
+ class LinearSolve2
+ {
+ public boolean error;
+ public double x1, x2;
+
+ // matrix looks like this
+ // a b
+ // c d
+ public double det(double a,double b, double c, double d)
+ {
+ return a*d-b*c;
+ }
+ // the equations look like thsi looks like this
+ // x1*a + x2*b = r1
+ // x1*c + x2*d = r2
+ public LinearSolve2(double a,double b, double c, double d, double r1, double r2)
+ {
+ double q;
+
+ q=det(a,b,c,d);
+ if (Math.abs(q) < 0.00000001)
+ {
+ this.error = true;
+ }
+ else
+ {
+ this.error = false;
+ this.x1=det(r1,b,r2,d)/q;
+ this.x2=det(a,r1,c,r2)/q;
+ }
+ }
+ }
+
+ class MetaCADLine {
+ protected Vec2 start,end, dir;
+ protected Vec2 normal;
+
+ public MetaCADLine(Vec3 s,Vec3 e)
+ {
+ this.start = new Vec2(s.x,s.y);
+ this.end = new Vec2(e.x, e.y);
+ this.dir = this.end.minus(this.start);
+ this.normal = new Vec2(this.dir);
+ this.normal.normalize();
+ this.normal.set(-this.normal.y, this.normal.x);
+ }
+
+ public void parallelMove(double d)
+ {
+ this.start.add(this.normal.times(d));
+ }
+
+ public Vec3 intersect3(MetaCADLine l)
+ {
+ LinearSolve2 solve = new LinearSolve2(l.dir.x, -this.dir.x, l.dir.y, -this.dir.y, this.start.x-l.start.x, this.start.y-l.start.y);
+ if (solve.error)
+ {
+ return null;
+ }
+ else
+ {
+ Vec2 point = this.start.plus(this.dir.times(solve.x2));
+ return new Vec3(point.x,point.y, 0);
+ }
+ }
+ }
+
+ Vec3[] insetPoly(Vec3[] poly, double inset)
+ {
+ //List<MetaCADLine> lines = new ArrayList<MetaCADLine>();
+ List<Vec3> points = new ArrayList<Vec3>();
+
+ for (int i = 0; i < poly.length; i++)
+ {
+ int iprev = (i+poly.length-1)%poly.length;
+ int inext = (i+1)%poly.length;
+
+ MetaCADLine prev = new MetaCADLine(poly[iprev], poly[i]);
+ MetaCADLine next = new MetaCADLine(poly[i], poly[inext]);
+
+ prev.parallelMove(inset);
+ next.parallelMove(inset);
+
+ Vec3 intersect=prev.intersect3(next);
+ if (intersect == null)
+ {
+ intersect = new Vec3(0,0,0);
+ }
+ points.add(intersect);
+ }
+
+ return points.toArray(new Vec3[1]);
+ }
+
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/JoinCurvesObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/JoinCurvesObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/JoinCurvesObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/JoinCurvesObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,161 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.math.CoordinateSystem;
+import artofillusion.math.Mat4;
+import artofillusion.math.Vec3;
+import artofillusion.object.Curve;
+import artofillusion.object.MeshVertex;
+import artofillusion.object.ObjectInfo;
+
+public class JoinCurvesObj extends MetaCADObject
+{
+
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ List<ObjectInfo> result = new LinkedList<ObjectInfo>();
+
+ List<ObjectInfo> ch = ParsedTree.evaluate(ctx, children);
+
+ // FIXME: Check that # children >= 2
+ // FIXME: Check that all children are curves
+
+ Vec3[][] ends = new Vec3[ch.size()][2];
+
+ float tol = 0.1f;
+ int smoothtype = 0;
+ float smoothness = 1.0f;
+ Boolean joinends = true;
+
+ // get total number of curve points and start/end vertices of each curve
+ int num = 0;
+ int idx = 0;
+ ObjectInfo[] curves = new ObjectInfo[ch.size()];
+ curves = ch.toArray(curves);
+ for (idx=0;idx<curves.length;idx++) {
+ Mat4 mat = curves[idx].coords.fromLocal();
+ MeshVertex[] verts = ((Curve)curves[idx].object).getVertices();
+ num = num + verts.length;
+ ends[idx][0] = mat.times(verts[0].r);
+ ends[idx][1] = mat.times(verts[verts.length-1].r);
+ }
+
+ int end0found = 0;
+ int end1found = 0;
+ int i;
+ // find ends
+ for (i=0;i<curves.length;i++) {
+ end0found = 0;
+ end1found = 0;
+ for (int j=0;j<curves.length;j++) {
+ if (j == i) continue;
+ for (int k=0;k<2;k++) {
+ if (ends[i][0].distance(ends[j][k]) < tol) end0found = 1;
+ if (ends[i][1].distance(ends[j][k]) < tol) end1found = 1;
+ }
+ }
+ if (end0found + end1found < 2) break;
+ }
+ if (end0found + end1found == 0) {
+ // FIXME: Throw exception
+// new MessageDialog(window, "One or more of the curves are not within selected Proximity - either increase Proximity or move curves");
+ return result;
+ }
+
+ //
+ Boolean loop;
+ int firstCurve;
+ if (i == curves.length) {
+ loop = true;
+ firstCurve = 0; // if no ends found, then must be a loop so choose any starting curve
+ }
+ else {
+ loop = false;
+ firstCurve = i; // otherwise curve i is at one end
+ }
+
+ // assemble the joined curve
+ int[] curvesUsed = new int[curves.length];
+ int curvesUsedIdx = 0;
+ curvesUsed[curvesUsedIdx] = firstCurve;
+ curvesUsedIdx++;
+ Vec3[] curvePoints;
+ int numCurvePoints = num - curves.length;
+ if (!loop) numCurvePoints++;
+ curvePoints = new Vec3[numCurvePoints];
+
+ // add first curve
+ int counter = 0;
+ Mat4 mat = curves[firstCurve].coords.fromLocal();
+ MeshVertex[] verts = ((Curve)curves[firstCurve].object).getVertices();
+ if (end1found == 1) {
+ for (int v=0;v<verts.length;v++) {
+ curvePoints[v+counter]=mat.times(verts[v].r); // update position in world space
+ }
+ }
+ if (end0found == 1) { // reverse order of vertices so curve starts at end
+ for (int v=0;v<verts.length;v++) {
+ curvePoints[verts.length-1-v+counter]=mat.times(verts[v].r); // update position in world space
+ }
+ }
+ counter = counter + verts.length;
+ if (joinends) counter--;
+
+ // assembly joined curve
+ while (curvesUsedIdx < curves.length) {
+ int c;
+ for (c=0;c<curves.length;c++) { //cycle through the selected curves
+ if (c == curvesUsed[curvesUsedIdx-1]) continue; // skip if the same curve
+ int pointToCheck;
+ if (joinends) pointToCheck = counter;
+ else pointToCheck = counter - 1;
+ //
+ if (curvePoints[pointToCheck].distance(ends[c][0])<tol) { // if start of curve c is close to end
+ mat= curves[c].coords.fromLocal();
+ verts = ((Curve)curves[c].object).getVertices();
+ for (int v=0;v<verts.length;v++) {
+ curvePoints[v+counter]=mat.times(verts[v].r);
+ }
+ curvesUsed[curvesUsedIdx]=c; // add curve to list of those used
+ curvesUsedIdx++; //update number of curves used
+ counter=counter+verts.length;
+ if (joinends) counter--;
+ break;
+ }
+ if (curvePoints[pointToCheck].distance(ends[c][1])<tol) { // if end of curve c is close to end
+ mat = curves[c].coords.fromLocal();
+ verts = ((Curve)curves[c].object).getVertices();
+ for (int v=0;v<verts.length;v++) {
+ curvePoints[verts.length-1-v+counter]=mat.times(verts[v].r);
+ }
+ curvesUsed[curvesUsedIdx]=c; // add curve to list of those used
+ curvesUsedIdx++; //update number of curves used
+ counter=counter+verts.length;
+ if (joinends) counter--;
+ break;
+ }
+ }
+ if (c == curves.length) {
+ // FIXME: Throw exception
+// new MessageDialog(window, "One or more of the curves are not within selected Proximity - either increase Proximity or move curves");
+ return result;
+ }
+ }
+// create new curve
+ float[] smooth = new float[num];
+ for (i=0;i<num;i++) {
+ smooth[i]=smoothness;
+ }
+
+ Curve curve = new Curve(curvePoints, smooth, smoothtype, joinends || loop);
+ result.add(new ObjectInfo(curve, new CoordinateSystem(), "dummy"));
+ return result;
+ }
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/LatheObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/LatheObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/LatheObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/LatheObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,77 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.math.CoordinateSystem;
+import artofillusion.object.Curve;
+import artofillusion.object.Mesh;
+import artofillusion.object.Object3D;
+import artofillusion.object.ObjectInfo;
+import artofillusion.tools.LatheTool;
+
+public class LatheObj extends MetaCADObject
+{
+
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ List<ObjectInfo> result = new LinkedList<ObjectInfo>();
+
+ // First parameter define the lathe axis (X, Y or Z)
+ int axis = LatheTool.X_AXIS;
+ if (parameters.size() >= 1) {
+ String dir = parameters.get(0);
+ if (dir.equals("Y")) axis = LatheTool.Y_AXIS;
+ else if (dir.equals("Z")) axis = LatheTool.Z_AXIS;
+ }
+
+ // 2. parameter is sweep angle
+ double sweepang = 360;
+ if (parameters.size() >= 2) {
+ sweepang = ctx.evaluateExpression(parameters.get(1));
+ }
+
+ // 3. parameter is radius
+ double radius = 0.0;
+ if (parameters.size() >= 3) {
+ radius = ctx.evaluateExpression(parameters.get(2));
+ }
+
+ result.addAll(lathe(ParsedTree.evaluate(ctx, children), axis, sweepang, radius));
+ return result;
+ }
+
+ /**
+ *
+ * Lathes the given profiles using the given parameters and returns the result object.
+ *
+ */
+ public List<ObjectInfo> lathe(List<ObjectInfo> objects, int axis, double sweepang, double radius)
+ {
+ // Lathe each lathable child object
+ List<ObjectInfo> resultobjects = new LinkedList<ObjectInfo>();
+ Iterator<ObjectInfo> iter = objects.iterator();
+ while (iter.hasNext()) {
+ ObjectInfo profile = iter.next();
+ Object3D profileobj = profile.getObject();
+ Object3D obj3D = null;
+ if (profileobj instanceof Curve) {
+ Mesh mesh = LatheTool.latheCurve((Curve)profileobj, axis, 16, sweepang, radius);
+ if (mesh instanceof Object3D) obj3D = (Object3D)mesh;
+ }
+ if (obj3D != null) {
+ ObjectInfo objinfo = new ObjectInfo(obj3D, new CoordinateSystem(), "tmp");
+ resultobjects.add(objinfo);
+ }
+ profile.setVisible(false);
+ }
+ // FIXME: Undo support?
+ return resultobjects;
+ }
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/MacroObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MacroObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/MacroObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/MacroObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,55 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.List;
+
+import org.cheffo.jeplite.ASTVarNode;
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+import org.reprap.artofillusion.language.MacroPrototype;
+
+import artofillusion.object.ObjectInfo;
+
+public class MacroObj extends MetaCADObject {
+ protected MacroPrototype prototype;
+
+ public MacroObj(MacroPrototype prototype)
+ {
+ this.prototype = prototype;
+ }
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ if (parameters.size() >= this.prototype.variables.size())
+ {
+ int n = this.prototype.variables.size();
+ ASTVarNode[] backup = new ASTVarNode[n];
+ double[] values = new double[n];
+ // backup variables
+ for (int i = 0; i < n; i++)
+ {
+ backup[i] = ctx.jep.getVarNode(this.prototype.variables.get(i));
+ values[i] = ctx.evaluateExpression(parameters.get(i));
+ }
+ // replace variables
+ for (int i = 0; i < n; i++)
+ {
+ ctx.jep.setVarNode(this.prototype.variables.get(i), null);
+ ctx.jep.addVariable(this.prototype.variables.get(i), values[i]);
+ }
+ // evaluate
+ List<ObjectInfo> result = ParsedTree.evaluate(ctx, this.prototype.children);
+ // restore previous variables
+ for (int i = 0; i < n; i++)
+ {
+ ctx.jep.setVarNode(this.prototype.variables.get(i), backup[i]);
+ }
+ return result;
+ }
+ else
+ {
+ throw new Exception("Not enough parameters given to Macro Call: " + this.prototype.name);
+ }
+ }
+
+}
\ No newline at end of file
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/MeshObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MeshObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/MeshObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/MeshObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,43 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.object.Curve;
+import artofillusion.object.Object3D;
+import artofillusion.object.ObjectInfo;
+import artofillusion.object.TriangleMesh;
+
+public class MeshObj extends MetaCADObject
+{
+
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ double tolerance = 0.2;
+ if (parameters.size() > 0) {
+ tolerance = ctx.evaluateExpression(parameters.get(0));
+ }
+
+ List<ObjectInfo> results = new LinkedList<ObjectInfo>();
+
+ Iterator<ObjectInfo> iter = ParsedTree.evaluate(ctx, children).iterator();
+ while(iter.hasNext()) {
+ ObjectInfo chinfo = iter.next();
+ Object3D obj3D = chinfo.getObject();
+ if (obj3D instanceof Curve) {
+ assert(obj3D.canConvertToTriangleMesh() != Object3D.CANT_CONVERT);
+ TriangleMesh mesh = obj3D.convertToTriangleMesh(tolerance);
+ ObjectInfo newinfo = new ObjectInfo(mesh, chinfo.getCoords(), "dummy");
+ newinfo.setTexture(ctx.scene.getDefaultTexture(), ctx.scene.getDefaultTexture().getDefaultMapping(mesh));
+ results.add(newinfo);
+ }
+ }
+ return results;
+ }
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/MetaCADObject.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/MetaCADObject.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/MetaCADObject.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/MetaCADObject.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,16 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.List;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.object.ObjectInfo;
+
+public abstract class MetaCADObject {
+
+ public abstract List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception;
+
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/NativeObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/NativeObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/NativeObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/NativeObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,20 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.List;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.object.ObjectInfo;
+
+
+public class NativeObj extends MetaCADObject {
+
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ return null;
+ }
+
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ObjFactory.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjFactory.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ObjFactory.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ObjFactory.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,73 @@
+package org.reprap.artofillusion.objects;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.language.MacroPrototype;
+
+import artofillusion.object.CSGObject;
+
+public class ObjFactory {
+ public static MetaCADObject create(MetaCADContext ctx, String name) throws ObjFactoryException {
+ name = name.toLowerCase();
+
+ if (name.equals("native")) {
+ return new NativeObj();
+ }
+ else if (name.startsWith("sphere")) {
+ return new SphereObj();
+ }
+ else if (name.startsWith("cube")) {
+ return new CubeObj();
+ }
+ else if (name.startsWith("cylinder")) {
+ return new CylinderObj();
+ }
+ else if (name.startsWith("cs")) {
+ return new CSObj();
+ }
+ else if (name.startsWith("union") || name.startsWith("+")) {
+ return new BooleanObj(CSGObject.UNION);
+ }
+ else if (name.startsWith("difference") || name.startsWith("-")) {
+ return new BooleanObj(CSGObject.DIFFERENCE12);
+ }
+ else if (name.startsWith("intersection") || name.startsWith("/")) {
+ return new BooleanObj(CSGObject.INTERSECTION);
+ }
+ else if (name.startsWith("star")) {
+ return new PolygonObj(PolygonObj.STAR);
+ }
+ else if (name.startsWith("reg")) {
+ return new PolygonObj(PolygonObj.REG);
+ }
+ else if (name.startsWith("roll")) {
+ return new PolygonObj(PolygonObj.ROLL);
+ }
+ else if (name.startsWith("extrude")) {
+ return new ExtrudeObj();
+ }
+ else if (name.startsWith("for")) {
+ return new ForObj();
+ }
+ else if (name.startsWith("inset")) {
+ return new InsetObj();
+ }
+ else if (name.startsWith("mesh")) {
+ return new MeshObj();
+ }
+ else if (name.startsWith("joincurves")) {
+ return new JoinCurvesObj();
+ }
+ else if (name.startsWith("lathe")) {
+ return new LatheObj();
+ }
+ else {
+ MacroPrototype macroPrototype = ctx.macros.get(name.toLowerCase());
+ if (macroPrototype != null)
+ {
+ return new MacroObj(macroPrototype);
+ }
+ }
+
+ throw new ObjFactoryException("ObjFactory: Unknown Object type: " + name);
+ }
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ObjFactoryException.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/ObjFactoryException.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ObjFactoryException.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/ObjFactoryException.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,12 @@
+package org.reprap.artofillusion.objects;
+
+import org.reprap.artofillusion.parser.ParseException;
+
+public class ObjFactoryException extends ParseException {
+
+ private static final long serialVersionUID = -5731809677962819119L;
+
+ public ObjFactoryException(String message) {
+ super(message);
+ }
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/PolygonObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/PolygonObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/PolygonObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/PolygonObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,156 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.math.CoordinateSystem;
+import artofillusion.math.Vec3;
+import artofillusion.object.Curve;
+import artofillusion.object.Mesh;
+import artofillusion.object.Object3D;
+import artofillusion.object.ObjectInfo;
+
+public class PolygonObj extends MetaCADObject
+{
+ public static final int STAR = 0;
+ public static final int REG = 1;
+ public static final int ROLL = 2;
+ int type;
+
+ public PolygonObj(int type) {
+ this.type = type;
+ }
+
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ List<ObjectInfo> result = new LinkedList<ObjectInfo>();
+
+ Vec3[] v=null;
+ switch (this.type) {
+ case STAR: {
+ int n = 6;
+ double inner = 3;
+ double outer = 5;
+ if (parameters.size() >= 1) {
+ n = (int)ctx.evaluateExpression(parameters.get(0));
+ }
+ if (parameters.size() >= 3) {
+ inner = ctx.evaluateExpression(parameters.get(1));
+ outer = ctx.evaluateExpression(parameters.get(2));
+ }
+
+ v = createStar(n, inner, outer);
+ break;
+ }
+ case REG: {
+ int n = 6;
+ double radiusx = 4;
+ double radiusy = 4;
+ if (parameters.size() >= 1) {
+ n = (int)ctx.evaluateExpression(parameters.get(0));
+ }
+ if (parameters.size() >= 2) {
+ radiusy = radiusx = ctx.evaluateExpression(parameters.get(1));
+ }
+ if (parameters.size() >= 3) {
+ radiusy = ctx.evaluateExpression(parameters.get(2));
+ }
+
+ v = createRegular(n, radiusx, radiusy);
+ break;
+ }
+ case ROLL: {
+ int n = 30;
+ double big = 5;
+ double small = 1;
+ double small2 = 0.8;
+ if (parameters.size() >= 1) {
+ n = (int)ctx.evaluateExpression(parameters.get(0));
+ }
+ if (parameters.size() >= 3) {
+ big = ctx.evaluateExpression(parameters.get(1));
+ small2 = small = ctx.evaluateExpression(parameters.get(2));
+ }
+ if (parameters.size() == 4) {
+ small2 = ctx.evaluateExpression(parameters.get(3));
+ }
+
+ v = createRoll(n, big, small, small2);
+ break;
+ }
+ }
+
+ if (v != null) {
+ Object3D obj3D = createPolygon(v);
+ result.add(new ObjectInfo(obj3D, new CoordinateSystem(), "dummy"));
+ return result;
+ }
+ return null;
+ }
+
+ Vec3[] createRoll(int n, double big, double small, double small2) {
+ Vec3[] v;
+ v = new Vec3[n];
+ int index = 0;
+ for (int i = 0; i < n; i++)
+ {
+ double biga=(2*Math.PI*i)/n;
+ double len = big*biga;
+ double smalla=len/small;
+ double x,y;
+
+ x = (big+small)*Math.cos(biga) + (small2)*Math.cos(smalla);
+ y = (big+small)*Math.sin(biga) + (small2)*Math.sin(smalla);
+
+ v[index] = new Vec3(x, y, 0 );
+
+ index++;
+ }
+ return v;
+ }
+
+ Vec3[] createRegular(int n, double radiusx, double radiusy) {
+ Vec3[] v;
+ v = new Vec3[n];
+ int index = 0;
+ for (int i = 0; i < n; i++)
+ {
+ v[index] = new Vec3( radiusx*Math.cos( 2*Math.PI * index / (double) n ),
+ radiusy*Math.sin(2*Math.PI * index / (double) n ), 0 );
+ index++;
+ }
+ return v;
+ }
+
+ Vec3[] createStar(int n, double inner, double outer) {
+ Vec3[] v;
+ v = new Vec3[2*n];
+ int index = 0;
+ for (int i = 0; i < n; i++) {
+ v[index] = new Vec3(Math.cos(Math.PI * index / (double) n),
+ Math.sin(Math.PI * index / (double) n), 0);
+ v[index].scale(inner);
+ v[index+1] = new Vec3(Math.cos(Math.PI * (index + 1) / (double) n),
+ Math.sin(Math.PI * (index + 1) / (double) n), 0);
+ v[index+1].scale(outer);
+ index += 2;
+ }
+ return v;
+ }
+
+ static public Object3D createPolygon(Vec3[] v) {
+ Object3D obj3D;
+ float smoothness[] = new float[v.length];
+ Arrays.fill(smoothness, 0.0f);
+ obj3D = new Curve(v, smoothness, Mesh.NO_SMOOTHING, true);
+ return obj3D;
+ }
+
+
+}
Copied: trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/SphereObj.java (from rev 2938, trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/SphereObj.java)
===================================================================
--- trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/SphereObj.java (rev 0)
+++ trunk/reprap/miscellaneous/AoI/plugins/CSGEvaluator/src/org/reprap/artofillusion/objects/SphereObj.java 2009-05-10 02:54:52 UTC (rev 2939)
@@ -0,0 +1,38 @@
+package org.reprap.artofillusion.objects;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.reprap.artofillusion.MetaCADContext;
+import org.reprap.artofillusion.ParsedTree;
+
+import artofillusion.math.CoordinateSystem;
+import artofillusion.math.Vec3;
+import artofillusion.object.Object3D;
+import artofillusion.object.ObjectInfo;
+
+public class SphereObj extends MetaCADObject {
+
+ public List<ObjectInfo> evaluateObject(MetaCADContext ctx,
+ List<String> parameters,
+ List<ParsedTree> children) throws Exception {
+
+ List<ObjectInfo> result = new LinkedList<ObjectInfo>();
+
+ double mainparam = 1.0f;
+ if (parameters.size() >= 1) {
+ mainparam = ctx.evaluateExpression(parameters.get(0));
+ }
+ Vec3 dims = new Vec3(mainparam, mainparam, mainparam);
+ if (parameters.size() >= 3) {
+ dims.set(mainparam,
+ ctx.evaluateExpression(parameters.get(1)),
+ ctx.evaluateExpression(parameters.get(2)));
+ }
+ Object3D obj3D = new artofillusion.object.Sphere(dims.x, dims.y, dims.z);
+
+ result.add(new ObjectInfo(obj3D, new CoordinateSystem(), "dummy"));
+
+ return result;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|