d1a2fee8 |
1 | using System; |
2 | using System.Drawing; |
3 | using System.Collections; |
4 | using System.ComponentModel; |
5 | using System.Windows.Forms; |
6 | |
7 | |
8 | namespace IE_WinForms |
9 | { |
10 | public enum CurrentAction3d |
11 | { |
12 | CurAction3d_Nothing, |
13 | CurAction3d_DynamicZooming, |
14 | CurAction3d_WindowZooming, |
15 | CurAction3d_DynamicPanning, |
16 | CurAction3d_GlobalPanning, |
17 | CurAction3d_DynamicRotation |
18 | } |
19 | public enum CurrentPressedKey |
20 | { |
21 | CurPressedKey_Nothing, |
22 | CurPressedKey_Ctrl, |
23 | CurPressedKey_Shift |
24 | } |
25 | public enum ModelFormat |
26 | { |
27 | BREP, |
d1a2fee8 |
28 | STEP, |
29 | IGES, |
30 | VRML, |
31 | STL, |
32 | IMAGE |
33 | } |
34 | /// <summary> |
35 | /// Summary description for Form2. |
36 | /// </summary> |
37 | public class Form2 : System.Windows.Forms.Form |
38 | { |
39 | private System.ComponentModel.IContainer components; |
40 | |
41 | public Form2() |
42 | { |
43 | // |
44 | // Required for Windows Form Designer support |
45 | // |
46 | InitializeComponent(); |
47 | |
48 | // |
49 | // Create OCCT proxy object |
50 | // |
51 | myOCCTProxy = new OCCTProxy(); |
52 | myCurrentMode = CurrentAction3d.CurAction3d_Nothing; |
53 | myCurrentPressedKey = CurrentPressedKey.CurPressedKey_Nothing; |
54 | myDegenerateModeIsOn = true; |
55 | IsRectVisible = false; |
56 | } |
57 | |
58 | /// <summary> |
59 | /// Clean up any resources being used. |
60 | /// </summary> |
61 | protected override void Dispose(bool disposing) |
62 | { |
63 | if (disposing) |
64 | { |
65 | if (components != null) |
66 | { |
67 | components.Dispose(); |
68 | } |
69 | } |
70 | base.Dispose(disposing); |
71 | } |
72 | |
73 | #region Windows Form Designer generated code |
74 | /// <summary> |
75 | /// Required method for Designer support - do not modify |
76 | /// the contents of this method with the code editor. |
77 | /// </summary> |
78 | private void InitializeComponent() |
79 | { |
80 | this.components = new System.ComponentModel.Container(); |
81 | System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form2)); |
82 | this.imageList1 = new System.Windows.Forms.ImageList(this.components); |
83 | this.myPopup = new System.Windows.Forms.ContextMenu(); |
84 | this.menuItem1 = new System.Windows.Forms.MenuItem(); |
85 | this.myPopupObject = new System.Windows.Forms.ContextMenu(); |
86 | this.ContextWireframe = new System.Windows.Forms.MenuItem(); |
87 | this.ContextShading = new System.Windows.Forms.MenuItem(); |
88 | this.ContextColor = new System.Windows.Forms.MenuItem(); |
89 | this.ContextMaterial = new System.Windows.Forms.MenuItem(); |
90 | this.ContMatBrass = new System.Windows.Forms.MenuItem(); |
91 | this.ContMenBronze = new System.Windows.Forms.MenuItem(); |
92 | this.ContMenCopper = new System.Windows.Forms.MenuItem(); |
93 | this.ContMenGold = new System.Windows.Forms.MenuItem(); |
94 | this.ContMenPewt = new System.Windows.Forms.MenuItem(); |
95 | this.ContMenPlaster = new System.Windows.Forms.MenuItem(); |
96 | this.ContMenPlastic = new System.Windows.Forms.MenuItem(); |
97 | this.ContMenSilver = new System.Windows.Forms.MenuItem(); |
98 | this.ContMenTranc = new System.Windows.Forms.MenuItem(); |
99 | this.ContMenDelete = new System.Windows.Forms.MenuItem(); |
100 | // |
101 | // imageList1 |
102 | // |
103 | this.imageList1.ImageSize = new System.Drawing.Size(16, 16); |
104 | this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream"))); |
105 | this.imageList1.TransparentColor = System.Drawing.Color.Transparent; |
106 | // |
107 | // myPopup |
108 | // |
109 | this.myPopup.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { |
110 | this.menuItem1}); |
111 | // |
112 | // menuItem1 |
113 | // |
114 | this.menuItem1.Index = 0; |
115 | this.menuItem1.Text = "Change &Background"; |
116 | this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click); |
117 | // |
118 | // myPopupObject |
119 | // |
120 | this.myPopupObject.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { |
121 | this.ContextWireframe, |
122 | this.ContextShading, |
123 | this.ContextColor, |
124 | this.ContextMaterial, |
125 | this.ContMenTranc, |
126 | this.ContMenDelete}); |
127 | this.myPopupObject.Popup += new System.EventHandler(this.myPopupObject_Popup); |
128 | // |
129 | // ContextWireframe |
130 | // |
131 | this.ContextWireframe.Index = 0; |
132 | this.ContextWireframe.Text = "Wireframe"; |
133 | this.ContextWireframe.Click += new System.EventHandler(this.ContextWireframe_Click); |
134 | // |
135 | // ContextShading |
136 | // |
137 | this.ContextShading.Index = 1; |
138 | this.ContextShading.Text = "Shading"; |
139 | this.ContextShading.Click += new System.EventHandler(this.ContextShading_Click); |
140 | // |
141 | // ContextColor |
142 | // |
143 | this.ContextColor.Index = 2; |
144 | this.ContextColor.Text = "Color"; |
145 | this.ContextColor.Click += new System.EventHandler(this.ContextColor_Click); |
146 | // |
147 | // ContextMaterial |
148 | // |
149 | this.ContextMaterial.Index = 3; |
150 | this.ContextMaterial.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { |
151 | this.ContMatBrass, |
152 | this.ContMenBronze, |
153 | this.ContMenCopper, |
154 | this.ContMenGold, |
155 | this.ContMenPewt, |
156 | this.ContMenPlaster, |
157 | this.ContMenPlastic, |
158 | this.ContMenSilver}); |
159 | this.ContextMaterial.Text = "Material"; |
160 | // |
161 | // ContMatBrass |
162 | // |
163 | this.ContMatBrass.Index = 0; |
164 | this.ContMatBrass.Text = "&Brass"; |
165 | this.ContMatBrass.Click += new System.EventHandler(this.ContMatBrass_Click); |
166 | // |
167 | // ContMenBronze |
168 | // |
169 | this.ContMenBronze.Index = 1; |
170 | this.ContMenBronze.Text = "&Bronze"; |
171 | this.ContMenBronze.Click += new System.EventHandler(this.ContMenBronze_Click); |
172 | // |
173 | // ContMenCopper |
174 | // |
175 | this.ContMenCopper.Index = 2; |
176 | this.ContMenCopper.Text = "&Copper"; |
177 | this.ContMenCopper.Click += new System.EventHandler(this.ContMenCopper_Click); |
178 | // |
179 | // ContMenGold |
180 | // |
181 | this.ContMenGold.Index = 3; |
182 | this.ContMenGold.Text = "&Gold"; |
183 | this.ContMenGold.Click += new System.EventHandler(this.ContMenGold_Click); |
184 | // |
185 | // ContMenPewt |
186 | // |
187 | this.ContMenPewt.Index = 4; |
188 | this.ContMenPewt.Text = "&Pewter"; |
189 | this.ContMenPewt.Click += new System.EventHandler(this.ContMenPewt_Click); |
190 | // |
191 | // ContMenPlaster |
192 | // |
193 | this.ContMenPlaster.Index = 5; |
194 | this.ContMenPlaster.Text = "&Plaster"; |
195 | this.ContMenPlaster.Click += new System.EventHandler(this.ContMenPlaster_Click); |
196 | // |
197 | // ContMenPlastic |
198 | // |
199 | this.ContMenPlastic.Index = 6; |
200 | this.ContMenPlastic.Text = "&Plastic"; |
201 | this.ContMenPlastic.Click += new System.EventHandler(this.ContMenPlastic_Click); |
202 | // |
203 | // ContMenSilver |
204 | // |
205 | this.ContMenSilver.Index = 7; |
206 | this.ContMenSilver.Text = "&Silver"; |
207 | this.ContMenSilver.Click += new System.EventHandler(this.ContMenSilver_Click); |
208 | // |
209 | // ContMenTranc |
210 | // |
211 | this.ContMenTranc.Index = 4; |
212 | this.ContMenTranc.Text = "&Trancparency"; |
213 | this.ContMenTranc.Click += new System.EventHandler(this.ContMenTranc_Click); |
214 | // |
215 | // ContMenDelete |
216 | // |
217 | this.ContMenDelete.Index = 5; |
218 | this.ContMenDelete.Text = "&Delete"; |
219 | this.ContMenDelete.Click += new System.EventHandler(this.ContMenDelete_Click); |
220 | // |
221 | // Form2 |
222 | // |
223 | this.AccessibleRole = System.Windows.Forms.AccessibleRole.Window; |
224 | this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); |
225 | this.ClientSize = new System.Drawing.Size(320, 261); |
226 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); |
227 | this.ImeMode = System.Windows.Forms.ImeMode.NoControl; |
228 | this.Name = "Form2"; |
229 | this.Text = "Document"; |
230 | this.WindowState = System.Windows.Forms.FormWindowState.Maximized; |
231 | this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form2_KeyDown); |
232 | this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form2_MouseDown); |
233 | this.SizeChanged += new System.EventHandler(this.Form2_SizeChanged); |
234 | this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form2_MouseUp); |
235 | this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form2_KeyUp); |
236 | this.Closed += new System.EventHandler(this.Form2_Closed); |
237 | this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form2_Paint); |
238 | this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form2_MouseMove); |
239 | } |
240 | #endregion |
241 | |
242 | private System.Windows.Forms.ImageList imageList1; |
243 | private System.Windows.Forms.ContextMenu myPopup; |
244 | private System.Windows.Forms.ContextMenu myPopupObject; |
245 | private System.Windows.Forms.MenuItem ContextWireframe; |
246 | private System.Windows.Forms.MenuItem ContextShading; |
247 | private System.Windows.Forms.MenuItem ContextColor; |
248 | private System.Windows.Forms.MenuItem ContextMaterial; |
249 | private System.Windows.Forms.MenuItem ContMatBrass; |
250 | private System.Windows.Forms.MenuItem ContMenBronze; |
251 | private System.Windows.Forms.MenuItem ContMenCopper; |
252 | private System.Windows.Forms.MenuItem ContMenGold; |
253 | private System.Windows.Forms.MenuItem ContMenPewt; |
254 | private System.Windows.Forms.MenuItem ContMenPlaster; |
255 | private System.Windows.Forms.MenuItem ContMenPlastic; |
256 | private System.Windows.Forms.MenuItem ContMenSilver; |
257 | private System.Windows.Forms.MenuItem ContMenTranc; |
258 | private System.Windows.Forms.MenuItem ContMenDelete; |
259 | private System.Windows.Forms.MenuItem menuItem1; |
260 | |
261 | private OCCTProxy myOCCTProxy; |
262 | private int myDocumentIndex, myViewIndex; |
263 | |
264 | public void InitV3D() |
265 | { |
266 | if (!myOCCTProxy.InitViewer(this.Handle)) |
267 | MessageBox.Show("Fatal Error during the graphic initialisation", "Error!", |
268 | MessageBoxButtons.OK, MessageBoxIcon.Error); |
269 | } |
270 | |
271 | public bool ImportBRep(System.String filename) |
272 | { |
273 | return myOCCTProxy.ImportBrep(filename); |
274 | } |
275 | |
276 | private void Form2_SizeChanged(object sender, System.EventArgs e) |
277 | { |
278 | myOCCTProxy.UpdateView(); |
279 | } |
280 | |
281 | private void Form2_Paint(object sender, System.Windows.Forms.PaintEventArgs e) |
282 | { |
283 | myOCCTProxy.RedrawView(); |
284 | myOCCTProxy.UpdateView(); |
285 | } |
286 | |
287 | protected CurrentAction3d myCurrentMode; |
288 | protected CurrentPressedKey myCurrentPressedKey; |
ee2be2a8 |
289 | protected float myCurZoom; |
d1a2fee8 |
290 | protected bool myDegenerateModeIsOn; |
291 | protected int myXmin; |
292 | protected int myYmin; |
293 | protected int myXmax; |
294 | protected int myYmax; |
295 | protected int theButtonDownX; |
296 | protected int theButtonDownY; |
297 | // for erasing of rectangle |
298 | protected int theRectDownX; |
299 | protected int theRectDownY; |
300 | protected bool IsRectVisible; |
301 | |
302 | private void Form2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) |
303 | { |
304 | switch (e.Button) |
305 | { |
306 | case MouseButtons.Left: |
307 | myXmin = e.X; myYmin = e.Y; |
308 | myXmax = e.X; myYmax = e.Y; |
309 | if (myCurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl) |
a110c4a3 |
310 | // start the dynamic zooming.... |
d1a2fee8 |
311 | myCurrentMode = CurrentAction3d.CurAction3d_DynamicZooming; |
312 | else |
313 | { |
314 | switch (myCurrentMode) |
315 | { |
316 | case CurrentAction3d.CurAction3d_Nothing: |
317 | if (myCurrentPressedKey == CurrentPressedKey.CurPressedKey_Shift) |
318 | MultiDragEvent(myXmax, myYmax, -1); |
319 | else |
320 | DragEvent(myXmax, myYmax, -1); |
321 | break; |
322 | case CurrentAction3d.CurAction3d_DynamicRotation: |
323 | if (!myDegenerateModeIsOn) |
324 | myOCCTProxy.SetDegenerateModeOn(); |
325 | //start the rotation |
326 | myOCCTProxy.StartRotation(e.X, e.Y); |
327 | break; |
328 | case IE_WinForms.CurrentAction3d.CurAction3d_WindowZooming: |
329 | this.Cursor = System.Windows.Forms.Cursors.Hand; |
330 | break; |
331 | default: |
332 | break; |
333 | } |
334 | } |
335 | break; |
336 | case MouseButtons.Right: |
337 | //MessageBox.Show("right mouse button is down"); |
338 | if (myCurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl) |
339 | { |
340 | if (!myDegenerateModeIsOn) |
341 | myOCCTProxy.SetDegenerateModeOn(); |
342 | myOCCTProxy.StartRotation(e.X, e.Y); |
343 | } |
344 | else |
345 | Popup(e.X, e.Y); |
346 | break; |
347 | default: |
348 | break; |
349 | } |
350 | } |
351 | |
352 | private void Form2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) |
353 | { |
354 | if (e.Shift) |
355 | myCurrentPressedKey = CurrentPressedKey.CurPressedKey_Shift; |
356 | else if (e.Control) |
357 | myCurrentPressedKey = CurrentPressedKey.CurPressedKey_Ctrl; |
358 | } |
359 | |
360 | private void Form2_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) |
361 | { |
362 | myCurrentPressedKey = CurrentPressedKey.CurPressedKey_Nothing; |
363 | } |
364 | |
365 | protected void MultiDragEvent(int x, int y, int theState) |
366 | { |
367 | if (theState == -1) |
368 | { |
369 | theButtonDownX = x; |
370 | theButtonDownY = y; |
371 | } |
372 | else if (theState == 1) |
373 | myOCCTProxy.ShiftSelect(Math.Min(theButtonDownX, x), Math.Min(theButtonDownY, y), |
374 | Math.Max(theButtonDownX, x), Math.Max(theButtonDownY, y)); |
375 | } |
376 | |
377 | protected void DragEvent(int x, int y, int theState) |
378 | { |
379 | if (theState == -1) //mouse is down |
380 | { |
381 | theButtonDownX = x; |
382 | theButtonDownY = y; |
383 | } |
384 | else if (theState == 1) //mouse is up |
385 | { |
386 | myOCCTProxy.Select(Math.Min(theButtonDownX, x), Math.Min(theButtonDownY, y), |
387 | Math.Max(theButtonDownX, x), Math.Max(theButtonDownY, y)); |
388 | } |
389 | } |
390 | |
391 | protected void Popup(int x, int y) |
392 | { |
393 | System.Drawing.Point p = new Point(x, y); |
394 | if (this.myOCCTProxy.IsObjectSelected()) |
395 | this.myPopupObject.Show(this, p); |
396 | else |
397 | this.myPopup.Show(this, p); |
398 | } |
399 | |
400 | private void Form2_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) |
401 | { |
402 | switch (e.Button) |
403 | { |
404 | case MouseButtons.Left: |
405 | if (myCurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl) |
406 | return; |
407 | switch (myCurrentMode) |
408 | { |
409 | case CurrentAction3d.CurAction3d_Nothing: |
410 | if (e.X == myXmin && e.Y == myYmin) |
411 | { |
412 | myXmax = e.X; myYmax = e.Y; |
413 | if (myCurrentPressedKey == CurrentPressedKey.CurPressedKey_Shift) |
414 | MultiInputEvent(myXmax, myYmax); |
415 | else |
416 | InputEvent(myXmax, myYmax); |
417 | } |
418 | else |
419 | { |
420 | myXmax = e.X; myYmax = e.Y; |
421 | DrawRectangle(false); |
422 | if (myCurrentPressedKey == CurrentPressedKey.CurPressedKey_Shift) |
423 | MultiDragEvent(myXmax, myYmax, 1); |
424 | else |
425 | DragEvent(myXmax, myYmax, 1); |
426 | } |
427 | break; |
428 | case CurrentAction3d.CurAction3d_DynamicZooming: |
429 | myCurrentMode = CurrentAction3d.CurAction3d_Nothing; |
430 | break; |
431 | case CurrentAction3d.CurAction3d_WindowZooming: |
432 | myXmax = e.X; myYmax = e.Y; |
433 | DrawRectangle(false); |
434 | int ValZWMin = 1; |
435 | if (Math.Abs(myXmax - myXmin) > ValZWMin && Math.Abs(myXmax - myYmax) > ValZWMin) |
436 | myOCCTProxy.WindowFitAll(myXmin, myYmin, myXmax, myYmax); |
437 | this.Cursor = System.Windows.Forms.Cursors.Default; |
438 | IE_WinForms.Form1 f = (IE_WinForms.Form1)this.ParentForm; |
439 | f.SelectionChanged(); |
440 | myCurrentMode = CurrentAction3d.CurAction3d_Nothing; |
441 | break; |
442 | case CurrentAction3d.CurAction3d_DynamicPanning: |
443 | myCurrentMode = CurrentAction3d.CurAction3d_Nothing; |
444 | break; |
445 | case CurrentAction3d.CurAction3d_GlobalPanning: |
446 | myOCCTProxy.Place(e.X, e.Y, myCurZoom); |
447 | myCurrentMode = CurrentAction3d.CurAction3d_Nothing; |
448 | break; |
449 | case CurrentAction3d.CurAction3d_DynamicRotation: |
450 | myCurrentMode = CurrentAction3d.CurAction3d_Nothing; |
451 | if (!myDegenerateModeIsOn) |
452 | { |
453 | myOCCTProxy.SetDegenerateModeOff(); |
454 | myDegenerateModeIsOn = false; |
455 | } |
456 | else |
457 | { |
458 | myOCCTProxy.SetDegenerateModeOn(); |
459 | myDegenerateModeIsOn = true; |
460 | } |
461 | break; |
462 | default: |
463 | break; |
464 | |
465 | } |
466 | break; |
467 | case MouseButtons.Right: |
468 | if (!myDegenerateModeIsOn) |
469 | { |
470 | myOCCTProxy.SetDegenerateModeOff(); |
471 | myDegenerateModeIsOn = false; |
472 | } |
473 | else |
474 | { |
475 | myOCCTProxy.SetDegenerateModeOn(); |
476 | myDegenerateModeIsOn = true; |
477 | } |
478 | break; |
479 | default: |
480 | break; |
481 | } |
482 | |
483 | IE_WinForms.Form1 parent = (IE_WinForms.Form1)this.ParentForm; |
484 | parent.SelectionChanged(); |
485 | } |
486 | |
487 | protected void MultiInputEvent(int x, int y) |
488 | { |
489 | myOCCTProxy.ShiftSelect(); |
490 | } |
491 | |
492 | protected void InputEvent(int x, int y) |
493 | { |
494 | myOCCTProxy.Select(); |
495 | } |
496 | |
497 | private void DrawRectangle(bool draw) |
498 | { |
499 | Graphics gr = Graphics.FromHwnd(this.Handle); |
500 | System.Drawing.Pen p = null; |
501 | if (this.IsRectVisible || (!draw))//erase the rect |
502 | { |
503 | int r = myOCCTProxy.GetBGColR(); |
504 | int g = myOCCTProxy.GetBGColG(); |
505 | int b = myOCCTProxy.GetBGColB(); |
506 | p = new Pen(System.Drawing.Color.FromArgb(r, g, b)); |
507 | this.IsRectVisible = false; |
508 | this.myOCCTProxy.UpdateView(); |
509 | } |
510 | else if (draw) |
511 | { |
512 | p = new Pen(System.Drawing.Color.White); |
513 | this.IsRectVisible = true; |
514 | } |
515 | if (p == null) |
516 | return; |
517 | int x = Math.Min(this.myXmin, this.myXmax); |
518 | int y = Math.Min(this.myYmin, this.myYmax); |
519 | gr.DrawRectangle(p, x, y, Math.Abs(myXmax - myXmin), Math.Abs(myYmax - myYmin)); |
520 | this.theRectDownX = Math.Max(this.myXmin, this.myXmax); |
521 | this.theRectDownY = Math.Max(this.myYmin, this.myYmax); |
522 | } |
523 | |
524 | private void Form2_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) |
525 | { |
526 | if (e.Button == MouseButtons.Left) //left button is pressed |
527 | { |
528 | if (myCurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl) |
529 | { |
530 | myOCCTProxy.Zoom(myXmax, myYmax, e.X, e.Y); |
531 | myXmax = e.X; myYmax = e.Y; |
532 | } |
533 | else |
534 | { |
535 | switch (myCurrentMode) |
536 | { |
537 | case CurrentAction3d.CurAction3d_Nothing: |
538 | DrawRectangle(false); |
539 | myXmax = e.X; myYmax = e.Y; |
540 | DrawRectangle(true); |
541 | break; |
542 | case CurrentAction3d.CurAction3d_DynamicZooming: |
543 | myOCCTProxy.Zoom(myXmax, myYmax, e.X, e.Y); |
544 | myXmax = e.X; myYmax = e.Y; |
545 | break; |
546 | case CurrentAction3d.CurAction3d_WindowZooming: |
547 | DrawRectangle(false); |
548 | myXmax = e.X; myYmax = e.Y; |
549 | DrawRectangle(true);//add brush here |
550 | break; |
551 | case CurrentAction3d.CurAction3d_DynamicPanning: |
552 | myOCCTProxy.Pan(e.X - myXmax, myYmax - e.Y); |
553 | myXmax = e.X; myYmax = e.Y; |
554 | break; |
555 | case CurrentAction3d.CurAction3d_GlobalPanning: |
556 | break; |
557 | case CurrentAction3d.CurAction3d_DynamicRotation: |
558 | myOCCTProxy.Rotation(e.X, e.Y); |
559 | myOCCTProxy.RedrawView(); |
560 | break; |
561 | default: |
562 | break; |
563 | } |
564 | } |
565 | } // e.Button == MouseButtons.Left |
566 | else if (e.Button == MouseButtons.Middle) |
567 | { |
568 | if (myCurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl) |
569 | { |
570 | myOCCTProxy.Pan(e.X - myXmax, myYmax - e.Y); |
571 | myXmax = e.X; myYmax = e.Y; |
572 | } |
573 | }//e.Button=MouseButtons.Middle |
574 | else if (e.Button == MouseButtons.Right) //right button is pressed |
575 | { |
576 | if (myCurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl) |
577 | myOCCTProxy.Rotation(e.X, e.Y); |
578 | } |
579 | else // no buttons are pressed |
580 | { |
581 | myXmax = e.X; myYmax = e.Y; |
582 | if (myCurrentPressedKey == CurrentPressedKey.CurPressedKey_Shift) |
583 | MultiMoveEvent(e.X, e.Y); |
584 | else |
585 | MoveEvent(e.X, e.Y); |
586 | } |
587 | |
588 | |
589 | } |
590 | |
591 | protected void MultiMoveEvent(int x, int y) |
592 | { |
593 | myOCCTProxy.MoveTo(x, y); |
594 | } |
595 | |
596 | protected void MoveEvent(int x, int y) |
597 | { |
598 | myOCCTProxy.MoveTo(x, y); |
599 | } |
600 | |
601 | public void SetDisplayMode(int aMode) |
602 | { |
603 | myOCCTProxy.SetDisplayMode(aMode); |
604 | } |
605 | |
606 | public void ChangeColor(bool IsObjectColor) |
607 | { |
608 | int r, g, b; |
609 | if (IsObjectColor) |
610 | { |
611 | r = myOCCTProxy.GetObjColR(); |
612 | g = myOCCTProxy.GetObjColG(); |
613 | b = myOCCTProxy.GetObjColB(); |
614 | } |
615 | else |
616 | { |
617 | r = myOCCTProxy.GetBGColR(); |
618 | g = myOCCTProxy.GetBGColG(); |
619 | b = myOCCTProxy.GetBGColB(); |
620 | } |
621 | System.Windows.Forms.ColorDialog ColDlg = new ColorDialog(); |
622 | ColDlg.Color = System.Drawing.Color.FromArgb(r, g, b); |
623 | if (ColDlg.ShowDialog() == DialogResult.OK) |
624 | { |
625 | Color c = ColDlg.Color; |
626 | r = c.R; |
627 | g = c.G; |
628 | b = c.B; |
629 | if (IsObjectColor) |
630 | myOCCTProxy.SetColor(r, g, b); |
631 | else |
632 | myOCCTProxy.SetBackgroundColor(r, g, b); |
633 | } |
634 | this.myOCCTProxy.UpdateCurrentViewer(); |
635 | |
636 | } |
637 | |
638 | public void DeleteObjects() |
639 | { |
640 | myOCCTProxy.EraseObjects(); |
4d6554d1 |
641 | IE_WinForms.Form1 parent = (IE_WinForms.Form1)this.ParentForm; |
642 | parent.SelectionChanged(); |
d1a2fee8 |
643 | } |
644 | public void ImportModel(IE_WinForms.ModelFormat format) |
645 | { |
646 | int theformat = 10; |
647 | System.Windows.Forms.OpenFileDialog openDialog = new OpenFileDialog(); |
648 | |
4b3541c6 |
649 | string DataDir = Environment.GetEnvironmentVariable("CSF_OCCTDataPath"); |
d1a2fee8 |
650 | |
651 | string filter = ""; |
652 | |
653 | switch (format) |
654 | { |
655 | case ModelFormat.BREP: |
656 | openDialog.InitialDirectory = (DataDir + "\\occ"); |
657 | theformat = 0; |
658 | filter = "BREP Files (*.brep *.rle)|*.brep; *.rle"; |
659 | break; |
d1a2fee8 |
660 | case IE_WinForms.ModelFormat.STEP: |
661 | openDialog.InitialDirectory = (DataDir + "\\step"); |
41f03605 |
662 | theformat = 1; |
d1a2fee8 |
663 | filter = "STEP Files (*.stp *.step)|*.stp; *.step"; |
664 | break; |
665 | case IE_WinForms.ModelFormat.IGES: |
666 | openDialog.InitialDirectory = (DataDir + "\\iges"); |
41f03605 |
667 | theformat = 2; |
d1a2fee8 |
668 | filter = "IGES Files (*.igs *.iges)|*.igs; *.iges"; |
669 | break; |
670 | default: |
671 | break; |
672 | } |
673 | openDialog.Filter = filter + "|All files (*.*)|*.*"; |
674 | if (openDialog.ShowDialog() == DialogResult.OK) |
675 | { |
676 | string filename = openDialog.FileName; |
677 | if (filename == "") |
678 | return; |
679 | this.Cursor = System.Windows.Forms.Cursors.WaitCursor; |
680 | if (!myOCCTProxy.TranslateModel(filename, theformat, true)) |
a110c4a3 |
681 | MessageBox.Show("Can't read this file", "Error!", |
d1a2fee8 |
682 | MessageBoxButtons.OK, MessageBoxIcon.Warning); |
683 | this.Cursor = System.Windows.Forms.Cursors.Default; |
684 | } |
685 | this.myOCCTProxy.ZoomAllView(); |
686 | } |
687 | |
688 | public void ExportModel(ModelFormat format) |
689 | { |
690 | int theformat = 10; |
691 | System.Windows.Forms.SaveFileDialog saveDialog = new SaveFileDialog(); |
4b3541c6 |
692 | string DataDir = Environment.GetEnvironmentVariable("CSF_OCCTDataPath"); |
d1a2fee8 |
693 | string filter = ""; |
694 | switch (format) |
695 | { |
696 | case IE_WinForms.ModelFormat.BREP: |
697 | saveDialog.InitialDirectory = (DataDir + "\\occ"); |
698 | theformat = 0; |
699 | filter = "BREP Files (*.brep *.rle)|*.brep; *.rle"; |
700 | break; |
d1a2fee8 |
701 | case IE_WinForms.ModelFormat.STEP: |
702 | saveDialog.InitialDirectory = (DataDir + "\\step"); |
41f03605 |
703 | theformat = 1; |
d1a2fee8 |
704 | filter = "STEP Files (*.stp *.step)|*.step; *.stp"; |
705 | break; |
706 | case IE_WinForms.ModelFormat.IGES: |
707 | saveDialog.InitialDirectory = (DataDir + "\\iges"); |
41f03605 |
708 | theformat = 2; |
d1a2fee8 |
709 | filter = "IGES Files (*.igs *.iges)| *.iges; *.igs"; |
710 | break; |
711 | case IE_WinForms.ModelFormat.VRML: |
712 | saveDialog.InitialDirectory = (DataDir + "\\vrml"); |
41f03605 |
713 | theformat = 3; |
d1a2fee8 |
714 | filter = "VRML Files (*.vrml)|*.vrml"; |
715 | break; |
716 | case IE_WinForms.ModelFormat.STL: |
717 | saveDialog.InitialDirectory = (DataDir + "\\stl"); |
41f03605 |
718 | theformat = 4; |
d1a2fee8 |
719 | filter = "STL Files (*.stl)|*.stl"; |
720 | break; |
721 | case IE_WinForms.ModelFormat.IMAGE: |
722 | saveDialog.InitialDirectory = (DataDir + "\\images"); |
41f03605 |
723 | theformat = 5; |
d1a2fee8 |
724 | filter = "Images Files (*.bmp *.gif)| *.bmp; *.gif"; |
725 | break; |
726 | default: |
727 | break; |
728 | } |
729 | saveDialog.Filter = filter; |
730 | if (saveDialog.ShowDialog() == DialogResult.OK) |
731 | { |
732 | string filename = saveDialog.FileName; |
733 | if (filename == "") |
734 | return; |
735 | this.Cursor = System.Windows.Forms.Cursors.WaitCursor; |
736 | if (!myOCCTProxy.TranslateModel(filename, theformat, false)) |
a110c4a3 |
737 | MessageBox.Show("Can't write this file", "Error!", |
d1a2fee8 |
738 | MessageBoxButtons.OK, MessageBoxIcon.Warning); |
739 | this.Cursor = System.Windows.Forms.Cursors.Default; |
740 | } |
741 | } |
742 | |
743 | private void ContextColor_Click(object sender, System.EventArgs e) |
744 | { |
745 | this.ChangeColor(true); |
746 | } |
747 | |
748 | private void menuItem1_Click(object sender, System.EventArgs e) |
749 | { |
750 | this.myOCCTProxy.UpdateCurrentViewer(); |
751 | this.ChangeColor(false); |
752 | } |
753 | |
754 | private void ContextWireframe_Click(object sender, System.EventArgs e) |
755 | { |
756 | this.SetDisplayMode(0); |
757 | this.myOCCTProxy.UpdateCurrentViewer(); |
758 | IE_WinForms.Form1 parent = (IE_WinForms.Form1)this.ParentForm; |
759 | parent.SelectionChanged(); |
760 | } |
761 | |
762 | private void ContextShading_Click(object sender, System.EventArgs e) |
763 | { |
764 | this.SetDisplayMode(1); |
765 | this.myOCCTProxy.UpdateCurrentViewer(); |
766 | IE_WinForms.Form1 parent = (IE_WinForms.Form1)this.ParentForm; |
767 | parent.SelectionChanged(); |
768 | } |
769 | |
770 | private void ContMenTranc_Click(object sender, System.EventArgs e) |
771 | { |
772 | IE_WinForms.TransparencyDialog dlg = new TransparencyDialog(); |
773 | dlg.View = this.myOCCTProxy; |
774 | dlg.ShowDialog(this); |
775 | } |
776 | |
777 | private void ContMenDelete_Click(object sender, System.EventArgs e) |
778 | { |
779 | this.DeleteObjects(); |
780 | } |
781 | |
782 | private void ContMatBrass_Click(object sender, System.EventArgs e) |
783 | { |
784 | this.myOCCTProxy.UpdateCurrentViewer(); |
785 | this.myOCCTProxy.SetMaterial(0); |
786 | } |
787 | |
788 | private void ContMenBronze_Click(object sender, System.EventArgs e) |
789 | { |
790 | this.myOCCTProxy.UpdateCurrentViewer(); |
791 | this.myOCCTProxy.SetMaterial(1); |
792 | } |
793 | |
794 | private void ContMenCopper_Click(object sender, System.EventArgs e) |
795 | { |
796 | this.myOCCTProxy.UpdateCurrentViewer(); |
797 | this.myOCCTProxy.SetMaterial(2); |
798 | } |
799 | |
800 | private void ContMenGold_Click(object sender, System.EventArgs e) |
801 | { |
802 | this.myOCCTProxy.UpdateCurrentViewer(); |
803 | this.myOCCTProxy.SetMaterial(3); |
804 | } |
805 | |
806 | private void ContMenPewt_Click(object sender, System.EventArgs e) |
807 | { |
808 | this.myOCCTProxy.UpdateCurrentViewer(); |
809 | this.myOCCTProxy.SetMaterial(4); |
810 | } |
811 | |
812 | private void ContMenPlaster_Click(object sender, System.EventArgs e) |
813 | { |
814 | this.myOCCTProxy.UpdateCurrentViewer(); |
815 | this.myOCCTProxy.SetMaterial(5); |
816 | } |
817 | |
818 | private void ContMenPlastic_Click(object sender, System.EventArgs e) |
819 | { |
820 | this.myOCCTProxy.UpdateCurrentViewer(); |
821 | this.myOCCTProxy.SetMaterial(6); |
822 | } |
823 | |
824 | private void ContMenSilver_Click(object sender, System.EventArgs e) |
825 | { |
826 | this.myOCCTProxy.UpdateCurrentViewer(); |
827 | this.myOCCTProxy.SetMaterial(7); |
828 | } |
829 | |
830 | private void toolBar1_MouseHover(object sender, System.EventArgs e) |
831 | { |
832 | IE_WinForms.Form1 parent = (IE_WinForms.Form1)this.ParentForm; |
833 | parent.StatusBar.Text = "View toolbar"; |
834 | |
835 | } |
836 | |
837 | private void toolBar1_MouseLeave(object sender, System.EventArgs e) |
838 | { |
839 | IE_WinForms.Form1 parent = (IE_WinForms.Form1)this.ParentForm; |
840 | parent.StatusBar.Text = ""; |
841 | } |
842 | |
843 | private void myPopupObject_Popup(object sender, System.EventArgs e) |
844 | { |
845 | int mode = this.myOCCTProxy.DisplayMode(); |
846 | switch (mode) |
847 | { |
848 | case -1: |
849 | break; |
850 | case 0: |
851 | this.ContextWireframe.Enabled = false; |
852 | this.ContextShading.Enabled = true; |
853 | this.ContMenTranc.Enabled = false; |
854 | break; |
855 | case 1: |
856 | this.ContextShading.Enabled = false; |
857 | this.ContextWireframe.Enabled = true; |
858 | this.ContMenTranc.Enabled = true; |
859 | break; |
860 | case 10: |
861 | this.ContextShading.Enabled = true; ; |
862 | this.ContextWireframe.Enabled = true; |
863 | this.ContMenTranc.Enabled = true; |
864 | break; |
865 | default: |
866 | break; |
867 | |
868 | } |
869 | } |
870 | |
871 | public OCCTProxy View |
872 | { |
873 | get |
874 | { |
875 | return this.myOCCTProxy; |
876 | } |
877 | set |
878 | { |
879 | this.myOCCTProxy = value; |
880 | } |
881 | } |
882 | |
883 | public void InitView() |
884 | { |
885 | this.myOCCTProxy.InitOCCTProxy(); |
886 | } |
887 | |
888 | public void SetIndex(int documentIndex, int viewIndex) |
889 | { |
890 | this.myDocumentIndex = documentIndex; |
891 | this.myViewIndex = viewIndex; |
892 | this.Text = System.String.Format("Document {0}:{1}", documentIndex, viewIndex); |
893 | } |
894 | |
895 | public void SetNextIndex(Form2 other) |
896 | { |
897 | SetIndex(other.myDocumentIndex, other.myViewIndex + 1); |
898 | } |
899 | |
900 | public void SetContext(OCCTProxy View) |
901 | { |
902 | this.myOCCTProxy.SetAISContext(View); |
903 | } |
904 | |
905 | private void Form2_Closed(object sender, System.EventArgs e) |
906 | { |
907 | IE_WinForms.Form1 parent = (IE_WinForms.Form1)this.ParentForm; |
908 | parent.OnFileClose(); |
909 | } |
910 | |
911 | public CurrentAction3d Mode |
912 | { |
913 | get |
914 | { |
915 | return this.myCurrentMode; |
916 | } |
917 | set |
918 | { |
919 | this.myCurrentMode = value; |
920 | } |
921 | } |
922 | |
923 | public float Zoom |
924 | { |
925 | set |
926 | { |
927 | this.myCurZoom = value; |
928 | } |
929 | } |
930 | |
931 | public bool DegenerateMode |
932 | { |
933 | get |
934 | { |
935 | return this.myDegenerateModeIsOn; |
936 | } |
937 | set |
938 | { |
939 | this.myDegenerateModeIsOn = value; |
940 | } |
941 | } |
942 | |
943 | } |
944 | |
945 | } |