50 lines
2.0 KiB
C#
50 lines
2.0 KiB
C#
using netDxf;
|
|
using netDxf.Tables;
|
|
using StructureHelperCommon.Infrastructures.Exceptions;
|
|
|
|
namespace StructureHelperCommon.Services.Exports
|
|
{
|
|
public class GetDxfLayerLogic : IGetDxfLayerLogic
|
|
{
|
|
private const string PrimitivesLayer = "STR-PRM";
|
|
private const string OpeningsLayer = "STR-OPN";
|
|
private const string RebarLayer = "STR-REB";
|
|
private const string LayerNameIsUnKnown = ": Layer name is unknown";
|
|
public Layer GetOrCreateLayer(DxfDocument dxf, LayerNames layerName)
|
|
{
|
|
string newLayerName = GetLayerName(layerName);
|
|
Layer newLayer = dxf.Layers.Contains(newLayerName)
|
|
? dxf.Layers[newLayerName]
|
|
: new Layer(newLayerName)
|
|
{
|
|
Color = GetLayerColor(layerName)
|
|
};
|
|
|
|
if (!dxf.Layers.Contains(newLayerName))
|
|
dxf.Layers.Add(newLayer);
|
|
return newLayer;
|
|
}
|
|
public string GetLayerName(LayerNames layerName)
|
|
{
|
|
if (layerName == LayerNames.StructiralPrimitives) { return PrimitivesLayer; }
|
|
else if (layerName == LayerNames.StructuralOpenings) { return OpeningsLayer; }
|
|
else if (layerName == LayerNames.StructuralRebars) { return RebarLayer; }
|
|
else
|
|
{
|
|
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(layerName) + LayerNameIsUnKnown);
|
|
}
|
|
}
|
|
|
|
public AciColor GetLayerColor(LayerNames layerName)
|
|
{
|
|
if (layerName == LayerNames.StructiralPrimitives) { return AciColor.Blue; }
|
|
else if (layerName == LayerNames.StructuralOpenings) { return AciColor.DarkGray; }
|
|
else if (layerName == LayerNames.StructuralRebars) { return AciColor.Magenta; }
|
|
else
|
|
{
|
|
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(layerName) + LayerNameIsUnKnown);
|
|
}
|
|
}
|
|
}
|
|
}
|