Skip to content

Commit 2f17a22

Browse files
committed
Integrate new Avalonia OpenGL renderer into ShapeIt [1/n]
1 parent 921769e commit 2f17a22

16 files changed

Lines changed: 2053 additions & 158 deletions

CADability.Avalonia/CADability.Avalonia.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
1717
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
1818
</PackageReference>
19+
<PackageReference Include="Silk.NET.OpenGL" Version="2.23.0" />
1920
</ItemGroup>
2021

2122
<ItemGroup>

CADability.Avalonia/CadCanvas.axaml.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private static CADability.Substitutes.Rectangle Subst(Rect v)
1818
return new Substitutes.Rectangle((int)v.X, (int)v.Y, (int)v.Width, (int)v.Height);
1919
}
2020

21-
private IPaintTo3D paintTo3D;
21+
private PaintToOpenGL paintTo3D;
2222
private IFrame frame;
2323
private IView view;
2424
private String currentCursor;
@@ -27,18 +27,14 @@ public CadCanvas()
2727
{
2828
InitializeComponent();
2929
// CadCanvasControl canvasControl = new CadCanvasControl();
30-
PaintToOpenGL openGlControl = new PaintToOpenGL();
31-
this.Content = openGlControl;
30+
paintTo3D = new PaintToOpenGL(1e-6);
31+
this.Content = paintTo3D;
3232
}
3333

3434
void ICanvas.Invalidate() {}
3535

3636
Rectangle ICanvas.ClientRectangle => Subst(base.Bounds);
37-
38-
IFrame ICanvas.Frame
39-
{
40-
get { return frame; }
41-
}
37+
public IFrame Frame { get; set; }
4238

4339
string ICanvas.Cursor
4440
{
@@ -53,7 +49,14 @@ IPaintTo3D ICanvas.PaintTo3D
5349

5450
public event Action<ICanvas> OnPaintDone;
5551

56-
void ICanvas.ShowView(IView toShow) {}
52+
void ICanvas.ShowView(IView toShow)
53+
{
54+
view = toShow;
55+
// TODO init paintTo3D here or in constructor?
56+
paintTo3D.View = view;
57+
// TODO view.Connect needed?
58+
view.Connect(this);
59+
}
5760

5861
IView ICanvas.GetView()
5962
{
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:ca="using:CADability.Avalonia"
4+
x:Class="CADability.Avalonia.CadControl">
5+
<ca:CadCanvas Name="cadCanvas"></ca:CadCanvas>
6+
</UserControl>
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
using Avalonia.Controls;
2+
using CADability.UserInterface;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.ComponentModel;
6+
using System.Diagnostics;
7+
using System.Text;
8+
using System.Xml;
9+
10+
11+
namespace CADability.Avalonia
12+
{
13+
public partial class CadControl : UserControl, ICommandHandler
14+
{
15+
private CadFrame cadFrame; // the frame, which knows about the views, the ControlCenter (PropertiesExplorer), the menu
16+
// private ProgressForm progressForm;
17+
public CadControl()
18+
{
19+
InitializeComponent(); // makes the cadCanvas and the propertiesExplorer
20+
// KeyPreview = true; // used to filter the escape key (and maybe some more?)
21+
// cadFrame = new CadFrame(propertiesExplorer, cadCanvas, this);
22+
cadFrame = new CadFrame(cadCanvas, this);
23+
// cadFrame.ProgressAction = (show, percent, title) => { this.ProgressForm.ShowProgressBar(show, percent, title); };
24+
cadCanvas.Frame = cadFrame;
25+
// propertiesExplorer.Frame = cadFrame;
26+
// show this menu in the MainForm
27+
// MenuWithHandler[] mainMenu = MenuResource.LoadMenuDefinition("SDI Menu", true, cadFrame);
28+
// MainMenuStrip = MenuManager.MakeMainMenu(mainMenu);
29+
// Controls.Add(MainMenuStrip);
30+
// cadFrame.FormMenu = MainMenuStrip;
31+
// open an existing Project or create a new one
32+
// ToolBars.CreateOrRestoreToolbars(topToolStripContainer, cadFrame);
33+
// Application.Idle += new EventHandler(OnIdle); // update the toolbars (menus are updated when they popup)
34+
}
35+
/// <summary>
36+
/// Resets the main menu of the form. After MenuResource.SetMenuResource has been loaded, the mainmenu in CADability
37+
/// is changed to the new resource. In order to set this menu in the form, call this method.
38+
/// </summary>
39+
/// <param name="debuggerPlaygroundClass">if not null, specifies an additional menue class, which will be created by reflection</param>
40+
// TODO
41+
// public void ResetMainMenu(string debuggerPlaygroundClass)
42+
// {
43+
// MenuWithHandler[] mainMenu = MenuResource.LoadMenuDefinition("SDI Menu", true, cadFrame);
44+
// if (!string.IsNullOrEmpty(debuggerPlaygroundClass))
45+
// {
46+
// // in the following lines a "DebuggerPlayground" object is created via reflection. This class is a playground to write testcode
47+
// // which is not included in the sources. This is why it is constructed via reflection, there is no need to have this class in the project.
48+
// Type dbgplygnd = Type.GetType(debuggerPlaygroundClass, false);
49+
// if (dbgplygnd != null)
50+
// {
51+
// MethodInfo connect = dbgplygnd.GetMethod("Connect");
52+
// if (connect != null) mainMenu = connect.Invoke(null, new object[] { cadFrame, mainMenu }) as MenuWithHandler[];
53+
// }
54+
// }
55+
56+
// if (this.MainMenuStrip != null)
57+
// {
58+
// this.Controls.Remove(this.MainMenuStrip);
59+
// this.MainMenuStrip.Dispose();
60+
// }
61+
// MainMenuStrip = MenuManager.MakeMainMenu(mainMenu);
62+
// this.Controls.Add(MainMenuStrip);
63+
// cadFrame.FormMenu = MainMenuStrip;
64+
// }
65+
// Access the components of the MainForm from the CadFrame.
66+
// TODO
67+
// public void SetToolbar(XmlNode definition)
68+
// {
69+
// ToolBars.SetToolBar(topToolStripContainer, cadFrame, definition);
70+
// }
71+
// TODO
72+
// public ProgressForm ProgressForm
73+
// {
74+
// get
75+
// {
76+
// if (progressForm == null)
77+
// {
78+
// progressForm = new ProgressForm
79+
// {
80+
// TopLevel = true,
81+
// Owner = this,
82+
// Visible = false
83+
// };
84+
// }
85+
// return progressForm;
86+
// }
87+
// }
88+
// public PropertiesExplorer PropertiesExplorer => propertiesExplorer;
89+
public CadCanvas CadCanvas => cadCanvas;
90+
public CadFrame CadFrame => cadFrame;
91+
92+
// slowdown OnIdle polling:
93+
readonly Stopwatch _idleSw = Stopwatch.StartNew();
94+
const int MinIdleCheckMs = 250;
95+
bool _idleBusy;
96+
// TODO Avalonia
97+
// private void OnIdle(object sender, EventArgs e)
98+
// {
99+
// if (_idleBusy) return;
100+
// if (_idleSw.ElapsedMilliseconds < MinIdleCheckMs) return;
101+
102+
// _idleBusy = true;
103+
// _idleSw.Restart();
104+
// try { ToolBars.UpdateCommandState(topToolStripContainer.TopToolStripPanel); }
105+
// finally { _idleBusy = false; }
106+
// }
107+
// TODO
108+
// protected override void OnClosing(CancelEventArgs e)
109+
// { // maybe we need to save the project
110+
// ToolBars.SaveToolbarPositions(topToolStripContainer);
111+
// Settings.SaveGlobalSettings();
112+
// ToolStripManager.SaveSettings(this); // save the positions of the toolbars (doesn't work correctly)
113+
// base.OnClosing(e);
114+
// }
115+
// TODO
116+
// protected override void OnFormClosed(FormClosedEventArgs e)
117+
// {
118+
// cadFrame.Dispose();
119+
// MainMenuStrip.Dispose();
120+
// this.Dispose();
121+
// cadCanvas.Dispose();
122+
// propertiesExplorer.Dispose();
123+
// topToolStripContainer.Dispose();
124+
// splitContainer.Dispose();
125+
// if (progressForm != null) progressForm.Dispose();
126+
127+
// MainMenuStrip = null;
128+
// cadFrame = null;
129+
// cadCanvas = null;
130+
// propertiesExplorer = null;
131+
// topToolStripContainer = null;
132+
// splitContainer = null;
133+
// progressForm = null;
134+
135+
// base.OnFormClosed(e);
136+
// }
137+
// TODO
138+
// protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
139+
// {
140+
// Keys nmKeyData = (Keys)((int)keyData & 0x0FFFF);
141+
// bool preProcess = nmKeyData >= Keys.F1 && nmKeyData <= Keys.F24;
142+
// preProcess = preProcess || (nmKeyData == Keys.Escape);
143+
// preProcess = preProcess || (nmKeyData == Keys.Up) || (nmKeyData == Keys.Down);
144+
// preProcess = preProcess || (nmKeyData == Keys.Tab) || (nmKeyData == Keys.Enter);
145+
// preProcess = preProcess || keyData.HasFlag(Keys.Control) || keyData.HasFlag(Keys.Alt); // menu shortcut
146+
// if (propertiesExplorer.EntryWithTextBox == null) preProcess |= (nmKeyData == Keys.Delete); // the delete key is preferred by the textbox, if there is one
147+
// Substitutes.KeyEventArgs e = new Substitutes.KeyEventArgs((Substitutes.Keys)keyData);
148+
// if (preProcess)
149+
// {
150+
// e.Handled = false;
151+
// cadFrame.PreProcessKeyDown(e);
152+
// if (e.Handled) return true;
153+
// }
154+
// CadFrame.PreProcessKeyDown(e);
155+
// if (e.Handled) return true;
156+
// //if (msg.Msg== 0x0101) // WM_KEYUP
157+
// //{ }
158+
// return base.ProcessCmdKey(ref msg, keyData);
159+
// }
160+
161+
public virtual bool OnCommand(string MenuId)
162+
{
163+
return false;
164+
}
165+
166+
public virtual bool OnUpdateCommand(string MenuId, CommandState CommandState)
167+
{
168+
return false;
169+
}
170+
171+
public virtual void OnSelected(MenuWithHandler selectedMenuItem, bool selected)
172+
{
173+
174+
}
175+
176+
}
177+
}

CADability.Avalonia/CadForm.axaml

Lines changed: 0 additions & 14 deletions
This file was deleted.

CADability.Avalonia/CadForm.axaml.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)