Skip to content

Commit

Permalink
fix init var not added issue
Browse files Browse the repository at this point in the history
  • Loading branch information
randolfly committed Jan 23, 2025
1 parent ffd94ff commit 205cca4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 4 additions & 2 deletions doc/roadmap/Feature Update.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ when load twincat project variables, sometimes it's nice to ignore some variable

- `axis.PlcToNc.xxx`

When multiple axis are used, these unnecessary variables will significantly slower the program, hence it's good to provide a filter to remove such variables. Moreover, it's better to provide a custom filter (of cource some default rules are provides)?
When multiple axis are used, these unnecessary variables will significantly slower the program, hence it's good to provide a filter to remove such variables. Moreover, it's better to provide a custom filter (of course some default rules are provides)?



## Remove Multiple Variables
## [Done]Remove Multiple Variables

when a variable is passed into a function block, whether it's by `VAR_INPUT` or `VAR_IN_OUT`, the twincat ads api will return handles for the variable out and in the function block, although they are basically the identical one.

Expand All @@ -21,3 +21,5 @@ To identify the duplicated variables, notice that they have same last name:
- `power_motor.Axis.NcToPlc.ActPos`=>`Axis.NcToPlc.ActPos`

the idea is to retain the variable with shortest name in the group of variables.

> Update: Use property `IsReference` can check if one variable is reference, which can be used to determine duplicated symbols
24 changes: 14 additions & 10 deletions src/TwincatToolbox/ViewModels/DataLogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,22 @@ public List<SymbolInfo> SearchResultSymbols
{
get
{
_searchResultSymbols = SearchSymbols(AvailableSymbols);

SearchResultSelectedSymbols.CollectionChanged -= OnSearchResultSelectedSymbolsChanged;
SearchResultSelectedSymbols.Clear();
var initSearchResultSelectedSymbols = _searchResultSymbols
.Intersect(LogSymbols, SymbolInfoComparer.Instance);
foreach (var symbol in initSearchResultSelectedSymbols) SearchResultSelectedSymbols.Add(symbol);
SearchResultSelectedSymbols.CollectionChanged += OnSearchResultSelectedSymbolsChanged;

UpdateSearchResultSymbols();
return _searchResultSymbols;
}
}

private void UpdateSearchResultSymbols() {
_searchResultSymbols = SearchSymbols(AvailableSymbols);

SearchResultSelectedSymbols.CollectionChanged -= OnSearchResultSelectedSymbolsChanged;
SearchResultSelectedSymbols.Clear();
var initSearchResultSelectedSymbols = _searchResultSymbols
.Intersect(LogSymbols, SymbolInfoComparer.Instance);
foreach (var symbol in initSearchResultSelectedSymbols) SearchResultSelectedSymbols.Add(symbol);
SearchResultSelectedSymbols.CollectionChanged += OnSearchResultSelectedSymbolsChanged;
}

[ObservableProperty] private ObservableCollection<SymbolInfo> _searchResultSelectedSymbols = new();
public ObservableCollection<SymbolInfo> LogSymbols { get; set; } = [];
public ObservableCollection<SymbolInfo> PlotSymbols { get; } = [];
Expand Down Expand Up @@ -105,6 +108,7 @@ private void OnGetAvailableSymbols()
if (_isFirstGetAvailableSymbols)
{
InitLogAndPlotSymbolsWithConfig(_logConfig);
UpdateSearchResultSymbols();
_isFirstGetAvailableSymbols = false;
}
}
Expand Down Expand Up @@ -133,7 +137,7 @@ public List<SymbolInfo> SearchSymbols(IList<SymbolInfo> sourceList)
if (string.IsNullOrEmpty((SearchText))) return sourceList.ToList();
var searchResults = sourceList
.OrderByDescending(s=>GetSimilarityScore(SearchText, s))
.Take(20).ToList();
.ToList();
// Debug.WriteLine("Search results: {0}", searchResults.Count());

return searchResults;
Expand Down

0 comments on commit 205cca4

Please sign in to comment.