Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add template to flat view #2717

Merged
merged 28 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
644d847
extract beaker funcs and find valid number
shawnyama Feb 9, 2024
43e08e3
Merge branch 'main' into model-edit-polish
shawnyama Feb 9, 2024
6b3bd18
proper number appeneded
shawnyama Feb 12, 2024
68a4204
determine num optimize
shawnyama Feb 12, 2024
d31782c
Merge branch 'main' into model-edit-polish
shawnyama Feb 12, 2024
e5724ca
optimize num determination and allow template dragging after flattene…
shawnyama Feb 12, 2024
d43b830
move beaker funcs
shawnyama Feb 13, 2024
77904a0
improve comments and sanity check
shawnyama Feb 13, 2024
b8341e4
Merge branch 'main' into model-edit-polish
shawnyama Feb 13, 2024
9f13d2a
sync frontend amr with mira properly true auto run
shawnyama Feb 13, 2024
04b85d5
add templateCard property to ModelMetadata
shawnyama Feb 13, 2024
4bc6a5a
Merge branch 'main' into model-edit-polish
shawnyama Feb 13, 2024
2834962
Merge branch 'main' into model-edit-polish
shawnyama Feb 13, 2024
26831cb
debug
shawnyama Feb 13, 2024
faa840c
diagram appears in notebook tab
shawnyama Feb 13, 2024
20c23a6
guard clause and edge case
shawnyama Feb 14, 2024
5b4eb2d
add to flat view
shawnyama Feb 14, 2024
192ba73
merge
shawnyama Feb 14, 2024
4185c8b
only add templates in UI first if in flat view
shawnyama Feb 14, 2024
9891d13
templates are passed to decomposed view once flattenedTemplates are l…
shawnyama Feb 14, 2024
1d8a729
Merge branch 'main' into add-to-flat-view
shawnyama Feb 14, 2024
8ae5ca2
add junction and default edge if required
shawnyama Feb 15, 2024
2d55bbd
rm copilot garbage suggestion
shawnyama Feb 15, 2024
cd09593
draw edges in decomp view based on flat view
shawnyama Feb 16, 2024
660efbb
Merge branch 'main' into add-to-flat-view
shawnyama Feb 16, 2024
f86656f
clean findTemplateCard function and fix new lint issues
shawnyama Feb 16, 2024
90cd5d5
Merge branch 'main' into add-to-flat-view
shawnyama Feb 16, 2024
dfabbed
Merge branch 'main' into add-to-flat-view
shawnyama Feb 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
toggle though since in some designs it is used outside of tera-model-diagram and others are inside -->
<SelectButton
:model-value="currentModelFormat"
@change="if ($event.value) currentModelFormat = $event.value;"
@change="if ($event.value) onEditorFormatSwitch($event.value);"
:options="modelFormatOptions"
>
<template #option="{ option }">
Expand Down Expand Up @@ -191,7 +191,7 @@ const currentTemplates = computed(() =>
: flattenedTemplates.value
);
const cards = computed<ModelTemplateCard[]>(
() => currentTemplates.value.models.map(({ metadata }) => metadata.templateCard) ?? []
() => currentTemplates.value.models.map(({ metadata }) => metadata?.templateCard) ?? []
);
const junctions = computed<ModelTemplateJunction[]>(() => currentTemplates.value.junctions);

Expand All @@ -207,7 +207,6 @@ const isCreatingNewEdge = computed(

function collisionFn(p: Position): boolean {
const buffer = 50;

return cards.value.some(({ x, y, width, height }) => {
const withinXRange = p.x >= x - buffer && p.x <= x + width + buffer;
const withinYRange = p.y >= y - buffer && p.y <= y + height + buffer;
Expand Down Expand Up @@ -274,17 +273,36 @@ function createNewEdge(card: ModelTemplateCard, portId: string) {
junctionIdForNewEdge &&
target.cardId !== newEdge.value.target.cardId // Prevents connecting to the same card
) {
modelTemplatingService.addEdgeInKernel(
props.kernelManager,
currentTemplates.value,
junctionIdForNewEdge,
target,
newEdge.value.target,
currentPortPosition,
outputCode,
syncWithMiraModel,
interpolatePointsForCurve
);
if (currentModelFormat.value === EditorFormat.Decomposed) {
modelTemplatingService.addEdgeInKernel(
props.kernelManager,
currentTemplates.value,
junctionIdForNewEdge,
target,
newEdge.value.target,
currentPortPosition,
outputCode,
syncWithMiraModel,
interpolatePointsForCurve
);
} else {
modelTemplatingService.addEdgeInView(
currentTemplates.value,
junctionIdForNewEdge,
target,
currentPortPosition,
interpolatePointsForCurve
);
// Once the second edge is drawn, reflect changes in decomposed view - once done, everything in the flattened view will be "merged"
modelTemplatingService.reflectFlattenedEditInDecomposedView(
props.kernelManager,
flattenedTemplates.value,
decomposedTemplates.value,
outputCode,
syncWithMiraModel,
interpolatePointsForCurve
);
}
cancelNewEdge();
}
}
Expand Down Expand Up @@ -337,13 +355,27 @@ function updateNewCardPosition(event) {
function onDrop(event) {
updateNewCardPosition(event);

modelTemplatingService.addDecomposedTemplateInKernel(
props.kernelManager,
currentTemplates.value,
newModelTemplate.value,
outputCode,
syncWithMiraModel
);
if (currentModelFormat.value === EditorFormat.Decomposed) {
modelTemplatingService.addDecomposedTemplateInKernel(
props.kernelManager,
decomposedTemplates.value,
newModelTemplate.value,
outputCode,
syncWithMiraModel
);
}
// Add decomposed template to the flattened view
else {
// If we are in the flattened view just add it in the UI - it will be added in kernel once linked to the flattened model
// Cards that aren't linked in the flattened view will be removed once the view switches to decomposed
const decomposedTemplateToAdd = modelTemplatingService.prepareDecomposedTemplateAddition(
flattenedTemplates.value,
newModelTemplate.value
);
if (decomposedTemplateToAdd) {
modelTemplatingService.addTemplateInView(flattenedTemplates.value, decomposedTemplateToAdd);
}
}

newModelTemplate.value = null;
}
Expand Down Expand Up @@ -403,15 +435,21 @@ function mouseUpdate(event: MouseEvent) {
prevY = event.y;
}

// Triggered after syncWithMiraModel() in parent
function refreshFlattenedTemplate() {
if (props.model) {
flattenedTemplates.value = modelTemplatingService.initializeModelTemplates();
modelTemplatingService.updateFlattenedTemplateInView(props.model, flattenedTemplates.value);
}
}

function onEditorFormatSwitch(newFormat: EditorFormat) {
currentModelFormat.value = newFormat;
if (newFormat === EditorFormat.Decomposed) refreshFlattenedTemplate(); // Removes unlinked decomposed templates
}

watch(
() => [props.model],
() => {
if (props.model) {
flattenedTemplates.value = modelTemplatingService.initializeModelTemplates();
modelTemplatingService.updateFlattenedTemplateInView(props.model, flattenedTemplates.value);
}
}
() => refreshFlattenedTemplate() // Triggered after syncWithMiraModel() in parent
);

onMounted(() => {
Expand Down
Loading
Loading