Clash Query#
Overview#
File Name: clash_query.py
The file defines a class for managing and executing clash detection queries. It includes functionality to serialize and deserialize settings, manage query metadata and update timestamps.
ClashQuery Class#
- class ClashQuery#
A class that is designed to manage settings for clash detection queries. It includes functionality to serialize and deserialize settings, manage query metadata and update timestamps.
Constants#
- VERSION: int = 3
The version number of the ClashQuery class for serialization purposes.
Constructor#
- __init__(
- identifier: int = -1,
- query_name: str = '',
- object_a_path: str = '',
- object_b_path: str = '',
- clash_detect_settings: Dict[str, Any] | None = None,
- creation_timestamp: datetime | None = None,
- last_modified_timestamp: datetime | None = None,
- last_modified_by: str = '',
- comment: str = '',
Initializes a new instance of the ClashQuery class.
- Parameters:
identifier (int, default is -1) – Unique identifier for the clash query. -1 means not yet assigned / uninitialized.
query_name (str, default is "") – Name of the clash query.
object_a_path (str, default is "") – Path to the first object involved in the clash detection. Can contain multiple paths separated by space/tab/newline.
object_b_path (str, default is "") – Path to the second object involved in the clash detection. Can contain multiple paths separated by space/tab/newline.
clash_detect_settings (Optional[Dict[str, Any]], default is None) – Settings for the clash detection process.
creation_timestamp (Optional[datetime], default is None) – Timestamp when the query was created.
last_modified_timestamp (Optional[datetime], default is None) – Timestamp when the query was last modified.
last_modified_by (str, default is "") – Name of the user who last modified the query.
comment (str, default is "") – Additional comments or notes about the query.
Methods#
- serialize_to_dict() Dict[str, Any]
Converts the ClashQuery instance to a dictionary in JSON-serializable format.
- Returns:
Dictionary containing the serialized ClashQuery data.
- Return type:
Dict[str, Any]
- deserialize_from_dict(
- data: Dict[str, Any],
- reset_identifier: bool = False,
Deserializes a ClashQuery instance from a JSON-serializable dictionary format.
- Parameters:
data (Dict[str, Any]) – Dictionary containing serialized ClashQuery data.
reset_identifier (bool, default is False) – If True, resets the identifier to -1 after deserialization.
- Returns:
New ClashQuery instance if deserialization succeeds, None if it fails.
- Return type:
ClashQuery | None
- load_settings_from_str(settings_str: str) bool
Deserializes settings values from the JSON string.
- Parameters:
settings_str (str) – The JSON string containing settings.
- Returns:
True on success, otherwise False.
- Return type:
bool
- get_settings_as_str() str
Serializes setting values to a JSON string and returns it.
- Returns:
The JSON string representation of settings.
- Return type:
str
- update_last_modified_timestamp() None
Updates last modified timestamp with current date & time.
Properties#
- identifier: int
Read-only property that returns the unique identifier of the query.
- query_name: str
Property to get or set the name of the query. Setting this property updates the last modified timestamp.
- object_a_path: str
Property to get or set the path to the first object in the clash detection query. Can contain multiple paths separated by space/tab/newline. Setting this property updates the last modified timestamp.
- object_b_path: str
Property to get or set the path to the second object in the clash detection query. Can contain multiple paths separated by space/tab/newline. Setting this property updates the last modified timestamp.
- clash_detect_settings: Dict[str, Any]
Property to get or set the clash detection settings as a dictionary. Setting this property updates the last modified timestamp.
- creation_timestamp: datetime
Read-only property that returns the timestamp when the query was created.
- last_modified_timestamp: datetime
Property to get or set the timestamp when the query was last modified. Setting this property updates the last modified by user to the current user.
- last_modified_by: str
Read-only property that returns the name of the user who last modified the query.
- comment: str
Property to get or set a comment or note associated with the query. Setting this property updates the last modified timestamp.
Usage Example#
# Create a new ClashQuery instance
clash_detect_settings = {
SettingId.SETTING_LOGGING.name: False,
SettingId.SETTING_DYNAMIC.name: True,
SettingId.SETTING_TOLERANCE.name: 0.05,
}
my_query = ClashQuery(
query_name="My Example Query",
object_a_path="/path/to/object_a",
object_b_path="/path/to/object_b",
clash_detect_settings=clash_detect_settings,
comment="My example comment"
)
# Retrieve the settings as a JSON string
settings_str = my_query.get_settings_as_str()
# Load query settings from a JSON string
success = my_query.load_settings_from_str(settings_str)
# Update the query name and automatically update the last modified timestamp
my_query.query_name = "Updated Query Name"
# Update the query comment and automatically update the last modified timestamp
my_query.comment = "Updated comment"