Coding - Add conversion utilities for STEP geometrical and visual enumerations#545
Conversation
dpasukhi
commented
May 17, 2025
- Introduced RWStepGeom_RWTransitionCode for converting StepGeom_TransitionCode to/from string representations.
- Refactored RWStepGeom_RWTrimmedCurve to utilize RWStepGeom_RWTrimmingPreference for trimming preference conversions.
- Created RWStepGeom_RWTrimmingPreference for handling StepGeom_TrimmingPreference enumerations.
- Updated RWStepGeom_RWUniformCurve and related classes to use RWStepGeom_RWBSplineCurveForm for B-spline curve form conversions.
- Added RWStepGeom_RWUniformSurface and related classes to use RWStepGeom_RWBSplineSurfaceForm for B-spline surface form conversions.
- Implemented RWStepShape_RWBooleanOperator for boolean operator conversions in STEP shapes.
- Refactored RWStepShape_RWBooleanResult to utilize RWStepShape_RWBooleanOperator for boolean operator handling.
- Introduced RWStepVisual_RWCentralOrParallel for central or parallel projection type conversions.
- Added RWStepVisual_RWSurfaceSide for surface side enumeration conversions.
- Updated RWStepVisual_RWSurfaceStyleUsage to use RWStepVisual_RWSurfaceSide for handling surface side.
- Created RWStepVisual_RWTextPath for text path enumeration conversions.
- Refactored RWStepVisual_RWTextLiteral to utilize RWStepVisual_RWTextPath for text path handling.
- Updated RWStepVisual_RWViewVolume to use RWStepVisual_RWCentralOrParallel for projection type conversions.
There was a problem hiding this comment.
Pull Request Overview
This PR replaces inline enumeration mapping with centralized conversion utilities, improving consistency and reducing boilerplate across STEP readers and writers.
- Replaced manual BSplineCurveForm string constants and switches with
RWStepGeom_RWBSplineCurveFormconversions - Introduced and applied
RWStepBasic_RWSiPrefixandRWStepBasic_RWSiUnitNamefor all SI unit reader/writer classes - Swapped out local enum mappings in
RWStepBasicforRWStepBasic_RWSourceandRWStepBasic_RWAheadOrBehind
Reviewed Changes
Copilot reviewed 56 out of 63 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/DataExchange/TKDESTEP/RWStepGeom/RWStepGeom_RWBSplineCurve.cxx | Use RWStepGeom_RWBSplineCurveForm for curve_form conversion |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitAndVolumeUnit.cxx | Read/write SI unit prefix and name via new ConvertToEnum/ConvertToString utilities |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitAndTimeUnit.cxx | Applied RWStepBasic enumeration utilities for time units |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitAndThermodynamicTemperatureUnit.cxx | Refactored thermodynamic temperature unit enum handling to use conversion utilities |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitAndSolidAngleUnit.cxx | Updated solid angle unit mapping to new shared converters |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitAndRatioUnit.cxx | Switched ratio unit read/write to RWStepBasic_RWSiPrefix and RWStepBasic_RWSiUnitName |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitAndPlaneAngleUnit.cxx | Replaced plane angle unit enum logic with centralized converters |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitAndMassUnit.cxx | Applied common SI enum converters for mass units |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitAndLengthUnit.cxx | Length unit mapping now uses shared prefix/name conversion |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitAndAreaUnit.cxx | Area unit reader/writer updated to use SI prefix/name utilities |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnit.cxx | Removed inline enum maps, delegating prefix/name conversions to RWStepBasic_RWSiPrefix and RWStepBasic_RWSiUnitName |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWProductDefinitionFormationWithSpecifiedSource.cxx | Simplified Source enum handling via RWStepBasic_RWSource |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWCoordinatedUniversalTimeOffset.cxx | Replaced AheadOrBehind inline mapping with RWStepBasic_RWAheadOrBehind |
Files not reviewed (7)
- src/DataExchange/TKDESTEP/RWStepBasic/FILES.cmake: Language not supported
- src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWAheadOrBehind.pxx: Language not supported
- src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiPrefix.pxx: Language not supported
- src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnit.pxx: Language not supported
- src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitName.pxx: Language not supported
- src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSource.pxx: Language not supported
- src/DataExchange/TKDESTEP/RWStepGeom/FILES.cmake: Language not supported
Comments suppressed due to low confidence (2)
src/DataExchange/TKDESTEP/RWStepGeom/RWStepGeom_RWBSplineCurve.cxx:82
- The error message refers to 'b_spline_curve_form' in lowercase; consider matching the exact enumeration identifier (e.g. 'B_SPLINE_CURVE_FORM') or including the parameter name (#4) for clarity.
ach->AddFail("Enumeration b_spline_curve_form has not an allowed value");
src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitAndVolumeUnit.cxx:57
- Consider adding unit tests to cover RWStepBasic_RWSiPrefix::ConvertToEnum and RWStepBasic_RWSiUnitName::ConvertToEnum to ensure all prefixes and unit names are correctly mapped.
hasAprefix = RWStepBasic_RWSiPrefix::ConvertToEnum(text, aPrefix);
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a set of conversion utility classes for STEP geometrical, basic, and visual enumerations, and refactors several RWStep* files to use these new conversion functions.
- Introduced conversion utilities (e.g., RWStepGeom_RWBSplineCurveForm, RWStepBasic_RWSiPrefix, RWStepBasic_RWSiUnitName, etc.) for enum‐to‐string and string‐to‐enum conversions.
- Refactored multiple files to remove custom decoding logic and use the new conversion routines.
- Updated error handling in enum conversion scenarios for improved consistency.
Reviewed Changes
Copilot reviewed 56 out of 63 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/DataExchange/TKDESTEP/RWStepGeom/RWStepGeom_RWBSplineCurve.cxx | Replaced custom enum mapping with conversion utility RWBSplineCurveForm. |
| src/DataExchange/TKDESTEP/RWStepBasic/* | Refactored RWStepBasic_RWSiUnitAnd... files to use RWStepBasic_RWSiPrefix and RWStepBasic_RWSiUnitName. |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWProductDefinitionFormationWithSpecifiedSource.cxx | Updated source enum conversion using RWStepBasic_RWSource utility. |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWCoordinatedUniversalTimeOffset.cxx | Replaced manual Ahead/Behind conversion with RWStepBasic_RWAheadOrBehind utility. |
| src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnit.cxx | Removed custom Decode/Encode functions in favor of new conversion methods. |
Files not reviewed (7)
- src/DataExchange/TKDESTEP/RWStepBasic/FILES.cmake: Language not supported
- src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWAheadOrBehind.pxx: Language not supported
- src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiPrefix.pxx: Language not supported
- src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnit.pxx: Language not supported
- src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitName.pxx: Language not supported
- src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSource.pxx: Language not supported
- src/DataExchange/TKDESTEP/RWStepGeom/FILES.cmake: Language not supported
Comments suppressed due to low confidence (5)
src/DataExchange/TKDESTEP/RWStepGeom/RWStepGeom_RWBSplineCurve.cxx:80
- Ensure that the ConvertToEnum function in RWStepGeom_RWBSplineCurveForm handles all possible curve form enum values and returns a clear error for unrecognized inputs.
if (!RWStepGeom_RWBSplineCurveForm::ConvertToEnum(text, aCurveForm))
src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitAndTimeUnit.cxx:60
- Verify that RWStepBasic_RWSiPrefix::ConvertToEnum covers all valid si_prefix cases to avoid potential mismatches across different unit files.
hasAprefix = RWStepBasic_RWSiPrefix::ConvertToEnum(text, aPrefix);
src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnit.cxx:48
- The removal of custom DecodePrefix/DecodeName functions improves maintainability. Ensure that the new conversion functions fully replicate the original behavior for all enum values.
hasAprefix = RWStepBasic_RWSiPrefix::ConvertToEnum(text, aPrefix);
src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWProductDefinitionFormationWithSpecifiedSource.cxx:66
- Confirm that RWStepBasic_RWSource::ConvertToEnum correctly distinguishes between all valid source enum values to maintain consistent behavior.
if (!RWStepBasic_RWSource::ConvertToEnum(text, aMakeOrBuy))
src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWCoordinatedUniversalTimeOffset.cxx:63
- Verify that the conversion utility RWStepBasic_RWAheadOrBehind accurately covers all enum variants for time offset sense, ensuring consistency with the updated conversion approach.
if (!RWStepBasic_RWAheadOrBehind::ConvertToEnum(text, aSense))
…merations - Introduced RWStepGeom_RWTransitionCode for converting StepGeom_TransitionCode to/from string representations. - Refactored RWStepGeom_RWTrimmedCurve to utilize RWStepGeom_RWTrimmingPreference for trimming preference conversions. - Created RWStepGeom_RWTrimmingPreference for handling StepGeom_TrimmingPreference enumerations. - Updated RWStepGeom_RWUniformCurve and related classes to use RWStepGeom_RWBSplineCurveForm for B-spline curve form conversions. - Added RWStepGeom_RWUniformSurface and related classes to use RWStepGeom_RWBSplineSurfaceForm for B-spline surface form conversions. - Implemented RWStepShape_RWBooleanOperator for boolean operator conversions in STEP shapes. - Refactored RWStepShape_RWBooleanResult to utilize RWStepShape_RWBooleanOperator for boolean operator handling. - Introduced RWStepVisual_RWCentralOrParallel for central or parallel projection type conversions. - Added RWStepVisual_RWSurfaceSide for surface side enumeration conversions. - Updated RWStepVisual_RWSurfaceStyleUsage to use RWStepVisual_RWSurfaceSide for handling surface side. - Created RWStepVisual_RWTextPath for text path enumeration conversions. - Refactored RWStepVisual_RWTextLiteral to utilize RWStepVisual_RWTextPath for text path handling. - Updated RWStepVisual_RWViewVolume to use RWStepVisual_RWCentralOrParallel for projection type conversions.
26eb2c3 to
09f5b46
Compare
Co-authored-by: Copilot <[email protected]> Signed-off-by: Pasukhin Dmitry <[email protected]>
ikochetkova
left a comment
There was a problem hiding this comment.
Please have a look at a couple of small comments.
| @@ -0,0 +1,81 @@ | |||
| // Created on: 1995-12-01 | |||
There was a problem hiding this comment.
File looks like a new one but with the very old header
| static constexpr char spPeta[] = ".PETA."; | ||
| static constexpr char spDeci[] = ".DECI."; | ||
| static constexpr char spKilo[] = ".KILO."; | ||
| static constexpr char spDeca[] = ".DECA."; |
There was a problem hiding this comment.
That was the sequence of the sorting? Looks random, it can easily lead to missing some prefixes.
There was a problem hiding this comment.
I just used what was before.
It is the same order as before, I'm not sure that it was ordered somehow.
I was afraid to change something, because I was assuming it was sortied by some hidden logic. But looks like it is just random :)
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the STEP enumeration conversion logic by introducing dedicated conversion utilities (in .pxx files) for various enumerations in STEP visual, shape, geom, and basic modules. Key changes include removing redundant inline static strings and switch-case conversions in reader/writer classes, and replacing them with centralized conversion functions to improve consistency and maintainability.
Reviewed Changes
Copilot reviewed 63 out of 63 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| RWStepVisual_RWViewVolume.cxx | Replaces inline enum comparisons with conversion functions for projection type. |
| RWStepShape_RWBooleanResult.cxx, RWStepShape_RWBooleanOperator.pxx | Refactors boolean operator conversion using a dedicated conversion file. |
| RWStepGeom/* files (e.g., RWStepGeom_RWBSplineSurfaceForm.pxx, RWStepGeom_RWTrimmingPreference.pxx) | Consolidates conversion logic for various geometric enums into centralized utilities. |
| RWStepBasic/* files (e.g., RWStepBasic_RWSiUnitName.pxx, RWStepBasic_RWSiPrefix.pxx) | Updates SI unit conversion to use shared conversion functions. |
Comments suppressed due to low confidence (2)
src/DataExchange/TKDESTEP/RWStepVisual/RWStepVisual_RWViewVolume.cxx:124
- The use of the conversion utility improves maintainability; however, ensure that ConvertToString reliably returns a valid string (i.e. not nullptr) for all valid enum values to prevent potential runtime issues during serialization.
SW.SendEnum(RWStepVisual_RWCentralOrParallel::ConvertToString(ent->ProjectionType()));
src/DataExchange/TKDESTEP/RWStepBasic/RWStepBasic_RWSiUnitAndVolumeUnit.cxx:109
- Refactoring to use conversion functions for SI unit names enhances consistency; consider adding a fallback or explicit error handling if ConvertToString returns nullptr.
SW.SendEnum(RWStepBasic_RWSiUnitName::ConvertToString(ent->Name()));
| case StepGeom_bssfQuadricSurf: | ||
| return bssfQuadricSurf; | ||
| } | ||
| return nullptr; |
There was a problem hiding this comment.
Returning nullptr for an unrecognized enumeration may lead to silent failures during WriteStep; consider either logging an error or providing a default string value to improve error visibility during debugging.
| return nullptr; | |
| std::cerr << "Error: Unrecognized StepGeom_BSplineSurfaceForm enumeration value encountered." << std::endl; | |
| return ".UNKNOWN_SURF_FORM."; |