2
2
using System . Collections . Generic ;
3
3
using System . Diagnostics ;
4
4
using System . Linq ;
5
+ using Dynamo . Engine ;
6
+ using Dynamo . Graph . Nodes ;
5
7
using Dynamo . Properties ;
6
8
using Dynamo . Search . SearchElements ;
7
9
using Dynamo . Wpf . ViewModels ;
@@ -39,7 +41,7 @@ private void InitializeDefaultAutoCompleteCandidates()
39
41
var candidates = new List < NodeSearchElementViewModel > ( ) ;
40
42
// TODO: These are basic input types in Dynamo
41
43
// This should be only served as a temporary default case.
42
- var queries = new List < string > ( ) { "String" , "Number Slider" , "Integer Slider" , "Number" , "Boolean" } ;
44
+ var queries = new List < string > ( ) { "String" , "Number Slider" , "Integer Slider" , "Number" , "Boolean" , "Watch" , "Watch 3D" , "Python Script" } ;
43
45
foreach ( var query in queries )
44
46
{
45
47
var foundNode = Search ( query ) . FirstOrDefault ( ) ;
@@ -57,27 +59,34 @@ internal void PopulateAutoCompleteCandidates()
57
59
58
60
searchElementsCache = GetMatchingSearchElements ( ) . ToList ( ) ;
59
61
60
- // If node match searchElements found, use default suggestions
62
+ // If node match searchElements found, use default suggestions.
63
+ // These default suggestions will be populated based on the port type.
61
64
if ( ! searchElementsCache . Any ( ) )
62
65
{
63
- searchElementsCache = DefaultResults . Select ( e => e . Model ) . ToList ( ) ;
64
- switch ( PortViewModel . PortModel . GetInputPortType ( ) )
66
+ if ( PortViewModel . PortModel . PortType == PortType . Input )
65
67
{
66
- case "int" :
67
- FilteredResults = DefaultResults . Where ( e => e . Name == "Number Slider" || e . Name == "Integer Slider" ) . ToList ( ) ;
68
- break ;
69
- case "double" :
70
- FilteredResults = DefaultResults . Where ( e => e . Name == "Number Slider" || e . Name == "Integer Slider" ) . ToList ( ) ;
71
- break ;
72
- case "string" :
73
- FilteredResults = DefaultResults . Where ( e => e . Name == "String" ) . ToList ( ) ;
74
- break ;
75
- case "bool" :
76
- FilteredResults = DefaultResults . Where ( e => e . Name == "Boolean" ) . ToList ( ) ;
77
- break ;
78
- default :
79
- FilteredResults = DefaultResults ;
80
- break ;
68
+ switch ( PortViewModel . PortModel . GetInputPortType ( ) )
69
+ {
70
+ case "int" :
71
+ FilteredResults = DefaultResults . Where ( e => e . Name == "Number Slider" || e . Name == "Integer Slider" ) . ToList ( ) ;
72
+ break ;
73
+ case "double" :
74
+ FilteredResults = DefaultResults . Where ( e => e . Name == "Number Slider" || e . Name == "Integer Slider" ) . ToList ( ) ;
75
+ break ;
76
+ case "string" :
77
+ FilteredResults = DefaultResults . Where ( e => e . Name == "String" ) . ToList ( ) ;
78
+ break ;
79
+ case "bool" :
80
+ FilteredResults = DefaultResults . Where ( e => e . Name == "Boolean" ) . ToList ( ) ;
81
+ break ;
82
+ default :
83
+ FilteredResults = DefaultResults . Where ( e => e . Name == "String" || e . Name == "Number Slider" || e . Name == "Integer Slider" || e . Name == "Number" || e . Name == "Boolean" ) ;
84
+ break ;
85
+ }
86
+ }
87
+ else
88
+ {
89
+ FilteredResults = DefaultResults . Where ( e => e . Name == "Watch" || e . Name == "Watch 3D" || e . Name == "Python Script" ) . ToList ( ) ;
81
90
}
82
91
}
83
92
else
@@ -126,55 +135,95 @@ internal void SearchAutoCompleteCandidates(string input)
126
135
internal IEnumerable < NodeSearchElement > GetMatchingSearchElements ( )
127
136
{
128
137
var elements = new List < NodeSearchElement > ( ) ;
129
- var inputPortType = PortViewModel . PortModel . GetInputPortType ( ) ;
138
+
139
+ var portType = String . Empty ;
140
+
141
+ if ( PortViewModel . PortModel . PortType == PortType . Input )
142
+ {
143
+ portType = PortViewModel . PortModel . GetInputPortType ( ) ;
144
+ }
145
+ else if ( PortViewModel . PortModel . PortType == PortType . Output )
146
+ {
147
+ portType = PortViewModel . PortModel . GetOutPortType ( ) ;
148
+ }
130
149
131
150
//List of input types that are skipped temporarily, and will display list of default suggestions instead.
132
151
var skippedInputTypes = new List < string > ( ) { "var" , "object" , "string" , "bool" , "int" , "double" } ;
133
152
134
- if ( inputPortType == null )
153
+ if ( portType == null )
135
154
{
136
155
return elements ;
137
156
}
138
157
139
158
var core = dynamoViewModel . Model . LibraryServices . LibraryManagementCore ;
140
159
141
160
//if inputPortType is an array, use just the typename
142
- var parseResult = ParserUtils . ParseWithCore ( $ "dummyName:{ inputPortType } ;", core ) ;
161
+ var parseResult = ParserUtils . ParseWithCore ( $ "dummyName:{ portType } ;", core ) ;
143
162
var ast = parseResult . CodeBlockNode . Children ( ) . FirstOrDefault ( ) as IdentifierNode ;
144
163
//if parsing the type failed, revert to original string.
145
- inputPortType = ast != null ? ast . datatype . Name : inputPortType ;
164
+ portType = ast != null ? ast . datatype . Name : portType ;
146
165
147
166
//check if the input port return type is in the skipped input types list
148
- if ( skippedInputTypes . Any ( s => s == inputPortType ) )
167
+ if ( skippedInputTypes . Any ( s => s == portType ) )
149
168
{
150
169
return elements ;
151
170
}
152
171
153
172
//gather all ztsearchelements that are visible in search and filter using inputPortType and zt return type name.
154
173
var ztSearchElements = Model . SearchEntries . OfType < ZeroTouchSearchElement > ( ) . Where ( x => x . IsVisibleInSearch ) ;
155
- foreach ( var ztSearchElement in ztSearchElements )
174
+
175
+ if ( PortViewModel . PortModel . PortType == PortType . Input )
156
176
{
157
- //for now, remove rank from descriptors
158
- var returnTypeName = ztSearchElement . Descriptor . ReturnType . Name ;
177
+ foreach ( var ztSearchElement in ztSearchElements )
178
+ {
179
+ //for now, remove rank from descriptors
180
+ var returnTypeName = ztSearchElement . Descriptor . ReturnType . Name ;
159
181
160
- var descriptor = ztSearchElement . Descriptor ;
161
- if ( ( returnTypeName == inputPortType )
162
- || DerivesFrom ( inputPortType , returnTypeName , core ) )
182
+ var descriptor = ztSearchElement . Descriptor ;
183
+ if ( ( returnTypeName == portType ) || DerivesFrom ( portType , returnTypeName , core ) )
184
+ {
185
+ elements . Add ( ztSearchElement ) ;
186
+ }
187
+ }
188
+
189
+ // NodeModel nodes, match any output return type to inputport type name
190
+ foreach ( var element in Model . SearchEntries . OfType < NodeModelSearchElement > ( ) )
163
191
{
164
- elements . Add ( ztSearchElement ) ;
192
+ if ( element . OutputParameters . Any ( op => op == portType ) )
193
+ {
194
+ elements . Add ( element ) ;
195
+ }
165
196
}
166
197
}
167
-
168
- // NodeModel nodes, match any output return type to inputport type name
169
- foreach ( var element in Model . SearchEntries . OfType < NodeModelSearchElement > ( ) )
198
+ else if ( PortViewModel . PortModel . PortType == PortType . Output )
170
199
{
171
- if ( element . OutputParameters . Any ( op => op == inputPortType ) )
200
+ foreach ( var ztSearchElement in ztSearchElements )
172
201
{
173
- elements . Add ( element ) ;
202
+ foreach ( var inputParameter in ztSearchElement . Descriptor . Parameters . Select ( ( value , index ) => new { value , index } ) )
203
+ {
204
+ if ( inputParameter . value . Type . ToString ( ) == portType || DerivesFrom ( inputParameter . value . Type . ToString ( ) , portType , core ) )
205
+ {
206
+ ztSearchElement . AutoCompletionNodeElementInfo . PortToConnect = ztSearchElement . Descriptor . Type == FunctionType . InstanceMethod ? inputParameter . index + 1 : inputParameter . index ;
207
+ elements . Add ( ztSearchElement ) ;
208
+ break ;
209
+ }
210
+ }
211
+ }
212
+
213
+ // NodeModel nodes, match any output return type to inputport type name
214
+ foreach ( var element in Model . SearchEntries . OfType < NodeModelSearchElement > ( ) )
215
+ {
216
+ foreach ( var inputParameter in element . InputParameters )
217
+ {
218
+ if ( inputParameter . Item2 == portType )
219
+ {
220
+ elements . Add ( element ) ;
221
+ }
222
+ }
174
223
}
175
224
}
176
225
177
- var comparer = new NodeSearchElementComparer ( inputPortType , core ) ;
226
+ var comparer = new NodeSearchElementComparer ( portType , core ) ;
178
227
179
228
//first sort by type distance to input port type
180
229
elements . Sort ( comparer ) ;
0 commit comments