Skip to content

Commit

Permalink
fix(Archicad): Timeout after 100s when sending large models #3 (#3052)
Browse files Browse the repository at this point in the history
timeout error

Co-authored-by: Alan Rynne <[email protected]>
  • Loading branch information
jozseflkiss and AlanRynne authored Nov 21, 2023
1 parent 068c786 commit 09e877b
Show file tree
Hide file tree
Showing 18 changed files with 350 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ static void GetModelInfoForElement (const Modeler::Elem& elem,
// edges
for (ULong edgeIdx = 0; edgeIdx < body.GetEdgeCount (); ++edgeIdx) {
const EDGE& edge = body.GetConstEdge (edgeIdx);
modelInfo.AddEdge (ModelInfo::EdgeId (edge.vert1 + vetrexOffset, edge.vert2 + vetrexOffset), ModelInfo::EdgeData (ModelInfo::VisibleEdge, edge.pgon1, edge.pgon2));
// send only edges which have no polygons (only 3D lines)
if (edge.pgon1 == Brep::MeshBrep::Edge::InvalidPgonIdx && edge.pgon2 == Brep::MeshBrep::Edge::InvalidPgonIdx)
modelInfo.AddEdge (ModelInfo::EdgeId (edge.vert1 + vetrexOffset, edge.vert2 + vetrexOffset), ModelInfo::EdgeData (ModelInfo::VisibleEdge, edge.pgon1, edge.pgon2));
}

// polygons
Expand Down
61 changes: 49 additions & 12 deletions ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,14 @@ public override async Task<StreamState> ReceiveStream(StreamState state, Progres
{
using (var timer = Archicad.Helpers.Timer.CreateReceive(state.StreamId))
{
Base commitObject = await Speckle.Core.Api.Helpers.Receive(IdentifyStream(state));
Base commitObject;

var context = Archicad.Helpers.Timer.Context.Peek;
using (context?.cumulativeTimer?.Begin(ConnectorArchicad.Properties.OperationNameTemplates.SendToServer))
{
commitObject = await Speckle.Core.Api.Helpers.Receive(IdentifyStream(state));
}

if (commitObject is not null)
await ElementConverterManager.Instance.ConvertToNative(state, commitObject, progress);

Expand Down Expand Up @@ -193,20 +200,50 @@ public override void PreviewSend(StreamState state, ProgressViewModel progress)

public override async Task<string> SendStream(StreamState state, ProgressViewModel progress)
{
if (state.Filter == null)
throw new InvalidOperationException("Expected selection filter to be non-null");
try
{
using (var timer = Archicad.Helpers.Timer.CreateSend(state.StreamId))
{
if (state.Filter == null)
{
throw new InvalidOperationException("Expected selection filter to be non-null");
}

var commitObject = await ElementConverterManager.Instance.ConvertToSpeckle(state.Filter, progress);
var commitObject = await ElementConverterManager.Instance.ConvertToSpeckle(state.Filter, progress);

if (commitObject == null)
throw new SpeckleException("Failed to convert objects to speckle: conversion returned null");
if (commitObject == null)
{
timer.Cancel();
throw new SpeckleException("Failed to convert objects to Speckle");
}

var context = Archicad.Helpers.Timer.Context.Peek;
using (context?.cumulativeTimer?.Begin(ConnectorArchicad.Properties.OperationNameTemplates.SendToServer))
{
return await Speckle.Core.Api.Helpers.Send(
IdentifyStream(state),
commitObject,
state.CommitMessage,
HostApplications.Archicad.Name
);
}
}
}
catch (Exception ex)
{
// log
if (ex is not OperationCanceledException)
SpeckleLog.Logger.Error("Conversion to Speckle failed.");

return await Speckle.Core.Api.Helpers.Send(
IdentifyStream(state),
commitObject,
state.CommitMessage,
HostApplications.Archicad.Name
);
// throw
switch (ex)
{
case OperationCanceledException:
throw new OperationCanceledException(ex.Message);
default:
throw new SpeckleException(ex.Message, ex);
}
}
}

public override void WriteStreamsToFile(List<StreamState> streams) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,26 @@ CancellationToken token
if (jArray is null)
return beams;

foreach (Speckle.Newtonsoft.Json.Linq.JToken jToken in jArray)
var context = Archicad.Helpers.Timer.Context.Peek;
using (context?.cumulativeTimer?.Begin(ConnectorArchicad.Properties.OperationNameTemplates.ConvertToSpeckle, Type.Name))
{
// convert between DTOs
Objects.BuiltElements.Archicad.ArchicadBeam beam =
Archicad.Converters.Utils.ConvertDTOs<Objects.BuiltElements.Archicad.ArchicadBeam>(jToken);

// downgrade (always): Objects.BuiltElements.Archicad.ArchicadBeam --> Objects.BuiltElements.Beam
foreach (Speckle.Newtonsoft.Json.Linq.JToken jToken in jArray)
{
beam.units = Units.Meters;
beam.displayValue = Operations.ModelConverter.MeshesToSpeckle(
elementModels.First(e => e.applicationId == beam.applicationId).model
);
beam.baseLine = new Line(beam.begC, beam.endC);
}
// convert between DTOs
Objects.BuiltElements.Archicad.ArchicadBeam beam =
Archicad.Converters.Utils.ConvertDTOs<Objects.BuiltElements.Archicad.ArchicadBeam>(jToken);

beams.Add(beam);
// downgrade (always): Objects.BuiltElements.Archicad.ArchicadBeam --> Objects.BuiltElements.Beam
{
beam.units = Units.Meters;
beam.displayValue = Operations.ModelConverter.MeshesToSpeckle(
elementModels.First(e => e.applicationId == beam.applicationId).model
);
beam.baseLine = new Line(beam.begC, beam.endC);
}

beams.Add(beam);
}
}

return beams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,22 @@ CancellationToken token
if (jArray is null)
return columns;

foreach (Speckle.Newtonsoft.Json.Linq.JToken jToken in jArray)
var context = Archicad.Helpers.Timer.Context.Peek;
using (context?.cumulativeTimer?.Begin(ConnectorArchicad.Properties.OperationNameTemplates.ConvertToSpeckle, Type.Name))
{
// convert between DTOs
Objects.BuiltElements.Archicad.ArchicadColumn column =
Archicad.Converters.Utils.ConvertDTOs<Objects.BuiltElements.Archicad.ArchicadColumn>(jToken);
foreach (Speckle.Newtonsoft.Json.Linq.JToken jToken in jArray)
{
// convert between DTOs
Objects.BuiltElements.Archicad.ArchicadColumn column =
Archicad.Converters.Utils.ConvertDTOs<Objects.BuiltElements.Archicad.ArchicadColumn>(jToken);

column.units = Units.Meters;
column.displayValue = Operations.ModelConverter.MeshesToSpeckle(
elementModels.First(e => e.applicationId == column.applicationId).model
);
column.baseLine = new Line(column.origoPos, column.origoPos + new Point(0, 0, column.height));
columns.Add(column);
column.units = Units.Meters;
column.displayValue = Operations.ModelConverter.MeshesToSpeckle(
elementModels.First(e => e.applicationId == column.applicationId).model
);
column.baseLine = new Line(column.origoPos, column.origoPos + new Point(0, 0, column.height));
columns.Add(column);
}
}

return columns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,17 @@ CancellationToken token
if (data is null)
return directShapes;

foreach (Objects.BuiltElements.Archicad.DirectShape directShape in data)
var context = Archicad.Helpers.Timer.Context.Peek;
using (context?.cumulativeTimer?.Begin(ConnectorArchicad.Properties.OperationNameTemplates.ConvertToSpeckle, Type.Name))
{
foreach (Objects.BuiltElements.Archicad.DirectShape directShape in data)
{
directShape.displayValue = Operations.ModelConverter.MeshesToSpeckle(
elementModels.First(e => e.applicationId == directShape.applicationId).model
);
directShapes.Add(directShape);
{
directShape.displayValue = Operations.ModelConverter.MeshesToSpeckle(
elementModels.First(e => e.applicationId == directShape.applicationId).model
);
directShapes.Add(directShape);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ CancellationToken token
if (data is null)
return openings;

foreach (Objects.BuiltElements.Archicad.ArchicadDoor subelement in data)
var context = Archicad.Helpers.Timer.Context.Peek;
using (context?.cumulativeTimer?.Begin(ConnectorArchicad.Properties.OperationNameTemplates.ConvertToSpeckle, Type.Name))
{
subelement.displayValue = Operations.ModelConverter.MeshesToSpeckle(
elementModels.First(e => e.applicationId == subelement.applicationId).model
);
openings.Add(subelement);
foreach (Objects.BuiltElements.Archicad.ArchicadDoor subelement in data)
{
subelement.displayValue = Operations.ModelConverter.MeshesToSpeckle(
elementModels.First(e => e.applicationId == subelement.applicationId).model
);
openings.Add(subelement);
}
}

return openings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,24 @@ CancellationToken token
if (jArray is null)
return floors;

foreach (Speckle.Newtonsoft.Json.Linq.JToken jToken in jArray)
var context = Archicad.Helpers.Timer.Context.Peek;
using (context?.cumulativeTimer?.Begin(ConnectorArchicad.Properties.OperationNameTemplates.ConvertToSpeckle, Type.Name))
{
// convert between DTOs
Objects.BuiltElements.Archicad.ArchicadFloor slab =
Archicad.Converters.Utils.ConvertDTOs<Objects.BuiltElements.Archicad.ArchicadFloor>(jToken);
foreach (Speckle.Newtonsoft.Json.Linq.JToken jToken in jArray)
{
// convert between DTOs
Objects.BuiltElements.Archicad.ArchicadFloor slab =
Archicad.Converters.Utils.ConvertDTOs<Objects.BuiltElements.Archicad.ArchicadFloor>(jToken);

slab.units = Units.Meters;
slab.displayValue = Operations.ModelConverter.MeshesToSpeckle(
elements.First(e => e.applicationId == slab.applicationId).model
);
slab.outline = Utils.PolycurveToSpeckle(slab.shape.contourPolyline);
if (slab.shape.holePolylines?.Count > 0)
slab.voids = new List<ICurve>(slab.shape.holePolylines.Select(Utils.PolycurveToSpeckle));
floors.Add(slab);
slab.units = Units.Meters;
slab.displayValue = Operations.ModelConverter.MeshesToSpeckle(
elements.First(e => e.applicationId == slab.applicationId).model
);
slab.outline = Utils.PolycurveToSpeckle(slab.shape.contourPolyline);
if (slab.shape.holePolylines?.Count > 0)
slab.voids = new List<ICurve>(slab.shape.holePolylines.Select(Utils.PolycurveToSpeckle));
floors.Add(slab);
}
}

return floors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,45 +89,49 @@ CancellationToken token
return new List<Base>();
}

List<Base> gridlines = new List<Base>();
foreach (Archicad.GridElement archicadGridElement in data)
var context = Archicad.Helpers.Timer.Context.Peek;
using (context?.cumulativeTimer?.Begin(ConnectorArchicad.Properties.OperationNameTemplates.ConvertToSpeckle, Type.Name))
{
Objects.BuiltElements.GridLine speckleGridLine = new Objects.BuiltElements.GridLine();
List<Base> gridlines = new List<Base>();
foreach (Archicad.GridElement archicadGridElement in data)
{
Objects.BuiltElements.GridLine speckleGridLine = new Objects.BuiltElements.GridLine();

// convert from Archicad to Speckle data structure
// Speckle base properties
speckleGridLine.id = archicadGridElement.id;
speckleGridLine.applicationId = archicadGridElement.applicationId;
speckleGridLine.label = archicadGridElement.markerText;
speckleGridLine.units = Units.Meters;
// convert from Archicad to Speckle data structure
// Speckle base properties
speckleGridLine.id = archicadGridElement.id;
speckleGridLine.applicationId = archicadGridElement.applicationId;
speckleGridLine.label = archicadGridElement.markerText;
speckleGridLine.units = Units.Meters;

// Archicad properties
// elementType and classifications do not exist in Objects.BuiltElements.GridLine
//speckleGrid.elementType = archicadGridElement.elementType;
//speckleGrid.classifications = archicadGridElement.classifications;
// Archicad properties
// elementType and classifications do not exist in Objects.BuiltElements.GridLine
//speckleGrid.elementType = archicadGridElement.elementType;
//speckleGrid.classifications = archicadGridElement.classifications;

if (!archicadGridElement.isArc)
{
speckleGridLine.baseLine = new Line(archicadGridElement.begin, archicadGridElement.end);
}
else
{
speckleGridLine.baseLine = new Arc(
archicadGridElement.begin,
archicadGridElement.end,
archicadGridElement.arcAngle
);
}
if (!archicadGridElement.isArc)
{
speckleGridLine.baseLine = new Line(archicadGridElement.begin, archicadGridElement.end);
}
else
{
speckleGridLine.baseLine = new Arc(
archicadGridElement.begin,
archicadGridElement.end,
archicadGridElement.arcAngle
);
}

speckleGridLine.displayValue = Operations.ModelConverter
.MeshesAndLinesToSpeckle(elementModels.First(e => e.applicationId == archicadGridElement.applicationId).model)
.Cast<Base>()
.ToList();
speckleGridLine.displayValue = Operations.ModelConverter
.MeshesAndLinesToSpeckle(elementModels.First(e => e.applicationId == archicadGridElement.applicationId).model)
.Cast<Base>()
.ToList();

gridlines.Add(speckleGridLine);
}
gridlines.Add(speckleGridLine);
}

return gridlines;
return gridlines;
}
}
}
}
Loading

0 comments on commit 09e877b

Please sign in to comment.