use of org.concord.energy3d.model.Meshable in project energy3d by concord-consortium.
the class SceneManager method mouseMoved.
private void mouseMoved() {
if (!mouseControlEnabled) {
return;
}
final int x = mouseState.getX();
final int y = mouseState.getY();
if (Scene.getInstance().getDisableShadowInAction()) {
if (mouseState.getButtonState(MouseButton.LEFT) == ButtonState.DOWN || mouseState.getButtonState(MouseButton.RIGHT) == ButtonState.DOWN) {
if (MainPanel.getInstance().getShadowButton().isSelected()) {
shadowPass.setEnabled(false);
}
} else {
if (MainPanel.getInstance().getShadowButton().isSelected()) {
shadowPass.setEnabled(true);
}
}
}
try {
if (selectedPart != null) {
if (!selectedPart.isDrawCompleted()) {
selectedPart.setPreviewPoint(x, y);
if (selectedPart instanceof Meshable) {
// don't draw grid if it sits on an imported mesh
selectedPart.setGridsVisible(((Meshable) selectedPart).getMeshLocator() == null);
}
} else if (objectMoveStartPoint != null) {
if ((operation == Operation.RESIZE || selectedPart instanceof Foundation)) {
final PickedHousePart pick = SelectUtil.pickPart(x, y, collisionLand);
if (pick != null) {
if (selectedPart instanceof Foundation) {
final Foundation foundation = (Foundation) selectedPart;
final Vector3 pickPoint = pick.getPoint().clone();
// if (!foundation.insideBuilding(pickPoint.getX(), pickPoint.getY(), true)) { // only move the building when clicking outside
final Vector3 d = pickPoint.multiply(1, 1, 0, null).subtractLocal(objectMoveStartPoint.multiply(1, 1, 0, null));
if (foundation.isGroupMaster()) {
final List<Foundation> g = Scene.getInstance().getFoundationGroup(foundation);
for (final Foundation f : g) {
final ArrayList<Vector3> movePoints = objectGroupMovePoints.get(f);
if (movePoints != null) {
// just in case this foundation's move point hasn't been included yet
f.move(d, movePoints);
}
}
} else {
foundation.move(d, objectMovePoints);
}
}
}
} else if (selectedPart instanceof Tree) {
final PickedHousePart pick = SelectUtil.pickPart(x, y, collisionLand);
if (pick != null) {
final Vector3 d = pick.getPoint().multiply(1, 1, 0, null).subtractLocal(objectMoveStartPoint.multiply(1, 1, 0, null));
((Tree) selectedPart).move(d, objectMovePoints);
}
} else if (selectedPart instanceof Window) {
final PickedHousePart pick = SelectUtil.pickPart(x, y, selectedPart.getContainer());
if (pick != null) {
final Vector3 d = pick.getPoint().subtract(objectMoveStartPoint, null);
((Window) selectedPart).move(d, objectMovePoints);
}
}
}
}
hoveredPart = null;
if ((operation == Operation.SELECT || operation == Operation.RESIZE) && mouseState.getButtonState(MouseButton.LEFT) == ButtonState.UP && mouseState.getButtonState(MouseButton.MIDDLE) == ButtonState.UP && mouseState.getButtonState(MouseButton.RIGHT) == ButtonState.UP) {
final PickedHousePart pickedPart = SelectUtil.selectHousePart(x, y, false);
pick = pickedPart == null ? null : pickedPart.getUserData();
final HousePart housePart = pick == null ? null : pick.getHousePart();
if (pick != null) {
hoveredPart = housePart;
if (pick.getEditPointIndex() != -1) {
lastSelectedEditPointMouseState = mouseState;
}
}
}
mouseState = null;
} catch (final Throwable t) {
t.printStackTrace();
BugReporter.report(t);
}
EventQueue.invokeLater(new // this method is run by the main Energy3D thread, so invoke the Swing code later
Runnable() {
@Override
public void run() {
final Component canvasComponent = (Component) canvas;
canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
if (!zoomLock && (operation == Operation.SELECT || operation == Operation.RESIZE) && hoveredPart != null) {
if (hoveredPart instanceof Tree || hoveredPart instanceof Human) {
canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
} else if (hoveredPart instanceof SolarCollector) {
if (pick.getEditPointIndex() >= 0) {
canvasComponent.setCursor(Cursor.getPredefinedCursor(pick.getEditPointIndex() == 0 ? Cursor.MOVE_CURSOR : Cursor.HAND_CURSOR));
}
} else {
if (pick.getEditPointIndex() == -1) {
if (hoveredPart instanceof Window) {
// for windows, there is no apparent move point
canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
}
}
}
}
}
});
}
Aggregations