Forráskód Böngészése

RountangleEditor: creating Rountangle constructs the EdgeCreation deltas directly (no need to go through NodeState + NodeState shouldn't be manually constructed) + cleanup.

Joeri Exelmans 2 éve
szülő
commit
dab226d86b

+ 11 - 3
src/frontend/rountangleEditor/RountangleEditor.tsx

@@ -107,7 +107,6 @@ export class RountangleEditor extends React.Component<RountangleEditorProps, {}>
     createValueDeltas(nodeState: NodeState, values: [string,PrimitiveValue][]): PrimitiveDelta[] {
         const deltas: PrimitiveDelta[] = [];
         for (const [edgeLabel, value] of values) {
-            // JE: create all deltas manually instead of using this function, because we know all relevant information at this point
             deltas.push(...nodeState.getDeltasForSetEdge(this.props.primitiveRegistry, edgeLabel, this.props.graphDeltaExecutor.getValueState(value)));
         }
         return deltas;
@@ -123,8 +122,17 @@ export class RountangleEditor extends React.Component<RountangleEditorProps, {}>
                 uuid = new UUID(action.id);
                 const createRountangleNodeDelta = this.props.primitiveRegistry.newNodeCreation(uuid);
                 deltas.push(createRountangleNodeDelta);
-                nodeState = new NodeState(createRountangleNodeDelta);
-                deltas.push(...this.createValueDeltas(nodeState, [["type","Rountangle"],["label",action.name],["x",action.posX],["y",action.posY],["z-index",action.posZ],["width",action.width],["height",action.height]]));
+                const edgeSpec: [string,PrimitiveValue][] = [
+                    ["type","Rountangle"],
+                    ["label",action.name],
+                    ["x",action.posX],
+                    ["y",action.posY],
+                    ["z-index",action.posZ],
+                    ["width",action.width],
+                    ["height",action.height],
+                ];
+                deltas.push(... edgeSpec.map(([edgeLabel, value]) =>
+                    this.props.primitiveRegistry.newEdgeCreation(createRountangleNodeDelta, edgeLabel, value)));
                 break;
             case 'moveRountangle':
                 // get nodeState from clicked node

+ 4 - 2
src/onion/delete_node.ts

@@ -12,11 +12,13 @@ import {
   PrimitiveRegistry,
 } from "./primitive_delta";
 
-// Alternative (i.e., produces the same result) as NodeState.getDeltasForDelete
+// Alternative (i.e., produces the same result) to NodeState.getDeltasForDelete.
 // Not as fast, but useful in case one does not have a graph state to play around with, and still faster than constructing a graph state from scratch.
-// Returns a set of deltas to execute the deletion of the given node, and all its incoming and outgoing deltas.
+// Returns a set of deltas to execute the deletion of the given node, and all its incoming and outgoing deltas, with the right dependencies.
 export function getDeltasForDelete(primitiveRegistry: PrimitiveRegistry, nodeCreation: NodeCreation, currentVersion: Version, additionalDependencies: PrimitiveDelta[] = []): (EdgeUpdate|NodeDeletion)[] {
+  // Returns whether 'delta' is part of the given version. Only when this is the case, can 'delta' be a dependency of our deletion.
   const awareOf = delta => additionalDependencies.includes(delta) || currentVersion.containsPrimitive(delta);
+
   const edgeUnsettings: EdgeUpdate[] = [];
   const incomingEdgeDependencies = nodeCreation.incomingEdges.filter(delta => awareOf(delta)).map(incomingEdge => {
     let current = incomingEdge;

+ 0 - 8
src/onion/primitive_registry.ts

@@ -1,8 +0,0 @@
-import {
-  PrimitiveDelta,
-  NodeCreation,
-  NodeDeletion,
-  EdgeCreation,
-  EdgeUpdate,
-} from "./primitive_delta";
-

+ 1 - 34
src/parser/trivial_parser.ts

@@ -51,7 +51,6 @@ export class TrivialParser implements Parser, Renderer {
   // We can use pretty much the same code for both parsing and rendering :)
   propagate_change(parse: boolean, sourceComposite: CompositeDelta, sourceParent: Version, corrParent: Version, targetParent: Version) {
     const sourceDeltas = [...sourceComposite.iterPrimitiveDeltas()];
-    const parentCorrDeltas = new Set(corrParent.iterPrimitiveDeltas());
 
     const targetDeltas: Delta[] = [];
     const corrDeltas: Delta[] = [];
@@ -78,22 +77,6 @@ export class TrivialParser implements Parser, Renderer {
         const sourceDeletion = sourceDelta; // alias for readability :)
         const sourceCreation = sourceDeletion.creation; // the NodeCreation of the deleted cs node
 
-        // // sourceDeletion will conflict with our earlier 'corr2Source' EdgeCreation delta:
-        // const corr2Source = sourceDeletion.edgeTargetConflicts.find(e => parentCorrDeltas.has(e));
-        // if (corr2Source === undefined) {
-        //   throw new Error("Assertion failed: When a node is deleted, the deletion must be conflicting with the creation of an incoming correspondence edge.");
-        // }
-        // const corrCreation = corr2Source.getCreation().source;
-        // // corrCreation will have only one other outgoing edge:
-        // const corr2Target = corrCreation.outgoingEdges.find(e => e !== corr2Source);
-        // if (corr2Target === undefined) {
-        //   throw new Error("Assertion failed: The correspondence node must have two outgoing edges, one to CS and one to AS.");
-        // }
-        // const targetCreation = corr2Target.target.getTarget();
-        // if (! (targetCreation instanceof NodeCreation)) {
-        //   throw new Error("Assertion failed: The target of corr2Target must be the NodeCreation of the AS node.");
-        // }
-
         // edge from corrspondence node to CS node:
         const corr2Source = sourceCreation.incomingEdges.find(delta => delta instanceof EdgeCreation && delta.label === corr2SourceLabel);
         if (corr2Source === undefined || !(corr2Source instanceof EdgeCreation)) {
@@ -119,26 +102,12 @@ export class TrivialParser implements Parser, Renderer {
         const targetDeletion = getDeltasForDelete(this.primitiveRegistry, targetCreation, targetParent);
         const targetDeletion1 = getDeltasForDelete(this.primitiveRegistry, targetCreation, corrParent, corrDeletion);
 
-        // const targetDeletion = new NodeDeletion(targetCreation, [], []); // only part of AS
-        // const targetDeletion1 = new NodeDeletion(targetCreation, [], [corrDeletion]); // only part of CORR (override)
-
         // We already have the deletion in the CS model, so we only need to create another one to be used in the CORR model:
         const sourceDeletion1 = getDeltasForDelete(this.primitiveRegistry, sourceCreation, corrParent, corrDeletion);
-        // const sourceDeletion1 = new NodeDeletion(sourceCreation,
-        //   sourceDeletion.deletedOutgoingEdges.map(d => corrParent.findOverride("cs", d) || d),
-        //   sourceDeletion.afterIncomingEdges.map(d => corrParent.findOverride("cs", d) || d).concat(corrDeletion));
 
         sourceOverrides.set(sourceDeletion, sourceDeletion1[sourceDeletion1.length-1]);
         targetOverrides.set(targetDeletion[targetDeletion.length-1], targetDeletion1[targetDeletion1.length-1]);
 
-        console.log({
-          targetDeletion,
-          targetDeletion1,
-          corrDeletion,
-          sourceDeletion,
-          sourceDeletion1,
-        })
-
         targetDeltas.push(...targetDeletion);
         corrDeltas.push(...corrDeletion);
       }
@@ -150,8 +119,6 @@ export class TrivialParser implements Parser, Renderer {
     const sourceDeltas1 = sourceDeltas.map(d => sourceOverrides.get(d) || d);
     const targetDeltas1 = targetDeltas.map(d => targetOverrides.get(d) || d);
 
-    console.log({sourceDeltas1, targetDeltas1})
-
     // the order in which corr-deltas are put in corrComposite matters - deltas must occur after their dependencies:
     const orderedByDependency: Delta[] = [];
     visitPartialOrdering(
@@ -170,7 +137,7 @@ export class TrivialParser implements Parser, Renderer {
     return result;
   }
 
-  parse(csComposite: CompositeDelta, csParent: Version, corrParent: Version, asParent): ParseOrRenderResult {
+  parse(csComposite: CompositeDelta, csParent: Version, corrParent: Version, asParent: Version): ParseOrRenderResult {
     const {
       corrComposite,
       targetComposite,