Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Added ability to adjust text size for text label method
Also added ability to change UI language of the plugin
  • Loading branch information
lin-ycv authored Mar 6, 2021
1 parent 5dfa4c1 commit 2b7d6d3
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 58 deletions.
55 changes: 39 additions & 16 deletions src/MultilingualGH/MultilingualComp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class MultilingualComp : GH_Component

public MultilingualComp()
: base("MultilingualGH", "MGH",
"Annotates components with desired language.",
UI.CompDes,
"Params", "Util")
{
}
public override GH_Exposure Exposure => GH_Exposure.primary | GH_Exposure.obscure;

protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddTextParameter("Exclude", "X", "List of components to exclude from annotations", GH_ParamAccess.list);
pManager.AddTextParameter(UI.CompIn, "X", UI.CompInDes, GH_ParamAccess.list);
pManager[0].Optional = true;
}

Expand All @@ -43,14 +43,14 @@ public override void AddedToDocument(GH_Document document)
{
if (mgh.compGuid != Guid.Empty && mgh.compGuid != InstanceGuid)
{
MessageBox.Show("There is already an instance of MultilingualGH on the canvas. No need for another one.", "MultilingualGH", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show(UI.TooMany, "MultilingualGH", MessageBoxButtons.OK, MessageBoxIcon.Information);
document.RemoveObject(this, false);
}
else
{
mgh.compGuid = InstanceGuid;
MultilingualMenu.mghDropdown.Enabled = false;
MultilingualMenu.mghDropdown.ToolTipText = "Menu disabled when MGH component is in use";
MultilingualMenu.mghDropdown.ToolTipText = UI.MenuDisabled;
document.ObjectsDeleted += RemovedMe;
IGH_Param inputParam = base.Params.Input[0];
if (mgh.excludeUser != string.Empty && inputParam.SourceCount == 0)
Expand Down Expand Up @@ -80,19 +80,38 @@ public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
var canvas = Grasshopper.Instances.ActiveCanvas;
var items = MultilingualMenu.mghDropdown.DropDownItems;
base.AppendAdditionalMenuItems(menu);
Menu_AppendItem(menu, "Use Text Label", (s, e) =>
Menu_AppendItem(menu, UI.UseTextLabel, (s, e) =>
{
mgh.textLabel = !mgh.textLabel;
((ToolStripComboBox)items["Method"]).SelectedIndex = mgh.textLabel ? 1 : 0;
MultilingualInstance.EventHandler(canvas, mgh);
}, true, mgh.textLabel);
Menu_AppendItem(menu, "Use Default Exclusions", (s, e) =>
if (mgh.textLabel)
{
NumericUpDown textSize = new NumericUpDown
{
Minimum = 1,
Maximum = 254,
Increment = 1,
Value = mgh.size,
DecimalPlaces = 0
};
textSize.ValueChanged += (s, e) =>
{
var inputSize = ((NumericUpDown)s).Value;
if (inputSize > textSize.Maximum) inputSize = textSize.Maximum;
else if (inputSize < textSize.Minimum) inputSize = textSize.Minimum;
mgh.size = Convert.ToInt32(inputSize);
};
Menu_AppendCustomItem(menu, textSize);
}
Menu_AppendItem(menu, UI.UseDefaultExclusions, (s, e) =>
{
mgh.excludeDefault = !mgh.excludeDefault;
((ToolStripMenuItem)items["Default"]).Checked = mgh.excludeDefault;
MultilingualInstance.EventHandler(canvas, mgh);
}, true, mgh.excludeDefault);
Menu_AppendItem(menu, "Keep annotations", (s, e) =>
Menu_AppendItem(menu, UI.KeepAnnotations, (s, e) =>
{
mgh.keep = !mgh.keep;
((ToolStripMenuItem)items["Keep"]).Checked = mgh.keep;
Expand All @@ -103,12 +122,12 @@ public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
{
Menu_AppendItem(menu, lang, (s, e) => LangSelection(lang), true, mgh.language == lang);
}
if(Translation.extraFiles.Count>0)
if (Translation.extraFiles.Count > 0)
Menu_AppendSeparator(menu);
foreach (var plugin in Translation.extraFiles)
{
string shorten = $"*{plugin.Split('_')[0]}*";
Menu_AppendItem(menu, plugin, (s, e) => PluginSelection(shorten), mgh.language!="English", mgh.language != "English" && mgh.extras.Contains(shorten));
Menu_AppendItem(menu, plugin, (s, e) => PluginSelection(shorten), mgh.language != "English", mgh.language != "English" && mgh.extras.Contains(shorten));
}
}
internal void LangSelection(string lang)
Expand All @@ -123,7 +142,7 @@ internal void LangSelection(string lang)
mgh.prevLang = lang;
ExpireSolution(true);
}
MultilingualInstance.EventHandler(Grasshopper.Instances.ActiveCanvas, mgh);
MultilingualInstance.EventHandler(Grasshopper.Instances.ActiveCanvas, mgh);
}
}
internal void PluginSelection(string plugin)
Expand All @@ -138,7 +157,7 @@ internal void PluginSelection(string plugin)
}
if (mgh.enabled)
{
if(clean)
if (clean)
Translation.Clear(Grasshopper.Instances.ActiveCanvas.Document);
ExpireSolution(true);
MultilingualInstance.EventHandler(Grasshopper.Instances.ActiveCanvas, mgh);
Expand All @@ -147,7 +166,7 @@ internal void PluginSelection(string plugin)

protected override void SolveInstance(IGH_DataAccess DA)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Version " + MultilingualGHInfo.Ver);
AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, UI.Version + MultilingualGHInfo.Ver);
var canvas = Grasshopper.Instances.ActiveCanvas;
if (mgh == null) AddedToDocument(canvas.Document);
if (Translation.noRoot) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $" Folder '{Translation.folder}' not found");
Expand All @@ -163,20 +182,20 @@ protected override void SolveInstance(IGH_DataAccess DA)
mgh.excludeUser = string.Empty;
((ToolStripMenuItem)MultilingualMenu.mghDropdown.DropDownItems["User"]).Checked = false;
}
Message = mgh.enabled ? mgh.language : "Disabled";
Message = mgh.enabled ? mgh.language : UI.Disabled;

if (mgh.language == "English")
DA.SetData(0, "https://github.com/v-xup6/MultilingualGH");
else
{
Translation.translations[mgh.language].TryGetValue("*Translator*", out string credit);
StringBuilder eCredits = new StringBuilder();
foreach(string plugin in mgh.extras.Split(new string[] { "**", "*" }, StringSplitOptions.RemoveEmptyEntries))
foreach (string plugin in mgh.extras.Split(new string[] { "**", "*" }, StringSplitOptions.RemoveEmptyEntries))
{
Translation.extraTranslations[plugin].TryGetValue("*Translator*", out string cred);
eCredits.Append(", " + cred);
}
DA.SetData(0, "Translation(s) by " + credit+eCredits.ToString());
DA.SetData(0, UI.TranslationBy + credit + eCredits.ToString());
}
MultilingualInstance.EventHandler(canvas, mgh);
}
Expand Down Expand Up @@ -208,7 +227,7 @@ public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH
{
MultilingualInstance.documents.TryGetValue(sender.Document.DocumentID, out MultilingualInstance mgh);
mgh.enabled = !mgh.enabled;
base.Owner.Message = mgh.enabled ? mgh.language : "Disabled";
base.Owner.Message = mgh.enabled ? mgh.language : UI.Disabled;
if (mgh.enabled)
{
if (!mgh.textLabel)
Expand Down Expand Up @@ -238,6 +257,8 @@ public override bool Write(GH_IO.Serialization.GH_IWriter writer)
writer.SetBoolean("MGHKeepAnno", mgh.keep);
writer.SetBoolean("MGHUseDe", mgh.excludeDefault);
writer.SetBoolean("MGHLabelMethod", mgh.textLabel);
writer.SetString("MGHExtras", mgh.extras);
writer.SetInt32("MGHTextSize", mgh.size);
return base.Write(writer);
}
public override bool Read(GH_IO.Serialization.GH_IReader reader)
Expand All @@ -251,6 +272,8 @@ public override bool Read(GH_IO.Serialization.GH_IReader reader)
reader.TryGetBoolean("MGHKeepAnno", ref mgh.keep);
reader.TryGetBoolean("MGHUseDe", ref mgh.excludeDefault);
reader.TryGetBoolean("MGHLabelMethod", ref mgh.textLabel);
reader.TryGetString("MGHExtras", ref mgh.extras);
reader.TryGetInt32("MGHTextSize", ref mgh.size);
}
return base.Read(reader);
}
Expand Down
3 changes: 2 additions & 1 deletion src/MultilingualGH/MultilingualGH.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
Expand Down Expand Up @@ -51,6 +51,7 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="UI.cs" />
<Compile Include="MultilingualComp.cs" />
<Compile Include="MultilingualInstance.cs" />
<Compile Include="MultilingualMenu.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/MultilingualGH/MultilingualGH.csproj.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartProgram>C:\Program Files\Rhino 6\System\Rhino.exe</StartProgram>
<StartProgram>C:\Program Files\Rhino 7\System\Rhino.exe</StartProgram>
</PropertyGroup>
</Project>
1 change: 0 additions & 1 deletion src/MultilingualGH/MultilingualGHInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,5 @@ public override string Version
return Ver;
}
}

}
}
5 changes: 4 additions & 1 deletion src/MultilingualGH/MultilingualInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MultilingualInstance
internal string extras = string.Empty;
internal string prevLang;
internal Guid compGuid = Guid.Empty;
internal int size = 8;

internal MultilingualInstance()
{
Expand All @@ -28,6 +29,7 @@ internal MultilingualInstance()
keep = Grasshopper.Instances.Settings.GetValue("MGHKeepAnno", false);
language = Grasshopper.Instances.Settings.GetValue("MGHLangSel", "English");
extras = Grasshopper.Instances.Settings.GetValue("MGHExtras", string.Empty);
size = Grasshopper.Instances.Settings.GetValue("MGHTextSize", 8);
}
static internal void SaveSettings(MultilingualInstance mgh)
{
Expand All @@ -37,7 +39,8 @@ static internal void SaveSettings(MultilingualInstance mgh)
Grasshopper.Instances.Settings.SetValue("MGHUseUe", mgh.excludeUser);
Grasshopper.Instances.Settings.SetValue("MGHKeepAnno", mgh.keep);
Grasshopper.Instances.Settings.SetValue("MGHLangSel", mgh.language);
Grasshopper.Instances.Settings.GetValue("MGHExtras", mgh.extras);
Grasshopper.Instances.Settings.SetValue("MGHExtras", mgh.extras);
Grasshopper.Instances.Settings.SetValue("MGHTextSize", mgh.size);
}
static internal void EventHandler(GH_Canvas sender, MultilingualInstance mgh)
{
Expand Down
Loading

0 comments on commit 2b7d6d3

Please sign in to comment.