use of org.concord.energy3d.model.HousePart in project energy3d by concord-consortium.
the class SceneManager method rotate.
public void rotate(final double angle) {
if (SceneManager.getInstance().getSolarHeatMap()) {
EnergyPanel.getInstance().updateRadiationHeatMap();
}
taskManager.update(new Callable<Object>() {
@Override
public Object call() {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Foundation) {
final RotateBuildingCommand c = new RotateBuildingCommand((Foundation) selectedPart, angle);
SceneManager.getInstance().rotateFoundation(angle, true);
SceneManager.getInstance().getUndoManager().addEdit(c);
} else if (selectedPart instanceof SolarPanel) {
final SolarPanel solarPanel = (SolarPanel) selectedPart;
final ChangeAzimuthCommand c = new ChangeAzimuthCommand(solarPanel);
solarPanel.setRelativeAzimuth(solarPanel.getRelativeAzimuth() + Math.toDegrees(angle));
solarPanel.draw();
SceneManager.getInstance().getUndoManager().addEdit(c);
} else if (selectedPart instanceof Rack) {
final Rack rack = (Rack) selectedPart;
final ChangeAzimuthCommand c = new ChangeAzimuthCommand(rack);
rack.setRelativeAzimuth(rack.getRelativeAzimuth() + Math.toDegrees(angle));
rack.draw();
SceneManager.getInstance().getUndoManager().addEdit(c);
} else if (selectedPart instanceof Mirror) {
final Mirror mirror = (Mirror) selectedPart;
final ChangeAzimuthCommand c = new ChangeAzimuthCommand(mirror);
mirror.setRelativeAzimuth(mirror.getRelativeAzimuth() + Math.toDegrees(angle));
mirror.draw();
SceneManager.getInstance().getUndoManager().addEdit(c);
} else if (selectedPart == null) {
final RotateBuildingCommand c = new RotateBuildingCommand(null, angle);
rotateAllFoundations(angle);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
EnergyPanel.getInstance().updateProperties();
}
});
return null;
}
});
}
use of org.concord.energy3d.model.HousePart in project energy3d by concord-consortium.
the class SceneManager method executeOperation.
public void executeOperation() {
operationFlag = false;
if (operation == Operation.RESIZE) {
if (selectedPart instanceof Foundation) {
((Foundation) selectedPart).setResizeHouseMode(true);
}
} else {
for (final HousePart part : Scene.getInstance().getParts()) {
if (part instanceof Foundation) {
((Foundation) part).setResizeHouseMode(false);
}
}
}
if (viewMode != ViewMode.PRINT_PREVIEW) {
Scene.getInstance().drawResizeBounds();
}
selectedPart = newPart();
if (selectedPart != null) {
cameraControl.setLeftMouseButtonEnabled(false);
}
}
use of org.concord.energy3d.model.HousePart in project energy3d by concord-consortium.
the class SceneManager method move.
public void move(final Vector3 v) {
if (SceneManager.getInstance().getSolarHeatMap()) {
EnergyPanel.getInstance().updateRadiationHeatMap();
}
final MovePartCommand c = new MovePartCommand(selectedPart, v);
if (selectedPart == null) {
for (final HousePart p : Scene.getInstance().getParts()) {
if (p instanceof Foundation) {
((Foundation) p).move(v, p.getGridSize());
}
}
Scene.getInstance().redrawAll();
} else if (selectedPart instanceof Foundation) {
final Foundation f = (Foundation) selectedPart;
if (f.isGroupMaster()) {
final List<Foundation> g = Scene.getInstance().getFoundationGroup(f);
for (final Foundation x : g) {
x.move(v, selectedPart.getGridSize());
}
} else {
f.move(v, selectedPart.getGridSize());
}
} else if (selectedPart instanceof FoundationPolygon) {
((Foundation) selectedPart.getContainer()).moveAllWithinPolygon(v);
} else if (selectedPart instanceof Roof) {
if (viewMode == ViewMode.TOP_VIEW) {
final Foundation f = selectedPart.getTopContainer();
if (f.isGroupMaster()) {
final List<Foundation> g = Scene.getInstance().getFoundationGroup(f);
for (final Foundation x : g) {
x.move(v, selectedPart.getGridSize());
}
} else {
f.move(v, selectedPart.getGridSize());
}
}
} else if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
w.move(v);
w.draw();
} else if (selectedPart instanceof SolarCollector) {
final SolarCollector sc = (SolarCollector) selectedPart;
sc.move(v, selectedPart.getGridSize());
selectedPart.draw();
} else if (selectedPart instanceof Tree) {
final Tree t = (Tree) selectedPart;
t.move(v, selectedPart.getGridSize());
t.draw();
} else if (selectedPart instanceof Human) {
final Human h = (Human) selectedPart;
h.move(v, selectedPart.getGridSize());
h.draw();
}
undoManager.addEdit(c);
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
use of org.concord.energy3d.model.HousePart in project energy3d by concord-consortium.
the class SceneManager method hideAllEditPoints.
public void hideAllEditPoints() {
for (final HousePart part : Scene.getInstance().getParts()) {
part.setEditPointsVisible(false);
part.setGridsVisible(false);
part.setLinePatternVisible(false);
}
selectedPart = null;
refresh = true;
}
use of org.concord.energy3d.model.HousePart 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