package org.reprap.artofillusion; import java.util.Collection; import java.util.Iterator; import artofillusion.LayoutWindow; import artofillusion.UndoRecord; import artofillusion.math.CoordinateSystem; import artofillusion.object.CSGObject; import artofillusion.object.Object3D; import artofillusion.object.ObjectInfo; import artofillusion.texture.Texture; import artofillusion.texture.TextureMapping; import artofillusion.ui.MessageDialog; public class CSGEvaluatorEngine { LayoutWindow window; public CSGEvaluatorEngine(LayoutWindow window) { this.window = window; } /** Returns a normalized selection, meaning children of a selected parent are removed. */ public ObjectInfo[] getSelection() { Collection sel = this.window.getSelectedObjects(); ObjectInfo[] objects = new ObjectInfo[sel.size()]; Iterator it = sel.iterator(); int i = 0; while (it.hasNext()) { ObjectInfo objinfo = it.next(); ObjectInfo p = objinfo.getParent(); while (p != null) { // Check if any parent is selected if (this.window.isObjectSelected(p)) break; p = p.getParent(); } if (p == null) objects[i++] = objinfo; } ObjectInfo[] cleanedobjects = new ObjectInfo[i]; System.arraycopy(objects, 0, cleanedobjects, 0, i); return cleanedobjects; } /** * Evaluates the currently selected subtree */ public void evaluate() { try { UndoRecord undo = new UndoRecord(this.window, false); ObjectInfo[] objects = getSelection(); if (objects != null) { for (int i=0;i= 2), and returns the resulting ObjectInfo containing a CSGObject. Calls evaluateNode() on each child before performing the operation. Hides the children. */ public ObjectInfo combine(ObjectInfo[] objects, int operation, UndoRecord undo) throws Exception { if (objects.length < 1) return null; if (objects.length < 2) return objects[0]; ObjectInfo a = evaluateNode(objects[0], undo); ObjectInfo b = evaluateNode(objects[1], undo); Object3D csgobj = new CSGObject(a, b, operation); ObjectInfo csgobjinfo = new ObjectInfo(csgobj, 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 ObjectInfo createNewObject(ObjectInfo[] objects, int operation, UndoRecord undo) throws Exception { ObjectInfo granddad = objects[0].parent; // create ObjectInfo for combined object ObjectInfo resultinfo = combine(objects, operation, undo); resultinfo.setName(opToString(operation)); //resultinfo.parent = granddad; // add the object info to the window (which adds it to the scene and the item tree // and creates the proper undo record commands) // FIXME: The index is sometimes wrong since moving objects with the mouse confuses AoI's index system. // Don't know how to get around this, so keep it like this for now. this.window.getScene().addObject(resultinfo, this.window.getScene().indexOf(objects[0]), undo); // reparent children for (int i=0;i