Skip to content

Commit e50c969

Browse files
Kinin-Code-OfficalKinin-Code-Offical
andauthored
RobotStudio: breadboard scaffold (#199)
* feat: unify RobotStudio package, diagnostics visuals, and perf fixes * feat: add breadboard spec + RobotStudio UI hooks * feat: complete breadboard placement + cleanup --------- Co-authored-by: Kinin-Code-Offical <yamacgursel@gmail.com>
1 parent bc90b56 commit e50c969

File tree

10 files changed

+328
-22
lines changed

10 files changed

+328
-22
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ crashlytics-build.properties
4747
.DS_Store
4848
Thumbs.db
4949
Desktop.ini
50-
50+
.amazonq/
5151
# Python
5252
.venv/
5353
.venv_step/

CoreSim/src/RobotTwin.CoreSim/Host/RealtimeHardening.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,22 @@ private static void TrySetAffinity(long affinityMask)
7171
#if NET5_0_OR_GREATER
7272
if (OperatingSystem.IsWindows())
7373
{
74-
typeof(Process).GetProperty("ProcessorAffinity")?.SetValue(process, affinityMask1);
74+
#pragma warning disable CA1416 // Platform compatibility
75+
process.ProcessorAffinity = affinityMask1;
76+
#pragma warning restore CA1416
7577
}
7678
else if (OperatingSystem.IsLinux())
7779
{
78-
typeof(Process).GetProperty("ProcessorAffinity")?.SetValue(process, affinityMask1);
80+
#pragma warning disable CA1416 // Platform compatibility
81+
process.ProcessorAffinity = affinityMask1;
82+
#pragma warning restore CA1416
7983
}
8084
#else
8185
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
8286
{
83-
typeof(Process).GetProperty("ProcessorAffinity")?.SetValue(process, affinityMask1);
87+
#pragma warning disable CA1416 // Platform compatibility
88+
process.ProcessorAffinity = affinityMask1;
89+
#pragma warning restore CA1416
8490
}
8591
#endif
8692
}

CoreSim/src/RobotTwin.CoreSim/Specs/AssemblySpec.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class AssemblySpec
66
{
77
public List<AssemblyPartSpec> Parts { get; set; } = new List<AssemblyPartSpec>();
88
public List<AssemblyWireSpec> Wires { get; set; } = new List<AssemblyWireSpec>();
9+
public List<BreadboardSpec> Breadboards { get; set; } = new List<BreadboardSpec>();
910
}
1011

1112
public class AssemblyPartSpec
@@ -33,6 +34,17 @@ public class AssemblyWireSpec
3334
public double Damping { get; set; } = 0.2;
3435
}
3536

37+
public class BreadboardSpec
38+
{
39+
public string Id { get; set; } = string.Empty;
40+
public int PinCount { get; set; } = 400;
41+
public int Columns { get; set; } = 10;
42+
public int Rows { get; set; } = 40;
43+
public double Pitch { get; set; } = 0.00254;
44+
public Vec3 Position { get; set; } = new Vec3();
45+
public Vec3 Rotation { get; set; } = new Vec3();
46+
public Vec3 Scale { get; set; } = new Vec3 { X = 1, Y = 1, Z = 1 };
47+
}
3648
public struct Vec3
3749
{
3850
public double X { get; set; }
1.5 KB
Binary file not shown.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using UnityEngine;
2+
3+
namespace RobotTwin.UI
4+
{
5+
public class RobotStudioBreadboard : MonoBehaviour
6+
{
7+
public string Id;
8+
public int PinCount;
9+
public int Columns;
10+
public int Rows;
11+
public float Pitch;
12+
public float Thickness;
13+
public float Margin;
14+
public float Width;
15+
public float Depth;
16+
public Renderer BoardRenderer;
17+
18+
// Owned resources created at runtime (e.g., texture/material for the base).
19+
// These are not Unity asset references and must be cleaned up to avoid leaks.
20+
public Material OwnedMaterial;
21+
public Texture2D OwnedTexture;
22+
23+
public float TopSurfaceY => Thickness * 0.5f;
24+
25+
private void OnDestroy()
26+
{
27+
// If we authored the shared material/texture at runtime, we own lifetime.
28+
if (BoardRenderer != null && OwnedMaterial != null && BoardRenderer.sharedMaterial == OwnedMaterial)
29+
{
30+
BoardRenderer.sharedMaterial = null;
31+
}
32+
33+
DestroyOwnedResource(OwnedMaterial);
34+
OwnedMaterial = null;
35+
36+
DestroyOwnedResource(OwnedTexture);
37+
OwnedTexture = null;
38+
}
39+
40+
private static void DestroyOwnedResource(Object resource)
41+
{
42+
if (resource == null) return;
43+
44+
if (Application.isPlaying)
45+
{
46+
Destroy(resource);
47+
}
48+
else
49+
{
50+
DestroyImmediate(resource);
51+
}
52+
}
53+
}
54+
}

RobotWin/Assets/Scripts/UI/RobotStudio/RobotStudioBreadboard.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)