Class ProcessDiagramExporter
- All Implemented Interfaces:
Serializable
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 Summary
FieldsModifier and TypeFieldDescriptionprivate DiagramDetailLevelDetail level for the diagram.private DiagramStyleDiagram style (NEQSIM, HYSYS, PROII, ASPEN_PLUS).private booleanWhether to highlight recycle streams with special styling.private final PFDLayoutPolicyThe layout policy for determining equipment positions.private static final org.apache.logging.log4j.Loggerprivate final ProcessSystemThe process system to export.private static final longprivate booleanWhether to show control equipment (adjusters, calculators).private booleanWhether to show DEXPI metadata (tag names, line numbers, fluid codes).private booleanWhether to show the legend.private booleanWhether to show stream values on edges.private StringGraph title.private booleanWhether to group equipment by role into clusters.private booleanWhether to show stream values as tables (HTML labels).private booleanWhether to use vertical (top-down) layout. -
Constructor Summary
ConstructorsConstructorDescriptionProcessDiagramExporter(ProcessSystem processSystem) Creates a new diagram exporter for a process system.ProcessDiagramExporter(ProcessSystem processSystem, PFDLayoutPolicy layoutPolicy) Creates a new diagram exporter with custom layout policy. -
Method Summary
Modifier and TypeMethodDescriptionprivate StringadjustBrightness(String hexColor, int amount) Adjusts the brightness of a hex color.private voidappendClusters(StringBuilder sb, ProcessGraph graph) Appends cluster subgraphs for grouping equipment by phase zone.private voidappendColumnNode(StringBuilder sb, String name, String type) Appends a column node (absorber, stripper, distillation) with tray visualization.private voidappendDexpiMetadata(StringBuilder label, ProcessEquipmentInterface equipment) Appends DEXPI metadata (tag names, line numbers, fluid codes) to a label.private voidappendEdge(StringBuilder sb, ProcessEdge edge) Appends an edge definition to the DOT output.private voidAppends graph-level attributes for professional appearance.private voidappendHeatExchangerNode(StringBuilder sb, ProcessNode node, String name, String type, String lowerType) Appends a heat exchanger (heater/cooler) node with circle shape.private voidAppends a legend to the diagram.private voidappendMixerSplitterNode(StringBuilder sb, String name, boolean isSplitter) Appends a mixer or splitter node with triangle shape.private voidappendNode(StringBuilder sb, ProcessNode node) Appends a node definition to the DOT output.private voidappendPhaseZoneOrdering(StringBuilder sb, ProcessGraph graph, List<ProcessNode> sourceNodes, List<ProcessNode> sinkNodes) Appends vertical ordering constraints based on phase zones.private voidappendPumpNode(StringBuilder sb, String name) Appends a pump node with circle on triangle (standard PFD pump symbol).private voidappendRankSubgraphs(StringBuilder sb, Map<Integer, List<ProcessNode>> rankGroups, ProcessGraph graph) Appends rank and ordering constraints for industry PFD layout.private voidappendRankSubgraphsLegacy(StringBuilder sb, Map<Integer, List<ProcessNode>> rankGroups) Appends rank subgraphs for enforcing vertical ordering (legacy method).private voidappendValveNode(StringBuilder sb, String name, String lowerType) Appends a valve node with bowtie symbol like HYSYS.private StringbuildNodeLabel(ProcessEquipmentInterface equipment, String name, String type) Builds a node label based on the detail level.private StringbuildStreamLabel(StreamInterface stream, boolean isRecycle) Builds a stream label based on display settings.private StringbuildStreamTableLabel(StreamInterface stream, boolean isRecycle) Builds an HTML table label for a stream (professional engineering style).private StringbuildStreamTextLabel(StreamInterface stream, boolean isRecycle) Builds a simple text label for a stream.private StringescapeHtml(String text) Escapes special characters for HTML labels.private StringEscapes a string for use in DOT format.voidExports the diagram to a file in DOT format.voidExports the diagram to PDF format using Graphviz.voidExports the diagram to PNG format using Graphviz.voidExports the diagram to SVG format using Graphviz.private voidexportWithGraphviz(Path path, String format) Exports using Graphviz command-line tool.private ProcessNodefindCentralProcessingNode(ProcessGraph graph, List<ProcessNode> feedNodes, List<ProcessNode> productNodes) Finds a central processing node (typically a separator) to anchor the layout.private StringgenerateDOT(ProcessGraph graph) Generates DOT format from a ProcessGraph.Gets the current diagram style.private Map<Integer, List<ProcessNode>> groupNodesByRank(ProcessGraph graph) Groups nodes by their rank level for vertical layout.static booleanChecks if Graphviz is available on the system.private booleanisSeparator(ProcessEquipmentInterface equipment) Checks if equipment is a separator type.private booleanisValve(ProcessEquipmentInterface equipment) Checks if equipment is a valve type.setDetailLevel(DiagramDetailLevel detailLevel) Sets the detail level.setDiagramStyle(DiagramStyle style) Sets the diagram style to use for rendering.setHighlightRecycles(boolean highlightRecycles) Sets whether to highlight recycle streams.setShowControlEquipment(boolean showControlEquipment) Sets whether to show control equipment (adjusters, calculators, recycles).setShowDexpiMetadata(boolean showDexpiMetadata) Sets whether to show DEXPI metadata (tag names, line numbers, fluid codes) in labels.setShowLegend(boolean showLegend) Sets whether to show the legend.setShowStreamValues(boolean showStreamValues) Sets whether to show stream values on edges.Sets the diagram title.setUseClusters(boolean useClusters) Sets whether to group equipment into clusters.setUseStreamTables(boolean useStreamTables) Sets whether to use HTML tables for stream values.setVerticalLayout(boolean verticalLayout) Sets whether to use vertical (top-down) layout.private booleanshouldIncludeEdge(ProcessEdge edge) Determines if an edge should be included in the diagram.private booleanshouldIncludeNode(ProcessNode node) Determines if a node should be included in the diagram.toDOT()Exports the process system as a DOT format string.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
logger
private static final org.apache.logging.log4j.Logger logger -
processSystem
The process system to export. -
layoutPolicy
The layout policy for determining equipment positions. -
diagramStyle
Diagram style (NEQSIM, HYSYS, PROII, ASPEN_PLUS). -
detailLevel
Detail level for the diagram. -
title
Graph title. -
verticalLayout
private boolean verticalLayoutWhether to use vertical (top-down) layout. -
useClusters
private boolean useClustersWhether to group equipment by role into clusters. -
showLegend
private boolean showLegendWhether to show the legend. -
showStreamValues
private boolean showStreamValuesWhether to show stream values on edges. -
useStreamTables
private boolean useStreamTablesWhether to show stream values as tables (HTML labels). -
highlightRecycles
private boolean highlightRecyclesWhether to highlight recycle streams with special styling. -
showControlEquipment
private boolean showControlEquipmentWhether to show control equipment (adjusters, calculators). -
showDexpiMetadata
private boolean showDexpiMetadataWhether to show DEXPI metadata (tag names, line numbers, fluid codes).
-
-
Constructor Details
-
ProcessDiagramExporter
Creates a new diagram exporter for a process system.- Parameters:
processSystem- the process system to export
-
ProcessDiagramExporter
Creates a new diagram exporter with custom layout policy.- Parameters:
processSystem- the process systemlayoutPolicy- the layout policy to use
-
-
Method Details
-
toDOT
Exports the process system as a DOT format string.- Returns:
- Graphviz DOT format string
-
generateDOT
Generates DOT format from a ProcessGraph.- Parameters:
graph- the process graph- Returns:
- DOT format string
-
appendGraphAttributes
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
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 builderrankGroups- 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 graphfeedNodes- feed nodes to excludeproductNodes- 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 buildergraph- the process graphsourceNodes- 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 builderrankGroups- the rank groups
-
appendClusters
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 buildergraph- the process graph
-
shouldIncludeNode
Determines if a node should be included in the diagram.- Parameters:
node- the process node- Returns:
- true if the node should be included
-
shouldIncludeEdge
Determines if an edge should be included in the diagram.- Parameters:
edge- the process edge- Returns:
- true if the edge should be included
-
appendNode
Appends a node definition to the DOT output.- Parameters:
sb- the string buildernode- the process node
-
appendMixerSplitterNode
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 buildername- the equipment nameisSplitter- true if splitter, false if mixer
-
appendValveNode
Appends a valve node with bowtie symbol like HYSYS. Classic PFD valve symbol with two triangles tip-to-tip.- Parameters:
sb- the string buildername- the valve namelowerType- 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 buildernode- the process nodename- the equipment nametype- the equipment typelowerType- the lowercase equipment type
-
appendPumpNode
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 buildername- the pump name
-
appendColumnNode
Appends a column node (absorber, stripper, distillation) with tray visualization.- Parameters:
sb- the string buildername- the column nametype- the column type
-
adjustBrightness
-
escapeHtml
-
buildNodeLabel
Builds a node label based on the detail level.- Parameters:
equipment- the equipmentname- the equipment nametype- the equipment type- Returns:
- the formatted label
-
appendDexpiMetadata
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 toequipment- the equipment to check for DEXPI metadata
-
appendEdge
Appends an edge definition to the DOT output.- Parameters:
sb- the string builderedge- the process edge
-
buildStreamLabel
Builds a stream label based on display settings.- Parameters:
stream- the streamisRecycle- whether this is a recycle stream- Returns:
- the label string (plain text or HTML)
-
buildStreamTextLabel
Builds a simple text label for a stream.- Parameters:
stream- the streamisRecycle- whether this is a recycle stream- Returns:
- the text label
-
buildStreamTableLabel
Builds an HTML table label for a stream (professional engineering style).- Parameters:
stream- the streamisRecycle- whether this is a recycle stream- Returns:
- the HTML table label
-
isSeparator
Checks if equipment is a separator type.- Parameters:
equipment- the equipment- Returns:
- true if separator
-
isValve
Checks if equipment is a valve type.- Parameters:
equipment- the equipment- Returns:
- true if valve
-
appendLegend
Appends a legend to the diagram.- Parameters:
sb- the string builder
-
escapeString
-
exportDOT
Exports the diagram to a file in DOT format.- Parameters:
path- the output file path- Throws:
IOException- if writing fails
-
exportSVG
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
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
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
Exports using Graphviz command-line tool.- Parameters:
path- output pathformat- 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
Sets the diagram title.- Parameters:
title- the title- Returns:
- this exporter for chaining
-
setDetailLevel
Sets the detail level.- Parameters:
detailLevel- the detail level- Returns:
- this exporter for chaining
-
setDiagramStyle
Sets the diagram style to use for rendering.Available styles include:
DiagramStyle.NEQSIM- Default NeqSim style with colored zonesDiagramStyle.HYSYS- AspenTech HYSYS-like style with blue streamsDiagramStyle.PROII- PRO/II style with gray backgroundDiagramStyle.ASPEN_PLUS- Aspen Plus style
- Parameters:
style- the diagram style- Returns:
- this exporter for chaining
-
getDiagramStyle
-
setVerticalLayout
Sets whether to use vertical (top-down) layout.- Parameters:
verticalLayout- true for vertical, false for horizontal- Returns:
- this exporter for chaining
-
setUseClusters
Sets whether to group equipment into clusters.- Parameters:
useClusters- true to use clusters- Returns:
- this exporter for chaining
-
setShowLegend
Sets whether to show the legend.- Parameters:
showLegend- true to show legend- Returns:
- this exporter for chaining
-
setShowStreamValues
Sets whether to show stream values on edges.- Parameters:
showStreamValues- true to show values- Returns:
- this exporter for chaining
-
setUseStreamTables
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
Sets whether to highlight recycle streams.- Parameters:
highlightRecycles- true to highlight recycles- Returns:
- this exporter for chaining
-
setShowControlEquipment
Sets whether to show control equipment (adjusters, calculators, recycles).- Parameters:
showControlEquipment- true to show control equipment- Returns:
- this exporter for chaining
-
setShowDexpiMetadata
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
-