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

Fixed Null Reference exception, conversion hangs and merged with the main branch #322

Open
wants to merge 29 commits into
base: NetCoreApp31
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e73df8b
Merge pull request #223 from xBimTeam/develop
andyward Oct 9, 2019
402ffcc
Added additional guard to be more tolerant when processing models wit…
andyward Oct 25, 2019
6c98867
More graceful handling of representations without a ContextOfItems. T…
andyward Oct 25, 2019
8c5db8c
Going for green.
andyward Oct 25, 2019
1dae92e
Fixes for SEH and other native code exceptions as well as improved ha…
SteveLockley Mar 27, 2020
477f612
Merge branch 'develop'
SteveLockley Apr 23, 2020
63732e0
Merge branch 'develop'
SteveLockley Apr 23, 2020
52705e3
Merge branch 'develop'
SteveLockley Jun 10, 2020
b3e1320
Update azure-pipelines.yml for Azure Pipelines
martin1cerny Oct 15, 2020
2002e1d
Updated Essentials.
andyward Oct 15, 2020
70cef22
Target net472 - attempt to fix build
andyward Oct 15, 2020
d1c6085
Target net472 - attempt to fix build
andyward Oct 15, 2020
b8152f7
Fixed HintPaths after net472 update
andyward Oct 17, 2020
df298ec
Fixed HintPaths after net472 update
andyward Oct 17, 2020
c39b50b
Build fix: Removed use of deprecated PackageIconUrl in packaging
andyward Oct 18, 2020
e3ef2e7
Update azure-pipelines.yml for Azure Pipelines
andyward Oct 18, 2020
57f9923
Updated the latest Essentials and stubbed implementation of new inter…
andyward Oct 23, 2020
9fb2519
Stubbed out implementation
andyward Oct 26, 2020
67837ce
Updated Essentials
martin1cerny Nov 18, 2020
039e59e
Merge branch 'develop'
SteveLockley Dec 15, 2020
1ec19ba
Merged develop
SteveLockley Dec 15, 2020
02ce514
Merged with Development
SteveLockley Dec 15, 2020
9dd9f04
Stubbed missing interface methods.
CBenghi Mar 3, 2021
c1ba561
Added regression commands for debugging.
CBenghi Mar 3, 2021
4007f28
merged
dmk-rib Mar 29, 2021
6e0f719
Fixed merge issues
dmk-rib Mar 29, 2021
ec86029
Fixed null ref errors
dmk-rib Apr 7, 2021
815a1af
Fixed file hang issues
dmk-rib Apr 7, 2021
9081cb6
Update XbimSolidSet.cpp
dmk-rib Apr 15, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.8" />
<PackageReference Include="Xbim.Essentials" Version="5.1.313-develop" />
<PackageReference Include="Xbim.Essentials" Version="5.1.328" />
</ItemGroup>
<Choose>
<When Condition="'$(Platform)'=='AnyCPU'">
Expand Down
4 changes: 2 additions & 2 deletions Xbim.Geometry.Engine.Interop/XbimCustomAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private static Assembly ProbeForAssembly(string moduleName)
{
_logger.LogDebug("Getting probing path from executing assembly");
Assembly assembly = Assembly.GetExecutingAssembly(); // The Xbim.Geometry.Engine.Interop assembly
// code base always points to the deployed DLL, which may be different to the executing Location because of Shadow Copying in the AppDomain (e.g. ASP.NET)
var codepath = new Uri(assembly.CodeBase);
// Location always points to the deployed DLL, which may be different to the executing Location because of Shadow Copying in the AppDomain (e.g. ASP.NET)
var codepath = new Uri(assembly.Location);
// Unlike Assembly.Location, CodeBase is a URI [file:\\c:\wwwroot\etc\WebApp\bin\Xbim.Geometry.Engine.Interop.dll]
appDir = Path.GetDirectoryName(codepath.LocalPath);
}
Expand Down
14 changes: 12 additions & 2 deletions Xbim.Geometry.Engine.Interop/XbimGeometryEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public XbimGeometryEngine(ILogger<XbimGeometryEngine> logger)
{
_logger = logger ?? XbimLogging.CreateLogger<XbimGeometryEngine>();

// Warn if runtime for Engine is not present, this is not necessary any more as we are net47

#if DELAY_LOAD

var conventions = new XbimArchitectureConventions(); // understands the process we run under
Expand Down Expand Up @@ -818,6 +816,18 @@ public string ToBrep(IXbimGeometryObject geometryObject)
}
}

public void WriteBrep(string filename, IXbimGeometryObject geomObj)
{
// no logger is provided so no tracing is started for this function
_engine.WriteBrep(filename, geomObj);
}

public IXbimGeometryObject ReadBrep(string filename)
{
// no logger is provided so no tracing is started for this function
return _engine.ReadBrep(filename);
}

public IXbimSolidSet CreateSolidSet(IIfcSweptAreaSolid ifcSolid, ILogger logger = null)
{
using (new Tracer(LogHelper.CurrentFunctionName(), this._logger, ifcSolid))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@ Standard_Real GetNextParamOnPC(const Handle(Geom2d_Curve)& aPC,
{
Standard_Real result = ( reverse ) ? fP : lP;
Standard_Real dP = Abs( lP - fP ) / 1000.; // was / 16.;
// Ensure incrememt is large enough to effect startPar
Standard_Real resolution = Abs(fP / Pow(2, 52));
dP = Max(dP, resolution);
if( reverse )
{
Standard_Real startPar = fP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,12 @@ static void RelocatePCurvesToNewUorigin(const TopTools_SequenceOfShape& theEdges
for (;;) //collect pcurves of a contour
{
RemoveEdgeFromMap(CurEdge, theVEmap);
theUsedEdges.Add(CurEdge);
Standard_Boolean notUsed = theUsedEdges.Add(CurEdge);
if (!notUsed)
break;
TopoDS_Vertex CurVertex = (anOr == TopAbs_FORWARD)?
TopExp::LastVertex(CurEdge, Standard_True) : TopExp::FirstVertex(CurEdge, Standard_True);
const TopTools_ListOfShape& Elist = theVEmap.FindFromKey(CurVertex);
if (Elist.IsEmpty())
break; //end of contour in 3d
Expand Down
57 changes: 26 additions & 31 deletions Xbim.Geometry.Engine/XbimFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1780,38 +1780,33 @@ namespace Xbim
//trim 1 and trim 2 will be cartesian points
IIfcCartesianPoint^ trim1 = dynamic_cast<IIfcCartesianPoint^>(Enumerable::FirstOrDefault(tc->Trim1));
IIfcCartesianPoint^ trim2 = dynamic_cast<IIfcCartesianPoint^>(Enumerable::FirstOrDefault(tc->Trim2));
gp_Pnt p1 = XbimConvert::GetPoint3d(trim1);
gp_Pnt p2 = XbimConvert::GetPoint3d(trim2);
//there are two solutions A, B
//calc solution A
double radsq = circle->Radius * circle->Radius;
double qX = System::Math::Sqrt(((p2.X() - p1.X()) * (p2.X() - p1.X())) + ((p2.Y() - p1.Y()) * (p2.Y() - p1.Y())));
double x3 = (p1.X() + p2.X()) / 2;
double centreX = x3 - System::Math::Sqrt(radsq - ((qX / 2) * (qX / 2))) * ((p1.Y() - p2.Y()) / qX);

double qY = System::Math::Sqrt(((p2.X() - p1.X()) * (p2.X() - p1.X())) + ((p2.Y() - p1.Y()) * (p2.Y() - p1.Y())));

double y3 = (p1.Y() + p2.Y()) / 2;

double centreY = y3 - System::Math::Sqrt(radsq - ((qY / 2) * (qY / 2))) * ((p2.X() - p1.X()) / qY);



ITransaction^ txn = sLin->Model->BeginTransaction("Fix Centre");


IIfcPlacement^ p = dynamic_cast<IIfcPlacement^>(circle->Position);

p->Location->Coordinates[0] = centreX;
p->Location->Coordinates[1] = centreY;
p->Location->Coordinates[2] = 0;

xbasisEdge1 = gcnew XbimEdge(sLin->SweptCurve, logger);
txn->RollBack();
isFixed = true;
if (trim1 != nullptr && trim2 != nullptr)
{
gp_Pnt p1 = XbimConvert::GetPoint3d(trim1);
gp_Pnt p2 = XbimConvert::GetPoint3d(trim2);
//there are two solutions A, B
//calc solution A
double radsq = circle->Radius * circle->Radius;
double qX = System::Math::Sqrt(((p2.X() - p1.X()) * (p2.X() - p1.X())) + ((p2.Y() - p1.Y()) * (p2.Y() - p1.Y())));
double x3 = (p1.X() + p2.X()) / 2;
double centreX = x3 - System::Math::Sqrt(radsq - ((qX / 2) * (qX / 2))) * ((p1.Y() - p2.Y()) / qX);

double qY = System::Math::Sqrt(((p2.X() - p1.X()) * (p2.X() - p1.X())) + ((p2.Y() - p1.Y()) * (p2.Y() - p1.Y())));
double y3 = (p1.Y() + p2.Y()) / 2;
double centreY = y3 - System::Math::Sqrt(radsq - ((qY / 2) * (qY / 2))) * ((p2.X() - p1.X()) / qY);

ITransaction^ txn = sLin->Model->BeginTransaction("Fix Centre");

IIfcPlacement^ p = dynamic_cast<IIfcPlacement^>(circle->Position);
p->Location->Coordinates[0] = centreX;
p->Location->Coordinates[1] = centreY;
p->Location->Coordinates[2] = 0;

xbasisEdge1 = gcnew XbimEdge(sLin->SweptCurve, logger);
txn->RollBack();
isFixed = true;
}
}


}
if (!isFixed) //just build it
xbasisEdge1 = gcnew XbimEdge(sLin->SweptCurve, logger);
Expand Down
19 changes: 19 additions & 0 deletions Xbim.Geometry.Engine/XbimGeometryCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,21 @@ namespace Xbim
LoggerExtensions::LogDebug(logger, "GeomEngine: {0} [{1}]", entity->GetType()->Name, msg);
}
}

void XbimGeometryCreator::WriteBrep(System::String^ filename, IXbimGeometryObject^ geomObj)
{
throw gcnew System::NotImplementedException();
// TODO: This is stubbed out until we merge the implementation from unpushed code.
// temp fix for broken build
}

IXbimGeometryObject^ XbimGeometryCreator::ReadBrep(System::String^ filename)
{
throw gcnew System::NotImplementedException();
// TODO: This is stubbed out until we merge the implementation from unpushed code.
// temp fix for broken build
}

void XbimGeometryCreator::LogError(ILogger^ logger, Object^ entity, System::String^ format, ...array<Object^>^ arg)
{
System::String^ msg = System::String::Format(format, arg);
Expand Down Expand Up @@ -287,6 +301,11 @@ namespace Xbim
LogError(logger, geomRep, "Error creating geometry #{2} representation of type {0}, {1}", geomRep->GetType()->Name, err, geomRep->EntityLabel);
return XbimGeometryObjectSet::Empty;
}
catch (System::Exception^ exc)
{
LogError(logger, geomRep, "Error creating geometry #{2} representation of type {0}, {1}", geomRep->GetType()->Name, exc, geomRep->EntityLabel);
return XbimGeometryObjectSet::Empty;
}
//catch ()
catch (...)
{
Expand Down
11 changes: 7 additions & 4 deletions Xbim.Geometry.Engine/XbimGeometryCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Xbim
public ref class XbimGeometryCreator : IXbimGeometryEngine
{

static Assembly^ ResolveHandler(Object^ /*Sender*/, System::ResolveEventArgs^ /*args*/)
static Assembly^ ResolveHandler(Object^ /*Sender*/, System::ResolveEventArgs^ /*args*/)
{

// Warning: this should check the args for the assembly name!
Expand Down Expand Up @@ -80,6 +80,9 @@ namespace Xbim
static void LogError(ILogger^ logger, Object^ entity, System::String^ format, ... array<Object^>^ arg);
static void LogDebug(ILogger^ logger, Object^ entity, System::String^ format, ... array<Object^>^ arg);

virtual void WriteBrep(System::String^ filename, IXbimGeometryObject^ geomObj);
virtual IXbimGeometryObject^ ReadBrep(System::String^ filename);

static int BooleanTimeOut;
static double FuzzyFactor;
static double LinearDeflectionInMM;
Expand All @@ -90,7 +93,7 @@ namespace Xbim

virtual XbimShapeGeometry^ CreateShapeGeometry(IXbimGeometryObject^ geometryObject, double precision, double deflection, ILogger^ logger/*, double angle = 0.5, XbimGeometryType storageType = XbimGeometryType::Polyhedron*/)
{
return CreateShapeGeometry(geometryObject, precision, deflection, 0.5, XbimGeometryType::PolyhedronBinary,logger);
return CreateShapeGeometry(geometryObject, precision, deflection, 0.5, XbimGeometryType::PolyhedronBinary, logger);
};

virtual XbimShapeGeometry^ CreateShapeGeometry(double oneMillimetre, IXbimGeometryObject^ geometryObject, double precision, ILogger^ logger)
Expand Down Expand Up @@ -242,9 +245,9 @@ namespace Xbim
{
return Moved(geometryObject, (IIfcPlacement ^)placement);
};
virtual IXbimGeometryObject ^ Moved(IXbimGeometryObject ^geometryObject, IIfcAxis2Placement2D ^placement)
virtual IXbimGeometryObject^ Moved(IXbimGeometryObject^ geometryObject, IIfcAxis2Placement2D^ placement)
{
return Moved(geometryObject, (IIfcPlacement ^)placement);
return Moved(geometryObject, (IIfcPlacement^)placement);
};
virtual IXbimGeometryObject ^ Moved(IXbimGeometryObject ^geometryObject, IIfcObjectPlacement ^objectPlacement, ILogger^ logger);
virtual IXbimGeometryObject^ FromBrep(System::String^ brepStr);
Expand Down
4 changes: 2 additions & 2 deletions Xbim.Geometry.Engine/XbimSolid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1307,9 +1307,9 @@ namespace Xbim
{
//BRepTools::Write(revol.Shape(), "d:\\tmp\\rev");
pSolid = new TopoDS_Solid();
*pSolid = TopoDS::Solid(revol.Shape());
if (repItem->Position != nullptr)
*pSolid = TopoDS::Solid(revol.Shape());
pSolid->Move(XbimConvert::ToLocation(repItem->Position));
pSolid->Move(XbimConvert::ToLocation(repItem->Position));
ShapeFix_ShapeTolerance tolFixer;
tolFixer.LimitTolerance(*pSolid, repItem->Model->ModelFactors->Precision);
}
Expand Down
4 changes: 3 additions & 1 deletion Xbim.Geometry.Engine/XbimSolidSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,9 @@ namespace Xbim
if (dynamic_cast<IIfcHalfSpaceSolid^>(bOp) && bOp->GetType()->Name->Contains("IfcHalfSpaceSolid") ||
dynamic_cast<IIfcPolygonalBoundedHalfSpace^>(bOp) && bOp->GetType()->Name->Contains("IfcPolygonalBoundedHalfSpace"))
{
bodySet = (XbimSolidSet^)bodySet->Cut(s, mf->Precision, logger);
XbimSolidSet^ bodySetCut = (XbimSolidSet^)bodySet->Cut(s, mf->Precision, logger);
if (bodySetCut->IsValid)
bodySet = bodySetCut;
}
else
solidSet->Add(s);
Expand Down
35 changes: 18 additions & 17 deletions Xbim.Geometry.Engine/XbimWire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,27 +236,28 @@ namespace Xbim
pWire = new TopoDS_Wire();
if (profile->ProfileType == IfcProfileTypeEnum::AREA && !loop->IsClosed) //need to make sure it is not self intersecting and it is closed area
{

// todo: this code is not quite robust, it did not manage to close fairly simple polylines.
try
{


double oneMilli = profile->Model->ModelFactors->OneMilliMeter;
TopoDS_Face face = gcnew XbimFace(loop, true, oneMilli, profile->OuterCurve->EntityLabel, logger);
ShapeFix_Wire wireFixer(loop, face, profile->Model->ModelFactors->Precision);
wireFixer.ClosedWireMode() = Standard_True;
wireFixer.FixGaps2dMode() = Standard_True;
wireFixer.FixGaps3dMode() = Standard_True;
wireFixer.ModifyGeometryMode() = Standard_True;
wireFixer.SetMinTolerance(profile->Model->ModelFactors->Precision);
wireFixer.SetPrecision(oneMilli);
wireFixer.SetMaxTolerance(oneMilli * 10);
Standard_Boolean closed = wireFixer.Perform();
if (closed)
*pWire = wireFixer.Wire();
else
*pWire = loop;
XbimFace^ xbimFace = gcnew XbimFace(loop, true, oneMilli, profile->OuterCurve->EntityLabel, logger);
if (xbimFace->IsValid)
{
TopoDS_Face face = xbimFace;
ShapeFix_Wire wireFixer(loop, face, profile->Model->ModelFactors->Precision);
wireFixer.ClosedWireMode() = Standard_True;
wireFixer.FixGaps2dMode() = Standard_True;
wireFixer.FixGaps3dMode() = Standard_True;
wireFixer.ModifyGeometryMode() = Standard_True;
wireFixer.SetMinTolerance(profile->Model->ModelFactors->Precision);
wireFixer.SetPrecision(oneMilli);
wireFixer.SetMaxTolerance(oneMilli * 10);
Standard_Boolean closed = wireFixer.Perform();
if (closed)
*pWire = wireFixer.Wire();
else
*pWire = loop;
}
}
catch (Standard_Failure sf)
{
Expand Down
2 changes: 1 addition & 1 deletion Xbim.Geometry.Packages/Xbim.Geometry.Packages.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.8" />
<PackageReference Include="Xbim.Essentials" Version="5.1.313-develop" />
<PackageReference Include="Xbim.Essentials" Version="5.1.328" />
</ItemGroup>

</Project>
78 changes: 75 additions & 3 deletions Xbim.Geometry.Regression/BatchProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using Xbim.Common;
using Xbim.Geometry.Engine.Interop;
using Xbim.Ifc;
using Xbim.Ifc4.Interfaces;
using Xbim.IO.Memory;
Expand Down Expand Up @@ -121,7 +122,6 @@ private ProcessResult ProcessFile(string ifcFile, StreamWriter writer, ILogger<B
var watch = new Stopwatch();
try
{

watch.Start();
using (var model = ParseModelFile(ifcFile, Params.Caching, logger))
{
Expand Down Expand Up @@ -169,11 +169,83 @@ private ProcessResult ProcessFile(string ifcFile, StreamWriter writer, ILogger<B
};

}

// Option to save breps of encountered classes by type or entityLabel for debugging purposes

if (_params.WriteBreps)
{
var path = Path.Combine(
Path.GetDirectoryName(ifcFile),
Path.GetFileName(ifcFile) + ".brep.unclassified");
IXbimGeometryEngine engine = new XbimGeometryEngine();
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
IfcStore s = model as IfcStore;
if (s != null)
{
var ents = new List<IPersistEntity>();

var exportBrepByType = new string[]
{
"IfcFacetedBrep",
// IIfcGeometricRepresentationItem
"IfcCsgSolid",
"IfcExtrudedAreaSolid",
"IfcExtrudedAreaSolidTapered",
"IfcFixedReferenceSweptAreaSolid",
"IfcRevolvedAreaSolid",
"IfcRevolvedAreaSolidTapered",
"IfcSurfaceCurveSweptAreaSolid",
"IfcSectionedSolidHorizontal",
"IfcSweptDiskSolid",
"IfcSweptDiskSolidPolygonal",
"IfcBooleanResult",
"IfcBooleanClippingResult",
// composing objects
"IfcConnectedFaceSet"
};

foreach (var type in exportBrepByType)
{
ents.AddRange(s.Instances.OfType(type, false));
}
foreach (var ent in ents)
{
try
{
Xbim.Common.Geometry.IXbimGeometryObject created = null;
if (ent is IIfcGeometricRepresentationItem igri)
created = engine.Create(igri);
if (ent is IIfcConnectedFaceSet icfs)
created = engine.CreateShell(icfs);
// IIfcConnectedFaceSet
if (created != null)
{
var brep = engine.ToBrep(created);
var brepFileName = Path.Combine(path, $"{ent.EntityLabel}.{ent.GetType().Name}.brep");
using (var tw = File.CreateText(brepFileName))
{
tw.WriteLine("DBRep_DrawableShape");
tw.WriteLine(brep);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error writing brep {ent.EntityLabel}: {ex.Message}");
}
}
}
}

if (_params.Caching)
{
IfcStore s = ((IfcStore)model);
s.SaveAs(xbimFilename, Xbim.IO.StorageType.Xbim);
s.Close();
if (s != null)
{
s.SaveAs(xbimFilename, Xbim.IO.StorageType.Xbim);
s.Close();
}
}
}
}
Expand Down
Loading