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

Now Grasshopper con compute solutions when expired on background. #1206

Merged
merged 2 commits into from
Nov 12, 2024
Merged
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
97 changes: 60 additions & 37 deletions src/RhinoInside.Revit/GH/Guest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -954,57 +954,80 @@ internal async void ObjectsDeleted(object sender, (GH_Document Document, IReadOn

void ActiveDefinition_SolutionStart(object sender, GH_SolutionEventArgs e)
{
// Expire objects that contain elements modified by Grasshopper.
while (DocumentChangedEvent.changeQueue.Count > 0)
if (e.Document is GH_Document document)
{
var change = DocumentChangedEvent.changeQueue.Dequeue();
// Expire objects that contain elements modified by Grasshopper.
while (DocumentChangedEvent.changeQueue.Count > 0)
{
var change = DocumentChangedEvent.changeQueue.Dequeue();

foreach (var obj in change.ExpiredObjects)
obj.ExpireSolution(false);
}
foreach (var obj in change.ExpiredObjects)
obj.ExpireSolution(false);
}

GeometryCache.StartKeepAliveRegion();
ActiveDocumentStack.Push(e.Document);
if (document.Enabled) StartTransactionGroups();
else if (Instances.ActiveCanvas?.Document == document)
{
if (PendingSolution is object) PendingSolution = document;
else
{
PendingSolution = document;
Revit.EnqueueIdlingAction(() =>
{
if (PendingSolution?.Enabled is true)
PendingSolution.NewSolution(expireAllObjects: false);

GeometryCache.StartKeepAliveRegion();
ActiveDocumentStack.Push(e.Document);
StartTransactionGroups();
PendingSolution = null;
});
}
}
}
}

private static GH_Document PendingSolution;

void ActiveDefinition_SolutionEnd(object sender, GH_SolutionEventArgs e)
{
if (ActiveDocumentStack.Peek() != e.Document)
throw new InvalidOperationException();
if (e.Document is GH_Document document)
{
if (ActiveDocumentStack.Peek() != e.Document)
throw new InvalidOperationException();

CommitTransactionGroups();
ActiveDocumentStack.Pop();
GeometryCache.EndKeepAliveRegion();
if (document.Enabled) CommitTransactionGroups();
ActiveDocumentStack.Pop();
GeometryCache.EndKeepAliveRegion();

// Warn the user about objects that contain elements modified by Grasshopper.
{
var expiredObjectsCount = 0;
foreach (var change in DocumentChangedEvent.changeQueue)
// Warn the user about objects that contain elements modified by Grasshopper.
{
if (e.Document == change.Definition)
expiredObjectsCount += change.ExpiredObjects.Count;
var expiredObjectsCount = 0;
foreach (var change in DocumentChangedEvent.changeQueue)
{
if (e.Document == change.Definition)
expiredObjectsCount += change.ExpiredObjects.Count;

foreach (var obj in change.ExpiredObjects)
obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "This object will be expired because it contains obsolete Revit elements.");
}
if (expiredObjectsCount > 0)
{
Instances.DocumentEditor.SetStatusBarEvent
(
new GH_RuntimeMessage
foreach (var obj in change.ExpiredObjects)
obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "This object will be expired because it contains obsolete Revit elements.");
}
if (expiredObjectsCount > 0)
{
Instances.DocumentEditor.SetStatusBarEvent
(
expiredObjectsCount == 1 ?
$"An object will be expired because contains obsolete Revit elements." :
$"{expiredObjectsCount} objects will be expired because contain obsolete Revit elements.",
GH_RuntimeMessageLevel.Remark,
"Rhino.Inside"
)
);
new GH_RuntimeMessage
(
expiredObjectsCount == 1 ?
$"An object will be expired because contains obsolete Revit elements." :
$"{expiredObjectsCount} objects will be expired because contain obsolete Revit elements.",
GH_RuntimeMessageLevel.Remark,
"Rhino.Inside"
)
);
}
}
}

ModelUnitScale = UnitScale.GetModelScale(RhinoDoc.ActiveDoc);
ModelUnitScale = UnitScale.GetModelScale(RhinoDoc.ActiveDoc);
}
}
#endregion
}
Expand Down
Loading