From 9b8c78539183f2125fed358b51a02a6813a7cc82 Mon Sep 17 00:00:00 2001 From: Maxim Klypin <70793854+L140-beep@users.noreply.github.com> Date: Fri, 6 Sep 2024 18:46:47 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BA=D0=BB=D1=8E?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=20=D1=82=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=80=D0=B5=D0=B6=D0=B8?= =?UTF-8?q?=D0=BC=20=D0=BF=D1=80=D0=B8=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B5=20=D1=87=D1=82=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=D0=B8?= =?UTF-8?q?=D0=B7=D1=83=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20=D1=81=D1=85?= =?UTF-8?q?=D0=B5=D0=BC=D1=8B=20(#444)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/lib/data/GraphmlBuilder.ts | 5 +- src/renderer/src/lib/data/GraphmlParser.ts | 61 +++++++++++++++------ 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/renderer/src/lib/data/GraphmlBuilder.ts b/src/renderer/src/lib/data/GraphmlBuilder.ts index f4f3b43b7..5af77a734 100644 --- a/src/renderer/src/lib/data/GraphmlBuilder.ts +++ b/src/renderer/src/lib/data/GraphmlBuilder.ts @@ -38,13 +38,14 @@ import { isDefaultComponent, convertDefaultComponent } from './ElementsValidator import { ChoiceState } from '../drawable'; -function exportMeta(meta: Meta, platform: Platform): CGMLMeta { +function exportMeta(visual: boolean, meta: Meta, platform: Platform): CGMLMeta { return { id: 'coreMeta', values: { ...meta, standardVersion: platform.standardVersion, platformVersion: platform.version, + lapkiVisual: visual.toString(), }, }; } @@ -391,7 +392,7 @@ export function exportCGML(elements: Elements): string { throw new Error('Внутренняя ошибка! В момент экспорта схемы платформа не инициализирована.'); } const cgmlElements: CGMLElements = createEmptyElements(); - cgmlElements.meta = exportMeta(elements.meta, platform); + cgmlElements.meta = exportMeta(elements.visual, elements.meta, platform); cgmlElements.format = 'Cyberiada-GraphML-1.0'; cgmlElements.platform = elements.platform; cgmlElements.stateMachines['g'] = { diff --git a/src/renderer/src/lib/data/GraphmlParser.ts b/src/renderer/src/lib/data/GraphmlParser.ts index 3336350fd..9ed8523e2 100644 --- a/src/renderer/src/lib/data/GraphmlParser.ts +++ b/src/renderer/src/lib/data/GraphmlParser.ts @@ -100,7 +100,7 @@ function initArgList(args: string[]): ArgList { return argList; } -const pictoRegex: RegExp = /.+\..+\(.*\)/; +const pictoRegex: RegExp = /.+(\.|::).+\(.*\)/; function parseAction(unproccessedAction: string): Action | undefined | string { if (unproccessedAction === '') { @@ -208,11 +208,16 @@ function getChoices(rawChoices: { [id: string]: CGMLVertex }): { return choices; } -function getStates(rawStates: { [id: string]: CGMLState }): { [id: string]: State } { +function getStates(rawStates: { [id: string]: CGMLState }): [boolean, { [id: string]: State }] { const states: { [id: string]: State } = {}; + let visual = true; for (const rawStateId in rawStates) { const rawState = rawStates[rawStateId]; - const events: EventData[] = actionsToEventData(rawState.actions); + const [isVisual, events] = actionsToEventData(rawState.actions); + // FIXME: здесь нужно пробросить предупреждение о переходе в тестовый режим + if (!isVisual) { + visual = false; + } states[rawStateId] = { // ПОМЕНЯТЬ ЦВЕТ color: rawState.color ?? '#FFFFFF', @@ -229,11 +234,14 @@ function getStates(rawStates: { [id: string]: CGMLState }): { [id: string]: Stat events: events, }; } - return states; + return [visual, states]; } -function actionsToEventData(rawActions: Array): EventData[] { +function actionsToEventData( + rawActions: Array +): [boolean, EventData[]] { const eventDataArr: EventData[] = []; + let visual = true; for (const action of rawActions) { const eventData: EventData = { trigger: { @@ -244,6 +252,10 @@ function actionsToEventData(rawActions: Array }; if (action.action) { const parsedActions = parseActions(action.action); + if (parsedActions && !Array.isArray(parsedActions)) { + // FIXME: здесь нужно пробросить предупреждение о переходе в тестовый режим + visual = false; + } if (parsedActions) { eventData.do = parsedActions; } @@ -259,13 +271,14 @@ function actionsToEventData(rawActions: Array } eventDataArr.push(eventData); } - return eventDataArr; + return [visual, eventDataArr]; } function getTransitions( rawTransitions: Record -): Record { +): [boolean, Record] { const transitions: Record = {}; + let visual = true; for (const id in rawTransitions) { const rawTransition = rawTransitions[id]; if (rawTransition.actions.length == 0) { @@ -277,20 +290,23 @@ function getTransitions( continue; } // В данный момент поддерживается только один триггер на переход - const eventData = actionsToEventData(rawTransition.actions)[0]; + const [isVisual, eventData] = actionsToEventData(rawTransition.actions); + if (!isVisual) { + visual = isVisual; + } transitions[id] = { sourceId: rawTransition.source, targetId: rawTransition.target, color: rawTransition.color, label: { position: rawTransition.labelPosition ?? { x: -1, y: -1 }, - trigger: eventData.trigger, - do: eventData.do, - condition: eventData.condition, + trigger: eventData[0].trigger, + do: eventData[0].do, + condition: eventData[0].condition, }, }; } - return transitions; + return [visual, transitions]; } function getComponents(rawComponents: { [id: string]: CGMLComponent }): { @@ -427,12 +443,16 @@ function getAllComponent(platformComponents: { [name: string]: ComponentProto }) return components; } -function getVisualFlag(rawMeta: CGMLMeta, platformVisual: boolean): boolean { +function getVisualFlag( + rawMeta: CGMLMeta, + platformVisual: boolean, + computedValue: boolean // Значение, которое выдал парсер после парсинга схемы +): boolean { const visual: boolean | undefined = rawMeta.values['lapkiVisual'] ? rawMeta.values['lapkiVisual'] === 'true' : undefined; if (visual === undefined) { - return platformVisual; + return platformVisual && computedValue; } if (visual && !platformVisual) { throw new Error( @@ -464,6 +484,7 @@ export function importGraphml( if (!isPlatformAvailable(rawElements.platform)) { throw new Error(`Неизвестная платформа ${rawElements.platform}.`); } + // TODO: добавить в платформу флаг для статических компонентов const platform: Platform | undefined = getPlatform(elements.platform); if (platform === undefined) { @@ -478,8 +499,10 @@ export function importGraphml( elements.initialStates = getInitialStates(sm.initialStates); elements.finalStates = getFinals(sm.finals); elements.notes = sm.notes; - elements.states = getStates(sm.states); - elements.transitions = getTransitions(sm.transitions); + const [stateVisual, states] = getStates(sm.states); + elements.states = states; + const [transitionVisual, transitions] = getTransitions(sm.transitions); + elements.transitions = transitions; elements.states = labelStateParameters( elements.states, platform.components, @@ -492,7 +515,11 @@ export function importGraphml( platform.components, elements.components ); - elements.visual = getVisualFlag(rawElements.meta, platform.visual); + elements.visual = getVisualFlag( + rawElements.meta, + platform.visual, + stateVisual && transitionVisual + ); validateElements(elements, platform); return elements;