use of cbit.vcell.geometry.CSGSetOperator in project vcell by virtualcell.
the class ComsolModelBuilder method csgVisitor.
private static VCCGeomFeature csgVisitor(CSGNode node, ArrayList<VCCGeomFeature> geomFeatureList, String namePrefix) {
final VCCGeomFeature newFeature;
if (node instanceof CSGPrimitive) {
CSGPrimitive csg = (CSGPrimitive) node;
switch(csg.getType()) {
case CONE:
{
newFeature = new VCCCone(namePrefix + csg.getName());
break;
}
case CUBE:
{
String[] size = new String[] { "2", "2", "2" };
String[] pos = new String[] { "-1", "-1", "-1" };
VCCBlock vccblock = new VCCBlock(namePrefix + csg.getName(), size, pos);
newFeature = vccblock;
break;
}
case CYLINDER:
{
newFeature = new VCCCylinder(namePrefix + csg.getName());
break;
}
case SPHERE:
{
String r = "1";
String[] pos = new String[] { "0", "0", "0" };
newFeature = new VCCSphere(namePrefix + csg.getName(), pos, r);
break;
}
default:
{
throw new RuntimeException("csg primative type '" + csg.getType().name() + "' not yet supported in COMSOL model builder");
}
}
} else if (node instanceof CSGSetOperator) {
CSGSetOperator setOp = (CSGSetOperator) node;
ArrayList<VCCGeomFeature> childSubtrees = new ArrayList<VCCGeomFeature>();
for (CSGNode child : setOp.getChildren()) {
VCCGeomFeature vccChild = csgVisitor(child, geomFeatureList, namePrefix);
childSubtrees.add(vccChild);
}
switch(setOp.getOpType()) {
case DIFFERENCE:
{
if (childSubtrees.size() != 2) {
throw new RuntimeException("expecting exactly two children for CSG difference operator");
}
VCCDifference diff = new VCCDifference(namePrefix + setOp.getName(), Keep.off);
diff.input.add(childSubtrees.get(0));
diff.input2.add(childSubtrees.get(1));
newFeature = diff;
break;
}
case INTERSECTION:
{
if (childSubtrees.size() < 2) {
throw new RuntimeException("expecting two or more children for CSG intersection operator");
}
VCCIntersection intersection = new VCCIntersection(namePrefix + setOp.getName(), Keep.off);
intersection.input.add(childSubtrees.get(0));
newFeature = intersection;
break;
}
case UNION:
{
if (childSubtrees.size() < 2) {
throw new RuntimeException("expecting two or more children for CSG union operator");
}
VCCUnion union = new VCCUnion(namePrefix + setOp.getName(), Keep.off);
union.input.add(childSubtrees.get(0));
newFeature = union;
break;
}
default:
{
throw new RuntimeException("csg set operator '" + setOp.getOpType().name() + "' not yet supported in COMSOL model builder");
}
}
} else if (node instanceof CSGTransformation) {
CSGTransformation transformation = (CSGTransformation) node;
VCCGeomFeature vccChild = csgVisitor(transformation.getChild(), geomFeatureList, namePrefix);
if (transformation instanceof CSGHomogeneousTransformation) {
throw new RuntimeException("unsupported CSG transformation type Homogeneous transformation");
} else if (transformation instanceof CSGRotation) {
CSGRotation rotation = (CSGRotation) transformation;
String[] axis = new String[] { Double.toString(rotation.getAxis().getX()), Double.toString(rotation.getAxis().getY()), Double.toString(rotation.getAxis().getZ()) };
String[] pos = new String[] { "0.0", "0.0", "0.0" };
String rot = Double.toString(rotation.getRotationRadians());
VCCRotate vccrotate = new VCCRotate(namePrefix + rotation.getName(), axis, pos, rot, Keep.off);
vccrotate.input.add(vccChild);
newFeature = vccrotate;
} else if (transformation instanceof CSGScale) {
CSGScale scale = (CSGScale) transformation;
String[] factor = new String[] { Double.toString(scale.getScale().getX()), Double.toString(scale.getScale().getY()), Double.toString(scale.getScale().getZ()) };
String[] pos = new String[] { "0.0", "0.0", "0.0" };
VCCScale vccscale = new VCCScale(namePrefix + scale.getName(), pos, factor, Keep.off);
vccscale.input.add(vccChild);
newFeature = vccscale;
} else if (transformation instanceof CSGTranslation) {
CSGTranslation translation = (CSGTranslation) transformation;
String[] displ = new String[] { Double.toString(translation.getTranslation().getX()), Double.toString(translation.getTranslation().getY()), Double.toString(translation.getTranslation().getZ()) };
VCCMove vccmove = new VCCMove(namePrefix + translation.getName(), displ, Keep.off);
vccmove.input.add(vccChild);
newFeature = vccmove;
} else {
throw new RuntimeException("unsupported CSG transformation type '" + transformation.getClass().getSimpleName() + "'");
}
} else {
throw new RuntimeException("unsupported CSGNode type '" + node.getClass().getSimpleName() + "'");
}
geomFeatureList.add(newFeature);
return newFeature;
}
use of cbit.vcell.geometry.CSGSetOperator in project vcell by virtualcell.
the class CSGObjectPropertiesPanel method showPopupMenu.
private void showPopupMenu(MouseEvent e) {
if (!e.isPopupTrigger()) {
return;
}
if (popupMenu == null) {
popupMenu = new JPopupMenu();
}
if (popupMenu.isShowing()) {
return;
}
selectClickPath(e);
TreePath[] selectedPaths = csgObjectTree.getSelectionPaths();
boolean bShowPopup = true;
boolean bTransform = false;
boolean bApplySetOperator = false;
boolean bAddPrimitive = false;
boolean bAddTransformation = false;
boolean bAddOperator = false;
boolean bEdit = false;
boolean bDelete = true;
if (selectedPaths == null) {
return;
}
for (TreePath tp : selectedPaths) {
Object obj = tp.getLastPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
continue;
}
BioModelNode selectedNode = (BioModelNode) obj;
Object userObject = selectedNode.getUserObject();
if (userObject == csgObject) {
bDelete = false;
if (csgObject.getRoot() == null) {
bAddPrimitive = true;
bAddOperator = true;
bAddTransformation = true;
}
} else if (userObject instanceof CSGPrimitive) {
bApplySetOperator = true;
bTransform = true;
bAddPrimitive = false;
bAddOperator = false;
bAddTransformation = false;
} else if (userObject instanceof CSGSetOperator) {
bApplySetOperator = true;
bTransform = true;
bAddPrimitive = true;
bAddOperator = true;
bAddTransformation = true;
} else if (userObject instanceof CSGTransformation) {
bApplySetOperator = true;
bTransform = true;
bEdit = true;
if (((CSGTransformation) userObject).getChild() == null) {
bAddPrimitive = true;
bAddOperator = true;
bAddTransformation = true;
}
}
}
if (bShowPopup) {
popupMenu.removeAll();
if (bAddPrimitive || bAddTransformation || bAddOperator) {
getAddPrimitiveMenu().setEnabled(bAddPrimitive);
getAddTransformationMenu().setEnabled(bAddTransformation);
getAddSetOperatorMenu().setEnabled(bAddOperator);
popupMenu.add(getAddMenu());
}
if (popupMenu.getComponents().length > 0) {
popupMenu.add(new JSeparator());
}
// everything can be renamed
popupMenu.add(getRenameMenuItem());
if (bEdit) {
popupMenu.add(getEditMenuItem());
}
if (bDelete) {
popupMenu.add(getDeleteMenuItem());
}
if (bTransform) {
if (popupMenu.getComponents().length > 0) {
popupMenu.add(new JSeparator());
}
popupMenu.add(getTransformMenu());
}
if (bApplySetOperator) {
if (popupMenu.getComponents().length > 0 && !bTransform) {
popupMenu.add(new JSeparator());
}
popupMenu.add(getApplySetOperatorMenu());
}
Point mousePoint = e.getPoint();
popupMenu.show(csgObjectTree, mousePoint.x, mousePoint.y);
}
}
use of cbit.vcell.geometry.CSGSetOperator in project vcell by virtualcell.
the class CSGObjectPropertiesPanel method addNode.
private boolean addNode(CSGNode newCsgNode) {
if (newCsgNode == null) {
return false;
}
Object obj = csgObjectTree.getLastSelectedPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
return false;
}
BioModelNode selectedNode = (BioModelNode) obj;
Object selectedUserObject = selectedNode.getUserObject();
if (selectedUserObject == csgObject) {
csgObject.setRoot(newCsgNode);
return true;
}
if (selectedUserObject instanceof CSGSetOperator) {
CSGSetOperator csgSetOperator = (CSGSetOperator) selectedUserObject;
csgSetOperator.addChild(newCsgNode);
return true;
}
if (selectedUserObject instanceof CSGTransformation) {
CSGTransformation csgTransformation = (CSGTransformation) selectedUserObject;
csgTransformation.setChild(newCsgNode);
return true;
}
return false;
}
use of cbit.vcell.geometry.CSGSetOperator in project vcell by virtualcell.
the class CSGObjectPropertiesPanel method transformOrApplySetOperator.
private boolean transformOrApplySetOperator(CSGNode newCsgNode) {
if (newCsgNode == null) {
return false;
}
Object obj = csgObjectTree.getLastSelectedPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
return false;
}
BioModelNode selectedNode = (BioModelNode) obj;
Object selectedUserObject = selectedNode.getUserObject();
if (!(selectedUserObject instanceof CSGNode)) {
return false;
}
CSGNode selectedCSGNode = (CSGNode) selectedUserObject;
TreeNode parentNode = selectedNode.getParent();
if (parentNode == null || !(parentNode instanceof BioModelNode)) {
return false;
}
Object parentObject = ((BioModelNode) parentNode).getUserObject();
if (newCsgNode instanceof CSGTransformation) {
CSGTransformation csgTransformation = (CSGTransformation) newCsgNode;
csgTransformation.setChild(selectedCSGNode);
} else if (newCsgNode instanceof CSGSetOperator) {
CSGSetOperator csgSetOperator = (CSGSetOperator) newCsgNode;
csgSetOperator.addChild(selectedCSGNode);
}
if (parentObject == csgObject) {
csgObject.setRoot(newCsgNode);
} else if (parentObject instanceof CSGSetOperator) {
CSGSetOperator parentCSGSetOperator = (CSGSetOperator) parentObject;
int index = parentCSGSetOperator.indexOf(selectedCSGNode);
if (index >= 0) {
parentCSGSetOperator.setChild(index, newCsgNode);
return true;
}
} else if (parentObject instanceof CSGTransformation) {
CSGTransformation parentCSGTransformation = (CSGTransformation) parentObject;
parentCSGTransformation.setChild(newCsgNode);
return true;
}
return false;
}
use of cbit.vcell.geometry.CSGSetOperator in project vcell by virtualcell.
the class CSGObjectPropertiesPanel method deleteNode.
private void deleteNode() {
Object obj = csgObjectTree.getLastSelectedPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
return;
}
BioModelNode selectedNode = (BioModelNode) obj;
Object selectedUserObject = selectedNode.getUserObject();
if (!(selectedUserObject instanceof CSGNode)) {
return;
}
CSGNode selectedCSGNode = (CSGNode) selectedUserObject;
TreeNode parentNode = selectedNode.getParent();
if (parentNode == null || !(parentNode instanceof BioModelNode)) {
return;
}
Object parentObject = ((BioModelNode) parentNode).getUserObject();
if (parentObject == csgObject) {
csgObject.setRoot(null);
} else if (parentObject instanceof CSGSetOperator) {
CSGSetOperator csgSetOperator = (CSGSetOperator) parentObject;
csgSetOperator.removeChild(selectedCSGNode);
} else if (parentObject instanceof CSGTransformation) {
CSGTransformation csgTransformation = (CSGTransformation) parentObject;
csgTransformation.setChild(null);
}
updateCSGObject(parentObject);
}
Aggregations