/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef TNW_FIND_CONDITION_UTILS_H_ #define TNW_FIND_CONDITION_UTILS_H_ #include "OdaCommon.h" #include "NwExport.h" #include "NwDataType.h" #include "SelectionSets/NwSelectionSetsTypes.h" #include class OdString; /** \details Utils of find condition using. */ namespace NwFindConditionUtils { /** \details Get default value for find condition's flags. \returns OdUInt32 value with defualt value of find condition's flag. */ constexpr OdUInt32 getDefaultConditionFlags() { return NwSelectionFindConditionFlags::IGNORE_CATEGORY_INTERNAL_NAME | NwSelectionFindConditionFlags::IGNORE_PROPERTY_INTERNAL_NAME; } /** \details Check if find condition's flag in the default state. \param flags [in] find condition's flags. \returns boolean flag if find condition's flags in the default state. */ constexpr bool isDefaultCondFlags(OdUInt32 flags) { return (flags & (NwSelectionFindConditionFlags::IGNORE_CATEGORY_USER_NAME | NwSelectionFindConditionFlags::IGNORE_CATEGORY_INTERNAL_NAME | NwSelectionFindConditionFlags::IGNORE_PROPERTY_USER_NAME | NwSelectionFindConditionFlags::IGNORE_PROPERTY_INTERNAL_NAME | NwSelectionFindConditionFlags::IGNORE_STRING_VALUE_CASE | NwSelectionFindConditionFlags::NEGATE_CONDITIONS | NwSelectionFindConditionFlags::IGNORE_STRING_VALUE_DIACRITICS | NwSelectionFindConditionFlags::IGNORE_STRING_VALUE_CHARACTER_WIDTH)) == getDefaultConditionFlags(); } /** \details Check if specified find condition matches the value data type. \param valueType [in] specified value data type for condition's checking. \returns boolean flag if specified find condition matches the value data type. \remarks valueType can be one of the following: Name Value Description NwDataType::dt_NONE 0 Default value type. NwDataType::dt_DOUBLE 0x01 Double value type. NwDataType::dt_INT32 0x02 32-bit integer value type. NwDataType::dt_BOOL 0x03 Boolean value type. NwDataType::dt_DISPLAY_STRING 0x04 Display end-user string value type. NwDataType::dt_DATETIME 0x05 Date time value type. NwDataType::dt_DOUBLE_LENGTH 0x06 Double value type for length (in length's units). NwDataType::dt_DOUBLE_ANGLE 0x07 Double value type for angle (in radians). NwDataType::dt_NAME 0x08 Name value type (with pointer to OdNwName object). NwDataType::dt_IDENTIFIER_STRING 0x09 Programmatic identifier string value type. NwDataType::dt_DOUBLE_AREA 0x0A Double value type for area. NwDataType::dt_DOUBLE_VOLUME 0x0B Double value type for volume. NwDataType::dt_POINT3D 0x0C Point3d value type. NwDataType::dt_POINT2D 0x0D Point2d value type.
Condition type can be one of the following: Name Value Description NwSelectionFindConditionType::NEVER 0 Never used. NwSelectionFindConditionType::ATTRIB 1 With attributes. NwSelectionFindConditionType::NO_ATTRIB 2 No attributes. NwSelectionFindConditionType::PROP 3 Defined; to match the search criteria, a property must have a value defined. NwSelectionFindConditionType::NO_PROP 4 Undefined; to match the search criteria, a property must not have a defined value. NwSelectionFindConditionType::SAME_TYPE 5 The same type NwSelectionFindConditionType::EQUALS 6 Equals; a property must match the value exactly. NwSelectionFindConditionType::NOT_EQUALS 7 Not equal; use with any type of property. NwSelectionFindConditionType::LESS_THAN 8 Less than; use with numerical property types only. NwSelectionFindConditionType::LESS_EQUAL 9 Less than or equal; use with numerical property types only. NwSelectionFindConditionType::GREATER_EQUAL 10 Greater than or equal; use with numerical property types only. NwSelectionFindConditionType::GREATER_THAN 11 Greater than; use with numerical property types only. NwSelectionFindConditionType::CONTAINS 12 A property must contain the specified value. NwSelectionFindConditionType::WILDCARD 13 Using wildcards allows matching any one character (?) or an arbitrary sequence of characters (*). NwSelectionFindConditionType::WITHIN_DAY 14 To match the search criteria, a property must be within the specified day. NwSelectionFindConditionType::WITHIN_WEEK 15 To match the search criteria, a property must be within the specified week.
*/ constexpr bool checkConditionForValueType(NwSelectionFindConditionType::Enum condition, NwDataType::Enum valueType) { switch (valueType) { case NwDataType::dt_NONE: return condition == NwSelectionFindConditionType::ATTRIB || condition == NwSelectionFindConditionType::NO_ATTRIB; break; case NwDataType::dt_DOUBLE: case NwDataType::dt_DOUBLE_ANGLE: case NwDataType::dt_DOUBLE_LENGTH: case NwDataType::dt_DOUBLE_VOLUME: case NwDataType::dt_DOUBLE_AREA: case NwDataType::dt_INT32: case NwDataType::dt_IDENTIFIER_STRING: case NwDataType::dt_POINT3D: return condition == NwSelectionFindConditionType::EQUALS || condition == NwSelectionFindConditionType::NOT_EQUALS || condition == NwSelectionFindConditionType::LESS_THAN || condition == NwSelectionFindConditionType::LESS_EQUAL || condition == NwSelectionFindConditionType::GREATER_THAN || condition == NwSelectionFindConditionType::GREATER_EQUAL || condition == NwSelectionFindConditionType::PROP || condition == NwSelectionFindConditionType::NO_PROP; break; case NwDataType::dt_NAME: case NwDataType::dt_BOOL: return condition == NwSelectionFindConditionType::EQUALS || condition == NwSelectionFindConditionType::NOT_EQUALS || condition == NwSelectionFindConditionType::PROP || condition == NwSelectionFindConditionType::NO_PROP; break; case NwDataType::dt_DISPLAY_STRING: return condition == NwSelectionFindConditionType::EQUALS || condition == NwSelectionFindConditionType::NOT_EQUALS || condition == NwSelectionFindConditionType::CONTAINS || condition == NwSelectionFindConditionType::WILDCARD || condition == NwSelectionFindConditionType::PROP || condition == NwSelectionFindConditionType::NO_PROP; break; case NwDataType::dt_DATETIME: return condition == NwSelectionFindConditionType::EQUALS || condition == NwSelectionFindConditionType::NOT_EQUALS || condition == NwSelectionFindConditionType::LESS_THAN || condition == NwSelectionFindConditionType::LESS_EQUAL || condition == NwSelectionFindConditionType::GREATER_THAN || condition == NwSelectionFindConditionType::GREATER_EQUAL || condition == NwSelectionFindConditionType::WITHIN_DAY || condition == NwSelectionFindConditionType::WITHIN_WEEK || condition == NwSelectionFindConditionType::PROP || condition == NwSelectionFindConditionType::NO_PROP; break; default: break; } return false; } /** \details Returns the count of possible find conditions for specified value data type. \param valueType [in] specified value data type for condition's detecting. \returns OdUInt32 with count of possible find condition for specified value data type. \remarks valueType can be one of the following: Name Value Description NwDataType::dt_NONE 0 Default value type. NwDataType::dt_DOUBLE 0x01 Double value type. NwDataType::dt_INT32 0x02 32-bit integer value type. NwDataType::dt_BOOL 0x03 Boolean value type. NwDataType::dt_DISPLAY_STRING 0x04 Display end-user string value type. NwDataType::dt_DATETIME 0x05 Date time value type. NwDataType::dt_DOUBLE_LENGTH 0x06 Double value type for length (in length's units). NwDataType::dt_DOUBLE_ANGLE 0x07 Double value type for angle (in radians). NwDataType::dt_NAME 0x08 Name value type (with pointer to OdNwName object). NwDataType::dt_IDENTIFIER_STRING 0x09 Programmatic identifier string value type. NwDataType::dt_DOUBLE_AREA 0x0A Double value type for area. NwDataType::dt_DOUBLE_VOLUME 0x0B Double value type for volume. NwDataType::dt_POINT3D 0x0C Point3d value type. NwDataType::dt_POINT2D 0x0D Point2d value type.
*/ constexpr OdUInt32 getConditionCountForValueType(NwDataType::Enum valueType) { OdUInt32 condCntForValueType = 0; for (int i = 0; i <= static_cast(NwSelectionFindConditionType::WITHIN_WEEK); ++i) { if (checkConditionForValueType(static_cast(i), valueType)) ++condCntForValueType; } return condCntForValueType; } //DOM-IGNORE-BEGIN constexpr NwSelectionFindConditionType::Enum getSortedConditionByUnsortedIdx(int idx) { switch (idx) { case 0: return NwSelectionFindConditionType::EQUALS; break; case 1: return NwSelectionFindConditionType::NOT_EQUALS; break; case 2: return NwSelectionFindConditionType::LESS_THAN; break; case 3: return NwSelectionFindConditionType::LESS_EQUAL; break; case 4: return NwSelectionFindConditionType::GREATER_THAN; break; case 5: return NwSelectionFindConditionType::GREATER_EQUAL; break; case 6: return NwSelectionFindConditionType::CONTAINS; break; case 7: return NwSelectionFindConditionType::WILDCARD; break; case 8: return NwSelectionFindConditionType::WITHIN_DAY; break; case 9: return NwSelectionFindConditionType::WITHIN_WEEK; break; case 10: return NwSelectionFindConditionType::PROP; break; case 11: return NwSelectionFindConditionType::NO_PROP; break; case 12: return NwSelectionFindConditionType::ATTRIB; break; case 13: return NwSelectionFindConditionType::NO_ATTRIB; break; default: break; } return NwSelectionFindConditionType::NEVER; } template constexpr NwSelectionFindConditionType::Enum getConditionForValueTypeByIdx(std::size_t idx) { OdUInt32 condIdxForValueType = 0; for (int i = 0; i <= static_cast(NwSelectionFindConditionType::WITHIN_WEEK); ++i) { auto sortedCondition = getSortedConditionByUnsortedIdx(i); if (checkConditionForValueType(sortedCondition, valueType)) { if (condIdxForValueType++ == idx) return sortedCondition; } } return NwSelectionFindConditionType::NEVER; } template constexpr std::array getConditionsForValueType(std::index_sequence ) { return { getConditionForValueTypeByIdx(Is)...}; } //DOM-IGNORE-END /** \details Returns the array of possible find conditions for specified value data type. \returns std::array with possible find condition for specified value data type. \remarks valueType can be one of the following: Name Value Description NwDataType::dt_NONE 0 Default value type. NwDataType::dt_DOUBLE 0x01 Double value type. NwDataType::dt_INT32 0x02 32-bit integer value type. NwDataType::dt_BOOL 0x03 Boolean value type. NwDataType::dt_DISPLAY_STRING 0x04 Display end-user string value type. NwDataType::dt_DATETIME 0x05 Date time value type. NwDataType::dt_DOUBLE_LENGTH 0x06 Double value type for length (in length's units). NwDataType::dt_DOUBLE_ANGLE 0x07 Double value type for angle (in radians). NwDataType::dt_NAME 0x08 Name value type (with pointer to OdNwName object). NwDataType::dt_IDENTIFIER_STRING 0x09 Programmatic identifier string value type. NwDataType::dt_DOUBLE_AREA 0x0A Double value type for area. NwDataType::dt_DOUBLE_VOLUME 0x0B Double value type for volume. NwDataType::dt_POINT3D 0x0C Point3d value type. NwDataType::dt_POINT2D 0x0D Point2d value type.
*/ template constexpr std::array getConditionsForValueType() { return getConditionsForValueType(std::make_index_sequence()); } /** \details Returns string interpretation for specified find condition. \param condition [in] specified condition for string conversion. \returns OdString with serialized condition value. \remarks Condition type can be one of the following: Name Value Description NwSelectionFindConditionType::NEVER 0 Never used. NwSelectionFindConditionType::ATTRIB 1 With attributes. NwSelectionFindConditionType::NO_ATTRIB 2 No attributes. NwSelectionFindConditionType::PROP 3 Defined; to match the search criteria, a property must have a value defined. NwSelectionFindConditionType::NO_PROP 4 Undefined; to match the search criteria, a property must not have a defined value. NwSelectionFindConditionType::SAME_TYPE 5 The same type NwSelectionFindConditionType::EQUALS 6 Equals; a property must match the value exactly. NwSelectionFindConditionType::NOT_EQUALS 7 Not equal; use with any type of property. NwSelectionFindConditionType::LESS_THAN 8 Less than; use with numerical property types only. NwSelectionFindConditionType::LESS_EQUAL 9 Less than or equal; use with numerical property types only. NwSelectionFindConditionType::GREATER_EQUAL 10 Greater than or equal; use with numerical property types only. NwSelectionFindConditionType::GREATER_THAN 11 Greater than; use with numerical property types only. NwSelectionFindConditionType::CONTAINS 12 A property must contain the specified value. NwSelectionFindConditionType::WILDCARD 13 Using wildcards allows matching any one character (?) or an arbitrary sequence of characters (*). NwSelectionFindConditionType::WITHIN_DAY 14 To match the search criteria, a property must be within the specified day. NwSelectionFindConditionType::WITHIN_WEEK 15 To match the search criteria, a property must be within the specified week.
*/ OdString NWDBEXPORT condition2str(NwSelectionFindConditionType::Enum condition); /** \details Returns find condition enumeration type by string find condition interpretation. \param sCondition [in] string condition value. \param isPropertyDefined [in] boolean flag is property is defined for condition, or not. In seond case this method work only for ATTRIB/NO_ATTRIB conditions. \returns condition type as string's conversion result. \remarks return condition type can be one of the following: Name Value Description NwSelectionFindConditionType::NEVER 0 Never used. NwSelectionFindConditionType::ATTRIB 1 With attributes. NwSelectionFindConditionType::NO_ATTRIB 2 No attributes. NwSelectionFindConditionType::PROP 3 Defined; to match the search criteria, a property must have a value defined. NwSelectionFindConditionType::NO_PROP 4 Undefined; to match the search criteria, a property must not have a defined value. NwSelectionFindConditionType::SAME_TYPE 5 The same type NwSelectionFindConditionType::EQUALS 6 Equals; a property must match the value exactly. NwSelectionFindConditionType::NOT_EQUALS 7 Not equal; use with any type of property. NwSelectionFindConditionType::LESS_THAN 8 Less than; use with numerical property types only. NwSelectionFindConditionType::LESS_EQUAL 9 Less than or equal; use with numerical property types only. NwSelectionFindConditionType::GREATER_EQUAL 10 Greater than or equal; use with numerical property types only. NwSelectionFindConditionType::GREATER_THAN 11 Greater than; use with numerical property types only. NwSelectionFindConditionType::CONTAINS 12 A property must contain the specified value. NwSelectionFindConditionType::WILDCARD 13 Using wildcards allows matching any one character (?) or an arbitrary sequence of characters (*). NwSelectionFindConditionType::WITHIN_DAY 14 To match the search criteria, a property must be within the specified day. NwSelectionFindConditionType::WITHIN_WEEK 15 To match the search criteria, a property must be within the specified week.
*/ NwSelectionFindConditionType::Enum NWDBEXPORT str2condition(const OdString& sCondition, bool isPropertyDefined); } #endif // TNW_FIND_CONDITION_UTILS_H_