Replies: 5 comments 8 replies
-
@SheetalNair There is a standard one that is enabled by default through QuantityFormatter acts as a helper API for formatting quantities, you can still create formatterSpecs and do formatting/parsing without it (it'll take a few extra lines of code). We don't have a similar class for backend because previously it was thought that the concept of formatting quantities and parsing them are a frontend/visualization concept. The effort it takes to implement a UnitsProvider in the backend was reduced a lot in the upcoming iTwin 5.0 - As for question 1, and I'll also answer on your code snippet: Yes, that's the right way to do it, to supply a FormatProps from core-quantity and not a formatString. SchemaItemFormatProps in ecschema-metadata is an extension of FormatProps in core-quantity, and SchemaItemOverrideFormatProps is an extension of SchemaItemFormatProps, so these APIs are compatible between each other. Anyways, to the root of question 1: How to create a FormatterSpec from an OverrideFormat (or formatString). It's clear that we did not expose an easy way to go from a formatString to a SchemaItemFormatProps (or SchemaItemOverrideFormatProps). The implementation is... long, and it's private - format overrides normally exist within KindOfQuantities so the logic for parsing them exist only in there, as a helper method. We can open a GH issue requesting enhancements to the OverrideFormat API to help deserializing OverrideFormats outside of a KoQ. While OverrideFormat has a ... // copy KindOfQuantity.ts 113-139
const overrideFormat = new OverrideFormat(format, precision, unitAndLabels) // unitAndLabels has it's first tuple value transformed from string to LazyLoadedUnit
const formatProps = overrideFormat.getJsonProps() |
Beta Was this translation helpful? Give feedback.
-
@ColinKerr @hl662 The above image shows a linear and an angular dimension, where the measurements 2250.479 ft and 90deg are not stored anywhere in the iModel, it gets generated in our backend geometry code and needs to be formatted to show the value in required units.
The above questions are just based on a primitive understanding of quantity formatter, please feel free to let me know if these assumptions are correct or not and also guide us in the right direction to implement this use case. Adding @Josh-Schifter in case I missed out any detail. |
Beta Was this translation helpful? Give feedback.
-
@hl662, what I think you might be missing is that we are not persisting the measured values at all. When the dimension geometry is being created (on the backend), we have geometric logic to compute the measured value. We want to use the QuantityFormatter logic to convert this measure value into a string. We will the turn the string into a TextString which will be added to our geometryStream. |
Beta Was this translation helpful? Give feedback.
-
@ColinKerr, I like the idea of each DimensionStyle storing the name of a KOQ. We will need to create a UI to show a filtered list of KOQs from the appropriate domain schema. We need to show a list of Length KOQs for use in formatting lengths, and Angle KOQs for angles, etc. This would be great because it allows the domain schema designers to control the options for formatting dimensions in their domain. The problem I see is that each KOQ can have multiple presentation units. We need a way to also present these as options in the UI. And we need a way to persist the chosen presentation unit in the dimension style. Where I get stuck is how to store a persistent reference to a presentation unit. I think we need to store a format string, for example "f:DefaultRealU(2)[u:MM]". ??? There is a strangeness here in that I think we don't actually require the KOQ to do the formatting since the format string seems to be sufficient. Nevertheless, I do think that KOQ is the key idea here since that's what allows the domain schema to influence the dimensions. If we agree on above, the rest is just implementation. I think we need help writing a backend function with inputs (measuredValue: number, formatString: string) which outputs formattedValue: string. Note for myself: The term "presentation units" here is used to describe more than just units. It also includes the formatting options. For example, this KOQ the "persentation units" string is actually a semicolon separated list of formatStrings: |
Beta Was this translation helpful? Give feedback.
-
After further discussion on this, I have just noted down a tentative plan that we have for storing formatting information in dimensionStyle element.
The koq property stores the {UnitSchemaName}.{koqName}, and the iModel we use, should have the UnitSchema already provisioned for this property to work well. In our backend code for dimension text formatting, we can use the below code where AeCUnits.LENGTH can be replaced by value of koq property from the above style element and "metric" can be replaced by the value of unitSystem property from the above style element. The above points are about how we store formatting information in the style element and use them in the backend for formatting.
This is just a rough summary of all the discussions, please feel free to ask questions and give suggestions. @ColinKerr @pmconne Adding @Josh-Schifter, in case I missed out any details |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posting this on behalf of @SheetalNair:
There are 2 major questions from our side:
Can we create a FormatterSpec from an OverrideFormat? … or more directly from a formatString?
It was mentioned that this could be tricky because the result of OverrideFormat.parseFormatString is OverrideFormatProps which cannot be directly used to create a FormatterSpec.
Though you suggested we could use serialize/deserialize methods to get Format Props, but I couldn’t find the method which would convert the result from OverrideFormatProps to OverrideFormat and then use it to get the formatProps we want.
Do we really need to supply our own UnitsProvider? … is there a way to get a standard one?
I tried to use the SchemaUnitProvider in the backend and it worked, but I want to share the code I tried and confirm if this is the right way. The input to this code is FormatProps from core-quantity NOT the formatString from ecschema-metadata.
For question 1: If we have a way to applyFormatting to value without using FormatterSpec and just by working with OverrideFormatProps from ecschema-metadata package, we can use the formatString to store formatters and work with that for quantity formatting. Is there already a way to do that? Am I missing something?
For question 2 : Why do we have QuantityFormatter class only on IModelApp which can be used only in frontend? If we had a similar class for backend, we won’t have to worry about UnitsProvider, as the QuantityFormatter will have all the data we need to get the FormatterSpec and applyFormating.
Beta Was this translation helpful? Give feedback.
All reactions