Skip to content
This repository was archived by the owner on Jan 6, 2021. It is now read-only.

Commit c9eab91

Browse files
committed
Merge pull request #51 from piac/master
changes and fixes for post-Grasshopper 0.9.61 full compatibility.
2 parents fa25e40 + b3e3303 commit c9eab91

22 files changed

Lines changed: 999 additions & 849 deletions

Component/ComponentIOMarshal.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,22 @@ abstract class ComponentIOMarshal
1919

2020
sealed class NewComponentIOMarshal : ComponentIOMarshal
2121
{
22-
private readonly ZuiPythonComponent _component;
23-
24-
private readonly GrasshopperDocument _document;
25-
private readonly CustomTable _objectTable;
22+
private readonly ZuiPythonComponent m_component;
23+
private readonly CustomTable m_objectTable;
24+
private readonly GrasshopperDocument m_document;
2625

2726
public NewComponentIOMarshal(GrasshopperDocument document, ZuiPythonComponent component)
2827
{
29-
_document = document;
30-
_objectTable = _document.Objects;
31-
_component = component;
28+
m_document = document;
29+
m_objectTable = m_document.Objects;
30+
m_component = component;
3231
}
3332

3433
#region Inputs
3534

3635
public override object GetInput(IGH_DataAccess DA, int i)
3736
{
38-
var input = (Param_ScriptVariable) _component.Params.Input[i];
37+
var input = (Param_ScriptVariable) m_component.Params.Input[i];
3938
bool addIntoGhDoc = input.TypeHint is GhDocGuidHint;
4039

4140
object o;
@@ -76,7 +75,7 @@ private object GetListFromParameter(IGH_DataAccess DA, int index, bool addIntoGh
7675
{
7776
List<IGH_Goo> list2 = new List<IGH_Goo>();
7877
DA.GetDataList(index, list2);
79-
IGH_TypeHint typeHint = ((Param_ScriptVariable) _component.Params.Input[index]).TypeHint;
78+
IGH_TypeHint typeHint = ((Param_ScriptVariable) m_component.Params.Input[index]).TypeHint;
8079
var t = Type.GetType("IronPython.Runtime.List,IronPython");
8180
IList list = Activator.CreateInstance(t) as IList;
8281

@@ -97,7 +96,7 @@ private object GetTreeFromParameter(IGH_DataAccess DA, int index, bool addIntoGh
9796
{
9897
GH_Structure<IGH_Goo> structure;
9998
DA.GetDataTree(index, out structure);
100-
IGH_TypeHint typeHint = ((Param_ScriptVariable) _component.Params.Input[index]).TypeHint;
99+
IGH_TypeHint typeHint = ((Param_ScriptVariable) m_component.Params.Input[index]).TypeHint;
101100
var tree = new DataTree<object>();
102101

103102
for (int i = 0; i < structure.PathCount; i++)
@@ -120,7 +119,7 @@ private object GetTreeFromParameter(IGH_DataAccess DA, int index, bool addIntoGh
120119

121120
private object TypeCast(IGH_Goo data, int index)
122121
{
123-
Param_ScriptVariable variable = (Param_ScriptVariable) _component.Params.Input[index];
122+
Param_ScriptVariable variable = (Param_ScriptVariable) m_component.Params.Input[index];
124123
return this.TypeCast(data, variable.TypeHint);
125124
}
126125

@@ -146,11 +145,11 @@ public void DocumentSingle(ref object input, bool addIntoGhDoc)
146145
{
147146
if (input is GeometryBase)
148147
{
149-
input = _objectTable.__InternalAdd(input as dynamic);
148+
input = m_objectTable.__InternalAdd(input as dynamic);
150149
}
151150
else if (input is Point3d)
152151
{
153-
input = _objectTable.AddPoint((Point3d) input);
152+
input = m_objectTable.AddPoint((Point3d) input);
154153
}
155154
}
156155
}
@@ -186,8 +185,9 @@ public override void SetOutput(object o, IGH_DataAccess DA, int index)
186185
{
187186
o = (this as dynamic).GeometryTree(o as dynamic);
188187
}
189-
catch
188+
catch (Exception ex)
190189
{
190+
Rhino.Runtime.HostUtils.ExceptionReport(ex);
191191
}
192192
DA.SetDataTree(index, o as IGH_DataTree);
193193
}
@@ -211,7 +211,7 @@ private void GeometrySingle(ref object input)
211211
{
212212
if (input is Guid)
213213
{
214-
AttributedGeometry a = _objectTable.Find((Guid) input);
214+
AttributedGeometry a = m_objectTable.Find((Guid) input);
215215
input = a.Geometry;
216216
}
217217
}
@@ -423,8 +423,9 @@ public override void SetOutput(object o, IGH_DataAccess DA, int index)
423423
{
424424
o = (this as dynamic).GeometryTree(o as dynamic);
425425
}
426-
catch
426+
catch (Exception ex)
427427
{
428+
Rhino.Runtime.HostUtils.ExceptionReport(ex);
428429
}
429430
}
430431
DA.SetDataTree(index, o as IGH_DataTree);

Component/DocStringUtils.cs

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55

66
namespace GhPython.Component
77
{
8-
/*
9-
# based on DocStrings as defined in
10-
# http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Comments
11-
""""""
12-
Title: Arithmetic Series
13-
Description: Computes the Sum of an Arithmetic Progression, or the
14-
sum of all numbers from F to L, included.
15-
Args:
16-
F: the first number included in the series.
17-
L: the last number included in the series.
18-
Returns:
19-
S: If F > L, then sum of all numbers [F,L].
20-
If F = L, then 0.
21-
If F < L, then sum of all numbers (L,F).
22-
K: Not used.
23-
Help:
24-
See also the Gauss elementary school story:
25-
http://mathworld.wolfram.com/ArithmeticSeries.html
26-
""""""
27-
*/
8+
/*
9+
# based on DocStrings as defined in
10+
# http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Comments
11+
""""""
12+
Title: Arithmetic Series
13+
Description: Computes the Sum of an Arithmetic Progression, or the
14+
sum of all numbers from F to L, included.
15+
Args:
16+
F: the first number included in the series.
17+
L: the last number included in the series.
18+
Returns:
19+
S: If F > L, then sum of all numbers [F,L].
20+
If F = L, then 0.
21+
If F < L, then sum of all numbers (L,F).
22+
K: Not used.
23+
Help:
24+
See also the Gauss elementary school story:
25+
http://mathworld.wolfram.com/ArithmeticSeries.html
26+
""""""
27+
*/
2828
class DocStringUtils
2929
{
3030
public static bool FindApplyDocString(string code, ScriptingAncestorComponent component)
@@ -55,7 +55,8 @@ public static bool FindApplyDocString(string code, ScriptingAncestorComponent co
5555
int endSeparator = line.IndexOf(_docStringSeparator);
5656
if (endSeparator != -1) line = line.Substring(0, endSeparator);
5757

58-
if (IsEmptyLine(line)) {
58+
if (IsEmptyLine(line))
59+
{
5960
if (endSeparator != -1) break;
6061
continue;
6162
}
@@ -141,7 +142,7 @@ private static void Send(string variable, ref StringBuilder result, KeywordType
141142
{
142143
if (variable != null)
143144
{
144-
switch(type)
145+
switch (type)
145146
{
146147
case KeywordType.Description:
147148
component.Description = result.ToString();
@@ -153,7 +154,7 @@ private static void Send(string variable, ref StringBuilder result, KeywordType
153154
FindAndDescribe(component.Params.Output, variable, result.ToString());
154155
break;
155156
case KeywordType.Help:
156-
component.SpecialPythonHelpContent = result.ToString();
157+
component.AdditionalHelpFromDocStrings = result.ToString();
157158
break;
158159
}
159160
result = new StringBuilder();
@@ -181,12 +182,6 @@ enum KeywordType
181182
Help,
182183
}
183184

184-
//private static void AppendText(StringBuilder result, string text)
185-
//{
186-
// if (result.Length != 0) result.Append(" ");
187-
// result.Append(text);
188-
//}
189-
190185
private static void AddLine(StringBuilder result, string text)
191186
{
192187
if (result.Length != 0) result.AppendLine();
@@ -237,7 +232,7 @@ private static bool IsEmptyOrFullyCommentedOutLine(string line)
237232

238233
public static string Htmlify(string input)
239234
{
240-
string firstRepl = System.Text.RegularExpressions.Regex.Replace(input, "[<>&\"'\n]",
235+
string firstRepl = System.Text.RegularExpressions.Regex.Replace(input, "[<>&\"'\n\r]",
241236
t =>
242237
{
243238
switch (t.Value)
@@ -254,6 +249,8 @@ public static string Htmlify(string input)
254249
return "&#39;";
255250
case "\n":
256251
return "<br>";
252+
case "\r":
253+
return string.Empty;
257254
}
258255
return string.Empty;
259256
});

Component/GHComponentsLoader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public static void Add(IGH_Component component)
7272
{
7373
object newobj = System.Activator.CreateInstance(t);
7474
}
75-
catch(Exception ex)
75+
76+
* (Exception ex)
7677
{
7778
int h = 0;
7879

Component/PyUpgrader.cs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,11 @@ public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document documen
1414

1515
ZuiPythonComponent component_new = new ZuiPythonComponent();
1616

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;
25-
26-
component_new.HideCodeOutput = component_OBSOLETE.HideCodeOutput;
17+
component_new.HiddenCodeInput = component_OBSOLETE.HiddenCodeInput;
18+
component_new.HiddenOutOutput = component_OBSOLETE.HiddenOutOutput;
2719

28-
if (component_new.HideCodeOutput)
29-
component_new.Params.Output.RemoveAt(0);
30-
31-
if (!component_new.CodeInputVisible)
32-
component_new.CodeInput = component_OBSOLETE.CodeInput;
33-
34-
component_OBSOLETE.Dispose();
20+
if (!component_new.HiddenCodeInput)
21+
component_new.Code = component_OBSOLETE.Code;
3522

3623
if (GH_UpgradeUtil.SwapComponents(component_OBSOLETE, component_new))
3724
{
@@ -55,7 +42,8 @@ public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document documen
5542
}
5643
}
5744

58-
component_new.CodeInputVisible = show_code_input;
45+
component_OBSOLETE.Dispose();
46+
5947
return component_new;
6048
}
6149
return null;
@@ -73,7 +61,7 @@ public Guid UpgradeTo
7361

7462
public DateTime Version
7563
{
76-
get { return new DateTime(2012, 3, 19, 21, 0, 0); }
64+
get { return new DateTime(2013, 10, 14, 0, 0, 0); }
7765
}
7866
}
7967
}

Component/PythonComponent.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public class PythonComponent_OBSOLETE : ScriptingAncestorComponent, IGH_VarParam
1414
{
1515
protected override void AddDefaultInput(GH_Component.GH_InputParamManager inputManager)
1616
{
17-
inputManager.RegisterParam(ConstructVariable(GH_VarParamSide.Input, "x"));
18-
inputManager.RegisterParam(ConstructVariable(GH_VarParamSide.Input, "y"));
17+
inputManager.AddParameter(ConstructVariable(GH_VarParamSide.Input, "x"));
18+
inputManager.AddParameter(ConstructVariable(GH_VarParamSide.Input, "y"));
1919
}
2020

2121
protected override void AddDefaultOutput(GH_Component.GH_OutputParamManager outputManager)
@@ -43,21 +43,21 @@ protected override void SetScriptTransientGlobals()
4343
case DocStorage.InGrasshopperMemory:
4444
case DocStorage.AutomaticMarshal:
4545
{
46-
_py.ScriptContextDoc = _document;
47-
_marshal = new OldComponentIOMarshal(_document, this);
48-
_py.SetVariable(DOCUMENT_NAME, _document);
49-
_py.SetIntellisenseVariable(DOCUMENT_NAME, _document);
46+
m_py.ScriptContextDoc = m_document;
47+
m_marshal = new OldComponentIOMarshal(m_document, this);
48+
m_py.SetVariable(DOCUMENT_NAME, m_document);
49+
m_py.SetIntellisenseVariable(DOCUMENT_NAME, m_document);
5050
break;
5151
}
5252
case DocStorage.InRhinoDoc:
5353
{
54-
_py.ScriptContextDoc = Rhino.RhinoDoc.ActiveDoc;
55-
_marshal = new OldComponentIOMarshal(Rhino.RhinoDoc.ActiveDoc, this);
54+
m_py.ScriptContextDoc = Rhino.RhinoDoc.ActiveDoc;
55+
m_marshal = new OldComponentIOMarshal(Rhino.RhinoDoc.ActiveDoc, this);
5656
Rhino.RhinoDoc.ActiveDoc.UndoRecordingEnabled = true;
57-
if (_py.ContainsVariable(DOCUMENT_NAME))
57+
if (m_py.ContainsVariable(DOCUMENT_NAME))
5858
{
59-
_py.RemoveVariable(DOCUMENT_NAME);
60-
_py.SetIntellisenseVariable(DOCUMENT_NAME, null);
59+
m_py.RemoveVariable(DOCUMENT_NAME);
60+
m_py.SetIntellisenseVariable(DOCUMENT_NAME, null);
6161
}
6262
break;
6363
}
@@ -88,7 +88,7 @@ public void SetDoc(object sender, EventArgs e)
8888
{
8989
try
9090
{
91-
Component.CheckAndSetupActions();
91+
Component.CheckIfSetupActionsAreNecessary();
9292

9393
Component.DocStorageMode = NewDocStorage;
9494
Component.SetScriptTransientGlobals();
@@ -181,13 +181,13 @@ public bool IsOutputVariable
181181

182182
public bool IsVariableParam(GH_VarParamEventArgs e)
183183
{
184-
return e.Index > (!CodeInputVisible ? -1 : 0);
184+
return e.Index > (!HiddenCodeInput ? -1 : 0);
185185
}
186186

187187
public void ManagerConstructed(GH_VarParamSide side, Grasshopper.GUI.GH_VariableParameterManager manager)
188188
{
189189
string pool = (side == GH_VarParamSide.Input) ? "xyzuvw" : "abcdef";
190-
manager.NameConstructor = new GH_CharPatternParamNameConstructor(pool, 4);
190+
manager.NameConstructor = new Grasshopper.Kernel.GH_StringPattern(pool, 4);
191191
}
192192

193193
public void ParametersModified(GH_VarParamSide side)

0 commit comments

Comments
 (0)