93246157c7
* Fix threading bug * untangle revit * revert rhino * revert autocad * revert rest * remove event agg and rhino implementation * remove event aggr from revit * remove event aggr from autocad and civil * remove event aggr tests * remove event aggr from tekla * Remove event aggr for navis * remove event aggr from csi etabs * remove event aggr for arcgis * remove remaining pieces * push autocad to run operations on main thread * adds teklaidlemanager * bring navis idle manager back * run send on main * remove unused function --------- Co-authored-by: Dogukan Karatas <karatasdogukan@gmail.com>
89 lines
2.7 KiB
C#
89 lines
2.7 KiB
C#
using Speckle.Connectors.DUI.Bridge;
|
|
using Speckle.Connectors.DUI.Models;
|
|
using Speckle.Connectors.DUI.Utils;
|
|
|
|
namespace Speckle.Connectors.Autocad.HostApp;
|
|
|
|
public class AutocadDocumentStore : DocumentModelStore
|
|
{
|
|
private const string NULL_DOCUMENT_NAME = "Null Doc";
|
|
private string _previousDocName;
|
|
private readonly AutocadDocumentManager _autocadDocumentManager;
|
|
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;
|
|
|
|
public AutocadDocumentStore(
|
|
IJsonSerializer jsonSerializer,
|
|
AutocadDocumentManager autocadDocumentManager,
|
|
ITopLevelExceptionHandler topLevelExceptionHandler
|
|
)
|
|
: base(jsonSerializer)
|
|
{
|
|
_autocadDocumentManager = autocadDocumentManager;
|
|
_topLevelExceptionHandler = topLevelExceptionHandler;
|
|
_previousDocName = NULL_DOCUMENT_NAME;
|
|
|
|
// POC: Will be addressed to move it into AutocadContext!
|
|
if (Application.DocumentManager.MdiActiveDocument != null)
|
|
{
|
|
IsDocumentInit = true;
|
|
// POC: this logic might go when we have document management in context
|
|
// It is with the case of if binding created with already a document
|
|
// This is valid when user opens acad file directly double clicking
|
|
OnDocChangeInternal(Application.DocumentManager.MdiActiveDocument);
|
|
}
|
|
|
|
Application.DocumentManager.DocumentActivated += (_, e) =>
|
|
topLevelExceptionHandler.CatchUnhandled(() => OnDocChangeInternal(e.Document));
|
|
|
|
// since below event triggered as secondary, it breaks the logic in OnDocChangeInternal function, leaving it here for now.
|
|
// Autodesk.AutoCAD.ApplicationServices.Application.DocumentWindowCollection.DocumentWindowActivated += (_, args) =>
|
|
// OnDocChangeInternal((Document)args.DocumentWindow.Document);
|
|
}
|
|
|
|
private void OnDocChangeInternal(Document? doc)
|
|
{
|
|
var currentDocName = doc != null ? doc.Name : NULL_DOCUMENT_NAME;
|
|
if (_previousDocName == currentDocName)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_previousDocName = currentDocName;
|
|
LoadState();
|
|
OnDocumentChanged();
|
|
}
|
|
|
|
protected override void LoadState()
|
|
{
|
|
// POC: Will be addressed to move it into AutocadContext!
|
|
Document? doc = Application.DocumentManager.MdiActiveDocument;
|
|
|
|
if (doc == null)
|
|
{
|
|
ClearAndSave();
|
|
return;
|
|
}
|
|
|
|
string? serializedModelCards = _autocadDocumentManager.ReadModelCards(doc);
|
|
if (serializedModelCards == null)
|
|
{
|
|
ClearAndSave();
|
|
return;
|
|
}
|
|
LoadFromString(serializedModelCards);
|
|
}
|
|
|
|
protected override void HostAppSaveState(string modelCardState)
|
|
{
|
|
// POC: Will be addressed to move it into AutocadContext!
|
|
Document doc = Application.DocumentManager.MdiActiveDocument;
|
|
|
|
if (doc == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_autocadDocumentManager.WriteModelCards(doc, modelCardState);
|
|
}
|
|
}
|