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

Allow App to specify GCS asset Dir #748

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
44ec5a9
add logging GCS
DanRod1999 May 3, 2024
0f15e86
undo comment
DanRod1999 May 3, 2024
1765575
remove unneeded var, fix typo
DanRod1999 May 3, 2024
1a2eb8c
Merge branch 'main' into dan/gcs-logging
DanRod1999 May 3, 2024
e5b1194
modify log for in workspace
DanRod1999 May 3, 2024
0ba5ddd
allow alternate gcs path through env var
DanRod1999 May 3, 2024
6b85c46
Merge branch 'main' into dan/gcs-logging
DanRod1999 May 7, 2024
34ba52d
Merge branch 'main' into dan/gcs-logging
DanRod1999 May 8, 2024
c3e3fa5
fix error
DanRod1999 May 8, 2024
65fc8bc
Merge branch 'dan/gcs-logging' of https://github.com/iTwin/imodel-nat…
DanRod1999 May 8, 2024
0fdc566
Merge branch 'main' into dan/gcs-logging
DanRod1999 May 13, 2024
2c48e11
Merge branch 'main' into dan/gcs-logging
DanRod1999 May 23, 2024
6621d9b
Merge branch 'main' into dan/gcs-logging
DanRod1999 May 28, 2024
54af621
add setGeoCoordAssetDir
DanRod1999 May 31, 2024
2fee4af
create setGeoCoordAssetDir
DanRod1999 Jun 4, 2024
f8febd8
Merge branch 'main' into dan/setGeoCoordDir
DanRod1999 Jun 4, 2024
9366fe4
fix failing tests
DanRod1999 Jun 6, 2024
3c65a45
add terminate
DanRod1999 Jun 11, 2024
7d835f5
Revert "add setGeoCoordAssetDir"
DanRod1999 Jun 11, 2024
8f2c213
Merge branch 'dan/setGeoCoordDir' into dan/gcs-logging
DanRod1999 Jun 11, 2024
8a6c348
remove get env
DanRod1999 Jun 11, 2024
b6332c6
Merge branch 'main' into dan/gcs-logging
DanRod1999 Jun 11, 2024
b55ca79
shutdown GCS on terminate
DanRod1999 Jun 11, 2024
347760b
add file path
DanRod1999 Jun 11, 2024
73fcf21
clean up comments
DanRod1999 Jun 11, 2024
33e2022
add comments
DanRod1999 Jun 12, 2024
caa09d2
Merge branch 'main' into dan/gcs-logging
DanRod1999 Jun 12, 2024
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
16 changes: 12 additions & 4 deletions iModelCore/GeoCoord/BaseGeoCoord/basegeocoord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8921,6 +8921,9 @@ struct WorkspaceResource : _csFile {
virtual int printf(Utf8CP format...) override { return readonly(); }
};

static bool s_loadLocalFiles = true;
void BaseGCS::EnableLocalGcsFiles(bool yesNo) { s_loadLocalFiles = yesNo; }

//=======================================================================================
// static methods for finding resources in the list of GCS resource files.
// @bsiclass
Expand All @@ -8946,7 +8949,10 @@ struct GeoCoordWorkspaces {
Logging::LogMessageV("GeoCoord", LOG_ERROR, "Unable to read data for GCS file %s from workspace %s, rc=%d", path, row.db->GetDbFileName(), rc);
nick4598 marked this conversation as resolved.
Show resolved Hide resolved
delete resource; // weren't able to read from row.
}
Logging::LogMessageV("GeoCoord", LOG_WARNING, "Unable to find GCS file %s in any workspace", path);
if (s_loadLocalFiles)
Logging::LogMessageV("GeoCoord", LOG_INFO, "Unable to find GCS file %s in any workspace, trying local file", path);
else
Logging::LogMessageV("GeoCoord", LOG_WARNING, "Unable to find GCS file %s in any workspace", path);
return nullptr;
}

Expand Down Expand Up @@ -8980,9 +8986,6 @@ struct GeoCoordWorkspaces {
}
};

static bool s_loadLocalFiles = true;
void BaseGCS::EnableLocalGcsFiles(bool yesNo) { s_loadLocalFiles = yesNo; }

/** Add a new entry to the list of gcs WorkspaceDbs */
bool BaseGCS::AddWorkspaceDb(Utf8String dbName, CloudContainerP container, int priority) {
WorkspaceDbPtr newDb = new WorkspaceDb(priority, dbName, container);
Expand Down Expand Up @@ -27323,6 +27326,11 @@ _csFile* CS_fopen(Utf8CP filename, Utf8CP mode) {

auto name = BentleyApi::GeoCoordinates::toAssetName(filename);
auto file = CS_fopen_caseInsensitive(name.c_str(), mode);
if (file != nullptr)
Logging::LogMessageV("GeoCoord", LOG_INFO, "Successfully loaded GCS file %s from %s", filename, name.c_str());
else
Logging::LogMessageV("GeoCoord", LOG_WARNING, "Unable to find GCS file %s in Workspace or %s", filename, name.c_str());

return nullptr == file ? nullptr : new AssetDirFile(file);
}

Expand Down
31 changes: 26 additions & 5 deletions iModelCore/iModelPlatform/DgnCore/DgnCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <DgnPlatform/DgnGeoCoord.h>
#include <DgnPlatform/DgnECSymbolProvider.h>
#include <DgnPlatform/Visualization.h>
#include <DgnPlatform/PlatformLib.h>

BeThreadLocalStorage t_threadId;

Expand Down Expand Up @@ -220,7 +221,8 @@ void PlatformLib::Terminate(bool onProgramExit) {
+---------------+---------------+---------------+---------------+---------------+------*/
void PlatformLib::Host::Terminate(bool onProgramExit) {

ON_HOST_TERMINATE(m_geoCoordAdmin, onProgramExit);
if( m_geoCoordAdmin != nullptr )
ON_HOST_TERMINATE(m_geoCoordAdmin, onProgramExit);
ON_HOST_TERMINATE(m_bRepGeometryAdmin, onProgramExit);

// UnRegister Symbol Provider for ECExpressions
Expand All @@ -234,6 +236,13 @@ void PlatformLib::Host::Terminate(bool onProgramExit) {
void _wassert(wchar_t const*, wchar_t const*, int) {BeAssert(false);}
#endif

/*---------------------------------------------------------------------------------**//**
* @bsimethod
+---------------+---------------+---------------+---------------+---------------+------*/
void PlatformLib::Host::TerminateGeoCoordAdmin(bool onProgramExit) {
ON_HOST_TERMINATE(m_geoCoordAdmin, onProgramExit);
}

/*---------------------------------------------------------------------------------**//**
* *Private* method called by Dgn::Host::Initialize.
* @bsimethod
Expand All @@ -242,7 +251,6 @@ void PlatformLib::Host::Initialize()
{
BeAssert(NULL == m_knownLocationsAdmin); m_knownLocationsAdmin = &_SupplyIKnownLocationsAdmin();
BeAssert(NULL == m_exceptionHandler); m_exceptionHandler = &_SupplyExceptionHandler();
BeAssert(NULL == m_geoCoordAdmin); m_geoCoordAdmin = &_SupplyGeoCoordinationAdmin();

auto assetDir = m_knownLocationsAdmin->GetDgnPlatformAssetsDirectory();

Expand All @@ -251,7 +259,6 @@ void PlatformLib::Host::Initialize()
&assetDir,
BeSQLiteLib::LogErrors::Yes);

GeoCoordinates::BaseGCS::Initialize(GetGeoCoordinationAdmin()._GetDataDirectory().GetNameUtf8().c_str());

DgnDomains::RegisterDomain(BisCoreDomain::GetDomain(), DgnDomain::Required::Yes, DgnDomain::Readonly::No);
DgnDomains::RegisterDomain(GenericDomain::GetDomain(), DgnDomain::Required::Yes, DgnDomain::Readonly::No);
Expand All @@ -272,6 +279,15 @@ void PlatformLib::Host::Initialize()
m_bRepGeometryAdmin->_Initialize(assetDir, tempDirBase);
}

/*---------------------------------------------------------------------------------**//**
* @bsimethod
+---------------+---------------+---------------+---------------+---------------+------*/
void PlatformLib::Host::GeoCoordInitialize(BeFileName geoCoordAssetPath)
{
BeAssert(NULL == m_geoCoordAdmin); m_geoCoordAdmin = &_SupplyGeoCoordinationAdmin(geoCoordAssetPath);
GeoCoordinates::BaseGCS::Initialize(GetGeoCoordinationAdmin()._GetDataDirectory().GetNameUtf8().c_str());
}

/*---------------------------------------------------------------------------------**//**
* @bsimethod
+---------------+---------------+---------------+---------------+---------------+------*/
Expand Down Expand Up @@ -437,9 +453,14 @@ PlatformLib::Host::BRepGeometryAdmin& PlatformLib::Host::_SupplyBRepGeometryAdmi
//---------------------------------------------------------------------------------------
// @bsimethod
//---------------------------------------------------------------------------------------
PlatformLib::Host::GeoCoordinationAdmin& PlatformLib::Host::_SupplyGeoCoordinationAdmin()
PlatformLib::Host::GeoCoordinationAdmin& PlatformLib::Host::_SupplyGeoCoordinationAdmin(BeFileName geoCoordAssetPath)
{
BeFileName geo = GetIKnownLocationsAdmin().GetGeoCoordinateDataDirectory();
BeFileName geo;
if (geoCoordAssetPath.empty())
geo = GetIKnownLocationsAdmin().GetGeoCoordinateDataDirectory();
else
geo = geoCoordAssetPath;


BeFileName path(geo);
path.AppendToPath(L"DgnGeoCoord");
Expand Down
5 changes: 5 additions & 0 deletions iModelCore/iModelPlatform/DgnGeoCoord/DgnGeoCoord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5340,7 +5340,12 @@ DgnGCSP DgnGCS::FromProject(DgnDbR project)
ScopedArray<Byte> buffer(propSize);
project.QueryProperty(buffer.GetData(), propSize, DgnProjectProperty::DgnGCS());

StopWatch timer;
timer.Start();
auto gcs = FromGeoCoordType66AppData((short const*)buffer.GetData(), project);
timer.Stop();
Logging::LogMessageV("GeoCoord", LOG_INFO, "Time to load gcs: %fs", timer.GetElapsedSeconds());

if (NULL == gcs)
{
project.AddAppData(NotFoundAppData::GetKey(), new NotFoundAppData());
Expand Down
1 change: 1 addition & 0 deletions iModelCore/iModelPlatform/DgnHandlers/ScopedDgnHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ ScopedDgnHostImpl::ScopedDgnHostImpl(ScopedDgnHostConfig* config) : m_config(con

PlatformLib::Initialize(*this);
m_isInitialized = true;
T_HOST.GeoCoordInitialize(BeFileName(""));
}

/*---------------------------------------------------------------------------------**//**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class PlatformLib {
friend class PlatformLib;

public:

//! Provides Exception handling capabilities
struct ExceptionHandler : IHostObject {
//! Possible outcomes of handling an exception
Expand Down Expand Up @@ -248,7 +249,13 @@ class PlatformLib {
DGNPLATFORM_EXPORT virtual VisualizationAdmin& _SupplyVisualizationAdmin();

//! Supply the GeoCoordinationStateAdmin for this session. This method is guaranteed to be called once per thread from PlatformLib::Host::Initialize and never again..
DGNPLATFORM_EXPORT virtual GeoCoordinationAdmin& _SupplyGeoCoordinationAdmin();
DGNPLATFORM_EXPORT virtual GeoCoordinationAdmin& _SupplyGeoCoordinationAdmin(BeFileName geoCoorAssetPath);

//! Initialize the GeoCoordinationAdmin on IModel Host Startup
DGNPLATFORM_EXPORT void GeoCoordInitialize(BeFileName geoCoordAssetPath);

//! Terminate the GeoCoordinationAdmin on IModel Host Shutdown
DGNPLATFORM_EXPORT void TerminateGeoCoordAdmin(bool onProgramExit);

//! Supply the BRepGeometryAdmin for this session. This method is guaranteed to be called once per thread from PlatformLib::Host::Initialize and never again.
DGNPLATFORM_EXPORT virtual BRepGeometryAdmin& _SupplyBRepGeometryAdmin();
Expand Down
14 changes: 14 additions & 0 deletions iModelJsNodeAddon/IModelJsNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2319,6 +2319,18 @@ struct NativeDgnDb : BeObjectWrap<NativeDgnDb>, SQLiteOps<DgnDb>
return Napi::String::New(info.Env(), asset.GetNameUtf8().c_str());
}

static void SetGeoCoordAssetDir(NapiInfoCR info)
{
BeFileName assetDir = BeFileName(info[0].ToString().Utf8Value().c_str());
T_HOST.GeoCoordInitialize(assetDir);
}

static void TerminateGeoCoordAssetDir(NapiInfoCR info)
{
T_HOST.TerminateGeoCoordAdmin(true);
GeoCoordinates::BaseGCS::Shutdown();
}

static Napi::Value EnableSharedCache(NapiInfoCR info)
{
REQUIRE_ARGUMENT_BOOL(0, enabled);
Expand Down Expand Up @@ -2812,6 +2824,8 @@ struct NativeDgnDb : BeObjectWrap<NativeDgnDb>, SQLiteOps<DgnDb>
InstanceMethod("setNoCaseCollation", &NativeDgnDb::SetNoCaseCollation),
StaticMethod("enableSharedCache", &NativeDgnDb::EnableSharedCache),
StaticMethod("getAssetsDir", &NativeDgnDb::GetAssetDir),
StaticMethod("setGeoCoordAssetsDir", &NativeDgnDb::SetGeoCoordAssetDir),
StaticMethod("terminateGeoCoordAssetsDir", &NativeDgnDb::TerminateGeoCoordAssetDir),
StaticMethod("zlibCompress", &NativeDgnDb::ZlibCompress),
StaticMethod("zlibDecompress", &NativeDgnDb::ZlibDecompress),
});
Expand Down
2 changes: 2 additions & 0 deletions iModelJsNodeAddon/api_package/ts/src/NativeLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,8 @@ export declare namespace IModelJsNative {
public setAutoCheckpointThreshold(frames: number): void;
public static enableSharedCache(enable: boolean): DbResult;
public static getAssetsDir(): string;
public static setGeoCoordAssetsDir(dir: string): void;
public static terminateGeoCoordAssetsDir(): void;
public static zlibCompress(data: Uint8Array): Uint8Array;
public static zlibDecompress(data: Uint8Array, actualSize: number): Uint8Array;
}
Expand Down
6 changes: 4 additions & 2 deletions iModelJsNodeAddon/api_package/ts/src/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function loadInstalledAddon(): typeof IModelJsNative {
return NativeLibrary.load();
}

export function loadLocalBuildOfAddon(): any {
export function loadLocalBuildOfAddon(): typeof IModelJsNative {
if (process.env.OutRoot === undefined) {
throw new Error("You must define 'OutRoot' in your environment");
}
Expand Down Expand Up @@ -71,7 +71,9 @@ export function logTest(msg: string) {

let _addon: undefined | typeof IModelJsNative;
function loadAddon() {
return _addon ??= useLocalBuild ? loadLocalBuildOfAddon() : loadInstalledAddon();
_addon ??= useLocalBuild ? loadLocalBuildOfAddon() : loadInstalledAddon();
_addon.DgnDb.setGeoCoordAssetsDir("");
return _addon;
}

export const iModelJsNative: typeof IModelJsNative = loadAddon();
Expand Down
Loading