use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.
the class TestListener method testGraphChangedWithGraph.
// Test commented out as TopComponent launches GUI panels which don't execute in the test environment
@Test
public void testGraphChangedWithGraph() throws Exception {
QualityControlAutoVetter.destroyInstance();
QualityControlAutoVetter instance = QualityControlAutoVetter.getInstance();
assertNull(instance.getCurrentGraph());
assertEquals(instance.getlastGlobalModCount(), (long) 0);
// Open a new graph
graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
// Add camera attribute
final WritableGraph wg = graph.getWritableGraph("TEST", true);
try {
final int cameraAttrId = VisualConcept.GraphAttribute.CAMERA.ensure(wg);
// Change camera attribute
final Camera camera = new Camera();
camera.setVisibilityLow(0.67f);
wg.setObjectValue(cameraAttrId, 0, camera);
} finally {
wg.commit();
}
try {
// Sleep until after pluginExecution thread has returned
Thread.sleep(1000);
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
// Set the current graph
instance.newActiveGraph(graph);
QualityControlAutoVetter.getInstance().graphChanged(null);
assertNotEquals(instance.getlastGlobalModCount(), (long) 0);
assertNotEquals(instance.getlastCameraModCount(), (long) 0);
}
use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.
the class DefaultInteractionEventHandler method mouseReleased.
@SuppressWarnings("fallthrough")
@Override
public void mouseReleased(final MouseEvent event) {
queue.add(wg -> {
// If a button other than the original button is involved, or a mouse pressed event was never registered (can happen when left clicking off a context menu) we ignore this event.
if (eventState.isMousePressed() && eventState.getCurrentButton() == event.getButton()) {
if (wg != null) {
// Once all buttons have been released, we immediately turn hit testing back on
setHitTestingEnabled(true);
final Camera camera = VisualGraphUtilities.getCamera(wg);
// HACK_DPI - Multiply point by DPI scale factor
Point point = event.getPoint();
scaleMousePointByDPIFactor(point);
final Point from;
final Point to;
switch(eventState.getCurrentAction()) {
case SELECTING:
if (eventState.isMouseDragged()) {
performBoxSelection(wg, point, eventState.getPoint(EventState.PRESSED_POINT), event.isShiftDown(), event.isControlDown());
clearSelectionBoxModel();
} else {
// If the mouse has clicked on an element (and neither pan nor control are pressed),
// or has double-clicked on the background, clear the selection.
final boolean clearSelection = !event.isControlDown() && !event.isShiftDown() && (!eventState.getCurrentHitType().equals(HitType.NO_ELEMENT) || event.getClickCount() == 2);
performPointSelection(event.isControlDown(), clearSelection, eventState.getCurrentHitType().elementType, eventState.getCurrentHitId());
}
break;
case FREEFORM_SELECTING:
if (eventState.isMouseDragged()) {
performFreeformSelection(wg, event.isShiftDown(), event.isControlDown());
clearSelectionFreeformModel();
} else {
// If the mouse has clicked on an element (and neither pan nor control are pressed),
// or has double-clicked on the background, clear the selection.
final boolean clearSelection = !event.isControlDown() && !event.isShiftDown() && (!eventState.getCurrentHitType().equals(HitType.NO_ELEMENT) || event.getClickCount() == 2);
performPointSelection(event.isControlDown(), clearSelection, eventState.getCurrentHitType().elementType, eventState.getCurrentHitId());
}
break;
case CREATING:
setCurrentCreationMode(camera, point, wg, event);
break;
case ROTATING:
if (!eventState.isMouseDragged() && eventState.getCurrentHitType().equals(HitType.VERTEX)) {
final Camera centredCamera = new Camera(camera);
CameraUtilities.setRotationCentre(centredCamera, VisualGraphUtilities.getMixedVertexCoordinates(wg, eventState.getCurrentHitId()));
VisualGraphUtilities.setCamera(wg, centredCamera);
scheduleCameraChangeOperation();
eventState.addEventName(SET_CENTRE_ACTION_NAME);
} else {
eventState.addEventName(ROTATE_ACTION_NAME);
}
break;
// mouse button require the context menu to be displayed.
case DRAG_NODES:
if (eventState.isMouseDragged()) {
from = eventState.getPoint(EventState.DRAG_POINT);
to = point;
performDrag(wg, camera, from, to);
eventState.addEventName(DRAG_ACTION_NAME);
}
// falls through
case PANNING:
if (!eventState.isMouseDragged()) {
showContextMenu(wg, camera, event.getPoint(), eventState.getCurrentHitType().elementType, eventState.getCurrentHitId());
} else {
eventState.addEventName(PAN_ACTION_NAME);
}
break;
default:
break;
}
}
if (!(eventState.getCurrentAction().equals(SceneAction.CREATING) && eventState.getCurrentCreationMode().equals(CreationMode.CREATING_TRANSACTION))) {
eventState.setCurrentAction(SceneAction.NONE);
}
eventState.invalidatePoints(EventState.PRESSED_POINT, EventState.DRAG_POINT, EventState.WHEEL_POINT, EventState.REFERENCE_POINT);
eventState.setNoButton();
}
return 0;
});
}
use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.
the class DefaultInteractionEventHandler method mouseDragged.
/**
* Mouse pressed.
* <p>
* Note: if you right-click on an element, move the mouse to another part of
* the element (ignoring the pop-up menu), and right-press, you don't get a
* mousePressed event.
*
* @param event Mouse event.
*/
@Override
public void mouseDragged(final MouseEvent event) {
queue.add(wg -> {
// If a mouse pressed event was never registered (can happen when left clicking off a context menu) we ignore this event.
// HACK_DPI - Multiply point by DPI scale factor
Point point = event.getPoint();
scaleMousePointByDPIFactor(point);
if (eventState.isMousePressed()) {
if (wg != null) {
final Camera camera = new Camera(VisualGraphUtilities.getCamera(wg));
final Point from;
final Point to;
boolean cameraChange = false;
switch(eventState.getCurrentAction()) {
case ROTATING:
from = eventState.getFirstValidPoint(EventState.DRAG_POINT, EventState.REFERENCE_POINT);
to = point;
final boolean zAxisRotation = !VisualGraphUtilities.isDisplayModeIn3D(wg) || (event.isControlDown() && event.isShiftDown());
if (zAxisRotation) {
CameraUtilities.spin(camera, visualInteraction.convertTranslationToSpin(from, to));
} else {
CameraUtilities.rotate(camera, event.isShiftDown() ? 0 : (from.y - to.y) / 2.0F, event.isControlDown() ? 0 : (from.x - to.x) / 2.0F);
}
cameraChange = true;
break;
case PANNING:
from = eventState.getFirstValidPoint(EventState.DRAG_POINT, EventState.REFERENCE_POINT);
to = point;
final Vector3f panReferencePoint = eventState.hasClosestNode() ? eventState.getClosestNode() : CameraUtilities.getFocusVector(camera);
final Vector3f translation = visualInteraction.convertTranslationToPan(from, to, panReferencePoint);
CameraUtilities.pan(camera, translation.getX(), translation.getY());
cameraChange = true;
break;
case DRAG_NODES:
from = eventState.getFirstValidPoint(EventState.DRAG_POINT, EventState.REFERENCE_POINT);
to = point;
performDrag(wg, camera, from, to);
break;
case SELECTING:
updateSelectionBoxModel(new SelectionBoxModel(eventState.getPoint(EventState.PRESSED_POINT), point));
break;
case FREEFORM_SELECTING:
freeformModel.addPoint(point);
updateSelectionFreeformModel(freeformModel);
break;
default:
break;
}
updateCameraAndNewLine(wg, point, cameraChange ? camera : VisualGraphUtilities.getCamera(wg), cameraChange);
}
eventState.storePoint(point, EventState.DRAG_POINT);
} else if (wg != null) {
// In this case, a button is held down but its pressed event was not registered for whatever reason.
updateHitTestAndNewLine(wg, point);
} else {
// Do nothing
}
return 0;
});
}
use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.
the class GLVisualProcessorGraphTester method createGraph.
public static StoreGraph createGraph() {
StoreGraph g = new StoreGraph();
final int v1 = g.addVertex();
final int v2 = g.addVertex();
final int t1 = g.addTransaction(v1, v2, false);
final int t2 = g.addTransaction(v1, v2, false);
final int t3 = g.addTransaction(v1, v2, true);
final int t4 = g.addTransaction(v2, v1, true);
final int loop = g.addTransaction(v1, v1, false);
final int xAttr = VisualConcept.VertexAttribute.X.ensure(g);
final int yAttr = VisualConcept.VertexAttribute.Y.ensure(g);
final int zAttr = VisualConcept.VertexAttribute.Z.ensure(g);
final int bgIconAttr = VisualConcept.VertexAttribute.BACKGROUND_ICON.ensure(g);
final int iconAttr = VisualConcept.VertexAttribute.FOREGROUND_ICON.ensure(g);
final int backgroundColorAttr = VisualConcept.GraphAttribute.BACKGROUND_COLOR.ensure(g);
final int cameraAttr = VisualConcept.GraphAttribute.CAMERA.ensure(g);
final int blazeAttr = VisualConcept.VertexAttribute.BLAZE.ensure(g);
final int widthAttr = VisualConcept.TransactionAttribute.WIDTH.ensure(g);
g.setDoubleValue(widthAttr, t1, 0.8);
g.setDoubleValue(widthAttr, t2, 1.0);
g.setDoubleValue(widthAttr, t3, 1.2);
g.setDoubleValue(widthAttr, t4, 1.4);
g.setDoubleValue(widthAttr, loop, 1.6);
g.setIntValue(xAttr, v1, -2);
g.setIntValue(xAttr, v2, 2);
g.setIntValue(yAttr, v1, 0);
g.setIntValue(yAttr, v2, 0);
g.setIntValue(zAttr, v1, -10);
g.setIntValue(zAttr, v2, -10);
g.setStringValue(bgIconAttr, v1, DefaultIconProvider.FLAT_SQUARE.getExtendedName());
g.setStringValue(bgIconAttr, v2, DefaultIconProvider.FLAT_SQUARE.getExtendedName());
g.setStringValue(iconAttr, v1, DefaultIconProvider.UNKNOWN.getExtendedName());
g.setStringValue(iconAttr, v2, DefaultIconProvider.UNKNOWN.getExtendedName());
g.setObjectValue(blazeAttr, v1, new Blaze(0, ConstellationColor.AZURE));
g.setObjectValue(cameraAttr, 0, new Camera());
g.setObjectValue(backgroundColorAttr, 0, ConstellationColor.NIGHT_SKY);
g.setPrimaryKey(GraphElementType.VERTEX, xAttr);
g.setPrimaryKey(GraphElementType.TRANSACTION, widthAttr);
return g;
}
use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.
the class SetCameraVisibilityRange method edit.
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
final float visibilityLow = parameters.getFloatValue(VISIBILITY_LOW_ID);
final float visibilityHigh = parameters.getFloatValue(VISIBILITY_HIGH_ID);
// Get a copy of the graph's current camera.
final int cameraAttribute = VisualConcept.GraphAttribute.CAMERA.get(graph);
if (cameraAttribute != Graph.NOT_FOUND) {
final Camera oldCamera = graph.getObjectValue(cameraAttribute, 0);
final Camera camera = new Camera(oldCamera);
camera.setVisibilityLow(visibilityLow);
camera.setVisibilityHigh(visibilityHigh);
graph.setObjectValue(cameraAttribute, 0, camera);
}
}
Aggregations