Skip to content

Commit 33cf7ed

Browse files
committed
General clean-up
Using Type.Guid for component id Added "hack" to deserialize when using the older component style
1 parent 3c999d7 commit 33cf7ed

13 files changed

+525
-440
lines changed

Component/ComponentIOMarshal.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
namespace GhPython.Component
1313
{
14-
internal abstract class ComponentIOMarshal
14+
abstract class ComponentIOMarshal
1515
{
1616
public abstract object GetInput(IGH_DataAccess DA, int i);
1717
public abstract void SetOutput(object o, IGH_DataAccess DA, int index);
1818
}
1919

20-
internal sealed class NewComponentIOMarshal : ComponentIOMarshal
20+
sealed class NewComponentIOMarshal : ComponentIOMarshal
2121
{
2222
private readonly ZuiPythonComponent _component;
2323

@@ -236,7 +236,7 @@ private IGH_DataTree GeometryTree<T>(DataTree<T> output)
236236
}
237237

238238

239-
internal sealed class OldComponentIOMarshal : ComponentIOMarshal
239+
sealed class OldComponentIOMarshal : ComponentIOMarshal
240240
{
241241
private readonly dynamic _document; //GrasshopperDocument-like object
242242
private readonly dynamic _objectTable; //CustomTable-like object

Component/PyUpgrader.cs

+24-21
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,25 @@ public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document documen
1010
{
1111
PythonComponent_OBSOLETE component_OBSOLETE = target as PythonComponent_OBSOLETE;
1212
if (component_OBSOLETE == null)
13-
{
1413
return null;
15-
}
14+
1615
ZuiPythonComponent component_new = new ZuiPythonComponent();
1716

18-
component_new.HideCodeInput = component_OBSOLETE.HideCodeInput;
19-
if (component_new.HideCodeInput)
20-
component_new.Params.Input.RemoveAt(0);
17+
bool show_code_input = false;
18+
if (component_OBSOLETE.CodeInputVisible)
19+
{
20+
// see if the "code" input on the old component really has anything
21+
// hooked up to it. If not, don't show the input
22+
show_code_input = component_OBSOLETE.Params.Input[0].SourceCount > 0;
23+
}
24+
component_new.CodeInputVisible = show_code_input;
2125

2226
component_new.HideCodeOutput = component_OBSOLETE.HideCodeOutput;
2327

2428
if (component_new.HideCodeOutput)
2529
component_new.Params.Output.RemoveAt(0);
2630

27-
if (component_new.HideCodeInput)
31+
if (!component_new.CodeInputVisible)
2832
component_new.CodeInput = component_OBSOLETE.CodeInput;
2933

3034
component_OBSOLETE.Dispose();
@@ -36,37 +40,36 @@ public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document documen
3640
foreach (var c in component_new.Params.Input)
3741
{
3842
var sc = c as Param_ScriptVariable;
39-
if (sc != null)
40-
{
41-
IGH_TypeHint newHint;
43+
if (sc == null) continue;
44+
IGH_TypeHint newHint;
4245

43-
if (toRhinoScript)
44-
{
45-
if (PythonHints.ToNewRhinoscriptHint(sc.TypeHint, out newHint))
46-
sc.TypeHint = newHint;
47-
}
48-
else
49-
{
50-
if (PythonHints.ToNewRhinoCommonHint(sc.TypeHint, out newHint))
51-
sc.TypeHint = newHint;
52-
}
46+
if (toRhinoScript)
47+
{
48+
if (PythonHints.ToNewRhinoscriptHint(sc.TypeHint, out newHint))
49+
sc.TypeHint = newHint;
50+
}
51+
else
52+
{
53+
if (PythonHints.ToNewRhinoCommonHint(sc.TypeHint, out newHint))
54+
sc.TypeHint = newHint;
5355
}
5456
}
5557
}
5658

59+
component_new.CodeInputVisible = show_code_input;
5760
return component_new;
5861
}
5962
return null;
6063
}
6164

6265
public Guid UpgradeFrom
6366
{
64-
get { return new Guid(PythonComponent_OBSOLETE.Id); }
67+
get { return typeof(PythonComponent_OBSOLETE).GUID; }
6568
}
6669

6770
public Guid UpgradeTo
6871
{
69-
get { return new Guid(ZuiPythonComponent.Id); }
72+
get { return typeof(ZuiPythonComponent).GUID; }
7073
}
7174

7275
public DateTime Version

0 commit comments

Comments
 (0)