AlloyTools / org.alloytools.alloy

Alloy is a language for describing structures and a tool for exploring them. It has been used in a wide range of applications from finding holes in security mechanisms to designing telephone switching networks. This repository contains the code for the tool.
Other
723 stars 122 forks source link

DOT graph generation via CLI wrapper #211

Open swamp-agr opened 1 year ago

swamp-agr commented 1 year ago

Hello,

Hope you are doing well.

Summary

Please find attached the link to CLI script for generating DOT files for model instances without triggering any GUI at all: https://gist.github.com/swamp-agr/560f0d9bf8dc034f99d6055a5a197285 (logic located below L2040).

Comments are welcome.

Motivation

Implementation

Disclaimer: I am not Java programmer and, to be honest, I am not familiar with OOP. I wrote some Java code in the past but it was too long ago. Now I am using Haskell for my job and also in my spare time.

import java.awt.BasicStroke;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.Line2D;
import java.awt.geom.RoundRectangle2D;
import java.awt.geom.CubicCurve2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;

Result

By making local copies of mentioned classes and removing all that Swing/AWT stuff (except java.awt.Color) I was able to draw DOT file and produce the plot.

Before: photo_2023-04-13 19 30 11

After: photo_2023-04-13 19 30 15

Conclusions

Nevertheless, thank you for your great work! It was quite fun to play with the Alloy app and with Alloy API too. 😄

Feel free to close the issue if you decide not to have such a feature in upstream.

Best Regards, Andrey

swamp-agr commented 1 year ago

Since yesterday Alloy 6 is generating images (for model instances) and GIFs (for temporal models) via both Telegram Bot interface and CLI Wrapper described in a previous message.

You can probably add it to your show cases.