Skip to content
Snippets Groups Projects
Commit df4aa861 authored by dgelessus's avatar dgelessus
Browse files

Use new high-level dot and table visualization APIs

parent 17c0c37a
Branches
No related tags found
Loading
Checking pipeline status
...@@ -15,7 +15,7 @@ import com.google.inject.Inject; ...@@ -15,7 +15,7 @@ import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import de.prob.animator.command.GetAllDotCommands; import de.prob.animator.command.GetAllDotCommands;
import de.prob.animator.command.GetSvgForVisualizationCommand; import de.prob.animator.domainobjects.DotVisualizationCommand;
import de.prob.animator.domainobjects.DynamicCommandItem; import de.prob.animator.domainobjects.DynamicCommandItem;
import de.prob.animator.domainobjects.FormulaExpand; import de.prob.animator.domainobjects.FormulaExpand;
import de.prob.animator.domainobjects.IEvalElement; import de.prob.animator.domainobjects.IEvalElement;
...@@ -105,9 +105,8 @@ public final class DotCommand implements Command { ...@@ -105,9 +105,8 @@ public final class DotCommand implements Command {
} }
final Trace trace = this.animationSelector.getCurrentTrace(); final Trace trace = this.animationSelector.getCurrentTrace();
final GetAllDotCommands cmd1 = new GetAllDotCommands(trace.getCurrentState()); final DotVisualizationCommand dotCommand = DotVisualizationCommand.getAll(trace.getCurrentState())
trace.getStateSpace().execute(cmd1); .stream()
final DynamicCommandItem item = cmd1.getCommands().stream()
.filter(i -> command.equals(i.getCommand())) .filter(i -> command.equals(i.getCommand()))
.findAny() .findAny()
.orElseThrow(() -> new UserErrorException("No such dot command: " + command)); .orElseThrow(() -> new UserErrorException("No such dot command: " + command));
...@@ -118,9 +117,8 @@ public final class DotCommand implements Command { ...@@ -118,9 +117,8 @@ public final class DotCommand implements Command {
} catch (final IOException e) { } catch (final IOException e) {
throw new UncheckedIOException("Failed to create temp file", e); throw new UncheckedIOException("Failed to create temp file", e);
} }
final GetSvgForVisualizationCommand cmd2 = new GetSvgForVisualizationCommand(trace.getCurrentState(), item, outPath.toFile(), dotCommandArgs);
// Provide source code (if any) to error highlighter // Provide source code (if any) to error highlighter
final Runnable execute = () -> trace.getStateSpace().execute(cmd2); final Runnable execute = () -> dotCommand.visualizeAsSvgToFile(outPath, dotCommandArgs);
if (code != null) { if (code != null) {
CommandUtils.withSourceCode(code, execute); CommandUtils.withSourceCode(code, execute);
} else { } else {
...@@ -153,7 +151,8 @@ public final class DotCommand implements Command { ...@@ -153,7 +151,8 @@ public final class DotCommand implements Command {
final GetAllDotCommands cmd = new GetAllDotCommands(trace.getCurrentState()); final GetAllDotCommands cmd = new GetAllDotCommands(trace.getCurrentState());
trace.getStateSpace().execute(cmd); trace.getStateSpace().execute(cmd);
final String prefix = commandName.substring(0, at); final String prefix = commandName.substring(0, at);
final List<String> commands = cmd.getCommands().stream() final List<String> commands = DotVisualizationCommand.getAll(trace.getCurrentState())
.stream()
.filter(DynamicCommandItem::isAvailable) .filter(DynamicCommandItem::isAvailable)
.map(DynamicCommandItem::getCommand) .map(DynamicCommandItem::getCommand)
.filter(s -> s.startsWith(prefix)) .filter(s -> s.startsWith(prefix))
......
...@@ -7,12 +7,10 @@ import java.util.stream.Collectors; ...@@ -7,12 +7,10 @@ import java.util.stream.Collectors;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import de.prob.animator.command.GetAllTableCommands;
import de.prob.animator.command.GetTableForVisualizationCommand;
import de.prob.animator.domainobjects.DynamicCommandItem;
import de.prob.animator.domainobjects.FormulaExpand; import de.prob.animator.domainobjects.FormulaExpand;
import de.prob.animator.domainobjects.IEvalElement; import de.prob.animator.domainobjects.IEvalElement;
import de.prob.animator.domainobjects.TableData; import de.prob.animator.domainobjects.TableData;
import de.prob.animator.domainobjects.TableVisualizationCommand;
import de.prob.statespace.AnimationSelector; import de.prob.statespace.AnimationSelector;
import de.prob.statespace.Trace; import de.prob.statespace.Trace;
import de.prob.unicode.UnicodeTranslator; import de.prob.unicode.UnicodeTranslator;
...@@ -75,15 +73,12 @@ public final class TableCommand implements Command { ...@@ -75,15 +73,12 @@ public final class TableCommand implements Command {
final String code = kernel.insertLetVariables(args.get(EXPRESSION_PARAM)); final String code = kernel.insertLetVariables(args.get(EXPRESSION_PARAM));
final IEvalElement formula = CommandUtils.withSourceCode(code, () -> kernel.parseFormula(code, FormulaExpand.EXPAND)); final IEvalElement formula = CommandUtils.withSourceCode(code, () -> kernel.parseFormula(code, FormulaExpand.EXPAND));
final GetAllTableCommands cmd1 = new GetAllTableCommands(trace.getCurrentState()); final TableData table = TableVisualizationCommand.getAll(trace.getCurrentState())
trace.getStateSpace().execute(cmd1); .stream()
final DynamicCommandItem dc = cmd1.getCommands().stream()
.filter(c -> "expr_as_table".equals(c.getCommand())) .filter(c -> "expr_as_table".equals(c.getCommand()))
.findAny() .findAny()
.orElseThrow(AssertionError::new); .orElseThrow(AssertionError::new)
final GetTableForVisualizationCommand cmd2 = new GetTableForVisualizationCommand(trace.getCurrentState(), dc, Collections.singletonList(formula)); .visualize(Collections.singletonList(formula));
trace.getStateSpace().execute(cmd2);
final TableData table = cmd2.getTable();
final StringBuilder sbPlain = new StringBuilder(); final StringBuilder sbPlain = new StringBuilder();
final StringBuilder sbMarkdown = new StringBuilder(); final StringBuilder sbMarkdown = new StringBuilder();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment