-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
200 lines (168 loc) · 5.68 KB
/
MainWindow.xaml.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Windows.Forms.Integration;
using System.Windows.Interop;
using System.Runtime.InteropServices;
namespace OccView
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged
{
//declare an event/instaniate a delegate which type is PropertyChangedEventHandler
/*PropertyChangedEventHandler(object sender, PropertyChangedEventArgs e)*/
//PropertyChanged takes 2 param: object sender, PropertyChangedEventArgs e
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string thePropertyName)
{//call observers registered method when property changed
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(thePropertyName));
}
}
public D3dViewer mViewer;
public MainWindow()
{
InitializeComponent();
InitViewer();
data = new CSData();
}
public void InitViewer()
{
mViewer = new D3dViewer();
Grid g = new Grid();
Map.Add(g, mViewer);
//1.use D3DImage to initialize imgBrush
ImageBrush imgBrush = new ImageBrush(mViewer.Image);
//2.use ImageBrush to fill grid background
g.Background = imgBrush;
g.MouseMove += new MouseEventHandler(g_MouseMove);
g.MouseDown += new MouseButtonEventHandler(g_MouseDown);
g.MouseUp += new MouseButtonEventHandler(g_MouseUp);
g.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
//3.assign grid to TabItem content
TabItem aNewTab = new TabItem();
aNewTab.Content = g; //assign grid to TabItem
aNewTab.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
aNewTab.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch;
aNewTab.VerticalContentAlignment = System.Windows.VerticalAlignment.Stretch;
g.SizeChanged += new SizeChangedEventHandler(g_SizeChanged);
aNewTab.IsSelected = true;
aNewTab.Header = "View " + mViewCounter.ToString();
mViewCounter++;
//4.add TabItem to xaml TabControl
ViewPanel.Items.Add(aNewTab);
ViewPanel.Focus();
//5.update XAML property
RaisePropertyChanged("IsDocumentOpen");
}
private void Import_Click(object sender, RoutedEventArgs e)
{
if (viewer != null)
{
viewer.ImportModel(ModelFormat.STEP);
}
}
private void Occ_Click(object sender, RoutedEventArgs e)
{
if (data != null)
{
data.ToOccJson();
}
}
private void CSharp_Click(object sender, RoutedEventArgs e)
{
if (data != null)
{
//actData.InitWeather();
data.LoadJson();
}
}
private void Test_Click(object sender, RoutedEventArgs e)
{
if (data != null)
{
data.TestConvert();
}
}
private OCCViewer viewer
{
get
{
if (!IsDocumentOpen)
{
return null;
}
Grid grid = (ViewPanel.SelectedContent) as Grid;
if (grid == null)
{
return null;
}
return Map[grid].Viewer;
}
}
public Boolean IsDocumentOpen
{
get
{
return ViewPanel.Items.Count > 0;
}
}
void g_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (!IsDocumentOpen)
return;
Grid aGrid = (ViewPanel.SelectedContent) as Grid;
if (aGrid == null)
return;
Map[aGrid].Resize(Convert.ToInt32(e.NewSize.Width),
Convert.ToInt32(e.NewSize.Height));
}
void g_MouseMove(object sender, MouseEventArgs e)
{
Grid aGrid = (ViewPanel.SelectedContent) as Grid;
if (aGrid != null)
{
viewer.OnMouseMove(aGrid, e);
}
}
void g_MouseDown(object sender, MouseButtonEventArgs e)
{
Grid aGrid = (ViewPanel.SelectedContent) as Grid;
if (aGrid != null)
{
viewer.OnMouseDown(ViewPanel, e);
}
}
void g_MouseUp(object sender, MouseButtonEventArgs e)
{
Grid aGrid = (ViewPanel.SelectedContent) as Grid;
if (aGrid != null)
{
viewer.OnMouseUp(aGrid, e);
}
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
}
private int mViewCounter = 1;
Dictionary<Grid, D3dViewer> Map = new Dictionary<Grid, D3dViewer>();
private void ViewPanel_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private CSData data;
}
}