From acb107e3e634ebda697cd79b3844095612f5355a Mon Sep 17 00:00:00 2001 From: Tom Glastonbury Date: Mon, 17 Jun 2024 14:30:53 +0100 Subject: [PATCH 1/8] Existing code style is a bit inconsistent. Added what are (IMHO) good default rules. --- .editorconfig | 594 ++++++++++++++++++++++++++++++++++++++++ CommonStyle.DotSettings | 403 +++++++++++++++++++++++++++ 2 files changed, 997 insertions(+) create mode 100644 .editorconfig create mode 100644 CommonStyle.DotSettings 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/CommonStyle.DotSettings b/CommonStyle.DotSettings new file mode 100644 index 0000000..91bc6b7 --- /dev/null +++ b/CommonStyle.DotSettings @@ -0,0 +1,403 @@ + + 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 + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + \ No newline at end of file From c0f6dea2a1004a3c1a1b2fb35f1aa333cd444ae1 Mon Sep 17 00:00:00 2001 From: Tom Glastonbury Date: Mon, 17 Jun 2024 14:31:27 +0100 Subject: [PATCH 2/8] Cleaup/formatting. --- .../AddOrChangePropertiesComponent.cs | 266 +++++++------ .../Components/ComponentUtil/AccessChecker.cs | 68 ++-- .../Components/ComponentUtil/DataUtil.cs | 40 +- .../Components/CreateObjectComponent.cs | 170 ++++---- ObjectivismGH/Components/FilterByType.cs | 189 ++++----- ObjectivismGH/Components/FilterByTypeV2.cs | 189 ++++----- .../Components/GetPropertiesComponent.cs | 338 ++++++++-------- .../Components/ImplementsComponent.cs | 64 +-- ObjectivismGH/Components/InheritComponent.cs | 280 +++++++------- ObjectivismGH/Components/ObjectToTree.cs | 171 ++++---- ObjectivismGH/DeReferenceGeometryUtil.cs | 47 +-- .../Forms/ChangePropertyNameForm.Designer.cs | 24 +- ObjectivismGH/Forms/ChangePropertyNameForm.cs | 364 +++++++++--------- .../ObjectClasses/GH_ObjectivismObject.cs | 135 +++---- ObjectivismGH/ObjectClasses/ObjectProperty.cs | 239 ++++++------ .../ObjectClasses/ObjectivismObject.cs | 289 +++++++------- ObjectivismGH/ObjectivismInfo.cs | 66 +--- ObjectivismGH/Parameters/IHasPreviewToggle.cs | 2 +- .../Parameters/Param_ExtraObjectProperty.cs | 160 ++++---- .../Parameters/Param_NewObjectProperty.cs | 142 ++++--- .../Parameters/Param_ObjectivismOutput.cs | 84 ++-- ObjectivismGH/Util.cs | 161 ++++---- 22 files changed, 1689 insertions(+), 1799 deletions(-) diff --git a/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs b/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs index c213314..9dcb300 100644 --- a/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs +++ b/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs @@ -2,235 +2,233 @@ using Grasshopper.Kernel.Parameters; using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Windows.Forms; using static Objectivism.DataUtil; + namespace Objectivism { 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 ) { + var param = new Param_ExtraObjectProperty + { + Name = "PropertyToChange", + nickNameCache = string.Empty, + NickName = string.Empty, + Description = this._description + }; + return param; } + 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.AllPropertyNames = 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(); + 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) + protected override void SolveInstance( IGH_DataAccess DA ) { - 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 ( !DA.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)); - - } + var updates = new List<(string Name, ObjectProperty Property)>(); - 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; - } - - 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( RetrieveProperties( DA, i, this ) ); } - 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 ); + DA.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", UpdateObjectEventHandler); - } + public override void AppendAdditionalMenuItems( ToolStripDropDown menu ) => + Menu_AppendItem( menu, "Recompute", this.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 index 6d237e9..dffd69c 100644 --- a/ObjectivismGH/Components/ComponentUtil/AccessChecker.cs +++ b/ObjectivismGH/Components/ComponentUtil/AccessChecker.cs @@ -1,73 +1,73 @@ using Grasshopper.Kernel; using System.Collections.Generic; + namespace Objectivism { - class AccessChecker + internal class AccessChecker { - private Dictionary accessRecorder; - private HashSet warningsToThrow; + private readonly Dictionary _accessRecorder; - private IGH_Component hostRef; + private readonly IGH_Component _hostRef; + private readonly HashSet _warningsToThrow; - public AccessChecker(IGH_Component @this) + public AccessChecker( IGH_Component @this ) { - this.accessRecorder = new Dictionary(); - this.warningsToThrow = new HashSet(); - this.hostRef = @this; + this._accessRecorder = new Dictionary(); + this._warningsToThrow = new HashSet(); + this._hostRef = @this; } - public void AccessCheck(ObjectProperty prop, string name) + public void AccessCheck( ObjectProperty prop, string name ) { - if (accessRecorder.ContainsKey(name)) + if ( this._accessRecorder.ContainsKey( name ) ) { - if (accessRecorder[name] != prop.Access) + if ( this._accessRecorder[name] != prop.Access ) { - warningsToThrow.Add(name); + this._warningsToThrow.Add( name ); } } else { - accessRecorder.Add(name, prop.Access); + this._accessRecorder.Add( name, prop.Access ); } } public void ThrowWarnings() { - foreach (var name in warningsToThrow) + foreach ( var name in this._warningsToThrow ) { - hostRef.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Access not consistent for {name} property. Output data tree may be messy and not consistent"); + 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) + public PropertyAccess BestGuessAccess( string name ) { - if (accessRecorder.ContainsKey(name)) + if ( this._accessRecorder.ContainsKey( name ) ) { - return accessRecorder[name]; + return this._accessRecorder[name]; } - else - { - try + try + { + var data = this._hostRef.Params.Input[0].VolatileData.AllData( true ); + foreach ( var goo in data ) { - var data = hostRef.Params.Input[0].VolatileData.AllData(true); - foreach (var goo in data) + if ( goo is GH_ObjectivismObject ghObj ) { - if (goo is GH_ObjectivismObject ghObj) + if ( ghObj.Value.HasProperty( name ) ) { - if (ghObj.Value.HasProperty(name)) - { - return ghObj.Value.GetProperty(name).Access; - } + return ghObj.Value.GetProperty( name ).Access; } } - return PropertyAccess.Item; - } - catch - { - return PropertyAccess.Item; } + + return PropertyAccess.Item; + } + catch + { + return PropertyAccess.Item; } } } -} +} \ No newline at end of file diff --git a/ObjectivismGH/Components/ComponentUtil/DataUtil.cs b/ObjectivismGH/Components/ComponentUtil/DataUtil.cs index 1d67186..4f8e6b5 100644 --- a/ObjectivismGH/Components/ComponentUtil/DataUtil.cs +++ b/ObjectivismGH/Components/ComponentUtil/DataUtil.cs @@ -6,54 +6,60 @@ namespace Objectivism { - static class DataUtil + internal static class DataUtil { - internal static (string Name, ObjectProperty Property) RetrieveProperties(IGH_DataAccess DA, int paramIndex, IGH_Component @this) + internal static (string Name, ObjectProperty Property) RetrieveProperties( IGH_DataAccess DA, int paramIndex, + IGH_Component @this ) { - bool previewOn = true; + var previewOn = true; var param = @this.Params.Input[paramIndex]; - if (param is IHasPreviewToggle hasPreviewToggle) + if ( param is IHasPreviewToggle hasPreviewToggle ) { previewOn = hasPreviewToggle.PreviewOn; } ObjectProperty prop; var name = param.NickName; - if (param.Access == GH_ParamAccess.item) + if ( param.Access == GH_ParamAccess.item ) { IGH_Goo item = null; - if (!DA.GetData(paramIndex, ref item)) + if ( !DA.GetData( paramIndex, ref item ) ) { - @this.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, $"{name} has no input and has been assigned null data"); + @this.AddRuntimeMessage( GH_RuntimeMessageLevel.Remark, + $"{name} has no input and has been assigned null data" ); } - prop = new ObjectProperty(item); + + prop = new ObjectProperty( item ); } - else if (param.Access == GH_ParamAccess.list) + else if ( param.Access == GH_ParamAccess.list ) { var items = new List(); - DA.GetDataList(paramIndex, items); - prop = new ObjectProperty(items); + DA.GetDataList( paramIndex, items ); + prop = new ObjectProperty( items ); } else //tree access { - DA.GetDataTree(paramIndex, out GH_Structure itemTree); - prop = new ObjectProperty(itemTree); + 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) + 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) + if ( !DA.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/Components/CreateObjectComponent.cs b/ObjectivismGH/Components/CreateObjectComponent.cs index b480777..359ba8a 100644 --- a/ObjectivismGH/Components/CreateObjectComponent.cs +++ b/ObjectivismGH/Components/CreateObjectComponent.cs @@ -1,6 +1,7 @@ using Grasshopper.Kernel; using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Windows.Forms; using static Objectivism.DataUtil; @@ -8,159 +9,134 @@ namespace Objectivism { - internal interface IHasMultipleTypes { HashSet TypeNames { get; } } + public class CreateObjectComponent : GH_Component, IGH_VariableParameterComponent { + private readonly string _defaultNickName = "Property"; + private readonly 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", "Object", + "Encapsulate multiple kinds of data within a single object", + "Sets", "Objectivism" ) { - NickNameCache = this.NickName; + this._nickNameCache = this.NickName; 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() + public bool CanInsertParameter( GH_ParameterSide side, int index ) => side == GH_ParameterSide.Input; + + public bool CanRemoveParameter( GH_ParameterSide side, int index ) => side == GH_ParameterSide.Input; + + public IGH_Param CreateParameter( GH_ParameterSide side, int index ) { - Params.Input.ForEach(CommitParamNames); - base.BeforeSolveInstance(); + var param = new Param_NewObjectProperty { NickName = string.Empty, Access = GH_ParamAccess.item }; + return param; } - private void CommitParamNames(IGH_Param param) + public bool DestroyParameter( GH_ParameterSide side, int index ) => true; + + public void VariableParameterMaintenance() { - if (param is Param_NewObjectProperty p) + var dynamicParams = this.Params.Input.ToList(); + foreach ( var param in dynamicParams ) { - p.CommitNickName(); + param.Optional = true; } - } - - protected override void SolveInstance(IGH_DataAccess DA) - { - var typeName = this.NickName; - NickNameCache = NickName; - var data = new List<(string Name, ObjectProperty Property)>(); - for (int i = 0; i < Params.Input.Count; i++) + var emptyParams = dynamicParams.Where( p => p.NickName == string.Empty ); + foreach ( var param in emptyParams ) { - data.Add(RetrieveProperties(DA, i, this)); + var paramKey = GH_ComponentParamServer.InventUniqueNickname( this._numbers, this.StrippedParamNames() ); + param.NickName = this._defaultNickName + paramKey; } - var obj = new ObjectivismObject(data, typeName); - var ghObj = new GH_ObjectivismObject(obj); - DA.SetData(0, ghObj); } - - - public bool CanInsertParameter(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 bool CanRemoveParameter(GH_ParameterSide side, int index) - { - return side == GH_ParameterSide.Input; - } + protected override void RegisterOutputParams( GH_OutputParamManager pManager ) => + pManager.AddGenericParameter( "Object", "O", "Object that is created", GH_ParamAccess.item ); - public IGH_Param CreateParameter(GH_ParameterSide side, int index) + protected override void BeforeSolveInstance() { - var param = new Param_NewObjectProperty(); - param.NickName = String.Empty; - param.Access = GH_ParamAccess.item; - return param; + this.Params.Input.ForEach( this.CommitParamNames ); + base.BeforeSolveInstance(); } - public bool DestroyParameter(GH_ParameterSide side, int index) + private void CommitParamNames( IGH_Param param ) { - return true; + if ( param is Param_NewObjectProperty p ) + { + p.CommitNickName(); + } } - public void VariableParameterMaintenance() + + protected override void SolveInstance( IGH_DataAccess DA ) { - var dynamicParams = Params.Input.ToList(); - foreach (var param in dynamicParams) - { - param.Optional = true; - } - var emptyParams = dynamicParams.Where(p => p.NickName == String.Empty); - foreach (var param in emptyParams) + 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( RetrieveProperties( DA, i, this ) ); } + + var obj = new ObjectivismObject( data, typeName ); + var ghObj = new GH_ObjectivismObject( obj ); + DA.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.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 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..0f47455 100644 --- a/ObjectivismGH/Components/FilterByType.cs +++ b/ObjectivismGH/Components/FilterByType.cs @@ -3,6 +3,7 @@ using Grasshopper.Kernel.Types; using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Windows.Forms; @@ -10,192 +11,172 @@ namespace Objectivism.Components { public class FilterByTypeOBSOLETE : 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") + : 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.AllPropertyNames = 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 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; } 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) + protected override void SolveInstance( IGH_DataAccess DA ) { IGH_Goo goo = null; - if (!DA.GetData(0, ref goo)) + if ( !DA.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) + var name = param.NickName; + if ( obj.Value.TypeName == name ) { - DA.SetData(i, obj); + DA.SetData( i, obj ); } else { - DA.SetData(i, null); + 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; - } - - 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(); + foreach ( var name in unusedNames ) { 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; - } + this.VariableParameterMaintenance(); + this.Params.OnParametersChanged(); + this.ExpireSolution( true ); } - /// - /// 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"); } - } + private void UpdateObjectEventHandler( object sender, EventArgs e ) => this.ExpireSolution( true ); } } \ No newline at end of file diff --git a/ObjectivismGH/Components/FilterByTypeV2.cs b/ObjectivismGH/Components/FilterByTypeV2.cs index b93411f..de6c4a1 100644 --- a/ObjectivismGH/Components/FilterByTypeV2.cs +++ b/ObjectivismGH/Components/FilterByTypeV2.cs @@ -3,6 +3,7 @@ using Grasshopper.Kernel.Types; using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Windows.Forms; @@ -11,53 +12,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.AllPropertyNames = 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 ) { - } 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 +103,81 @@ 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) + protected override void SolveInstance( IGH_DataAccess DA ) { IGH_Goo goo = null; - if (!DA.GetData(0, ref goo)) + if ( !DA.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); + DA.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; - } - - 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(); + foreach ( var name in unusedNames ) { 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 + private void UpdateObjectEventHandler( object sender, EventArgs e ) { - 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"); } + //ExpireSolution(true); } - } } \ No newline at end of file diff --git a/ObjectivismGH/Components/GetPropertiesComponent.cs b/ObjectivismGH/Components/GetPropertiesComponent.cs index b24cecd..ff4ec48 100644 --- a/ObjectivismGH/Components/GetPropertiesComponent.cs +++ b/ObjectivismGH/Components/GetPropertiesComponent.cs @@ -5,6 +5,7 @@ using Grasshopper.Kernel.Types; using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Windows.Forms; @@ -12,341 +13,320 @@ namespace Objectivism { 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.AllPropertyNames = 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) + protected override void SolveInstance( IGH_DataAccess DA ) { - IGH_Goo goo = null; - if (!DA.GetData(0, ref goo)) + if ( !DA.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 = DA.ParameterTargetPath( i ); + if ( this._graftItems ) { - int[] index = { DA.ParameterTargetIndex(0) }; - var newPath = new GH_Path(path.Indices.Concat(index).ToArray()); + int[] index = { DA.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 ); + DA.SetDataTree( i, tree ); } else { var tree = new GH_Structure(); - tree.Append(item, path); - DA.SetDataTree(i, tree); + tree.Append( item, path ); + DA.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 = DA.ParameterTargetPath( i ); + int[] index = { DA.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 ); + DA.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 = DA.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 = { DA.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); + + DA.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(); + foreach ( var name in unusedNames ) { 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..6ee30dc 100644 --- a/ObjectivismGH/Components/ImplementsComponent.cs +++ b/ObjectivismGH/Components/ImplementsComponent.cs @@ -1,57 +1,59 @@ using Grasshopper.Kernel; 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 DA ) { - 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 ( !DA.TryGetObjectivsmObject( 0, out var template ) ) + { + return; + } - DA.SetData(0, subject.Implements(template)); - } - - protected override System.Drawing.Bitmap Icon => Resources.implements; + if ( !DA.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; } + DA.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..5af9ea8 100644 --- a/ObjectivismGH/Components/InheritComponent.cs +++ b/ObjectivismGH/Components/InheritComponent.cs @@ -2,6 +2,7 @@ using Grasshopper.Kernel.Parameters; using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Windows.Forms; using static Objectivism.DataUtil; @@ -10,245 +11,240 @@ namespace Objectivism { public class InheritComponent : 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(); + + 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", "NewTypeName", + "Create a new object from a template. Add or change properties as required", + "Sets", "Objectivism" ) { - NickNameCache = this.NickName; + this._nickNameCache = this.NickName; 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 ) + { + var param = new Param_ExtraObjectProperty + { + Name = "PropertyToChange", + nickNameCache = string.Empty, + NickName = string.Empty, + Description = this._description + }; + return param; + } + + 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.AllPropertyNames = 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(); + 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(); + 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 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(); } } - 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) + protected override void SolveInstance( IGH_DataAccess DA ) { var typeName = this.NickName; - NickNameCache = NickName; + this._nickNameCache = this.NickName; - 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 ( !DA.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( RetrieveProperties( DA, i, this ) ); } - 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 ); + DA.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", UpdateObjectEventHandler); - } + public override void AppendAdditionalMenuItems( ToolStripDropDown menu ) => + Menu_AppendItem( menu, "Recompute", this.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..d13e7b6 100644 --- a/ObjectivismGH/Components/ObjectToTree.cs +++ b/ObjectivismGH/Components/ObjectToTree.cs @@ -3,174 +3,171 @@ using Grasshopper.Kernel.Types; 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) + protected override void SolveInstance( IGH_DataAccess DA ) { IGH_Goo goo = null; - if (!DA.GetData(0, ref goo)) + if ( !DA.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( n => this.AddToStoreIfRequired( n ) ); + + 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( DA.ParameterTargetPath( 0 ).Indices ); + path.Add( DA.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( DA.ParameterTargetPath( 0 ).Indices ); + path.Add( DA.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( DA.ParameterTargetPath( 0 ).Indices ); + path.Add( DA.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; - } + DA.SetDataTree( 0, outTree ); + DA.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/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..0ac7a3d 100644 --- a/ObjectivismGH/Forms/ChangePropertyNameForm.cs +++ b/ObjectivismGH/Forms/ChangePropertyNameForm.cs @@ -10,289 +10,283 @@ 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 createParams = this._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 == 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 c ) + .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 ); var count = allParams.Count(); - _paramsToChange = allParams.ToList(); + this._paramsToChange = allParams.ToList(); 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 + .Where( obj => obj is IHasMultipleTypes ) + .Select( obj => (IHasMultipleTypes) obj ) ); + + 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); + && 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 ); var count = allParams.Count(); - _paramsToChange = allParams.ToList(); + this._paramsToChange = allParams.ToList(); 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); + && 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 ); var count = allParams.Count(); - _paramsToChange = allParams.ToList(); + this._paramsToChange = allParams.ToList(); 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..15dcfdc 100644 --- a/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs +++ b/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs @@ -5,128 +5,111 @@ using Rhino.Geometry; using Rhino.Render; using System; + namespace Objectivism { - public class GH_ObjectivismObject : GH_GeometricGoo, IGH_PreviewData, IGH_RenderAwareData, GH_ISerializable + public class GH_ObjectivismObject : GH_GeometricGoo, IGH_PreviewData, IGH_RenderAwareData, + GH_ISerializable { - public override bool IsValid => true; - - public override bool IsReferencedGeometry => false; - public override string TypeName => Value.TypeName; - - public override string TypeDescription => $"Objectivism object of type: {Value.TypeName}"; - - - public BoundingBox ClippingBox => Value.ClippingBox; - - public override BoundingBox Boundingbox => Value.BoundingBox; - - public override IGH_Goo Duplicate() - { - return new GH_ObjectivismObject(this.Value); - } - public override IGH_GeometricGoo DuplicateGeometry() - { - return new GH_ObjectivismObject(this.Value); - } - - public override string ToString() + public GH_ObjectivismObject( ObjectivismObject value ) { - return $"{Value.TypeName} object"; + this.Value = value; } - public GH_ObjectivismObject(ObjectivismObject value) - { - Value = value; - } public GH_ObjectivismObject() { - Value = null; + this.Value = null; } - public GH_ObjectivismObject(GH_ObjectivismObject other) + + public GH_ObjectivismObject( GH_ObjectivismObject other ) { - Value = other.Value; + this.Value = other.Value; } - public override bool Read(GH_IReader reader) + public override bool IsValid => true; + + public override bool IsReferencedGeometry => false; + public override string TypeName => this.Value.TypeName; + + public override string TypeDescription => $"Objectivism object of type: {this.Value.TypeName}"; + + public override BoundingBox Boundingbox => this.Value.BoundingBox; + + 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 void DrawViewportMeshes(GH_PreviewMeshArgs args) - { - Value.DrawViewportMeshes(args); - } + public BoundingBox ClippingBox => this.Value.ClippingBox; - public void AppendRenderGeometry(GH_RenderArgs args, RenderMaterial material) - { - Value.AppendRenderGeometry(args, material); - } + public void DrawViewportWires( GH_PreviewWireArgs args ) => this.Value.DrawViewportWires( args ); - public override bool CastFrom(object source) + public void DrawViewportMeshes( GH_PreviewMeshArgs args ) => this.Value.DrawViewportMeshes( args ); + + public void AppendRenderGeometry( GH_RenderArgs args, RenderMaterial material ) => + this.Value.AppendRenderGeometry( args, material ); + + public override IGH_Goo Duplicate() => new GH_ObjectivismObject( this.Value ); + + public override IGH_GeometricGoo DuplicateGeometry() => new GH_ObjectivismObject( this.Value ); + + public override string ToString() => $"{this.Value.TypeName} object"; + + 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 gh_obj ) { this.Value = gh_obj.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..ffeecfd 100644 --- a/ObjectivismGH/ObjectClasses/ObjectProperty.cs +++ b/ObjectivismGH/ObjectClasses/ObjectProperty.cs @@ -12,184 +12,199 @@ namespace Objectivism { - enum PropertyAccess { Item, List, Tree } + internal 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( goo => this.DeReferenceIfRequired( goo ) ).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) + + if ( goo != null ) { return goo.Duplicate(); } - else { return goo; } + + return goo; } - 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..1c23a4c 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; @@ -11,194 +12,210 @@ namespace Objectivism { 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.ContainsKey( name ) ) { - property = properties[propertyGetter[name]].Property; + property = this._properties[this._propertyGetter[name]].Property; return true; } + return false; } - public ObjectProperty GetProperty(string name) + public ObjectProperty GetProperty( string name ) { - if (propertyGetter.ContainsKey(name)) - { - return properties[propertyGetter[name]].Property; - } - else + if ( this._propertyGetter.ContainsKey( name ) ) { - return null; + return this._properties[this._propertyGetter[name]].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 +224,59 @@ 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) + if ( prop.Access == PropertyAccess.Item ) { var item = prop != null - ? ProcessGoo(prop.Data.get_FirstItem(false)) + ? ProcessGoo( prop.Data.get_FirstItem( false ) ) : null; - eoColl.Add(new KeyValuePair(name, item)); + eoColl.Add( new KeyValuePair( name, item ) ); } - if (prop.Access == PropertyAccess.List) + + if ( prop.Access == PropertyAccess.List ) { var list = prop != null - ? prop.Data.Branches[0].Select(ProcessGoo).ToList() + ? prop.Data.Branches[0].Select( ProcessGoo ).ToList() : new List(); - eoColl.Add(new KeyValuePair(name, list)); + eoColl.Add( new KeyValuePair( name, list ) ); } - if (prop.Access == PropertyAccess.Tree) + + if ( prop.Access == PropertyAccess.Tree ) { var tree = prop != null - ? prop.Data.ToDataTree(ProcessGoo) - : new Grasshopper.DataTree(); - eoColl.Add(new KeyValuePair(name, tree)); + ? prop.Data.ToDataTree( ProcessGoo ) + : new DataTree(); + eoColl.Add( new KeyValuePair( name, tree ) ); } } + dynamic eoDynamic = eo; return eoDynamic; - } - - private static object ProcessGoo(IGH_Goo goo) - { - return goo != null ? goo.ScriptVariable() : null; - } + private static object ProcessGoo( IGH_Goo goo ) => goo?.ScriptVariable(); internal class AccessInfo { - List Conflicts; - public void AddConflict(string propertyName) => Conflicts.Add(propertyName); - public void BroadcastConflicts(GH_Component comp) => Conflicts.ForEach(conflict => comp.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"{conflict} has its access level changed")); + private readonly List _conflicts; public AccessInfo() { - Conflicts = new List(); + this._conflicts = new List(); } + + public void AddConflict( string propertyName ) => this._conflicts.Add( propertyName ); + + public void BroadcastConflicts( GH_Component comp ) => this._conflicts.ForEach( conflict => + comp.AddRuntimeMessage( GH_RuntimeMessageLevel.Warning, $"{conflict} has its access level changed" ) ); } } -} +} \ No newline at end of file diff --git a/ObjectivismGH/ObjectivismInfo.cs b/ObjectivismGH/ObjectivismInfo.cs index e00c672..8fb5290 100644 --- a/ObjectivismGH/ObjectivismInfo.cs +++ b/ObjectivismGH/ObjectivismInfo.cs @@ -6,52 +6,24 @@ namespace Objectivism { public class ObjectivismInfo : GH_AssemblyInfo { - public override string Name - { - get - { - return "Objectivism"; - } - } - public override Bitmap Icon - { - get - { - //Return a 24x24 pixel bitmap to represent this GHA library. - return Resources.ObjectivismLogoSmall; - } - } - public override string Description - { - get - { - //Return a short string describing the purpose of this GHA library. - return "Objectivism allows you to create objects in Grasshopper, enabling better management of data"; - } - } - public override Guid Id - { - get - { - return new Guid("3bc8585d-aa6b-49b6-8c92-ff1f0e14b3b4"); - } - } + public override string Name => "Objectivism"; - public override string AuthorName - { - get - { - //Return a string identifying you or your company. - return "Dominic Beer"; - } - } - public override string AuthorContact - { - get - { - //Return a string representing your preferred contact details. - return ""; - } - } + public override Bitmap Icon => + //Return a 24x24 pixel bitmap to represent this GHA library. + Resources.ObjectivismLogoSmall; + + public override string Description => + //Return a short string describing the purpose of this GHA library. + "Objectivism allows you to create objects in Grasshopper, enabling better management of data"; + + public override Guid Id => new Guid( "3bc8585d-aa6b-49b6-8c92-ff1f0e14b3b4" ); + + public override string AuthorName => + //Return a string identifying you or your company. + "Dominic Beer"; + + public override string AuthorContact => + //Return a string representing your preferred contact details. + ""; } -} +} \ No newline at end of file diff --git a/ObjectivismGH/Parameters/IHasPreviewToggle.cs b/ObjectivismGH/Parameters/IHasPreviewToggle.cs index 689d77d..018850b 100644 --- a/ObjectivismGH/Parameters/IHasPreviewToggle.cs +++ b/ObjectivismGH/Parameters/IHasPreviewToggle.cs @@ -4,4 +4,4 @@ internal interface IHasPreviewToggle { bool PreviewOn { get; } } -} +} \ No newline at end of file diff --git a/ObjectivismGH/Parameters/Param_ExtraObjectProperty.cs b/ObjectivismGH/Parameters/Param_ExtraObjectProperty.cs index 8a25169..da3bb2f 100644 --- a/ObjectivismGH/Parameters/Param_ExtraObjectProperty.cs +++ b/ObjectivismGH/Parameters/Param_ExtraObjectProperty.cs @@ -12,159 +12,163 @@ namespace Objectivism { public class Param_ExtraObjectProperty : Param_GenericObject, IHasPreviewToggle //Item access, property retrieval { - public override Guid ComponentGuid => new Guid("41412f8c-c2d9-45c7-83d0-bd04a10e14fa"); + internal HashSet AllPropertyNames = new HashSet(); internal string nickNameCache = ""; + + public Param_ExtraObjectProperty() + { + this.Name = "Extra Property"; + this.nickNameCache = string.Empty; + this.NickName = string.Empty; + this.Description = "Property to change/add to object"; + this.Access = GH_ParamAccess.item; + this.ObjectChanged += this.NickNameChangedEventHandler; + } + + public override Guid ComponentGuid => new Guid( "41412f8c-c2d9-45c7-83d0-bd04a10e14fa" ); public override GH_Exposure Exposure => GH_Exposure.hidden; public override string TypeName => "Object Property Data"; public bool PreviewOn { get; private set; } = true; + internal void CommitNickName() => this.nickNameCache = this.NickName; - internal HashSet AllPropertyNames = new HashSet(); - internal void CommitNickName() { this.nickNameCache = NickName; } - public Param_ExtraObjectProperty() : base() + public void NickNameChangedEventHandler( object sender, GH_ObjectChangedEventArgs args ) { - Name = "Extra Property"; - nickNameCache = String.Empty; - NickName = String.Empty; - Description = "Property to change/add to object"; - Access = GH_ParamAccess.item; - ObjectChanged += NickNameChangedEventHandler; - } - - 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, "Property input name changed but object not updated, right click on component and press \"Recompute\""); + this.AddRuntimeMessage( GH_RuntimeMessageLevel.Warning, + "Property input name changed but object not updated, right click on component and press \"Recompute\"" ); } } } - public override void AppendAdditionalMenuItems(ToolStripDropDown menu) + public override void AppendAdditionalMenuItems( ToolStripDropDown menu ) { + base.AppendAdditionalMenuItems( menu ); - base.AppendAdditionalMenuItems(menu); - - Menu_AppendSeparator(menu); + Menu_AppendSeparator( menu ); - var recomputeButton = Menu_AppendItem(menu, "Recompute", RecomputeHandler); + var recomputeButton = Menu_AppendItem( menu, "Recompute", this.RecomputeHandler ); - Menu_AppendSeparator(menu); + Menu_AppendSeparator( menu ); - var toggleButton = Menu_AppendItem(menu, "Preview Geometry", PreviewToggleHandler, true, PreviewOn); + var toggleButton = + Menu_AppendItem( menu, "Preview Geometry", this.PreviewToggleHandler, true, this.PreviewOn ); - Menu_AppendSeparator(menu); + Menu_AppendSeparator( menu ); - bool isItem = Access == GH_ParamAccess.item; - bool isList = Access == GH_ParamAccess.list; - bool isTree = Access == GH_ParamAccess.tree; + var isItem = this.Access == GH_ParamAccess.item; + var isList = this.Access == GH_ParamAccess.list; + var isTree = this.Access == GH_ParamAccess.tree; - var itemButton = Menu_AppendItem(menu, "Item Access", ItemAccessEventHandler, true, isItem); - var listButton = Menu_AppendItem(menu, "List Access", ListAccessEventHandler, true, isList); - var treeButton = Menu_AppendItem(menu, "Tree Access", TreeAccessEventHandler, true, isTree); + var itemButton = Menu_AppendItem( menu, "Item Access", this.ItemAccessEventHandler, true, isItem ); + var listButton = Menu_AppendItem( menu, "List Access", this.ListAccessEventHandler, true, isList ); + var treeButton = Menu_AppendItem( menu, "Tree Access", this.TreeAccessEventHandler, true, isTree ); - Menu_AppendSeparator(menu); + Menu_AppendSeparator( menu ); - var button = Menu_AppendItem(menu, "Properties"); - var dropDownButtons = this.AllPropertyNames.Select(n => new ToolStripMenuItem(n, null, PropertyClickEventHandler)).ToArray(); - button.DropDownItems.AddRange(dropDownButtons); - - Menu_AppendSeparator(menu); - var changeButton = Menu_AppendItem(menu, "Change Property Name", LaunchChangeDialog, true); + var button = Menu_AppendItem( menu, "Properties" ); + var dropDownButtons = this.AllPropertyNames + .Select( n => new ToolStripMenuItem( n, null, this.PropertyClickEventHandler ) ).ToArray(); + button.DropDownItems.AddRange( dropDownButtons ); + Menu_AppendSeparator( menu ); + var changeButton = Menu_AppendItem( menu, "Change Property Name", this.LaunchChangeDialog, true ); } - private void PreviewToggleHandler(object sender, EventArgs e) + private void PreviewToggleHandler( object sender, EventArgs e ) { - RecordUndoEvent("Change object preview type"); - PreviewOn = !PreviewOn; - ExpireSolution(true); + this.RecordUndoEvent( "Change object preview type" ); + this.PreviewOn = !this.PreviewOn; + this.ExpireSolution( true ); } - private void RecomputeHandler(object sender, EventArgs e) + private void RecomputeHandler( object sender, EventArgs e ) { var parent = this.GetParentComponent(); - if (parent != null) + if ( parent != null ) { - parent.Params.Input.ForEach(p => p.ExpireSolution(false)); - parent.ExpireSolution(true); + parent.Params.Input.ForEach( p => p.ExpireSolution( false ) ); + parent.ExpireSolution( true ); } } //When it is updated to cope with multiple types on arrival - private void LaunchChangeDialog(object sender, EventArgs e) + private void LaunchChangeDialog( object sender, EventArgs e ) { var parent = this.GetParentComponent(); - if (parent != null) + if ( parent != null ) { - var comp = (IHasMultipleTypes)parent; + var comp = (IHasMultipleTypes) parent; var tn = comp.TypeNames.FirstOrDefault(); var multiple = comp.TypeNames.Count() != 1; - var form = new ChangePropertyNameForm(this.NickName, tn, this.OnPingDocument(), multiple); + var form = new ChangePropertyNameForm( this.NickName, tn, this.OnPingDocument(), multiple ); form.ShowDialog(); } - } - public void ItemAccessEventHandler(object sender, EventArgs e) + public void ItemAccessEventHandler( object sender, EventArgs e ) { - if (Access != GH_ParamAccess.item) + if ( this.Access != GH_ParamAccess.item ) { - RecordUndoEvent("Change access type"); - Access = GH_ParamAccess.item; - ExpireSolution(true); + this.RecordUndoEvent( "Change access type" ); + this.Access = GH_ParamAccess.item; + this.ExpireSolution( true ); } } - public void ListAccessEventHandler(object sender, EventArgs e) + + public void ListAccessEventHandler( object sender, EventArgs e ) { - if (Access != GH_ParamAccess.list) + if ( this.Access != GH_ParamAccess.list ) { - RecordUndoEvent("Change access type"); - Access = GH_ParamAccess.list; - ExpireSolution(true); + this.RecordUndoEvent( "Change access type" ); + this.Access = GH_ParamAccess.list; + this.ExpireSolution( true ); } } - public void TreeAccessEventHandler(object sender, EventArgs e) + + public void TreeAccessEventHandler( object sender, EventArgs e ) { - if (Access != GH_ParamAccess.tree) + if ( this.Access != GH_ParamAccess.tree ) { - RecordUndoEvent("Change access type"); - Access = GH_ParamAccess.tree; - ExpireSolution(true); + this.RecordUndoEvent( "Change access type" ); + this.Access = GH_ParamAccess.tree; + this.ExpireSolution( true ); } } - private void PropertyClickEventHandler(object sender, EventArgs e) + private void PropertyClickEventHandler( object sender, EventArgs e ) { - RecordUndoEvent("Change property name"); - if (sender is ToolStripMenuItem button) + this.RecordUndoEvent( "Change property name" ); + if ( sender is ToolStripMenuItem button ) { this.NickName = button.Text; - this.ExpireSolution(true); + this.ExpireSolution( true ); } } - public override bool Read(GH_IReader reader) + public override bool Read( GH_IReader reader ) { try { - PreviewOn = reader.GetBoolean("PreviewState"); + this.PreviewOn = reader.GetBoolean( "PreviewState" ); } catch { - PreviewOn = true; + this.PreviewOn = true; } - return base.Read(reader); + + return base.Read( reader ); } - public override bool Write(GH_IWriter writer) + public override bool Write( GH_IWriter writer ) { - writer.SetBoolean("PreviewState", PreviewOn); - return base.Write(writer); + writer.SetBoolean( "PreviewState", this.PreviewOn ); + return base.Write( writer ); } } -} +} \ No newline at end of file diff --git a/ObjectivismGH/Parameters/Param_NewObjectProperty.cs b/ObjectivismGH/Parameters/Param_NewObjectProperty.cs index 1f1df46..7209a34 100644 --- a/ObjectivismGH/Parameters/Param_NewObjectProperty.cs +++ b/ObjectivismGH/Parameters/Param_NewObjectProperty.cs @@ -10,36 +10,34 @@ namespace Objectivism { public class Param_NewObjectProperty : Param_GenericObject, IHasPreviewToggle { - public override Guid ComponentGuid => new Guid("81320c17-4090-470d-b036-95005338c2b1"); internal string nickNameCache = ""; + + public Param_NewObjectProperty() + { + this.Name = "Property"; + this.nickNameCache = "Prop"; + this.NickName = "Prop"; + this.Description = "Property for an Objectivsm Object "; + this.ObjectChanged += this.NickNameChangedEventHandler; + } + + public override Guid ComponentGuid => new Guid( "81320c17-4090-470d-b036-95005338c2b1" ); public override string TypeName => "Object Property Data"; public override GH_Exposure Exposure => GH_Exposure.hidden; public bool PreviewOn { get; private set; } = true; - public Param_NewObjectProperty() : base() - { - - Name = "Property"; - nickNameCache = "Prop"; - NickName = "Prop"; - Description = "Property for an Objectivsm Object "; - ObjectChanged += NickNameChangedEventHandler; - } + internal void CommitNickName() => this.nickNameCache = this.NickName; - - internal void CommitNickName() + public void NickNameChangedEventHandler( object sender, GH_ObjectChangedEventArgs args ) { - nickNameCache = NickName; - } - 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, "Property input name changed but object not updated, right click on component and press \"Recompute\""); + this.AddRuntimeMessage( GH_RuntimeMessageLevel.Warning, + "Property input name changed but object not updated, right click on component and press \"Recompute\"" ); } else { @@ -48,110 +46,110 @@ public void NickNameChangedEventHandler(object sender, GH_ObjectChangedEventArgs } } - public override void AppendAdditionalMenuItems(ToolStripDropDown menu) + public override void AppendAdditionalMenuItems( ToolStripDropDown menu ) { - base.AppendAdditionalMenuItems(menu); - - Menu_AppendSeparator(menu); + base.AppendAdditionalMenuItems( menu ); - var recomputeButton = Menu_AppendItem(menu, "Recompute", RecomputeHandler); + Menu_AppendSeparator( menu ); - Menu_AppendSeparator(menu); + var recomputeButton = Menu_AppendItem( menu, "Recompute", this.RecomputeHandler ); - var toggleButton = Menu_AppendItem(menu, "Preview Geometry", PreviewToggleHandler, true, PreviewOn); + Menu_AppendSeparator( menu ); - Menu_AppendSeparator(menu); + var toggleButton = + Menu_AppendItem( menu, "Preview Geometry", this.PreviewToggleHandler, true, this.PreviewOn ); - bool isItem = Access == GH_ParamAccess.item; - bool isList = Access == GH_ParamAccess.list; - bool isTree = Access == GH_ParamAccess.tree; + Menu_AppendSeparator( menu ); - var itemButton = Menu_AppendItem(menu, "Item Access", ItemAccessEventHandler, true, isItem); - var listButton = Menu_AppendItem(menu, "List Access", ListAccessEventHandler, true, isList); - var treeButton = Menu_AppendItem(menu, "Tree Access", TreeAccessEventHandler, true, isTree); + var isItem = this.Access == GH_ParamAccess.item; + var isList = this.Access == GH_ParamAccess.list; + var isTree = this.Access == GH_ParamAccess.tree; - Menu_AppendSeparator(menu); + var itemButton = Menu_AppendItem( menu, "Item Access", this.ItemAccessEventHandler, true, isItem ); + var listButton = Menu_AppendItem( menu, "List Access", this.ListAccessEventHandler, true, isList ); + var treeButton = Menu_AppendItem( menu, "Tree Access", this.TreeAccessEventHandler, true, isTree ); - var changeButton = Menu_AppendItem(menu, "Change Property Name", LaunchChangeDialog, true); + Menu_AppendSeparator( menu ); + var changeButton = Menu_AppendItem( menu, "Change Property Name", this.LaunchChangeDialog, true ); } - private void PreviewToggleHandler(object sender, EventArgs e) + private void PreviewToggleHandler( object sender, EventArgs e ) { - RecordUndoEvent("Change object preview type"); - PreviewOn = !PreviewOn; - ExpireSolution(true); + this.RecordUndoEvent( "Change object preview type" ); + this.PreviewOn = !this.PreviewOn; + this.ExpireSolution( true ); } - private void RecomputeHandler(object sender, EventArgs e) + private void RecomputeHandler( object sender, EventArgs e ) { var parent = this.GetParentComponent(); - if (parent != null) + if ( parent != null ) { - parent.Params.Input.ForEach(p => p.ExpireSolution(false)); - parent.ExpireSolution(true); + parent.Params.Input.ForEach( p => p.ExpireSolution( false ) ); + parent.ExpireSolution( true ); } } - private void LaunchChangeDialog(object sender, EventArgs e) + private void LaunchChangeDialog( object sender, EventArgs e ) { var parent = this.GetParentComponent(); - if (parent != null) + if ( parent != null ) { var typeName = this.GetParentComponent().NickName; - var form = new ChangePropertyNameForm(this.NickName, typeName, this.OnPingDocument(), false); + var form = new ChangePropertyNameForm( this.NickName, typeName, this.OnPingDocument(), false ); form.ShowDialog(); } - } - public void ItemAccessEventHandler(object sender, EventArgs e) + public void ItemAccessEventHandler( object sender, EventArgs e ) { - if (Access != GH_ParamAccess.item) + if ( this.Access != GH_ParamAccess.item ) { - RecordUndoEvent("Change access type"); - Access = GH_ParamAccess.item; - ExpireSolution(true); + this.RecordUndoEvent( "Change access type" ); + this.Access = GH_ParamAccess.item; + this.ExpireSolution( true ); } } - public void ListAccessEventHandler(object sender, EventArgs e) + + public void ListAccessEventHandler( object sender, EventArgs e ) { - if (Access != GH_ParamAccess.list) + if ( this.Access != GH_ParamAccess.list ) { - RecordUndoEvent("Change access type"); - Access = GH_ParamAccess.list; - ExpireSolution(true); + this.RecordUndoEvent( "Change access type" ); + this.Access = GH_ParamAccess.list; + this.ExpireSolution( true ); } } - public void TreeAccessEventHandler(object sender, EventArgs e) + + public void TreeAccessEventHandler( object sender, EventArgs e ) { - if (Access != GH_ParamAccess.tree) + if ( this.Access != GH_ParamAccess.tree ) { - RecordUndoEvent("Change access type"); - Access = GH_ParamAccess.tree; - ExpireSolution(true); + this.RecordUndoEvent( "Change access type" ); + this.Access = GH_ParamAccess.tree; + this.ExpireSolution( true ); } } - public override bool Read(GH_IReader reader) + public override bool Read( GH_IReader reader ) { try { - PreviewOn = reader.GetBoolean("PreviewState"); + this.PreviewOn = reader.GetBoolean( "PreviewState" ); } catch { - PreviewOn = true; + this.PreviewOn = true; } - return base.Read(reader); + + return base.Read( reader ); } - public override bool Write(GH_IWriter writer) + public override bool Write( GH_IWriter writer ) { - writer.SetBoolean("PreviewState", PreviewOn); - return base.Write(writer); + writer.SetBoolean( "PreviewState", this.PreviewOn ); + return base.Write( writer ); } - } - -} +} \ No newline at end of file diff --git a/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs b/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs index b27e43d..0085c62 100644 --- a/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs +++ b/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs @@ -9,32 +9,35 @@ namespace Objectivism { public class Param_ObjectivismOutput : Param_GenericObject { - public override Guid ComponentGuid => new Guid("1b625488-3ec8-4189-8d14-6de1b0c9effd"); - protected virtual string outputType => "Property"; - protected virtual string outputTypePlural => "Properties"; - protected string outputTyputLC => outputType.ToLower(); - internal string nickNameCache = ""; - public override GH_Exposure Exposure => GH_Exposure.hidden; - internal void CommitNickName() { this.nickNameCache = NickName; } - public override string TypeName => $"Object {outputType} Data"; internal HashSet AllPropertyNames = new HashSet(); - public Param_ObjectivismOutput() : base() + internal string nickNameCache = ""; + + public Param_ObjectivismOutput() { - Name = outputType; - nickNameCache = String.Empty; - NickName = String.Empty; - Description = $"Retrieved {outputType} "; - Access = GH_ParamAccess.tree; - ObjectChanged += NickNameChangedEventHandler; + this.Name = this.OutputType; + this.nickNameCache = string.Empty; + this.NickName = string.Empty; + this.Description = $"Retrieved {this.OutputType} "; + this.Access = GH_ParamAccess.tree; + this.ObjectChanged += this.NickNameChangedEventHandler; } - public void NickNameChangedEventHandler(object sender, GH_ObjectChangedEventArgs args) + public override Guid ComponentGuid => new Guid( "1b625488-3ec8-4189-8d14-6de1b0c9effd" ); + protected virtual string OutputType => "Property"; + protected virtual string OutputTypePlural => "Properties"; + protected string OutputTyputLC => this.OutputType.ToLower(); + public override GH_Exposure Exposure => GH_Exposure.hidden; + public override string TypeName => $"Object {this.OutputType} Data"; + internal void CommitNickName() => this.nickNameCache = this.NickName; + + 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, $"{outputType} name changed but component not updated, right click on component and press \"Recompute\""); + this.AddRuntimeMessage( GH_RuntimeMessageLevel.Warning, + $"{this.OutputType} name changed but component not updated, right click on component and press \"Recompute\"" ); } else { @@ -43,46 +46,45 @@ public void NickNameChangedEventHandler(object sender, GH_ObjectChangedEventArgs } } - public override void AppendAdditionalMenuItems(ToolStripDropDown menu) + public override void AppendAdditionalMenuItems( ToolStripDropDown menu ) { - base.AppendAdditionalMenuItems(menu); - - Menu_AppendSeparator(menu); - var recomputeButton = Menu_AppendItem(menu, "Recompute", RecomputeHandler); - Menu_AppendSeparator(menu); - var button = Menu_AppendItem(menu, outputTypePlural); - var dropDownButtons = this.AllPropertyNames.Select(n => new ToolStripMenuItem(n, null, PropertyClickEventHandler)).ToArray(); - button.DropDownItems.AddRange(dropDownButtons); + base.AppendAdditionalMenuItems( menu ); + Menu_AppendSeparator( menu ); + var recomputeButton = Menu_AppendItem( menu, "Recompute", this.RecomputeHandler ); + Menu_AppendSeparator( menu ); + var button = Menu_AppendItem( menu, this.OutputTypePlural ); + var dropDownButtons = this.AllPropertyNames + .Select( n => new ToolStripMenuItem( n, null, this.PropertyClickEventHandler ) ).ToArray(); + button.DropDownItems.AddRange( dropDownButtons ); } - private void RecomputeHandler(object sender, EventArgs e) + private void RecomputeHandler( object sender, EventArgs e ) { var parent = this.GetParentComponent(); - if (parent != null) + if ( parent != null ) { - parent.Params.Input.ForEach(p => p.ExpireSolution(false)); - parent.ExpireSolution(true); - + parent.Params.Input.ForEach( p => p.ExpireSolution( false ) ); + parent.ExpireSolution( true ); } } - private void PropertyClickEventHandler(object sender, EventArgs e) + private void PropertyClickEventHandler( object sender, EventArgs e ) { - RecordUndoEvent($"Change {outputTyputLC} name"); - if (sender is ToolStripMenuItem button) + this.RecordUndoEvent( $"Change {this.OutputTyputLC} name" ); + if ( sender is ToolStripMenuItem button ) { this.NickName = button.Text; var parent = this.Attributes.GetTopLevel.DocObject; - parent.ExpireSolution(true); + parent.ExpireSolution( true ); } } } public class Param_ObjectivismObjectTypeOutput : Param_ObjectivismOutput { - protected override string outputType => "Type"; - protected override string outputTypePlural => "Types"; - public override Guid ComponentGuid => new Guid("55bf273b-08ac-4cd7-a3a2-27bb1228a58c"); + protected override string OutputType => "Type"; + protected override string OutputTypePlural => "Types"; + public override Guid ComponentGuid => new Guid( "55bf273b-08ac-4cd7-a3a2-27bb1228a58c" ); } -} +} \ No newline at end of file diff --git a/ObjectivismGH/Util.cs b/ObjectivismGH/Util.cs index edf22c3..6d110c0 100644 --- a/ObjectivismGH/Util.cs +++ b/ObjectivismGH/Util.cs @@ -10,171 +10,170 @@ namespace Objectivism { - static class Util + internal static class Util { + internal static GH_Structure EmptyTree + { + get + { + var tree = new GH_Structure(); + tree.AppendRange( new List() ); + return tree; + } + } - public static IGH_Component GetParentComponent(this IGH_Param param) + public static IGH_Component GetParentComponent( this IGH_Param param ) { var obj = param.Attributes.GetTopLevel.DocObject; - if (obj != null && obj is IGH_Component c) + if ( obj != null && obj is IGH_Component c ) { return c; } + return null; } - public static IEnumerable WhereIsType(this IEnumerable seq) + public static IEnumerable WhereIsType( this IEnumerable seq ) { var outList = new List(); - foreach (var val in seq) + foreach ( var val in seq ) { - if (val is TNew newval) + if ( val is TNew newval ) { - outList.Add(newval); + outList.Add( newval ); } } + return outList; } - public static bool SetGoo(this GH_IWriter writer, string itemName, IGH_Goo item) + public static bool SetGoo( this GH_IWriter writer, string itemName, IGH_Goo item ) { - var itemWriter = writer.CreateChunk(itemName); + var itemWriter = writer.CreateChunk( itemName ); var tree = new GH_Structure(); - tree.Append(item); - return tree.Write(itemWriter); + tree.Append( item ); + return tree.Write( itemWriter ); } - public static IGH_Goo GetGoo(this GH_IReader reader, string itemName) + public static IGH_Goo GetGoo( this GH_IReader reader, string itemName ) { - var dataReader = reader.FindChunk(itemName); + var dataReader = reader.FindChunk( itemName ); var tree = new GH_Structure(); - tree.Read(dataReader); + tree.Read( dataReader ); return tree.Branches[0][0]; } - public static bool SetList(this GH_IWriter writer, string listName, List list) + public static bool SetList( this GH_IWriter writer, string listName, List list ) { - var listWriter = writer.CreateChunk(listName); + var listWriter = writer.CreateChunk( listName ); var tree = new GH_Structure(); - tree.AppendRange(list); - return tree.Write(listWriter); + tree.AppendRange( list ); + return tree.Write( listWriter ); } - public static List GetList(this GH_IReader reader, string listName) + public static List GetList( this GH_IReader reader, string listName ) { - var listReader = reader.FindChunk(listName); + var listReader = reader.FindChunk( listName ); var tree = new GH_Structure(); - tree.Read(listReader); + tree.Read( listReader ); return tree.Branches[0]; } - public static bool SetTree(this GH_IWriter writer, string treeName, GH_Structure tree) + public static bool SetTree( this GH_IWriter writer, string treeName, GH_Structure tree ) { - var treeWriter = writer.CreateChunk(treeName); - return tree.Write(treeWriter); - + var treeWriter = writer.CreateChunk( treeName ); + return tree.Write( treeWriter ); } - public static GH_Structure GetTree(this GH_IReader reader, string treeName) + + public static GH_Structure GetTree( this GH_IReader reader, string treeName ) { var tree = new GH_Structure(); - var treeReader = reader.FindChunk(treeName); - tree.Read(treeReader); + var treeReader = reader.FindChunk( treeName ); + tree.Read( treeReader ); return tree; } - public static BoundingBox UnionBoxes(List boxes) + + public static BoundingBox UnionBoxes( List boxes ) { - var points = new List(boxes.Count * 2); - foreach (var box in boxes) + var points = new List( boxes.Count * 2 ); + foreach ( var box in boxes ) { - points.Add(box.Min); - points.Add(box.Max); + points.Add( box.Min ); + points.Add( box.Max ); } - return new BoundingBox(points); + + return new BoundingBox( points ); } - public static GH_Structure MapTree(this GH_Structure tree, Func function) + public static GH_Structure MapTree( this GH_Structure tree, Func function ) { - var tree2 = new GH_Structure(tree, true); - foreach (var branch in tree2.Branches) + var tree2 = new GH_Structure( tree, true ); + foreach ( var branch in tree2.Branches ) { - for (int i = 0; i < branch.Count; i++) + for ( var i = 0; i < branch.Count; i++ ) { - branch[i] = function(branch[i]); + branch[i] = function( branch[i] ); } } + return tree2; } - public static GH_Structure MapTree(this GH_Structure tree, Func function, T param) + + public static GH_Structure MapTree( this GH_Structure tree, + Func function, T param ) { - var tree2 = new GH_Structure(tree, true); - foreach (var branch in tree2.Branches) + var tree2 = new GH_Structure( tree, true ); + foreach ( var branch in tree2.Branches ) { - for (int i = 0; i < branch.Count; i++) + for ( var i = 0; i < branch.Count; i++ ) { - branch[i] = function(branch[i], param); + branch[i] = function( branch[i], param ); } } + return tree2; } //python style enumerate for use in a foreach loop - public static IEnumerable<(int, T)> Enumerate(this IEnumerable series) - { - return series.Select((x, i) => (i, x)); - } + public static IEnumerable<(int, T)> Enumerate( this IEnumerable series ) => + series.Select( ( x, i ) => (i, x) ); - public static string SpacesToUnderscores(this string @this) - { - return @this.Replace(" ", "_"); - } - - internal static GH_Structure EmptyTree - { - get - { - var tree = new GH_Structure(); - tree.AppendRange(new List()); - return tree; - } - } + public static string SpacesToUnderscores( this string @this ) => @this.Replace( " ", "_" ); - internal static object UnwrapGoo(this IGH_Goo goo) + internal static object UnwrapGoo( this IGH_Goo goo ) { var goo2 = goo.Duplicate(); var type = goo2.GetType(); - var propInfo = type.GetProperty("Value"); - if (propInfo != null) + var propInfo = type.GetProperty( "Value" ); + if ( propInfo != null ) { - return propInfo.GetValue(goo2); - } - else - { - return goo2; + return propInfo.GetValue( goo2 ); } + + return goo2; } - internal static object PackSubObjects(this object obj) + internal static object PackSubObjects( this object obj ) { - if (obj is ObjectivismObject objectivismObject) + if ( obj is ObjectivismObject objectivismObject ) { return objectivismObject.ToDynamic(); } - else - { - return obj; - } + + return obj; } - internal static DataTree ToDataTree(this GH_Structure gooTree, Func deGoo) + internal static DataTree ToDataTree( this GH_Structure gooTree, Func deGoo ) { var tree = new DataTree(); - foreach (var path in gooTree.Paths) + foreach ( var path in gooTree.Paths ) { - var branch = gooTree[path].Select(deGoo); - tree.AddRange(branch, path); + var branch = gooTree[path].Select( deGoo ); + tree.AddRange( branch, path ); } + return tree; } } -} +} \ No newline at end of file From b1770125d88fe096587d8a8195a5a2dc185b1d04 Mon Sep 17 00:00:00 2001 From: Tom Glastonbury Date: Mon, 17 Jun 2024 15:54:23 +0100 Subject: [PATCH 3/8] Ignore .sarif files as generated by jb inspectcode. --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 From e1ec2a10f89d777c75f5dd2d288b41d62ec578e8 Mon Sep 17 00:00:00 2001 From: Tom Glastonbury Date: Mon, 17 Jun 2024 15:54:44 +0100 Subject: [PATCH 4/8] Make namespaces match directory structure. --- ObjectivismGH/Components/AddOrChangePropertiesComponent.cs | 6 ++++-- ObjectivismGH/Components/CreateObjectComponent.cs | 7 ++++--- ObjectivismGH/Components/FilterByType.cs | 2 ++ ObjectivismGH/Components/FilterByTypeV2.cs | 2 ++ ObjectivismGH/Components/GetPropertiesComponent.cs | 5 ++++- ObjectivismGH/Components/ImplementsComponent.cs | 1 + ObjectivismGH/Components/InheritComponent.cs | 6 ++++-- ObjectivismGH/Components/ObjectToTree.cs | 2 ++ .../{ComponentUtil => Utilities}/AccessChecker.cs | 3 ++- .../Components/{ComponentUtil => Utilities}/DataUtil.cs | 3 ++- ObjectivismGH/Forms/ChangePropertyNameForm.cs | 2 ++ ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs | 2 +- ObjectivismGH/ObjectClasses/ObjectProperty.cs | 3 +-- ObjectivismGH/ObjectClasses/ObjectivismObject.cs | 2 +- ObjectivismGH/Parameters/Param_ExtraObjectProperty.cs | 4 ++-- ObjectivismGH/Parameters/Param_NewObjectProperty.cs | 3 +-- ObjectivismGH/Parameters/Param_ObjectivismOutput.cs | 2 +- ObjectivismGH/Util.cs | 1 + 18 files changed, 37 insertions(+), 19 deletions(-) rename ObjectivismGH/Components/{ComponentUtil => Utilities}/AccessChecker.cs (96%) rename ObjectivismGH/Components/{ComponentUtil => Utilities}/DataUtil.cs (96%) diff --git a/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs b/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs index 9dcb300..fe9a89f 100644 --- a/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs +++ b/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs @@ -1,13 +1,15 @@ using Grasshopper.Kernel; using Grasshopper.Kernel.Parameters; +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.DataUtil; -namespace Objectivism +namespace Objectivism.Components { public class AddOrChangePropertiesComponent : GH_Component, IGH_VariableParameterComponent, IHasMultipleTypes { diff --git a/ObjectivismGH/Components/CreateObjectComponent.cs b/ObjectivismGH/Components/CreateObjectComponent.cs index 359ba8a..dba374f 100644 --- a/ObjectivismGH/Components/CreateObjectComponent.cs +++ b/ObjectivismGH/Components/CreateObjectComponent.cs @@ -1,13 +1,14 @@ 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.DataUtil; - -namespace Objectivism +namespace Objectivism.Components { internal interface IHasMultipleTypes { diff --git a/ObjectivismGH/Components/FilterByType.cs b/ObjectivismGH/Components/FilterByType.cs index 0f47455..ca012e4 100644 --- a/ObjectivismGH/Components/FilterByType.cs +++ b/ObjectivismGH/Components/FilterByType.cs @@ -1,6 +1,8 @@ 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; diff --git a/ObjectivismGH/Components/FilterByTypeV2.cs b/ObjectivismGH/Components/FilterByTypeV2.cs index de6c4a1..b59fa69 100644 --- a/ObjectivismGH/Components/FilterByTypeV2.cs +++ b/ObjectivismGH/Components/FilterByTypeV2.cs @@ -1,6 +1,8 @@ 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; diff --git a/ObjectivismGH/Components/GetPropertiesComponent.cs b/ObjectivismGH/Components/GetPropertiesComponent.cs index ff4ec48..d2f39b1 100644 --- a/ObjectivismGH/Components/GetPropertiesComponent.cs +++ b/ObjectivismGH/Components/GetPropertiesComponent.cs @@ -3,13 +3,16 @@ 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 { diff --git a/ObjectivismGH/Components/ImplementsComponent.cs b/ObjectivismGH/Components/ImplementsComponent.cs index 6ee30dc..1d5ad80 100644 --- a/ObjectivismGH/Components/ImplementsComponent.cs +++ b/ObjectivismGH/Components/ImplementsComponent.cs @@ -1,4 +1,5 @@ using Grasshopper.Kernel; +using Objectivism.Components.Utilities; using System; using System.Collections.Generic; using System.Drawing; diff --git a/ObjectivismGH/Components/InheritComponent.cs b/ObjectivismGH/Components/InheritComponent.cs index 5af9ea8..c0246bc 100644 --- a/ObjectivismGH/Components/InheritComponent.cs +++ b/ObjectivismGH/Components/InheritComponent.cs @@ -1,13 +1,15 @@ using Grasshopper.Kernel; using Grasshopper.Kernel.Parameters; +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.DataUtil; -namespace Objectivism +namespace Objectivism.Components { public class InheritComponent : GH_Component, IGH_VariableParameterComponent, IHasMultipleTypes { diff --git a/ObjectivismGH/Components/ObjectToTree.cs b/ObjectivismGH/Components/ObjectToTree.cs index d13e7b6..11f8afe 100644 --- a/ObjectivismGH/Components/ObjectToTree.cs +++ b/ObjectivismGH/Components/ObjectToTree.cs @@ -1,6 +1,8 @@ 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; diff --git a/ObjectivismGH/Components/ComponentUtil/AccessChecker.cs b/ObjectivismGH/Components/Utilities/AccessChecker.cs similarity index 96% rename from ObjectivismGH/Components/ComponentUtil/AccessChecker.cs rename to ObjectivismGH/Components/Utilities/AccessChecker.cs index dffd69c..532e344 100644 --- a/ObjectivismGH/Components/ComponentUtil/AccessChecker.cs +++ b/ObjectivismGH/Components/Utilities/AccessChecker.cs @@ -1,7 +1,8 @@ using Grasshopper.Kernel; +using Objectivism.ObjectClasses; using System.Collections.Generic; -namespace Objectivism +namespace Objectivism.Components.Utilities { internal class AccessChecker { diff --git a/ObjectivismGH/Components/ComponentUtil/DataUtil.cs b/ObjectivismGH/Components/Utilities/DataUtil.cs similarity index 96% rename from ObjectivismGH/Components/ComponentUtil/DataUtil.cs rename to ObjectivismGH/Components/Utilities/DataUtil.cs index 4f8e6b5..a7527c8 100644 --- a/ObjectivismGH/Components/ComponentUtil/DataUtil.cs +++ b/ObjectivismGH/Components/Utilities/DataUtil.cs @@ -1,10 +1,11 @@ using Grasshopper.Kernel; using Grasshopper.Kernel.Data; using Grasshopper.Kernel.Types; +using Objectivism.ObjectClasses; using Objectivism.Parameters; using System.Collections.Generic; -namespace Objectivism +namespace Objectivism.Components.Utilities { internal static class DataUtil { diff --git a/ObjectivismGH/Forms/ChangePropertyNameForm.cs b/ObjectivismGH/Forms/ChangePropertyNameForm.cs index 0ac7a3d..bb1d456 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; diff --git a/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs b/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs index 15dcfdc..87bdba2 100644 --- a/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs +++ b/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs @@ -6,7 +6,7 @@ using Rhino.Render; using System; -namespace Objectivism +namespace Objectivism.ObjectClasses { public class GH_ObjectivismObject : GH_GeometricGoo, IGH_PreviewData, IGH_RenderAwareData, GH_ISerializable diff --git a/ObjectivismGH/ObjectClasses/ObjectProperty.cs b/ObjectivismGH/ObjectClasses/ObjectProperty.cs index ffeecfd..74e8b4f 100644 --- a/ObjectivismGH/ObjectClasses/ObjectProperty.cs +++ b/ObjectivismGH/ObjectClasses/ObjectProperty.cs @@ -9,8 +9,7 @@ using static Objectivism.DeReferenceGeometryUtil; using static Objectivism.Util; - -namespace Objectivism +namespace Objectivism.ObjectClasses { internal enum PropertyAccess { Item, List, Tree } diff --git a/ObjectivismGH/ObjectClasses/ObjectivismObject.cs b/ObjectivismGH/ObjectClasses/ObjectivismObject.cs index 1c23a4c..0cfeced 100644 --- a/ObjectivismGH/ObjectClasses/ObjectivismObject.cs +++ b/ObjectivismGH/ObjectClasses/ObjectivismObject.cs @@ -8,7 +8,7 @@ using System.Dynamic; using System.Linq; -namespace Objectivism +namespace Objectivism.ObjectClasses { public class ObjectivismObject : IGH_PreviewData, IGH_RenderAwareData { diff --git a/ObjectivismGH/Parameters/Param_ExtraObjectProperty.cs b/ObjectivismGH/Parameters/Param_ExtraObjectProperty.cs index da3bb2f..1166867 100644 --- a/ObjectivismGH/Parameters/Param_ExtraObjectProperty.cs +++ b/ObjectivismGH/Parameters/Param_ExtraObjectProperty.cs @@ -1,14 +1,14 @@ using GH_IO.Serialization; using Grasshopper.Kernel; using Grasshopper.Kernel.Parameters; +using Objectivism.Components; using Objectivism.Forms; -using Objectivism.Parameters; using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; -namespace Objectivism +namespace Objectivism.Parameters { public class Param_ExtraObjectProperty : Param_GenericObject, IHasPreviewToggle //Item access, property retrieval { diff --git a/ObjectivismGH/Parameters/Param_NewObjectProperty.cs b/ObjectivismGH/Parameters/Param_NewObjectProperty.cs index 7209a34..8192c17 100644 --- a/ObjectivismGH/Parameters/Param_NewObjectProperty.cs +++ b/ObjectivismGH/Parameters/Param_NewObjectProperty.cs @@ -2,11 +2,10 @@ using Grasshopper.Kernel; using Grasshopper.Kernel.Parameters; using Objectivism.Forms; -using Objectivism.Parameters; using System; using System.Windows.Forms; -namespace Objectivism +namespace Objectivism.Parameters { public class Param_NewObjectProperty : Param_GenericObject, IHasPreviewToggle { diff --git a/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs b/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs index 0085c62..d0b5a5f 100644 --- a/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs +++ b/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Windows.Forms; -namespace Objectivism +namespace Objectivism.Parameters { public class Param_ObjectivismOutput : Param_GenericObject { diff --git a/ObjectivismGH/Util.cs b/ObjectivismGH/Util.cs index 6d110c0..aeea98d 100644 --- a/ObjectivismGH/Util.cs +++ b/ObjectivismGH/Util.cs @@ -3,6 +3,7 @@ using Grasshopper.Kernel; using Grasshopper.Kernel.Data; using Grasshopper.Kernel.Types; +using Objectivism.ObjectClasses; using Rhino.Geometry; using System; using System.Collections.Generic; From e178e6f95a8aef79aaf0fc50e9b04302843f0871 Mon Sep 17 00:00:00 2001 From: Tom Glastonbury Date: Mon, 17 Jun 2024 16:57:29 +0100 Subject: [PATCH 5/8] More code formatting/normalizing. --- .../AddOrChangePropertiesComponent.cs | 16 +++---- .../Components/CreateObjectComponent.cs | 30 +++++++------ ObjectivismGH/Components/FilterByType.cs | 31 ++++--------- ObjectivismGH/Components/FilterByTypeV2.cs | 18 +++----- .../Components/GetPropertiesComponent.cs | 28 ++++++------ .../Components/ImplementsComponent.cs | 8 ++-- ObjectivismGH/Components/InheritComponent.cs | 43 +++++++++---------- ObjectivismGH/Components/ObjectToTree.cs | 22 +++++----- .../{DataUtil.cs => ComponentExtensions.cs} | 32 ++++---------- .../Utilities/DataAccessExtensions.cs | 28 ++++++++++++ 10 files changed, 128 insertions(+), 128 deletions(-) rename ObjectivismGH/Components/Utilities/{DataUtil.cs => ComponentExtensions.cs} (55%) create mode 100644 ObjectivismGH/Components/Utilities/DataAccessExtensions.cs diff --git a/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs b/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs index fe9a89f..224888e 100644 --- a/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs +++ b/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs @@ -1,5 +1,6 @@ using Grasshopper.Kernel; using Grasshopper.Kernel.Parameters; +using Objectivism.Components.Utilities; using Objectivism.ObjectClasses; using Objectivism.Parameters; using System; @@ -7,7 +8,6 @@ using System.Drawing; using System.Linq; using System.Windows.Forms; -using static Objectivism.Components.Utilities.DataUtil; namespace Objectivism.Components { @@ -93,6 +93,8 @@ internal List GetUnusedNames() => internal string NextUnusedName() { + // TODO: TG: Review. The use of StrippedParamNames() does not make sense to me. + var unusedNames = this.GetUnusedNames(); return unusedNames.Count == 0 ? this._defaultNickName + @@ -142,8 +144,6 @@ private void ObjectWireChangedHandler( IGH_DocumentObject sender, GH_ObjectChang { this.UpdatePropertyNames(); } - - ; } /// @@ -192,10 +192,10 @@ private void CommitParamNames( IGH_Param param ) /// /// 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 ) ) + if ( !daObject.TryGetObjectivsmObject( 0, out var obj ) ) { return; } @@ -204,12 +204,12 @@ protected override void SolveInstance( IGH_DataAccess DA ) for ( var i = 1; i < this.Params.Input.Count; i++ ) { - updates.Add( RetrieveProperties( DA, i, this ) ); + updates.Add( this.GetProperty( daObject, i ) ); } var (newObj, accessConflict) = obj.AddOrChangeProperties( updates ); accessConflict.BroadcastConflicts( this ); - DA.SetData( 0, new GH_ObjectivismObject( newObj ) ); + daObject.SetData( 0, new GH_ObjectivismObject( newObj ) ); } private List StrippedParamNames() diff --git a/ObjectivismGH/Components/CreateObjectComponent.cs b/ObjectivismGH/Components/CreateObjectComponent.cs index dba374f..3637787 100644 --- a/ObjectivismGH/Components/CreateObjectComponent.cs +++ b/ObjectivismGH/Components/CreateObjectComponent.cs @@ -6,7 +6,7 @@ using System.Drawing; using System.Linq; using System.Windows.Forms; -using static Objectivism.Components.Utilities.DataUtil; +using static Objectivism.Components.Utilities.ComponentExtensions; namespace Objectivism.Components { @@ -17,17 +17,18 @@ internal interface IHasMultipleTypes public class CreateObjectComponent : GH_Component, IGH_VariableParameterComponent { - private readonly string _defaultNickName = "Property"; - private readonly string _numbers = "1234567890"; + private const string _myDefaultNickname = "Object"; + private const string _defaultNickName = "Property"; + private const string _numbers = "1234567890"; private string _nickNameCache; public CreateObjectComponent() - : base( "Create Object", "Object", + : base( "Create Object", _myDefaultNickname, "Encapsulate multiple kinds of data within a single object", "Sets", "Objectivism" ) { - this._nickNameCache = this.NickName; + this._nickNameCache = _myDefaultNickname; this.IconDisplayMode = GH_IconDisplayMode.name; this.ObjectChanged += this.NickNameChangedEventHandler; } @@ -60,8 +61,10 @@ public void VariableParameterMaintenance() var emptyParams = dynamicParams.Where( p => p.NickName == string.Empty ); foreach ( var param in emptyParams ) { - var paramKey = GH_ComponentParamServer.InventUniqueNickname( this._numbers, this.StrippedParamNames() ); - param.NickName = this._defaultNickName + paramKey; + // TODO: TG: Review. The use of StrippedParamNames() does not make sense to me. + + var paramKey = GH_ComponentParamServer.InventUniqueNickname( _numbers, this.StrippedParamNames() ); + param.NickName = _defaultNickName + paramKey; } } @@ -92,19 +95,19 @@ private void CommitParamNames( IGH_Param param ) } - protected override void SolveInstance( IGH_DataAccess DA ) + 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++ ) { - data.Add( RetrieveProperties( DA, i, this ) ); + data.Add( this.GetProperty( daObject, i ) ); } var obj = new ObjectivismObject( data, typeName ); var ghObj = new GH_ObjectivismObject( obj ); - DA.SetData( 0, ghObj ); + daObject.SetData( 0, ghObj ); } private List StrippedParamNames() @@ -113,9 +116,10 @@ private List StrippedParamNames() return variableParams .Select( p => p.NickName ) .Where( n => - n.StartsWith( this._defaultNickName ) && - this._numbers.Contains( n.ToCharArray()[this._defaultNickName.Length] ) ) - .Select( n => n.Replace( this._defaultNickName, "" ) ) + n.Length > _defaultNickName.Length + && char.IsDigit( n[_defaultNickName.Length] ) + && n.StartsWith( _defaultNickName, StringComparison.Ordinal ) ) + .Select( n => n.Substring( _defaultNickName.Length ) ) .ToList(); } diff --git a/ObjectivismGH/Components/FilterByType.cs b/ObjectivismGH/Components/FilterByType.cs index ca012e4..be9a4e3 100644 --- a/ObjectivismGH/Components/FilterByType.cs +++ b/ObjectivismGH/Components/FilterByType.cs @@ -1,5 +1,4 @@ using Grasshopper.Kernel; -using Grasshopper.Kernel.Parameters; using Grasshopper.Kernel.Types; using Objectivism.ObjectClasses; using Objectivism.Parameters; @@ -11,14 +10,15 @@ 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. /// - public FilterByTypeOBSOLETE() + public FilterByType() : base( "Filter By Type Old", "Filter", "Filter objects by their type name", "Sets", "Objectivism" ) @@ -86,17 +86,6 @@ 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(); @@ -106,11 +95,11 @@ protected override void BeforeSolveInstance() /// /// 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; } @@ -133,11 +122,11 @@ protected override void SolveInstance( IGH_DataAccess DA ) var name = param.NickName; if ( obj.Value.TypeName == name ) { - DA.SetData( i, obj ); + daObject.SetData( i, obj ); } else { - DA.SetData( i, null ); + daObject.SetData( i, null ); } } } @@ -167,7 +156,7 @@ private void GetAllTypesEventHandler( object sender, EventArgs e ) { this.RecordUndoEvent( "GetAllTypes" ); var unusedNames = this.GetUnusedNames(); - foreach ( var name in unusedNames ) + for ( var i = 0; i < unusedNames.Count; ++i ) { var param = new Param_ObjectivismObjectTypeOutput(); this.Params.RegisterOutputParam( param ); @@ -178,7 +167,5 @@ private void GetAllTypesEventHandler( object sender, EventArgs e ) this.Params.OnParametersChanged(); this.ExpireSolution( true ); } - - private void UpdateObjectEventHandler( object sender, EventArgs e ) => this.ExpireSolution( true ); } } \ No newline at end of file diff --git a/ObjectivismGH/Components/FilterByTypeV2.cs b/ObjectivismGH/Components/FilterByTypeV2.cs index b59fa69..f3aee8f 100644 --- a/ObjectivismGH/Components/FilterByTypeV2.cs +++ b/ObjectivismGH/Components/FilterByTypeV2.cs @@ -87,7 +87,7 @@ protected override void RegisterOutputParams( GH_OutputParamManager pManager ) { } - + // TODO: Appears to be unused. Remove? private HashSet GetTypeNames() { var input = (Param_GenericObject) this.Params.Input[0]; @@ -107,11 +107,11 @@ protected override void BeforeSolveInstance() /// /// 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; } @@ -134,7 +134,7 @@ protected override void SolveInstance( IGH_DataAccess DA ) var name = param.NickName; if ( obj.Value.TypeName == name ) { - DA.SetData( i, obj ); + daObject.SetData( i, obj ); } //DA.SetData(i, null); } @@ -165,7 +165,8 @@ private void GetAllTypesEventHandler( object sender, EventArgs e ) { this.RecordUndoEvent( "GetAllTypes" ); var unusedNames = this.GetUnusedNames(); - foreach ( var name in unusedNames ) + + for ( var i = 0; i < unusedNames.Count; ++i ) { var param = new Param_ObjectivismObjectTypeOutput(); this.Params.RegisterOutputParam( param ); @@ -176,10 +177,5 @@ private void GetAllTypesEventHandler( object sender, EventArgs e ) this.Params.OnParametersChanged(); this.ExpireSolution( true ); } - - private void UpdateObjectEventHandler( object sender, EventArgs e ) - { - //ExpireSolution(true); - } } } \ No newline at end of file diff --git a/ObjectivismGH/Components/GetPropertiesComponent.cs b/ObjectivismGH/Components/GetPropertiesComponent.cs index d2f39b1..d77b1e5 100644 --- a/ObjectivismGH/Components/GetPropertiesComponent.cs +++ b/ObjectivismGH/Components/GetPropertiesComponent.cs @@ -159,11 +159,11 @@ private string GetTypeName() /// /// 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; } @@ -204,20 +204,20 @@ protected override void SolveInstance( IGH_DataAccess DA ) if ( access == PropertyAccess.Item ) { var item = prop?.Data.get_FirstItem( false ); - var path = DA.ParameterTargetPath( i ); + var path = daObject.ParameterTargetPath( i ); if ( this._graftItems ) { - int[] index = { DA.ParameterTargetIndex( 0 ) }; + 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 ); + daObject.SetDataTree( i, tree ); } else { var tree = new GH_Structure(); tree.Append( item, path ); - DA.SetDataTree( i, tree ); + daObject.SetDataTree( i, tree ); } } @@ -227,12 +227,12 @@ protected override void SolveInstance( IGH_DataAccess DA ) ? prop.Data.Branches[0] : new List(); - var path = DA.ParameterTargetPath( i ); - int[] index = { DA.ParameterTargetIndex( 0 ) }; + 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 ); + daObject.SetDataTree( i, tree ); } if ( access == PropertyAccess.Tree ) @@ -240,13 +240,13 @@ protected override void SolveInstance( IGH_DataAccess DA ) var tree = prop != null ? prop.Data : Util.EmptyTree; - var basePath = DA.ParameterTargetPath( i ); + var basePath = daObject.ParameterTargetPath( i ); var outTree = new GH_Structure(); 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 ) @@ -255,7 +255,7 @@ protected override void SolveInstance( IGH_DataAccess DA ) outTree.AppendRange( branch, newPath ); } - DA.SetDataTree( i, outTree ); + daObject.SetDataTree( i, outTree ); } } } @@ -296,7 +296,7 @@ private void FullExplodeEventHandler( object sender, EventArgs e ) { this.RecordUndoEvent( "Object full explode" ); var unusedNames = this.GetUnusedNames(); - foreach ( var name in unusedNames ) + for ( var i = 0; i < unusedNames.Count; ++i ) { var param = new Param_ObjectivismOutput(); this.Params.RegisterOutputParam( param ); diff --git a/ObjectivismGH/Components/ImplementsComponent.cs b/ObjectivismGH/Components/ImplementsComponent.cs index 1d5ad80..35b76e6 100644 --- a/ObjectivismGH/Components/ImplementsComponent.cs +++ b/ObjectivismGH/Components/ImplementsComponent.cs @@ -39,14 +39,14 @@ protected override void RegisterInputParams( GH_InputParamManager pManager ) 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 ) ) + if ( !daObject.TryGetObjectivsmObject( 0, out var template ) ) { return; } - if ( !DA.TryGetObjectivsmObject( 1, out var subject ) ) + if ( !daObject.TryGetObjectivsmObject( 1, out var subject ) ) { return; } @@ -54,7 +54,7 @@ protected override void SolveInstance( IGH_DataAccess DA ) this.TypeNames.Add( template.TypeName ); this.TypeNames.Add( subject.TypeName ); - DA.SetData( 0, subject.Implements( template ) ); + 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 c0246bc..a978a2f 100644 --- a/ObjectivismGH/Components/InheritComponent.cs +++ b/ObjectivismGH/Components/InheritComponent.cs @@ -1,5 +1,6 @@ using Grasshopper.Kernel; using Grasshopper.Kernel.Parameters; +using Objectivism.Components.Utilities; using Objectivism.ObjectClasses; using Objectivism.Parameters; using System; @@ -7,32 +8,31 @@ using System.Drawing; using System.Linq; using System.Windows.Forms; -using static Objectivism.Components.Utilities.DataUtil; namespace Objectivism.Components { public class InheritComponent : GH_Component, IGH_VariableParameterComponent, IHasMultipleTypes { - private readonly string _defaultNickName = "Property"; + private const string _myDefaultNickname = "NewTypeName"; + private const string _defaultNickName = "Property"; - private readonly string _description = + 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 readonly string _numbers = "1234567890"; + private const string _numbers = "1234567890"; private readonly HashSet _propertyNames = new HashSet(); - private string _nickNameCache; /// /// Initializes a new instance of the ChangePropertiesComponent class. /// public InheritComponent() - : base( "Inherit", "NewTypeName", + : base( "Inherit", _myDefaultNickname, "Create a new object from a template. Add or change properties as required", "Sets", "Objectivism" ) { - this._nickNameCache = this.NickName; + this._nickNameCache = _myDefaultNickname; this.IconDisplayMode = GH_IconDisplayMode.name; this.ObjectChanged += this.NickNameChangedEventHandler; this.Message = "Inherit"; @@ -62,7 +62,7 @@ public IGH_Param CreateParameter( GH_ParameterSide side, int index ) Name = "PropertyToChange", nickNameCache = string.Empty, NickName = string.Empty, - Description = this._description + Description = _description }; return param; } @@ -98,10 +98,12 @@ internal List GetUnusedNames() => internal string NextUnusedName() { + // TODO: TG: Review. The use of StrippedParamNames() does not make sense to me. + var unusedNames = this.GetUnusedNames(); return unusedNames.Count == 0 - ? this._defaultNickName + - GH_ComponentParamServer.InventUniqueNickname( this._numbers, this.StrippedParamNames() ) + ? _defaultNickName + + GH_ComponentParamServer.InventUniqueNickname( _numbers, this.StrippedParamNames() ) : unusedNames[0]; } @@ -147,8 +149,6 @@ private void ObjectWireChangedHandler( IGH_DocumentObject sender, GH_ObjectChang { this.UpdatePropertyNames(); } - - ; } /// @@ -180,8 +180,6 @@ private void UpdateTypeNames() } } - private bool JustOneTypeName() => this.TypeNames.Count <= 1; - private void CommitParamNames( IGH_Param param ) { if ( param is Param_ExtraObjectProperty p ) @@ -205,13 +203,13 @@ public void NickNameChangedEventHandler( object sender, GH_ObjectChangedEventArg /// /// 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; this._nickNameCache = this.NickName; - if ( !DA.TryGetObjectivsmObject( 0, out var obj ) ) + if ( !daObject.TryGetObjectivsmObject( 0, out var obj ) ) { return; } @@ -220,12 +218,12 @@ protected override void SolveInstance( IGH_DataAccess DA ) for ( var i = 1; i < this.Params.Input.Count; i++ ) { - updates.Add( RetrieveProperties( DA, i, this ) ); + updates.Add( this.GetProperty( daObject, i ) ); } var (newObj, accessConflict) = obj.AddOrChangeProperties( updates, typeName ); accessConflict.BroadcastConflicts( this ); - DA.SetData( 0, new GH_ObjectivismObject( newObj ) ); + daObject.SetData( 0, new GH_ObjectivismObject( newObj ) ); } private List StrippedParamNames() @@ -234,9 +232,10 @@ private List StrippedParamNames() return variableParams .Select( p => p.NickName ) .Where( n => - n.StartsWith( this._defaultNickName ) && - this._numbers.Contains( n.ToCharArray()[this._defaultNickName.Length] ) ) - .Select( n => n.Replace( this._defaultNickName, "" ) ) + n.Length > _defaultNickName.Length + && char.IsDigit( n[_defaultNickName.Length] ) + && n.StartsWith( _defaultNickName, StringComparison.Ordinal ) ) + .Select( n => n.Substring( _defaultNickName.Length ) ) .ToList(); } diff --git a/ObjectivismGH/Components/ObjectToTree.cs b/ObjectivismGH/Components/ObjectToTree.cs index 11f8afe..e669ab9 100644 --- a/ObjectivismGH/Components/ObjectToTree.cs +++ b/ObjectivismGH/Components/ObjectToTree.cs @@ -75,11 +75,11 @@ private void AddToStoreIfRequired( string name ) /// /// 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; } @@ -120,8 +120,8 @@ protected override void SolveInstance( IGH_DataAccess DA ) { var item = prop?.Data.get_FirstItem( false ); var path = new List { i }; - path.AddRange( DA.ParameterTargetPath( 0 ).Indices ); - path.Add( DA.ParameterTargetIndex( 0 ) ); + 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 ); @@ -133,8 +133,8 @@ protected override void SolveInstance( IGH_DataAccess DA ) ? prop.Data.Branches[0] : new List(); var path = new List { i }; - path.AddRange( DA.ParameterTargetPath( 0 ).Indices ); - path.Add( DA.ParameterTargetIndex( 0 ) ); + 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 ); @@ -146,8 +146,8 @@ protected override void SolveInstance( IGH_DataAccess DA ) ? prop.Data : Util.EmptyTree; var path = new List { i }; - path.AddRange( DA.ParameterTargetPath( 0 ).Indices ); - path.Add( DA.ParameterTargetIndex( 0 ) ); + path.AddRange( daObject.ParameterTargetPath( 0 ).Indices ); + path.Add( daObject.ParameterTargetIndex( 0 ) ); for ( var j = 0; j < tree.PathCount; j++ ) { var branch = tree.Branches[j]; @@ -162,8 +162,8 @@ protected override void SolveInstance( IGH_DataAccess DA ) } } - DA.SetDataTree( 0, outTree ); - DA.SetDataTree( 1, nameTree ); + daObject.SetDataTree( 0, outTree ); + daObject.SetDataTree( 1, nameTree ); } protected override void AfterSolveInstance() diff --git a/ObjectivismGH/Components/Utilities/DataUtil.cs b/ObjectivismGH/Components/Utilities/ComponentExtensions.cs similarity index 55% rename from ObjectivismGH/Components/Utilities/DataUtil.cs rename to ObjectivismGH/Components/Utilities/ComponentExtensions.cs index a7527c8..ca09bd4 100644 --- a/ObjectivismGH/Components/Utilities/DataUtil.cs +++ b/ObjectivismGH/Components/Utilities/ComponentExtensions.cs @@ -7,13 +7,14 @@ namespace Objectivism.Components.Utilities { - internal static class DataUtil + internal static class ComponentExtensions { - internal static (string Name, ObjectProperty Property) RetrieveProperties( IGH_DataAccess DA, int paramIndex, - IGH_Component @this ) + public static (string Name, ObjectProperty Property) GetProperty( this IGH_Component component, + IGH_DataAccess daObject, int paramIndex ) { var previewOn = true; - var param = @this.Params.Input[paramIndex]; + var param = component.Params.Input[paramIndex]; + if ( param is IHasPreviewToggle hasPreviewToggle ) { previewOn = hasPreviewToggle.PreviewOn; @@ -24,9 +25,9 @@ internal static (string Name, ObjectProperty Property) RetrieveProperties( IGH_D if ( param.Access == GH_ParamAccess.item ) { IGH_Goo item = null; - if ( !DA.GetData( paramIndex, ref item ) ) + if ( !daObject.GetData( paramIndex, ref item ) ) { - @this.AddRuntimeMessage( GH_RuntimeMessageLevel.Remark, + component.AddRuntimeMessage( GH_RuntimeMessageLevel.Remark, $"{name} has no input and has been assigned null data" ); } @@ -35,32 +36,17 @@ internal static (string Name, ObjectProperty Property) RetrieveProperties( IGH_D else if ( param.Access == GH_ParamAccess.list ) { var items = new List(); - DA.GetDataList( paramIndex, items ); + daObject.GetDataList( paramIndex, items ); prop = new ObjectProperty( items ); } else //tree access { - DA.GetDataTree( paramIndex, out GH_Structure itemTree ); + daObject.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; - } } } \ 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 From 60143e7e1688d624283258c9ca1aeec6e10ab4fd Mon Sep 17 00:00:00 2001 From: Tom Glastonbury Date: Mon, 17 Jun 2024 20:04:19 +0100 Subject: [PATCH 6/8] Fix/comment warnings. --- CommonStyle.DotSettings | 48 ------------------ .../AddOrChangePropertiesComponent.cs | 13 +---- ObjectivismGH/Components/FilterByType.cs | 2 +- ObjectivismGH/Components/FilterByTypeV2.cs | 2 +- .../Components/GetPropertiesComponent.cs | 2 +- ObjectivismGH/Components/InheritComponent.cs | 13 +---- ObjectivismGH/Forms/ChangePropertyNameForm.cs | 22 ++++----- .../ObjectClasses/GH_ObjectivismObject.cs | 45 +++++++---------- ObjectivismGH/ObjectClasses/ObjectProperty.cs | 7 +-- .../ObjectClasses/ObjectivismObject.cs | 49 ++++++++++++------- .../Parameters/Param_ExtraObjectProperty.cs | 44 +++++++++++------ .../Parameters/Param_NewObjectProperty.cs | 28 ++++++----- .../Parameters/Param_ObjectivismOutput.cs | 39 ++++++++++++--- 13 files changed, 143 insertions(+), 171 deletions(-) diff --git a/CommonStyle.DotSettings b/CommonStyle.DotSettings index 91bc6b7..9b17839 100644 --- a/CommonStyle.DotSettings +++ b/CommonStyle.DotSettings @@ -351,53 +351,5 @@ True True True - True - True - True - True - True - True True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - 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 224888e..098877e 100644 --- a/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs +++ b/ObjectivismGH/Components/AddOrChangePropertiesComponent.cs @@ -51,16 +51,7 @@ public bool CanRemoveParameter( GH_ParameterSide side, int index ) => side == GH_ParameterSide.Input && index != 0; public IGH_Param CreateParameter( GH_ParameterSide side, int index ) - { - var param = new Param_ExtraObjectProperty - { - Name = "PropertyToChange", - nickNameCache = string.Empty, - NickName = string.Empty, - Description = this._description - }; - return param; - } + => new Param_ExtraObjectProperty { Name = "PropertyToChange", Description = this._description }; public bool DestroyParameter( GH_ParameterSide side, int index ) => true; @@ -76,7 +67,7 @@ public void VariableParameterMaintenance() { if ( param is Param_ExtraObjectProperty extraParam ) { - extraParam.AllPropertyNames = this._propertyNames; + extraParam.ReplaceAllPropertyNames( this._propertyNames ); } if ( param.NickName == string.Empty ) diff --git a/ObjectivismGH/Components/FilterByType.cs b/ObjectivismGH/Components/FilterByType.cs index be9a4e3..796879e 100644 --- a/ObjectivismGH/Components/FilterByType.cs +++ b/ObjectivismGH/Components/FilterByType.cs @@ -57,7 +57,7 @@ public void VariableParameterMaintenance() if ( param is Param_ObjectivismObjectTypeOutput outputParam ) { - outputParam.AllPropertyNames = this._typeNames; + outputParam.ReplaceAllPropertyNames( this._typeNames ); } } } diff --git a/ObjectivismGH/Components/FilterByTypeV2.cs b/ObjectivismGH/Components/FilterByTypeV2.cs index f3aee8f..7720555 100644 --- a/ObjectivismGH/Components/FilterByTypeV2.cs +++ b/ObjectivismGH/Components/FilterByTypeV2.cs @@ -52,7 +52,7 @@ public void VariableParameterMaintenance() if ( param is Param_ObjectivismObjectTypeOutput outputParam ) { - outputParam.AllPropertyNames = this.TypeNames; + outputParam.ReplaceAllPropertyNames( this.TypeNames ); } } } diff --git a/ObjectivismGH/Components/GetPropertiesComponent.cs b/ObjectivismGH/Components/GetPropertiesComponent.cs index d77b1e5..42d3866 100644 --- a/ObjectivismGH/Components/GetPropertiesComponent.cs +++ b/ObjectivismGH/Components/GetPropertiesComponent.cs @@ -61,7 +61,7 @@ public void VariableParameterMaintenance() if ( param is Param_ObjectivismOutput outputParam ) { - outputParam.AllPropertyNames = this._propertyNames; + outputParam.ReplaceAllPropertyNames( this._propertyNames ); } } } diff --git a/ObjectivismGH/Components/InheritComponent.cs b/ObjectivismGH/Components/InheritComponent.cs index a978a2f..4bb084e 100644 --- a/ObjectivismGH/Components/InheritComponent.cs +++ b/ObjectivismGH/Components/InheritComponent.cs @@ -56,16 +56,7 @@ public bool CanRemoveParameter( GH_ParameterSide side, int index ) => side == GH_ParameterSide.Input && index != 0; public IGH_Param CreateParameter( GH_ParameterSide side, int index ) - { - var param = new Param_ExtraObjectProperty - { - Name = "PropertyToChange", - nickNameCache = string.Empty, - NickName = string.Empty, - Description = _description - }; - return param; - } + => new Param_ExtraObjectProperty { Name = "PropertyToChange", Description = _description }; public bool DestroyParameter( GH_ParameterSide side, int index ) => true; @@ -81,7 +72,7 @@ public void VariableParameterMaintenance() { if ( param is Param_ExtraObjectProperty extraParam ) { - extraParam.AllPropertyNames = this._propertyNames; + extraParam.ReplaceAllPropertyNames( this._propertyNames ); } if ( param.NickName == string.Empty ) diff --git a/ObjectivismGH/Forms/ChangePropertyNameForm.cs b/ObjectivismGH/Forms/ChangePropertyNameForm.cs index bb1d456..523a8ea 100644 --- a/ObjectivismGH/Forms/ChangePropertyNameForm.cs +++ b/ObjectivismGH/Forms/ChangePropertyNameForm.cs @@ -74,7 +74,7 @@ private void SetRadio( int i ) private void GetParamsOfAllTypes() { var createParams = this._doc.Objects - .Where( obj => obj is CreateObjectComponent c ) + .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 ) ) @@ -86,14 +86,14 @@ private void GetParamsOfAllTypes() .Where( p => p is Param_ExtraObjectProperty && p.NickName == this._propName ) ) .SelectMany( x => x ); var propParams = this._doc.Objects - .Where( obj => obj is GetPropertiesComponent c ) + .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 ); - var count = allParams.Count(); - this._paramsToChange = allParams.ToList(); + var allParams = createParams.Concat( changeParams ).Concat( propParams ).ToList(); + var count = allParams.Count; + this._paramsToChange = allParams; this.InstancesLabel.Text = $"{count} instances found"; this.Update(); } @@ -135,9 +135,9 @@ obj is GetPropertiesComponent c .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 ); - var count = allParams.Count(); - this._paramsToChange = allParams.ToList(); + var allParams = createParams.Concat( changeParams ).Concat( propParams ).ToList(); + var count = allParams.Count; + this._paramsToChange = allParams; this.InstancesLabel.Text = $"{count} instances found"; this.Update(); } @@ -196,9 +196,9 @@ obj is GetPropertiesComponent c .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 ); - var count = allParams.Count(); - this._paramsToChange = allParams.ToList(); + var allParams = createParams.Concat( changeParams ).Concat( propParams ).ToList(); + var count = allParams.Count; + this._paramsToChange = allParams; this.InstancesLabel.Text = $"{count} instances found"; this.Update(); } diff --git a/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs b/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs index 87bdba2..ca51bb7 100644 --- a/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs +++ b/ObjectivismGH/ObjectClasses/GH_ObjectivismObject.cs @@ -1,5 +1,4 @@ -using GH_IO; -using GH_IO.Serialization; +using GH_IO.Serialization; using Grasshopper.Kernel; using Grasshopper.Kernel.Types; using Rhino.Geometry; @@ -8,23 +7,13 @@ 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 ) - { - this.Value = value; - } + public GH_ObjectivismObject( ObjectivismObject value ) : base( value ) { } - public GH_ObjectivismObject() - { - this.Value = null; - } + public GH_ObjectivismObject() { } - public GH_ObjectivismObject( GH_ObjectivismObject other ) - { - this.Value = other.Value; - } + public GH_ObjectivismObject( GH_ObjectivismObject other ) : base( other.Value ) { } public override bool IsValid => true; @@ -35,6 +24,16 @@ public GH_ObjectivismObject( GH_ObjectivismObject other ) public override BoundingBox Boundingbox => this.Value.BoundingBox; + + public BoundingBox ClippingBox => this.Value.ClippingBox; + + public void DrawViewportWires( GH_PreviewWireArgs args ) => this.Value.DrawViewportWires( args ); + + public void DrawViewportMeshes( GH_PreviewMeshArgs args ) => this.Value.DrawViewportMeshes( args ); + + public void AppendRenderGeometry( GH_RenderArgs args, RenderMaterial material ) => + this.Value.AppendRenderGeometry( args, material ); + public override bool Read( GH_IReader reader ) { var value = new ObjectivismObject(); @@ -61,16 +60,6 @@ public override bool Write( GH_IWriter writer ) } } - - public BoundingBox ClippingBox => this.Value.ClippingBox; - - public void DrawViewportWires( GH_PreviewWireArgs args ) => this.Value.DrawViewportWires( args ); - - public void DrawViewportMeshes( GH_PreviewMeshArgs args ) => this.Value.DrawViewportMeshes( args ); - - public void AppendRenderGeometry( GH_RenderArgs args, RenderMaterial material ) => - this.Value.AppendRenderGeometry( args, material ); - public override IGH_Goo Duplicate() => new GH_ObjectivismObject( this.Value ); public override IGH_GeometricGoo DuplicateGeometry() => new GH_ObjectivismObject( this.Value ); @@ -81,9 +70,9 @@ public override bool CastFrom( object source ) { if ( source == null ) { return false; } - if ( source is GH_ObjectivismObject gh_obj ) + if ( source is GH_ObjectivismObject ghObject ) { - this.Value = gh_obj.Value; + this.Value = ghObject.Value; return true; } diff --git a/ObjectivismGH/ObjectClasses/ObjectProperty.cs b/ObjectivismGH/ObjectClasses/ObjectProperty.cs index 74e8b4f..1ccbc88 100644 --- a/ObjectivismGH/ObjectClasses/ObjectProperty.cs +++ b/ObjectivismGH/ObjectClasses/ObjectProperty.cs @@ -152,12 +152,7 @@ private IGH_Goo DuplicateUtil( IGH_Goo goo ) return geom.DuplicateGeometry(); } - if ( goo != null ) - { - return goo.Duplicate(); - } - - return goo; + return goo?.Duplicate(); } public bool WriteProp( GH_IWriter writer ) diff --git a/ObjectivismGH/ObjectClasses/ObjectivismObject.cs b/ObjectivismGH/ObjectClasses/ObjectivismObject.cs index 0cfeced..c58b7a6 100644 --- a/ObjectivismGH/ObjectClasses/ObjectivismObject.cs +++ b/ObjectivismGH/ObjectClasses/ObjectivismObject.cs @@ -232,28 +232,41 @@ internal dynamic ToDynamic() { 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(); - eoColl.Add( new KeyValuePair( name, list ) ); + eoColl.Add( new KeyValuePair( name, null ) ); } - - if ( prop.Access == PropertyAccess.Tree ) + else { - var tree = prop != null - ? prop.Data.ToDataTree( ProcessGoo ) - : new DataTree(); - eoColl.Add( new KeyValuePair( name, tree ) ); + 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 ) + { + var list = prop != null + ? prop.Data.Branches[0].Select( ProcessGoo ).ToList() + : new List(); + eoColl.Add( new KeyValuePair( name, list ) ); + } + + if ( prop.Access == PropertyAccess.Tree ) + { + var tree = prop != null + ? prop.Data.ToDataTree( ProcessGoo ) + : new DataTree(); + eoColl.Add( new KeyValuePair( name, tree ) ); + } } } diff --git a/ObjectivismGH/Parameters/Param_ExtraObjectProperty.cs b/ObjectivismGH/Parameters/Param_ExtraObjectProperty.cs index 1166867..c27c1af 100644 --- a/ObjectivismGH/Parameters/Param_ExtraObjectProperty.cs +++ b/ObjectivismGH/Parameters/Param_ExtraObjectProperty.cs @@ -10,15 +10,20 @@ namespace Objectivism.Parameters { - public class Param_ExtraObjectProperty : Param_GenericObject, IHasPreviewToggle //Item access, property retrieval + public sealed class + Param_ExtraObjectProperty : Param_GenericObject, IHasPreviewToggle //Item access, property retrieval { - internal HashSet AllPropertyNames = new HashSet(); - internal string nickNameCache = ""; + private readonly HashSet _allPropertyNames = new HashSet(); + private string _nickNameCache; + /// + /// Initializes a new instance of the class with default values. + /// The initial nick name and nick name cache are . + /// public Param_ExtraObjectProperty() { this.Name = "Extra Property"; - this.nickNameCache = string.Empty; + this._nickNameCache = string.Empty; this.NickName = string.Empty; this.Description = "Property to change/add to object"; this.Access = GH_ParamAccess.item; @@ -26,17 +31,26 @@ public Param_ExtraObjectProperty() } public override Guid ComponentGuid => new Guid( "41412f8c-c2d9-45c7-83d0-bd04a10e14fa" ); + public override GH_Exposure Exposure => GH_Exposure.hidden; + public override string TypeName => "Object Property Data"; public bool PreviewOn { get; private set; } = true; - internal void CommitNickName() => this.nickNameCache = this.NickName; + + internal void ReplaceAllPropertyNames( IEnumerable names ) + { + this._allPropertyNames.Clear(); + this._allPropertyNames.UnionWith( names ); + } + + internal void CommitNickName() => this._nickNameCache = this.NickName; public void NickNameChangedEventHandler( object sender, GH_ObjectChangedEventArgs args ) { if ( args.Type == GH_ObjectEventType.NickName ) { - if ( this.NickName != this.nickNameCache ) + if ( this.NickName != this._nickNameCache ) { this.AddRuntimeMessage( GH_RuntimeMessageLevel.Warning, "Property input name changed but object not updated, right click on component and press \"Recompute\"" ); @@ -50,12 +64,11 @@ public override void AppendAdditionalMenuItems( ToolStripDropDown menu ) Menu_AppendSeparator( menu ); - var recomputeButton = Menu_AppendItem( menu, "Recompute", this.RecomputeHandler ); + Menu_AppendItem( menu, "Recompute", this.RecomputeHandler ); Menu_AppendSeparator( menu ); - var toggleButton = - Menu_AppendItem( menu, "Preview Geometry", this.PreviewToggleHandler, true, this.PreviewOn ); + Menu_AppendItem( menu, "Preview Geometry", this.PreviewToggleHandler, true, this.PreviewOn ); Menu_AppendSeparator( menu ); @@ -63,19 +76,20 @@ public override void AppendAdditionalMenuItems( ToolStripDropDown menu ) var isList = this.Access == GH_ParamAccess.list; var isTree = this.Access == GH_ParamAccess.tree; - var itemButton = Menu_AppendItem( menu, "Item Access", this.ItemAccessEventHandler, true, isItem ); - var listButton = Menu_AppendItem( menu, "List Access", this.ListAccessEventHandler, true, isList ); - var treeButton = Menu_AppendItem( menu, "Tree Access", this.TreeAccessEventHandler, true, isTree ); + Menu_AppendItem( menu, "Item Access", this.ItemAccessEventHandler, true, isItem ); + Menu_AppendItem( menu, "List Access", this.ListAccessEventHandler, true, isList ); + Menu_AppendItem( menu, "Tree Access", this.TreeAccessEventHandler, true, isTree ); Menu_AppendSeparator( menu ); var button = Menu_AppendItem( menu, "Properties" ); - var dropDownButtons = this.AllPropertyNames - .Select( n => new ToolStripMenuItem( n, null, this.PropertyClickEventHandler ) ).ToArray(); + var dropDownButtons = this._allPropertyNames + .Select( n => (ToolStripItem) new ToolStripMenuItem( n, null, this.PropertyClickEventHandler ) ) + .ToArray(); button.DropDownItems.AddRange( dropDownButtons ); Menu_AppendSeparator( menu ); - var changeButton = Menu_AppendItem( menu, "Change Property Name", this.LaunchChangeDialog, true ); + Menu_AppendItem( menu, "Change Property Name", this.LaunchChangeDialog, true ); } private void PreviewToggleHandler( object sender, EventArgs e ) diff --git a/ObjectivismGH/Parameters/Param_NewObjectProperty.cs b/ObjectivismGH/Parameters/Param_NewObjectProperty.cs index 8192c17..311556d 100644 --- a/ObjectivismGH/Parameters/Param_NewObjectProperty.cs +++ b/ObjectivismGH/Parameters/Param_NewObjectProperty.cs @@ -7,14 +7,19 @@ namespace Objectivism.Parameters { - public class Param_NewObjectProperty : Param_GenericObject, IHasPreviewToggle + public sealed class Param_NewObjectProperty : Param_GenericObject, IHasPreviewToggle { - internal string nickNameCache = ""; + private const string _myDefaultNickName = "Prop"; + private string _nickNameCache; + /// + /// Initializes a new instance of the class with default values. + /// Nick name and nick name cache are both set to "Prop". + /// public Param_NewObjectProperty() { this.Name = "Property"; - this.nickNameCache = "Prop"; + this._nickNameCache = "Prop"; this.NickName = "Prop"; this.Description = "Property for an Objectivsm Object "; this.ObjectChanged += this.NickNameChangedEventHandler; @@ -27,13 +32,13 @@ public Param_NewObjectProperty() public bool PreviewOn { get; private set; } = true; - internal void CommitNickName() => this.nickNameCache = this.NickName; + internal void CommitNickName() => this._nickNameCache = this.NickName; public void NickNameChangedEventHandler( object sender, GH_ObjectChangedEventArgs args ) { if ( args.Type == GH_ObjectEventType.NickName ) { - if ( this.NickName != this.nickNameCache ) + if ( this.NickName != this._nickNameCache ) { this.AddRuntimeMessage( GH_RuntimeMessageLevel.Warning, "Property input name changed but object not updated, right click on component and press \"Recompute\"" ); @@ -51,12 +56,11 @@ public override void AppendAdditionalMenuItems( ToolStripDropDown menu ) Menu_AppendSeparator( menu ); - var recomputeButton = Menu_AppendItem( menu, "Recompute", this.RecomputeHandler ); + Menu_AppendItem( menu, "Recompute", this.RecomputeHandler ); Menu_AppendSeparator( menu ); - var toggleButton = - Menu_AppendItem( menu, "Preview Geometry", this.PreviewToggleHandler, true, this.PreviewOn ); + Menu_AppendItem( menu, "Preview Geometry", this.PreviewToggleHandler, true, this.PreviewOn ); Menu_AppendSeparator( menu ); @@ -64,13 +68,13 @@ public override void AppendAdditionalMenuItems( ToolStripDropDown menu ) var isList = this.Access == GH_ParamAccess.list; var isTree = this.Access == GH_ParamAccess.tree; - var itemButton = Menu_AppendItem( menu, "Item Access", this.ItemAccessEventHandler, true, isItem ); - var listButton = Menu_AppendItem( menu, "List Access", this.ListAccessEventHandler, true, isList ); - var treeButton = Menu_AppendItem( menu, "Tree Access", this.TreeAccessEventHandler, true, isTree ); + Menu_AppendItem( menu, "Item Access", this.ItemAccessEventHandler, true, isItem ); + Menu_AppendItem( menu, "List Access", this.ListAccessEventHandler, true, isList ); + Menu_AppendItem( menu, "Tree Access", this.TreeAccessEventHandler, true, isTree ); Menu_AppendSeparator( menu ); - var changeButton = Menu_AppendItem( menu, "Change Property Name", this.LaunchChangeDialog, true ); + Menu_AppendItem( menu, "Change Property Name", this.LaunchChangeDialog, true ); } private void PreviewToggleHandler( object sender, EventArgs e ) diff --git a/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs b/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs index d0b5a5f..627def5 100644 --- a/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs +++ b/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs @@ -9,32 +9,54 @@ namespace Objectivism.Parameters { public class Param_ObjectivismOutput : Param_GenericObject { - internal HashSet AllPropertyNames = new HashSet(); - internal string nickNameCache = ""; + private readonly HashSet _allPropertyNames = new HashSet(); + private string _nickNameCache; + /// + /// Initializes a new instance of the class with default values. + /// Nick name and nick name cache are both set to . + /// public Param_ObjectivismOutput() { - this.Name = this.OutputType; - this.nickNameCache = string.Empty; + base.Name = this.OutputType; + this._nickNameCache = string.Empty; this.NickName = string.Empty; this.Description = $"Retrieved {this.OutputType} "; this.Access = GH_ParamAccess.tree; this.ObjectChanged += this.NickNameChangedEventHandler; } + public new virtual string Name + { + get => base.Name; + set => base.Name = value; + } + public override Guid ComponentGuid => new Guid( "1b625488-3ec8-4189-8d14-6de1b0c9effd" ); + protected virtual string OutputType => "Property"; + protected virtual string OutputTypePlural => "Properties"; + protected string OutputTyputLC => this.OutputType.ToLower(); + public override GH_Exposure Exposure => GH_Exposure.hidden; + public override string TypeName => $"Object {this.OutputType} Data"; - internal void CommitNickName() => this.nickNameCache = this.NickName; + + internal void ReplaceAllPropertyNames( IEnumerable names ) + { + this._allPropertyNames.Clear(); + this._allPropertyNames.UnionWith( names ); + } + + internal void CommitNickName() => this._nickNameCache = this.NickName; public void NickNameChangedEventHandler( object sender, GH_ObjectChangedEventArgs args ) { if ( args.Type == GH_ObjectEventType.NickName ) { - if ( this.NickName != this.nickNameCache ) + if ( this.NickName != this._nickNameCache ) { this.AddRuntimeMessage( GH_RuntimeMessageLevel.Warning, $"{this.OutputType} name changed but component not updated, right click on component and press \"Recompute\"" ); @@ -54,8 +76,9 @@ public override void AppendAdditionalMenuItems( ToolStripDropDown menu ) var recomputeButton = Menu_AppendItem( menu, "Recompute", this.RecomputeHandler ); Menu_AppendSeparator( menu ); var button = Menu_AppendItem( menu, this.OutputTypePlural ); - var dropDownButtons = this.AllPropertyNames - .Select( n => new ToolStripMenuItem( n, null, this.PropertyClickEventHandler ) ).ToArray(); + var dropDownButtons = this._allPropertyNames + .Select( n => (ToolStripItem) new ToolStripMenuItem( n, null, this.PropertyClickEventHandler ) ) + .ToArray(); button.DropDownItems.AddRange( dropDownButtons ); } From 57fc94d03d2b9f19fc8a0cb1942cd3eef101a1dc Mon Sep 17 00:00:00 2001 From: Tom Glastonbury Date: Tue, 18 Jun 2024 14:05:22 +0100 Subject: [PATCH 7/8] Apply selected codefix suggestions. --- ObjectivismGH/Components/FilterByType.cs | 9 +-------- ObjectivismGH/Components/ObjectToTree.cs | 2 +- .../Components/Utilities/AccessChecker.cs | 8 ++++---- ObjectivismGH/Forms/ChangePropertyNameForm.cs | 6 ++---- ObjectivismGH/ObjectClasses/ObjectProperty.cs | 2 +- ObjectivismGH/ObjectClasses/ObjectivismObject.cs | 16 ++++++---------- .../Parameters/Param_ObjectivismOutput.cs | 1 + 7 files changed, 16 insertions(+), 28 deletions(-) diff --git a/ObjectivismGH/Components/FilterByType.cs b/ObjectivismGH/Components/FilterByType.cs index 796879e..4278dbd 100644 --- a/ObjectivismGH/Components/FilterByType.cs +++ b/ObjectivismGH/Components/FilterByType.cs @@ -120,14 +120,7 @@ protected override void SolveInstance( IGH_DataAccess daObject ) foreach ( var (i, param) in this.Params.Output.Enumerate() ) { var name = param.NickName; - if ( obj.Value.TypeName == name ) - { - daObject.SetData( i, obj ); - } - else - { - daObject.SetData( i, null ); - } + daObject.SetData( i, obj.Value.TypeName == name ? obj : null ); } } diff --git a/ObjectivismGH/Components/ObjectToTree.cs b/ObjectivismGH/Components/ObjectToTree.cs index e669ab9..ee1afc4 100644 --- a/ObjectivismGH/Components/ObjectToTree.cs +++ b/ObjectivismGH/Components/ObjectToTree.cs @@ -96,7 +96,7 @@ protected override void SolveInstance( IGH_DataAccess daObject ) return; } - obj.AllProperties.ForEach( n => this.AddToStoreIfRequired( n ) ); + obj.AllProperties.ForEach( this.AddToStoreIfRequired ); var outTree = new GH_Structure(); var nameTree = new GH_Structure(); diff --git a/ObjectivismGH/Components/Utilities/AccessChecker.cs b/ObjectivismGH/Components/Utilities/AccessChecker.cs index 532e344..077c6d9 100644 --- a/ObjectivismGH/Components/Utilities/AccessChecker.cs +++ b/ObjectivismGH/Components/Utilities/AccessChecker.cs @@ -20,9 +20,9 @@ public AccessChecker( IGH_Component @this ) public void AccessCheck( ObjectProperty prop, string name ) { - if ( this._accessRecorder.ContainsKey( name ) ) + if ( this._accessRecorder.TryGetValue( name, out var access ) ) { - if ( this._accessRecorder[name] != prop.Access ) + if ( access != prop.Access ) { this._warningsToThrow.Add( name ); } @@ -44,9 +44,9 @@ public void ThrowWarnings() public PropertyAccess BestGuessAccess( string name ) { - if ( this._accessRecorder.ContainsKey( name ) ) + if ( this._accessRecorder.TryGetValue( name, out var access ) ) { - return this._accessRecorder[name]; + return access; } try diff --git a/ObjectivismGH/Forms/ChangePropertyNameForm.cs b/ObjectivismGH/Forms/ChangePropertyNameForm.cs index 523a8ea..6fd837c 100644 --- a/ObjectivismGH/Forms/ChangePropertyNameForm.cs +++ b/ObjectivismGH/Forms/ChangePropertyNameForm.cs @@ -103,9 +103,7 @@ private void GetParamsOfConnectedTypes() var connectedTypes = new HashSet { this._typeName }; var typeComps = - new Stack( this._doc.Objects - .Where( obj => obj is IHasMultipleTypes ) - .Select( obj => (IHasMultipleTypes) obj ) ); + new Stack( this._doc.Objects.OfType() ); connectedTypes = this.FindAllConnectedTypes( connectedTypes, typeComps ); @@ -144,7 +142,7 @@ obj is GetPropertiesComponent c private HashSet FindAllConnectedTypes( HashSet connectedTypes, Stack stack ) { - if ( stack.Count() == 0 ) + if ( stack.Count == 0 ) { return connectedTypes; } diff --git a/ObjectivismGH/ObjectClasses/ObjectProperty.cs b/ObjectivismGH/ObjectClasses/ObjectProperty.cs index 1ccbc88..d0ea749 100644 --- a/ObjectivismGH/ObjectClasses/ObjectProperty.cs +++ b/ObjectivismGH/ObjectClasses/ObjectProperty.cs @@ -32,7 +32,7 @@ public ObjectProperty( IGH_Goo item ) public ObjectProperty( List list ) { this.Data = new GH_Structure(); - var list2 = list.Select( goo => this.DeReferenceIfRequired( goo ) ).ToList(); + var list2 = list.Select( this.DeReferenceIfRequired ).ToList(); this.Data.AppendRange( list2 ); this.Access = PropertyAccess.List; } diff --git a/ObjectivismGH/ObjectClasses/ObjectivismObject.cs b/ObjectivismGH/ObjectClasses/ObjectivismObject.cs index c58b7a6..54d7137 100644 --- a/ObjectivismGH/ObjectClasses/ObjectivismObject.cs +++ b/ObjectivismGH/ObjectClasses/ObjectivismObject.cs @@ -92,9 +92,10 @@ internal bool Implements( ObjectivismObject template ) => public bool TryGetProperty( string name, out ObjectProperty property ) { property = null; - if ( this._propertyGetter.ContainsKey( name ) ) + + if ( this._propertyGetter.TryGetValue( name, out var propertyIndex ) ) { - property = this._properties[this._propertyGetter[name]].Property; + property = this._properties[propertyIndex].Property; return true; } @@ -103,9 +104,9 @@ public bool TryGetProperty( string name, out ObjectProperty property ) public ObjectProperty GetProperty( string name ) { - if ( this._propertyGetter.ContainsKey( name ) ) + if ( this._propertyGetter.TryGetValue( name, out var propertyIndex ) ) { - return this._properties[this._propertyGetter[name]].Property; + return this._properties[propertyIndex].Property; } return null; @@ -279,12 +280,7 @@ internal dynamic ToDynamic() internal class AccessInfo { - private readonly List _conflicts; - - public AccessInfo() - { - this._conflicts = new List(); - } + private readonly List _conflicts = new List(); public void AddConflict( string propertyName ) => this._conflicts.Add( propertyName ); diff --git a/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs b/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs index 627def5..d99b9d7 100644 --- a/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs +++ b/ObjectivismGH/Parameters/Param_ObjectivismOutput.cs @@ -18,6 +18,7 @@ public class Param_ObjectivismOutput : Param_GenericObject /// public Param_ObjectivismOutput() { + // TODO: Review, remove virtual member calls. https://discourse.mcneel.com/t/api-param-genericobject-does-not-provide-suitable-constructors/184753 base.Name = this.OutputType; this._nickNameCache = string.Empty; this.NickName = string.Empty; From 760f4ed5fe12817b3a3a4d22de4e29e60e7e2fc0 Mon Sep 17 00:00:00 2001 From: Tom Glastonbury Date: Tue, 18 Jun 2024 14:19:48 +0100 Subject: [PATCH 8/8] Final fixes. All tests (including manual) pass. --- ObjectivismGH/ObjectClasses/ObjectProperty.cs | 2 -- ObjectivismGH/ObjectClasses/PropertyAccess.cs | 4 ++++ ObjectivismGH/Parameters/Param_NewObjectProperty.cs | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 ObjectivismGH/ObjectClasses/PropertyAccess.cs diff --git a/ObjectivismGH/ObjectClasses/ObjectProperty.cs b/ObjectivismGH/ObjectClasses/ObjectProperty.cs index d0ea749..9cf13b8 100644 --- a/ObjectivismGH/ObjectClasses/ObjectProperty.cs +++ b/ObjectivismGH/ObjectClasses/ObjectProperty.cs @@ -11,8 +11,6 @@ namespace Objectivism.ObjectClasses { - internal enum PropertyAccess { Item, List, Tree } - public class ObjectProperty : IGH_RenderAwareData, IGH_PreviewData { public ObjectProperty() diff --git a/ObjectivismGH/ObjectClasses/PropertyAccess.cs b/ObjectivismGH/ObjectClasses/PropertyAccess.cs new file mode 100644 index 0000000..a1c96a2 --- /dev/null +++ b/ObjectivismGH/ObjectClasses/PropertyAccess.cs @@ -0,0 +1,4 @@ +namespace Objectivism.ObjectClasses +{ + internal enum PropertyAccess { Item, List, Tree } +} \ No newline at end of file diff --git a/ObjectivismGH/Parameters/Param_NewObjectProperty.cs b/ObjectivismGH/Parameters/Param_NewObjectProperty.cs index 311556d..6fde54c 100644 --- a/ObjectivismGH/Parameters/Param_NewObjectProperty.cs +++ b/ObjectivismGH/Parameters/Param_NewObjectProperty.cs @@ -9,7 +9,6 @@ namespace Objectivism.Parameters { public sealed class Param_NewObjectProperty : Param_GenericObject, IHasPreviewToggle { - private const string _myDefaultNickName = "Prop"; private string _nickNameCache; ///