Skip to content

Commit

Permalink
Update SymuForm
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorisse committed May 29, 2020
1 parent afec775 commit 5c7ee44
Show file tree
Hide file tree
Showing 30 changed files with 728 additions and 952 deletions.
107 changes: 87 additions & 20 deletions Symu examples/SymuBeliefsAndInfluence/Home.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 28 additions & 61 deletions Symu examples/SymuBeliefsAndInfluence/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#region using directives

using System;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
Expand All @@ -19,14 +20,14 @@
using Symu.Environment;
using Symu.Forms;
using Symu.Repository.Networks.Beliefs;
using Symu.Tools;
using SymuBeliefsAndInfluence.Classes;
using static Symu.Tools.Constants;

#endregion

namespace SymuBeliefsAndInfluence
{
public partial class Home : BaseForm
public partial class Home : SymuForm
{
private readonly ExampleEnvironment _environment = new ExampleEnvironment();
private int _initialTasksDone;
Expand Down Expand Up @@ -115,15 +116,14 @@ protected override void UpdateSettings()

#endregion

SetTimeStepType(TimeStepType.Daily);
}

protected override void SetScenarii()
{
_ = new TimeBasedScenario(_environment)
var scenario = new TimeBasedScenario(_environment)
{
NumberOfSteps = ushort.Parse(tbSteps.Text)
};

AddScenario(scenario);

SetTimeStepType(TimeStepType.Daily);
}

protected override void OnStopped()
Expand All @@ -142,7 +142,7 @@ private void Button2_Click(object sender, EventArgs e)
Cancel();
}

public override void Display()
public override void DisplayStep()
{
DisplayButtons();
WriteTextSafe(TimeStep, _environment.Schedule.Step.ToString());
Expand All @@ -163,7 +163,7 @@ private void UpdateAgents()
WriteTextSafe(InitialTotalBeliefs,
_environment.IterationResult.OrganizationKnowledgeAndBelief.Beliefs.First().Sum
.ToString("F1", CultureInfo.InvariantCulture));
var tasksDoneRatio = _environment.Schedule.Step * _environment.WorkersCount < Constants.Tolerance
var tasksDoneRatio = _environment.Schedule.Step * _environment.WorkersCount < Tolerance
? 0
: _environment.IterationResult.Tasks.Done * 100 /
(_environment.Schedule.Step * _environment.WorkersCount);
Expand Down Expand Up @@ -192,55 +192,7 @@ private void button3_Click(object sender, EventArgs e)

private void DisplayButtons()
{
switch (State)
{
case AgentState.Stopped:
case AgentState.NotStarted:
WriteButtonSafe(btnStart, true);
WriteButtonSafe(btnStop, false);
WriteButtonSafe(btnPause, false);
WriteButtonSafe(btnResume, false);
break;
case AgentState.Stopping:
case AgentState.Starting:
WriteButtonSafe(btnStart, false);
WriteButtonSafe(btnStop, false);
WriteButtonSafe(btnPause, false);
WriteButtonSafe(btnResume, false);
break;
case AgentState.Started:
WriteButtonSafe(btnStart, false);
WriteButtonSafe(btnStop, true);
WriteButtonSafe(btnPause, true);
WriteButtonSafe(btnResume, false);
break;
case AgentState.Paused:
WriteButtonSafe(btnStart, false);
WriteButtonSafe(btnStop, true);
WriteButtonSafe(btnPause, false);
WriteButtonSafe(btnResume, true);
break;
default:
throw new ArgumentOutOfRangeException();
}
}

protected void WriteButtonSafe(Button button, bool enabled)
{
if (button is null)
{
throw new ArgumentNullException(nameof(button));
}

if (button.InvokeRequired)
{
var d = new SafeCallButtonDelegate(WriteButtonSafe);
button.Invoke(d, button, enabled);
}
else
{
button.Enabled = enabled;
}
DisplayButtons(btnStart, btnStop, btnPause, btnResume);
}

private void tbWorkers_TextChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -502,11 +454,26 @@ private void BeliefsRateOfAgentsOn_TextChanged(object sender, EventArgs e)
MessageBox.Show(exception.Message);
}
}
#region Menu
private void symuorgToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start("https://symu.org");
}

#region Nested type: SafeCallButtonDelegate
private void documentationToolStripMenuItem1_Click(object sender, EventArgs e)
{
Process.Start("http://docs.symu.org/");
}

protected delegate void SafeCallButtonDelegate(Button button, bool enabled);
private void sourceCodeToolStripMenuItem1_Click(object sender, EventArgs e)
{
Process.Start("http://github.symu.org/");
}

private void issuesToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start("http://github.symu.org/issues");
}
#endregion
}
}
3 changes: 3 additions & 0 deletions Symu examples/SymuBeliefsAndInfluence/Home.resx
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,7 @@
Beliefs and influence model have an impact on different parameters :
perform tasks, modify the sphere of interaction, agents beliefs.</value>
</data>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\SymuOrg\Github\Symu source code\SymuTools\SymuTools.csproj">
<Project>{28ca606e-49d3-4136-ad3f-6b46eab9be75}</Project>
<Name>SymuTools</Name>
</ProjectReference>
<ProjectReference Include="..\..\Symu source code\SymuForm\SymuForm.csproj">
<Project>{fb0a9519-923e-4a4f-a6ac-dab4c7a03f63}</Project>
<Name>SymuForm</Name>
</ProjectReference>
<ProjectReference Include="..\..\Symu source code\SymuTools\SymuTools.csproj">
<Project>{28ca606e-49d3-4136-ad3f-6b46eab9be75}</Project>
<Name>SymuTools</Name>
</ProjectReference>
<ProjectReference Include="..\..\Symu source code\Symu\Symu.csproj">
<Project>{bd01bccd-7194-4bd1-8e62-9be1343af2ce}</Project>
<Name>Symu</Name>
Expand Down

0 comments on commit 5c7ee44

Please sign in to comment.