-
Notifications
You must be signed in to change notification settings - Fork 334
/
Copy pathMainForm.cs
92 lines (80 loc) · 2.4 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
namespace EtoApp
{
class MainForm : Eto.Forms.Form
{
static Rhino.Runtime.InProcess.RhinoCore _rhinoCore;
public static void Run()
{
_rhinoCore = new Rhino.Runtime.InProcess.RhinoCore(null, Rhino.Runtime.InProcess.WindowStyle.Hidden);
MainForm mf = new MainForm();
mf.Show();
for (int i = 0; i < System.Windows.Application.Current.Windows.Count; i++)
{
var window = System.Windows.Application.Current.Windows[i];
if (window.IsVisible)
{
window.Closed += (s, e) => Shutdown();
break;
}
}
System.Windows.Forms.Application.Run();
}
static void Shutdown()
{
_rhinoCore.Dispose();
System.Windows.Forms.Application.Exit();
}
Rhino.UI.Controls.ViewportControl _viewportControl;
public MainForm()
{
Title = "Rhino.Inside";
ClientSize = new Eto.Drawing.Size(400, 400);
_viewportControl = new Rhino.UI.Controls.ViewportControl();
Content = _viewportControl;
var viewMenu = new Eto.Forms.ButtonMenuItem { Text = "&View" };
BuildDisplayModesMenu(viewMenu.Items);
Menu = new Eto.Forms.MenuBar()
{
Items =
{
new Eto.Forms.ButtonMenuItem
{
Text = "&File",
Items =
{
new Eto.Forms.ButtonMenuItem(new Eto.Forms.Command((s,e)=>OpenFile())) { Text = "Open..." }
}
},
viewMenu
}
};
}
void BuildDisplayModesMenu(Eto.Forms.MenuItemCollection collection)
{
Rhino.Display.DisplayModeDescription[] modes = Rhino.Display.DisplayModeDescription.GetDisplayModes();
foreach(var mode in modes)
{
var menuitem = new Eto.Forms.ButtonMenuItem((s, e) =>
{
_viewportControl.Viewport.DisplayMode = mode;
_viewportControl.Refresh();
});
menuitem.Text = mode.EnglishName;
collection.Add(menuitem);
}
}
void OpenFile()
{
var ofd = new Eto.Forms.OpenFileDialog();
ofd.Filters.Add(new Eto.Forms.FileFilter("Rhino 3dm", ".3dm"));
if( ofd.ShowDialog(this) == Eto.Forms.DialogResult.Ok )
{
Title = $"Rhino.Inside ({ofd.FileName})";
Rhino.RhinoDoc.Open(ofd.FileName, out bool alreadyOpen);
_viewportControl.Viewport.ZoomExtents();
_viewportControl.Refresh();
}
}
}
}