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

refactor(objects): cnx 687 purge unused classes from objects #333

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,14 @@ private RenderMaterialProxy ConvertMaterialToRenderMaterialProxy(Material materi
diffuseColor.Blue
);

string name = material.Name;
double opacity = material.Opacity.Percentage;

RenderMaterial renderMaterial = new(opacity: opacity, diffuse: diffuse) { name = name, applicationId = id };
RenderMaterial renderMaterial =
new()
{
name = material.Name,
opacity = material.Opacity.Percentage,
diffuse = diffuse.ToArgb(),
applicationId = id
};

// Add additional properties
renderMaterial["ior"] = material.Refraction.Index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ localToGlobalMap.AtomicObject is ITransformable transformable and ICurve
ITransformable? newTransformable = null;
foreach (var mat in localToGlobalMap.Matrix)
{
transformable.TransformTo(new Transform(mat, units), out newTransformable);
transformable.TransformTo(new Transform() { matrix = mat, units = units }, out newTransformable);
}

localToGlobalMap.AtomicObject = (newTransformable as Base)!;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using Rhino;
using Rhino.DocObjects;
using Rhino.Render;
Expand Down Expand Up @@ -180,9 +180,14 @@ private SpeckleRenderMaterial ConvertRenderMaterialToSpeckle(RenderMaterial rend
: pbRenderMaterial.Emission.AsSystemColor(); // pbRenderMaterial.emission gives wrong color for emission materials, and material.emissioncolor gives the wrong value for most others *shrug*

SpeckleRenderMaterial speckleRenderMaterial =
new(opacity, pbRenderMaterial.Metallic, pbRenderMaterial.Roughness, diffuse, emissive)
new()
{
name = renderMaterialName,
opacity = opacity,
metalness = pbRenderMaterial.Metallic,
roughness = pbRenderMaterial.Roughness,
diffuse = diffuse.ToArgb(),
emissive = emissive.ToArgb(),
applicationId = renderMaterial.Id.ToString()
};

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public SOG.Box Convert(Envelope target)

return new SOG.Box()
{
basePlane = plane,
plane = plane,
xSize = new Interval { start = minPtSpeckle.x, end = maxPtSpeckle.x },
ySize = new Interval { start = minPtSpeckle.y, end = maxPtSpeckle.y },
zSize = new Interval { start = minPtSpeckle.z, end = maxPtSpeckle.z },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,49 +186,10 @@ List<string> fieldAdded
{
if (field.Value is Base attributeBase)
{
// only traverse Base if it's Rhino userStrings, or Revit parameter, or Base containing Revit parameters
if (field.Key == "parameters")
{
foreach (KeyValuePair<string, object?> attributField in attributeBase.GetMembers(DynamicBaseMemberType.Dynamic))
{
// only iterate through elements if they are actually Revit Parameters or parameter IDs
if (
attributField.Value is Objects.BuiltElements.Revit.Parameter
|| attributField.Key == "applicationId"
|| attributField.Key == "id"
)
{
KeyValuePair<string, object?> newAttributField =
new($"{field.Key}.{attributField.Key}", attributField.Value);
Func<Base, object?> functionAdded = x => (function(x) as Base)?[attributField.Key];
TraverseAttributes(newAttributField, functionAdded, fieldsAndFunctions, fieldAdded);
}
}
}
else if (field.Key == "userStrings")
{
foreach (KeyValuePair<string, object?> attributField in attributeBase.GetMembers(DynamicBaseMemberType.Dynamic))
{
KeyValuePair<string, object?> newAttributField = new($"{field.Key}.{attributField.Key}", attributField.Value);
Func<Base, object?> functionAdded = x => (function(x) as Base)?[attributField.Key];
TraverseAttributes(newAttributField, functionAdded, fieldsAndFunctions, fieldAdded);
}
}
else if (field.Value is Objects.BuiltElements.Revit.Parameter)
{
foreach (
KeyValuePair<string, object?> attributField in attributeBase.GetMembers(DynamicBaseMemberType.Instance)
)
{
KeyValuePair<string, object?> newAttributField = new($"{field.Key}.{attributField.Key}", attributField.Value);
Func<Base, object?> functionAdded = x => (function(x) as Base)?[attributField.Key];
TraverseAttributes(newAttributField, functionAdded, fieldsAndFunctions, fieldAdded);
}
}
else
{
// for now, ignore all other properties of Base type
}
// Revit parameters are sent under the `properties` field as a `Dictionary<string,object?>`.
// This is the same for attributes from other applications. No Speckle objects should have attributes of type `Base`.
// Currently we are not sending any rhino user strings.
// TODO: add support for attributes of type `Dictionary<string,object?>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can just move this part of code lower to the condition "if Dict" rather than if Base. Why removing if the TODO is already done here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's sync on this: archicad, civil3d, revit, and eventually tekla will send some properties/parameters under the properties field with a dict value - need to implement this in a way in arcgis that can handle diff levels of nesting

}
else if (field.Value is IList attributeList)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Xml.Linq;
using ArcGIS.Desktop.Mapping;
using Speckle.Objects.BuiltElements.Revit;
using Speckle.Sdk.Common;
using Speckle.Sdk.Models;

namespace Speckle.Converters.ArcGIS3.Utils;

Expand Down Expand Up @@ -70,35 +68,6 @@ private void NormalizeAngle()
}
}

public static double? RotationFromRevitData(Base rootObject)
{
// rewrite function to take into account Local reference point in Revit, and Transformation matrix
foreach (KeyValuePair<string, object?> prop in rootObject.GetMembers(DynamicBaseMemberType.Dynamic))
{
if (prop.Key == "info")
{
ProjectInfo? revitProjInfo = (ProjectInfo?)rootObject[prop.Key];
if (revitProjInfo != null)
{
try
{
if (revitProjInfo["locations"] is List<Base> locationList && locationList.Count > 0)
{
Base location = locationList[0];
return Convert.ToDouble(location["trueNorth"]);
}
}
catch (Exception ex) when (ex is FormatException || ex is InvalidCastException || ex is OverflowException)
{
// origin not found, do nothing
}
break;
}
}
}
return null;
}

/// <summary>
/// Initializes a new instance of <see cref="CRSoffsetRotation"/>.
/// </summary>
Expand Down
35 changes: 0 additions & 35 deletions Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/CRSorigin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using ArcGIS.Core.Geometry;
using Speckle.Objects.BuiltElements.Revit;
using Speckle.Sdk.Models;

namespace Speckle.Converters.ArcGIS3.Utils;

Expand All @@ -23,39 +21,6 @@ public CRSorigin(double latDegrees, double lonDegrees)
LonDegrees = lonDegrees;
}

public static CRSorigin? FromRevitData(Base rootObject)
{
// rewrite function to take into account Local reference point in Revit, and Transformation matrix
foreach (KeyValuePair<string, object?> prop in rootObject.GetMembers(DynamicBaseMemberType.Dynamic))
{
if (prop.Key == "info")
{
ProjectInfo? revitProjInfo = (ProjectInfo?)rootObject[prop.Key];
if (revitProjInfo != null)
{
try
{
double lat = Convert.ToDouble(revitProjInfo["latitude"]);
double lon = Convert.ToDouble(revitProjInfo["longitude"]);
double trueNorth;
if (revitProjInfo["locations"] is List<Base> locationList && locationList.Count > 0)
{
Base location = locationList[0];
trueNorth = Convert.ToDouble(location["trueNorth"]);
}
return new CRSorigin(lat * 180 / Math.PI, lon * 180 / Math.PI);
}
catch (Exception ex) when (ex is FormatException || ex is InvalidCastException || ex is OverflowException)
{
// origin not found, do nothing
}
break;
}
}
}
return null;
}

public SpatialReference CreateCustomCRS()
{
string wktString =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@
break;
case SOG.Arc arc:
// POC: possibly endAngle and startAngle null?
double? angle = arc.endAngle - arc.startAngle;
angle = angle < 0 ? angle + 2 * Math.PI : angle;
if (angle is null)
double measure = arc.measure;

Check failure on line 49 in Converters/Autocad/Speckle.Converters.AutocadShared/ToHost/Raw/PolycurveToHostPolylineRawConverter.cs

View workflow job for this annotation

GitHub Actions / build

'Arc' does not contain a definition for 'measure' and no accessible extension method 'measure' accepting a first argument of type 'Arc' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 49 in Converters/Autocad/Speckle.Converters.AutocadShared/ToHost/Raw/PolycurveToHostPolylineRawConverter.cs

View workflow job for this annotation

GitHub Actions / build

'Arc' does not contain a definition for 'measure' and no accessible extension method 'measure' accepting a first argument of type 'Arc' could be found (are you missing a using directive or an assembly reference?)
if (measure <= 0 || measure >= 2 * Math.PI)
{
throw new ArgumentNullException(nameof(target), "Cannot convert arc without angle value.");
throw new ArgumentOutOfRangeException(nameof(target), "Cannot convert arc with measure <= 0 or >= 2 pi");
}

var bulge = Math.Tan((double)angle / 4) * BulgeDirection(arc.startPoint, arc.midPoint, arc.endPoint);
var bulge = Math.Tan(measure / 4) * BulgeDirection(arc.startPoint, arc.midPoint, arc.endPoint);
polyline.AddVertexAt(count, _pointConverter.Convert(arc.startPoint).Convert2d(plane), bulge, 0, 0);
if (!target.closed && count == target.segments.Count - 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public SOG.Autocad.AutocadPolycurve Convert(ADB.Polyline3d target)
new()
{
segments = segments,
bulges = null,
tangents = null,
normal = null,
value = value,
polyType = polyType,
closed = target.Closed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public SOG.Autocad.AutocadPolycurve Convert(ADB.Polyline target)
value = value,
bulges = bulges,
normal = normal,
tangents = null,
elevation = target.Elevation,
polyType = SOG.Autocad.AutocadPolyType.Light,
closed = target.Closed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
SOP.Interval xSize = new() { start = target.MinPoint.X, end = target.MaxPoint.X };
SOP.Interval ySize = new() { start = target.MinPoint.Y, end = target.MaxPoint.Y };
SOP.Interval zSize = new() { start = target.MinPoint.Z, end = target.MaxPoint.Z };
double volume = xSize.Length * ySize.Length * zSize.Length;

// get the base plane of the bounding box from extents and current UCS
var ucs = _settingsStore.Current.Document.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d;
Expand All @@ -34,14 +33,13 @@
SOG.Plane plane = _planeConverter.Convert(acadPlane);

SOG.Box box =
new()

Check failure on line 36 in Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/BoxToSpeckleRawConverter.cs

View workflow job for this annotation

GitHub Actions / build

Required member 'Box.basePlane' must be set in the object initializer or attribute constructor.

Check failure on line 36 in Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/BoxToSpeckleRawConverter.cs

View workflow job for this annotation

GitHub Actions / build

Required member 'Box.basePlane' must be set in the object initializer or attribute constructor.
{
basePlane = plane,
plane = plane,

Check failure on line 38 in Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/BoxToSpeckleRawConverter.cs

View workflow job for this annotation

GitHub Actions / build

'Box' does not contain a definition for 'plane'

Check failure on line 38 in Converters/Autocad/Speckle.Converters.AutocadShared/ToSpeckle/Raw/BoxToSpeckleRawConverter.cs

View workflow job for this annotation

GitHub Actions / build

'Box' does not contain a definition for 'plane'
xSize = xSize,
ySize = ySize,
zSize = zSize,
units = _settingsStore.Current.SpeckleUnits,
volume = volume,
units = _settingsStore.Current.SpeckleUnits
};

return box;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@ public SOG.Arc Convert(AG.CircularArc2d target)
{
string units = _settingsStore.Current.SpeckleUnits;

// find arc plane (normal is in clockwise dir)
// find arc plane (normal is in counterclockwise dir)
var center3 = new AG.Point3d(target.Center.X, target.Center.Y, 0);
AG.Plane plane = target.IsClockWise
? new AG.Plane(center3, AG.Vector3d.ZAxis.MultiplyBy(-1))
: new AG.Plane(center3, AG.Vector3d.ZAxis);

// calculate total angle. TODO: This needs to be validated across all possible arc orientations
var totalAngle = target.IsClockWise
? Math.Abs(target.EndAngle - target.StartAngle)
: Math.Abs(target.EndAngle - target.StartAngle);

double startParam = target.GetParameterOf(target.StartPoint);
double endParam = target.GetParameterOf(target.EndPoint);
AG.Point2d midPoint = target.EvaluatePoint(target.StartAngle + (target.EndAngle - target.StartAngle) / 2);
Expand All @@ -40,7 +35,6 @@ public SOG.Arc Convert(AG.CircularArc2d target)
var arc = new SOG.Arc()
{
plane = _planeConverter.Convert(plane),
radius = target.Radius,
startPoint = new()
{
x = target.StartPoint.X,
Expand All @@ -62,11 +56,7 @@ public SOG.Arc Convert(AG.CircularArc2d target)
z = 0,
units = units
},
startAngle = target.StartAngle,
endAngle = target.EndAngle,
angleRadians = totalAngle,
domain = new SOP.Interval { start = startParam, end = endParam },
length = target.GetLength(0, 1),
units = units
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ IConverterSettingsStore<AutocadConversionSettings> settingsStore

public SOG.Arc Convert(AG.CircularArc3d target)
{
SOG.Plane plane = _planeConverter.Convert(target.GetPlane());
SOG.Plane plane = _planeConverter.Convert(new(target.Center, target.Normal));
SOG.Point start = _pointConverter.Convert(target.StartPoint);
SOG.Point end = _pointConverter.Convert(target.EndPoint);
double startParam = target.GetParameterOf(target.StartPoint);
Expand All @@ -31,20 +31,14 @@ public SOG.Arc Convert(AG.CircularArc3d target)
SOG.Point mid = _pointConverter.Convert(midPoint);

SOG.Arc arc =
new(
plane,
target.Radius,
target.StartAngle,
target.EndAngle,
target.EndAngle - target.StartAngle, // POC: testing, unsure
_settingsStore.Current.SpeckleUnits
)
new()
{
plane = plane,
startPoint = start,
endPoint = end,
midPoint = mid,
domain = new SOP.Interval { start = startParam, end = endParam },
length = target.GetLength(0, 1, 0.000)
units = _settingsStore.Current.SpeckleUnits,
};

return arc;
Expand Down
Loading
Loading