Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLeader snooping fix #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 36 additions & 99 deletions Snoop/CollectorExts/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ protected override void
#region Entity
// main branch for anything derived from Entity (AcDbEntity)

private void
TryStreamProperty<T>(ArrayList data, Func<T> getProperty, string propertyName) where T: Snoop.Data.Data
{
try
{
data.Add(getProperty());
}
catch (Autodesk.AutoCAD.Runtime.Exception e)
{
if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.NotApplicable)
data.Add(new Snoop.Data.Exception(propertyName, e));
else if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.InvalidExtents)
data.Add(new Snoop.Data.Exception(propertyName, e));
else if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.NullExtents)
data.Add(new Snoop.Data.Exception(propertyName, e));
else if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.InvalidContext)
data.Add(new Snoop.Data.Exception(propertyName, e));
else
throw e;
}
}

private void
Stream (ArrayList data, AcDb.Entity ent)
{
Expand Down Expand Up @@ -94,27 +116,9 @@ private void
data.Add(new Snoop.Data.String("Collision type", ent.CollisionType.ToString()));

// the following functions only work in some cases
try {
data.Add(new Snoop.Data.Object("Geom extents", ent.GeometricExtents));
}
catch (Autodesk.AutoCAD.Runtime.Exception e) {
if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.InvalidExtents)
data.Add(new Snoop.Data.Exception("Geom extents", e));
else if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.NullExtents)
data.Add(new Snoop.Data.Exception("Geom extents", e));
else
throw e;
}
TryStreamProperty(data, () => new Snoop.Data.Object("Geom extents", ent.GeometricExtents), "Geom extents");

try {
data.Add(new Snoop.Data.Object("Compound object transform", ent.CompoundObjectTransform));
}
catch (Autodesk.AutoCAD.Runtime.Exception e) {
if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.NotApplicable)
data.Add(new Snoop.Data.Exception("Compound object transform", e));
else
throw e;
}
TryStreamProperty(data, () => new Snoop.Data.Object("Compound object transform", ent.CompoundObjectTransform), "Compound object transform");

// branch to all known major sub-classes

Expand Down Expand Up @@ -333,38 +337,13 @@ private void

// Start point and end point are not applicable for some types of
// curves (e.g., Ray, Xline)
try {
data.Add(new Snoop.Data.Point3d("Start point", crv.StartPoint));
}
catch (Autodesk.AutoCAD.Runtime.Exception e) {
if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.NotApplicable)
data.Add(new Snoop.Data.Exception("Start point", e));
else
throw e;
}

try {
data.Add(new Snoop.Data.Point3d("End point", crv.EndPoint));
}
catch (Autodesk.AutoCAD.Runtime.Exception e) {
if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.NotApplicable)
data.Add(new Snoop.Data.Exception("End point", e));
else
throw e;
}
// the following is only valid in some cases
TryStreamProperty(data, () => new Snoop.Data.Point3d("Start point", crv.StartPoint), "Start point");
TryStreamProperty(data, () => new Snoop.Data.Point3d("End point", crv.EndPoint), "End point");

data.Add(new Snoop.Data.Bool("Is periodic", crv.IsPeriodic));

// the following is only valid in some cases
try {
data.Add(new Snoop.Data.Object("Spline", crv.Spline));
}
catch (Autodesk.AutoCAD.Runtime.Exception e) {
if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.NotApplicable)
data.Add(new Snoop.Data.Exception("Spline", e));
else
throw e;
}
TryStreamProperty(data, () => new Snoop.Data.Object("Spline", crv.Spline), "Spline");

// branch to all known major sub-classes
Line line = crv as Line;
Expand Down Expand Up @@ -628,49 +607,15 @@ private void
data.Add(new Snoop.Data.ClassSeparator(typeof(Spline)));

data.Add(new Snoop.Data.Int("Degree", spline.Degree));

try {
data.Add(new Snoop.Data.Vector3d("Start fit tangent", spline.StartFitTangent));
}
catch (Autodesk.AutoCAD.Runtime.Exception e) {
if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.NotApplicable)
data.Add(new Snoop.Data.Exception("Start fit tangent", e));
else
throw e;
}

try {
data.Add(new Snoop.Data.Vector3d("End fit tangent", spline.EndFitTangent));
}
catch (Autodesk.AutoCAD.Runtime.Exception e){
if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.NotApplicable)
data.Add(new Snoop.Data.Exception("End fit tangent", e));
else
throw e;
}
TryStreamProperty(data, () => new Snoop.Data.Vector3d("Start fit tangent", spline.StartFitTangent), "Start fit tangent");
TryStreamProperty(data, () => new Snoop.Data.Vector3d("End fit tangent", spline.EndFitTangent), "End fit tangent");

data.Add(new Snoop.Data.Bool("Has fit data", spline.HasFitData));

try {
data.Add(new Snoop.Data.Object("Fit data", spline.FitData));
}
catch (Autodesk.AutoCAD.Runtime.Exception e) {
if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.NotApplicable)
data.Add(new Snoop.Data.Exception("Fit data", e));
else
throw e;
}

try {
data.Add(new Snoop.Data.Double("Fit tolerance", spline.FitTolerance));
}
catch (Autodesk.AutoCAD.Runtime.Exception e) {
if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.NotApplicable)
data.Add(new Snoop.Data.Exception("Fit tolerance", e));
else
throw e;
}

TryStreamProperty(data, () => new Snoop.Data.Object("Fit data", spline.FitData), "Fit data");
TryStreamProperty(data, () => new Snoop.Data.Double("Fit tolerance", spline.FitTolerance), "Fit tolerance");

data.Add(new Snoop.Data.Object("Nurbs data", spline.NurbsData));
data.Add(new Snoop.Data.Bool("Is null", spline.IsNull));
data.Add(new Snoop.Data.Bool("Is rational", spline.IsRational));
Expand Down Expand Up @@ -894,7 +839,7 @@ private void
data.Add(new Snoop.Data.Object("Block color", mleader.BlockColor));
data.Add(new Snoop.Data.String("Block connection type", mleader.BlockConnectionType.ToString()));
data.Add(new Snoop.Data.ObjectId("Block content Id", mleader.BlockContentId));
data.Add(new Snoop.Data.Point3d("Block position", mleader.BlockPosition));
TryStreamProperty(data, () => new Snoop.Data.Point3d("Block position", mleader.BlockPosition), "Block position");
data.Add(new Snoop.Data.Double("Block rotation", mleader.BlockRotation));
data.Add(new Snoop.Data.Scale3d("Block scale", mleader.BlockScale));
data.Add(new Snoop.Data.String("Content type", mleader.ContentType.ToString()));
Expand All @@ -920,7 +865,7 @@ private void
data.Add(new Snoop.Data.Double("Text height", mleader.TextHeight));
data.Add(new Snoop.Data.Point3d("Text location", mleader.TextLocation));
data.Add(new Snoop.Data.ObjectId("Text style Id", mleader.TextStyleId));
data.Add(new Snoop.Data.Point3d("Tolerance location", mleader.ToleranceLocation));
TryStreamProperty(data, () => new Snoop.Data.Point3d("Tolerance location", mleader.ToleranceLocation), "Tolerance location");
}

private void
Expand Down Expand Up @@ -962,15 +907,7 @@ private void
data.Add(new Snoop.Data.ObjectToString("Background fill color", mtext.BackgroundFillColor));
}

try {
data.Add(new Snoop.Data.Double("Background scale factor", mtext.BackgroundScaleFactor));
}
catch (Autodesk.AutoCAD.Runtime.Exception e) {
if (e.ErrorStatus == Autodesk.AutoCAD.Runtime.ErrorStatus.NotApplicable)
data.Add(new Snoop.Data.Exception("Background scale factor", e));
else
throw e;
}
TryStreamProperty(data, () => new Snoop.Data.Double("Background scale factor", mtext.BackgroundScaleFactor), "Background scale factor");

data.Add(new Snoop.Data.Object("Background transparency", mtext.Transparency));

Expand Down