forked from DongwanCho/IfcDoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CtlInheritance.cs
213 lines (187 loc) · 5.71 KB
/
CtlInheritance.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
201
202
203
204
205
206
207
208
209
210
211
212
213
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using IfcDoc.Schema.DOC;
using IfcDoc.Format.PNG;
namespace IfcDoc
{
public partial class CtlInheritance : ScrollableControl
{
private DocProject m_project;
private DocModelView m_modelview;
private DocEntity m_entity;
private DocEntity m_highlight;
private DocEntity m_selection;
private ToolMode m_mode;
private Image m_image;
private Dictionary<Rectangle, DocEntity> m_hitmap;
private Rectangle m_rcHighlight;
private Rectangle m_rcSelection;
public CtlInheritance()
{
InitializeComponent();
this.DoubleBuffered = true;
this.ResizeRedraw = true;
}
public DocProject Project
{
get
{
return this.m_project;
}
set
{
this.m_project = value;
}
}
public DocModelView ModelView
{
get
{
return this.m_modelview;
}
set
{
this.m_modelview = value;
}
}
public DocEntity Entity
{
get
{
return this.m_entity;
}
set
{
this.m_entity = value;
this.m_selection = null;
this.m_highlight = null;
this.Render();
}
}
public ToolMode Mode
{
get
{
return this.m_mode;
}
set
{
this.m_mode = value;
}
}
public DocEntity Selection
{
get
{
return this.m_selection;
}
}
public event EventHandler SelectionChanged;
public void Render()
{
if (this.m_image != null)
{
this.m_image.Dispose();
this.m_image = null;
}
Dictionary<DocObject, bool> included = null;
if (this.m_modelview != null)
{
included = new Dictionary<DocObject, bool>();
this.m_project.RegisterObjectsInScope(this.m_modelview, included);
}
this.m_hitmap = new Dictionary<Rectangle, DocEntity>();
this.m_image = FormatPNG.CreateInheritanceDiagram(this.m_project, included, this.m_entity, null, this.Font, this.m_hitmap);
if (this.m_image != null)
{
this.AutoScrollMinSize = new Size(this.m_image.Width, this.m_image.Height);
}
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs pe)
{
if (this.m_image == null)
return;
Graphics g = pe.Graphics;
g.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);
g.DrawImage(this.m_image, Point.Empty);
if (this.m_highlight != null)
{
g.DrawRectangle(Pens.Red, this.m_rcHighlight);
}
}
private DocEntity Pick(Point pt, out Rectangle rectangle)
{
rectangle = Rectangle.Empty;
pt.X -= this.AutoScrollPosition.X;
pt.Y -= this.AutoScrollPosition.Y;
foreach (Rectangle rc in this.m_hitmap.Keys)
{
if (rc.Contains(pt))
{
rectangle = rc;
DocEntity docEnt = this.m_hitmap[rc];
return docEnt;
}
}
return null;
}
private void CtlInheritance_MouseDown(object sender, MouseEventArgs e)
{
this.m_selection = this.Pick(e.Location, out this.m_rcSelection);
switch (this.m_mode)
{
case ToolMode.Select:
if (this.SelectionChanged != null)
{
this.SelectionChanged(this, EventArgs.Empty);
}
break;
case ToolMode.Move:
if (this.m_selection != null)
{
this.m_selection._InheritanceDiagramFlag = !this.m_selection._InheritanceDiagramFlag;
this.m_selection.Status = (this.m_selection._InheritanceDiagramFlag ? "H" : String.Empty);
this.Render();
}
break;
}
}
private void CtlInheritance_MouseMove(object sender, MouseEventArgs e)
{
this.m_highlight = this.Pick(e.Location, out this.m_rcHighlight);
switch(this.m_mode)
{
case ToolMode.Select:
if (m_highlight != null)
{
this.Cursor = Cursors.Hand;
}
else
{
this.Cursor = Cursors.Default;
}
break;
case ToolMode.Move:
if (m_highlight != null)
{
this.Cursor = Cursors.UpArrow;
}
else
{
this.Cursor = Cursors.Default;
}
break;
}
this.Invalidate();
}
private void CtlInheritance_MouseUp(object sender, MouseEventArgs e)
{
}
}
}