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