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

add isolate elements feature to transformer test app #3601

Merged
merged 14 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions test-apps/imodel-transformer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ A common strategy is to run with verbose logging on to find the problem element
Once the problem area has been identified, you can employ various strategies to set a conditional breakpoint.
One possibility is to edit the `onTransformElement` method in `Transformer.ts` to add a `if (sourceElement.getDisplayLabel() === "x")` or `if (sourceElement.id === "x")` conditional (using information from the log output) around a "hit problem area" log function call and then set a breakpoint on that log message.
After rebuilding, re-running, and hitting the breakpoint, you can then step into the core IModelTransformer methods to see what is really going on.

### isolating bad elements

You can pass a comma-separated list of element ids to the (`--isolateElements id1,id2`) argument to transform to the specified target
a filtered iModel containing only the path to and child subtrees of the given elements/models specified by the given ids. This can be
useful to create smaller reproduction iModels with less data that still contain problematic elements.
17 changes: 17 additions & 0 deletions test-apps/imodel-transformer/src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ void (async () => {
type: "boolean",
default: false,
},
isolateElements: {
desc: "transform filtering all unnecessary element/model trees except for those listed in a comma-separated argument of ids",
type: "string",
},
loadSourceGeometry: {
desc: "load geometry from the source as JSON while transforming, for easier (but not performant) transforming of geometry",
type: "boolean",
default: false,
},
cloneUsingJsonGeometry: {
desc: "sets cloneUsingBinaryGeometry in the transformer options to true, which is slower but allows simple editing of geometry in javascript.",
type: "boolean",
default: false,
},
})
.parse();

Expand Down Expand Up @@ -327,13 +341,16 @@ void (async () => {

const transformerOptions: TransformerOptions = {
...args,
cloneUsingBinaryGeometry: !args.cloneUsingJsonGeometry,
excludeSubCategories: args.excludeSubCategories?.split(","),
excludeCategories: args.excludeCategories?.split(","),
};

if (processChanges) {
assert(undefined !== args.sourceStartChangesetId);
await Transformer.transformChanges(await acquireAccessToken(), sourceDb, targetDb, args.sourceStartChangesetId, transformerOptions);
} else if (args.isolateElements !== undefined) {
await Transformer.transformIsolated(sourceDb, targetDb, args.isolateElements.split(","), transformerOptions);
} else {
await Transformer.transformAll(sourceDb, targetDb, transformerOptions);
}
Expand Down
23 changes: 23 additions & 0 deletions test-apps/imodel-transformer/src/Transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ export class Transformer extends IModelTransformer {
transformer.logElapsedTime();
}

/** attempt to isolate a set of elements by transforming only them from the source to the target */
public static async transformIsolated(
sourceDb: IModelDb,
targetDb: IModelDb,
isolatedElementIds: Id64Array,
options?: TransformerOptions
): Promise<void> {
// might need to inject RequestContext for schemaExport.
const transformer = new Transformer(sourceDb, targetDb, options);
transformer.initialize(options);
await transformer.processSchemas();
await transformer.saveChanges("processSchemas");
for (const id of isolatedElementIds)
await transformer.processElement(id);
await transformer.saveChanges("process isolated elements");
if (options?.deleteUnusedGeometryParts) {
transformer.deleteUnusedGeometryParts();
await transformer.saveChanges("deleteUnusedGeometryParts");
}
transformer.dispose();
transformer.logElapsedTime();
}

private constructor(sourceDb: IModelDb, targetDb: IModelDb, options?: TransformerOptions) {
super(sourceDb, new IModelImporter(targetDb, { simplifyElementGeometry: options?.simplifyElementGeometry }), options);
}
Expand Down