Skip to content

Commit 79d8e69

Browse files
author
Fraser Greenroyd
authored
New boolean toggle component (#687)
2 parents 27c819e + 17a8c91 commit 79d8e69

File tree

4 files changed

+190
-25
lines changed

4 files changed

+190
-25
lines changed

Grasshopper_Engine/Grasshopper_Engine.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
@@ -175,4 +175,4 @@ Copy /Y "$(TargetDir)$(TargetName).dll" "C:\ProgramData\BHoM\Assemblies\$(Target
175175
<Target Name="AfterBuild">
176176
</Target>
177177
-->
178-
</Project>
178+
</Project>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using System;
24+
using System.Drawing;
25+
using Grasshopper.Kernel;
26+
using Grasshopper.GUI;
27+
using BH.oM.Base;
28+
using BH.UI.Grasshopper.Templates;
29+
using BH.UI.Base;
30+
using BH.UI.Base.Components;
31+
using GH = Grasshopper;
32+
using System.Windows.Forms;
33+
using GH_IO.Serialization;
34+
using BH.Engine.Reflection;
35+
using BH.oM.UI;
36+
using Grasshopper.GUI.RemotePanel;
37+
using Grasshopper.Kernel.Attributes;
38+
using Grasshopper.GUI.Canvas;
39+
using Rhino.Runtime;
40+
using BH.Engine.Base;
41+
using BH.UI.Grasshopper.CustomAttributes;
42+
43+
namespace BH.UI.Grasshopper.Components
44+
{
45+
public class FalseStartToggleComponent : CallerComponent
46+
{
47+
/*******************************************/
48+
/**** Properties ****/
49+
/*******************************************/
50+
51+
public override Caller Caller { get; } = new FalseStartToggleCaller();
52+
53+
/*******************************************/
54+
55+
public FalseStartToggleComponent()
56+
{
57+
UpdateComponentDisplay();
58+
}
59+
60+
/*******************************************/
61+
62+
public override bool Read(GH_IReader reader)
63+
{
64+
bool success = base.Read(reader);
65+
66+
//Ensure the component is defaulting to false on load
67+
Caller.SetItem(false);
68+
UpdateComponentDisplay();
69+
70+
return success;
71+
}
72+
73+
/*******************************************/
74+
75+
public override void CreateAttributes()
76+
{
77+
m_attributes = new FalseStartToggleAttributes(this);
78+
}
79+
80+
/*******************************************/
81+
82+
public void UpdateComponent()
83+
{
84+
(Caller as FalseStartToggleCaller).SetItem(!(Caller as FalseStartToggleCaller).Value);
85+
UpdateComponentDisplay();
86+
}
87+
88+
/*******************************************/
89+
90+
protected override void OnCallerModified(object sender, CallerUpdate update)
91+
{
92+
UpdateComponentDisplay();
93+
94+
base.OnCallerModified(sender, update);
95+
}
96+
97+
/*******************************************/
98+
99+
private void UpdateComponentDisplay()
100+
{
101+
// Adding a tag under the component
102+
bool value = (bool)Caller.SelectedItem;
103+
Message = value.ToString();
104+
105+
SetIconOverride((Caller as FalseStartToggleCaller).Icon_24x24);
106+
ExpireSolution(true);
107+
}
108+
}
109+
}
110+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using System;
24+
using Grasshopper.Kernel;
25+
using Grasshopper.Kernel.Attributes;
26+
using BH.oM.Base;
27+
using BH.UI.Grasshopper.Templates;
28+
using BH.UI.Base;
29+
using BH.UI.Base.Components;
30+
using Grasshopper.GUI.Canvas;
31+
using System.Drawing;
32+
using Grasshopper.GUI;
33+
using System.Drawing.Drawing2D;
34+
using BH.UI.Grasshopper.Components;
35+
36+
namespace BH.UI.Grasshopper.CustomAttributes
37+
{
38+
public class FalseStartToggleAttributes : GH_ComponentAttributes
39+
{
40+
public FalseStartToggleAttributes(IGH_Component component) : base(component)
41+
{
42+
}
43+
44+
/*******************************************/
45+
46+
public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvasMouseEvent e)
47+
{
48+
((FalseStartToggleComponent)Owner).UpdateComponent();
49+
50+
return GH_ObjectResponse.Handled;
51+
}
52+
}
53+
}

Grasshopper_UI/Grasshopper_UI.csproj

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,37 @@
4040
</PropertyGroup>
4141
<ItemGroup>
4242
<Reference Include="BHoM">
43-
<HintPath>C:\ProgramData\BHoM\Assemblies\BHoM.dll</HintPath>
43+
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM.dll</HintPath>
4444
<Private>False</Private>
4545
<SpecificVersion>False</SpecificVersion>
4646
</Reference>
4747
<Reference Include="BHoM_Adapter">
4848
<SpecificVersion>False</SpecificVersion>
49-
<HintPath>C:\ProgramData\BHoM\Assemblies\BHoM_Adapter.dll</HintPath>
49+
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM_Adapter.dll</HintPath>
5050
<Private>False</Private>
5151
</Reference>
5252
<Reference Include="BHoM_Engine">
53-
<HintPath>C:\ProgramData\BHoM\Assemblies\BHoM_Engine.dll</HintPath>
53+
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM_Engine.dll</HintPath>
5454
<Private>False</Private>
5555
<SpecificVersion>False</SpecificVersion>
5656
</Reference>
5757
<Reference Include="BHoM_UI">
58-
<HintPath>C:\ProgramData\BHoM\Assemblies\BHoM_UI.dll</HintPath>
58+
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM_UI.dll</HintPath>
5959
<Private>False</Private>
6060
<SpecificVersion>False</SpecificVersion>
6161
</Reference>
6262
<Reference Include="Data_Engine">
6363
<SpecificVersion>False</SpecificVersion>
64-
<HintPath>C:\ProgramData\BHoM\Assemblies\Data_Engine.dll</HintPath>
64+
<HintPath>$(ProgramData)\BHoM\Assemblies\Data_Engine.dll</HintPath>
6565
<Private>False</Private>
6666
</Reference>
6767
<Reference Include="Data_oM">
6868
<SpecificVersion>False</SpecificVersion>
69-
<HintPath>C:\ProgramData\BHoM\Assemblies\Data_oM.dll</HintPath>
69+
<HintPath>$(ProgramData)\BHoM\Assemblies\Data_oM.dll</HintPath>
7070
<Private>False</Private>
7171
</Reference>
7272
<Reference Include="Dimensional_oM">
73-
<HintPath>C:\ProgramData\BHoM\Assemblies\Dimensional_oM.dll</HintPath>
73+
<HintPath>$(ProgramData)\BHoM\Assemblies\Dimensional_oM.dll</HintPath>
7474
<Private>False</Private>
7575
<SpecificVersion>False</SpecificVersion>
7676
</Reference>
@@ -79,57 +79,57 @@
7979
</Reference>
8080
<Reference Include="Geometry_Engine">
8181
<SpecificVersion>False</SpecificVersion>
82-
<HintPath>C:\ProgramData\BHoM\Assemblies\Geometry_Engine.dll</HintPath>
82+
<HintPath>$(ProgramData)\BHoM\Assemblies\Geometry_Engine.dll</HintPath>
8383
<Private>False</Private>
8484
</Reference>
8585
<Reference Include="Geometry_oM">
8686
<SpecificVersion>False</SpecificVersion>
87-
<HintPath>C:\ProgramData\BHoM\Assemblies\Geometry_oM.dll</HintPath>
87+
<HintPath>$(ProgramData)\BHoM\Assemblies\Geometry_oM.dll</HintPath>
8888
<Private>False</Private>
8989
</Reference>
9090
<Reference Include="GH_IO, Version=6.33.20343.16430, Culture=neutral, PublicKeyToken=6a29997d2e6b4f97, processorArchitecture=MSIL">
9191
<HintPath>..\packages\Grasshopper.6.33.20343.16431\lib\net45\GH_IO.dll</HintPath>
9292
</Reference>
9393
<Reference Include="Graphics_oM">
94-
<HintPath>C:\ProgramData\BHoM\Assemblies\Graphics_oM.dll</HintPath>
94+
<HintPath>$(ProgramData)\BHoM\Assemblies\Graphics_oM.dll</HintPath>
9595
<Private>False</Private>
9696
<SpecificVersion>False</SpecificVersion>
9797
</Reference>
9898
<Reference Include="Grasshopper, Version=6.33.20343.16430, Culture=neutral, PublicKeyToken=dda4f5ec2cd80803, processorArchitecture=MSIL">
9999
<HintPath>..\packages\Grasshopper.6.33.20343.16431\lib\net45\Grasshopper.dll</HintPath>
100100
</Reference>
101101
<Reference Include="Library_Engine">
102-
<HintPath>C:\ProgramData\BHoM\Assemblies\Library_Engine.dll</HintPath>
102+
<HintPath>$(ProgramData)\BHoM\Assemblies\Library_Engine.dll</HintPath>
103103
<Private>False</Private>
104104
<SpecificVersion>False</SpecificVersion>
105105
</Reference>
106106
<Reference Include="Microsoft.CSharp" />
107107
<Reference Include="Planning_oM">
108-
<HintPath>C:\ProgramData\BHoM\Assemblies\Planning_oM.dll</HintPath>
108+
<HintPath>$(ProgramData)\BHoM\Assemblies\Planning_oM.dll</HintPath>
109109
<Private>False</Private>
110110
<SpecificVersion>False</SpecificVersion>
111111
</Reference>
112112
<Reference Include="PresentationFramework" />
113113
<Reference Include="Programming_Engine">
114-
<HintPath>C:\ProgramData\BHoM\Assemblies\Programming_Engine.dll</HintPath>
114+
<HintPath>$(ProgramData)\BHoM\Assemblies\Programming_Engine.dll</HintPath>
115115
<Private>False</Private>
116116
<SpecificVersion>False</SpecificVersion>
117117
</Reference>
118118
<Reference Include="Programming_oM">
119-
<HintPath>C:\ProgramData\BHoM\Assemblies\Programming_oM.dll</HintPath>
119+
<HintPath>$(ProgramData)\BHoM\Assemblies\Programming_oM.dll</HintPath>
120120
<Private>False</Private>
121121
<SpecificVersion>False</SpecificVersion>
122122
</Reference>
123123
<Reference Include="Reflection_Engine">
124124
<SpecificVersion>False</SpecificVersion>
125-
<HintPath>C:\ProgramData\BHoM\Assemblies\Reflection_Engine.dll</HintPath>
125+
<HintPath>$(ProgramData)\BHoM\Assemblies\Reflection_Engine.dll</HintPath>
126126
<Private>False</Private>
127127
</Reference>
128128
<Reference Include="Rhino.UI, Version=6.33.20343.16430, Culture=neutral, PublicKeyToken=552281e97c755530, processorArchitecture=MSIL">
129129
<HintPath>..\packages\RhinoCommon.6.33.20343.16431\lib\net45\Rhino.UI.dll</HintPath>
130130
</Reference>
131131
<Reference Include="Rhinoceros_Engine">
132-
<HintPath>C:\ProgramData\BHoM\Assemblies\Rhinoceros_Engine.dll</HintPath>
132+
<HintPath>$(ProgramData)\BHoM\Assemblies\Rhinoceros_Engine.dll</HintPath>
133133
<Private>False</Private>
134134
<SpecificVersion>False</SpecificVersion>
135135
</Reference>
@@ -142,7 +142,7 @@
142142
</Reference>
143143
<Reference Include="Serialiser_Engine">
144144
<SpecificVersion>False</SpecificVersion>
145-
<HintPath>C:\ProgramData\BHoM\Assemblies\Serialiser_Engine.dll</HintPath>
145+
<HintPath>$(ProgramData)\BHoM\Assemblies\Serialiser_Engine.dll</HintPath>
146146
<Private>False</Private>
147147
</Reference>
148148
<Reference Include="System" />
@@ -151,12 +151,12 @@
151151
<Reference Include="System.Windows.Forms" />
152152
<Reference Include="UI_Engine">
153153
<SpecificVersion>False</SpecificVersion>
154-
<HintPath>C:\ProgramData\BHoM\Assemblies\UI_Engine.dll</HintPath>
154+
<HintPath>$(ProgramData)\BHoM\Assemblies\UI_Engine.dll</HintPath>
155155
<Private>False</Private>
156156
</Reference>
157157
<Reference Include="UI_oM">
158158
<SpecificVersion>False</SpecificVersion>
159-
<HintPath>C:\ProgramData\BHoM\Assemblies\UI_oM.dll</HintPath>
159+
<HintPath>$(ProgramData)\BHoM\Assemblies\UI_oM.dll</HintPath>
160160
<Private>False</Private>
161161
</Reference>
162162
</ItemGroup>
@@ -176,7 +176,9 @@
176176
<Compile Include="Components\Engine\GetEvents.cs" />
177177
<Compile Include="Components\Parameters\Param_BHoMAdapter.cs" />
178178
<Compile Include="Components\Parameters\Param_Variable.cs" />
179+
<Compile Include="Components\UI\FalseStartToggle.cs" />
179180
<Compile Include="Components\UI\UnitTest.cs" />
181+
<Compile Include="CustomAttributes\FalseStartToggleAttributes.cs" />
180182
<Compile Include="CustomAttributes\PrototypeAttribute.cs" />
181183
<Compile Include="CustomAttributes\PrototypeValueListAttribute.cs" />
182184
<Compile Include="Global\WireInfo.cs" />
@@ -376,7 +378,7 @@
376378
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
377379
<PropertyGroup>
378380
<PostBuildEvent>
379-
xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y
381+
xcopy "$(TargetDir)$(TargetFileName)" "$(ProgramData)\BHoM\Assemblies" /Y
380382
</PostBuildEvent>
381383
</PropertyGroup>
382384
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
@@ -388,11 +390,11 @@ xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y
388390
-->
389391
<PropertyGroup>
390392
<PostBuildEvent>rem copy .gh file to BHoM/Assembly folder
391-
Copy /Y "$(TargetDir)$(TargetName).dll" "C:\ProgramData\BHoM\Assemblies\$(TargetName).gha"
392-
xcopy "$(TargetDir)Script.dll" "C:\ProgramData\BHoM\Assemblies" /Y
393+
Copy /Y "$(TargetDir)$(TargetName).dll" "$(ProgramData)\BHoM\Assemblies\$(TargetName).gha"
394+
xcopy "$(TargetDir)Script.dll" "$(ProgramData)\BHoM\Assemblies" /Y
393395

394396
rem create .ghlink file
395-
echo C:\ProgramData\BHoM\Assemblies\$(TargetName).gha &gt; "$(AppData)\Grasshopper\Libraries\$(TargetName).ghlink"</PostBuildEvent>
397+
echo $(ProgramData)\BHoM\Assemblies\$(TargetName).gha &gt; "$(AppData)\Grasshopper\Libraries\$(TargetName).ghlink"</PostBuildEvent>
396398
</PropertyGroup>
397399
<PropertyGroup>
398400
<FallbackCulture>en-US</FallbackCulture>

0 commit comments

Comments
 (0)