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

reread the extents from the database when getIModelProps is called after a pullChanges #866

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion iModelCore/iModelPlatform/DgnCore/DgnDbSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ DbResult DgnDb::InitializeDgnDb(CreateDgnDbParams const& params) {
if (extents.IsNull())
extents = m_geoLocation.GetDefaultProjectExtents();

m_geoLocation.SetProjectExtents(extents);
m_geoLocation.SetProjectExtents(extents, false);
m_geoLocation.SetGlobalOrigin(params.m_globalOrigin);
m_geoLocation.Save();

Expand Down
13 changes: 8 additions & 5 deletions iModelCore/iModelPlatform/DgnCore/DgnUnits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ void DgnGeoLocation::Save()
/*---------------------------------------------------------------------------------**//**
* @bsimethod
+---------------+---------------+---------------+---------------+---------------+------*/
void DgnGeoLocation::SetProjectExtents(AxisAlignedBox3dCR newExtents)
void DgnGeoLocation::SetProjectExtents(AxisAlignedBox3dCR newExtents, bool fromChangesetAppliedEvent)
{
DgnDb::VerifyClientThread();

Expand All @@ -476,9 +476,12 @@ void DgnGeoLocation::SetProjectExtents(AxisAlignedBox3dCR newExtents)
// JsonCpp and RapidJson differ slightly in precision of floating point numbers.
// Tile content Ids include a hash of the project extents.
// Differing precision => different content Ids => invalidate every cached tile in existence.
Json::Value jsonObj;
BeJsGeomUtils::DRange3dToJson(jsonObj, m_extent);
m_dgndb.SavePropertyString(DgnProjectProperty::Extents(), jsonObj.ToString());
if (!fromChangesetAppliedEvent)
bbastings marked this conversation as resolved.
Show resolved Hide resolved
{
Json::Value jsonObj;
BeJsGeomUtils::DRange3dToJson(jsonObj, m_extent);
m_dgndb.SavePropertyString(DgnProjectProperty::Extents(), jsonObj.ToString());
}

if (!m_ecefLocation.m_isValid)
{
Expand All @@ -499,7 +502,7 @@ void DgnGeoLocation::SetProjectExtents(AxisAlignedBox3dCR newExtents)
+---------------+---------------+---------------+---------------+---------------+------*/
void DgnGeoLocation::InitializeProjectExtents(DRange3dP rangeWithOutliers, bvector<BeInt64Id>* elementOutliers)
{
SetProjectExtents(ComputeProjectExtents(rangeWithOutliers, elementOutliers));
SetProjectExtents(ComputeProjectExtents(rangeWithOutliers, elementOutliers), false);

// We need an immutable origin for Cesium tile publishing that will not
// change when project extents change. Set it here only.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ struct DgnGeoLocation : NonCopyableClass
void SetProjectExtentsSource(ProjectExtentsSource source) const {m_extentSource = source;}

//! Update the project extents for this BIM
DGNPLATFORM_EXPORT void SetProjectExtents(AxisAlignedBox3dCR newExtents);
DGNPLATFORM_EXPORT void SetProjectExtents(AxisAlignedBox3dCR newExtents, bool fromChangesetAppliedEvent);

//! Reset the in-memory project extents to a null range. Strictly for tests.
void ResetProjectExtents() {
Expand Down
3 changes: 2 additions & 1 deletion iModelJsNodeAddon/IModelJsNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2341,7 +2341,8 @@ struct NativeDgnDb : BeObjectWrap<NativeDgnDb>, SQLiteOps<DgnDb>
void UpdateProjectExtents(NapiInfoCR info)
{
REQUIRE_ARGUMENT_STRING(0, newExtentsJson)
JsInterop::UpdateProjectExtents(GetOpenedDb(info), BeJsDocument(newExtentsJson));
REQUIRE_ARGUMENT_BOOL(1, fromChangesetAppliedEvent);
JsInterop::UpdateProjectExtents(GetOpenedDb(info), BeJsDocument(newExtentsJson), fromChangesetAppliedEvent);
}

Napi::Value GetCodeValueBehavior(NapiInfoCR info) {
Expand Down
2 changes: 1 addition & 1 deletion iModelJsNodeAddon/IModelJsNative.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ struct JsInterop {
static DgnDbStatus GetModel(Napi::Object results, DgnDbR db, BeJsConst inOpts);
static void QueryModelExtents(BeJsValue extents, DgnDbR db, BeJsConst options);
static DgnDbStatus QueryDefinitionElementUsage(BeJsValue usageInfo, DgnDbR db, bvector<Utf8String> const& idStringArray);
static void UpdateProjectExtents(DgnDbR dgndb, BeJsConst newExtents);
static void UpdateProjectExtents(DgnDbR dgndb, BeJsConst newExtents, bool fromChangesetAppliedEvent);
static void UpdateIModelProps(DgnDbR dgndb, BeJsConst);
static Napi::Value GetInstance(ECDbR db, NapiInfoCR info);

Expand Down
15 changes: 12 additions & 3 deletions iModelJsNodeAddon/JsInteropDgnDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,20 @@ DgnDbStatus JsInterop::SimplifyElementGeometry(DgnDbR db, Napi::Object simplifyA
/*---------------------------------------------------------------------------------**//**
* @bsimethod
+---------------+---------------+---------------+---------------+---------------+------*/
void JsInterop::UpdateProjectExtents(DgnDbR dgndb, BeJsConst newExtents) {
void JsInterop::UpdateProjectExtents(DgnDbR dgndb, BeJsConst newExtents, bool fromChangesetAppliedEvent) {
auto& geolocation = dgndb.GeoLocation();
AxisAlignedBox3d extents;
extents.FromJson(newExtents);
geolocation.SetProjectExtents(extents);
// Check if our extents have actually changed. If not, return early.
if (geolocation.GetProjectExtents().IsEqual(extents, 0.01))
return;
if (fromChangesetAppliedEvent) {
// set isValid to false so that we recalculate the ecefLocation in SetProjectExtents with these new extents.
auto ecefLocation = geolocation.GetEcefLocation();
ecefLocation.m_isValid = false;
bbastings marked this conversation as resolved.
Show resolved Hide resolved
}

geolocation.SetProjectExtents(extents, fromChangesetAppliedEvent);
geolocation.Save();
}

Expand All @@ -526,7 +535,7 @@ void JsInterop::UpdateIModelProps(DgnDbR dgndb, BeJsConst props) {
if (!extJson.isNull()) {
AxisAlignedBox3d extents;
extents.FromJson(props[json_projectExtents()]);
geolocation.SetProjectExtents(extents);
geolocation.SetProjectExtents(extents, false);
}
auto orgJson = props[json_globalOrigin()];
if (!orgJson.isNull())
Expand Down
3 changes: 2 additions & 1 deletion iModelJsNodeAddon/api_package/ts/src/NativeLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,8 @@ export declare namespace IModelJsNative {
public updateLinkTableRelationship(props: RelationshipProps): DbResult;
public updateModel(modelProps: ModelProps): void;
public updateModelGeometryGuid(modelId: Id64String): IModelStatus;
public updateProjectExtents(newExtentsJson: string): void;
// fromChangesetAppliedEvent lets updateProjectExtents know that the extents are already stored in the iModel and do not need to be written to the database again.
public updateProjectExtents(newExtentsJson: string, fromChangesetAppliedEvent: boolean): void;
public writeAffectedElementDependencyGraphToFile(dotFileName: string, changedElems: Id64Array): BentleyStatus;
public writeFullElementDependencyGraphToFile(dotFileName: string): BentleyStatus;
public vacuum(arg?: { pageSize?: number, into?: LocalFileName }): void;
Expand Down