use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class LayersViewControllerNGTest method setupGraph.
/**
* Set up a graph with two vertices and two transactions on layer 1.
*/
private void setupGraph() {
graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
try {
WritableGraph wg = graph.getWritableGraph("", true);
// Create LayerMask attributes
layerMaskV = LayersConcept.VertexAttribute.LAYER_MASK.ensure(wg);
layerMaskT = LayersConcept.TransactionAttribute.LAYER_MASK.ensure(wg);
// Create LayerVisilibity Attributes
layerVisibilityV = LayersConcept.VertexAttribute.LAYER_VISIBILITY.ensure(wg);
layerVisibilityT = LayersConcept.TransactionAttribute.LAYER_VISIBILITY.ensure(wg);
// Create Selected Attributes
selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
// Adding 2 Vertices - not selected, layer 1, visible
vxId1 = wg.addVertex();
wg.setIntValue(layerMaskV, vxId1, 1);
wg.setFloatValue(layerVisibilityV, vxId1, 1.0f);
wg.setBooleanValue(selectedV, vxId1, false);
vxId2 = wg.addVertex();
wg.setIntValue(layerMaskV, vxId2, 1);
wg.setFloatValue(layerVisibilityV, vxId2, 1.0f);
wg.setBooleanValue(selectedV, vxId2, false);
// Adding 2 Transactions - not selected, layer 1, visible
txId1 = wg.addTransaction(vxId1, vxId2, true);
wg.setIntValue(layerMaskT, txId1, 1);
wg.setFloatValue(layerVisibilityT, txId1, 1.0f);
wg.setBooleanValue(selectedT, txId1, false);
txId2 = wg.addTransaction(vxId1, vxId2, false);
wg.setIntValue(layerMaskT, txId2, 1);
wg.setFloatValue(layerVisibilityT, vxId2, 1.0f);
wg.setBooleanValue(selectedT, vxId2, false);
wg.commit();
} catch (final InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class LayersDualGraphSyncNGTest method dynamicLayerChangeTest.
@Test
public void dynamicLayerChangeTest() throws InterruptedException, PluginException {
// Check Vertex set correctly
ReadableGraph readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getIntValue(layerMaskV, vxId1), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 1.0f);
assertEquals(readableGraph.getIntValue(layerMaskV, vxId2), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getIntValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 1.0f);
} finally {
readableGraph.release();
}
WritableGraph writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(bitmaskAttributeId, 0, 0b10);
writableGraph.setLongValue(layerMaskV, vxId1, 3);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 0.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 0.0f);
} finally {
writableGraph.commit();
}
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(bitmaskAttributeId, 0), 0b10);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId1), 1.0f);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId2), 1);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId2), 0.0f);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
// change an attribute to trigger switching of graph object within dual graph
PluginExecution.withPlugin(new SimpleEditPlugin("Test: change attribute value") {
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
final int maxTransactionsId = VisualConcept.GraphAttribute.MAX_TRANSACTIONS.ensure(graph);
graph.setLongValue(maxTransactionsId, 0, 9);
}
}).executeNow(graph);
// Check Vertex set correctly on second graph of dualgraph
readableGraph = graph.getReadableGraph();
try {
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId1), 1.0f);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId2), 1);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId2), 0.0f);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(layerMaskV, vxId1, 3);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 1.0f);
} finally {
writableGraph.commit();
}
// PluginExecution.withPlugin(new UpdateLayerSelectionPlugin(queries, 1)).executeNow(graph);
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 1.0f);
} finally {
readableGraph.release();
}
writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(layerMaskV, vxId1, 3);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 0.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 0b101);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 0.0f);
} finally {
writableGraph.commit();
}
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 0.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 0b101);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(layerMaskV, vxId1, 3);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 0b101);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 1.0f);
} finally {
writableGraph.commit();
}
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 0b101);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 1.0f);
} finally {
readableGraph.release();
}
writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(layerMaskV, vxId1, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 0.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 0b111);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 0.0f);
} finally {
writableGraph.commit();
}
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 0.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 0b111);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
PluginExecution.withPlugin(new SimpleEditPlugin("Test: change attribute value") {
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
final int maxTransactionsId = VisualConcept.GraphAttribute.MAX_TRANSACTIONS.ensure(graph);
graph.setIntValue(maxTransactionsId, 0, 9);
}
}).executeNow(graph);
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 0.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 0b111);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class LayersDualGraphSyncNGTest method setUpMethod.
@BeforeMethod
public void setUpMethod() throws Exception {
queries = new ArrayList();
graph = new DualGraph(null);
final WritableGraph writableGraph = graph.getWritableGraph("test", true);
try {
bitmaskAttributeId = LayersViewConcept.GraphAttribute.LAYER_MASK_SELECTED.ensure(writableGraph);
// Create LayerMask attributes
layerMaskV = LayersConcept.VertexAttribute.LAYER_MASK.ensure(writableGraph);
if (layerMaskV == Graph.NOT_FOUND) {
fail();
}
layerMaskT = LayersConcept.TransactionAttribute.LAYER_MASK.ensure(writableGraph);
if (layerMaskT == Graph.NOT_FOUND) {
fail();
}
// Create LayerVisilibity Attributes
layerVisibilityV = LayersConcept.VertexAttribute.LAYER_VISIBILITY.ensure(writableGraph);
if (layerVisibilityV == Graph.NOT_FOUND) {
fail();
}
layerVisibilityT = LayersConcept.TransactionAttribute.LAYER_VISIBILITY.ensure(writableGraph);
if (layerVisibilityT == Graph.NOT_FOUND) {
fail();
}
// Create Selected Attributes
selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(writableGraph);
if (selectedV == Graph.NOT_FOUND) {
fail();
}
selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(writableGraph);
if (selectedT == Graph.NOT_FOUND) {
fail();
}
// Create Color Attributes
colorV = VisualConcept.VertexAttribute.COLOR.ensure(writableGraph);
if (colorV == Graph.NOT_FOUND) {
fail();
}
colorT = VisualConcept.TransactionAttribute.COLOR.ensure(writableGraph);
if (colorT == Graph.NOT_FOUND) {
fail();
}
vx1Color = ConstellationColor.getColorValue("#ed76b1");
vx2Color = ConstellationColor.getColorValue("#eb78b2");
vx3Color = ConstellationColor.getColorValue("#ee71b3");
// Adding 2 Vertices layer 1, visible
vxId1 = writableGraph.addVertex();
vxId2 = writableGraph.addVertex();
vxId3 = writableGraph.addVertex();
writableGraph.setObjectValue(colorV, vxId1, vx1Color);
writableGraph.setObjectValue(colorV, vxId2, vx2Color);
writableGraph.setObjectValue(colorV, vxId3, vx3Color);
} finally {
writableGraph.commit();
}
final WritableGraph writableGraph2 = graph.getWritableGraph("test2", true);
try {
writableGraph2.setLongValue(layerMaskV, vxId1, 1);
writableGraph2.setFloatValue(layerVisibilityV, vxId1, 1.0f);
writableGraph2.setBooleanValue(selectedV, vxId1, false);
vxId2 = writableGraph2.addVertex();
writableGraph2.setLongValue(layerMaskV, vxId2, 1);
writableGraph2.setFloatValue(layerVisibilityV, vxId2, 1.0f);
writableGraph2.setBooleanValue(selectedV, vxId2, false);
} finally {
writableGraph2.commit();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class GraphVisualAccessNGTest method testGetDrawFlagsAttributeAdded.
/**
* Test of getDrawFlags method when attribute is added, of class
* GraphVisualAccess.
*
* @throws InterruptedException
*/
@Test
public void testGetDrawFlagsAttributeAdded() throws InterruptedException {
System.out.println("getDrawFlagsAttributeAdded");
final WritableGraph wg = graph.getWritableGraph("Graph Visual Access", true);
try {
final int graphDrawFlagsAttribute = VisualConcept.GraphAttribute.DRAW_FLAGS.ensure(wg);
wg.setObjectValue(graphDrawFlagsAttribute, 0, new DrawFlags(DrawFlags.NODE_LABELS));
} finally {
wg.commit();
}
final GraphVisualAccess instance = new GraphVisualAccess(graph);
instance.beginUpdate();
instance.updateInternally();
final DrawFlags flags = instance.getDrawFlags();
instance.endUpdate();
assertEquals(flags.getFlags(), 4);
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class GraphVisualAccessNGTest method testGetVertexVisibilityAttributesAdded.
/**
* Test of getVertexVisibility method when attributes are added, of class
* GraphVisualAccess.
*
* @throws InterruptedException
*/
@Test
public void testGetVertexVisibilityAttributesAdded() throws InterruptedException {
System.out.println("getVertexVisibilityAttributesAdded");
WritableGraph wg = graph.getWritableGraph("Graph Visual Access", true);
try {
final int vertexLayerVisibilityAttribute = LayersConcept.VertexAttribute.LAYER_VISIBILITY.ensure(wg);
wg.setObjectValue(vertexLayerVisibilityAttribute, vxId1, 0.4f);
wg.setObjectValue(vertexLayerVisibilityAttribute, vxId2, 0.75f);
} finally {
wg.commit();
}
final GraphVisualAccess instance = new GraphVisualAccess(graph);
instance.beginUpdate();
instance.updateInternally();
float visibility1 = instance.getVertexVisibility(0);
float visibility2 = instance.getVertexVisibility(1);
instance.endUpdate();
assertEquals(visibility1, 0.4f);
assertEquals(visibility2, 0.75f);
wg = graph.getWritableGraph("Graph Visual Access", true);
try {
final int vertexVisibilityAttribute = VisualConcept.VertexAttribute.VISIBILITY.ensure(wg);
wg.setObjectValue(vertexVisibilityAttribute, vxId1, 0.5f);
wg.setObjectValue(vertexVisibilityAttribute, vxId2, 0.2f);
} finally {
wg.commit();
}
instance.beginUpdate();
instance.updateInternally();
visibility1 = instance.getVertexVisibility(0);
visibility2 = instance.getVertexVisibility(1);
instance.endUpdate();
assertEquals(visibility1, 0.2f);
assertEquals(visibility2, 0.15f);
}
Aggregations