Skip to content

Commit b26c5c4

Browse files
author
sripp
committed
Fix DistributorWithOr
1 parent f30e7b1 commit b26c5c4

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

TiaCodeGen.Tests/SampleTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using NUnit.Framework;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Linq;
45
using TiaCodegen.Blocks;
56
using TiaCodegen.Commands;
@@ -247,5 +248,34 @@ public void TestCallWithTPAndDistributor()
247248
block.Interface = TestInterface;
248249
var xml = block.GetCode();
249250
}
251+
252+
[Test]
253+
public void DistributorWithOr()
254+
{
255+
var codeblock = new CodeBlock() { Safety = false };
256+
257+
var nw = new Network("Test2", "Test2en");
258+
nw.Add(
259+
new And(
260+
new Signal("asd"),
261+
new Distributor(
262+
new SCoil(new Signal("x")),
263+
new And(
264+
new Or(
265+
new Signal("a"),
266+
new Signal("b")
267+
),
268+
new SCoil(new Signal("c"))
269+
)
270+
)
271+
)
272+
);
273+
274+
codeblock.Add(nw);
275+
276+
var block = new Block("Test", "blabla", codeblock);
277+
block.Interface = TestInterface;
278+
var xml = block.GetCode();
279+
}
250280
}
251281
}

TiaCodegen/CodeGen/KopCodeHelper.cs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,14 @@ private void AddWires(IOperationOrSignal op)
517517
{
518518
_sb.AppendLine("<IdentCon UId=\"" + ((Signal)c).SignalId + "\" />" + " <!-- " + ((Signal)c).Name + " -->");
519519
}
520+
else if (c is And && c.Children.FirstOrDefault() is Or)
521+
{
522+
foreach(var ch in c.Children.FirstOrDefault().Children)
523+
{
524+
var inName = ch is FunctionCall ? ((ch is InRangeCall || ch is OutRangeCall) ? "pre" : "en") : "in";
525+
_sb.AppendLine("<NameCon UId=\"" + ch.OperationId + "\" Name=\"" + inName + "\" />");
526+
}
527+
}
520528
else
521529
{
522530
var inName = c is FunctionCall ? ((c is InRangeCall || c is OutRangeCall) ? "pre" : "en") : "in";
@@ -554,7 +562,7 @@ private void AddWires(IOperationOrSignal op)
554562
_currentId++;
555563
}
556564
else if (op is Or && op.Children.Count > 1)
557-
{
565+
{
558566
int i = 1;
559567
foreach (var ch in op.Children)
560568
{
@@ -700,17 +708,24 @@ private void AddWires(IOperationOrSignal op)
700708
akC = c.Children.First();
701709
}
702710

703-
if (akC is CompareOperator || akC is InRangeCall || akC is OutRangeCall)
704-
{
705-
_sb.AppendLine("<NameCon UId=\"" + akC.OperationId + "\" Name=\"pre\" />" + " <!-- " + akC.GetType().Name + " -->");
706-
}
707-
else if (akC is FunctionCall || akC is IFunctionOperation)
708-
{
709-
_sb.AppendLine("<NameCon UId=\"" + akC.OperationId + "\" Name=\"en\" />" + " <!-- " + akC.GetType().Name + " -->");
710-
}
711-
else
711+
var l = new List<IOperationOrSignal>() { akC };
712+
if (akC is Or)
713+
l = akC.Children;
714+
715+
foreach (var s in l)
712716
{
713-
_sb.AppendLine("<NameCon UId=\"" + akC.OperationId + "\" Name=\"in\" />" + " <!-- " + akC.GetType().Name + " -->");
717+
if (s is CompareOperator || s is InRangeCall || s is OutRangeCall)
718+
{
719+
_sb.AppendLine("<NameCon UId=\"" + s.OperationId + "\" Name=\"pre\" />" + " <!-- " + s.GetType().Name + " -->");
720+
}
721+
else if (s is FunctionCall || s is IFunctionOperation)
722+
{
723+
_sb.AppendLine("<NameCon UId=\"" + s.OperationId + "\" Name=\"en\" />" + " <!-- " + s.GetType().Name + " -->");
724+
}
725+
else
726+
{
727+
_sb.AppendLine("<NameCon UId=\"" + s.OperationId + "\" Name=\"in\" />" + " <!-- " + s.GetType().Name + " -->");
728+
}
714729
}
715730
}
716731
}

0 commit comments

Comments
 (0)