diff --git a/CtrEditor.csproj b/CtrEditor.csproj
index bed0220..f4d3ba2 100644
--- a/CtrEditor.csproj
+++ b/CtrEditor.csproj
@@ -103,6 +103,8 @@
+
+
diff --git a/DataStates/StateManager.cs b/DataStates/StateManager.cs
index 884af89..cdcc3c0 100644
--- a/DataStates/StateManager.cs
+++ b/DataStates/StateManager.cs
@@ -258,12 +258,9 @@ namespace CtrEditor
if (obj != null)
{
obj.CheckData();
- await Task.Run(() =>
+ await Application.Current.Dispatcher.InvokeAsync(() =>
{
- Application.Current.Dispatcher.Invoke(() =>
- {
- CrearUserControlDesdeObjetoSimulable(obj);
- });
+ CrearUserControlDesdeObjetoSimulable(obj);
});
}
}
@@ -369,7 +366,16 @@ namespace CtrEditor
{
if (_hasUnsavedChanges)
{
- SaveAllAsync().Wait();
+ try
+ {
+ // Usar TaskScheduler.Default para evitar deadlocks en UI thread
+ Task.Run(async () => await SaveAllAsync()).Wait(TimeSpan.FromSeconds(10));
+ }
+ catch (Exception ex)
+ {
+ // Log error en lugar de fallar el dispose
+ System.Diagnostics.Debug.WriteLine($"[StateManager] Error en Dispose: {ex.Message}");
+ }
}
}
}
diff --git a/Documentation/MCP/MCP_LLM_Guide.md b/Documentation/MCP/MCP_LLM_Guide.md
index c007bf6..e046fd7 100644
--- a/Documentation/MCP/MCP_LLM_Guide.md
+++ b/Documentation/MCP/MCP_LLM_Guide.md
@@ -12,6 +12,8 @@
### 🟡 **Medium** (Use When Needed)
- `search_debug_log` → 50-200 tokens (max_lines=3-10)
- `build_project` → 100-500 tokens (errors only)
+- `execute_python` → 50-500 tokens (depends on script)
+- `python_help` → 100-300 tokens
### 🔴 **Heavy** (Use Sparingly)
- `list_objects` → 500-2000+ tokens
@@ -27,6 +29,7 @@
```
### Build & Debug
+Para los Debug se usa DebugTraceListener que es soportado por WPF
```json
{"tool": "build_project", "parameters": {}}
{"tool": "start_debug_listener", "parameters": {}}
@@ -49,6 +52,16 @@
{"tool": "delete_objects", "parameters": {"ids": ["123", "456"]}}
```
+### Python Debug Scripts ⚡ NEW
+```json
+{"tool": "execute_python", "parameters": {"code": "print(f'Total objects: {len(objects)}')"}}
+{"tool": "execute_python", "parameters": {
+ "code": "result = [obj for obj in objects if 'Pump' in str(type(obj))]",
+ "return_variables": ["result"]
+}}
+{"tool": "python_help", "parameters": {"object_name": "app"}}
+```
+
## ⚡ Optimal Workflows
### Quick Development Cycle
@@ -56,12 +69,14 @@
{"tool": "get_ctreditor_status", "parameters": {}}
{"tool": "build_project", "parameters": {}}
{"tool": "start_simulation", "parameters": {}}
+{"tool": "execute_python", "parameters": {"code": "print(f'Objects: {len(objects)}, Running: {app.IsSimulationRunning}')"}}
{"tool": "get_simulation_status", "parameters": {}}
```
### Bug Investigation
```json
{"tool": "search_debug_log", "parameters": {"pattern": "error|exception", "max_lines": 3}}
+{"tool": "execute_python", "parameters": {"code": "print([type(obj).__name__ for obj in objects[:5]])"}}
{"tool": "get_simulation_status", "parameters": {}}
```
@@ -73,6 +88,12 @@
## 📊 Key Object Properties
+### Python Debug Variables
+- **app**: MainViewModel (simulation state, canvas, objects)
+- **canvas**: MainCanvas (Width, Height, visual elements)
+- **objects**: ObservableCollection of all simulable objects
+- **get_objects()**: Returns List