Skip to content

Add dropdown-based node and edge editors#4

Merged
wnj00524 merged 1 commit into
masterfrom
codex/wpf-network-simulator
Apr 7, 2026
Merged

Add dropdown-based node and edge editors#4
wnj00524 merged 1 commit into
masterfrom
codex/wpf-network-simulator

Conversation

@wnj00524
Copy link
Copy Markdown
Owner

@wnj00524 wnj00524 commented Apr 7, 2026

Move node role editing into a dedicated window with dropdown selection for nodes, traffic entries, traffic types, and roles, and constrain edge endpoints to existing nodes.

Move node role editing into a dedicated window with dropdown selection for nodes, traffic entries, traffic types, and roles, and constrain edge endpoints to existing nodes.
@wnj00524 wnj00524 self-assigned this Apr 7, 2026
@wnj00524 wnj00524 merged commit 956d4da into master Apr 7, 2026
@wnj00524 wnj00524 deleted the codex/wpf-network-simulator branch April 7, 2026 15:31
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a dedicated node editor window and a Node Roles tab to manage node properties and traffic profiles. Key changes include the addition of the NodeEditorWindow, UI updates for node selection, and view model enhancements for role-based configuration. Feedback identifies a redundant property assignment when adding nodes, potential logic issues leading to duplicate traffic profiles, code duplication in error handling methods, and opportunities to optimize property setters in the view models.

Comment on lines 325 to +326
SelectedNode = node;
SelectedNodeTrafficProfile = initialProfile;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The assignment to SelectedNodeTrafficProfile on line 326 is redundant. Setting SelectedNode = node on the previous line already triggers the SelectedNode property setter (see line 144), which automatically selects the first traffic profile of the node. Since initialProfile was just added as the first profile, it will be selected automatically.

        SelectedNode = node;

Comment on lines +363 to +367
var trafficName = TrafficDefinitions
.Select(definition => definition.Name)
.Where(name => !string.IsNullOrWhiteSpace(name))
.FirstOrDefault(name => SelectedNode.TrafficProfiles.All(profile => !Comparer.Equals(profile.TrafficType, name)))
?? primaryTrafficDefinition.Name;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic can lead to duplicate traffic profiles for the same traffic type on a single node. If all defined traffic types are already present in the node's profiles, FirstOrDefault returns null and trafficName defaults to the primary traffic definition's name. If that primary definition is also already present, a duplicate profile will be added. Consider preventing the addition or generating a new unique traffic type if no unused types are available.

Comment on lines +42 to +57
private void ExecuteWithErrorHandling(Action action)
{
try
{
action();
}
catch (Exception ex)
{
MessageBox.Show(
this,
ex.Message,
"MedW Network Simulator",
MessageBoxButton.OK,
MessageBoxImage.Error);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ExecuteWithErrorHandling method is duplicated from MainWindow.xaml.cs. To improve maintainability and adhere to the DRY principle, consider moving this logic to a shared base class or a helper service.

Comment on lines +152 to +185
set
{
ArgumentNullException.ThrowIfNull(value);

switch (value)
{
case ProducerRole:
ApplyRoleSelection(isProducer: true, isConsumer: false, canTransship: false);
break;
case ConsumerRole:
ApplyRoleSelection(isProducer: false, isConsumer: true, canTransship: false);
break;
case TransshipRole:
ApplyRoleSelection(isProducer: false, isConsumer: false, canTransship: true);
break;
case ProducerConsumerRole:
ApplyRoleSelection(isProducer: true, isConsumer: true, canTransship: false);
break;
case ProducerTransshipRole:
ApplyRoleSelection(isProducer: true, isConsumer: false, canTransship: true);
break;
case ConsumerTransshipRole:
ApplyRoleSelection(isProducer: false, isConsumer: true, canTransship: true);
break;
case ProducerConsumerTransshipRole:
ApplyRoleSelection(isProducer: true, isConsumer: true, canTransship: true);
break;
default:
ApplyRoleSelection(isProducer: false, isConsumer: false, canTransship: false);
break;
}

OnPropertyChanged(nameof(SelectedRoleName));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The SelectedRoleName setter should check if the value has actually changed before proceeding to avoid unnecessary processing. Additionally, the explicit call to OnPropertyChanged(nameof(SelectedRoleName)) at the end is redundant because ApplyRoleSelection modifies properties whose setters already trigger a notification for SelectedRoleName.

        set
        {
            ArgumentNullException.ThrowIfNull(value);
            if (string.Equals(value, SelectedRoleName, StringComparison.Ordinal))
            {
                return;
            }

            switch (value)
            {
                case ProducerRole:
                    ApplyRoleSelection(isProducer: true, isConsumer: false, canTransship: false);
                    break;
                case ConsumerRole:
                    ApplyRoleSelection(isProducer: false, isConsumer: true, canTransship: false);
                    break;
                case TransshipRole:
                    ApplyRoleSelection(isProducer: false, isConsumer: false, canTransship: true);
                    break;
                case ProducerConsumerRole:
                    ApplyRoleSelection(isProducer: true, isConsumer: true, canTransship: false);
                    break;
                case ProducerTransshipRole:
                    ApplyRoleSelection(isProducer: true, isConsumer: false, canTransship: true);
                    break;
                case ConsumerTransshipRole:
                    ApplyRoleSelection(isProducer: false, isConsumer: true, canTransship: true);
                    break;
                case ProducerConsumerTransshipRole:
                    ApplyRoleSelection(isProducer: true, isConsumer: true, canTransship: true);
                    break;
                default:
                    ApplyRoleSelection(isProducer: false, isConsumer: false, canTransship: false);
                    break;
            }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant