Skip to content

Commit

Permalink
Merge pull request #13 from equinor/story175069ExtendXLSTMappingBLuep…
Browse files Browse the repository at this point in the history
…rint

Extend XSLT mappings to handle NOAKADEXPI Blueprint dexpi
  • Loading branch information
eoye authored Oct 3, 2024
2 parents 4ab6201 + b547fc3 commit 1fa24bb
Show file tree
Hide file tree
Showing 8 changed files with 473 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pandid.xml
pandid.trig
rml/segments.trig
client/.idea
.vs
client/Boundaries/Dexpi2Svg/test.svg
rml/C03V04.trig
www/C03V04.svg
Expand Down
20 changes: 15 additions & 5 deletions client/Boundaries/Dexpi2Svg/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class Program
{
static void Main(string[] args)
{
if(args.Length < 2)
AppContext.SetSwitch("Switch.System.Xml.AllowDefaultResolver", true);//added
if (args.Length < 2)
{
Console.WriteLine("Usage: dotnet run input.xml style.xslt");
return;
Expand All @@ -21,10 +22,15 @@ static void Main(string[] args)
xmlDoc.LoadXml(xmlData);

XslCompiledTransform xslt = new XslCompiledTransform();
XsltSettings xsltSettings = new XsltSettings(true, true);//Added

XmlReaderSettings readerSettings = new XmlReaderSettings(); //Added
readerSettings.DtdProcessing = DtdProcessing.Parse; //added

using (StringReader sr = new StringReader(xsltData))
using (XmlReader xr = XmlReader.Create(sr))
using (XmlReader xr = XmlReader.Create(sr, readerSettings)) // added
{
xslt.Load(xr);
xslt.Load(xr, xsltSettings, new XmlUrlResolver());//added
}

MathExtensions mathExtensions = new MathExtensions();
Expand All @@ -36,12 +42,16 @@ static void Main(string[] args)

XmlWriterSettings settings = xslt.OutputSettings?.Clone() ?? throw new Exception("No xslt output settings found!");
settings.OmitXmlDeclaration = true;

// Transform XML to SVG
using (StringReader sr = new StringReader(xmlData))//added
using (XmlReader xr = XmlReader.Create(sr, readerSettings)) //added
using (StringWriter sw = new StringWriter())
using (XmlWriter xw = XmlWriter.Create(sw, settings))
{
xslt.Transform(xmlDoc, xsltArgs, xw);
string svgOutput = sw.ToString();
xslt.Transform(xr, xsltArgs, xw);
//xslt.Transform(xmlDoc, xsltArgs, xw);
string svgOutput = sw.ToString();//adedd

// Save or use the SVG output
Console.WriteLine(svgOutput);
Expand Down
5 changes: 5 additions & 0 deletions datalog/noaka_boundary.datalog
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ data:insideBoundary [?new_node] :-
data:insideBoundary [?new_node] :-
data:insideBoundary [?node],
imf:hasPart[?new_node, ?node] .


data:boundary [?new_node] :-
data:boundary [?node],
imf:hasPart[?new_node, ?node] .
4 changes: 2 additions & 2 deletions rml_noaka/PipingNetworkSegmentConnectionTerminal.map.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
rml:iterator "//PipingNetworkSegment/Connection[not (contains(@ToID, 'Nozzle'))]"
];
rr:subjectMap [
rr:template "https://assetid.equinor.com/plantx#{concat(@ToID, '_input')}";
rr:template "if(@ToID) then https://assetid.equinor.com/plantx#{concat(@ToID, '_input')}";
rr:termType rr:IRI;
rr:class imf:Terminal
] ;
Expand All @@ -95,7 +95,7 @@
rml:iterator "//PipingNetworkSegment/Connection[not (contains(@FromID, 'Nozzle'))]"
];
rr:subjectMap [
rr:template "https://assetid.equinor.com/plantx#{concat(@FromID, '_output')}";
rr:template "if(@FromID) then https://assetid.equinor.com/plantx#{concat(@FromID, '_output')}";
rr:termType rr:IRI;
rr:class imf:Terminal
] ;
Expand Down
35 changes: 35 additions & 0 deletions www/ProgramOverviewNoaka.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Program Overview

## Overview of XSLT Stylesheet for SVG Conversion

This document outlines the components of the XSLT stylesheet designed to transform XML data from NOAKADexpi into a graphical SVG format. Specific templates within the stylesheet are responsible for various aspects of the SVG output.

### SVG Structure and Design

- **Base SVG Output (`/PlantModel` Template)**: This template is responsible for generating the foundational SVG structure, including setting the `width` and `viewBox` attributes based on the XML input.

### Dynamic Visual Elements

- **Matching piping linesTemplate**: This template draws SVG paths for elements like `CenterLine`, applying styles such as dashed lines to denote information flows.
- **Positioning and Transformations**: It calculates the correct positioning and rotation for SVG elements.
- **Template for PipingNetworkSystem**: Manages the creation of text labels on the lines, and its text orientation.
- **Shape Catalog Template**: defines SVG symbols. It locates the appropriate `_Origo.svg` file based on the `shapeValue` and then processes text elements, passing their values as arguments to populate text fields within the Symbol SVG. Before appyling another template to the symbols.
- **Style-Based Exclusions (`Style-Based Filtering` Section)**: Elements with specific stroke or fill colors are excluded from the output, which is a deliberate filtering process to manage the visual output when showing the symbols.
- **Direct Element Copying (`Generic Copying` Section)**: To ensure all SVG elements not explicitly matched by other templates are included in the output, a generic copying process is employed.


### Special Considerations and Notes

- **Symbol Library Location**: The symbol library repo must be located in a adjacent folder to SSI-DEXPI-TEMP for the stylesheet to function correctly.
- **Shape Exclusions and Fallbacks**:
- The `BORDER_A1_Origo.svg` file does not exist, necessitating an `if` check to handle its absence.
- Since `PV001A_Origo.svg` is also missing, an empty SVG text element was created as a placeholder.


### Known Issues and Limitations
- Not all nozzles are present in the provided data.




---
67 changes: 67 additions & 0 deletions www/RunGuide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Running the NOAKADEXPI Program

This guide will help you run the NOAKADEXPI program that converts DEPI XML files to SVG format using the DEXPI2SVG tool.

## Prerequisites

Before you start, ensure that you have the following repository structure on your local machine:

- `NOAKADEXPI` repository located adjacent to the `SSI_DEXPI_TEMP` repository.

## Steps to Run the Program

1. **Navigate to the Tool Directory**

Open a command prompt or terminal window and navigate to the `Client/boundaries/Dexpi2svg` directory within the `NOAKADEXPI` repository.

2. **Run the Conversion Command**

Use the following command to convert your DEPI XML file to SVG format:

```sh
dotnet run "<path-to-your-xml-file>" "<path-to-your-xslt-file>" > output.svg
```

Replace `<path-to-your-xml-file>` with the generic path to your DEPI XML file and `<path-to-your-xslt-file>` with the generic path to your XSLT file.

3. **Addressing Missing Symbol Error**

If you encounter an error about a missing symbol `PV001A_Origio.svg`, you will need to create it by following these steps:

a. Create a new file inside the `NOAKADEXPI/SYMBOL/Origo` directory.

b. Paste the following SVG content into the new file:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"
width="277.791mm" height="93.6551mm" viewBox="-64.8125 -10.8125 65.625 22.125">
<defs vector-effect="non-scaling-stroke" />
<g>
</g>
</svg>
```

Name this file `PV001A_Origio.svg`.

4. **Integrate the SVG Output**

Once you have the `output.svg` file, you can integrate it into your `dexpi.html` file:

a. Copy the full contents of `output.svg`.

b. Paste the copied SVG content into `dexpi.html` after the line `<?xml version='1.0' encoding='UTF-8'?>`.

Ensure that the end of your `dexpi.html` file only contains the following lines:

```html
<script src="script.js" crossorigin="anonymous"></script>
</body>
</html>
```

5. **View the Result**

Open `dexpi.html` in a web browser to view the SVG representation of your DEPI XML file. You should now be able to click on the components within the SVG as intended.
If you want to be able to create boundaries you must use RDFox aswell, to manage this see the README in client/boundaries.
Loading

0 comments on commit 1fa24bb

Please sign in to comment.