Skip to content

New boolean toggle component #687

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

Merged
merged 24 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
be22b01
BooleanToggles automatically sets to false whenever a new file is opened
albinber Sep 21, 2023
e07df51
Now only targets toggles connected to pull, push and execute components
albinber Sep 25, 2023
c9e8063
New boolean toggle component
albinber Oct 2, 2023
84c4ff1
Update Grasshopper_UI/Components/UI/FalseStartToggle.cs
albinber Oct 2, 2023
4629902
Update Grasshopper_UI/Components/UI/FalseStartToggle.cs
albinber Oct 2, 2023
2de995f
Update Grasshopper_UI/Components/UI/FalseStartToggle.cs
albinber Oct 2, 2023
919d648
Update Grasshopper_UI/Components/UI/FalseStartToggle.cs
albinber Oct 2, 2023
fac6fc2
Update Grasshopper_UI/Components/UI/FalseStartToggle.cs
albinber Oct 2, 2023
9ce15d2
Update Grasshopper_UI/Global/GlobalSearch.cs
albinber Oct 2, 2023
cef81c1
Update Grasshopper_UI/Global/GlobalSearch.cs
albinber Oct 2, 2023
0a139f1
Update Grasshopper_UI/Components/UI/FalseStartToggle.cs
albinber Oct 2, 2023
f3a5e13
Update Grasshopper_UI/Components/UI/FalseStartToggle.cs
albinber Oct 2, 2023
1a45030
Making requested changes
albinber Oct 2, 2023
c1341e1
Merge branch 'BHoM_UI-#684-NewToggleForBHoM' of https://github.com/BH…
albinber Oct 2, 2023
94f6f25
Update Grasshopper_UI/Components/UI/FalseStartToggle.cs
Oct 2, 2023
efe30f2
Update Grasshopper_UI/Components/UI/FalseStartToggle.cs
Oct 2, 2023
b44a549
Update Grasshopper_UI/Components/UI/FalseStartToggle.cs
Oct 2, 2023
49c60bd
Update Grasshopper_UI/Components/UI/FalseStartToggle.cs
Oct 2, 2023
e72a746
Update Grasshopper_UI/Components/UI/FalseStartToggle.cs
Oct 2, 2023
053e9c9
Updates following testing
Oct 2, 2023
4af76e8
Expire solution
Oct 3, 2023
43cbb94
Tidy up
Oct 3, 2023
a97ccd1
Tidy up attributes
Oct 3, 2023
17a8c91
Fix project compliance
Oct 3, 2023
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
4 changes: 2 additions & 2 deletions Grasshopper_Engine/Grasshopper_Engine.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -175,4 +175,4 @@ Copy /Y "$(TargetDir)$(TargetName).dll" "C:\ProgramData\BHoM\Assemblies\$(Target
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
138 changes: 138 additions & 0 deletions Grasshopper_UI/Components/UI/FalseStartToggle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using System;
using System.Drawing;
using Grasshopper.Kernel;
using Grasshopper.GUI;
using BH.oM.Base;
using BH.UI.Grasshopper.Templates;
using BH.UI.Base;
using BH.UI.Base.Components;
using GH = Grasshopper;
using System.Windows.Forms;
using GH_IO.Serialization;
using BH.Engine.Reflection;
using BH.oM.UI;
using Grasshopper.GUI.RemotePanel;
using Grasshopper.Kernel.Attributes;
using Grasshopper.GUI.Canvas;
using Rhino.Runtime;
using BH.Engine.Base;

namespace BH.UI.Grasshopper.Components
{
public class FalseStartToggleComponent : CallerComponent
{
/*******************************************/
/**** Properties ****/
/*******************************************/

public override Caller Caller { get; } = new FalseStartToggleCaller();

/*******************************************/

public FalseStartToggleComponent()
{

}

public override bool Read(GH_IReader reader)
{
bool success = base.Read(reader);

Caller.SetItem(false);

// Adding a tag under the component
bool value = (bool)Caller.SelectedItem;

Message = value.ToString();

return success;
}

public override void CreateAttributes()
{
m_attributes = new FalseStartToggleAttributes(this);
}

public void UpdateComponent()
{
(Caller as FalseStartToggleCaller).SetItem(!(Caller as FalseStartToggleCaller).Value);

}

protected override void OnCallerModified(object sender, CallerUpdate update)
{
// Adding a tag under the component
bool value = (bool)Caller.SelectedItem;

Message = value.ToString();

base.OnCallerModified(sender, update);
}
}

public class FalseStartToggleAttributes : GH_ComponentAttributes
{
public FalseStartToggleAttributes(IGH_Component component) : base(component)
{
}

public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvasMouseEvent e)
{
((FalseStartToggleComponent)Owner).UpdateComponent();

return GH_ObjectResponse.Handled;
}

protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
{
if (channel == GH_CanvasChannel.Objects)
{
var value = (bool)((FalseStartToggleComponent)Owner).Caller.SelectedItem;

// Cache the existing style.
GH_PaletteStyle dstyle = GH_Skin.palette_hidden_standard;

// Swap out palette for boolean toggle components based on the current output.

if (value)
GH_Skin.palette_hidden_standard = new GH_PaletteStyle(Color.Green);
else
{
GH_Skin.palette_hidden_standard = new GH_PaletteStyle(Color.Red);
}

base.Render(canvas, graphics, channel);

// Put the original style back.
GH_Skin.palette_hidden_standard = dstyle;
}
else
base.Render(canvas, graphics, channel);
}
}
}



9 changes: 9 additions & 0 deletions Grasshopper_UI/Global/GlobalSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
using Grasshopper.Kernel.Types;
using BH.oM.Grasshopper;
using System.IO;
using BH.UI.Base.Menus;
using System.Runtime.CompilerServices;
using Grasshopper.Kernel.Special;
using System.Net.Mail;
using Grasshopper.Documentation;
using BH.Engine.Grasshopper;
using BH.oM.Programming;
using System.Runtime.InteropServices;

namespace BH.UI.Grasshopper.Global
{
Expand Down Expand Up @@ -239,6 +247,7 @@ private static void GlobalSearch_ItemSelected(object sender, oM.UI.ComponentRequ
}

m_LastWire = null;

}

/*******************************************/
Expand Down
1 change: 1 addition & 0 deletions Grasshopper_UI/Grasshopper_UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
<Compile Include="Components\Engine\GetEvents.cs" />
<Compile Include="Components\Parameters\Param_BHoMAdapter.cs" />
<Compile Include="Components\Parameters\Param_Variable.cs" />
<Compile Include="Components\UI\FalseStartToggle.cs" />
<Compile Include="Components\UI\UnitTest.cs" />
<Compile Include="CustomAttributes\PrototypeAttribute.cs" />
<Compile Include="CustomAttributes\PrototypeValueListAttribute.cs" />
Expand Down