1
- using System ;
2
- using System . Collections . Generic ;
3
- using System . Linq ;
1
+ using System . Collections . Generic ;
2
+ using GH_IO . Serialization ;
4
3
using Grasshopper . Kernel ;
5
- using Grasshopper . Kernel . Types ;
6
- using Newtonsoft . Json ;
7
- using OasysGH . Parameters ;
8
- using OasysUnits ;
9
- using OasysUnits . Serialization . JsonNet ;
10
4
11
5
namespace OasysGH . Components {
12
6
public abstract class GH_OasysDropDownComponent : GH_OasysComponent , IGH_VariableParameterComponent {
13
- protected internal bool _alwaysExpireDownStream = false ;
14
7
protected internal List < List < string > > _dropDownItems ;
15
- protected internal Dictionary < int , List < string > > _existingOutputsSerialized = new Dictionary < int , List < string > > ( ) ;
16
8
protected internal bool _isInitialised = false ;
17
9
protected internal List < string > _selectedItems ;
18
10
protected internal List < string > _spacerDescriptions ;
19
- private static readonly OasysUnitsIQuantityJsonConverter converter = new OasysUnitsIQuantityJsonConverter ( ) ;
20
- private Dictionary < int , bool > _outputIsExpired = new Dictionary < int , bool > ( ) ;
21
- private Dictionary < int , List < bool > > _outputsAreExpired = new Dictionary < int , List < bool > > ( ) ;
22
11
23
12
public GH_OasysDropDownComponent ( string name , string nickname , string description , string category , string subCategory ) : base ( name , nickname , description , category , subCategory ) {
24
13
}
@@ -38,41 +27,7 @@ public override void CreateAttributes() {
38
27
39
28
bool IGH_VariableParameterComponent . DestroyParameter ( GH_ParameterSide side , int index ) => false ;
40
29
41
- public void OutputChanged < T > ( T data , int outputIndex , int index ) where T : IGH_Goo {
42
- if ( ! _existingOutputsSerialized . ContainsKey ( outputIndex ) ) {
43
- _existingOutputsSerialized . Add ( outputIndex , new List < string > ( ) ) ;
44
- _outputsAreExpired . Add ( outputIndex , new List < bool > ( ) ) ;
45
- }
46
-
47
- string outputsSerialized = "" ;
48
- if ( data . GetType ( ) == typeof ( GH_UnitNumber ) ) {
49
- // use IQuantity converter if data is a IQuantity (struct)
50
- IQuantity quantity = ( ( GH_UnitNumber ) ( object ) data ) . Value ;
51
- outputsSerialized = JsonConvert . SerializeObject ( quantity , converter ) ;
52
- } else {
53
- object obj = ( ( T ) ( object ) data ) . ScriptVariable ( ) ;
54
- try {
55
- outputsSerialized = JsonConvert . SerializeObject ( obj ) ;
56
- } catch ( Exception ) {
57
- outputsSerialized = data . GetHashCode ( ) . ToString ( ) ;
58
- }
59
- }
60
-
61
- if ( _existingOutputsSerialized [ outputIndex ] . Count == index ) {
62
- _existingOutputsSerialized [ outputIndex ] . Add ( outputsSerialized ) ;
63
- _outputsAreExpired [ outputIndex ] . Add ( true ) ;
64
- return ;
65
- }
66
-
67
- if ( _existingOutputsSerialized [ outputIndex ] [ index ] != outputsSerialized ) {
68
- _existingOutputsSerialized [ outputIndex ] [ index ] = outputsSerialized ;
69
- _outputsAreExpired [ outputIndex ] [ index ] = true ;
70
- return ;
71
- }
72
- _outputsAreExpired [ outputIndex ] [ index ] = false ;
73
- }
74
-
75
- public override bool Read ( GH_IO . Serialization . GH_IReader reader ) {
30
+ public override bool Read ( GH_IReader reader ) {
76
31
Helpers . DeSerialization . ReadDropDownComponents ( ref reader , ref _dropDownItems , ref _selectedItems , ref _spacerDescriptions ) ;
77
32
78
33
_isInitialised = true ;
@@ -86,31 +41,19 @@ public override bool Read(GH_IO.Serialization.GH_IReader reader) {
86
41
public virtual void VariableParameterMaintenance ( ) {
87
42
}
88
43
89
- public override bool Write ( GH_IO . Serialization . GH_IWriter writer ) {
44
+ public override bool Write ( GH_IWriter writer ) {
90
45
Helpers . DeSerialization . WriteDropDownComponents ( ref writer , _dropDownItems , _selectedItems , _spacerDescriptions ) ;
91
46
return base . Write ( writer ) ;
92
47
}
93
48
94
- protected internal abstract void InitialiseDropdowns ( ) ;
95
-
96
- protected override void ExpireDownStreamObjects ( ) {
97
- if ( _alwaysExpireDownStream ) {
98
- base . ExpireDownStreamObjects ( ) ;
99
- return ;
100
- }
101
-
102
- SetExpireDownStream ( ) ;
103
- if ( _outputIsExpired . Count > 0 ) {
104
- for ( int outputIndex = 0 ; outputIndex < Params . Output . Count ; outputIndex ++ ) {
105
- if ( _outputIsExpired [ outputIndex ] ) {
106
- IGH_Param item = Params . Output [ outputIndex ] ;
107
- item . ExpireSolution ( recompute : false ) ;
108
- }
109
- }
110
- } else
111
- base . ExpireDownStreamObjects ( ) ;
49
+ protected sealed override void SolveInstance ( IGH_DataAccess da ) {
50
+ SolveInternal ( da ) ;
112
51
}
113
52
53
+ protected abstract void SolveInternal ( IGH_DataAccess da ) ;
54
+
55
+ protected internal abstract void InitialiseDropdowns ( ) ;
56
+
114
57
protected virtual void UpdateUI ( ) {
115
58
( this as IGH_VariableParameterComponent ) . VariableParameterMaintenance ( ) ;
116
59
ExpireSolution ( true ) ;
@@ -122,17 +65,5 @@ protected virtual void UpdateUIFromSelectedItems() {
122
65
CreateAttributes ( ) ;
123
66
UpdateUI ( ) ;
124
67
}
125
-
126
- private void SetExpireDownStream ( ) {
127
- if ( _outputsAreExpired != null && _outputsAreExpired . Count > 0 ) {
128
- _outputIsExpired = new Dictionary < int , bool > ( ) ;
129
- for ( int outputIndex = 0 ; outputIndex < Params . Output . Count ; outputIndex ++ ) {
130
- if ( _outputsAreExpired . ContainsKey ( outputIndex ) )
131
- _outputIsExpired . Add ( outputIndex , _outputsAreExpired [ outputIndex ] . Any ( c => c == true ) ) ;
132
- else
133
- _outputIsExpired . Add ( outputIndex , true ) ;
134
- }
135
- }
136
- }
137
68
}
138
69
}
0 commit comments