Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions BrainSimMAC/BrainSimMACMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
*
* This file is part of Brain Simulator Thought and is licensed under
* the MIT License. You may use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of this software under the terms of
* sublicense, and/or sell copies of the software under the terms of
* the MIT License.
*
* See the LICENSE file in the project root for full license information.
*/
using BrainSimulator;
using System.Diagnostics;
using UKS;


Expand Down Expand Up @@ -67,15 +68,22 @@
//force the MainWindow to always be activated
moduleHandler.ActivateModule("MainWindow.py");

const int loopDelayMs = 50;

while (true)
{
activeModulesRoot = moduleHandler.theUKS.Labeled("ActiveModule");
if (activeModulesRoot is null)
{
Thread.Sleep(loopDelayMs);
continue;
}

foreach (var module in activeModulesRoot.Children)
{
if (module.Label.Contains(".py"))
moduleHandler.RunScript(module.Label);
}
activeModulesRoot = moduleHandler.theUKS.Labeled("ActiveModule");

for (int i = 0; i < moduleHandler.activePythonModules.Count; i++)
{
Expand All @@ -88,7 +96,12 @@
moduleHandler.activePythonModules.RemoveAt(i);
i--;
}
catch { }
catch (Exception ex)
{
Debug.WriteLine($"BrainSimMAC: Close failed for {module.Item1}: {ex.Message}");
}
}
}
}

Thread.Sleep(loopDelayMs);
}
3 changes: 3 additions & 0 deletions BrainSimulator/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
*
* See the LICENSE file in the project root for full license information.
*/
using System.Runtime.CompilerServices;
using System.Windows;

[assembly: InternalsVisibleTo("Tests")]

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
Expand Down
22 changes: 13 additions & 9 deletions BrainSimulator/BrainSim Thought.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<AssemblyVersion>1.6.4</AssemblyVersion>
<ApplicationIcon>Iconsmall.ico</ApplicationIcon>
<SourceRevisionId>build$([System.DateTime]::UtcNow.ToString("yyyyMMddHHmmss"))</SourceRevisionId>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<AnalysisMode>Default</AnalysisMode>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -25,9 +25,13 @@
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="Tests" />
</ItemGroup>
<ItemGroup>
<Compile Remove="archive\legacy\**" />
<Compile Remove="GlobalSuppressions.cs" />
<Compile Remove="ImgUtils.cs" />
<Compile Remove="MainWindowPythonModules.cs" />

<Compile Remove="Modules\Module2DSim.cs" />
<Compile Remove="Modules\Module2DSimDlg.xaml.cs" />
<Compile Remove="Modules\Module2DVision.cs" />
Expand All @@ -49,7 +53,7 @@
<Compile Remove="Sallie.cs" />
<Compile Remove="Tools\Module.cs" />
<Compile Remove="Tools\ModuleDlg.xaml.cs" />
<Compile Remove="XmlFile.cs" />

</ItemGroup>
<ItemGroup>
<None Remove="refresh-3104.png" />
Expand Down Expand Up @@ -123,6 +127,11 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="Resources\wordlist.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="..\PythonProj\utils.py">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -131,11 +140,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Compile Remove="Modules\Vision\**" />
<EmbeddedResource Remove="Modules\Vision\**" />
<None Remove="Modules\Vision\**" />
<Page Remove="Modules\Vision\**" />
</ItemGroup>


</Project>
2 changes: 2 additions & 0 deletions BrainSimulator/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Legacy BrainSim3 "Thing" alias removed 2026-07 with old Vision code.
// Native code uses Thought / Link directly. Python interop updated separately if needed.
39 changes: 3 additions & 36 deletions BrainSimulator/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,6 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e)

//setup the python support
pythonPath = (string)Environment.GetEnvironmentVariable("PythonPath", EnvironmentVariableTarget.User);
if (false)
//if (string.IsNullOrEmpty(pythonPath))
{
var result1 = MessageBox.Show("Do you want to use Python Modules?", "Python?", MessageBoxButton.YesNo);
if (result1 == MessageBoxResult.Yes)
{
string likeliPath = (string)Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
likeliPath += @"\Programs\Python";
System.Windows.Forms.OpenFileDialog openFileDialog = new()
{
Title = "SELECT path to Python .dll (or cancel for no Python support)",
InitialDirectory = likeliPath,
};

// Show the file Dialog.
System.Windows.Forms.DialogResult result = openFileDialog.ShowDialog();
// If the user clicked OK in the dialog and
if (result == System.Windows.Forms.DialogResult.OK)
{
pythonPath = openFileDialog.FileName;
Environment.SetEnvironmentVariable("PythonPath", pythonPath, EnvironmentVariableTarget.User);
}
else
{
Environment.SetEnvironmentVariable("PythonPath", "", EnvironmentVariableTarget.User);
}
openFileDialog.Dispose();
}
else
{
pythonPath = "no";
Environment.SetEnvironmentVariable("PythonPath", pythonPath, EnvironmentVariableTarget.User);
}
}
moduleHandler.PythonPath = pythonPath;
if (pythonPath != "no")
{
Expand Down Expand Up @@ -112,7 +78,7 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e)
CreateEmptyUKS();
}
}
catch (Exception ex)
catch (Exception)
{
System.Windows.MessageBox.Show("UKS Content not loaded");
}
Expand Down Expand Up @@ -327,8 +293,9 @@ public static void ResumeEngine()
}

//THIS IS THE MAIN ENGINE LOOP
private void Dt_Tick(object? sender, EventArgs e)
private void Dt_Tick(object sender, EventArgs e)
{
theUKS.BeginTraversalCycle();
Thought activeModuleParent = theUKS.Labeled("ActiveModule");
if (activeModuleParent is null) return;
foreach (Thought module in activeModuleParent.Children)
Expand Down
5 changes: 2 additions & 3 deletions BrainSimulator/MainWindowFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace BrainSimulator
/// </summary>
public partial class MainWindow : Window
{
private static StackPanel loadedModulesSP;
private bool LoadFile(string fileName)
{
SuspendEngine();
Expand Down Expand Up @@ -63,10 +62,10 @@ public void ReloadActiveModulesSP()
ActiveModuleSP.Children.Clear();

Thought activeModuleParent = theUKS.Labeled("ActiveModule");
if (activeModuleParent is null) { return; }

//TODO: Remove
activeModuleParent.AddParent("BrainSim");

if (activeModuleParent is null) { return; }
var activeModules1 = activeModuleParent.Children;
activeModules1 = activeModules1.OrderBy(x => x.Label).ToList();

Expand Down
4 changes: 2 additions & 2 deletions BrainSimulator/MainWindowPythonModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ static void RunScript(string moduleLabel)
{
bool firstTime = false;
//get the ModuleType
Thing tModule = theUKS.Labeled(moduleLabel);
Thought tModule = theUKS.Labeled(moduleLabel);
if (tModule == null) { return; }
Thing tModuleType = tModule.Parents.FindFirst(x => x.HasAncestorLabeled("AvailableModule"));
Thought tModuleType = tModule.Parents.FindFirst(x => x.HasAncestorLabeled("AvailableModule"));
if (tModuleType == null) return;
string moduleType = tModuleType.Label;
moduleType = moduleType.Replace(".py", "");
Expand Down
8 changes: 0 additions & 8 deletions BrainSimulator/ModuleDescriptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,6 @@ Works together with SpeechParser, PhraseRecognizer, QueryResolution and SpeechOu
<moduleName>ModuleUKSClause</moduleName>
<description>This dialog creates a Link between two Relastionships connected by a Clause Type. This can be used to create conditioinan links by using the clause type "if". That is, enter Mary can play outside if weather is sunny. This link will only be added to search results if the condition, weather is sunny, is true.</description>
</ModuleDescription>
<ModuleDescription>
<moduleName>ModuleVision</moduleName>
<description>This module iintended to provide input/test data for visual recognition. It performs generic CV algorithms to locate corners in a simple visual input.</description>
</ModuleDescription>
<ModuleDescription>
<moduleName>ModuleShape</moduleName>
<description>This module allows the system to save shapes and retrieve them by content.</description>
</ModuleDescription>
<ModuleDescription>
<moduleName>ModuleAttributeBubble</moduleName>
<description>This Agent scans the UKS Object tree looking for object Children which have common attributes which can be "bubbled" up to the parent.
Expand Down
14 changes: 4 additions & 10 deletions BrainSimulator/ModuleHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,7 @@ public void DeactivateModule(string moduleLabel)
{
Thought t = theUKS.Labeled(moduleLabel);
if (t is null) return;
for (int i = 0; i < t.LinksTo.Count; i++)
{
Link r = t.LinksTo[i];
r.To.Delete();
}
t.Delete();

return;
}


Expand Down Expand Up @@ -141,7 +134,7 @@ public void Close(string moduleLabel)
{
theModuleEntry.Item2.Close();
}
catch { }
catch (Exception ex) { Debug.WriteLine($"Python Close failed for {theModuleEntry.Item1}: {ex.Message}"); }
}
}
}
Expand Down Expand Up @@ -221,9 +214,10 @@ public void RunScript(string moduleLabel)
catch (Exception ex)
{
activePythonModules.Remove(theModuleEntry);
DeactivateModule(moduleLabel);
#if !CONSOLE_APP
MainWindow.theWindow.ReloadActiveModulesSP();
MainWindow.theWindow?.DeactivateModule(moduleLabel);
#else
DeactivateModule(moduleLabel);
#endif
Console.WriteLine("Fire method call failed for module: " + moduleLabel + " Reason: " + ex.Message);
}
Expand Down
33 changes: 23 additions & 10 deletions BrainSimulator/ModuleViewMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public void CreateContextMenu(ModuleBase nr, FrameworkElement r, ContextMenu cm
cm = new ContextMenu();
cm.SetValue(moduleNameProperty, nr.Label);

StackPanel sp;
MenuItem mi = new MenuItem();
mi = new MenuItem();
mi.Header = "Delete";
Expand Down Expand Up @@ -100,17 +99,16 @@ private void Mi_Click(object sender, RoutedEventArgs e)
if ((string)mi.Header == "View Dialog Source")
theModuleType += "Dlg.xaml";

string cwd = System.IO.Directory.GetCurrentDirectory();
if (cwd.Contains("bin\\"))
cwd = cwd.ToLower().Substring(0, cwd.IndexOf("bin\\"));
string fileName = cwd + @"modules\" + theModuleType + ".cs";
string cwd = Directory.GetCurrentDirectory();
string binSegment = "bin" + Path.DirectorySeparatorChar;
int binIndex = cwd.IndexOf(binSegment, StringComparison.OrdinalIgnoreCase);
if (binIndex >= 0)
cwd = cwd.Substring(0, binIndex);
string fileName = Path.Combine(cwd, "modules", theModuleType + ".cs");
if (!File.Exists(fileName))
fileName = Path.Combine(cwd, "BrainSim2modules", theModuleType + ".cs");
if (File.Exists(fileName))
OpenSource(fileName);
else
{
fileName = cwd + @"BrainSim2modules\" + theModuleType + ".cs";
OpenSource(fileName);
}
}
if ((string)mi.Header == "Delete")
{
Expand Down Expand Up @@ -176,5 +174,20 @@ public void DeleteModule(string moduleName)

ReloadActiveModulesSP();
}

public void DeactivateModule(string moduleLabel)
{
ModuleBase mb = activeModules.FindFirst(x => x.Label == moduleLabel);
if (mb is not null)
{
mb.CloseDlg();
mb.Closing();
activeModules.Remove(mb);
}
pythonModules.Remove(moduleLabel);
moduleHandler.pythonModules.Remove(moduleLabel);
moduleHandler.DeactivateModule(moduleLabel);
ReloadActiveModulesSP();
}
}
}
2 changes: 1 addition & 1 deletion BrainSimulator/Modules/Agents/ModuleAddCounts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override void Fire()
UpdateDialog();
}

public bool isEnabled { get; set; }
public new bool isEnabled { get; set; }

private Timer timer;
//private UKS.UKS theUKS1;
Expand Down
Loading