Skip to content

Commit

Permalink
Fixed: ExportStep Failure #145
Browse files Browse the repository at this point in the history
Fixed: cylinder sphere intersection (special cases)
  • Loading branch information
SOFAgh committed Dec 12, 2024
1 parent 5b5cecc commit 0e8ab39
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 73 deletions.
12 changes: 10 additions & 2 deletions CADability/Arc2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,16 @@ public override ICurve2D GetModified(ModOp2D m)
return new Arc2D(m * Center, Math.Abs(m.Determinant * Radius), m * StartPoint, m * EndPoint, cc);
}
Geometry.PrincipalAxis(m * Center, m * (Radius * GeoVector2D.XAxis), m * (Radius * GeoVector2D.YAxis), out majorAxis, out minorAxis, out left, out right, out bottom, out top, false);
double a1 = GeoVector2D.Area(m * (Radius * GeoVector2D.XAxis), m * (Radius * GeoVector2D.YAxis));
double a2 = GeoVector2D.Area(majorAxis, minorAxis);
// geändert wg. Fehler in IsIsogonal Fall, noch nicht getestet
return EllipseArc2D.Create(m * Center, majorAxis, minorAxis, m * StartPoint, m * EndPoint, cc);
EllipseArc2D res = EllipseArc2D.Create(m * Center, majorAxis, minorAxis, m * StartPoint, m * EndPoint, cc);
double rpos = res.PositionOf(m*this.PointAt(0.5));
if (rpos < 0 || rpos>1)
{
res = EllipseArc2D.Create(m * Center, majorAxis, minorAxis, m * StartPoint, m * EndPoint, !cc);
}
return res;

//if (m.Determinant < 0.0)
//{
Expand Down Expand Up @@ -888,7 +896,7 @@ internal override void GetTriangulationPoints(out GeoPoint2D[] interpol, out dou
{
int n = (int)Math.Floor(Math.Abs(sweep) / (Math.PI / 2.0)) + 1;
if (n == 1) n = 2;
interparam=new double[n];
interparam = new double[n];
for (int i = 0; i < n; i++)
{
interparam[i] = i / (double)(n - 1);
Expand Down
4 changes: 2 additions & 2 deletions CADability/ExportStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ public int WriteAxis2Placement3d(GeoPoint location, GeoVector normal, GeoVector
int nl = (location as IExportStep).Export(this, false);
int n = (normal.Normalized as IExportStep).Export(this, false);
int nx = (xdir.Normalized as IExportStep).Export(this, false);
return WriteDefinition("AXIS2_PLACEMENT_3D('',#" + nl.ToString() + ",#" + n.ToString() + ",#" + nx.ToString() + ");");
return WriteDefinition("AXIS2_PLACEMENT_3D('',#" + nl.ToString() + ",#" + n.ToString() + ",#" + nx.ToString() + ")");
}
public int WriteAxis1Placement3d(GeoPoint location, GeoVector normal)
{
int nl = (location as IExportStep).Export(this, false);
int n = (normal.Normalized as IExportStep).Export(this, false);
return WriteDefinition("AXIS1_PLACEMENT('',#" + nl.ToString() + ",#" + n.ToString() + ");");
return WriteDefinition("AXIS1_PLACEMENT('',#" + nl.ToString() + ",#" + n.ToString() + ")");
}

internal string ToString(int[] ints, bool makeReference)
Expand Down
9 changes: 8 additions & 1 deletion CADability/GeneralCurve2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,14 @@ public virtual double PositionOf(GeoPoint2D p)
{
found = FindPerpendicularFoot(p, 0.0, 1.0, StartPoint, EndPoint, StartDirection.ToRight(), EndDirection.ToRight(), out res);
}
if (!found) return double.MinValue;
if (!found)
{
double ds = p | StartPoint;
double de = p | EndPoint;
if (ds < this.Length * 1e-4) return 0.0;
if (de < this.Length * 1e-4) return 1.0;
return double.MinValue;
}
return res;
}
/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions CADability/GeoPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,10 @@ public bool SameGeometry(Axis other)
}
return false;
}
public double Distance(GeoPoint p)
{
return Geometry.DistPL(p, this);
}
#region ISerializable Members
/// <summary>
/// Constructor required by deserialization
Expand Down
4 changes: 2 additions & 2 deletions CADability/ImportStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2721,7 +2721,7 @@ private object CreateEntity(Item item)
case Item.ItemType.curveBoundedSurface: // basis_surface : Surface; boundaries: SET[1 : ?] OF Boundary_Curve; implicit_outer: BOOLEAN;
{
#if DEBUG
if (2932 == item.definingIndex || 13754 == item.definingIndex)
if (237 == item.definingIndex || 13754 == item.definingIndex)
{
}
#endif
Expand Down Expand Up @@ -2795,7 +2795,7 @@ private object CreateEntity(Item item)
case Item.ItemType.advancedFace: // name, bounds, face_geometry, same_sense
{
#if DEBUG
if (14640 == item.definingIndex || 17778 == item.definingIndex)
if (237 == item.definingIndex || 205 == item.definingIndex)
{
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion CADability/ModOp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public bool IsIsogonal
get
{
if (!Precision.IsPerpendicular(new GeoVector2D(Matrix00, Matrix10), new GeoVector2D(Matrix01, Matrix11), false)) return false;
//if (!Precision.IsPerpendicular(new GeoVector2D(Matrix00 + Matrix10, Matrix01 + Matrix11), new GeoVector2D(Matrix00 - Matrix10, -Matrix01 + Matrix11), false)) return false;
if (!Precision.IsPerpendicular(new GeoVector2D(Matrix00 + Matrix10, Matrix01 + Matrix11), new GeoVector2D(Matrix00 - Matrix10, -Matrix01 + Matrix11), false)) return false;
return true;
}
}
Expand Down
132 changes: 67 additions & 65 deletions CADability/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,88 +1563,90 @@ internal static Project ReadFromFile(string FileName, bool useProgress)
//FileName = dlg.FileName;
}
Project res = null;
FileStream stream = File.Open(FileName, FileMode.Open, System.IO.FileAccess.Read);
int firstByte = stream.ReadByte();
stream.Seek(0, SeekOrigin.Begin);
if (firstByte == 123)
using (FileStream stream = File.Open(FileName, FileMode.Open, System.IO.FileAccess.Read))
{
res = ReadFromJson(stream);
if (res != null)
int firstByte = stream.ReadByte();
stream.Seek(0, SeekOrigin.Begin);
if (firstByte == 123)
{
res.fileName = FileName;
res.openedAsJson = true;
stream.Close();
return res;
res = ReadFromJson(stream);
if (res != null)
{
res.fileName = FileName;
res.openedAsJson = true;
stream.Close();
return res;
}
}
}
//Form.ActiveForm.Update();
//ReadProgress progress = new ReadProgress(stream);
//ProgressFeedBack pf = null;
//if (useProgress)
//{
// pf = new ProgressFeedBack();
// pf.Title = StringTable.GetFormattedString("ReadFile.Progress", FileName);
// pf.StreamPosition(50, stream);
// pf.Float(100);
//}
//ReadProgress.ShowProgressDelegate showProgressDelegate = new ReadProgress.ShowProgressDelegate(progress.ShowProgress);
// ReadProgress funktioniert noch nicht perfekt.
try
{
//if (pf != null) pf.Start();
//showProgressDelegate.BeginInvoke(null,null);
res = ReadFromStream(stream);
if (res == null)
//Form.ActiveForm.Update();
//ReadProgress progress = new ReadProgress(stream);
//ProgressFeedBack pf = null;
//if (useProgress)
//{
// pf = new ProgressFeedBack();
// pf.Title = StringTable.GetFormattedString("ReadFile.Progress", FileName);
// pf.StreamPosition(50, stream);
// pf.Float(100);
//}
//ReadProgress.ShowProgressDelegate showProgressDelegate = new ReadProgress.ShowProgressDelegate(progress.ShowProgress);
// ReadProgress funktioniert noch nicht perfekt.
try
{
stream.Close();
//if (pf != null) pf.Start();
//showProgressDelegate.BeginInvoke(null,null);
res = ReadFromStream(stream);
if (res == null)
{
stream.Close();

return null;
return null;
}
res.fileName = FileName;
}
res.fileName = FileName;
}
catch (ProjectOldVersionException ex)
{
stream.Close();
stream.Dispose();
if (cdbFixFw2 == null)
catch (ProjectOldVersionException ex)
{
Assembly ThisAssembly = Assembly.GetExecutingAssembly();
int lastSlash = ThisAssembly.Location.LastIndexOf('\\');
if (lastSlash >= 0)
stream.Close();
stream.Dispose();
if (cdbFixFw2 == null)
{
string path = ThisAssembly.Location.Substring(0, lastSlash);
lastSlash = path.LastIndexOf('\\');
//if (lastSlash >= 0) // das geht noch ein level zurück, wir erwarten die Anwendung im selben Verzeichnis wie CADability
//{
// path = path.Substring(0, lastSlash);
//}
string[] files = Directory.GetFiles(path, "cdbFixFw2.exe", SearchOption.AllDirectories);
if (files.Length > 0)
Assembly ThisAssembly = Assembly.GetExecutingAssembly();
int lastSlash = ThisAssembly.Location.LastIndexOf('\\');
if (lastSlash >= 0)
{
cdbFixFw2 = files[0];
string path = ThisAssembly.Location.Substring(0, lastSlash);
lastSlash = path.LastIndexOf('\\');
//if (lastSlash >= 0) // das geht noch ein level zurück, wir erwarten die Anwendung im selben Verzeichnis wie CADability
//{
// path = path.Substring(0, lastSlash);
//}
string[] files = Directory.GetFiles(path, "cdbFixFw2.exe", SearchOption.AllDirectories);
if (files.Length > 0)
{
cdbFixFw2 = files[0];
}
}
}
}
if (cdbFixFw2 != null)
{
Process process = Process.Start(cdbFixFw2, "\"" + FileName + "\"");
if (process != null)
if (cdbFixFw2 != null)
{
process.WaitForExit();
if (process.ExitCode == 0) // d.h. OK
Process process = Process.Start(cdbFixFw2, "\"" + FileName + "\"");
if (process != null)
{
return ReadConvertedFile(FileName, useProgress);
process.WaitForExit();
if (process.ExitCode == 0) // d.h. OK
{
return ReadConvertedFile(FileName, useProgress);
}
}
}
}
finally
{
//if (pf != null) pf.Stop();
//progress.Finished();
stream.Close();
}
return res;
}
finally
{
//if (pf != null) pf.Stop();
//progress.Finished();
stream.Close();
}
return res;
}
private static Project ReadFromJson(FileStream stream)
{
Expand Down
5 changes: 5 additions & 0 deletions CADability/SelectObjectsAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,11 @@ public void AddSelectedObjects(GeoObjectList selObj)
bool ok = true;
if (selObj[0] is Solid)
{
foreach (Edge edge in (selObj[0] as Solid).Shells[0].Edges)
{
if (edge.Curve3D!=null && edge.Curve3D.GetExtent().Zmin<-0.1)
{ }
}
ok = (selObj[0] as Solid).Shells[0].CheckConsistency();
//Shell sh = (selObj[0] as Solid).Shells[0].Clone() as Shell;
//sh.RecalcVertices();
Expand Down
16 changes: 16 additions & 0 deletions CADability/SphericalSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,22 @@ public override IDualSurfaceCurve[] GetDualSurfaceCurves(BoundingRect thisBounds
}
return new IDualSurfaceCurve[0];
}
else if (other is ICylinder cyl)
{
if (cyl.Axis.Distance(this.Location)<Precision.eps && Math.Abs(cyl.Radius-this.RadiusX)<Precision.eps)
{ // this sphere is touching the cylinder:
Plane pln = new Plane(Location, cyl.Axis.Direction); // the plane through center of this sphere, perpendicular to the cylinder axis
IDualSurfaceCurve[] cylcrv = other.GetPlaneIntersection(new PlaneSurface(pln), otherBounds.Left, otherBounds.Right, otherBounds.Bottom, otherBounds.Top, 0.0);
if (cylcrv!=null && cylcrv.Length==1)
{
if (cylcrv[0].Curve3D is Ellipse elli)
{
ICurve2D pc = this.GetProjectedCurve(elli, 0.0);
return new IDualSurfaceCurve[] { new DualSurfaceCurve(elli, this, pc, other, cylcrv[0].Curve2D1) };
}
}
}
}
return base.GetDualSurfaceCurves(thisBounds, other, otherBounds, seeds, extremePositions);
}
public override GeoPoint2D[] PerpendicularFoot(GeoPoint fromHere)
Expand Down

0 comments on commit 0e8ab39

Please sign in to comment.