use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.
the class GraphRecordStoreUtilities method copyTransactionsBetweenVertices.
/**
* Take transactions between two constituents of an expanded composite and
* add to a {@link RecordStore} copies of these transactions. This is used
* when a composite node is contracted so that these transactions can be *
* added back when it is expanded.
*
* @param graph A {@link GraphReadMethods} from which the
* {@link RecordStore} will be created.
* @param recordStore The {@link RecordStore} to add the transactions to.
* @param fromVxId The vertex id of the first composite constituent.
* @param toVxId The vertex id of the second composite constituent.
* @param fromId The id of the first composite constituent to be used in the
* {@link RecordStore}.
* @param toId The id of the first composite constituent to be used in the
* {@link RecordStore}.
*/
public static void copyTransactionsBetweenVertices(final GraphReadMethods graph, final RecordStore recordStore, final int fromVxId, final int toVxId, final String fromId, final String toId) {
final int transactionAttributeCount = graph.getAttributeCount(GraphElementType.TRANSACTION);
final Attribute[] transactionAttributes = new Attribute[transactionAttributeCount];
for (int a = 0; a < transactionAttributeCount; a++) {
int attributeId = graph.getAttribute(GraphElementType.TRANSACTION, a);
transactionAttributes[a] = new GraphAttribute(graph, attributeId);
}
final int lxId = graph.getLink(fromVxId, toVxId);
if (lxId != Graph.NOT_FOUND) {
final int transactionCount = graph.getLinkTransactionCount(lxId);
for (int t = 0; t < transactionCount; t++) {
final int transaction = graph.getLinkTransaction(lxId, t);
final int source = graph.getTransactionSourceVertex(transaction);
final String sourceId = source == fromVxId ? fromId : toId;
final String destId = source == fromVxId ? toId : fromId;
recordStore.add();
for (Attribute transactionAttribute : transactionAttributes) {
final String value = graph.getStringValue(transactionAttribute.getId(), transaction);
recordStore.set(TRANSACTION + transactionAttribute.getName() + "<" + transactionAttribute.getAttributeType() + ">", value);
}
if (graph.getTransactionDirection(transaction) == Graph.UNDIRECTED) {
recordStore.set(TRANSACTION + DIRECTED_KEY, FALSE);
}
recordStore.set(TRANSACTION + ID, COPY + String.format(NUMBER_STRING_STRING_FORMAT, transaction, sourceId, destId));
recordStore.set(SOURCE + ID, sourceId);
recordStore.set(DESTINATION + ID, destId);
}
}
}
use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.
the class CopyGraphUtilities method copyGraphToGraph.
/**
* Adapted from CopySelectedElementsPlugin.makeGraph
*
* @param original - the Graph to copy elements from
* @param graph - the Graph to copy elements to
* @param copyAll - whether to copy all elements or just the selected ones
*/
public static void copyGraphToGraph(final GraphReadMethods original, final GraphWriteMethods graph, final boolean copyAll) {
final int vertexSelected = original.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.SELECTED.getName());
final int transactionSelected = original.getAttribute(GraphElementType.TRANSACTION, VisualConcept.TransactionAttribute.SELECTED.getName());
final int[] attributeTranslation = new int[original.getAttributeCapacity()];
// Copy the attributes.
for (final GraphElementType type : GraphElementType.values()) {
final int attributeCount = original.getAttributeCount(type);
for (int attributePosition = 0; attributePosition < attributeCount; attributePosition++) {
int originalAttributeId = original.getAttribute(type, attributePosition);
final Attribute attribute = new GraphAttribute(original, originalAttributeId);
int newAttributeId = graph.getAttribute(type, attribute.getName());
if (newAttributeId == Graph.NOT_FOUND) {
newAttributeId = graph.addAttribute(type, attribute.getAttributeType(), attribute.getName(), attribute.getDescription(), attribute.getDefaultValue(), null);
}
attributeTranslation[originalAttributeId] = newAttributeId;
if (type == GraphElementType.GRAPH) {
graph.setObjectValue(newAttributeId, 0, original.getObjectValue(originalAttributeId, 0));
}
}
}
// Copy the vertices.
final int[] vertexTranslation = new int[original.getVertexCapacity()];
for (int position = 0; position < original.getVertexCount(); position++) {
final int originalVertex = original.getVertex(position);
if (copyAll || vertexSelected == Graph.NOT_FOUND || original.getBooleanValue(vertexSelected, originalVertex)) {
final int newVertex = graph.addVertex();
vertexTranslation[originalVertex] = newVertex;
for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.VERTEX); attributePosition++) {
final int originalAttributeId = original.getAttribute(GraphElementType.VERTEX, attributePosition);
final int newAttributeId = attributeTranslation[originalAttributeId];
graph.setObjectValue(newAttributeId, newVertex, original.getObjectValue(originalAttributeId, originalVertex));
}
}
}
// Copy the transactions.
final int[] edgeTranslation = new int[original.getEdgeCapacity()];
final int[] linkTranslation = new int[original.getLinkCapacity()];
for (int position = 0; position < original.getTransactionCount(); position++) {
final int originalTransaction = original.getTransaction(position);
if (!copyAll && ((transactionSelected != Graph.NOT_FOUND && !original.getBooleanValue(transactionSelected, originalTransaction)) || (vertexSelected != Graph.NOT_FOUND && (!original.getBooleanValue(vertexSelected, original.getTransactionSourceVertex(originalTransaction)) || !original.getBooleanValue(vertexSelected, original.getTransactionDestinationVertex(originalTransaction)))))) {
continue;
}
final int sourceVertex = vertexTranslation[original.getTransactionSourceVertex(originalTransaction)];
final int destinationVertex = vertexTranslation[original.getTransactionDestinationVertex(originalTransaction)];
final boolean directed = original.getTransactionDirection(originalTransaction) < 2;
final int newTransaction = graph.addTransaction(sourceVertex, destinationVertex, directed);
// add the edge translations
final int originalEdge = original.getTransactionEdge(originalTransaction);
final int newEdge = graph.getTransactionEdge(newTransaction);
edgeTranslation[originalEdge] = newEdge;
// add the link translations
final int originalLink = original.getTransactionLink(originalTransaction);
final int newLink = graph.getTransactionLink(newTransaction);
linkTranslation[originalLink] = newLink;
for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.TRANSACTION); attributePosition++) {
final int originalAttributeId = original.getAttribute(GraphElementType.TRANSACTION, attributePosition);
final int newAttributeId = attributeTranslation[originalAttributeId];
graph.setObjectValue(newAttributeId, newTransaction, original.getObjectValue(originalAttributeId, originalTransaction));
}
}
// Copy the edges
for (int position = 0; position < original.getEdgeCount(); position++) {
final int originalEdge = original.getEdge(position);
if (!copyAll && ((transactionSelected != Graph.NOT_FOUND && !original.getBooleanValue(transactionSelected, originalEdge)) || (vertexSelected != Graph.NOT_FOUND && (!original.getBooleanValue(vertexSelected, original.getEdgeSourceVertex(originalEdge)) || !original.getBooleanValue(vertexSelected, original.getEdgeDestinationVertex(originalEdge)))))) {
continue;
}
for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.EDGE); attributePosition++) {
final int originalAttributeId = original.getAttribute(GraphElementType.EDGE, attributePosition);
final int newAttributeId = attributeTranslation[originalAttributeId];
graph.setObjectValue(newAttributeId, edgeTranslation[originalEdge], original.getObjectValue(originalAttributeId, originalEdge));
}
}
// Copy the links
for (int position = 0; position < original.getLinkCount(); position++) {
final int originalLink = original.getLink(position);
if (!copyAll && ((transactionSelected != Graph.NOT_FOUND && !original.getBooleanValue(transactionSelected, originalLink)) || (vertexSelected != Graph.NOT_FOUND && (!original.getBooleanValue(vertexSelected, original.getEdgeSourceVertex(originalLink)) || !original.getBooleanValue(vertexSelected, original.getEdgeDestinationVertex(originalLink)))))) {
continue;
}
for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.LINK); attributePosition++) {
final int originalAttributeId = original.getAttribute(GraphElementType.LINK, attributePosition);
final int newAttributeId = attributeTranslation[originalAttributeId];
graph.setObjectValue(newAttributeId, linkTranslation[originalLink], original.getObjectValue(originalAttributeId, originalLink));
}
}
}
use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.
the class CopyGraphUtilities method copyGraphTypeElements.
/**
* Copy a graph attribute and its values to a new graph
*
* @param original Original graph
* @param graph New graph
*/
public static void copyGraphTypeElements(final GraphReadMethods original, final GraphWriteMethods graph) {
final int attributeCount = original.getAttributeCount(GraphElementType.GRAPH);
for (int attributePosition = 0; attributePosition < attributeCount; attributePosition++) {
int originalAttributeId = original.getAttribute(GraphElementType.GRAPH, attributePosition);
final Attribute attribute = new GraphAttribute(original, originalAttributeId);
int newAttributeId = graph.getAttribute(GraphElementType.GRAPH, attribute.getName());
if (newAttributeId == Graph.NOT_FOUND) {
newAttributeId = graph.addAttribute(GraphElementType.GRAPH, attribute.getAttributeType(), attribute.getName(), attribute.getDescription(), attribute.getDefaultValue(), null);
}
graph.setObjectValue(newAttributeId, 0, original.getObjectValue(originalAttributeId, 0));
}
}
use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.
the class ImportController method updateAutoAddedAttributes.
/**
* Get the attributes that will automatically be added to the attribute
* list.
*
* @param elementType
* @param attributes
* @param rg
*/
private void updateAutoAddedAttributes(final GraphElementType elementType, final Map<String, Attribute> attributes, final GraphReadMethods rg, final boolean showSchemaAttributes) {
attributes.clear();
// Add attributes from the graph
int attributeCount = rg.getAttributeCount(elementType);
for (int i = 0; i < attributeCount; i++) {
int attributeId = rg.getAttribute(elementType, i);
Attribute attribute = new GraphAttribute(rg, attributeId);
attributes.put(attribute.getName(), attribute);
}
// Add attributes from the schema
if (showSchemaAttributes && rg.getSchema() != null) {
final SchemaFactory factory = rg.getSchema().getFactory();
for (final SchemaAttribute sattr : factory.getRegisteredAttributes(elementType).values()) {
final Attribute attribute = new GraphAttribute(elementType, sattr.getAttributeType(), sattr.getName(), sattr.getDescription());
if (!attributes.containsKey(attribute.getName())) {
attributes.put(attribute.getName(), attribute);
}
}
}
// Add pseudo-attributes
if (elementType == GraphElementType.TRANSACTION) {
final Attribute attribute = new GraphAttribute(elementType, BooleanAttributeDescription.ATTRIBUTE_NAME, DIRECTED, "Is this transaction directed?");
attributes.put(attribute.getName(), attribute);
}
// Add primary keys
for (int key : rg.getPrimaryKey(elementType)) {
keys.add(key);
}
}
use of au.gov.asd.tac.constellation.graph.Attribute in project constellation by constellation-app.
the class ImportController method updateDisplayedAttributes.
public void updateDisplayedAttributes() {
if (configurationPane != null) {
displayedVertexAttributes = createDisplayedAttributes(autoAddedVertexAttributes, manuallyAddedVertexAttributes);
displayedTransactionAttributes = createDisplayedAttributes(autoAddedTransactionAttributes, manuallyAddedTransactionAttributes);
for (Attribute attribute : configurationPane.getAllocatedAttributes()) {
if (attribute.getElementType() == GraphElementType.VERTEX) {
if (!displayedVertexAttributes.containsKey(attribute.getName())) {
Attribute newAttribute = new NewAttribute(attribute);
displayedVertexAttributes.put(newAttribute.getName(), newAttribute);
}
} else {
if (!displayedTransactionAttributes.containsKey(attribute.getName())) {
Attribute newAttribute = new NewAttribute(attribute);
displayedTransactionAttributes.put(newAttribute.getName(), newAttribute);
}
}
}
configurationPane.setDisplayedAttributes(displayedVertexAttributes, displayedTransactionAttributes, keys);
}
}
Aggregations