/*
*/
/*
TODO:
* don't collapse hierarchy after operation: Need to get hold of the TreeList instance. Doesn't look doable..
* ok/cancel -> close: Use superclass of ComponentsDialog?
* Make evaluate work with object which have been converted to triangles
* stop the UI thread while our methods execute to prevent race conditions
*/
class MetaCAD
{
public static String opToString(int operation) {
switch (operation) {
case CSGObject.UNION:
return "union";
break;
case CSGObject.INTERSECTION:
return "intersection";
break;
case CSGObject.DIFFERENCE12:
return "difference";
break;
default:
return null;
}
}
public static int stringToOp(String opstr) {
String lower = opstr.toLowerCase();
if (lower.startsWith("union") || lower.startsWith("+")) {
return CSGObject.UNION;
}
else if (lower.startsWith("intersection") || lower.startsWith("/")) {
return CSGObject.INTERSECTION;
}
else if (lower.startsWith("difference") || lower.startsWith("-")) {
return CSGObject.DIFFERENCE12;
}
else return -1;
}
/*
Recursively (Re-)evaluates the object tree rooted at the given root object
based on the object name.
The result should be one CSG object where the entire child tree is disabled.
*/
public static ObjectInfo evaluateNode(ObjectInfo parent, UndoRecord undo)
{
int op = stringToOp(parent.name);
if (op == -1) return parent;
else return combine(parent, op, undo);
}
/*
Recursively (Re-)deevaluates the object tree rooted at the given root object
based on the object name.
This disables all implicit (parent) objects and enabled the leaf nodes.
*/
public static void devaluateNode(ObjectInfo parent, UndoRecord undo)
{
int op = stringToOp(parent.name);
if (op != -1) {
if (undo != null)
undo.addCommand(UndoRecord.COPY_OBJECT_INFO, new Object [] {parent, parent.duplicate()});
parent.setVisible(false);
//TODO: should not be necessary since we don't modify the object (only the object info)
window.getScene().objectModified(parent.getObject());
ObjectInfo[] children = parent.getChildren();
for (int i=0;i= 2),
and returns the resulting ObjectInfo containing a CSGObject.
Calls evaluateNode() on each child.
*/
public static ObjectInfo combine(ObjectInfo[] objects, int operation, UndoRecord undo)
{
debug("start combine");
if (objects.length < 1) return null;
if (objects.length < 2) return objects[0];
ObjectInfo a, b;
a = evaluateNode(objects[0], undo);
b = evaluateNode(objects[1], undo);
Object3D unionobj = new CSGObject(a,
b,
operation);
ObjectInfo unioninfo = new ObjectInfo(unionobj, new CoordinateSystem(), "tmp");
for (int i=2;i= 2).
Inserts the new object into the scene and makes the original objects
children of the new object. Also hides the children.
*/
public static ObjectInfo create(ObjectInfo[] objects, int operation, UndoRecord undo)
{
debug("start create");
Scene scene = window.getScene();
//create ObjectInfo for combined object
ObjectInfo result = combine(objects, operation, undo);
result.setName(opToString(operation));
debug("after combine");
//add the object info to the wimdow (which adds it to the scene and the item tree
// and creates the proper undo record commands)
window.getScene().addObject(result, undo);
debug("after addObject");
//move children
for (int i=0;i