Skip to content

Commit

Permalink
Fixed layer adding
Browse files Browse the repository at this point in the history
  • Loading branch information
puppetsw committed Sep 24, 2022
1 parent 6391f4a commit 2870683
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Documents;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.Civil;
Expand All @@ -10,9 +9,9 @@
using StringMaster.Extensions;
using DBObject = Autodesk.AutoCAD.DatabaseServices.DBObject;

namespace StringMaster.Utilities;
namespace StringMaster.Helpers;

public static class FeatureLineUtils
public static class FeatureLineHelpers
{
public static ObjectId CreateFeatureLineFromPoly(this Site site, Polyline poly, FeatureLineStyle style)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using StringMaster.Extensions;
using StringMaster.Models;

namespace StringMaster.Utilities;
namespace StringMaster.Helpers;

public static class LayerUtils
public static class LayerHelpers
{
/// <summary>
/// Check if the database contains the specified layer
Expand Down Expand Up @@ -41,15 +41,32 @@ public static void CreateLayer(AcadLayer layer, Transaction tr, Database databas
if (layerTable.Has(layer.Name))
return;

LinetypeTableRecord lineType = null;

var ltTable = (LinetypeTable)tr.GetObject(CivilApplication.ActiveDatabase.LinetypeTableId, OpenMode.ForRead);
if (ltTable.Has(layer.Linetype))
{
foreach (ObjectId objectId in ltTable)
{
lineType = (LinetypeTableRecord)tr.GetObject(objectId, OpenMode.ForRead);
if (lineType.Name == layer.Linetype)
break;
}
}

var ltr = new LayerTableRecord
{
Name = layer.Name,
Color = layer.Color.ToColor(),
IsLocked = layer.IsLocked,
IsFrozen = layer.IsFrozen,
IsOff = !layer.IsOn
IsOff = !layer.IsOn,
LineWeight = LineweightHelpers.LineweightStringtoLineweight(layer.Lineweight)
};

if (lineType != null)
ltr.LinetypeObjectId = lineType.ObjectId;

layerTable.UpgradeOpen();
layerTable.Add(ltr);
tr.AddNewlyCreatedDBObject(ltr, true);
Expand Down
72 changes: 72 additions & 0 deletions src/StringMaster/Helpers/LineweightHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using Autodesk.AutoCAD.DatabaseServices;

namespace StringMaster.Helpers;

public static class LineweightHelpers
{
public static LineWeight LineweightStringtoLineweight(string lineweight)
{
switch (lineweight)
{
case "0.00 mm":
return LineWeight.LineWeight000;
case "0.05 mm":
return LineWeight.LineWeight005;
case "0.09 mm":
return LineWeight.LineWeight009;
case "0.13 mm":
return LineWeight.LineWeight013;
case "0.15 mm":
return LineWeight.LineWeight015;
case "0.18 mm":
return LineWeight.LineWeight018;
case "0.20 mm":
return LineWeight.LineWeight020;
case "0.25 mm":
return LineWeight.LineWeight025;
case "0.30 mm":
return LineWeight.LineWeight030;
case "0.35 mm":
return LineWeight.LineWeight035;
case "0.40 mm":
return LineWeight.LineWeight040;
case "0.50 mm":
return LineWeight.LineWeight050;
case "0.53 mm":
return LineWeight.LineWeight053;
case "0.60 mm":
return LineWeight.LineWeight060;
case "0.70 mm":
return LineWeight.LineWeight070;
case "0.80 mm":
return LineWeight.LineWeight080;
case "0.90 mm":
return LineWeight.LineWeight090;
case "1.00 mm":
return LineWeight.LineWeight100;
case "1.06 mm":
return LineWeight.LineWeight106;
case "1.20 mm":
return LineWeight.LineWeight120;
case "1.40 mm":
return LineWeight.LineWeight140;
case "1.58 mm":
return LineWeight.LineWeight158;
case "2.00 mm":
return LineWeight.LineWeight200;
case "2.11 mm":
return LineWeight.LineWeight211;
case "ByLayer":
return LineWeight.ByLayer;
case "ByBlock":
return LineWeight.ByBlock;
case "Default":
return LineWeight.ByLineWeightDefault;
case "ByDIPs":
return LineWeight.ByDIPs;
default:
throw new ArgumentOutOfRangeException(nameof(lineweight), lineweight, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
using StringMaster.Models;
using Polyline = Autodesk.AutoCAD.DatabaseServices.Polyline;

namespace StringMaster.Utilities;
namespace StringMaster.Helpers;

public static class PolylineUtils
public static class PolylineHelpers
{
public static ObjectId DrawPolyline3d(Transaction tr, BlockTableRecord btr, Point3dCollection points, string layerName, Color color, bool closed = false)
{
Expand Down
2 changes: 1 addition & 1 deletion src/StringMaster/Models/DescriptionKeyMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StringMaster.Models;
/// <summary>
/// DescriptionKeyMatch class
/// </summary>
public class DescriptionKeyMatch
public sealed class DescriptionKeyMatch
{
public DescriptionKey DescriptionKey { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/StringMaster/Models/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace StringMaster.Models;

[DebuggerDisplay("{X}"+ "," + "{Y}" + "," + "{Z}")]
public class Point : ICloneable
public sealed class Point : ICloneable
{
public double X { get; set; }
public double Y { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/StringMaster/Models/RadiusPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace StringMaster.Models;

public class RadiusPoint
public sealed class RadiusPoint
{
public double Radius { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions src/StringMaster/Models/SurveyPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace StringMaster.Models;

public class SurveyPointList : List<SurveyPoint> { }
public sealed class SurveyPointList : List<SurveyPoint> { }

public class SurveyPoint : IEquatable<SurveyPoint>, ICloneable
public sealed class SurveyPoint : IEquatable<SurveyPoint>, ICloneable
{
public Point Point { get; set; }

Expand Down
6 changes: 3 additions & 3 deletions src/StringMaster/Services/Implementation/AcadLayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using StringMaster.Extensions;
using StringMaster.Helpers;
using StringMaster.Models;
using StringMaster.Services.Interfaces;
using StringMaster.Utilities;

namespace StringMaster.Services.Implementation;

Expand Down Expand Up @@ -92,8 +92,8 @@ public void CreateLayer(AcadLayer? layer, string? documentName = null)

using var tr = document.TransactionManager.StartLockedTransaction();

if (!LayerUtils.HasLayer(layer.Name, tr, document.Database))
LayerUtils.CreateLayer(layer, tr, document.Database);
if (!LayerHelpers.HasLayer(layer.Name, tr, document.Database))
LayerHelpers.CreateLayer(layer, tr, document.Database);

tr.Commit();
}
Expand Down
8 changes: 5 additions & 3 deletions src/StringMaster/StringMaster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<Compile Include="Extensions\CircularArcExtensions.cs" />
<Compile Include="Extensions\ColorExtensions.cs" />
<Compile Include="Extensions\WindowExtensions.cs" />
<Compile Include="Helpers\LineweightHelpers.cs" />
<Compile Include="Helpers\ResourceExtension.cs" />
<Compile Include="Helpers\AngleHelpers.cs" />
<Compile Include="Ioc.cs" />
Expand Down Expand Up @@ -156,14 +157,14 @@
<Compile Include="Services\Interfaces\IPaletteControl.cs" />
<Compile Include="Models\AcadColor.cs" />
<Compile Include="Services\Interfaces\IAcadColorDialogService.cs" />
<Compile Include="Utilities\FeatureLineUtils.cs" />
<Compile Include="Helpers\FeatureLineHelpers.cs" />
<Compile Include="Helpers\MathHelpers.cs" />
<Compile Include="Helpers\PointHelpers.cs" />
<Compile Include="Helpers\StringHelpers.cs" />
<Compile Include="Helpers\XmlHelper.cs" />
<Compile Include="StringMasterPalette.cs" />
<Compile Include="StringMasterPlugin.cs" />
<Compile Include="Utilities\LayerUtils.cs" />
<Compile Include="Helpers\LayerHelpers.cs" />
<Compile Include="Models\Angle.cs" />
<Compile Include="Models\DescriptionKey.cs" />
<Compile Include="Models\DescriptionKeyMatch.cs" />
Expand All @@ -172,7 +173,7 @@
<Compile Include="Models\RadiusPoint.cs" />
<Compile Include="Models\SurveyPoint.cs" />
<Compile Include="Extensions\PointExtensions.cs" />
<Compile Include="Utilities\PolylineUtils.cs" />
<Compile Include="Helpers\PolylineHelpers.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RelayCommand.cs" />
<Compile Include="Strings\ResourceStrings.Designer.cs">
Expand Down Expand Up @@ -290,5 +291,6 @@
<Version>5.4.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
9 changes: 4 additions & 5 deletions src/StringMaster/ViewModels/StringCogoPointsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using StringMaster.Helpers;
using StringMaster.Models;
using StringMaster.Services.Interfaces;
using StringMaster.Utilities;

// ReSharper disable UnusedMember.Global

Expand Down Expand Up @@ -300,8 +299,8 @@ private void StringCogoPoints()

if (deskeyMatch.DescriptionKey.AcadLayer.IsSelected)
{
if (!LayerUtils.HasLayer(layerName, tr, CivilApplication.ActiveDatabase))
LayerUtils.CreateLayer(deskeyMatch.DescriptionKey.AcadLayer, tr, CivilApplication.ActiveDatabase);
if (!LayerHelpers.HasLayer(layerName, tr, CivilApplication.ActiveDatabase))
LayerHelpers.CreateLayer(deskeyMatch.DescriptionKey.AcadLayer, tr, CivilApplication.ActiveDatabase);
}
else
{
Expand Down Expand Up @@ -369,10 +368,10 @@ private void StringCogoPoints()

// Draw the polylines.
if (deskeyMatch.DescriptionKey.Draw2D && !hasCurve)
PolylineUtils.DrawPolyline2d(tr, btr, pointCollection, layerName, deskeyMatch.DescriptionKey.AcadColor.ToColor(), isClosed);
PolylineHelpers.DrawPolyline2d(tr, btr, pointCollection, layerName, deskeyMatch.DescriptionKey.AcadColor.ToColor(), isClosed);

if (deskeyMatch.DescriptionKey.Draw3D && !hasCurve)
PolylineUtils.DrawPolyline3d(tr, btr, pointCollection, layerName, deskeyMatch.DescriptionKey.AcadColor.ToColor(), isClosed);
PolylineHelpers.DrawPolyline3d(tr, btr, pointCollection, layerName, deskeyMatch.DescriptionKey.AcadColor.ToColor(), isClosed);

if (deskeyMatch.DescriptionKey.DrawFeatureLine && !hasCurve)
{
Expand Down

0 comments on commit 2870683

Please sign in to comment.