Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to preview or hide preview of all geometry in a group and Fix top menu pixel difference #13702

Merged
merged 7 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/DynamoCore/Graph/Annotations/AnnotationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,26 @@ internal set
/// </summary>
public bool HasNestedGroups => nodes.OfType<AnnotationModel>().Any();

private bool isVisible = true;
/// <summary>
/// Preview visibility of the nodes in a group
/// </summary>
[JsonIgnore]
public bool IsVisible
{
get
{
return isVisible;
}
internal set
{
if (value != isVisible)
{
isVisible = value;
RaisePropertyChanged(nameof(IsVisible));
}
}
}
#endregion

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion src/DynamoCoreWpf/Controls/ShortcutToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ public ShortcutToolbar(DynamoViewModel dynamoViewModel)
var shortcutToolbar = new ShortcutToolbarViewModel(dynamoViewModel);
DataContext = shortcutToolbar;
authManager = dynamoViewModel.Model.AuthenticationManager;
if (authManager.IsLoggedIn()) {
if (authManager.IsLoggedIn())
{
authManager.LoginStateChanged += SignOutHandler;
}
else {
logoutOption.Visibility = Visibility.Collapsed;
}
}

private void SignOutHandler(LoginState status)
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/Controls/StartPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</Grid.RowDefinitions>

<!-- Begin top part (i.e. the "Start" tab) -->
<Border HorizontalAlignment="Stretch" Background="#3C3C3C" Margin="220,-40,0,49"></Border>
<Border HorizontalAlignment="Stretch" Background="#3C3C3C" Margin="220,-40,0,50"></Border>

<!-- Begin Dynamo logo -->
<Image Name="StartPageLogo"
Expand Down
13 changes: 11 additions & 2 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ To avoid unintended behavior, uninstall the conflicting loaded package(s), resta
<value>Is Output</value>
</data>
<data name="NodeContextMenuPreview" xml:space="preserve">
<value>Preview</value>
<value>Preview Geometry</value>
<comment>Context menu item - preview geometry</comment>
</data>
<data name="NodeContextMenuRenameNode" xml:space="preserve">
Expand Down Expand Up @@ -3482,4 +3482,7 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="SplashScreenSigningIn" xml:space="preserve">
<value>Signing In</value>
</data>
<data name="GroupContextMenuPreview" xml:space="preserve">
<value>Preview Geometry</value>
</data>
</root>
5 changes: 4 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@
<comment>Lacing strategy: use the shortest list</comment>
</data>
<data name="NodeContextMenuPreview" xml:space="preserve">
<value>Preview</value>
<value>Preview Geometry</value>
<comment>Context menu item - preview geometry</comment>
</data>
<data name="NodeContextMenuRenameNode" xml:space="preserve">
Expand Down Expand Up @@ -3469,4 +3469,7 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="SplashScreenSigningIn" xml:space="preserve">
<value>Signing In</value>
</data>
<data name="GroupContextMenuPreview" xml:space="preserve">
<value>Preview Geometry</value>
</data>
</root>
48 changes: 41 additions & 7 deletions src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,26 @@ private bool CanChangeFontSize(object obj)
{
return true;
}

private DelegateCommand toggleIsVisibleGroupCommand;

/// <summary>
/// Command to toggle this group's node preview visibility.
/// belongs to.
/// </summary>
[JsonIgnore]
public DelegateCommand ToggleIsVisibleGroupCommand
{
get
{
if (toggleIsVisibleGroupCommand == null)
toggleIsVisibleGroupCommand =
new DelegateCommand(ToggleIsVisibleGroup, CanToggleIsVisibleGroup);
new DelegateCommand(RemoveGroupFromGroup, CanUngroupGroup);

return toggleIsVisibleGroupCommand;
}
}
#endregion

public AnnotationViewModel(WorkspaceViewModel workspaceViewModel, AnnotationModel model)
Expand Down Expand Up @@ -795,13 +815,6 @@ internal IEnumerable<PortModel> GetGroupOutPorts(IEnumerable<NodeModel> ownerNod
);
}

private double GetPortVerticalOffset(PortModel portModel, int proxyPortIndex)
{
// calculate the vertical offset based on the port index.
double portHeight = portModel.Height;
return verticalOffset + (proxyPortIndex * portHeight) + portVerticalMidPoint;
}

Comment on lines -798 to -804
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed because unused method

private Point2D CalculatePortPosition(PortModel portModel, double verticalPosition)
{
double groupHeaderHeight = Height - ModelAreaRect.Height;
Expand Down Expand Up @@ -1348,6 +1361,27 @@ private bool BelongsToGroup()
return WorkspaceViewModel.Model.Annotations.ContainsModel(this.annotationModel);
}

internal void ToggleIsVisibleGroup(object parameters)
{
DynamoSelection.Instance.ClearSelection();
Copy link
Contributor

Choose a reason for hiding this comment

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

why is it necessary to clear the selection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to clear any other groups/notes/nodes that may be present in the selection, as we only want to target the current group and its contents.

var nodesInGroup = this.AnnotationModel.Nodes.Select(n => n.GUID).ToList();

var command = new DynamoModel.UpdateModelValueCommand(Guid.Empty,
nodesInGroup, "IsVisible", (!this.AnnotationModel.IsVisible).ToString());

this.AnnotationModel.IsVisible = !this.AnnotationModel.IsVisible;
WorkspaceViewModel.DynamoViewModel.Model.ExecuteCommand(command);
WorkspaceViewModel.DynamoViewModel.RaiseCanExecuteUndoRedo();
WorkspaceViewModel.HasUnsavedChanges = true;

Analytics.TrackEvent(Actions.Preview, Categories.GroupOperations, this.AnnotationModel.IsVisible.ToString());
}

internal bool CanToggleIsVisibleGroup(object parameters)
{
return true;
}

public override void Dispose()
{
annotationModel.PropertyChanged -= model_PropertyChanged;
Expand Down
2 changes: 0 additions & 2 deletions src/DynamoCoreWpf/ViewModels/Core/ShortcutToolbarViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Dynamo.Core;
using Dynamo.UI.Commands;
using Dynamo.UI.Controls;
using Dynamo.ViewModels;
using System.Windows;

namespace Dynamo.Wpf.ViewModels.Core
{
Expand Down
5 changes: 5 additions & 0 deletions src/DynamoCoreWpf/Views/Core/AnnotationView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@
<MenuItem Name="UngroupAnnotation"
Click="OnUngroupAnnotation"
Header="{x:Static p:Resources.GroupContextMenuUngroup}" />
<MenuItem Name="PreviewAnnotation"
Command="{Binding Path=ToggleIsVisibleGroupCommand}"
Header="{x:Static p:Resources.GroupContextMenuPreview}"
IsCheckable="true"
IsChecked="{Binding Path=AnnotationModel.IsVisible, Mode=OneWay}"/>
<MenuItem Name="unGroup_cm"
Command="{Binding Path=RemoveGroupFromGroupCommand}"
Header="{x:Static p:Resources.ContextUnGroupFromSelection}" />
Expand Down
5 changes: 0 additions & 5 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,6 @@
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>

<Grid Name="loginGrid"
Grid.Row="0"
Grid.Column="1">
</Grid>

<Border Name="shortcutBarBorder"
BorderThickness="0"
HorizontalAlignment="Stretch"
Expand Down
47 changes: 44 additions & 3 deletions test/DynamoCoreWpfTests/AnnotationViewModelTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
Expand Down Expand Up @@ -154,13 +154,13 @@ public void CanUngroupNodeFromAGroup()
var secondNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+"));
ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(secondNode, false);

//verify the node was created
//verify if the second node was created
Assert.AreEqual(2, ViewModel.Model.CurrentWorkspace.Nodes.Count());

//Select the node
DynamoSelection.Instance.Selection.Add(addNode);

//Check whether group can be created
//Check whether group can be ungrouped
Assert.AreEqual(true, ViewModel.CanUngroupModel(null));
}

Expand Down Expand Up @@ -1377,6 +1377,47 @@ public void ShowGroupContentsTest()
Assert.IsTrue(connectorViewModel.IsCollapsed);
}

[Test]
public void CanToggleVisibilityOfAllNodesInAGroup()
{
// Arrange
var parentGroupName = "GroupWithGroupedGroup";
var nestedGroupName = "GroupInsideOtherGroup";

OpenModel(@"core\annotationViewModelTests\groupsTestFile.dyn");

var parentGroupNameViewModel = ViewModel.CurrentSpaceViewModel.Annotations.FirstOrDefault(x => x.AnnotationText == parentGroupName);
var nestedGroupNameViewModel = ViewModel.CurrentSpaceViewModel.Annotations.FirstOrDefault(x => x.AnnotationText == nestedGroupName);

//No. of nodes in parent group with preview enabled before the toggle.
var parentGroupContentBefore = parentGroupNameViewModel.Nodes.OfType<NodeModel>().Where(x => x.IsVisible == true).ToList();
var nestedGroupContentBefore = nestedGroupNameViewModel.Nodes.OfType<NodeModel>().Where(x => x.IsVisible == true).ToList();

Assert.AreEqual(2, parentGroupContentBefore.Count);
Assert.AreEqual(2, nestedGroupContentBefore.Count);

//Assert HasUnsavedChanges is false
Assert.AreEqual(false, ViewModel.CurrentSpaceViewModel.HasUnsavedChanges);

// Act
parentGroupNameViewModel.ToggleIsVisibleGroupCommand.Execute(null);

// Assert
// Only the nodes in parent group are affected
var parentGroupContentAfter = parentGroupNameViewModel.Nodes.OfType<NodeModel>().Where(x => x.IsVisible == true).ToList();
var nestedGroupContentAfter = nestedGroupNameViewModel.Nodes.OfType<NodeModel>().Where(x => x.IsVisible == true).ToList();
Assert.AreEqual(0, parentGroupContentAfter.Count);
Assert.AreEqual(2, nestedGroupContentAfter.Count);

// Now both the groups are affected
nestedGroupNameViewModel.ToggleIsVisibleGroupCommand.Execute(null);
nestedGroupContentAfter = nestedGroupNameViewModel.Nodes.OfType<NodeModel>().Where(x => x.IsVisible == true).ToList();
Assert.AreEqual(0, nestedGroupContentAfter.Count);

//Assert HasUnsavedChanges is false
Assert.AreEqual(true, ViewModel.CurrentSpaceViewModel.HasUnsavedChanges);
}

#endregion
}
}