Class ProcessDiagramExporter

java.lang.Object
neqsim.process.processmodel.diagram.ProcessDiagramExporter
All Implemented Interfaces:
Serializable

public class ProcessDiagramExporter extends Object implements Serializable
Exports ProcessSystem as professional oil & gas style process flow diagrams.

This class generates PFDs that follow industry conventions:

  • Gravity logic - Gas flows upward, liquids flow downward
  • Functional zoning - Separation center, gas processing upper, liquid lower
  • Equipment semantics - Separator outlets positioned correctly
  • Phase-aware styling - Stream colors based on phase
  • Stable layout - Same model produces same diagram every time

Supported output formats:

  • DOT - Graphviz DOT format (text)
  • SVG - Scalable Vector Graphics (requires Graphviz installed)
  • PNG - Portable Network Graphics (requires Graphviz installed)
  • PDF - Portable Document Format (requires Graphviz installed)

Usage:

ProcessDiagramExporter exporter = new ProcessDiagramExporter(processSystem);
String dot = exporter.toDOT();
exporter.exportSVG(Path.of("diagram.svg"));
Version:
1.0
Author:
NeqSim
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • logger

      private static final org.apache.logging.log4j.Logger logger
    • processSystem

      private final ProcessSystem processSystem
      The process system to export.
    • layoutPolicy

      private final PFDLayoutPolicy layoutPolicy
      The layout policy for determining equipment positions.
    • diagramStyle

      private DiagramStyle diagramStyle
      Diagram style (NEQSIM, HYSYS, PROII, ASPEN_PLUS).
    • detailLevel

      private DiagramDetailLevel detailLevel
      Detail level for the diagram.
    • title

      private String title
      Graph title.
    • verticalLayout

      private boolean verticalLayout
      Whether to use vertical (top-down) layout.
    • useClusters

      private boolean useClusters
      Whether to group equipment by role into clusters.
    • showLegend

      private boolean showLegend
      Whether to show the legend.
    • showStreamValues

      private boolean showStreamValues
      Whether to show stream values on edges.
    • useStreamTables

      private boolean useStreamTables
      Whether to show stream values as tables (HTML labels).
    • highlightRecycles

      private boolean highlightRecycles
      Whether to highlight recycle streams with special styling.
    • showControlEquipment

      private boolean showControlEquipment
      Whether to show control equipment (adjusters, calculators).
    • showDexpiMetadata

      private boolean showDexpiMetadata
      Whether to show DEXPI metadata (tag names, line numbers, fluid codes).
  • Constructor Details

    • ProcessDiagramExporter

      public ProcessDiagramExporter(ProcessSystem processSystem)
      Creates a new diagram exporter for a process system.
      Parameters:
      processSystem - the process system to export
    • ProcessDiagramExporter

      public ProcessDiagramExporter(ProcessSystem processSystem, PFDLayoutPolicy layoutPolicy)
      Creates a new diagram exporter with custom layout policy.
      Parameters:
      processSystem - the process system
      layoutPolicy - the layout policy to use
  • Method Details

    • toDOT

      public String toDOT()
      Exports the process system as a DOT format string.
      Returns:
      Graphviz DOT format string
    • generateDOT

      private String generateDOT(ProcessGraph graph)
      Generates DOT format from a ProcessGraph.
      Parameters:
      graph - the process graph
      Returns:
      DOT format string
    • appendGraphAttributes

      private void appendGraphAttributes(StringBuilder sb)
      Appends graph-level attributes for professional appearance.

      Industry-standard oil & gas PFD layout:

      • Left-to-right process flow (rankdir=LR)
      • Vertical phase stratification via subgraphs and ordering
      • Feed streams enter from left, products exit right
      • Gas at top, oil in middle, water at bottom
      Parameters:
      sb - the string builder
    • groupNodesByRank

      private Map<Integer, List<ProcessNode>> groupNodesByRank(ProcessGraph graph)
      Groups nodes by their rank level for vertical layout.
      Parameters:
      graph - the process graph
      Returns:
      map of rank level to nodes
    • appendRankSubgraphs

      private void appendRankSubgraphs(StringBuilder sb, Map<Integer, List<ProcessNode>> rankGroups, ProcessGraph graph)
      Appends rank and ordering constraints for industry PFD layout.

      Creates a layout where:

      • Feed streams are on the LEFT (rank=min)
      • Product streams are on the RIGHT (rank=max)
      • Gas processing is at TOP (min vertical position)
      • Oil processing is in MIDDLE
      • Water processing is at BOTTOM (max vertical position)
      Parameters:
      sb - the string builder
      rankGroups - the rank groups (by phase)
      graph - the process graph
    • findCentralProcessingNode

      private ProcessNode findCentralProcessingNode(ProcessGraph graph, List<ProcessNode> feedNodes, List<ProcessNode> productNodes)
      Finds a central processing node (typically a separator) to anchor the layout.
      Parameters:
      graph - the process graph
      feedNodes - feed nodes to exclude
      productNodes - product nodes to exclude
      Returns:
      a central processing node, or null if none found
    • appendPhaseZoneOrdering

      private void appendPhaseZoneOrdering(StringBuilder sb, ProcessGraph graph, List<ProcessNode> sourceNodes, List<ProcessNode> sinkNodes)
      Appends vertical ordering constraints based on phase zones.

      Uses invisible edges to enforce vertical ordering: Gas → Separation → Oil → Water

      Parameters:
      sb - the string builder
      graph - the process graph
      sourceNodes - feed streams (excluded from phase ordering)
      sinkNodes - product streams (included for water zone vertical positioning)
    • appendRankSubgraphsLegacy

      private void appendRankSubgraphsLegacy(StringBuilder sb, Map<Integer, List<ProcessNode>> rankGroups)
      Appends rank subgraphs for enforcing vertical ordering (legacy method).

      Deprecated: Use appendRankSubgraphs(StringBuilder, Map, ProcessGraph) instead.

      Parameters:
      sb - the string builder
      rankGroups - the rank groups
    • appendClusters

      private void appendClusters(StringBuilder sb, ProcessGraph graph)
      Appends cluster subgraphs for grouping equipment by phase zone.

      Creates visual clusters with vertical ordering:

      • Gas Processing (top) - light blue background
      • Separation (center anchor) - yellow/gold background
      • Oil Processing (middle) - tan/brown background
      • Water Processing (bottom) - blue background
      Parameters:
      sb - the string builder
      graph - the process graph
    • shouldIncludeNode

      private boolean shouldIncludeNode(ProcessNode node)
      Determines if a node should be included in the diagram.
      Parameters:
      node - the process node
      Returns:
      true if the node should be included
    • shouldIncludeEdge

      private boolean shouldIncludeEdge(ProcessEdge edge)
      Determines if an edge should be included in the diagram.
      Parameters:
      edge - the process edge
      Returns:
      true if the edge should be included
    • appendNode

      private void appendNode(StringBuilder sb, ProcessNode node)
      Appends a node definition to the DOT output.
      Parameters:
      sb - the string builder
      node - the process node
    • appendMixerSplitterNode

      private void appendMixerSplitterNode(StringBuilder sb, String name, boolean isSplitter)
      Appends a mixer or splitter node with triangle shape. Mixer: right-pointing (▶) - multiple inlets, single outlet Splitter: left-pointing (◀) - single inlet, multiple outlets
      Parameters:
      sb - the string builder
      name - the equipment name
      isSplitter - true if splitter, false if mixer
    • appendValveNode

      private void appendValveNode(StringBuilder sb, String name, String lowerType)
      Appends a valve node with bowtie symbol like HYSYS. Classic PFD valve symbol with two triangles tip-to-tip.
      Parameters:
      sb - the string builder
      name - the valve name
      lowerType - the lowercase valve type for color selection
    • appendHeatExchangerNode

      private void appendHeatExchangerNode(StringBuilder sb, ProcessNode node, String name, String type, String lowerType)
      Appends a heat exchanger (heater/cooler) node with circle shape.
      Parameters:
      sb - the string builder
      node - the process node
      name - the equipment name
      type - the equipment type
      lowerType - the lowercase equipment type
    • appendPumpNode

      private void appendPumpNode(StringBuilder sb, String name)
      Appends a pump node with circle on triangle (standard PFD pump symbol). Circle represents the casing, small circle inside represents impeller, triangle below represents the discharge direction.
      Parameters:
      sb - the string builder
      name - the pump name
    • appendColumnNode

      private void appendColumnNode(StringBuilder sb, String name, String type)
      Appends a column node (absorber, stripper, distillation) with tray visualization.
      Parameters:
      sb - the string builder
      name - the column name
      type - the column type
    • adjustBrightness

      private String adjustBrightness(String hexColor, int amount)
      Adjusts the brightness of a hex color.
      Parameters:
      hexColor - the hex color (e.g., "#FF6347")
      amount - the brightness adjustment (-255 to 255)
      Returns:
      the adjusted hex color
    • escapeHtml

      private String escapeHtml(String text)
      Escapes special characters for HTML labels.
      Parameters:
      text - the text to escape
      Returns:
      the escaped text
    • buildNodeLabel

      private String buildNodeLabel(ProcessEquipmentInterface equipment, String name, String type)
      Builds a node label based on the detail level.
      Parameters:
      equipment - the equipment
      name - the equipment name
      type - the equipment type
      Returns:
      the formatted label
    • appendDexpiMetadata

      private void appendDexpiMetadata(StringBuilder label, ProcessEquipmentInterface equipment)
      Appends DEXPI metadata (tag names, line numbers, fluid codes) to a label.

      This enriches diagram labels with P&ID reference information for equipment imported from DEXPI XML files.

      Parameters:
      label - the label builder to append to
      equipment - the equipment to check for DEXPI metadata
    • appendEdge

      private void appendEdge(StringBuilder sb, ProcessEdge edge)
      Appends an edge definition to the DOT output.
      Parameters:
      sb - the string builder
      edge - the process edge
    • buildStreamLabel

      private String buildStreamLabel(StreamInterface stream, boolean isRecycle)
      Builds a stream label based on display settings.
      Parameters:
      stream - the stream
      isRecycle - whether this is a recycle stream
      Returns:
      the label string (plain text or HTML)
    • buildStreamTextLabel

      private String buildStreamTextLabel(StreamInterface stream, boolean isRecycle)
      Builds a simple text label for a stream.
      Parameters:
      stream - the stream
      isRecycle - whether this is a recycle stream
      Returns:
      the text label
    • buildStreamTableLabel

      private String buildStreamTableLabel(StreamInterface stream, boolean isRecycle)
      Builds an HTML table label for a stream (professional engineering style).
      Parameters:
      stream - the stream
      isRecycle - whether this is a recycle stream
      Returns:
      the HTML table label
    • isSeparator

      private boolean isSeparator(ProcessEquipmentInterface equipment)
      Checks if equipment is a separator type.
      Parameters:
      equipment - the equipment
      Returns:
      true if separator
    • isValve

      private boolean isValve(ProcessEquipmentInterface equipment)
      Checks if equipment is a valve type.
      Parameters:
      equipment - the equipment
      Returns:
      true if valve
    • appendLegend

      private void appendLegend(StringBuilder sb)
      Appends a legend to the diagram.
      Parameters:
      sb - the string builder
    • escapeString

      private String escapeString(String s)
      Escapes a string for use in DOT format.
      Parameters:
      s - the string
      Returns:
      escaped string
    • exportDOT

      public void exportDOT(Path path) throws IOException
      Exports the diagram to a file in DOT format.
      Parameters:
      path - the output file path
      Throws:
      IOException - if writing fails
    • exportSVG

      public void exportSVG(Path path) throws IOException
      Exports the diagram to SVG format using Graphviz.

      Requires Graphviz (dot) to be installed and in PATH.

      Parameters:
      path - the output file path
      Throws:
      IOException - if export fails
    • exportPNG

      public void exportPNG(Path path) throws IOException
      Exports the diagram to PNG format using Graphviz.

      Requires Graphviz (dot) to be installed and in PATH.

      Parameters:
      path - the output file path
      Throws:
      IOException - if export fails
    • exportPDF

      public void exportPDF(Path path) throws IOException
      Exports the diagram to PDF format using Graphviz.

      Requires Graphviz (dot) to be installed and in PATH.

      Parameters:
      path - the output file path
      Throws:
      IOException - if export fails
    • exportWithGraphviz

      private void exportWithGraphviz(Path path, String format) throws IOException
      Exports using Graphviz command-line tool.
      Parameters:
      path - output path
      format - output format (svg, png, pdf)
      Throws:
      IOException - if export fails
    • isGraphvizAvailable

      public static boolean isGraphvizAvailable()
      Checks if Graphviz is available on the system.
      Returns:
      true if Graphviz (dot) is available
    • setTitle

      public ProcessDiagramExporter setTitle(String title)
      Sets the diagram title.
      Parameters:
      title - the title
      Returns:
      this exporter for chaining
    • setDetailLevel

      public ProcessDiagramExporter setDetailLevel(DiagramDetailLevel detailLevel)
      Sets the detail level.
      Parameters:
      detailLevel - the detail level
      Returns:
      this exporter for chaining
    • setDiagramStyle

      public ProcessDiagramExporter setDiagramStyle(DiagramStyle style)
      Sets the diagram style to use for rendering.

      Available styles include:

      Parameters:
      style - the diagram style
      Returns:
      this exporter for chaining
    • getDiagramStyle

      public DiagramStyle getDiagramStyle()
      Gets the current diagram style.
      Returns:
      the diagram style
    • setVerticalLayout

      public ProcessDiagramExporter setVerticalLayout(boolean verticalLayout)
      Sets whether to use vertical (top-down) layout.
      Parameters:
      verticalLayout - true for vertical, false for horizontal
      Returns:
      this exporter for chaining
    • setUseClusters

      public ProcessDiagramExporter setUseClusters(boolean useClusters)
      Sets whether to group equipment into clusters.
      Parameters:
      useClusters - true to use clusters
      Returns:
      this exporter for chaining
    • setShowLegend

      public ProcessDiagramExporter setShowLegend(boolean showLegend)
      Sets whether to show the legend.
      Parameters:
      showLegend - true to show legend
      Returns:
      this exporter for chaining
    • setShowStreamValues

      public ProcessDiagramExporter setShowStreamValues(boolean showStreamValues)
      Sets whether to show stream values on edges.
      Parameters:
      showStreamValues - true to show values
      Returns:
      this exporter for chaining
    • setUseStreamTables

      public ProcessDiagramExporter setUseStreamTables(boolean useStreamTables)
      Sets whether to use HTML tables for stream values.

      When true, stream values are displayed in professional table format with temperature, pressure, and flow rate. When false, values are shown as simple text labels.

      Parameters:
      useStreamTables - true to use tables
      Returns:
      this exporter for chaining
    • setHighlightRecycles

      public ProcessDiagramExporter setHighlightRecycles(boolean highlightRecycles)
      Sets whether to highlight recycle streams.
      Parameters:
      highlightRecycles - true to highlight recycles
      Returns:
      this exporter for chaining
    • setShowControlEquipment

      public ProcessDiagramExporter setShowControlEquipment(boolean showControlEquipment)
      Sets whether to show control equipment (adjusters, calculators, recycles).
      Parameters:
      showControlEquipment - true to show control equipment
      Returns:
      this exporter for chaining
    • setShowDexpiMetadata

      public ProcessDiagramExporter setShowDexpiMetadata(boolean showDexpiMetadata)
      Sets whether to show DEXPI metadata (tag names, line numbers, fluid codes) in labels.

      When enabled, equipment imported from DEXPI XML files will have their P&ID reference information (line numbers, fluid codes) displayed in the diagram labels.

      Parameters:
      showDexpiMetadata - true to show DEXPI metadata
      Returns:
      this exporter for chaining