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

Import step fix #180

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions CADability/BSpline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,7 @@ public GeoPoint PointAtParam(double param)
lock (this)
{
if (!nurbsHelper) MakeNurbsHelper();
if (plane.HasValue)
if (plane.HasValue && (nubs2d != null | nurbs2d != null))
{
if (nubs2d != null)
{
Expand Down Expand Up @@ -2069,7 +2069,6 @@ private void PointDirAtParam(double param, out GeoPoint point, out GeoVector dir
lock (this)
{
if (!nurbsHelper) MakeNurbsHelper();

if (plane.HasValue && (nubs2d != null | nurbs2d != null))
{
if (nubs2d != null)
Expand Down
241 changes: 121 additions & 120 deletions CADability/ImportStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,7 @@ private object CreateEntity(Item item)
pnt.Symbol = PointSymbol.Cross;
pnt.Name = subItem.parameter["name"].sval;
val.Add(pnt);
subItem.val = pnt; //For this CartesianPoint a Cadability Point is generated. I set it to the item instead of GeoPoint to make it work layer assignment.
}
else if (o is IGeoObject) val.Add(o as IGeoObject);
else if (o is GeoObjectList) val.AddRange(o as GeoObjectList);
Expand Down Expand Up @@ -4350,9 +4351,9 @@ private object CreateEntity(Item item)
case Item.ItemType.colourRgb:
{
string name = item.parameter["name"].sval;
int red = (int)(item.parameter["red"].fval * 255);
int green = (int)(item.parameter["green"].fval * 255);
int blue = (int)(item.parameter["blue"].fval * 255);
int red = (int)Math.Round(item.parameter["red"].fval * 255);
int green = (int)Math.Round(item.parameter["green"].fval * 255);
int blue = (int)Math.Round(item.parameter["blue"].fval * 255);
if (string.IsNullOrWhiteSpace(name)) name = "rgb:" + red.ToString() + "_" + green.ToString() + "_" + blue.ToString();
item.val = new ColorDef(name, Color.FromArgb(red, green, blue));
AvoidDuplicateColorNames(item.val as ColorDef);
Expand All @@ -4370,123 +4371,123 @@ private object CreateEntity(Item item)
{
string nm = item.SubString(0);
object oo = CreateEntity(item.SubItem(1));
if (oo is ICurve basisCurve)
{
basisCurve = basisCurve.Clone();
double startParameter = double.MinValue;
double endParameter = double.MinValue;
GeoPoint startPoint = GeoPoint.Invalid;
GeoPoint endPoint = GeoPoint.Invalid;
if (item.SubItem(2).type == Item.ItemType.list)
{
List<Item> lst = (item.SubItem(2).val as List<Item>);
for (int i = 0; i < lst.Count; i++)
{
object o = CreateEntity(lst[i]);
if (o is List<Item>) o = (o as List<Item>)[0].val;
if (o is double) startParameter = (double)o;
if (o is GeoPoint) startPoint = (GeoPoint)o;
}
}
if (item.SubItem(3).type == Item.ItemType.list)
{
List<Item> lst = (item.SubItem(3).val as List<Item>);
for (int i = 0; i < lst.Count; i++)
{
object o = CreateEntity(lst[i]);
if (o is List<Item>) o = (o as List<Item>)[0].val;
if (o is double) endParameter = (double)o;
if (o is GeoPoint) endPoint = (GeoPoint)o;
}
}
bool sense = item.SubBool(4);
string masterRepresentation = item.SubString(5);
if (startParameter != double.MinValue && masterRepresentation != "CARTESIAN")
{
// trimmed curve defined by start- and endParameter
if (basisCurve is Ellipse)
{
if (context != null)
{
startParameter = context.toRadian * startParameter;
endParameter = context.toRadian * endParameter;
}
}
if (!sense) basisCurve.Reverse();
if (startParameter != endParameter) basisCurve.Trim(basisCurve.ParameterToPosition(startParameter), basisCurve.ParameterToPosition(endParameter));
item.val = basisCurve;
}
else if (startPoint.IsValid && endPoint.IsValid)
{
// trimmed curve defined by start- and endpoint
if (!sense) basisCurve.Reverse();
double startPos = basisCurve.PositionOf(startPoint);
double endPos = basisCurve.PositionOf(endPoint);
basisCurve.Trim(startPos, endPos);
item.val = basisCurve;
}
}
else if (oo is ICurve2D basisCurve2d)
{
basisCurve2d = basisCurve2d.Clone();
double startParameter = double.MinValue;
double endParameter = double.MinValue;
GeoPoint2D startPoint = GeoPoint2D.Invalid;
GeoPoint2D endPoint = GeoPoint2D.Invalid;
if (item.SubItem(2).type == Item.ItemType.list)
{
List<Item> lst = (item.SubItem(2).val as List<Item>);
for (int i = 0; i < lst.Count; i++)
{
object o = CreateEntity(lst[i]);
if (o is List<Item>) o = (o as List<Item>)[0].val;
if (o is double) startParameter = (double)o;
if (o is GeoPoint2D) startPoint = (GeoPoint2D)o;
}
}
if (item.SubItem(3).type == Item.ItemType.list)
{
List<Item> lst = (item.SubItem(3).val as List<Item>);
for (int i = 0; i < lst.Count; i++)
{
object o = CreateEntity(lst[i]);
if (o is List<Item>) o = (o as List<Item>)[0].val;
if (o is double) endParameter = (double)o;
if (o is GeoPoint2D) endPoint = (GeoPoint2D)o;
}
}
bool sense = item.SubBool(4);
string masterRepresentation = item.SubString(5);
if (startParameter != double.MinValue && masterRepresentation != "CARTESIAN")
{
// trimmed curve defined by start- and endParameter
if (basisCurve2d is Ellipse2D elli2d)
{
if (context != null)
{
startParameter = context.toRadian * startParameter;
endParameter = context.toRadian * endParameter;
}
elli2d.Trim(startParameter / (2 * Math.PI), endParameter / (2 * Math.PI));
}
else
{ // are all other curves from 0 to 1 ??? there is no "ParameterToPosition" for 2d curves
// basisCurve2d.Trim(basisCurve2d.ParameterToPosition(startParameter), basisCurve.ParameterToPosition(endParameter));
basisCurve2d.Trim(startParameter, endParameter);
}
if (!sense) basisCurve2d.Reverse();
item.val = basisCurve2d;
}
else if (startPoint.IsValid && endPoint.IsValid)
{
// trimmed curve defined by start- and endpoint
double startPos = basisCurve2d.PositionOf(startPoint);
double endPos = basisCurve2d.PositionOf(endPoint);
basisCurve2d.Trim(startPos, endPos);
if (!sense) basisCurve2d.Reverse();
item.val = basisCurve2d;
}
}
if (oo is ICurve basisCurve)
{
basisCurve = basisCurve.Clone();
double startParameter = double.MinValue;
double endParameter = double.MinValue;
GeoPoint startPoint = GeoPoint.Invalid;
GeoPoint endPoint = GeoPoint.Invalid;
if (item.SubItem(2).type == Item.ItemType.list)
{
List<Item> lst = (item.SubItem(2).val as List<Item>);
for (int i = 0; i < lst.Count; i++)
{
object o = CreateEntity(lst[i]);
if (o is List<Item>) o = (o as List<Item>)[0].val;
if (o is double) startParameter = (double)o;
if (o is GeoPoint) startPoint = (GeoPoint)o;
}
}
if (item.SubItem(3).type == Item.ItemType.list)
{
List<Item> lst = (item.SubItem(3).val as List<Item>);
for (int i = 0; i < lst.Count; i++)
{
object o = CreateEntity(lst[i]);
if (o is List<Item>) o = (o as List<Item>)[0].val;
if (o is double) endParameter = (double)o;
if (o is GeoPoint) endPoint = (GeoPoint)o;
}
}
bool sense = item.SubBool(4);
string masterRepresentation = item.SubString(5);
if (startParameter != double.MinValue && masterRepresentation != "CARTESIAN")
{
// trimmed curve defined by start- and endParameter
if (basisCurve is Ellipse)
{
if (context != null)
{
startParameter = context.toRadian * startParameter;
endParameter = context.toRadian * endParameter;
}
}
if (!sense) basisCurve.Reverse();
if (startParameter != endParameter) basisCurve.Trim(basisCurve.ParameterToPosition(startParameter), basisCurve.ParameterToPosition(endParameter));
item.val = basisCurve;
}
else if (startPoint.IsValid && endPoint.IsValid)
{
// trimmed curve defined by start- and endpoint
if (!sense) basisCurve.Reverse();
double startPos = basisCurve.PositionOf(startPoint);
double endPos = basisCurve.PositionOf(endPoint);
basisCurve.Trim(startPos, endPos);
item.val = basisCurve;
}
}
else if (oo is ICurve2D basisCurve2d)
{
basisCurve2d = basisCurve2d.Clone();
double startParameter = double.MinValue;
double endParameter = double.MinValue;
GeoPoint2D startPoint = GeoPoint2D.Invalid;
GeoPoint2D endPoint = GeoPoint2D.Invalid;
if (item.SubItem(2).type == Item.ItemType.list)
{
List<Item> lst = (item.SubItem(2).val as List<Item>);
for (int i = 0; i < lst.Count; i++)
{
object o = CreateEntity(lst[i]);
if (o is List<Item>) o = (o as List<Item>)[0].val;
if (o is double) startParameter = (double)o;
if (o is GeoPoint2D) startPoint = (GeoPoint2D)o;
}
}
if (item.SubItem(3).type == Item.ItemType.list)
{
List<Item> lst = (item.SubItem(3).val as List<Item>);
for (int i = 0; i < lst.Count; i++)
{
object o = CreateEntity(lst[i]);
if (o is List<Item>) o = (o as List<Item>)[0].val;
if (o is double) endParameter = (double)o;
if (o is GeoPoint2D) endPoint = (GeoPoint2D)o;
}
}
bool sense = item.SubBool(4);
string masterRepresentation = item.SubString(5);
if (startParameter != double.MinValue && masterRepresentation != "CARTESIAN")
{
// trimmed curve defined by start- and endParameter
if (basisCurve2d is Ellipse2D elli2d)
{
if (context != null)
{
startParameter = context.toRadian * startParameter;
endParameter = context.toRadian * endParameter;
}
elli2d.Trim(startParameter / (2 * Math.PI), endParameter / (2 * Math.PI));
}
else
{ // are all other curves from 0 to 1 ??? there is no "ParameterToPosition" for 2d curves
// basisCurve2d.Trim(basisCurve2d.ParameterToPosition(startParameter), basisCurve.ParameterToPosition(endParameter));
basisCurve2d.Trim(startParameter, endParameter);
}
if (!sense) basisCurve2d.Reverse();
item.val = basisCurve2d;
}
else if (startPoint.IsValid && endPoint.IsValid)
{
// trimmed curve defined by start- and endpoint
double startPos = basisCurve2d.PositionOf(startPoint);
double endPos = basisCurve2d.PositionOf(endPoint);
basisCurve2d.Trim(startPos, endPos);
if (!sense) basisCurve2d.Reverse();
item.val = basisCurve2d;
}
}
}
break;
case Item.ItemType.mappedItem:
Expand Down
2 changes: 1 addition & 1 deletion CADability/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5779,7 +5779,7 @@ public Face[][] FindSameForm(Face[] form, double precision, FindSameFormSearchMo
internal static Shell MakeShell(Face[] faces, bool tryToConnectOpenEdges = false)
{
Shell res = Shell.Construct();
res.colorDef = faces[0].ColorDef;
if (faces.Length > 0) res.colorDef = faces[0].ColorDef;
res.SetFaces(faces);
if (tryToConnectOpenEdges)
{
Expand Down