diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..a010658
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,594 @@
+root = true
+
+# C# files
+[*.cs]
+
+#### Core EditorConfig Options ####
+
+# Indentation and spacing
+indent_size = 4
+indent_style = space
+tab_width = 4
+
+# New line preferences
+end_of_line = crlf
+insert_final_newline = false
+
+#### .NET Coding Conventions ####
+
+# Organize usings
+dotnet_separate_import_directive_groups = false
+dotnet_sort_system_directives_first = false
+
+# this. and Me. preferences
+dotnet_style_qualification_for_event = true:warning
+dotnet_style_qualification_for_field = true:warning
+dotnet_style_qualification_for_method = true:warning
+dotnet_style_qualification_for_property = true:warning
+
+# Language keywords vs BCL types preferences
+dotnet_style_predefined_type_for_locals_parameters_members = true:warning
+dotnet_style_predefined_type_for_member_access = true:warning
+
+# Parentheses preferences
+dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning
+dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning
+dotnet_style_parentheses_in_other_operators = never_if_unnecessary:warning
+dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning
+
+# Modifier preferences
+dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning
+
+# Expression-level preferences
+csharp_style_deconstructed_variable_declaration = true:none
+dotnet_style_coalesce_expression = true:warning
+dotnet_style_collection_initializer = true:warning
+dotnet_style_explicit_tuple_names = true:warning
+dotnet_style_null_propagation = true:warning
+dotnet_style_object_initializer = true:suggestion
+dotnet_style_operator_placement_when_wrapping = beginning_of_line
+dotnet_style_prefer_auto_properties = true:warning
+dotnet_style_prefer_compound_assignment = true:warning
+dotnet_style_prefer_conditional_expression_over_assignment = true:none
+dotnet_style_prefer_conditional_expression_over_return = true:none
+dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
+dotnet_style_prefer_inferred_tuple_names = true:suggestion
+dotnet_style_prefer_is_null_check_over_reference_equality_method = false:warning
+dotnet_style_prefer_simplified_boolean_expressions = true:warning
+dotnet_style_prefer_simplified_interpolation = true:warning
+
+# Field preferences
+dotnet_style_readonly_field = true:warning
+
+# Parameter preferences
+dotnet_code_quality_unused_parameters = all:suggestion
+
+# Suppression preferences
+dotnet_remove_unnecessary_suppression_exclusions = warning
+
+#### C# Coding Conventions ####
+
+# var preferences
+csharp_style_var_elsewhere = true:warning
+csharp_style_var_for_built_in_types = true:warning
+csharp_style_var_when_type_is_apparent = true:warning
+
+# Expression-bodied members
+csharp_style_expression_bodied_accessors = when_on_single_line:warning
+csharp_style_expression_bodied_constructors = false:warning
+csharp_style_expression_bodied_indexers = when_on_single_line:warning
+csharp_style_expression_bodied_lambdas = true:warning
+csharp_style_expression_bodied_local_functions = false:none
+csharp_style_expression_bodied_methods = when_on_single_line:hint
+csharp_style_expression_bodied_operators = when_on_single_line:warning
+csharp_style_expression_bodied_properties = when_on_single_line:warning
+
+# Pattern matching preferences
+csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
+csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
+csharp_style_prefer_not_pattern = true:suggestion
+csharp_style_prefer_pattern_matching = false:none
+csharp_style_prefer_switch_expression = true:suggestion
+
+# Null-checking preferences
+csharp_style_conditional_delegate_call = true:warning
+
+# Modifier preferences
+csharp_prefer_static_local_function = true:warning
+csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async:warning
+
+# Code-block preferences
+csharp_prefer_braces = true:warning
+csharp_prefer_simple_using_statement = true:suggestion
+
+# Expression-level preferences
+csharp_prefer_simple_default_expression = true:warning
+csharp_style_deconstructed_variable_declaration = true:warning
+csharp_style_inlined_variable_declaration = true:warning
+csharp_style_pattern_local_over_anonymous_function = true:warning
+csharp_style_prefer_index_operator = true:suggestion
+csharp_style_prefer_range_operator = true:suggestion
+csharp_style_throw_expression = true:warning
+csharp_style_unused_value_assignment_preference = discard_variable:warning
+csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion
+
+# 'using' directive preferences
+csharp_using_directive_placement = outside_namespace:warning
+
+#### C# Formatting Rules ####
+
+# New line preferences
+csharp_new_line_before_catch = true
+csharp_new_line_before_else = true
+csharp_new_line_before_finally = true
+csharp_new_line_before_members_in_anonymous_types = true
+csharp_new_line_before_members_in_object_initializers = true
+csharp_new_line_before_open_brace = all
+csharp_new_line_between_query_expression_clauses = true
+
+# Indentation preferences
+csharp_indent_block_contents = true
+csharp_indent_braces = false
+csharp_indent_case_contents = true
+csharp_indent_case_contents_when_block = true
+csharp_indent_labels = one_less_than_current
+csharp_indent_switch_labels = true
+
+# ElasticSpace preferences
+csharp_space_after_cast = true
+csharp_space_after_colon_in_inheritance_clause = true
+csharp_space_after_comma = true
+csharp_space_after_dot = false
+csharp_space_after_keywords_in_control_flow_statements = true
+csharp_space_after_semicolon_in_for_statement = true
+csharp_space_around_binary_operators = before_and_after
+csharp_space_around_declaration_statements = false
+csharp_space_before_colon_in_inheritance_clause = true
+csharp_space_before_comma = false
+csharp_space_before_dot = false
+csharp_space_before_open_square_brackets = false
+csharp_space_before_semicolon_in_for_statement = false
+csharp_space_between_empty_square_brackets = false
+csharp_space_between_method_call_empty_parameter_list_parentheses = false
+csharp_space_between_method_call_name_and_opening_parenthesis = false
+csharp_space_between_method_call_parameter_list_parentheses = true
+csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
+csharp_space_between_method_declaration_name_and_open_parenthesis = false
+csharp_space_between_method_declaration_parameter_list_parentheses = true
+csharp_space_between_parentheses = control_flow_statements
+csharp_space_between_square_brackets = false
+
+# Wrapping preferences
+csharp_preserve_single_line_blocks = true
+csharp_preserve_single_line_statements = false
+
+#### Naming styles ####
+
+# Naming rules
+
+dotnet_naming_rule.interface_should_be_begins_with_i.severity = error
+dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
+dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
+
+dotnet_naming_rule.types_should_be_pascal_case.severity = error
+dotnet_naming_rule.types_should_be_pascal_case.symbols = types
+dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
+
+dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = warning
+dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
+dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
+
+dotnet_naming_rule.public_or_protected_field_should_be_pascal_case.severity = warning
+dotnet_naming_rule.public_or_protected_field_should_be_pascal_case.symbols = public_or_protected_field
+dotnet_naming_rule.public_or_protected_field_should_be_pascal_case.style = pascal_case
+
+dotnet_naming_rule.private_field_should_be_begins_with_underscore.severity = warning
+dotnet_naming_rule.private_field_should_be_begins_with_underscore.symbols = private_field
+dotnet_naming_rule.private_field_should_be_begins_with_underscore.style = begins_with_underscore
+
+# Symbol specifications
+
+dotnet_naming_symbols.interface.applicable_kinds = interface
+dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.interface.required_modifiers =
+
+dotnet_naming_symbols.public_or_protected_field.applicable_kinds = field
+dotnet_naming_symbols.public_or_protected_field.applicable_accessibilities = public, protected
+dotnet_naming_symbols.public_or_protected_field.required_modifiers =
+
+dotnet_naming_symbols.private_field.applicable_kinds = field
+dotnet_naming_symbols.private_field.applicable_accessibilities = private, private_protected
+dotnet_naming_symbols.private_field.required_modifiers =
+
+dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
+dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.types.required_modifiers =
+
+dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
+dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.non_field_members.required_modifiers =
+
+# Naming styles
+
+dotnet_naming_style.pascal_case.required_prefix =
+dotnet_naming_style.pascal_case.required_suffix =
+dotnet_naming_style.pascal_case.word_separator =
+dotnet_naming_style.pascal_case.capitalization = pascal_case
+
+dotnet_naming_style.begins_with_i.required_prefix = I
+dotnet_naming_style.begins_with_i.required_suffix =
+dotnet_naming_style.begins_with_i.word_separator =
+dotnet_naming_style.begins_with_i.capitalization = pascal_case
+
+dotnet_naming_style.begins_with_underscore.required_prefix = _
+dotnet_naming_style.begins_with_underscore.required_suffix =
+dotnet_naming_style.begins_with_underscore.word_separator =
+dotnet_naming_style.begins_with_underscore.capitalization = camel_case
+
+# IDE0021: Use expression body for constructors
+dotnet_diagnostic.IDE0021.severity = suggestion
+
+# IDE0019: Use pattern matching
+dotnet_diagnostic.IDE0019.severity = suggestion
+
+# IDE0021: Use expression body for constructors
+dotnet_diagnostic.IDE0021.severity = warning
+
+# IDE0044: Add readonly modifier
+dotnet_diagnostic.IDE0044.severity = warning
+
+# IDE0079: Remove unnecessary suppression
+dotnet_diagnostic.IDE0079.severity = warning
+
+# SA0001: XML doc analysis disabled
+dotnet_diagnostic.SA0001.severity = none
+
+# SA1009: Closing parenthesis should be spaced correctly
+dotnet_diagnostic.SA1009.severity = none
+
+# SA1309: Field names should not begin with underscore
+dotnet_diagnostic.SA1309.severity = none
+
+# SA1633: File should have header
+dotnet_diagnostic.SA1633.severity = none
+
+# SA1636: File header should be correct
+dotnet_diagnostic.SA1636.severity = none
+
+# SA1200: Using directives should be placed within namespace
+dotnet_diagnostic.SA1200.severity = none
+
+# SA1204: Static members should appear before non-static members
+dotnet_diagnostic.SA1204.severity = none
+
+# SA1208: Using directive should appear before...
+dotnet_diagnostic.SA1208.severity = none
+
+# SA1500: Braces for multi-line statements should not share line
+dotnet_diagnostic.SA1500.severity = none
+
+# SA1501: Statement should not be on a single line
+dotnet_diagnostic.SA1501.severity = none
+
+# SA1502: Element should not be on a single line
+dotnet_diagnostic.SA1502.severity = none
+
+# SA1505: Opening braces should not be followed by blank line
+dotnet_diagnostic.SA1505.severity = none
+
+# SA1600: Elements should be documented
+dotnet_diagnostic.SA1600.severity = none
+
+# SA1008: Opening parenthesis should be spaced correctly
+dotnet_diagnostic.SA1008.severity = none
+
+# SA1128: Put constructor initializers on their own line
+dotnet_diagnostic.SA1128.severity = none
+
+# SA1202: Elements should be ordered by access
+dotnet_diagnostic.SA1202.severity = none
+
+# SA1614: Element parameter documentation should have text
+dotnet_diagnostic.SA1614.severity = none
+
+# SA1615: Element return value should be documented
+dotnet_diagnostic.SA1615.severity = none
+
+# SA1616: Element return value documentation should have text
+dotnet_diagnostic.SA1616.severity = none
+
+# SA1201: Elements should appear in the correct order
+dotnet_diagnostic.SA1201.severity = none
+
+# SA1601: Partial elements should be documented
+dotnet_diagnostic.SA1601.severity = none
+
+# SA1003: Symbols should be spaced correctly
+dotnet_diagnostic.SA1003.severity = none
+
+# SA1622: Generic type parameter documentation should have text
+dotnet_diagnostic.SA1622.severity = none
+
+# SA1611: Element parameters should be documented
+dotnet_diagnostic.SA1611.severity = none
+
+# SA1512: Single-line comments should not be followed by blank line
+dotnet_diagnostic.SA1512.severity = none
+
+# SA1515: Single-line comment should be preceded by blank line
+dotnet_diagnostic.SA1515.severity = none
+
+# SA1516: Elements should be separated by blank line
+dotnet_diagnostic.SA1516.severity = none
+
+# SA1010: Opening square brackets should be spaced correctly
+dotnet_diagnostic.SA1010.severity = none
+
+# SA1011: Closing square brackets should be spaced correctly
+dotnet_diagnostic.SA1011.severity = none
+
+# SA1118: Parameter should not span multiple lines
+dotnet_diagnostic.SA1118.severity = suggestion
+
+# SA1413: Use trailing comma in multi-line initializers
+dotnet_diagnostic.SA1413.severity = none
+
+# SA1122: Use string.Empty for empty strings
+dotnet_diagnostic.SA1122.severity = none
+
+# CA1310: Specify StringComparison for correctness
+dotnet_diagnostic.CA1310.severity = warning
+
+# CA1725: Parameter names should match base declaration
+dotnet_diagnostic.CA1725.severity = warning
+
+# CA1805: Do not initialize unnecessarily
+dotnet_diagnostic.CA1805.severity = warning
+
+# CA1822: Member can be marked as static
+dotnet_diagnostic.CA1822.severity = warning
+
+# CA1829: Use the Count property instead of Enumerable.Count()
+dotnet_diagnostic.CA1829.severity = warning
+
+# CA2201: Do not raise reserved exception types
+dotnet_diagnostic.CA2201.severity = warning
+
+# CA2215: Dispose methods should call base class dispose
+dotnet_diagnostic.CA2215.severity = warning
+
+# CA5350: Do Not Use Weak Cryptographic Algorithms
+dotnet_diagnostic.CA5350.severity = warning
+
+# CA5351: Do Not Use Broken Cryptographic Algorithms
+dotnet_diagnostic.CA5351.severity = warning
+
+# CA5369: Use XmlReader For Deserialize
+dotnet_diagnostic.CA5369.severity = warning
+
+# CA5370: Use XmlReader For Validating Reader
+dotnet_diagnostic.CA5370.severity = warning
+
+# CA5371: Use XmlReader For Schema Read
+dotnet_diagnostic.CA5371.severity = warning
+
+# CA5372: Use XmlReader For XPathDocument
+dotnet_diagnostic.CA5372.severity = warning
+
+# CA5373: Do not use obsolete key derivation function
+dotnet_diagnostic.CA5373.severity = warning
+
+# CA5374: Do Not Use XslTransform
+dotnet_diagnostic.CA5374.severity = warning
+
+# CA5379: Do Not Use Weak Key Derivation Function Algorithm
+dotnet_diagnostic.CA5379.severity = warning
+
+# CA5384: Do Not Use Digital Signature Algorithm (DSA)
+dotnet_diagnostic.CA5384.severity = warning
+
+# CA5385: Use Rivest�Shamir�Adleman (RSA) Algorithm With Sufficient Key Size
+dotnet_diagnostic.CA5385.severity = warning
+
+# CA5397: Do not use deprecated SslProtocols values
+dotnet_diagnostic.CA5397.severity = warning
+
+# CA1001: Types that own disposable fields should be disposable
+dotnet_diagnostic.CA1001.severity = warning
+
+# CA1309: Use ordinal string comparison
+dotnet_diagnostic.CA1309.severity = warning
+dotnet_diagnostic.CA1307.severity = warning
+dotnet_diagnostic.CA1305.severity = warning
+dotnet_diagnostic.CA1304.severity = warning
+
+# IDE0004: Remove Unnecessary Cast
+dotnet_diagnostic.IDE0004.severity = warning
+
+# IDE0005: Using directive is unnecessary.
+dotnet_diagnostic.IDE0005.severity = warning
+
+# IDE0007: Use implicit type
+dotnet_diagnostic.IDE0007.severity = warning
+
+# IDE0007: Use explicit type
+dotnet_diagnostic.IDE0008.severity = none
+
+# IDE0009: Member access should be qualified.
+dotnet_diagnostic.IDE0009.severity = warning
+
+# IDE0011: Add braces
+dotnet_diagnostic.IDE0011.severity = warning
+
+# IDE0016: Use 'throw' expression
+dotnet_diagnostic.IDE0016.severity = warning
+
+# IDE0017: Simplify object initialization
+dotnet_diagnostic.IDE0017.severity = suggestion
+
+# IDE0018: Inline variable declaration
+dotnet_diagnostic.IDE0018.severity = warning
+
+# IDE0020: Use pattern matching
+dotnet_diagnostic.IDE0020.severity = suggestion
+
+# IDE0023: Use expression body for operators
+dotnet_diagnostic.IDE0023.severity = none
+
+# IDE0024: Use expression body for operators
+dotnet_diagnostic.IDE0024.severity = none
+
+# IDE0025: Use expression body for properties
+dotnet_diagnostic.IDE0025.severity = warning
+
+# IDE0026: Use expression body for indexers
+dotnet_diagnostic.IDE0026.severity = warning
+
+# IDE0027: Use expression body for accessors
+dotnet_diagnostic.IDE0027.severity = warning
+
+# IDE0028: Simplify collection initialization
+dotnet_diagnostic.IDE0028.severity = warning
+
+# IDE0031: Use null propagation
+dotnet_diagnostic.IDE0031.severity = warning
+
+# IDE0032: Use auto property
+dotnet_diagnostic.IDE0032.severity = warning
+
+# IDE0030: Use coalesce expression
+dotnet_diagnostic.IDE0030.severity = warning
+
+# IDE0029: Use coalesce expression
+dotnet_diagnostic.IDE0029.severity = warning
+
+# IDE0034: Simplify 'default' expression
+dotnet_diagnostic.IDE0034.severity = warning
+
+# IDE0036: Order modifiers
+dotnet_diagnostic.IDE0036.severity = warning
+
+# IDE0039: Use local function
+dotnet_diagnostic.IDE0039.severity = warning
+
+# IDE0040: Add accessibility modifiers
+dotnet_diagnostic.IDE0040.severity = warning
+
+# IDE0041: Use 'is null' check
+dotnet_diagnostic.IDE0041.severity = warning
+
+# IDE0042: Deconstruct variable declaration
+dotnet_diagnostic.IDE0042.severity = none
+
+# IDE0047: Remove unnecessary parentheses
+dotnet_diagnostic.IDE0047.severity = warning
+
+# IDE0048: Add parentheses for clarity
+dotnet_diagnostic.IDE0048.severity = warning
+
+# IDE0050: Convert to tuple
+dotnet_diagnostic.IDE0050.severity = warning
+
+# IDE0051: Private member is unused
+dotnet_diagnostic.IDE0051.severity = warning
+
+# IDE0054: Use compound assignment
+dotnet_diagnostic.IDE0054.severity = warning
+
+# IDE0057: Use range operator
+dotnet_diagnostic.IDE0057.severity = suggestion
+
+# IDE0058: Expression value is never used
+dotnet_diagnostic.IDE0058.severity = none
+
+# IDE0059: Unnecessary assignment of a value
+dotnet_diagnostic.IDE0059.severity = warning
+
+# IDE0060: Remove unused parameter
+dotnet_diagnostic.IDE0060.severity = suggestion
+
+# IDE0061: Use expression body for local functions
+dotnet_diagnostic.IDE0061.severity = none
+
+# IDE0062: Make local function 'static'
+dotnet_diagnostic.IDE0062.severity = warning
+
+# IDE0065: Misplaced using directive
+dotnet_diagnostic.IDE0065.severity = warning
+
+# IDE0071: Simplify interpolation
+dotnet_diagnostic.IDE0071.severity = warning
+
+# IDE0072: Add missing cases
+dotnet_diagnostic.IDE0072.severity = suggestion
+
+# IDE0073: File header
+dotnet_diagnostic.IDE0073.severity = warning
+
+# IDE0075: Simplify conditional expression
+dotnet_diagnostic.IDE0075.severity = warning
+
+# IDE0080: Remove unnecessary suppression operator
+dotnet_diagnostic.IDE0080.severity = warning
+
+# IDE0082: 'typeof' can be converted to 'nameof'
+dotnet_diagnostic.IDE0082.severity = warning
+
+# IDE0083: Use pattern matching
+dotnet_diagnostic.IDE0083.severity = suggestion
+
+# IDE0090: 'new' expression can be simplified
+dotnet_diagnostic.IDE0083.severity = warning
+
+# IDE1005: Delegate invocation can be simplified.
+dotnet_diagnostic.IDE1005.severity = warning
+
+# IDE1006: Naming Styles
+dotnet_diagnostic.IDE1006.severity = warning
+
+# SA1602: Enumeration items should be documented
+dotnet_diagnostic.SA1602.severity = suggestion
+
+# SA1618: Generic type parameters should be documented
+dotnet_diagnostic.SA1618.severity = suggestion
+
+# SA1021: Negative signs should be spaced correctly
+dotnet_diagnostic.SA1021.severity = none
+
+# SA1402: File may only contain a single type
+dotnet_diagnostic.SA1402.severity = warning
+
+# SA1604: Element documentation should have summary
+dotnet_diagnostic.SA1604.severity = none
+
+# SA1620: Generic type parameter documentation should match type parameters
+dotnet_diagnostic.SA1620.severity = none
+
+# SA1028: Code should not contain trailing whitespace
+dotnet_diagnostic.SA1028.severity = none
+
+# SA1513: Closing brace should be followed by blank line
+dotnet_diagnostic.SA1513.severity = none
+
+# SA1012: Opening brace should be preceded by a space
+dotnet_diagnostic.SA1012.severity = none
+
+# SA1001: Commas should not be preceded by whitespace
+dotnet_diagnostic.SA1001.severity = none
+
+# SA1514: Element documentation header should be preceded by blank line
+dotnet_diagnostic.SA1514.severity = none
+
+# SA1024: Deference symbol '*' should not be followed by a space.
+dotnet_diagnostic.SA1023.severity = none
+
+dotnet_diagnostic.IDE0052.severity = warning
+dotnet_diagnostic.IDE0043.severity = warning
+dotnet_diagnostic.CA1507.severity = warning
+dotnet_diagnostic.CA1825.severity = warning
+
+dotnet_diagnostic.CA1018.severity = warning
+dotnet_diagnostic.CA1821.severity = warning
+dotnet_diagnostic.CA1827.severity = warning
+dotnet_diagnostic.CA1836.severity = warning
+dotnet_diagnostic.CA2011.severity = warning
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 5ec90ba..0937582 100644
--- a/.gitignore
+++ b/.gitignore
@@ -362,4 +362,7 @@ MigrationBackup/
.ionide/
# Fody - auto-generated XML schema
-FodyWeavers.xsd
\ No newline at end of file
+FodyWeavers.xsd
+
+# SARIF log files from jb inspectcode
+*.sarif
\ No newline at end of file
diff --git a/CommonStyle.DotSettings b/CommonStyle.DotSettings
new file mode 100644
index 0000000..9b17839
--- /dev/null
+++ b/CommonStyle.DotSettings
@@ -0,0 +1,355 @@
+
+ AutomaticProperty
+ True
+ *.g.cs
+ WARNING
+ HINT
+ WARNING
+ WARNING
+ DO_NOT_SHOW
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ HINT
+ WARNING
+ WARNING
+ WARNING
+
+ True
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ SUGGESTION
+ WARNING
+ SUGGESTION
+ SUGGESTION
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ HINT
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ HINT
+ WARNING
+ WARNING
+ WARNING
+ SUGGESTION
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ SUGGESTION
+ SUGGESTION
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ DO_NOT_SHOW
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ SUGGESTION
+ SUGGESTION
+ WARNING
+ DO_NOT_SHOW
+ DO_NOT_SHOW
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ WARNING
+ True
+ False
+ ShowAndRun
+ SUGGESTION
+ Built-in: Reformat & Apply Syntax Style
+ False
+ Required
+ Required
+ Required
+ Required
+ True
+ True
+ False
+ True
+ True
+ True
+ True
+ True
+ True
+ True
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ TOGETHER_SAME_LINE
+ True
+ 1
+ 1
+ False
+ False
+ False
+ False
+ False
+ True
+ True
+ NEVER
+ NEVER
+ NEVER
+ False
+ NEVER
+ True
+ True
+ True
+ True
+ True
+ True
+ True
+ True
+ CHOP_IF_LONG
+ CHOP_IF_LONG
+ True
+ True
+ True
+ CHOP_IF_LONG
+ 160
+ CHOP_ALWAYS
+ CHOP_IF_LONG
+ False
+ False
+ True
+ Skip
+ Skip
+ True
+ True
+ True
+ False
+ True
+ True
+ False
+ False
+ True
+ False
+ True
+ True
+ <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
+ <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" />
+ <Policy><Descriptor Staticness="Any" AccessRightKinds="Private" Description="Constant fields (private)"><ElementKinds><Kind Name="CONSTANT_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /></Policy>
+ <Policy><Descriptor Staticness="Any" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Constant fields (not private)"><ElementKinds><Kind Name="CONSTANT_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></Policy>
+ <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
+ True
+ True
+ True
+ True
+ True
+ True
+
\ No newline at end of file
diff --git a/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs b/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs
index c213314..098877e 100644
--- a/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs
+++ b/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs
@@ -1,236 +1,227 @@
using Grasshopper.Kernel;
using Grasshopper.Kernel.Parameters;
+using Objectivism.Components.Utilities;
+using Objectivism.ObjectClasses;
+using Objectivism.Parameters;
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.Linq;
using System.Windows.Forms;
-using static Objectivism.DataUtil;
-namespace Objectivism
+
+namespace Objectivism.Components
{
public class AddOrChangePropertiesComponent : GH_Component, IGH_VariableParameterComponent, IHasMultipleTypes
{
+ private readonly string _defaultNickName = "Property";
+
+ private readonly string _description =
+ "Property to change in object, or add if the property does not exist. Param nickname must correspond to name of property to change/add";
+
+ private readonly string _numbers = "1234567890";
+
+
+ private readonly HashSet _propertyNames = new HashSet();
+
///
- /// Initializes a new instance of the ChangePropertiesComponent class.
+ /// Initializes a new instance of the ChangePropertiesComponent class.
///
public AddOrChangePropertiesComponent()
- : base("Add Or Change Properties", "Add/Change",
- "Change the value of a particular property, or add a new property",
- "Sets", "Objectivism")
+ : base( "Add Or Change Properties", "Add/Change",
+ "Change the value of a particular property, or add a new property",
+ "Sets", "Objectivism" )
+ {
+ }
+
+ ///
+ /// Provides an Icon for the component.
+ ///
+ protected override Bitmap Icon => Resources.objchange;
+
+ ///
+ /// Gets the unique ID for this component. Do not change this ID after release.
+ ///
+ public override Guid ComponentGuid => new Guid( "e9a4a775-aaa2-489f-9d8e-6f8f7c1bc36b" );
+
+
+ public bool CanInsertParameter( GH_ParameterSide side, int index ) =>
+ side == GH_ParameterSide.Input && index != 0;
+
+ public bool CanRemoveParameter( GH_ParameterSide side, int index ) =>
+ side == GH_ParameterSide.Input && index != 0;
+
+ public IGH_Param CreateParameter( GH_ParameterSide side, int index )
+ => new Param_ExtraObjectProperty { Name = "PropertyToChange", Description = this._description };
+
+ public bool DestroyParameter( GH_ParameterSide side, int index ) => true;
+
+ public void VariableParameterMaintenance()
{
+ this.UpdatePropertyNames();
+ for ( var i = 1; i < this.Params.Input.Count; i++ )
+ {
+ this.Params.Input[i].Optional = true;
+ }
+
+ foreach ( var param in this.Params.Input )
+ {
+ if ( param is Param_ExtraObjectProperty extraParam )
+ {
+ extraParam.ReplaceAllPropertyNames( this._propertyNames );
+ }
+
+ if ( param.NickName == string.Empty )
+ {
+ param.NickName = this.NextUnusedName();
+ }
+ }
}
+ public HashSet TypeNames { get; } = new HashSet();
+
+ internal List GetUnusedNames() =>
+ this._propertyNames.Except( this.Params.Input.Select( p => p.NickName ).Skip( 1 ) ).ToList();
- private HashSet PropertyNames = new HashSet();
- internal List GetUnusedNames() => PropertyNames.Except(Params.Input.Select(p => p.NickName).Skip(1)).ToList();
internal string NextUnusedName()
{
- var unusedNames = GetUnusedNames();
+ // TODO: TG: Review. The use of StrippedParamNames() does not make sense to me.
+
+ var unusedNames = this.GetUnusedNames();
return unusedNames.Count == 0
- ? defaultNickName + GH_ComponentParamServer.InventUniqueNickname(numbers, StrippedParamNames())
+ ? this._defaultNickName +
+ GH_ComponentParamServer.InventUniqueNickname( this._numbers, this.StrippedParamNames() )
: unusedNames[0];
}
private void UpdatePropertyNames()
{
- PropertyNames.Clear();
- var data = this.Params.Input[0].VolatileData.AllData(true).ToList();
- foreach (var goo in data)
+ this._propertyNames.Clear();
+ var data = this.Params.Input[0].VolatileData.AllData( true ).ToList();
+ foreach ( var goo in data )
{
- if (goo is GH_ObjectivismObject ghObj)
+ if ( goo is GH_ObjectivismObject ghObj )
{
var propNames = ghObj.Value.AllProperties;
- PropertyNames.UnionWith(propNames);
+ this._propertyNames.UnionWith( propNames );
}
}
}
///
- /// Registers all the input parameters for this component.
+ /// Registers all the input parameters for this component.
///
- protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
+ protected override void RegisterInputParams( GH_InputParamManager pManager )
{
- pManager.AddGenericParameter("Object", "O", "Object to make changes to", GH_ParamAccess.item);
-
- var objParam = new Param_GenericObject();
- objParam.NickName = "O";
- objParam.Name = "Object";
- objParam.Description = "Object to modify";
- objParam.Access = GH_ParamAccess.item;
- objParam.ObjectChanged += ObjectWireChangedHandler;
+ pManager.AddGenericParameter( "Object", "O", "Object to make changes to", GH_ParamAccess.item );
+
+ var objParam = new Param_GenericObject
+ {
+ NickName = "O", Name = "Object", Description = "Object to modify", Access = GH_ParamAccess.item
+ };
+ objParam.ObjectChanged += this.ObjectWireChangedHandler;
/*
var param = new Param_ExtraObjectProperty();
param.Name = "PropertyName";
param.nickNameCache = defaultNickName + "1";
param.NickName = param.nickNameCache;
param.Description = description;
- pManager.AddParameter(param);
+ pManager.AddParameter(param);
*/
}
- private void ObjectWireChangedHandler(IGH_DocumentObject sender, GH_ObjectChangedEventArgs e)
+ private void ObjectWireChangedHandler( IGH_DocumentObject sender, GH_ObjectChangedEventArgs e )
{
- if (e.Type == GH_ObjectEventType.Sources)
+ if ( e.Type == GH_ObjectEventType.Sources )
{
this.UpdatePropertyNames();
- };
+ }
}
- private readonly string description = "Property to change in object, or add if the property does not exist. Param nickname must correspond to name of property to change/add";
///
- /// Registers all the output parameters for this component.
+ /// Registers all the output parameters for this component.
///
- protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
- {
- pManager.AddGenericParameter("Object", "O", "Modified object", GH_ParamAccess.item);
- }
+ protected override void RegisterOutputParams( GH_OutputParamManager pManager ) =>
+ pManager.AddGenericParameter( "Object", "O", "Modified object", GH_ParamAccess.item );
protected override void BeforeSolveInstance()
{
- UpdateTypeNames();
- if (!JustOneTypeName())
+ this.UpdateTypeNames();
+ if ( !this.JustOneTypeName() )
{
- this.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Mutliple types detected");
+ this.AddRuntimeMessage( GH_RuntimeMessageLevel.Remark, "Mutliple types detected" );
}
+
this.UpdatePropertyNames();
- Params.Input.ForEach(CommitParamNames);
+ this.Params.Input.ForEach( this.CommitParamNames );
base.BeforeSolveInstance();
}
- private HashSet typeNames = new HashSet();
- public HashSet TypeNames => typeNames;
-
private void UpdateTypeNames()
{
- typeNames.Clear();
- var data = this.Params.Input[0].VolatileData.AllData(true);
- foreach (var goo in data)
+ this.TypeNames.Clear();
+ var data = this.Params.Input[0].VolatileData.AllData( true );
+ foreach ( var goo in data )
{
- if (goo is GH_ObjectivismObject ghObj)
+ if ( goo is GH_ObjectivismObject ghObj )
{
var tn = ghObj.Value.TypeName;
- typeNames.Add(tn);
+ this.TypeNames.Add( tn );
}
}
}
- private bool JustOneTypeName() => typeNames.Count <= 1;
+ private bool JustOneTypeName() => this.TypeNames.Count <= 1;
- private void CommitParamNames(IGH_Param param)
+ private void CommitParamNames( IGH_Param param )
{
- if (param is Param_ExtraObjectProperty p)
+ if ( param is Param_ExtraObjectProperty p )
{
p.CommitNickName();
}
}
///
- /// This is the method that actually does the work.
+ /// This is the method that actually does the work.
///
- /// The DA object is used to retrieve from inputs and store in outputs.
- protected override void SolveInstance(IGH_DataAccess DA)
+ /// The DA object is used to retrieve from inputs and store in outputs.
+ protected override void SolveInstance( IGH_DataAccess daObject )
{
- if (!DA.TryGetObjectivsmObject(0, out var obj)) return;
-
- var updates = new List<(string Name, ObjectProperty Property)>();
-
- for (int i = 1; i < Params.Input.Count; i++)
+ if ( !daObject.TryGetObjectivsmObject( 0, out var obj ) )
{
- updates.Add(RetrieveProperties(DA, i, this));
+ return;
}
- (var newObj, var accessConflict) = obj.AddOrChangeProperties(updates);
- accessConflict.BroadcastConflicts(this);
- DA.SetData(0, new GH_ObjectivismObject(newObj));
-
- }
-
-
- public bool CanInsertParameter(GH_ParameterSide side, int index)
- {
- return side == GH_ParameterSide.Input && index != 0;
- }
-
- public bool CanRemoveParameter(GH_ParameterSide side, int index)
- {
- return side == GH_ParameterSide.Input && index != 0;
- }
- public IGH_Param CreateParameter(GH_ParameterSide side, int index)
- {
- var param = new Param_ExtraObjectProperty();
- param.Name = "PropertyToChange";
- param.nickNameCache = string.Empty;
- param.NickName = string.Empty;
- param.Description = description;
- return param;
- }
-
- public bool DestroyParameter(GH_ParameterSide side, int index)
- {
- return true;
- }
+ var updates = new List<(string Name, ObjectProperty Property)>();
- public void VariableParameterMaintenance()
- {
- this.UpdatePropertyNames();
- for (int i = 1; i < Params.Input.Count; i++)
+ for ( var i = 1; i < this.Params.Input.Count; i++ )
{
- Params.Input[i].Optional = true;
+ updates.Add( this.GetProperty( daObject, i ) );
}
- foreach (var param in Params.Input)
- {
- if (param is Param_ExtraObjectProperty extraParam)
- {
- extraParam.AllPropertyNames = this.PropertyNames;
- }
- if (param.NickName == string.Empty)
- {
- param.NickName = NextUnusedName();
- }
- }
+ var (newObj, accessConflict) = obj.AddOrChangeProperties( updates );
+ accessConflict.BroadcastConflicts( this );
+ daObject.SetData( 0, new GH_ObjectivismObject( newObj ) );
}
private List StrippedParamNames()
{
var variableParams = this.Params.Input.ToList();
return variableParams
- .Select(p => p.NickName)
- .Where(n => n.StartsWith(defaultNickName) && numbers.Contains(n.ToCharArray()[defaultNickName.Length]))
- .Select(n => n.Replace(defaultNickName, ""))
+ .Select( p => p.NickName )
+ .Where( n =>
+ n.StartsWith( this._defaultNickName ) &&
+ this._numbers.Contains( n.ToCharArray()[this._defaultNickName.Length] ) )
+ .Select( n => n.Replace( this._defaultNickName, "" ) )
.ToList();
}
- private readonly string defaultNickName = "Property";
- private readonly string numbers = "1234567890";
+ public override void AppendAdditionalMenuItems( ToolStripDropDown menu ) =>
+ Menu_AppendItem( menu, "Recompute", this.UpdateObjectEventHandler );
- public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
- {
- Menu_AppendItem(menu, "Recompute", UpdateObjectEventHandler);
- }
-
- private void UpdateObjectEventHandler(object sender, EventArgs e)
- {
- this.Params.Input.ForEach(p => p.ExpireSolution(false));
- ExpireSolution(true);
- }
-
- ///
- /// Provides an Icon for the component.
- ///
- protected override System.Drawing.Bitmap Icon
- {
- get
- {
- return Resources.objchange;
- }
- }
-
- ///
- /// Gets the unique ID for this component. Do not change this ID after release.
- ///
- public override Guid ComponentGuid
+ private void UpdateObjectEventHandler( object sender, EventArgs e )
{
- get { return new Guid("e9a4a775-aaa2-489f-9d8e-6f8f7c1bc36b"); }
+ this.Params.Input.ForEach( p => p.ExpireSolution( false ) );
+ this.ExpireSolution( true );
}
}
}
\ No newline at end of file
diff --git a/ObjectivismGH/Components/ComponentUtil/AccessChecker.cs b/ObjectivismGH/Components/ComponentUtil/AccessChecker.cs
deleted file mode 100644
index 6d237e9..0000000
--- a/ObjectivismGH/Components/ComponentUtil/AccessChecker.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using Grasshopper.Kernel;
-using System.Collections.Generic;
-namespace Objectivism
-{
- class AccessChecker
- {
- private Dictionary accessRecorder;
- private HashSet warningsToThrow;
-
- private IGH_Component hostRef;
-
- public AccessChecker(IGH_Component @this)
- {
- this.accessRecorder = new Dictionary();
- this.warningsToThrow = new HashSet();
- this.hostRef = @this;
- }
-
- public void AccessCheck(ObjectProperty prop, string name)
- {
- if (accessRecorder.ContainsKey(name))
- {
- if (accessRecorder[name] != prop.Access)
- {
- warningsToThrow.Add(name);
- }
- }
- else
- {
- accessRecorder.Add(name, prop.Access);
- }
- }
-
- public void ThrowWarnings()
- {
- foreach (var name in warningsToThrow)
- {
- hostRef.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Access not consistent for {name} property. Output data tree may be messy and not consistent");
- }
- }
-
- public PropertyAccess BestGuessAccess(string name)
- {
- if (accessRecorder.ContainsKey(name))
- {
- return accessRecorder[name];
- }
- else
- {
-
- try
- {
- var data = hostRef.Params.Input[0].VolatileData.AllData(true);
- foreach (var goo in data)
- {
- if (goo is GH_ObjectivismObject ghObj)
- {
- if (ghObj.Value.HasProperty(name))
- {
- return ghObj.Value.GetProperty(name).Access;
- }
- }
- }
- return PropertyAccess.Item;
- }
- catch
- {
- return PropertyAccess.Item;
- }
- }
- }
- }
-}
diff --git a/ObjectivismGH/Components/ComponentUtil/DataUtil.cs b/ObjectivismGH/Components/ComponentUtil/DataUtil.cs
deleted file mode 100644
index 1d67186..0000000
--- a/ObjectivismGH/Components/ComponentUtil/DataUtil.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-using Grasshopper.Kernel;
-using Grasshopper.Kernel.Data;
-using Grasshopper.Kernel.Types;
-using Objectivism.Parameters;
-using System.Collections.Generic;
-
-namespace Objectivism
-{
- static class DataUtil
- {
- internal static (string Name, ObjectProperty Property) RetrieveProperties(IGH_DataAccess DA, int paramIndex, IGH_Component @this)
- {
- bool previewOn = true;
- var param = @this.Params.Input[paramIndex];
- if (param is IHasPreviewToggle hasPreviewToggle)
- {
- previewOn = hasPreviewToggle.PreviewOn;
- }
-
- ObjectProperty prop;
- var name = param.NickName;
- if (param.Access == GH_ParamAccess.item)
- {
- IGH_Goo item = null;
- if (!DA.GetData(paramIndex, ref item))
- {
- @this.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, $"{name} has no input and has been assigned null data");
- }
- prop = new ObjectProperty(item);
- }
- else if (param.Access == GH_ParamAccess.list)
- {
- var items = new List();
- DA.GetDataList(paramIndex, items);
- prop = new ObjectProperty(items);
- }
- else //tree access
- {
- DA.GetDataTree(paramIndex, out GH_Structure itemTree);
- prop = new ObjectProperty(itemTree);
- }
- prop.PreviewOn = previewOn;
- return (name, prop);
- }
-
- internal static bool TryGetObjectivsmObject(this IGH_DataAccess DA, int paramIndex, out ObjectivismObject obj)
- {
- obj = null;
- IGH_Goo goo = null;
- if (!DA.GetData(paramIndex, ref goo)) { return false; }
- if (goo is GH_ObjectivismObject ghObj)
- {
- obj = ghObj.Value;
- return true;
- }
- return false;
- }
- }
-}
diff --git a/ObjectivismGH/Components/CreateObjectComponent.cs b/ObjectivismGH/Components/CreateObjectComponent.cs
index b480777..3637787 100644
--- a/ObjectivismGH/Components/CreateObjectComponent.cs
+++ b/ObjectivismGH/Components/CreateObjectComponent.cs
@@ -1,166 +1,147 @@
using Grasshopper.Kernel;
+using Objectivism.ObjectClasses;
+using Objectivism.Parameters;
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.Linq;
using System.Windows.Forms;
-using static Objectivism.DataUtil;
+using static Objectivism.Components.Utilities.ComponentExtensions;
-
-namespace Objectivism
+namespace Objectivism.Components
{
-
internal interface IHasMultipleTypes
{
HashSet TypeNames { get; }
}
+
public class CreateObjectComponent : GH_Component, IGH_VariableParameterComponent
{
+ private const string _myDefaultNickname = "Object";
+ private const string _defaultNickName = "Property";
+ private const string _numbers = "1234567890";
+
+ private string _nickNameCache;
public CreateObjectComponent()
- : base("Create Object", "Object",
- "Encapsulate multiple kinds of data within a single object",
- "Sets", "Objectivism")
+ : base( "Create Object", _myDefaultNickname,
+ "Encapsulate multiple kinds of data within a single object",
+ "Sets", "Objectivism" )
{
- NickNameCache = this.NickName;
+ this._nickNameCache = _myDefaultNickname;
this.IconDisplayMode = GH_IconDisplayMode.name;
- this.ObjectChanged += NickNameChangedEventHandler;
+ this.ObjectChanged += this.NickNameChangedEventHandler;
}
- private string NickNameCache;
+ protected override Bitmap Icon => Resources.objcreate;
- protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
- {
- var param1 = new Param_NewObjectProperty();
- param1.NickName = String.Empty;
- param1.Access = GH_ParamAccess.item;
- pManager.AddParameter(param1);
- var param2 = new Param_NewObjectProperty();
- param2.NickName = String.Empty;
- param2.Access = GH_ParamAccess.item;
- pManager.AddParameter(param2);
- VariableParameterMaintenance();
- }
+ public override Guid ComponentGuid => new Guid( "312f8eb3-254f-4c22-aead-7918c6cc6699" );
- protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
- {
- pManager.AddGenericParameter("Object", "O", "Object that is created", GH_ParamAccess.item);
- }
- protected override void BeforeSolveInstance()
- {
- Params.Input.ForEach(CommitParamNames);
- base.BeforeSolveInstance();
- }
+ public bool CanInsertParameter( GH_ParameterSide side, int index ) => side == GH_ParameterSide.Input;
+
+ public bool CanRemoveParameter( GH_ParameterSide side, int index ) => side == GH_ParameterSide.Input;
- private void CommitParamNames(IGH_Param param)
+ public IGH_Param CreateParameter( GH_ParameterSide side, int index )
{
- if (param is Param_NewObjectProperty p)
- {
- p.CommitNickName();
- }
+ var param = new Param_NewObjectProperty { NickName = string.Empty, Access = GH_ParamAccess.item };
+ return param;
}
+ public bool DestroyParameter( GH_ParameterSide side, int index ) => true;
- protected override void SolveInstance(IGH_DataAccess DA)
+ public void VariableParameterMaintenance()
{
- var typeName = this.NickName;
- NickNameCache = NickName;
- var data = new List<(string Name, ObjectProperty Property)>();
- for (int i = 0; i < Params.Input.Count; i++)
+ var dynamicParams = this.Params.Input.ToList();
+ foreach ( var param in dynamicParams )
{
- data.Add(RetrieveProperties(DA, i, this));
+ param.Optional = true;
}
- var obj = new ObjectivismObject(data, typeName);
- var ghObj = new GH_ObjectivismObject(obj);
- DA.SetData(0, ghObj);
- }
-
+ var emptyParams = dynamicParams.Where( p => p.NickName == string.Empty );
+ foreach ( var param in emptyParams )
+ {
+ // TODO: TG: Review. The use of StrippedParamNames() does not make sense to me.
- public bool CanInsertParameter(GH_ParameterSide side, int index)
- {
- return side == GH_ParameterSide.Input;
+ var paramKey = GH_ComponentParamServer.InventUniqueNickname( _numbers, this.StrippedParamNames() );
+ param.NickName = _defaultNickName + paramKey;
+ }
}
- public bool CanRemoveParameter(GH_ParameterSide side, int index)
+ protected override void RegisterInputParams( GH_InputParamManager pManager )
{
- return side == GH_ParameterSide.Input;
+ var param1 = new Param_NewObjectProperty { NickName = string.Empty, Access = GH_ParamAccess.item };
+ pManager.AddParameter( param1 );
+ var param2 = new Param_NewObjectProperty { NickName = string.Empty, Access = GH_ParamAccess.item };
+ pManager.AddParameter( param2 );
+ this.VariableParameterMaintenance();
}
- public IGH_Param CreateParameter(GH_ParameterSide side, int index)
- {
- var param = new Param_NewObjectProperty();
- param.NickName = String.Empty;
- param.Access = GH_ParamAccess.item;
- return param;
- }
+ protected override void RegisterOutputParams( GH_OutputParamManager pManager ) =>
+ pManager.AddGenericParameter( "Object", "O", "Object that is created", GH_ParamAccess.item );
- public bool DestroyParameter(GH_ParameterSide side, int index)
+ protected override void BeforeSolveInstance()
{
- return true;
+ this.Params.Input.ForEach( this.CommitParamNames );
+ base.BeforeSolveInstance();
}
- public void VariableParameterMaintenance()
+ private void CommitParamNames( IGH_Param param )
{
- var dynamicParams = Params.Input.ToList();
- foreach (var param in dynamicParams)
+ if ( param is Param_NewObjectProperty p )
{
- param.Optional = true;
+ p.CommitNickName();
}
- var emptyParams = dynamicParams.Where(p => p.NickName == String.Empty);
- foreach (var param in emptyParams)
+ }
+
+
+ protected override void SolveInstance( IGH_DataAccess daObject )
+ {
+ var typeName = this.NickName;
+ this._nickNameCache = this.NickName;
+ var data = new List<(string Name, ObjectProperty Property)>();
+ for ( var i = 0; i < this.Params.Input.Count; i++ )
{
- var paramKey = GH_ComponentParamServer.InventUniqueNickname(numbers, StrippedParamNames());
- param.NickName = defaultNickName + paramKey;
+ data.Add( this.GetProperty( daObject, i ) );
}
+
+ var obj = new ObjectivismObject( data, typeName );
+ var ghObj = new GH_ObjectivismObject( obj );
+ daObject.SetData( 0, ghObj );
}
private List StrippedParamNames()
{
var variableParams = this.Params.Input.ToList();
return variableParams
- .Select(p => p.NickName)
- .Where(n => n.StartsWith(defaultNickName) && numbers.Contains(n.ToCharArray()[defaultNickName.Length]))
- .Select(n => n.Replace(defaultNickName, ""))
+ .Select( p => p.NickName )
+ .Where( n =>
+ n.Length > _defaultNickName.Length
+ && char.IsDigit( n[_defaultNickName.Length] )
+ && n.StartsWith( _defaultNickName, StringComparison.Ordinal ) )
+ .Select( n => n.Substring( _defaultNickName.Length ) )
.ToList();
}
- private readonly string defaultNickName = "Property";
- private readonly string numbers = "1234567890";
-
- public void NickNameChangedEventHandler(object sender, GH_ObjectChangedEventArgs args)
+ public void NickNameChangedEventHandler( object sender, GH_ObjectChangedEventArgs args )
{
- if (args.Type == GH_ObjectEventType.NickName)
+ if ( args.Type == GH_ObjectEventType.NickName )
{
- if (NickName != NickNameCache)
+ if ( this.NickName != this._nickNameCache )
{
- this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Type name (component nickname) changed but object not updated, right click on component and press \"Recompute\"");
+ this.AddRuntimeMessage( GH_RuntimeMessageLevel.Warning,
+ "Type name (component nickname) changed but object not updated, right click on component and press \"Recompute\"" );
}
}
}
- public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
- {
- Menu_AppendItem(menu, "Recompute", UpdateObjectEventHandler);
- }
-
- private void UpdateObjectEventHandler(object sender, EventArgs e)
- {
- this.Params.Input.ForEach(p => p.ExpireSolution(false));
- ExpireSolution(true);
- }
-
- protected override System.Drawing.Bitmap Icon
- {
- get
- {
- return Resources.objcreate;
- }
- }
+ public override void AppendAdditionalMenuItems( ToolStripDropDown menu ) =>
+ Menu_AppendItem( menu, "Recompute", this.UpdateObjectEventHandler );
- public override Guid ComponentGuid
+ private void UpdateObjectEventHandler( object sender, EventArgs e )
{
- get { return new Guid("312f8eb3-254f-4c22-aead-7918c6cc6699"); }
+ this.Params.Input.ForEach( p => p.ExpireSolution( false ) );
+ this.ExpireSolution( true );
}
}
-}
+}
\ No newline at end of file
diff --git a/ObjectivismGH/Components/FilterByType.cs b/ObjectivismGH/Components/FilterByType.cs
index 3473c9a..4278dbd 100644
--- a/ObjectivismGH/Components/FilterByType.cs
+++ b/ObjectivismGH/Components/FilterByType.cs
@@ -1,201 +1,164 @@
using Grasshopper.Kernel;
-using Grasshopper.Kernel.Parameters;
using Grasshopper.Kernel.Types;
+using Objectivism.ObjectClasses;
+using Objectivism.Parameters;
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace Objectivism.Components
{
- public class FilterByTypeOBSOLETE : GH_Component, IGH_VariableParameterComponent
+ [Obsolete( "Obsolete", true )]
+ public class FilterByType : GH_Component, IGH_VariableParameterComponent
{
+ private readonly HashSet _typeNames = new HashSet();
+
///
- /// Initializes a new instance of the FilterByType class.
+ /// Initializes a new instance of the FilterByType class.
///
- public FilterByTypeOBSOLETE()
- : base("Filter By Type Old", "Filter",
- "Filter objects by their type name",
- "Sets", "Objectivism")
+ public FilterByType()
+ : base( "Filter By Type Old", "Filter",
+ "Filter objects by their type name",
+ "Sets", "Objectivism" )
{
-
}
+
public override bool Obsolete => true;
public override GH_Exposure Exposure => GH_Exposure.hidden;
- private HashSet TypeNames = new HashSet();
- internal List GetUnusedNames() => TypeNames.Except(Params.Output.Select(p => p.NickName)).ToList();
+ ///
+ /// Provides an Icon for the component.
+ ///
+ protected override Bitmap Icon => Resources.GroupByType;
+
+ ///
+ /// Gets the unique ID for this component. Do not change this ID after release.
+ ///
+ public override Guid ComponentGuid => new Guid( "615e81f0-484b-4b43-91c4-1f0a211c200c" );
+
+ public bool CanInsertParameter( GH_ParameterSide side, int index ) => side == GH_ParameterSide.Output;
+
+ public bool CanRemoveParameter( GH_ParameterSide side, int index ) => side == GH_ParameterSide.Output;
+
+ public IGH_Param CreateParameter( GH_ParameterSide side, int index ) => new Param_ObjectivismObjectTypeOutput();
+
+ public bool DestroyParameter( GH_ParameterSide side, int index ) => true;
+
+ public void VariableParameterMaintenance()
+ {
+ foreach ( var param in this.Params.Output )
+ {
+ if ( param.NickName == string.Empty )
+ {
+ param.NickName = this.NextUnusedName();
+ }
+
+ if ( param is Param_ObjectivismObjectTypeOutput outputParam )
+ {
+ outputParam.ReplaceAllPropertyNames( this._typeNames );
+ }
+ }
+ }
+
+ internal List GetUnusedNames() =>
+ this._typeNames.Except( this.Params.Output.Select( p => p.NickName ) ).ToList();
+
internal string NextUnusedName()
{
- var unusedNames = GetUnusedNames();
+ var unusedNames = this.GetUnusedNames();
return unusedNames.Count == 0
? "No properties to list"
: unusedNames[0];
-
}
///
- /// Registers all the input parameters for this component.
+ /// Registers all the input parameters for this component.
///
- protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
- {
- pManager.AddGenericParameter("Object", "O", "Objectivism object to turn into tree", GH_ParamAccess.item);
- }
+ protected override void RegisterInputParams( GH_InputParamManager pManager ) =>
+ pManager.AddGenericParameter( "Object", "O", "Objectivism object to turn into tree", GH_ParamAccess.item );
///
- /// Registers all the output parameters for this component.
+ /// Registers all the output parameters for this component.
///
- protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
+ protected override void RegisterOutputParams( GH_OutputParamManager pManager )
{
-
- }
-
-
- private HashSet GetTypeNames()
- {
- var input = (Param_GenericObject)this.Params.Input[0];
- var objs = input.PersistentDataCount != 0
- ? input.PersistentData.WhereIsType().ToList()
- : input.VolatileData.AllData(false).WhereIsType().ToList();
- var inputNames = new HashSet(objs.Select(obj => obj.Value.TypeName));
- return inputNames;
}
protected override void BeforeSolveInstance()
{
- this.TypeNames.Clear();
+ this._typeNames.Clear();
base.BeforeSolveInstance();
}
///
- /// This is the method that actually does the work.
+ /// This is the method that actually does the work.
///
- /// The DA object is used to retrieve from inputs and store in outputs.
- protected override void SolveInstance(IGH_DataAccess DA)
+ /// The DA object is used to retrieve from inputs and store in outputs.
+ protected override void SolveInstance( IGH_DataAccess daObject )
{
IGH_Goo goo = null;
- if (!DA.GetData(0, ref goo))
+ if ( !daObject.GetData( 0, ref goo ) )
{
return;
}
+
GH_ObjectivismObject obj;
- if (goo is GH_ObjectivismObject ghObj)
+ if ( goo is GH_ObjectivismObject ghObj )
{
obj = ghObj;
}
else
{
- this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Can only filter ojects built with Objectivism");
+ this.AddRuntimeMessage( GH_RuntimeMessageLevel.Error, "Can only filter ojects built with Objectivism" );
return;
}
- TypeNames.Add(obj.Value.TypeName);
- foreach ((int i, var param) in Params.Output.Enumerate())
+ this._typeNames.Add( obj.Value.TypeName );
+
+ foreach ( var (i, param) in this.Params.Output.Enumerate() )
{
- string name = param.NickName;
- if (obj.Value.TypeName == name)
- {
- DA.SetData(i, obj);
- }
- else
- {
- DA.SetData(i, null);
- }
+ var name = param.NickName;
+ daObject.SetData( i, obj.Value.TypeName == name ? obj : null );
}
}
protected override void AfterSolveInstance()
{
- VariableParameterMaintenance();
- foreach (var p in Params.Output)
+ this.VariableParameterMaintenance();
+ foreach ( var p in this.Params.Output )
{
- if (p is Param_ObjectivismObjectTypeOutput o)
+ if ( p is Param_ObjectivismObjectTypeOutput o )
{
o.CommitNickName();
}
}
- base.AfterSolveInstance();
- }
-
- public bool CanInsertParameter(GH_ParameterSide side, int index)
- {
- return side == GH_ParameterSide.Output;
- }
- public bool CanRemoveParameter(GH_ParameterSide side, int index)
- {
- return side == GH_ParameterSide.Output;
- }
-
- public IGH_Param CreateParameter(GH_ParameterSide side, int index)
- {
- return new Param_ObjectivismObjectTypeOutput();
- }
-
- public bool DestroyParameter(GH_ParameterSide side, int index)
- {
- return true;
- }
-
- public void VariableParameterMaintenance()
- {
- foreach (var param in Params.Output)
- {
- if (param.NickName == string.Empty)
- {
- param.NickName = NextUnusedName();
- }
- if (param is Param_ObjectivismObjectTypeOutput outputParam)
- {
- outputParam.AllPropertyNames = this.TypeNames;
- }
- }
+ base.AfterSolveInstance();
}
- public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
+ public override void AppendAdditionalMenuItems( ToolStripDropDown menu )
{
- Menu_AppendSeparator(menu);
- Menu_AppendItem(menu, "Get All Types", GetAllTypesEventHandler);
+ Menu_AppendSeparator( menu );
+ Menu_AppendItem( menu, "Get All Types", this.GetAllTypesEventHandler );
}
- private void GetAllTypesEventHandler(object sender, EventArgs e)
+ private void GetAllTypesEventHandler( object sender, EventArgs e )
{
- RecordUndoEvent("GetAllTypes");
- var unusedNames = GetUnusedNames();
- foreach (var name in unusedNames)
+ this.RecordUndoEvent( "GetAllTypes" );
+ var unusedNames = this.GetUnusedNames();
+ for ( var i = 0; i < unusedNames.Count; ++i )
{
var param = new Param_ObjectivismObjectTypeOutput();
- Params.RegisterOutputParam(param);
- param.ExpireSolution(false);
+ this.Params.RegisterOutputParam( param );
+ param.ExpireSolution( false );
}
- VariableParameterMaintenance();
- Params.OnParametersChanged();
- ExpireSolution(true);
- }
- private void UpdateObjectEventHandler(object sender, EventArgs e)
- {
- ExpireSolution(true);
- }
-
- ///
- /// Provides an Icon for the component.
- ///
- protected override System.Drawing.Bitmap Icon
- {
- get
- {
- return Resources.GroupByType;
- }
- }
-
- ///
- /// Gets the unique ID for this component. Do not change this ID after release.
- ///
- public override Guid ComponentGuid
- {
- get { return new Guid("615e81f0-484b-4b43-91c4-1f0a211c200c"); }
+ this.VariableParameterMaintenance();
+ this.Params.OnParametersChanged();
+ this.ExpireSolution( true );
}
}
}
\ No newline at end of file
diff --git a/ObjectivismGH/Components/FilterByTypeV2.cs b/ObjectivismGH/Components/FilterByTypeV2.cs
index b93411f..7720555 100644
--- a/ObjectivismGH/Components/FilterByTypeV2.cs
+++ b/ObjectivismGH/Components/FilterByTypeV2.cs
@@ -1,8 +1,11 @@
using Grasshopper.Kernel;
using Grasshopper.Kernel.Parameters;
using Grasshopper.Kernel.Types;
+using Objectivism.ObjectClasses;
+using Objectivism.Parameters;
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.Linq;
using System.Windows.Forms;
@@ -11,53 +14,87 @@ namespace Objectivism.Components
public class FilterByTypeV2 : GH_Component, IGH_VariableParameterComponent, IHasMultipleTypes
{
///
- /// Initializes a new instance of the FilterByType class.
+ /// Initializes a new instance of the FilterByType class.
///
public FilterByTypeV2()
- : base("Filter By Type", "Filter",
- "Filter objects by their type name",
- "Sets", "Objectivism")
+ : base( "Filter By Type", "Filter",
+ "Filter objects by their type name",
+ "Sets", "Objectivism" )
{
}
- public HashSet TypeNames { get; private set; } = new HashSet();
- internal List GetUnusedNames() => TypeNames.Except(Params.Output.Select(p => p.NickName)).ToList();
+ ///
+ /// Provides an Icon for the component.
+ ///
+ protected override Bitmap Icon => Resources.GroupByType;
+
+ ///
+ /// Gets the unique ID for this component. Do not change this ID after release.
+ ///
+ public override Guid ComponentGuid => new Guid( "91ecf9aa-50ba-4bf4-bd3e-70066350458e" );
+
+ public bool CanInsertParameter( GH_ParameterSide side, int index ) => side == GH_ParameterSide.Output;
+
+ public bool CanRemoveParameter( GH_ParameterSide side, int index ) => side == GH_ParameterSide.Output;
+
+ public IGH_Param CreateParameter( GH_ParameterSide side, int index ) => new Param_ObjectivismObjectTypeOutput();
+
+ public bool DestroyParameter( GH_ParameterSide side, int index ) => true;
+
+ public void VariableParameterMaintenance()
+ {
+ foreach ( var param in this.Params.Output )
+ {
+ if ( param.NickName == string.Empty )
+ {
+ param.NickName = this.NextUnusedName();
+ }
+
+ if ( param is Param_ObjectivismObjectTypeOutput outputParam )
+ {
+ outputParam.ReplaceAllPropertyNames( this.TypeNames );
+ }
+ }
+ }
+
+ public HashSet TypeNames { get; } = new HashSet();
+
+ internal List GetUnusedNames() =>
+ this.TypeNames.Except( this.Params.Output.Select( p => p.NickName ) ).ToList();
+
internal string NextUnusedName()
{
- var unusedNames = GetUnusedNames();
+ var unusedNames = this.GetUnusedNames();
return unusedNames.Count == 0
? "No properties to list"
: unusedNames[0];
-
}
///
- /// Registers all the input parameters for this component.
+ /// Registers all the input parameters for this component.
///
- protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
+ protected override void RegisterInputParams( GH_InputParamManager pManager )
{
- pManager.AddGenericParameter("Object", "O", "Objectivism object to turn into tree", GH_ParamAccess.item);
- var inp = (Param_GenericObject)this.Params.Input[0];
+ pManager.AddGenericParameter( "Object", "O", "Objectivism object to turn into tree", GH_ParamAccess.item );
+ var inp = (Param_GenericObject) this.Params.Input[0];
inp.DataMapping = GH_DataMapping.Graft;
-
}
///
- /// Registers all the output parameters for this component.
+ /// Registers all the output parameters for this component.
///
- protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
+ protected override void RegisterOutputParams( GH_OutputParamManager pManager )
{
-
}
-
+ // TODO: Appears to be unused. Remove?
private HashSet GetTypeNames()
{
- var input = (Param_GenericObject)this.Params.Input[0];
+ var input = (Param_GenericObject) this.Params.Input[0];
var objs = input.PersistentDataCount != 0
? input.PersistentData.WhereIsType().ToList()
- : input.VolatileData.AllData(false).WhereIsType().ToList();
- var inputNames = new HashSet(objs.Select(obj => obj.Value.TypeName));
+ : input.VolatileData.AllData( false ).WhereIsType().ToList();
+ var inputNames = new HashSet( objs.Select( obj => obj.Value.TypeName ) );
return inputNames;
}
@@ -68,135 +105,77 @@ protected override void BeforeSolveInstance()
}
///
- /// This is the method that actually does the work.
+ /// This is the method that actually does the work.
///
- /// The DA object is used to retrieve from inputs and store in outputs.
- protected override void SolveInstance(IGH_DataAccess DA)
+ /// The DA object is used to retrieve from inputs and store in outputs.
+ protected override void SolveInstance( IGH_DataAccess daObject )
{
IGH_Goo goo = null;
- if (!DA.GetData(0, ref goo))
+ if ( !daObject.GetData( 0, ref goo ) )
{
return;
}
+
GH_ObjectivismObject obj;
- if (goo is GH_ObjectivismObject ghObj)
+ if ( goo is GH_ObjectivismObject ghObj )
{
obj = ghObj;
}
else
{
- this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Can only filter ojects built with Objectivism");
+ this.AddRuntimeMessage( GH_RuntimeMessageLevel.Error, "Can only filter ojects built with Objectivism" );
return;
}
- TypeNames.Add(obj.Value.TypeName);
- foreach ((int i, var param) in Params.Output.Enumerate())
+ this.TypeNames.Add( obj.Value.TypeName );
+
+ foreach ( var (i, param) in this.Params.Output.Enumerate() )
{
- string name = param.NickName;
- if (obj.Value.TypeName == name)
- {
- DA.SetData(i, obj);
- }
- else
+ var name = param.NickName;
+ if ( obj.Value.TypeName == name )
{
- //DA.SetData(i, null);
+ daObject.SetData( i, obj );
}
+ //DA.SetData(i, null);
}
}
protected override void AfterSolveInstance()
{
- VariableParameterMaintenance();
- foreach (var p in Params.Output)
+ this.VariableParameterMaintenance();
+ foreach ( var p in this.Params.Output )
{
- if (p is Param_ObjectivismObjectTypeOutput o)
+ if ( p is Param_ObjectivismObjectTypeOutput o )
{
o.CommitNickName();
}
}
- base.AfterSolveInstance();
- }
-
- public bool CanInsertParameter(GH_ParameterSide side, int index)
- {
- return side == GH_ParameterSide.Output;
- }
- public bool CanRemoveParameter(GH_ParameterSide side, int index)
- {
- return side == GH_ParameterSide.Output;
+ base.AfterSolveInstance();
}
- public IGH_Param CreateParameter(GH_ParameterSide side, int index)
+ public override void AppendAdditionalMenuItems( ToolStripDropDown menu )
{
- return new Param_ObjectivismObjectTypeOutput();
+ Menu_AppendSeparator( menu );
+ Menu_AppendItem( menu, "Get All Types", this.GetAllTypesEventHandler );
}
- public bool DestroyParameter(GH_ParameterSide side, int index)
- {
- return true;
- }
- public void VariableParameterMaintenance()
+ private void GetAllTypesEventHandler( object sender, EventArgs e )
{
- foreach (var param in Params.Output)
- {
- if (param.NickName == string.Empty)
- {
- param.NickName = NextUnusedName();
- }
- if (param is Param_ObjectivismObjectTypeOutput outputParam)
- {
- outputParam.AllPropertyNames = this.TypeNames;
- }
- }
- }
-
- public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
- {
- Menu_AppendSeparator(menu);
- Menu_AppendItem(menu, "Get All Types", GetAllTypesEventHandler);
- }
+ this.RecordUndoEvent( "GetAllTypes" );
+ var unusedNames = this.GetUnusedNames();
-
- private void GetAllTypesEventHandler(object sender, EventArgs e)
- {
- RecordUndoEvent("GetAllTypes");
- var unusedNames = GetUnusedNames();
- foreach (var name in unusedNames)
+ for ( var i = 0; i < unusedNames.Count; ++i )
{
var param = new Param_ObjectivismObjectTypeOutput();
- Params.RegisterOutputParam(param);
- param.ExpireSolution(false);
+ this.Params.RegisterOutputParam( param );
+ param.ExpireSolution( false );
}
- VariableParameterMaintenance();
- Params.OnParametersChanged();
- ExpireSolution(true);
- }
- private void UpdateObjectEventHandler(object sender, EventArgs e)
- {
- //ExpireSolution(true);
+ this.VariableParameterMaintenance();
+ this.Params.OnParametersChanged();
+ this.ExpireSolution( true );
}
-
- ///
- /// Provides an Icon for the component.
- ///
- protected override System.Drawing.Bitmap Icon
- {
- get
- {
- return Resources.GroupByType;
- }
- }
-
- ///
- /// Gets the unique ID for this component. Do not change this ID after release.
- ///
- public override Guid ComponentGuid
- {
- get { return new Guid("91ecf9aa-50ba-4bf4-bd3e-70066350458e"); }
- }
-
}
}
\ No newline at end of file
diff --git a/ObjectivismGH/Components/GetPropertiesComponent.cs b/ObjectivismGH/Components/GetPropertiesComponent.cs
index b24cecd..42d3866 100644
--- a/ObjectivismGH/Components/GetPropertiesComponent.cs
+++ b/ObjectivismGH/Components/GetPropertiesComponent.cs
@@ -3,350 +3,333 @@
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Parameters;
using Grasshopper.Kernel.Types;
+using Objectivism.Components.Utilities;
+using Objectivism.ObjectClasses;
+using Objectivism.Parameters;
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.Linq;
using System.Windows.Forms;
-namespace Objectivism
+namespace Objectivism.Components
{
public class GetPropertiesComponent : GH_Component, IGH_VariableParameterComponent, IHasMultipleTypes
{
+ private readonly HashSet _propertyNames = new HashSet();
+ private AccessChecker _accessChecker;
+ private bool _graftItems;
+
///
- /// Initializes a new instance of the GetPropertiesComponent class.
+ /// Initializes a new instance of the GetPropertiesComponent class.
///
public GetPropertiesComponent()
- : base("Get Object Properties", "Object.",
- "Retrieve stored properties of an Objectivism object",
- "Sets", "Objectivism")
+ : base( "Get Object Properties", "Object.",
+ "Retrieve stored properties of an Objectivism object",
+ "Sets", "Objectivism" )
{
this.IconDisplayMode = GH_IconDisplayMode.name;
- this.Message = getGraftMessage();
+ this.Message = this.GetGraftMessage();
+ }
+
+ ///
+ /// Provides an Icon for the component.
+ ///
+ protected override Bitmap Icon => Resources.objexplode;
+
+ ///
+ /// Gets the unique ID for this component. Do not change this ID after release.
+ ///
+ public override Guid ComponentGuid => new Guid( "9605357b-fad0-4c44-8dda-1cd9ba685fbc" );
+
+ public bool CanInsertParameter( GH_ParameterSide side, int index ) => side == GH_ParameterSide.Output;
+
+ public bool CanRemoveParameter( GH_ParameterSide side, int index ) => side == GH_ParameterSide.Output;
+
+ public IGH_Param CreateParameter( GH_ParameterSide side, int index ) => new Param_ObjectivismOutput();
+
+ public bool DestroyParameter( GH_ParameterSide side, int index ) => true;
+
+ public void VariableParameterMaintenance()
+ {
+ foreach ( var param in this.Params.Output )
+ {
+ if ( param.NickName == string.Empty )
+ {
+ param.NickName = this.NextUnusedName();
+ }
+
+ if ( param is Param_ObjectivismOutput outputParam )
+ {
+ outputParam.ReplaceAllPropertyNames( this._propertyNames );
+ }
+ }
}
- private bool GraftItems = false;
- private string getGraftMessage() => GraftItems
- ? "Graft all properties"
- : "Graft lists + trees";
- private HashSet PropertyNames = new HashSet();
- internal List GetUnusedNames() => PropertyNames.Except(Params.Output.Select(p => p.NickName)).ToList();
+
+ public HashSet TypeNames { get; } = new HashSet();
+
+ private string GetGraftMessage() =>
+ this._graftItems
+ ? "Graft all properties"
+ : "Graft lists + trees";
+
+ internal List GetUnusedNames() =>
+ this._propertyNames.Except( this.Params.Output.Select( p => p.NickName ) ).ToList();
+
internal string NextUnusedName()
{
- var unusedNames = GetUnusedNames();
+ var unusedNames = this.GetUnusedNames();
return unusedNames.Count == 0
? "No properties to list"
: unusedNames[0];
-
}
+
///
- /// Registers all the input parameters for this component.
+ /// Registers all the input parameters for this component.
///
- protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
- {
- pManager.AddGenericParameter("Object", "O", "Objectivism object to retrieve properties from", GH_ParamAccess.item);
- }
+ protected override void RegisterInputParams( GH_InputParamManager pManager ) =>
+ pManager.AddGenericParameter( "Object", "O", "Objectivism object to retrieve properties from",
+ GH_ParamAccess.item );
///
- /// Registers all the output parameters for this component.
+ /// Registers all the output parameters for this component.
///
- protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
+ protected override void RegisterOutputParams( GH_OutputParamManager pManager )
{
}
protected override void BeforeSolveInstance()
{
- UpdateTypeNames();
- if (!JustOneTypeName())
+ this.UpdateTypeNames();
+ if ( !this.JustOneTypeName() )
{
this.NickName = "MultipleTypes.";
}
else
{
- this.NickName = GetTypeName() + ".";
+ this.NickName = this.GetTypeName() + ".";
}
- this.PropertyNames.Clear();
- accessChecker = new AccessChecker(this);
+
+ this._propertyNames.Clear();
+ this._accessChecker = new AccessChecker( this );
base.BeforeSolveInstance();
}
- private AccessChecker accessChecker;
-
- private HashSet typeNames = new HashSet();
- public HashSet TypeNames => typeNames;
-
private void UpdateTypeNames()
{
- typeNames.Clear();
- var data = this.Params.Input[0].VolatileData.AllData(true);
- foreach (var goo in data)
+ this.TypeNames.Clear();
+ var data = this.Params.Input[0].VolatileData.AllData( true );
+ foreach ( var goo in data )
{
- if (goo is GH_ObjectivismObject ghObj)
+ if ( goo is GH_ObjectivismObject ghObj )
{
var tn = ghObj.Value.TypeName;
- typeNames.Add(tn);
+ this.TypeNames.Add( tn );
}
}
}
- private bool JustOneTypeName() => typeNames.Count <= 1;
+ private bool JustOneTypeName() => this.TypeNames.Count <= 1;
private string GetTypeName()
{
- var input = (Param_GenericObject)this.Params.Input[0];
+ var input = (Param_GenericObject) this.Params.Input[0];
var allObjects = input.PersistentDataCount != 0
? input.PersistentData
: input.VolatileData;
- if (!allObjects.IsEmpty)
+ if ( !allObjects.IsEmpty )
{
- if (allObjects is GH_Structure tree)
+ if ( allObjects is GH_Structure tree )
{
- var first = tree.get_FirstItem(true);
- if (first != null)
+ var first = tree.get_FirstItem( true );
+ if ( first != null )
{
- if (first is GH_ObjectivismObject obj)
+ if ( first is GH_ObjectivismObject obj )
{
return obj.Value.TypeName;
}
}
}
}
+
return "NoValidType";
}
-
-
///
- /// This is the method that actually does the work.
+ /// This is the method that actually does the work.
///
- /// The DA object is used to retrieve from inputs and store in outputs.
- protected override void SolveInstance(IGH_DataAccess DA)
+ /// The DA object is used to retrieve from inputs and store in outputs.
+ protected override void SolveInstance( IGH_DataAccess daObject )
{
-
IGH_Goo goo = null;
- if (!DA.GetData(0, ref goo))
+ if ( !daObject.GetData( 0, ref goo ) )
{
return;
}
+
ObjectivismObject obj;
- if (goo is GH_ObjectivismObject ghObj)
+ if ( goo is GH_ObjectivismObject ghObj )
{
obj = ghObj.Value;
}
else
{
- this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Can only get properties from ojects built with Objectivism");
+ this.AddRuntimeMessage( GH_RuntimeMessageLevel.Error,
+ "Can only get properties from ojects built with Objectivism" );
return;
}
- PropertyNames.UnionWith(obj.AllProperties);
+ this._propertyNames.UnionWith( obj.AllProperties );
- foreach ((int i, var param) in Params.Output.Enumerate())
+ foreach ( var (i, param) in this.Params.Output.Enumerate() )
{
-
- string name = param.NickName;
-
+ var name = param.NickName;
- var prop = obj.GetProperty(name);
+ var prop = obj.GetProperty( name );
PropertyAccess access;
- if (prop != null)
+ if ( prop != null )
{
access = prop.Access;
- accessChecker.AccessCheck(prop, name);
+ this._accessChecker.AccessCheck( prop, name );
}
else
{
- access = accessChecker.BestGuessAccess(name);
+ access = this._accessChecker.BestGuessAccess( name );
}
-
- if (access == PropertyAccess.Item)
+ if ( access == PropertyAccess.Item )
{
- var item = prop != null
- ? prop.Data.get_FirstItem(false)
- : null;
- var path = DA.ParameterTargetPath(i);
- if (GraftItems)
+ var item = prop?.Data.get_FirstItem( false );
+ var path = daObject.ParameterTargetPath( i );
+ if ( this._graftItems )
{
- int[] index = { DA.ParameterTargetIndex(0) };
- var newPath = new GH_Path(path.Indices.Concat(index).ToArray());
+ int[] index = { daObject.ParameterTargetIndex( 0 ) };
+ var newPath = new GH_Path( path.Indices.Concat( index ).ToArray() );
var tree = new GH_Structure();
- tree.Append(item, newPath);
- DA.SetDataTree(i, tree);
+ tree.Append( item, newPath );
+ daObject.SetDataTree( i, tree );
}
else
{
var tree = new GH_Structure();
- tree.Append(item, path);
- DA.SetDataTree(i, tree);
+ tree.Append( item, path );
+ daObject.SetDataTree( i, tree );
}
-
}
- if (access == PropertyAccess.List)
+
+ if ( access == PropertyAccess.List )
{
var list = prop != null
? prop.Data.Branches[0]
: new List();
- var path = DA.ParameterTargetPath(i);
- int[] index = { DA.ParameterTargetIndex(0) };
- var newPath = new GH_Path(path.Indices.Concat(index).ToArray());
+ var path = daObject.ParameterTargetPath( i );
+ int[] index = { daObject.ParameterTargetIndex( 0 ) };
+ var newPath = new GH_Path( path.Indices.Concat( index ).ToArray() );
var tree = new GH_Structure();
- tree.AppendRange(list, newPath);
- DA.SetDataTree(i, tree);
+ tree.AppendRange( list, newPath );
+ daObject.SetDataTree( i, tree );
}
- if (access == PropertyAccess.Tree)
+
+ if ( access == PropertyAccess.Tree )
{
var tree = prop != null
? prop.Data
: Util.EmptyTree;
- var basePath = DA.ParameterTargetPath(i);
+ var basePath = daObject.ParameterTargetPath( i );
var outTree = new GH_Structure();
- for (int j = 0; j < tree.PathCount; j++)
+ for ( var j = 0; j < tree.PathCount; j++ )
{
var branch = tree.Branches[j];
var path = tree.Paths[j];
- int[] index = { DA.ParameterTargetIndex(0) };
+ int[] index = { daObject.ParameterTargetIndex( 0 ) };
var newPathIndices = basePath.Indices
- .Concat(index)
- .Concat(path.Indices)
+ .Concat( index )
+ .Concat( path.Indices )
.ToArray();
- var newPath = new GH_Path(newPathIndices);
- outTree.AppendRange(branch, newPath);
+ var newPath = new GH_Path( newPathIndices );
+ outTree.AppendRange( branch, newPath );
}
- DA.SetDataTree(i, outTree);
+
+ daObject.SetDataTree( i, outTree );
}
}
}
-
protected override void AfterSolveInstance()
{
- VariableParameterMaintenance();
- foreach (var p in Params.Output)
+ this.VariableParameterMaintenance();
+ foreach ( var p in this.Params.Output )
{
- if (p is Param_ObjectivismOutput o)
+ if ( p is Param_ObjectivismOutput o )
{
o.CommitNickName();
}
}
- accessChecker.ThrowWarnings();
- base.AfterSolveInstance();
- }
- public bool CanInsertParameter(GH_ParameterSide side, int index)
- {
- return side == GH_ParameterSide.Output;
- }
-
- public bool CanRemoveParameter(GH_ParameterSide side, int index)
- {
- return side == GH_ParameterSide.Output;
- }
-
- public IGH_Param CreateParameter(GH_ParameterSide side, int index)
- {
- return new Param_ObjectivismOutput();
- }
-
- public bool DestroyParameter(GH_ParameterSide side, int index)
- {
- return true;
- }
-
- public void VariableParameterMaintenance()
- {
- foreach (var param in Params.Output)
- {
- if (param.NickName == string.Empty)
- {
- param.NickName = NextUnusedName();
- }
- if (param is Param_ObjectivismOutput outputParam)
- {
- outputParam.AllPropertyNames = this.PropertyNames;
- }
- }
+ this._accessChecker.ThrowWarnings();
+ base.AfterSolveInstance();
}
- public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
+ public override void AppendAdditionalMenuItems( ToolStripDropDown menu )
{
- Menu_AppendSeparator(menu);
- Menu_AppendItem(menu, "Recompute", UpdateObjectEventHandler);
- Menu_AppendItem(menu, "Full Explode", FullExplodeEventHandler);
- Menu_AppendItem(menu, "Graft all properties", DoNotGraftItemsEventHandler, true, GraftItems);
+ Menu_AppendSeparator( menu );
+ Menu_AppendItem( menu, "Recompute", this.UpdateObjectEventHandler );
+ Menu_AppendItem( menu, "Full Explode", this.FullExplodeEventHandler );
+ Menu_AppendItem( menu, "Graft all properties", this.DoNotGraftItemsEventHandler, true, this._graftItems );
}
- private void DoNotGraftItemsEventHandler(object sender, EventArgs e)
+ private void DoNotGraftItemsEventHandler( object sender, EventArgs e )
{
- RecordUndoEvent("Get object properties graft mode");
- GraftItems = !GraftItems;
- this.Message = getGraftMessage();
- ExpireSolution(true);
-
+ this.RecordUndoEvent( "Get object properties graft mode" );
+ this._graftItems = !this._graftItems;
+ this.Message = this.GetGraftMessage();
+ this.ExpireSolution( true );
}
- private void FullExplodeEventHandler(object sender, EventArgs e)
+ private void FullExplodeEventHandler( object sender, EventArgs e )
{
- RecordUndoEvent("Object full explode");
- var unusedNames = GetUnusedNames();
- foreach (var name in unusedNames)
+ this.RecordUndoEvent( "Object full explode" );
+ var unusedNames = this.GetUnusedNames();
+ for ( var i = 0; i < unusedNames.Count; ++i )
{
var param = new Param_ObjectivismOutput();
- Params.RegisterOutputParam(param);
- param.ExpireSolution(false);
+ this.Params.RegisterOutputParam( param );
+ param.ExpireSolution( false );
}
- VariableParameterMaintenance();
- Params.OnParametersChanged();
- ExpireSolution(true);
- }
- private void UpdateObjectEventHandler(object sender, EventArgs e)
- {
- ExpireSolution(true);
+ this.VariableParameterMaintenance();
+ this.Params.OnParametersChanged();
+ this.ExpireSolution( true );
}
- ///
- /// Provides an Icon for the component.
- ///
- protected override System.Drawing.Bitmap Icon
- {
- get
- {
- return Resources.objexplode;
- }
- }
-
- ///
- /// Gets the unique ID for this component. Do not change this ID after release.
- ///
- public override Guid ComponentGuid
- {
- get { return new Guid("9605357b-fad0-4c44-8dda-1cd9ba685fbc"); }
- }
+ private void UpdateObjectEventHandler( object sender, EventArgs e ) => this.ExpireSolution( true );
- public override bool Read(GH_IReader reader)
+ public override bool Read( GH_IReader reader )
{
try
{
- GraftItems = reader.GetBoolean("GraftItemsToggle");
- Message = getGraftMessage();
+ this._graftItems = reader.GetBoolean( "GraftItemsToggle" );
+ this.Message = this.GetGraftMessage();
}
catch
{
- GraftItems = true;
- Message = getGraftMessage();
+ this._graftItems = true;
+ this.Message = this.GetGraftMessage();
}
- return base.Read(reader);
+ return base.Read( reader );
}
- public override bool Write(GH_IWriter writer)
+
+ public override bool Write( GH_IWriter writer )
{
- writer.SetBoolean("GraftItemsToggle", GraftItems);
- return base.Write(writer);
+ writer.SetBoolean( "GraftItemsToggle", this._graftItems );
+ return base.Write( writer );
}
}
}
\ No newline at end of file
diff --git a/ObjectivismGH/Components/ImplementsComponent.cs b/ObjectivismGH/Components/ImplementsComponent.cs
index d7b031b..35b76e6 100644
--- a/ObjectivismGH/Components/ImplementsComponent.cs
+++ b/ObjectivismGH/Components/ImplementsComponent.cs
@@ -1,57 +1,60 @@
using Grasshopper.Kernel;
+using Objectivism.Components.Utilities;
using System;
using System.Collections.Generic;
+using System.Drawing;
namespace Objectivism.Components
{
public class ImplementsComponent : GH_Component, IHasMultipleTypes
{
///
- /// Initializes a new instance of the Implements class.
+ /// Initializes a new instance of the Implements class.
///
public ImplementsComponent()
- : base("Implements", "Implements",
- "Tests if an object implements all the properties of a template object. An object implements the template if it has all the properties of the template, with name and access level matching",
- "Sets", "Objectivism")
+ : base( "Implements", "Implements",
+ "Tests if an object implements all the properties of a template object. An object implements the template if it has all the properties of the template, with name and access level matching",
+ "Sets", "Objectivism" )
{
- TypeNames = new HashSet();
+ this.TypeNames = new HashSet();
}
- protected override void BeforeSolveInstance()
- {
- TypeNames.Clear();
- }
+ protected override Bitmap Icon => Resources.implements;
+
+ public override Guid ComponentGuid => new Guid( "B77AF544-BB27-4BFB-8032-09993C3EEE4C" );
+
+ public HashSet TypeNames { get; }
+
+ protected override void BeforeSolveInstance() => this.TypeNames.Clear();
///
- /// Registers all the input parameters for this component.
+ /// Registers all the input parameters for this component.
///
- protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
+ protected override void RegisterInputParams( GH_InputParamManager pManager )
{
- pManager.AddGenericParameter("Template", "T", "Template object", GH_ParamAccess.item);
- pManager.AddGenericParameter("Object", "O", "Subject object", GH_ParamAccess.item);
-
+ pManager.AddGenericParameter( "Template", "T", "Template object", GH_ParamAccess.item );
+ pManager.AddGenericParameter( "Object", "O", "Subject object", GH_ParamAccess.item );
}
- protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
- {
- pManager.AddBooleanParameter("Implements", "I", "", GH_ParamAccess.item);
- }
+ protected override void RegisterOutputParams( GH_OutputParamManager pManager ) =>
+ pManager.AddBooleanParameter( "Implements", "I", "", GH_ParamAccess.item );
- protected override void SolveInstance(IGH_DataAccess DA)
+ protected override void SolveInstance( IGH_DataAccess daObject )
{
- if (!DA.TryGetObjectivsmObject(0, out var template)) return;
- if (!DA.TryGetObjectivsmObject(1, out var subject)) return;
-
- TypeNames.Add(template.TypeName);
- TypeNames.Add(subject.TypeName);
+ if ( !daObject.TryGetObjectivsmObject( 0, out var template ) )
+ {
+ return;
+ }
- DA.SetData(0, subject.Implements(template));
- }
-
- protected override System.Drawing.Bitmap Icon => Resources.implements;
+ if ( !daObject.TryGetObjectivsmObject( 1, out var subject ) )
+ {
+ return;
+ }
- public override Guid ComponentGuid => new Guid("B77AF544-BB27-4BFB-8032-09993C3EEE4C");
+ this.TypeNames.Add( template.TypeName );
+ this.TypeNames.Add( subject.TypeName );
- public HashSet TypeNames { get; private set; }
+ daObject.SetData( 0, subject.Implements( template ) );
+ }
}
-}
+}
\ No newline at end of file
diff --git a/ObjectivismGH/Components/InheritComponent.cs b/ObjectivismGH/Components/InheritComponent.cs
index 16bdf25..4bb084e 100644
--- a/ObjectivismGH/Components/InheritComponent.cs
+++ b/ObjectivismGH/Components/InheritComponent.cs
@@ -1,254 +1,242 @@
using Grasshopper.Kernel;
using Grasshopper.Kernel.Parameters;
+using Objectivism.Components.Utilities;
+using Objectivism.ObjectClasses;
+using Objectivism.Parameters;
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.Linq;
using System.Windows.Forms;
-using static Objectivism.DataUtil;
-namespace Objectivism
+namespace Objectivism.Components
{
public class InheritComponent : GH_Component, IGH_VariableParameterComponent, IHasMultipleTypes
{
+ private const string _myDefaultNickname = "NewTypeName";
+ private const string _defaultNickName = "Property";
+
+ private const string _description =
+ "Property to change in object, or add if the property does not exist. Param nickname must correspond to name of property to change/add";
+
+ private const string _numbers = "1234567890";
+
+ private readonly HashSet _propertyNames = new HashSet();
+ private string _nickNameCache;
+
///
- /// Initializes a new instance of the ChangePropertiesComponent class.
+ /// Initializes a new instance of the ChangePropertiesComponent class.
///
public InheritComponent()
- : base("Inherit", "NewTypeName",
- "Create a new object from a template. Add or change properties as required",
- "Sets", "Objectivism")
+ : base( "Inherit", _myDefaultNickname,
+ "Create a new object from a template. Add or change properties as required",
+ "Sets", "Objectivism" )
{
- NickNameCache = this.NickName;
+ this._nickNameCache = _myDefaultNickname;
this.IconDisplayMode = GH_IconDisplayMode.name;
- this.ObjectChanged += NickNameChangedEventHandler;
+ this.ObjectChanged += this.NickNameChangedEventHandler;
this.Message = "Inherit";
}
- private string NickNameCache;
+ ///
+ /// Provides an Icon for the component.
+ ///
+ protected override Bitmap Icon => Resources.inherit;
+
+ ///
+ /// Gets the unique ID for this component. Do not change this ID after release.
+ ///
+ public override Guid ComponentGuid => new Guid( "6F1CED3F-D460-4339-A494-D1829342E2C3" );
+
+
+ public bool CanInsertParameter( GH_ParameterSide side, int index ) =>
+ side == GH_ParameterSide.Input && index != 0;
+
+ public bool CanRemoveParameter( GH_ParameterSide side, int index ) =>
+ side == GH_ParameterSide.Input && index != 0;
+
+ public IGH_Param CreateParameter( GH_ParameterSide side, int index )
+ => new Param_ExtraObjectProperty { Name = "PropertyToChange", Description = _description };
+
+ public bool DestroyParameter( GH_ParameterSide side, int index ) => true;
+
+ public void VariableParameterMaintenance()
+ {
+ this.UpdatePropertyNames();
+ for ( var i = 1; i < this.Params.Input.Count; i++ )
+ {
+ this.Params.Input[i].Optional = true;
+ }
+
+ foreach ( var param in this.Params.Input )
+ {
+ if ( param is Param_ExtraObjectProperty extraParam )
+ {
+ extraParam.ReplaceAllPropertyNames( this._propertyNames );
+ }
+
+ if ( param.NickName == string.Empty )
+ {
+ param.NickName = this.NextUnusedName();
+ }
+ }
+ }
+
+ public HashSet TypeNames { get; } = new HashSet();
+
+ internal List GetUnusedNames() =>
+ this._propertyNames.Except( this.Params.Input.Select( p => p.NickName ).Skip( 1 ) ).ToList();
- private HashSet PropertyNames = new HashSet();
- internal List GetUnusedNames() => PropertyNames.Except(Params.Input.Select(p => p.NickName).Skip(1)).ToList();
internal string NextUnusedName()
{
- var unusedNames = GetUnusedNames();
+ // TODO: TG: Review. The use of StrippedParamNames() does not make sense to me.
+
+ var unusedNames = this.GetUnusedNames();
return unusedNames.Count == 0
- ? defaultNickName + GH_ComponentParamServer.InventUniqueNickname(numbers, StrippedParamNames())
+ ? _defaultNickName +
+ GH_ComponentParamServer.InventUniqueNickname( _numbers, this.StrippedParamNames() )
: unusedNames[0];
}
private void UpdatePropertyNames()
{
- PropertyNames.Clear();
- var data = this.Params.Input[0].VolatileData.AllData(true).ToList();
- foreach (var goo in data)
+ this._propertyNames.Clear();
+ var data = this.Params.Input[0].VolatileData.AllData( true ).ToList();
+ foreach ( var goo in data )
{
- if (goo is GH_ObjectivismObject ghObj)
+ if ( goo is GH_ObjectivismObject ghObj )
{
var propNames = ghObj.Value.AllProperties;
- PropertyNames.UnionWith(propNames);
+ this._propertyNames.UnionWith( propNames );
}
}
}
///
- /// Registers all the input parameters for this component.
+ /// Registers all the input parameters for this component.
///
- protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
+ protected override void RegisterInputParams( GH_InputParamManager pManager )
{
- pManager.AddGenericParameter("Object", "O", "Object to make changes to", GH_ParamAccess.item);
-
- var objParam = new Param_GenericObject();
- objParam.NickName = "O";
- objParam.Name = "Object";
- objParam.Description = "Object to modify";
- objParam.Access = GH_ParamAccess.item;
- objParam.ObjectChanged += ObjectWireChangedHandler;
+ pManager.AddGenericParameter( "Object", "O", "Object to make changes to", GH_ParamAccess.item );
+
+ var objParam = new Param_GenericObject
+ {
+ NickName = "O", Name = "Object", Description = "Object to modify", Access = GH_ParamAccess.item
+ };
+ objParam.ObjectChanged += this.ObjectWireChangedHandler;
/*
var param = new Param_ExtraObjectProperty();
param.Name = "PropertyName";
param.nickNameCache = defaultNickName + "1";
param.NickName = param.nickNameCache;
param.Description = description;
- pManager.AddParameter(param);
+ pManager.AddParameter(param);
*/
}
- private void ObjectWireChangedHandler(IGH_DocumentObject sender, GH_ObjectChangedEventArgs e)
+ private void ObjectWireChangedHandler( IGH_DocumentObject sender, GH_ObjectChangedEventArgs e )
{
- if (e.Type == GH_ObjectEventType.Sources)
+ if ( e.Type == GH_ObjectEventType.Sources )
{
this.UpdatePropertyNames();
- };
+ }
}
- private readonly string description = "Property to change in object, or add if the property does not exist. Param nickname must correspond to name of property to change/add";
///
- /// Registers all the output parameters for this component.
+ /// Registers all the output parameters for this component.
///
- protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
- {
- pManager.AddGenericParameter("Object", "O", "Modified object", GH_ParamAccess.item);
- }
+ protected override void RegisterOutputParams( GH_OutputParamManager pManager ) =>
+ pManager.AddGenericParameter( "Object", "O", "Modified object", GH_ParamAccess.item );
protected override void BeforeSolveInstance()
{
- UpdateTypeNames();
+ this.UpdateTypeNames();
this.UpdatePropertyNames();
- Params.Input.ForEach(CommitParamNames);
+ this.Params.Input.ForEach( this.CommitParamNames );
base.BeforeSolveInstance();
}
- private HashSet typeNames = new HashSet();
- public HashSet TypeNames => typeNames;
-
private void UpdateTypeNames()
{
- typeNames.Clear();
- typeNames.Add(this.NickName);
- var data = this.Params.Input[0].VolatileData.AllData(true);
- foreach (var goo in data)
+ this.TypeNames.Clear();
+ this.TypeNames.Add( this.NickName );
+ var data = this.Params.Input[0].VolatileData.AllData( true );
+ foreach ( var goo in data )
{
- if (goo is GH_ObjectivismObject ghObj)
+ if ( goo is GH_ObjectivismObject ghObj )
{
var tn = ghObj.Value.TypeName;
- typeNames.Add(tn);
+ this.TypeNames.Add( tn );
}
}
}
- private bool JustOneTypeName() => typeNames.Count <= 1;
-
- private void CommitParamNames(IGH_Param param)
+ private void CommitParamNames( IGH_Param param )
{
- if (param is Param_ExtraObjectProperty p)
+ if ( param is Param_ExtraObjectProperty p )
{
p.CommitNickName();
}
}
- public void NickNameChangedEventHandler(object sender, GH_ObjectChangedEventArgs args)
+ public void NickNameChangedEventHandler( object sender, GH_ObjectChangedEventArgs args )
{
- if (args.Type == GH_ObjectEventType.NickName)
+ if ( args.Type == GH_ObjectEventType.NickName )
{
- if (NickName != NickNameCache)
+ if ( this.NickName != this._nickNameCache )
{
- this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Type name (component nickname) changed but object not updated, right click on component and press \"Recompute\"");
+ this.AddRuntimeMessage( GH_RuntimeMessageLevel.Warning,
+ "Type name (component nickname) changed but object not updated, right click on component and press \"Recompute\"" );
}
}
}
///
- /// This is the method that actually does the work.
+ /// This is the method that actually does the work.
///
- /// The DA object is used to retrieve from inputs and store in outputs.
- protected override void SolveInstance(IGH_DataAccess DA)
+ /// The DA object is used to retrieve from inputs and store in outputs.
+ protected override void SolveInstance( IGH_DataAccess daObject )
{
var typeName = this.NickName;
- NickNameCache = NickName;
-
- if (!DA.TryGetObjectivsmObject(0, out var obj)) return;
-
- var updates = new List<(string Name, ObjectProperty Property)>();
+ this._nickNameCache = this.NickName;
- for (int i = 1; i < Params.Input.Count; i++)
+ if ( !daObject.TryGetObjectivsmObject( 0, out var obj ) )
{
- updates.Add(RetrieveProperties(DA, i, this));
+ return;
}
- (var newObj, var accessConflict) = obj.AddOrChangeProperties(updates, typeName);
- accessConflict.BroadcastConflicts(this);
- DA.SetData(0, new GH_ObjectivismObject(newObj));
-
- }
-
-
- public bool CanInsertParameter(GH_ParameterSide side, int index)
- {
- return side == GH_ParameterSide.Input && index != 0;
- }
-
- public bool CanRemoveParameter(GH_ParameterSide side, int index)
- {
- return side == GH_ParameterSide.Input && index != 0;
- }
-
- public IGH_Param CreateParameter(GH_ParameterSide side, int index)
- {
- var param = new Param_ExtraObjectProperty();
- param.Name = "PropertyToChange";
- param.nickNameCache = string.Empty;
- param.NickName = string.Empty;
- param.Description = description;
- return param;
- }
-
- public bool DestroyParameter(GH_ParameterSide side, int index)
- {
- return true;
- }
+ var updates = new List<(string Name, ObjectProperty Property)>();
- public void VariableParameterMaintenance()
- {
- this.UpdatePropertyNames();
- for (int i = 1; i < Params.Input.Count; i++)
+ for ( var i = 1; i < this.Params.Input.Count; i++ )
{
- Params.Input[i].Optional = true;
+ updates.Add( this.GetProperty( daObject, i ) );
}
- foreach (var param in Params.Input)
- {
- if (param is Param_ExtraObjectProperty extraParam)
- {
- extraParam.AllPropertyNames = this.PropertyNames;
- }
- if (param.NickName == string.Empty)
- {
- param.NickName = NextUnusedName();
- }
- }
+ var (newObj, accessConflict) = obj.AddOrChangeProperties( updates, typeName );
+ accessConflict.BroadcastConflicts( this );
+ daObject.SetData( 0, new GH_ObjectivismObject( newObj ) );
}
private List StrippedParamNames()
{
var variableParams = this.Params.Input.ToList();
return variableParams
- .Select(p => p.NickName)
- .Where(n => n.StartsWith(defaultNickName) && numbers.Contains(n.ToCharArray()[defaultNickName.Length]))
- .Select(n => n.Replace(defaultNickName, ""))
+ .Select( p => p.NickName )
+ .Where( n =>
+ n.Length > _defaultNickName.Length
+ && char.IsDigit( n[_defaultNickName.Length] )
+ && n.StartsWith( _defaultNickName, StringComparison.Ordinal ) )
+ .Select( n => n.Substring( _defaultNickName.Length ) )
.ToList();
}
- private readonly string defaultNickName = "Property";
- private readonly string numbers = "1234567890";
+ public override void AppendAdditionalMenuItems( ToolStripDropDown menu ) =>
+ Menu_AppendItem( menu, "Recompute", this.UpdateObjectEventHandler );
- public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
- {
- Menu_AppendItem(menu, "Recompute", UpdateObjectEventHandler);
- }
-
- private void UpdateObjectEventHandler(object sender, EventArgs e)
- {
- this.Params.Input.ForEach(p => p.ExpireSolution(false));
- ExpireSolution(true);
- }
-
- ///
- /// Provides an Icon for the component.
- ///
- protected override System.Drawing.Bitmap Icon
- {
- get
- {
- return Resources.inherit;
- }
- }
-
- ///
- /// Gets the unique ID for this component. Do not change this ID after release.
- ///
- public override Guid ComponentGuid
+ private void UpdateObjectEventHandler( object sender, EventArgs e )
{
- get { return new Guid("6F1CED3F-D460-4339-A494-D1829342E2C3"); }
+ this.Params.Input.ForEach( p => p.ExpireSolution( false ) );
+ this.ExpireSolution( true );
}
}
}
\ No newline at end of file
diff --git a/ObjectivismGH/Components/ObjectToTree.cs b/ObjectivismGH/Components/ObjectToTree.cs
index 65a74d1..ee1afc4 100644
--- a/ObjectivismGH/Components/ObjectToTree.cs
+++ b/ObjectivismGH/Components/ObjectToTree.cs
@@ -1,176 +1,175 @@
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
+using Objectivism.Components.Utilities;
+using Objectivism.ObjectClasses;
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.Linq;
namespace Objectivism.Components
{
public class ObjectToTree : GH_Component
{
+ private AccessChecker _accessChecker;
+ private HashSet _propNamesSet;
+
+ private List _propNamesStore;
+
///
- /// Initializes a new instance of the ObjectToTree class.
+ /// Initializes a new instance of the ObjectToTree class.
///
public ObjectToTree()
- : base("Object To Tree", "ToTree",
- "Turn an objectivism object into a tree. Also returns a mirror tree of the property names",
- "Sets", "Objectivism")
+ : base( "Object To Tree", "ToTree",
+ "Turn an objectivism object into a tree. Also returns a mirror tree of the property names",
+ "Sets", "Objectivism" )
{
}
///
- /// Registers all the input parameters for this component.
+ /// Provides an Icon for the component.
///
- protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
- {
- pManager.AddGenericParameter("Object", "O", "Objectivism object to turn into tree", GH_ParamAccess.item);
- }
+ protected override Bitmap Icon => Resources.ObjToTree;
///
- /// Registers all the output parameters for this component.
+ /// Gets the unique ID for this component. Do not change this ID after release.
///
- protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
+ public override Guid ComponentGuid => new Guid( "b717a0eb-95ae-4e64-8dbb-7ad39f6fcda0" );
+
+ ///
+ /// Registers all the input parameters for this component.
+ ///
+ protected override void RegisterInputParams( GH_InputParamManager pManager ) =>
+ pManager.AddGenericParameter( "Object", "O", "Objectivism object to turn into tree", GH_ParamAccess.item );
+
+ ///
+ /// Registers all the output parameters for this component.
+ ///
+ protected override void RegisterOutputParams( GH_OutputParamManager pManager )
{
- pManager.AddGenericParameter("Tree", "T", "Object as tree, root branch paths correspond to properties", GH_ParamAccess.tree);
- pManager.AddTextParameter("Property Names", "P", "Property names in tree of same structure as output tree", GH_ParamAccess.tree);
+ pManager.AddGenericParameter( "Tree", "T", "Object as tree, root branch paths correspond to properties",
+ GH_ParamAccess.tree );
+ pManager.AddTextParameter( "Property Names", "P", "Property names in tree of same structure as output tree",
+ GH_ParamAccess.tree );
}
- private List propNamesStore;
- private HashSet propNamesSet;
protected override void BeforeSolveInstance()
{
- propNamesStore = new List();
- propNamesSet = new HashSet();
- accessChecker = new AccessChecker(this);
+ this._propNamesStore = new List();
+ this._propNamesSet = new HashSet();
+ this._accessChecker = new AccessChecker( this );
base.BeforeSolveInstance();
}
- private AccessChecker accessChecker;
-
- private void AddToStoreIfRequired(string name)
+ private void AddToStoreIfRequired( string name )
{
- if (!propNamesSet.Contains(name))
+ if ( !this._propNamesSet.Contains( name ) )
{
- propNamesStore.Add(name);
- propNamesSet.Add(name);
+ this._propNamesStore.Add( name );
+ this._propNamesSet.Add( name );
}
}
-
///
- /// This is the method that actually does the work.
+ /// This is the method that actually does the work.
///
- /// The DA object is used to retrieve from inputs and store in outputs.
- protected override void SolveInstance(IGH_DataAccess DA)
+ /// The DA object is used to retrieve from inputs and store in outputs.
+ protected override void SolveInstance( IGH_DataAccess daObject )
{
IGH_Goo goo = null;
- if (!DA.GetData(0, ref goo))
+ if ( !daObject.GetData( 0, ref goo ) )
{
return;
}
+
ObjectivismObject obj;
- if (goo is GH_ObjectivismObject ghObj)
+ if ( goo is GH_ObjectivismObject ghObj )
{
obj = ghObj.Value;
}
else
{
- this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Can only get properties from ojects built with Objectivism");
+ this.AddRuntimeMessage( GH_RuntimeMessageLevel.Error,
+ "Can only get properties from ojects built with Objectivism" );
return;
}
- obj.AllProperties.ForEach(n => AddToStoreIfRequired(n));
- GH_Structure outTree = new GH_Structure();
- GH_Structure nameTree = new GH_Structure();
+ obj.AllProperties.ForEach( this.AddToStoreIfRequired );
+
+ var outTree = new GH_Structure();
+ var nameTree = new GH_Structure();
- foreach ((int i, string name) in propNamesStore.Enumerate())
+ foreach ( var (i, name) in this._propNamesStore.Enumerate() )
{
- GH_String nameGoo = new GH_String(name);
- var prop = obj.GetProperty(name);
+ var nameGoo = new GH_String( name );
+ var prop = obj.GetProperty( name );
PropertyAccess access;
- if (prop != null)
+ if ( prop != null )
{
access = prop.Access;
- accessChecker.AccessCheck(prop, name);
+ this._accessChecker.AccessCheck( prop, name );
}
else
{
- access = accessChecker.BestGuessAccess(name);
+ access = this._accessChecker.BestGuessAccess( name );
}
- if (access == PropertyAccess.Item)
+ if ( access == PropertyAccess.Item )
{
- var item = prop != null
- ? prop.Data.get_FirstItem(false)
- : null;
- var path = new List() { i };
- path.AddRange(DA.ParameterTargetPath(0).Indices);
- path.Add(DA.ParameterTargetIndex(0));
- var newPath = new GH_Path(path.ToArray());
- outTree.Append(item, newPath);
- nameTree.Append(nameGoo, newPath);
+ var item = prop?.Data.get_FirstItem( false );
+ var path = new List { i };
+ path.AddRange( daObject.ParameterTargetPath( 0 ).Indices );
+ path.Add( daObject.ParameterTargetIndex( 0 ) );
+ var newPath = new GH_Path( path.ToArray() );
+ outTree.Append( item, newPath );
+ nameTree.Append( nameGoo, newPath );
}
- if (access == PropertyAccess.List)
+
+ if ( access == PropertyAccess.List )
{
var list = prop != null
? prop.Data.Branches[0]
: new List();
- var path = new List() { i };
- path.AddRange(DA.ParameterTargetPath(0).Indices);
- path.Add(DA.ParameterTargetIndex(0));
- var newPath = new GH_Path(path.ToArray());
- outTree.AppendRange(list, newPath);
- nameTree.Append(nameGoo, newPath);
+ var path = new List { i };
+ path.AddRange( daObject.ParameterTargetPath( 0 ).Indices );
+ path.Add( daObject.ParameterTargetIndex( 0 ) );
+ var newPath = new GH_Path( path.ToArray() );
+ outTree.AppendRange( list, newPath );
+ nameTree.Append( nameGoo, newPath );
}
- if (access == PropertyAccess.Tree)
+
+ if ( access == PropertyAccess.Tree )
{
var tree = prop != null
? prop.Data
: Util.EmptyTree;
- var path = new List() { i };
- path.AddRange(DA.ParameterTargetPath(0).Indices);
- path.Add(DA.ParameterTargetIndex(0));
- for (int j = 0; j < tree.PathCount; j++)
+ var path = new List { i };
+ path.AddRange( daObject.ParameterTargetPath( 0 ).Indices );
+ path.Add( daObject.ParameterTargetIndex( 0 ) );
+ for ( var j = 0; j < tree.PathCount; j++ )
{
var branch = tree.Branches[j];
var subPath = tree.Paths[j].Indices;
var newPathIndices = path
- .Concat(subPath)
+ .Concat( subPath )
.ToArray();
- var newPath = new GH_Path(newPathIndices);
- outTree.AppendRange(branch, newPath);
- nameTree.Append(nameGoo, newPath);
+ var newPath = new GH_Path( newPathIndices );
+ outTree.AppendRange( branch, newPath );
+ nameTree.Append( nameGoo, newPath );
}
}
}
- DA.SetDataTree(0, outTree);
- DA.SetDataTree(1, nameTree);
- }
- protected override void AfterSolveInstance()
- {
- accessChecker.ThrowWarnings();
- base.AfterSolveInstance();
- }
- ///
- /// Provides an Icon for the component.
- ///
- protected override System.Drawing.Bitmap Icon
- {
- get
- {
- return Resources.ObjToTree;
- }
+ daObject.SetDataTree( 0, outTree );
+ daObject.SetDataTree( 1, nameTree );
}
- ///
- /// Gets the unique ID for this component. Do not change this ID after release.
- ///
- public override Guid ComponentGuid
+ protected override void AfterSolveInstance()
{
- get { return new Guid("b717a0eb-95ae-4e64-8dbb-7ad39f6fcda0"); }
+ this._accessChecker.ThrowWarnings();
+ base.AfterSolveInstance();
}
}
}
\ No newline at end of file
diff --git a/ObjectivismGH/Components/Utilities/AccessChecker.cs b/ObjectivismGH/Components/Utilities/AccessChecker.cs
new file mode 100644
index 0000000..077c6d9
--- /dev/null
+++ b/ObjectivismGH/Components/Utilities/AccessChecker.cs
@@ -0,0 +1,74 @@
+using Grasshopper.Kernel;
+using Objectivism.ObjectClasses;
+using System.Collections.Generic;
+
+namespace Objectivism.Components.Utilities
+{
+ internal class AccessChecker
+ {
+ private readonly Dictionary _accessRecorder;
+
+ private readonly IGH_Component _hostRef;
+ private readonly HashSet _warningsToThrow;
+
+ public AccessChecker( IGH_Component @this )
+ {
+ this._accessRecorder = new Dictionary();
+ this._warningsToThrow = new HashSet();
+ this._hostRef = @this;
+ }
+
+ public void AccessCheck( ObjectProperty prop, string name )
+ {
+ if ( this._accessRecorder.TryGetValue( name, out var access ) )
+ {
+ if ( access != prop.Access )
+ {
+ this._warningsToThrow.Add( name );
+ }
+ }
+ else
+ {
+ this._accessRecorder.Add( name, prop.Access );
+ }
+ }
+
+ public void ThrowWarnings()
+ {
+ foreach ( var name in this._warningsToThrow )
+ {
+ this._hostRef.AddRuntimeMessage( GH_RuntimeMessageLevel.Warning,
+ $"Access not consistent for {name} property. Output data tree may be messy and not consistent" );
+ }
+ }
+
+ public PropertyAccess BestGuessAccess( string name )
+ {
+ if ( this._accessRecorder.TryGetValue( name, out var access ) )
+ {
+ return access;
+ }
+
+ try
+ {
+ var data = this._hostRef.Params.Input[0].VolatileData.AllData( true );
+ foreach ( var goo in data )
+ {
+ if ( goo is GH_ObjectivismObject ghObj )
+ {
+ if ( ghObj.Value.HasProperty( name ) )
+ {
+ return ghObj.Value.GetProperty( name ).Access;
+ }
+ }
+ }
+
+ return PropertyAccess.Item;
+ }
+ catch
+ {
+ return PropertyAccess.Item;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ObjectivismGH/Components/Utilities/ComponentExtensions.cs b/ObjectivismGH/Components/Utilities/ComponentExtensions.cs
new file mode 100644
index 0000000..ca09bd4
--- /dev/null
+++ b/ObjectivismGH/Components/Utilities/ComponentExtensions.cs
@@ -0,0 +1,52 @@
+using Grasshopper.Kernel;
+using Grasshopper.Kernel.Data;
+using Grasshopper.Kernel.Types;
+using Objectivism.ObjectClasses;
+using Objectivism.Parameters;
+using System.Collections.Generic;
+
+namespace Objectivism.Components.Utilities
+{
+ internal static class ComponentExtensions
+ {
+ public static (string Name, ObjectProperty Property) GetProperty( this IGH_Component component,
+ IGH_DataAccess daObject, int paramIndex )
+ {
+ var previewOn = true;
+ var param = component.Params.Input[paramIndex];
+
+ if ( param is IHasPreviewToggle hasPreviewToggle )
+ {
+ previewOn = hasPreviewToggle.PreviewOn;
+ }
+
+ ObjectProperty prop;
+ var name = param.NickName;
+ if ( param.Access == GH_ParamAccess.item )
+ {
+ IGH_Goo item = null;
+ if ( !daObject.GetData( paramIndex, ref item ) )
+ {
+ component.AddRuntimeMessage( GH_RuntimeMessageLevel.Remark,
+ $"{name} has no input and has been assigned null data" );
+ }
+
+ prop = new ObjectProperty( item );
+ }
+ else if ( param.Access == GH_ParamAccess.list )
+ {
+ var items = new List();
+ daObject.GetDataList( paramIndex, items );
+ prop = new ObjectProperty( items );
+ }
+ else //tree access
+ {
+ daObject.GetDataTree( paramIndex, out GH_Structure itemTree );
+ prop = new ObjectProperty( itemTree );
+ }
+
+ prop.PreviewOn = previewOn;
+ return (name, prop);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ObjectivismGH/Components/Utilities/DataAccessExtensions.cs b/ObjectivismGH/Components/Utilities/DataAccessExtensions.cs
new file mode 100644
index 0000000..876fe6f
--- /dev/null
+++ b/ObjectivismGH/Components/Utilities/DataAccessExtensions.cs
@@ -0,0 +1,28 @@
+using Grasshopper.Kernel;
+using Grasshopper.Kernel.Types;
+using Objectivism.ObjectClasses;
+
+namespace Objectivism.Components.Utilities
+{
+ internal static class DataAccessExtensions
+ {
+ public static bool TryGetObjectivsmObject( this IGH_DataAccess daObject, int paramIndex,
+ out ObjectivismObject obj )
+ {
+ obj = null;
+ IGH_Goo goo = null;
+ if ( !daObject.GetData( paramIndex, ref goo ) )
+ {
+ return false;
+ }
+
+ if ( goo is GH_ObjectivismObject ghObj )
+ {
+ obj = ghObj.Value;
+ return true;
+ }
+
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/ObjectivismGH/DeReferenceGeometryUtil.cs b/ObjectivismGH/DeReferenceGeometryUtil.cs
index 21354c3..f54ca53 100644
--- a/ObjectivismGH/DeReferenceGeometryUtil.cs
+++ b/ObjectivismGH/DeReferenceGeometryUtil.cs
@@ -2,59 +2,62 @@
using Rhino.Geometry;
using System;
using System.Reflection;
+
namespace Objectivism
{
-
- static class DeReferenceGeometryUtil
+ internal static class DeReferenceGeometryUtil
{
/*I am convinced this should be easier to do, just using IGH_GeometricGoo.DuplicateGeometry() didn't work,
did not seem to be properly duplicated when applying the transforms. This however does work. */
- internal static IGH_GeometricGoo DeReferenceWhereRequired(IGH_GeometricGoo geom)
+ internal static IGH_GeometricGoo DeReferenceWhereRequired( IGH_GeometricGoo geom )
{
- if (geom.IsReferencedGeometry)
+ if ( geom.IsReferencedGeometry )
{
geom.LoadGeometry();
//As far as I am aware only these geometry types support direct reference from Rhino.
- if (geom is GH_Brep brep) { return new GH_Brep((Brep)brep.Value.Duplicate()); }
- if (geom is GH_Curve curve) { return new GH_Curve((Curve)curve.Value.Duplicate()); }
- if (geom is GH_Mesh mesh) { return new GH_Mesh((Mesh)mesh.Value.Duplicate()); }
- if (geom is GH_Point point) { return new GH_Point(point.Value); }
- if (geom is GH_Surface surface) { return new GH_Surface((Brep)surface.Value.Duplicate()); }
+ if ( geom is GH_Brep brep ) { return new GH_Brep( (Brep) brep.Value.Duplicate() ); }
+
+ if ( geom is GH_Curve curve ) { return new GH_Curve( (Curve) curve.Value.Duplicate() ); }
+
+ if ( geom is GH_Mesh mesh ) { return new GH_Mesh( (Mesh) mesh.Value.Duplicate() ); }
+
+ if ( geom is GH_Point point ) { return new GH_Point( point.Value ); }
+
+ if ( geom is GH_Surface surface ) { return new GH_Surface( (Brep) surface.Value.Duplicate() ); }
//if (geom is GH_SubD subd) { return new GH_SubD((SubD)subd.Value.Duplicate()); }
//(Building for Rhino 6, subD workds with the reflection method.)
//If none of the hard coded cases fit use reflection to copy the object
- return DeReferenceWithReflection(geom);
- }
- else
- {
- return geom;
+ return DeReferenceWithReflection( geom );
}
+
+ return geom;
}
- private static IGH_GeometricGoo DeReferenceWithReflection(IGH_GeometricGoo geom)
+ private static IGH_GeometricGoo DeReferenceWithReflection( IGH_GeometricGoo geom )
{
var geomType = geom.GetType();
- var geomInfo = geomType.GetRuntimeProperty("Value");
- if (geomInfo != null)
+ var geomInfo = geomType.GetRuntimeProperty( "Value" );
+ if ( geomInfo != null )
{
- var geomVal = geomInfo.GetValue(geom);
- if (geomVal is GeometryBase rhinoGeom)
+ var geomVal = geomInfo.GetValue( geom );
+ if ( geomVal is GeometryBase rhinoGeom )
{
IGH_GeometricGoo newGoo;
try
{
- newGoo = (IGH_GeometricGoo)Activator.CreateInstance(geomType, rhinoGeom);
+ newGoo = (IGH_GeometricGoo) Activator.CreateInstance( geomType, rhinoGeom );
}
//Plugins that implement IGH_GeometricGoo may not have a constructor like above
//In this case revert to DuplicateGeometry and hope it is implemented properly.
catch { newGoo = geom.DuplicateGeometry(); }
+
geom = newGoo;
}
-
}
+
return geom.DuplicateGeometry();
}
}
-}
+}
\ No newline at end of file
diff --git a/ObjectivismGH/Forms/ChangePropertyNameForm.Designer.cs b/ObjectivismGH/Forms/ChangePropertyNameForm.Designer.cs
index 2ab9455..cb5c42e 100644
--- a/ObjectivismGH/Forms/ChangePropertyNameForm.Designer.cs
+++ b/ObjectivismGH/Forms/ChangePropertyNameForm.Designer.cs
@@ -37,7 +37,7 @@ private void InitializeComponent()
this.ThisTypeButton = new System.Windows.Forms.RadioButton();
this.ConnectedTypesButton = new System.Windows.Forms.RadioButton();
this.AllTypesButton = new System.Windows.Forms.RadioButton();
- this.label1 = new System.Windows.Forms.Label();
+ this.Label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// OkButton
@@ -141,15 +141,15 @@ private void InitializeComponent()
//
// label1
//
- this.label1.AutoSize = true;
- this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.label1.Location = new System.Drawing.Point(21, 66);
- this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(510, 25);
- this.label1.TabIndex = 3;
- this.label1.Text = "Change this property name for components operating on: ";
- this.label1.Click += new System.EventHandler(this.label1_Click);
+ this.Label1.AutoSize = true;
+ this.Label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.Label1.Location = new System.Drawing.Point(21, 66);
+ this.Label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+ this.Label1.Name = "label1";
+ this.Label1.Size = new System.Drawing.Size(510, 25);
+ this.Label1.TabIndex = 3;
+ this.Label1.Text = "Change this property name for components operating on: ";
+ this.Label1.Click += new System.EventHandler(this.Label1_Click);
//
// ChangePropertyNameForm
//
@@ -161,7 +161,7 @@ private void InitializeComponent()
this.Controls.Add(this.ConnectedTypesButton);
this.Controls.Add(this.ThisTypeButton);
this.Controls.Add(this.NewNameBox);
- this.Controls.Add(this.label1);
+ this.Controls.Add(this.Label1);
this.Controls.Add(this.NewNameLabel);
this.Controls.Add(this.InstancesLabel);
this.Controls.Add(this.WelcomeTextLabel);
@@ -190,6 +190,6 @@ private void InitializeComponent()
private System.Windows.Forms.RadioButton ThisTypeButton;
private System.Windows.Forms.RadioButton ConnectedTypesButton;
private System.Windows.Forms.RadioButton AllTypesButton;
- private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.Label Label1;
}
}
\ No newline at end of file
diff --git a/ObjectivismGH/Forms/ChangePropertyNameForm.cs b/ObjectivismGH/Forms/ChangePropertyNameForm.cs
index 1d2184b..6fd837c 100644
--- a/ObjectivismGH/Forms/ChangePropertyNameForm.cs
+++ b/ObjectivismGH/Forms/ChangePropertyNameForm.cs
@@ -1,5 +1,7 @@
using Grasshopper.Kernel;
using Grasshopper.Kernel.Undo;
+using Objectivism.Components;
+using Objectivism.Parameters;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -10,289 +12,281 @@ namespace Objectivism.Forms
public partial class ChangePropertyNameForm : Form
{
private readonly GH_Document _doc;
- private List _paramsToChange;
private readonly string _propName;
private readonly string _typeName;
- private int radioState = 0;
- private void setRadio(int i)
+ private List _paramsToChange;
+ private int _radioState;
+
+ public ChangePropertyNameForm( string propertyName, string typeName, GH_Document ghDoc, bool multipleTypesOnly )
{
- if (i != radioState)
+ this.InitializeComponent();
+
+ this._doc = ghDoc;
+ this.WelcomeTextLabel.Text = multipleTypesOnly
+ ? $"Change property name \"{propertyName}\" used in multiple types"
+ : $"Change property name \"{propertyName}\" belonging to type \"{typeName}\"";
+ this._propName = propertyName;
+ this._typeName = typeName;
+
+ if ( multipleTypesOnly )
{
- radioState = i;
- if (i == 0)
+ this.ConnectedTypesButton.Checked = true;
+ this.ThisTypeButton.Checked = false;
+ this.ThisTypeButton.Enabled = false;
+ }
+
+ if ( multipleTypesOnly )
+ {
+ this.GetParamsOfConnectedTypes();
+ }
+ else
+ {
+ this.GetParamsOfThisType();
+ }
+ }
+
+ private void SetRadio( int i )
+ {
+ if ( i != this._radioState )
+ {
+ this._radioState = i;
+ if ( i == 0 )
{
- GetParamsOfThisType();
+ this.GetParamsOfThisType();
}
- if (i == 1)
+
+ if ( i == 1 )
{
- GetParamsOfConnectedTypes();
+ this.GetParamsOfConnectedTypes();
}
- if (i == 2)
+
+ if ( i == 2 )
{
- GetParamsOfAllTypes();
+ this.GetParamsOfAllTypes();
}
- ThisTypeButton.Checked = i == 0;
- ConnectedTypesButton.Checked = i == 1;
- AllTypesButton.Checked = i == 2;
- }
+ this.ThisTypeButton.Checked = i == 0;
+ this.ConnectedTypesButton.Checked = i == 1;
+ this.AllTypesButton.Checked = i == 2;
+ }
}
private void GetParamsOfAllTypes()
{
- var createParams =
- _doc.Objects
- .Where(obj => obj is CreateObjectComponent c)
- .Select(obj => (IGH_Component)obj)
- .Select(c => c.Params.Input
- .Where(p => p is Param_NewObjectProperty && p.NickName == _propName))
- .SelectMany(x => x);
- var changeParams =
- _doc.Objects
- .Where(obj => obj is AddOrChangePropertiesComponent || obj is InheritComponent)
- .Select(obj => (IGH_Component)obj)
- .Select(c => c.Params.Input
- .Where(p => p is Param_ExtraObjectProperty && p.NickName == _propName))
- .SelectMany(x => x);
- var propParams =
- _doc.Objects
- .Where(obj => obj is GetPropertiesComponent c)
- .Select(obj => (IGH_Component)obj)
- .Select(c => c.Params.Output
- .Where(p => p is Param_ObjectivismOutput && p.NickName == _propName))
- .SelectMany(x => x);
- var allParams = createParams.Concat(changeParams).Concat(propParams);
- var count = allParams.Count();
- _paramsToChange = allParams.ToList();
+ var createParams = this._doc.Objects
+ .Where( obj => obj is CreateObjectComponent )
+ .Select( obj => (IGH_Component) obj )
+ .Select( c => c.Params.Input
+ .Where( p => p is Param_NewObjectProperty && p.NickName == this._propName ) )
+ .SelectMany( x => x );
+ var changeParams = this._doc.Objects
+ .Where( obj => obj is AddOrChangePropertiesComponent || obj is InheritComponent )
+ .Select( obj => (IGH_Component) obj )
+ .Select( c => c.Params.Input
+ .Where( p => p is Param_ExtraObjectProperty && p.NickName == this._propName ) )
+ .SelectMany( x => x );
+ var propParams = this._doc.Objects
+ .Where( obj => obj is GetPropertiesComponent )
+ .Select( obj => (IGH_Component) obj )
+ .Select( c => c.Params.Output
+ .Where( p => p is Param_ObjectivismOutput && p.NickName == this._propName ) )
+ .SelectMany( x => x );
+ var allParams = createParams.Concat( changeParams ).Concat( propParams ).ToList();
+ var count = allParams.Count;
+ this._paramsToChange = allParams;
this.InstancesLabel.Text = $"{count} instances found";
this.Update();
-
}
private void GetParamsOfConnectedTypes()
{
- var connectedTypes = new HashSet { _typeName };
+ var connectedTypes = new HashSet { this._typeName };
var typeComps =
- new Stack(
- _doc.Objects
- .Where(obj => obj is IHasMultipleTypes)
- .Select(obj => (IHasMultipleTypes)obj));
-
- connectedTypes = FindAllConnectedTypes(connectedTypes, typeComps);
-
- var createParams =
- _doc.Objects
- .Where(obj => obj is CreateObjectComponent c && connectedTypes.Contains(c.NickName))
- .Select(obj => (IGH_Component)obj)
- .Select(c => c.Params.Input
- .Where(p => p is Param_NewObjectProperty && p.NickName == _propName))
- .SelectMany(x => x);
- var changeParams =
- _doc.Objects
- .Where(obj =>
- obj is AddOrChangePropertiesComponent || obj is InheritComponent)
- .Where(obj =>
+ new Stack( this._doc.Objects.OfType() );
+
+ connectedTypes = this.FindAllConnectedTypes( connectedTypes, typeComps );
+
+ var createParams = this._doc.Objects
+ .Where( obj => obj is CreateObjectComponent c && connectedTypes.Contains( c.NickName ) )
+ .Select( obj => (IGH_Component) obj )
+ .Select( c => c.Params.Input
+ .Where( p => p is Param_NewObjectProperty && p.NickName == this._propName ) )
+ .SelectMany( x => x );
+ var changeParams = this._doc.Objects
+ .Where( obj =>
+ obj is AddOrChangePropertiesComponent || obj is InheritComponent )
+ .Where( obj =>
obj is IHasMultipleTypes c
&& c.TypeNames.Count != 0
- && connectedTypes.Contains(c.TypeNames.First()))
- .Select(obj => (IGH_Component)obj)
- .Select(c => c.Params.Input
- .Where(p => p is Param_ExtraObjectProperty && p.NickName == _propName))
- .SelectMany(x => x);
- var propParams =
- _doc.Objects
- .Where(obj =>
+ && connectedTypes.Contains( c.TypeNames.First() ) )
+ .Select( obj => (IGH_Component) obj )
+ .Select( c => c.Params.Input
+ .Where( p => p is Param_ExtraObjectProperty && p.NickName == this._propName ) )
+ .SelectMany( x => x );
+ var propParams = this._doc.Objects
+ .Where( obj =>
obj is GetPropertiesComponent c
&& c.TypeNames.Count != 0
- && connectedTypes.Contains(c.TypeNames.First()))
- .Select(obj => (IGH_Component)obj)
- .Select(c => c.Params.Output
- .Where(p => p is Param_ObjectivismOutput && p.NickName == _propName))
- .SelectMany(x => x);
- var allParams = createParams.Concat(changeParams).Concat(propParams);
- var count = allParams.Count();
- _paramsToChange = allParams.ToList();
+ && connectedTypes.Contains( c.TypeNames.First() ) )
+ .Select( obj => (IGH_Component) obj )
+ .Select( c => c.Params.Output
+ .Where( p => p is Param_ObjectivismOutput && p.NickName == this._propName ) )
+ .SelectMany( x => x );
+ var allParams = createParams.Concat( changeParams ).Concat( propParams ).ToList();
+ var count = allParams.Count;
+ this._paramsToChange = allParams;
this.InstancesLabel.Text = $"{count} instances found";
this.Update();
}
- private HashSet FindAllConnectedTypes(HashSet connectedTypes, Stack stack)
+ private HashSet FindAllConnectedTypes( HashSet connectedTypes, Stack stack )
{
- if (stack.Count() == 0)
+ if ( stack.Count == 0 )
{
return connectedTypes;
}
+
var thisComp = stack.Pop();
var intersection = false;
- foreach (var t in thisComp.TypeNames)
+ foreach ( var t in thisComp.TypeNames )
{
- if (connectedTypes.Contains(t))
+ if ( connectedTypes.Contains( t ) )
{
intersection = true;
break;
}
}
- if (intersection)
- {
- connectedTypes.UnionWith(thisComp.TypeNames);
- }
- return FindAllConnectedTypes(connectedTypes, stack);
- }
-
- public ChangePropertyNameForm(string propertyName, string typeName, GH_Document ghDoc, bool multipleTypesOnly)
- {
- InitializeComponent();
-
- _doc = ghDoc;
- WelcomeTextLabel.Text = multipleTypesOnly
- ? $"Change property name \"{propertyName}\" used in multiple types"
- : $"Change property name \"{propertyName}\" belonging to type \"{typeName}\"";
- _propName = propertyName;
- _typeName = typeName;
- if (multipleTypesOnly)
+ if ( intersection )
{
- this.ConnectedTypesButton.Checked = true;
- this.ThisTypeButton.Checked = false;
- this.ThisTypeButton.Enabled = false;
+ connectedTypes.UnionWith( thisComp.TypeNames );
}
- if (multipleTypesOnly)
- {
- GetParamsOfConnectedTypes();
- }
- else
- {
- GetParamsOfThisType();
- }
-
-
+ return this.FindAllConnectedTypes( connectedTypes, stack );
}
public void GetParamsOfThisType()
{
- var createParams =
- _doc.Objects
- .Where(obj => obj is CreateObjectComponent c && c.NickName == _typeName)
- .Select(obj => (IGH_Component)obj)
- .Select(c => c.Params.Input
- .Where(p => p is Param_NewObjectProperty && p.NickName == _propName))
- .SelectMany(x => x);
- var changeParams =
- _doc.Objects
- .Where(obj =>
- obj is AddOrChangePropertiesComponent || obj is InheritComponent)
- .Where(obj =>
+ var createParams = this._doc.Objects
+ .Where( obj => obj is CreateObjectComponent c && c.NickName == this._typeName )
+ .Select( obj => (IGH_Component) obj )
+ .Select( c => c.Params.Input
+ .Where( p => p is Param_NewObjectProperty && p.NickName == this._propName ) )
+ .SelectMany( x => x );
+ var changeParams = this._doc.Objects
+ .Where( obj =>
+ obj is AddOrChangePropertiesComponent || obj is InheritComponent )
+ .Where( obj =>
obj is IHasMultipleTypes c
&& c.TypeNames.Count == 1
- && c.TypeNames.First() == _typeName)
- .Select(obj => (IGH_Component)obj)
- .Select(c => c.Params.Input
- .Where(p => p is Param_ExtraObjectProperty && p.NickName == _propName))
- .SelectMany(x => x);
- var propParams =
- _doc.Objects
- .Where(obj =>
+ && c.TypeNames.First() == this._typeName )
+ .Select( obj => (IGH_Component) obj )
+ .Select( c => c.Params.Input
+ .Where( p => p is Param_ExtraObjectProperty && p.NickName == this._propName ) )
+ .SelectMany( x => x );
+ var propParams = this._doc.Objects
+ .Where( obj =>
obj is GetPropertiesComponent c
&& c.TypeNames.Count == 1
- && c.TypeNames.First() == _typeName)
- .Select(obj => (IGH_Component)obj)
- .Select(c => c.Params.Output
- .Where(p => p is Param_ObjectivismOutput && p.NickName == _propName))
- .SelectMany(x => x);
- var allParams = createParams.Concat(changeParams).Concat(propParams);
- var count = allParams.Count();
- _paramsToChange = allParams.ToList();
+ && c.TypeNames.First() == this._typeName )
+ .Select( obj => (IGH_Component) obj )
+ .Select( c => c.Params.Output
+ .Where( p => p is Param_ObjectivismOutput && p.NickName == this._propName ) )
+ .SelectMany( x => x );
+ var allParams = createParams.Concat( changeParams ).Concat( propParams ).ToList();
+ var count = allParams.Count;
+ this._paramsToChange = allParams;
this.InstancesLabel.Text = $"{count} instances found";
this.Update();
-
}
-
- private void OkButton_Click(object sender, EventArgs e)
+ private void OkButton_Click( object sender, EventArgs e )
{
var newName = this.NewNameBox.Text.Trim();
- if (newName == "")
+ if ( newName == "" )
{
- MessageBox.Show("No new name entered, please enter a name");
+ MessageBox.Show( "No new name entered, please enter a name" );
return;
}
- var undo = new GH_UndoRecord("Rename property for doc");
- foreach (var p in _paramsToChange)
+ var undo = new GH_UndoRecord( "Rename property for doc" );
+
+ foreach ( var p in this._paramsToChange )
{
- var action = new ChangeNameAction(p, p.NickName, newName);
- undo.AddAction(action);
+ var action = new ChangeNameAction( p, p.NickName, newName );
+ undo.AddAction( action );
p.NickName = newName;
- p.ExpireSolution(false);
+ p.ExpireSolution( false );
}
- _paramsToChange.ForEach(p => p.Attributes.ExpireLayout());
- _paramsToChange.First().ExpireSolution(true);
- _doc.UndoUtil.RecordEvent(undo);
+
+ this._paramsToChange.ForEach( p => p.Attributes.ExpireLayout() );
+ this._paramsToChange.First().ExpireSolution( true );
+ this._doc.UndoUtil.RecordEvent( undo );
this.Close();
}
+ private void CancelButton_Click( object sender, EventArgs e ) => this.Close();
- private void CancelButton_Click(object sender, EventArgs e)
+ private void ThisType_CheckedChanged( object sender, EventArgs e )
{
- this.Close();
- }
-
- private void ThisType_CheckedChanged(object sender, EventArgs e)
- {
- if (ThisTypeButton.Checked == true)
- setRadio(0);
+ if ( this.ThisTypeButton.Checked )
+ {
+ this.SetRadio( 0 );
+ }
}
- private void ConnectedTypesButton_CheckedChanged(object sender, EventArgs e)
+ private void ConnectedTypesButton_CheckedChanged( object sender, EventArgs e )
{
- if (ConnectedTypesButton.Checked == true)
- setRadio(1);
+ if ( this.ConnectedTypesButton.Checked )
+ {
+ this.SetRadio( 1 );
+ }
}
- private void AllTypesButton_CheckedChanged(object sender, EventArgs e)
+ private void AllTypesButton_CheckedChanged( object sender, EventArgs e )
{
- if (AllTypesButton.Checked == true)
- setRadio(2);
+ if ( this.AllTypesButton.Checked )
+ {
+ this.SetRadio( 2 );
+ }
}
- private void label1_Click(object sender, EventArgs e)
+ private void Label1_Click( object sender, EventArgs e )
{
-
}
}
- class ChangeNameAction : GH_UndoAction
+ internal class ChangeNameAction : GH_UndoAction
{
- private readonly IGH_Param param;
- private readonly string oldName;
- private readonly string newName;
- public override bool ExpiresSolution => true;
- protected override void Internal_Redo(GH_Document doc)
+ private readonly string _newName;
+ private readonly string _oldName;
+ private readonly IGH_Param _param;
+
+ public ChangeNameAction( IGH_Param param, string oldName, string newName )
{
- param.NickName = newName;
- param.Attributes.GetTopLevel.ExpireLayout();
- param.ExpireSolution(false);
+ this._param = param;
+ this._oldName = oldName;
+ this._newName = newName;
}
- protected override void Internal_Undo(GH_Document doc)
+ public override bool ExpiresSolution => true;
+
+ protected override void Internal_Redo( GH_Document doc )
{
- param.NickName = oldName;
- param.Attributes.GetTopLevel.ExpireLayout();
- param.ExpireSolution(false);
+ this._param.NickName = this._newName;
+ this._param.Attributes.GetTopLevel.ExpireLayout();
+ this._param.ExpireSolution( false );
}
- public ChangeNameAction(IGH_Param param, string oldName, string newName)
+ protected override void Internal_Undo( GH_Document doc )
{
- this.param = param;
- this.oldName = oldName;
- this.newName = newName;
+ this._param.NickName = this._oldName;
+ this._param.Attributes.GetTopLevel.ExpireLayout();
+ this._param.ExpireSolution( false );
}
}
-
-
-}
+}
\ No newline at end of file
diff --git a/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs b/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs
index f636128..ca51bb7 100644
--- a/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs
+++ b/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs
@@ -1,132 +1,104 @@
-using GH_IO;
-using GH_IO.Serialization;
+using GH_IO.Serialization;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
using Rhino.Geometry;
using Rhino.Render;
using System;
-namespace Objectivism
+
+namespace Objectivism.ObjectClasses
{
- public class GH_ObjectivismObject : GH_GeometricGoo, IGH_PreviewData, IGH_RenderAwareData, GH_ISerializable
+ public class GH_ObjectivismObject : GH_GeometricGoo, IGH_PreviewData, IGH_RenderAwareData
{
+ public GH_ObjectivismObject( ObjectivismObject value ) : base( value ) { }
+
+ public GH_ObjectivismObject() { }
+
+ public GH_ObjectivismObject( GH_ObjectivismObject other ) : base( other.Value ) { }
+
public override bool IsValid => true;
public override bool IsReferencedGeometry => false;
- public override string TypeName => Value.TypeName;
+ public override string TypeName => this.Value.TypeName;
- public override string TypeDescription => $"Objectivism object of type: {Value.TypeName}";
+ public override string TypeDescription => $"Objectivism object of type: {this.Value.TypeName}";
+ public override BoundingBox Boundingbox => this.Value.BoundingBox;
- public BoundingBox ClippingBox => Value.ClippingBox;
- public override BoundingBox Boundingbox => Value.BoundingBox;
+ public BoundingBox ClippingBox => this.Value.ClippingBox;
- public override IGH_Goo Duplicate()
- {
- return new GH_ObjectivismObject(this.Value);
- }
- public override IGH_GeometricGoo DuplicateGeometry()
- {
- return new GH_ObjectivismObject(this.Value);
- }
+ public void DrawViewportWires( GH_PreviewWireArgs args ) => this.Value.DrawViewportWires( args );
- public override string ToString()
- {
- return $"{Value.TypeName} object";
- }
+ public void DrawViewportMeshes( GH_PreviewMeshArgs args ) => this.Value.DrawViewportMeshes( args );
- public GH_ObjectivismObject(ObjectivismObject value)
- {
- Value = value;
- }
- public GH_ObjectivismObject()
- {
- Value = null;
- }
- public GH_ObjectivismObject(GH_ObjectivismObject other)
- {
- Value = other.Value;
- }
+ public void AppendRenderGeometry( GH_RenderArgs args, RenderMaterial material ) =>
+ this.Value.AppendRenderGeometry( args, material );
- public override bool Read(GH_IReader reader)
+ public override bool Read( GH_IReader reader )
{
var value = new ObjectivismObject();
- value.GH_Read(reader);
- Value = value;
+ value.GH_Read( reader );
+ this.Value = value;
return true;
}
- public override bool Write(GH_IWriter writer)
+
+ public override bool Write( GH_IWriter writer )
{
try
{
- Value.GH_Write(writer);
+ this.Value.GH_Write( writer );
return true;
}
- catch (Exception e)
+ catch ( Exception e )
{
- writer.SetString("Oh Dear", "An Exception Occured");
- writer.SetString("Exception Message", e.Message);
- writer.SetString("Stack Trace", e.StackTrace);
- writer.SetString("Exception Type", e.GetType().FullName);
- writer.SetString("TargetSite", e.TargetSite.ToString());
+ writer.SetString( "Oh Dear", "An Exception Occured" );
+ writer.SetString( "Exception Message", e.Message );
+ writer.SetString( "Stack Trace", e.StackTrace );
+ writer.SetString( "Exception Type", e.GetType().FullName );
+ writer.SetString( "TargetSite", e.TargetSite.ToString() );
return true;
}
}
- public void DrawViewportWires(GH_PreviewWireArgs args)
- {
- Value.DrawViewportWires(args);
- }
+ public override IGH_Goo Duplicate() => new GH_ObjectivismObject( this.Value );
- public void DrawViewportMeshes(GH_PreviewMeshArgs args)
- {
- Value.DrawViewportMeshes(args);
- }
+ public override IGH_GeometricGoo DuplicateGeometry() => new GH_ObjectivismObject( this.Value );
- public void AppendRenderGeometry(GH_RenderArgs args, RenderMaterial material)
- {
- Value.AppendRenderGeometry(args, material);
- }
+ public override string ToString() => $"{this.Value.TypeName} object";
- public override bool CastFrom(object source)
+ public override bool CastFrom( object source )
{
- if (source == null) { return false; }
- if (source is GH_ObjectivismObject gh_obj)
+ if ( source == null ) { return false; }
+
+ if ( source is GH_ObjectivismObject ghObject )
{
- this.Value = gh_obj.Value;
+ this.Value = ghObject.Value;
return true;
}
- if (source is GH_Goo goo)
+
+ if ( source is GH_Goo goo )
{
this.Value = goo.Value;
return true;
}
- if (source is ObjectivismObject obj2)
+
+ if ( source is ObjectivismObject obj2 )
{
this.Value = obj2;
return true;
}
+
return false;
}
- public override BoundingBox GetBoundingBox(Transform xform)
- {
- return Value.Transform(xform).BoundingBox;
- }
+ public override BoundingBox GetBoundingBox( Transform xform ) => this.Value.Transform( xform ).BoundingBox;
- public override IGH_GeometricGoo Transform(Transform xform)
- {
- return new GH_ObjectivismObject(Value.Transform(xform));
- }
+ public override IGH_GeometricGoo Transform( Transform xform ) =>
+ new GH_ObjectivismObject( this.Value.Transform( xform ) );
- public override IGH_GeometricGoo Morph(SpaceMorph xmorph)
- {
- return new GH_ObjectivismObject(Value.Morph(xmorph));
- }
+ public override IGH_GeometricGoo Morph( SpaceMorph xmorph ) =>
+ new GH_ObjectivismObject( this.Value.Morph( xmorph ) );
- public override object ScriptVariable()
- {
- return Value.ToDynamic();
- }
+ public override object ScriptVariable() => this.Value.ToDynamic();
}
-}
+}
\ No newline at end of file
diff --git a/ObjectivismGH/ObjectClasses/ObjectProperty.cs b/ObjectivismGH/ObjectClasses/ObjectProperty.cs
index d423aa0..9cf13b8 100644
--- a/ObjectivismGH/ObjectClasses/ObjectProperty.cs
+++ b/ObjectivismGH/ObjectClasses/ObjectProperty.cs
@@ -9,187 +9,194 @@
using static Objectivism.DeReferenceGeometryUtil;
using static Objectivism.Util;
-
-namespace Objectivism
+namespace Objectivism.ObjectClasses
{
- enum PropertyAccess { Item, List, Tree }
public class ObjectProperty : IGH_RenderAwareData, IGH_PreviewData
{
+ public ObjectProperty()
+ {
+ this.Data = new GH_Structure();
+ this.Access = PropertyAccess.Item;
+ }
+
+ public ObjectProperty( IGH_Goo item )
+ {
+ this.Data = new GH_Structure();
+ var item2 = this.DeReferenceIfRequired( item );
+ this.Data.Append( item2 );
+ this.Access = PropertyAccess.Item;
+ }
+
+ public ObjectProperty( List list )
+ {
+ this.Data = new GH_Structure();
+ var list2 = list.Select( this.DeReferenceIfRequired ).ToList();
+ this.Data.AppendRange( list2 );
+ this.Access = PropertyAccess.List;
+ }
+
+ public ObjectProperty( GH_Structure tree )
+ {
+ var tree2 = tree.MapTree( this.DeReferenceIfRequired );
+ this.Data = tree2;
+ this.Access = PropertyAccess.Tree;
+ }
+
+ internal ObjectProperty( GH_Structure tree, PropertyAccess access )
+ {
+ var tree2 = tree.MapTree( this.DeReferenceIfRequired );
+ this.Data = tree2;
+ this.Access = access;
+ }
+
+ public ObjectProperty( ObjectProperty other )
+ {
+ this.Access = other.Access;
+ this.Data = other.Data.MapTree( this.DuplicateUtil );
+ }
+
public bool PreviewOn { get; internal set; } = true;
public GH_Structure Data { get; private set; }
internal PropertyAccess Access { get; private set; }
+
public BoundingBox BoundingBox
{
get
{
- if (HasGeometry && PreviewOn)
+ if ( this.HasGeometry && this.PreviewOn )
{
var boxes = new List();
- foreach (var goo in Data)
+ foreach ( var goo in this.Data )
{
- if (goo is IGH_GeometricGoo geom)
+ if ( goo is IGH_GeometricGoo geom )
{
- boxes.Add(geom.Boundingbox);
+ boxes.Add( geom.Boundingbox );
}
}
- return UnionBoxes(boxes);
- }
- else
- {
- return default;
+
+ return UnionBoxes( boxes );
}
+
+ return default;
}
}
- public bool HasGeometry => Data.Any(goo => goo is IGH_GeometricGoo);
- public BoundingBox ClippingBox => BoundingBox;
- public ObjectProperty()
+ public bool HasGeometry => this.Data.Any( goo => goo is IGH_GeometricGoo );
+ public BoundingBox ClippingBox => this.BoundingBox;
+
+ public void DrawViewportWires( GH_PreviewWireArgs args )
{
- Data = new GH_Structure();
- Access = PropertyAccess.Item;
+ if ( !this.PreviewOn )
+ {
+ return;
+ }
+ foreach ( var goo in this.Data )
+ {
+ if ( goo is IGH_PreviewData previewGoo )
+ {
+ previewGoo.DrawViewportWires( args );
+ }
+ }
}
- public ObjectProperty(IGH_Goo item)
- {
- Data = new GH_Structure();
- var item2 = DeReferenceIfRequired(item);
- Data.Append(item2);
- Access = PropertyAccess.Item;
- }
- public ObjectProperty(List list)
+ public void DrawViewportMeshes( GH_PreviewMeshArgs args )
{
- Data = new GH_Structure();
- var list2 = list.Select(goo => DeReferenceIfRequired(goo)).ToList();
- Data.AppendRange(list2);
- Access = PropertyAccess.List;
- }
+ if ( !this.PreviewOn )
+ {
+ return;
+ }
- public ObjectProperty(GH_Structure tree)
- {
- var tree2 = tree.MapTree(DeReferenceIfRequired);
- Data = tree2;
- Access = PropertyAccess.Tree;
+ foreach ( var goo in this.Data )
+ {
+ if ( goo is IGH_PreviewData previewGoo )
+ {
+ previewGoo.DrawViewportMeshes( args );
+ }
+ }
}
- internal ObjectProperty(GH_Structure tree, PropertyAccess access)
+ public void AppendRenderGeometry( GH_RenderArgs args, RenderMaterial material )
{
- var tree2 = tree.MapTree(DeReferenceIfRequired);
- Data = tree2;
- Access = access;
- }
+ if ( !this.PreviewOn )
+ {
+ return;
+ }
- public ObjectProperty(ObjectProperty other)
- {
- Access = other.Access;
- Data = other.Data.MapTree(DuplicateUtil);
+ foreach ( var goo in this.Data )
+ {
+ if ( goo is IGH_RenderAwareData renderGoo )
+ {
+ renderGoo.AppendRenderGeometry( args, material );
+ }
+ }
}
- private IGH_Goo DeReferenceIfRequired(IGH_Goo goo)
+ private IGH_Goo DeReferenceIfRequired( IGH_Goo goo )
{
- if (goo is IGH_GeometricGoo geom)
+ if ( goo is IGH_GeometricGoo geom )
{
- return DeReferenceWhereRequired(geom);
+ return DeReferenceWhereRequired( geom );
}
+
return goo;
}
-
- private IGH_Goo DuplicateUtil(IGH_Goo goo)
+ private IGH_Goo DuplicateUtil( IGH_Goo goo )
{
- if (goo is IGH_GeometricGoo geom)
+ if ( goo is IGH_GeometricGoo geom )
{
return geom.DuplicateGeometry();
}
- if (goo != null)
- {
- return goo.Duplicate();
- }
- else { return goo; }
+
+ return goo?.Duplicate();
}
- public bool WriteProp(GH_IWriter writer)
+ public bool WriteProp( GH_IWriter writer )
{
- writer.SetTree("PropertyDataTree", Data);
- writer.SetInt32("Access", (int)Access);
- writer.SetBoolean("PreviewToggle", PreviewOn);
+ writer.SetTree( "PropertyDataTree", this.Data );
+ writer.SetInt32( "Access", (int) this.Access );
+ writer.SetBoolean( "PreviewToggle", this.PreviewOn );
return true;
}
- public bool ReadProp(GH_IReader reader)
+ public bool ReadProp( GH_IReader reader )
{
- Data = reader.GetTree("PropertyDataTree");
- Access = (PropertyAccess)reader.GetInt32("Access");
+ this.Data = reader.GetTree( "PropertyDataTree" );
+ this.Access = (PropertyAccess) reader.GetInt32( "Access" );
try
{
- PreviewOn = reader.GetBoolean("PreviewToggle");
+ this.PreviewOn = reader.GetBoolean( "PreviewToggle" );
}
catch
{
- PreviewOn = true;
+ this.PreviewOn = true;
}
- return true;
- }
- public ObjectProperty Transform(Transform xform)
- {
- var newData = Data.MapTree(TransformUtil, xform);
- return new ObjectProperty(newData, this.Access);
- }
- public ObjectProperty Morph(SpaceMorph morph)
- {
- var newData = Data.MapTree(MorphUtil, morph);
- return new ObjectProperty(newData, this.Access);
+ return true;
}
- public static IGH_Goo TransformUtil(IGH_Goo item, Transform xform)
- {
- return item is IGH_GeometricGoo geom
- ? geom.DuplicateGeometry().Transform(xform)
- : item;
- }
- public static IGH_Goo MorphUtil(IGH_Goo item, SpaceMorph morph)
+ public ObjectProperty Transform( Transform xform )
{
- return item is IGH_GeometricGoo geom
- ? geom.DuplicateGeometry().Morph(morph)
- : item;
+ var newData = this.Data.MapTree( TransformUtil, xform );
+ return new ObjectProperty( newData, this.Access );
}
- public void AppendRenderGeometry(GH_RenderArgs args, RenderMaterial material)
+ public ObjectProperty Morph( SpaceMorph morph )
{
- if (!PreviewOn) return;
- foreach (var goo in Data)
- {
- if (goo is IGH_RenderAwareData renderGoo)
- {
- renderGoo.AppendRenderGeometry(args, material);
- }
- }
+ var newData = this.Data.MapTree( MorphUtil, morph );
+ return new ObjectProperty( newData, this.Access );
}
- public void DrawViewportWires(GH_PreviewWireArgs args)
- {
- if (!PreviewOn) return;
- foreach (var goo in Data)
- {
- if (goo is IGH_PreviewData previewGoo)
- {
- previewGoo.DrawViewportWires(args);
- }
- }
- }
+ public static IGH_Goo TransformUtil( IGH_Goo item, Transform xform ) =>
+ item is IGH_GeometricGoo geom
+ ? geom.DuplicateGeometry().Transform( xform )
+ : item;
- public void DrawViewportMeshes(GH_PreviewMeshArgs args)
- {
- if (!PreviewOn) return;
- foreach (var goo in Data)
- {
- if (goo is IGH_PreviewData previewGoo)
- {
- previewGoo.DrawViewportMeshes(args);
- }
- }
- }
+ public static IGH_Goo MorphUtil( IGH_Goo item, SpaceMorph morph ) =>
+ item is IGH_GeometricGoo geom
+ ? geom.DuplicateGeometry().Morph( morph )
+ : item;
}
-}
+}
\ No newline at end of file
diff --git a/ObjectivismGH/ObjectClasses/ObjectivismObject.cs b/ObjectivismGH/ObjectClasses/ObjectivismObject.cs
index b9dac72..54d7137 100644
--- a/ObjectivismGH/ObjectClasses/ObjectivismObject.cs
+++ b/ObjectivismGH/ObjectClasses/ObjectivismObject.cs
@@ -1,4 +1,5 @@
using GH_IO.Serialization;
+using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
using Rhino.Geometry;
@@ -7,198 +8,215 @@
using System.Dynamic;
using System.Linq;
-namespace Objectivism
+namespace Objectivism.ObjectClasses
{
public class ObjectivismObject : IGH_PreviewData, IGH_RenderAwareData
{
- private List<(string Name, ObjectProperty Property)> properties;
- private Dictionary propertyGetter;
+ private BoundingBox _boxCache;
+ private bool _boxIsCached;
+ private List<(string Name, ObjectProperty Property)> _properties;
+ private Dictionary _propertyGetter;
- public List AllProperties => this.properties.Select(x => x.Name).ToList();
+ public ObjectivismObject()
+ {
+ this.TypeName = "Objectivism Object";
+ }
+
+
+ public ObjectivismObject( List<(string Name, ObjectProperty Property)> props, string typeName )
+ {
+ this.TypeName = typeName;
+ this._properties = props;
+ this._propertyGetter = props
+ .Select( ( p, i ) => (p.Name, i) )
+ .ToDictionary( t => t.Name, t => t.i );
+ }
+
+ public ObjectivismObject( ObjectivismObject obj )
+ {
+ this.TypeName = obj.TypeName;
+ this._properties = obj._properties.Select( pair => (pair.Name, new ObjectProperty( pair.Property )) )
+ .ToList();
+ this._propertyGetter = new Dictionary( obj._propertyGetter );
+ }
+
+ public List AllProperties => this._properties.Select( x => x.Name ).ToList();
public string TypeName { get; private set; }
- private BoundingBox boxCache;
- private bool boxIsCached = false;
+
public BoundingBox BoundingBox
{
get
{
- if (boxIsCached)
+ if ( this._boxIsCached )
{
- return boxCache;
+ return this._boxCache;
}
- var boxes = properties
- .Select(pair => pair.Property)
- .Where(p => p.HasGeometry)
- .Select(p => p.BoundingBox)
+
+ var boxes = this._properties
+ .Select( pair => pair.Property )
+ .Where( p => p.HasGeometry )
+ .Select( p => p.BoundingBox )
.ToList();
- boxCache = Util.UnionBoxes(boxes);
- boxIsCached = true;
- return boxCache;
+ this._boxCache = Util.UnionBoxes( boxes );
+ this._boxIsCached = true;
+ return this._boxCache;
}
}
- public BoundingBox ClippingBox => BoundingBox;
+ public BoundingBox ClippingBox => this.BoundingBox;
- public ObjectivismObject()
- {
- this.TypeName = "Objectivism Object";
- }
+ public void DrawViewportWires( GH_PreviewWireArgs args ) =>
+ this._properties.ForEach( prop => prop.Property.DrawViewportWires( args ) );
+ public void DrawViewportMeshes( GH_PreviewMeshArgs args ) =>
+ this._properties.ForEach( prop => prop.Property.DrawViewportMeshes( args ) );
- public ObjectivismObject(List<(string Name, ObjectProperty Property)> props, string typeName)
- {
- TypeName = typeName;
- properties = props;
- propertyGetter = props
- .Select((p, i) => (p.Name, i))
- .ToDictionary(t => t.Name, t => t.i);
- }
- public ObjectivismObject(ObjectivismObject obj)
- {
- TypeName = obj.TypeName;
- properties = obj.properties.Select(pair => (pair.Name, new ObjectProperty(pair.Property))).ToList();
- propertyGetter = new Dictionary(obj.propertyGetter);
- }
+ public void AppendRenderGeometry( GH_RenderArgs args, RenderMaterial material ) =>
+ this._properties.ForEach( prop => prop.Property.AppendRenderGeometry( args, material ) );
- public bool HasProperty(string name)
- {
- return propertyGetter.ContainsKey(name);
- }
+ public bool HasProperty( string name ) => this._propertyGetter.ContainsKey( name );
- internal bool HasProperty(string name, PropertyAccess access)
+ internal bool HasProperty( string name, PropertyAccess access )
{
- if (TryGetProperty(name, out var property))
+ if ( this.TryGetProperty( name, out var property ) )
{
return property.Access == access;
}
+
return false;
}
- internal bool Implements(ObjectivismObject template)
- {
- return template.properties.All(prop => this.HasProperty(prop.Name, prop.Property.Access));
- }
+ internal bool Implements( ObjectivismObject template ) =>
+ template._properties.All( prop => this.HasProperty( prop.Name, prop.Property.Access ) );
- public bool TryGetProperty(string name, out ObjectProperty property)
+ public bool TryGetProperty( string name, out ObjectProperty property )
{
property = null;
- if (propertyGetter.ContainsKey(name))
+
+ if ( this._propertyGetter.TryGetValue( name, out var propertyIndex ) )
{
- property = properties[propertyGetter[name]].Property;
+ property = this._properties[propertyIndex].Property;
return true;
}
+
return false;
}
- public ObjectProperty GetProperty(string name)
+ public ObjectProperty GetProperty( string name )
{
- if (propertyGetter.ContainsKey(name))
+ if ( this._propertyGetter.TryGetValue( name, out var propertyIndex ) )
{
- return properties[propertyGetter[name]].Property;
- }
- else
- {
- return null;
+ return this._properties[propertyIndex].Property;
}
+
+ return null;
}
- internal (ObjectivismObject obj, AccessInfo conflicts) AddOrChangeProperties(List<(string name, ObjectProperty newProperty)> changes) =>
- AddOrChangeProperties(changes, this.TypeName);
+ internal (ObjectivismObject obj, AccessInfo conflicts) AddOrChangeProperties(
+ List<(string name, ObjectProperty newProperty)> changes ) =>
+ this.AddOrChangeProperties( changes, this.TypeName );
- internal (ObjectivismObject obj, AccessInfo conflicts) AddOrChangeProperties(List<(string name, ObjectProperty newProperty)> changes, string newName)
+ internal (ObjectivismObject obj, AccessInfo conflicts) AddOrChangeProperties(
+ List<(string name, ObjectProperty newProperty)> changes, string newName )
{
- var newObj = new ObjectivismObject(this);
- newObj.TypeName = newName;
- var numberOfExistingProps = newObj.properties.Count;
- AccessInfo accessInfo = new AccessInfo();
- foreach ((string name, var newProp) in changes)
+ var newObj = new ObjectivismObject( this ) { TypeName = newName };
+ var numberOfExistingProps = newObj._properties.Count;
+ var accessInfo = new AccessInfo();
+ foreach ( var (name, newProp) in changes )
{
-
- if (newObj.propertyGetter.ContainsKey(name))
+ if ( newObj._propertyGetter.ContainsKey( name ) )
{
- var currentAccess = newObj.GetProperty(name).Access;
+ var currentAccess = newObj.GetProperty( name ).Access;
var newAccess = newProp.Access;
- if (newAccess != currentAccess)
+ if ( newAccess != currentAccess )
{
- accessInfo.AddConflict(name);
+ accessInfo.AddConflict( name );
}
- newObj.properties[propertyGetter[name]] = (name, newProp);
+
+ newObj._properties[this._propertyGetter[name]] = (name, newProp);
}
else
{
- newObj.properties.Add((name, newProp));
- newObj.propertyGetter.Add(name, numberOfExistingProps);
+ newObj._properties.Add( (name, newProp) );
+ newObj._propertyGetter.Add( name, numberOfExistingProps );
numberOfExistingProps++;
}
}
+
return (newObj, accessInfo);
}
- internal ObjectivismObject AddProperties(List<(string name, ObjectProperty newProperty)> additions)
+
+ internal ObjectivismObject AddProperties( List<(string name, ObjectProperty newProperty)> additions )
{
- var newObj = new ObjectivismObject(this);
- var numberOfExistingProps = newObj.properties.Count;
- foreach (var addition in additions)
+ var newObj = new ObjectivismObject( this );
+ var numberOfExistingProps = newObj._properties.Count;
+ foreach ( var addition in additions )
{
- newObj.properties.Add(addition);
- newObj.propertyGetter.Add(addition.name, numberOfExistingProps);
+ newObj._properties.Add( addition );
+ newObj._propertyGetter.Add( addition.name, numberOfExistingProps );
numberOfExistingProps++;
}
+
return newObj;
}
- public ObjectivismObject Transform(Transform xform)
+
+ public ObjectivismObject Transform( Transform xform )
{
- var newObj = new ObjectivismObject(this);
- newObj.properties = newObj.properties
- .Select(p => (p.Name, p.Property.Transform(xform)))
+ var newObj = new ObjectivismObject( this );
+ newObj._properties = newObj._properties
+ .Select( p => (p.Name, p.Property.Transform( xform )) )
.ToList();
return newObj;
}
- public ObjectivismObject Morph(SpaceMorph xmorph)
+
+ public ObjectivismObject Morph( SpaceMorph xmorph )
{
- var newObj = new ObjectivismObject(this);
- newObj.properties = newObj.properties
- .Select(p => (p.Name, p.Property.Morph(xmorph)))
+ var newObj = new ObjectivismObject( this );
+ newObj._properties = newObj._properties
+ .Select( p => (p.Name, p.Property.Morph( xmorph )) )
.ToList();
return newObj;
-
}
- public bool GH_Write(GH_IWriter writer)
+
+ public bool GH_Write( GH_IWriter writer )
{
- writer.SetString("ObjectTypeName", TypeName);
+ writer.SetString( "ObjectTypeName", this.TypeName );
- writer.SetInt32("NumberOfProperties", properties.Count);
- var nameWriter = writer.CreateChunk("Names");
- int i = 0;
- foreach (var pair in properties)
+ writer.SetInt32( "NumberOfProperties", this._properties.Count );
+ var nameWriter = writer.CreateChunk( "Names" );
+ var i = 0;
+ foreach ( var pair in this._properties )
{
- nameWriter.SetString("Name", i, pair.Name);
- var propWriter = nameWriter.CreateChunk("Prop", i);
- pair.Property.WriteProp(propWriter);
+ nameWriter.SetString( "Name", i, pair.Name );
+ var propWriter = nameWriter.CreateChunk( "Prop", i );
+ pair.Property.WriteProp( propWriter );
i++;
}
+
return true;
}
- public bool GH_Read(GH_IReader reader)
+ public bool GH_Read( GH_IReader reader )
{
try
{
- this.TypeName = reader.GetString("ObjectTypeName");
- this.properties = new List<(string Name, ObjectProperty Property)>();
- this.propertyGetter = new Dictionary();
- int count = reader.GetInt32("NumberOfProperties");
- var nameReader = reader.FindChunk("Names");
- for (int i = 0; i < count; i++)
+ this.TypeName = reader.GetString( "ObjectTypeName" );
+ this._properties = new List<(string Name, ObjectProperty Property)>();
+ this._propertyGetter = new Dictionary();
+ var count = reader.GetInt32( "NumberOfProperties" );
+ var nameReader = reader.FindChunk( "Names" );
+ for ( var i = 0; i < count; i++ )
{
- string name = nameReader.GetString("Name", i);
+ var name = nameReader.GetString( "Name", i );
var prop = new ObjectProperty();
- var propReader = nameReader.FindChunk("Prop", i);
- prop.ReadProp(propReader);
- properties.Add((name, prop));
- propertyGetter.Add(name, i);
+ var propReader = nameReader.FindChunk( "Prop", i );
+ prop.ReadProp( propReader );
+ this._properties.Add( (name, prop) );
+ this._propertyGetter.Add( name, i );
}
+
return true;
}
catch
@@ -207,73 +225,67 @@ public bool GH_Read(GH_IReader reader)
}
}
- public void DrawViewportWires(GH_PreviewWireArgs args)
- {
- properties.ForEach(prop => prop.Property.DrawViewportWires(args));
- }
-
- public void DrawViewportMeshes(GH_PreviewMeshArgs args)
- {
- properties.ForEach(prop => prop.Property.DrawViewportMeshes(args));
- }
-
- public void AppendRenderGeometry(GH_RenderArgs args, RenderMaterial material)
- {
- properties.ForEach(prop => prop.Property.AppendRenderGeometry(args, material));
- }
-
internal dynamic ToDynamic()
{
var eo = new ExpandoObject();
- var eoColl = (ICollection>)eo;
- foreach (var pair in properties)
+ var eoColl = (ICollection>) eo;
+ foreach ( var pair in this._properties )
{
var name = pair.Name.SpacesToUnderscores();
var prop = pair.Property;
- if (prop.Access == PropertyAccess.Item)
- {
- var item = prop != null
- ? ProcessGoo(prop.Data.get_FirstItem(false))
- : null;
- eoColl.Add(new KeyValuePair(name, item));
- }
- if (prop.Access == PropertyAccess.List)
+
+ // TODO: Review null handling.
+ // I've added the following null test. The original code is in the `else` branch. The original code
+ // checks prop.Access, then tests prop for null. If prop is null, prop.Access will throw. If
+ // empty List or DataTree are required, PropertyAccess must be stored separately.
+
+ if ( prop == null )
{
- var list = prop != null
- ? prop.Data.Branches[0].Select(ProcessGoo).ToList()
- : new List