Skip to content

Commit

Permalink
🚚 nameentity on slab and bar
Browse files Browse the repository at this point in the history
  • Loading branch information
lorinczandrea committed Oct 25, 2023
1 parent 65ffea1 commit ad53e79
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 67 deletions.
70 changes: 31 additions & 39 deletions FemDesign.Core/Bars/Bar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,29 @@ namespace FemDesign.Bars
[XmlInclude(typeof(Truss))]
[XmlRoot("database", Namespace = "urn:strusoft")]
[System.Serializable]
public partial class Bar : EntityBase, INamedEntity, IStructureElement, IStageElement, IBar
public partial class Bar : NamedEntityBase, INamedEntity, IStructureElement, IStageElement, IBar
{
[XmlIgnore]
private static int _barInstance = 0; // Number of bar/beam instances created
[XmlIgnore]
private static int _columnInstance = 0; // Number of column instances created
[XmlIgnore]
private static int _trussInstance = 0; // Number of truss instances created
protected override int GetUniqueInstanceCount() // This method body must be the same as the method of the BarPart class
{
switch (this.Type)
{
case BarType.Beam:
return ++_barInstance;
case BarType.Column:
return ++_columnInstance;
case BarType.Truss:
return ++_trussInstance;
default:
throw new System.ArgumentException($"Incorrect type of bar: {this.Type}");
}
}

/// <summary>
/// Truss only.
/// </summary>enum
Expand Down Expand Up @@ -120,36 +141,7 @@ public List<Reinforcement.BarReinforcement> LongitudinalBars
}
}

[XmlAttribute("name")]
public string _name; // identifier
public string Name
{
get
{
var foundIndexes = new List<int>();
for (int i = 0; i < this.BarPart.Name.Length; i++)
if (this.BarPart.Name[i] == '.')
foundIndexes.Add(i);

return this.BarPart.Name.Substring(0, foundIndexes.Last());
}
}

public int Instance => this.BarPart.Instance;

[XmlIgnore]
public string Identifier
{
get => this.BarPart.Identifier;
set => this.BarPart.Identifier = value;
}
[XmlIgnore]
public bool LockedIdentifier
{
get => this.BarPart.LockedIdentifier;
set => this.BarPart.LockedIdentifier = value;
}


/// <summary>
/// Parameterless constructor for serialization.
/// </summary>
Expand All @@ -174,7 +166,7 @@ public Bar(Geometry.Edge edge, Materials.Material material, Sections.Section sec

this.EntityCreated();
this.Type = type;
//this.Identifier = identifier;
this.Identifier = identifier;

if (eccentricity == null) { eccentricity = Eccentricity.Default; }
if (connectivity == null) { connectivity = Connectivity.Default; }
Expand Down Expand Up @@ -203,7 +195,7 @@ public Bar(FemDesign.Geometry.Point3d startPoint, FemDesign.Geometry.Point3d end

this.EntityCreated();
this.Type = type;
//this.Identifier = identifier;
this.Identifier = identifier;

if (startEccentricity == null) { startEccentricity = Eccentricity.Default; }
if (endEccentricity == null) { endEccentricity = Eccentricity.Default; }
Expand Down Expand Up @@ -238,7 +230,7 @@ public Bar(Geometry.Edge edge, BarType type, Materials.Material material, Sectio

this.EntityCreated();
this.Type = type;
//this.Identifier = identifier;
this.Identifier = identifier;


this.BarPart = new BarPart(edge, this.Type, material, section, startEccentricity, endEccentricity, startConnectivity, endConnectivity, identifier);
Expand All @@ -263,7 +255,7 @@ public Bar(Geometry.Edge edge, BarType type, Materials.Material material, Sectio

this.EntityCreated();
this.Type = type;
//this.Identifier = identifier;
this.Identifier = identifier;
this.BarPart = new BarPart(edge, this.Type, material, startSection, endSection, startEccentricity, endEccentricity, startConnectivity, endConnectivity, identifier);
}

Expand All @@ -284,7 +276,7 @@ public Bar(Geometry.Edge edge, BarType type, Materials.Material material, Sectio

this.EntityCreated();
this.Type = type;
//this.Identifier = identifier;
this.Identifier = identifier;
this.BarPart = new BarPart(edge, this.Type, material, sections, eccentricities, connectivities, identifier);
}

Expand All @@ -306,7 +298,7 @@ public Bar(Geometry.Edge edge, BarType type, Materials.Material material, Sectio

this.EntityCreated();
this.Type = type;
//this.Identifier = identifier;
this.Identifier = identifier;
this.BarPart = new BarPart(edge, this.Type, material, sections, positions, eccentricities, startConnectivity, endConnectivity, identifier);
}

Expand All @@ -324,7 +316,7 @@ public Bar(Geometry.Edge edge, Materials.Material material, Sections.Section sec
{
this.EntityCreated();
this.Type = BarType.Truss;
//this.Identifier = identifier;
this.Identifier = identifier;
if(trussBehaviour != null)
{
this.TrussBehaviour = trussBehaviour;
Expand Down Expand Up @@ -352,7 +344,7 @@ public static Bar Truss(Geometry.Edge edge, Materials.Material material, Section

truss.EntityCreated();
truss.Type = BarType.Truss;
//truss.Identifier = identifier;
truss.Identifier = identifier;
truss.BarPart = new BarPart(edge, truss.Type, material, section, identifier);
return truss;
}
Expand Down
6 changes: 3 additions & 3 deletions FemDesign.Core/GenericClasses/NamedEntityBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public abstract partial class NamedEntityBase : EntityBase, INamedEntity
else
return "@" + this._xmlName;
}
set
set
{
if (value.StartsWith("@"))
this._xmlName = value;
else
this._xmlName = "@" + value;
this._xmlName = "@" + value;
}
}
[XmlIgnore]
Expand All @@ -41,7 +41,7 @@ public virtual string Identifier
{
this._name = $"{value}.{GetUniqueInstanceCount()}";

if (string .IsNullOrEmpty(value) || _namePattern.IsMatch(this._name) == false)
if (string.IsNullOrEmpty(value) || _namePattern.IsMatch(this._name) == false)
throw new ArgumentException($"'{value}' is not a valid Identifier.");
}
}
Expand Down
38 changes: 13 additions & 25 deletions FemDesign.Core/Shells/Slab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,23 @@ namespace FemDesign.Shells
/// slab_type
/// </summary>
[System.Serializable]
public partial class Slab : EntityBase, INamedEntity, IStructureElement, IStageElement, IShell
public partial class Slab : NamedEntityBase, INamedEntity, IStructureElement, IStageElement, IShell
{
[XmlAttribute("name")]
public string _name; // identifier
public string Name
{
get
{
var foundIndexes = new List<int>();
for (int i = 0; i < this.SlabPart.Name.Length; i++)
if (this.SlabPart.Name[i] == '.')
foundIndexes.Add(i);

return this.SlabPart.Name.Substring(0, foundIndexes.Last());
}
}
public int Instance => this.SlabPart.Instance;

[XmlIgnore]
public string Identifier
{
get => this.SlabPart.Identifier;
set => this.SlabPart.Identifier = value;
}
private static int _plateInstance = 0; // Number of plate instances created
[XmlIgnore]
public bool LockedIdentifier
private static int _wallInstance = 0; // Number of wall instances created
protected override int GetUniqueInstanceCount() // This method body must be the same as the method of the SlabPart class
{
get => this.SlabPart.LockedIdentifier;
set => this.SlabPart.LockedIdentifier = value;
switch (this.Type)
{
case SlabType.Plate:
return ++_plateInstance;
case SlabType.Wall:
return ++_wallInstance;
default:
throw new ArgumentException($"Incorrect type of slab: {this.Type}");
}
}

[XmlIgnore]
Expand Down
5 changes: 5 additions & 0 deletions FemDesign.Tests/Bars/BarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public void ResetInstanceCounters()
barPartType.SetStaticFieldOrProperty("_columnInstance", 0);
barPartType.SetStaticFieldOrProperty("_trussInstance", 0);

PrivateType barType = new PrivateType(typeof(Bar));
barType.SetStaticFieldOrProperty("_barInstance", 0);
barType.SetStaticFieldOrProperty("_columnInstance", 0);
barType.SetStaticFieldOrProperty("_trussInstance", 0);

}

[TestMethod("Bar constructor 1")]
Expand Down

0 comments on commit ad53e79

Please sign in to comment.