Integration of OCCT 6.5.0 from SVN
[occt.git] / samples / CSharp / IE / Form2.cs
CommitLineData
7fd59977 1using System;
2using System.Drawing;
3using System.Collections;
4using System.ComponentModel;
5using System.Windows.Forms;
6
7
8namespace IE
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 // TODO: Add any constructor code after InitializeComponent call
51 //
52 myView = new shell();
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 }
242 #endregion
243
244 private System.Windows.Forms.ImageList imageList1;
245 private System.Windows.Forms.ContextMenu myPopup;
246 private System.Windows.Forms.ContextMenu myPopupObject;
247 private System.Windows.Forms.MenuItem ContextWireframe;
248 private System.Windows.Forms.MenuItem ContextShading;
249 private System.Windows.Forms.MenuItem ContextColor;
250 private System.Windows.Forms.MenuItem ContextMaterial;
251 private System.Windows.Forms.MenuItem ContMatBrass;
252 private System.Windows.Forms.MenuItem ContMenBronze;
253 private System.Windows.Forms.MenuItem ContMenCopper;
254 private System.Windows.Forms.MenuItem ContMenGold;
255 private System.Windows.Forms.MenuItem ContMenPewt;
256 private System.Windows.Forms.MenuItem ContMenPlaster;
257 private System.Windows.Forms.MenuItem ContMenPlastic;
258 private System.Windows.Forms.MenuItem ContMenSilver;
259 private System.Windows.Forms.MenuItem ContMenTranc;
260 private System.Windows.Forms.MenuItem ContMenDelete;
261 private System.Windows.Forms.MenuItem menuItem1;
262
263 private shell myView;
264
265 public void InitV3D()
266 {
267
268 if( !myView.InitViewer(this.Handle) )
269 MessageBox.Show("Fatal Error during the graphic initialisation", "Error!",
270 MessageBoxButtons.OK, MessageBoxIcon.Error);
271 }
272
273 public bool ImportBRep(System.String filename)
274 {
275 return myView.ImportBrep(filename);
276 }
277
278 private void Form2_SizeChanged(object sender, System.EventArgs e)
279 {
280 myView.UpdateView();
281 }
282
283 private void Form2_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
284 {
285 myView.RedrawView();
286 myView.UpdateView();
287 }
288
289 protected CurrentAction3d myCurrentMode;
290 protected CurrentPressedKey myCurrentPressedKey;
291 protected float myCurZoom;// ~ Quantity_Factor
292 protected bool myDegenerateModeIsOn;
293 protected int myXmin;
294 protected int myYmin;
295 protected int myXmax;
296 protected int myYmax;
297 protected int theButtonDownX;
298 protected int theButtonDownY;
299 // for erasing of rectangle
300 protected int theRectDownX;
301 protected int theRectDownY;
302 protected bool IsRectVisible;
303
304 private void Form2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
305 {
306 switch (e.Button)
307 {
308 case MouseButtons.Left:
309 myXmin=e.X; myYmin=e.Y;
310 myXmax=e.X; myYmax=e.Y;
311 if (myCurrentPressedKey==CurrentPressedKey.CurPressedKey_Ctrl)
312 // start the dinamic zooming....
313 myCurrentMode=CurrentAction3d.CurAction3d_DynamicZooming;
314 else
315 {
316 switch(myCurrentMode)
317 {
318 case CurrentAction3d.CurAction3d_Nothing:
319 if (myCurrentPressedKey==CurrentPressedKey.CurPressedKey_Shift)
320 MultiDragEvent(myXmax, myYmax, -1);
321 else
322 DragEvent(myXmax, myYmax, -1);
323 break;
324 case CurrentAction3d.CurAction3d_DynamicRotation:
325 if (!myDegenerateModeIsOn)
326 myView.SetDegenerateModeOn();
327 //start the rotation
328 myView.StartRotation(e.X, e.Y);
329 break;
330 case IE.CurrentAction3d.CurAction3d_WindowZooming:
331 this.Cursor=System.Windows.Forms.Cursors.Hand;
332 break;
333 default:
334 break;
335 }
336 }
337 break;
338 case MouseButtons.Right:
339 //MessageBox.Show("right mouse button is down");
340 if (myCurrentPressedKey==CurrentPressedKey.CurPressedKey_Ctrl)
341 {
342 if (!myDegenerateModeIsOn)
343 myView.SetDegenerateModeOn();
344 myView.StartRotation(e.X, e.Y);
345 }
346 else
347 Popup(e.X, e.Y);
348 break;
349 default:
350 break;
351 }
352
353 }
354
355 private void Form2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
356 {
357 if (e.Shift)
358 myCurrentPressedKey=CurrentPressedKey.CurPressedKey_Shift;
359 else if (e.Control)
360 myCurrentPressedKey=CurrentPressedKey.CurPressedKey_Ctrl;
361 }
362
363 private void Form2_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
364 {
365 myCurrentPressedKey=CurrentPressedKey.CurPressedKey_Nothing;
366 }
367
368 protected void MultiDragEvent(int x, int y, int theState)
369 {
370 if ( theState==-1)
371 {
372 theButtonDownX=x;
373 theButtonDownY=y;
374 }
375 else if (theState==1)
376 myView.ShiftSelect(Math.Min(theButtonDownX,x), Math.Min(theButtonDownY,y),
377 Math.Max(theButtonDownX, x), Math.Max(theButtonDownY, y));
378 }
379
380 protected void DragEvent(int x, int y, int theState)
381 {
382 if (theState==-1) //mouse is down
383 {
384 theButtonDownX=x;
385 theButtonDownY=y;
386 }
387 else if (theState==1) //mouse is up
388 {
389 myView.Select(Math.Min(theButtonDownX, x), Math.Min(theButtonDownY,y),
390 Math.Max(theButtonDownX, x), Math.Max(theButtonDownY,y));
391 }
392 }
393
394 protected void Popup(int x, int y)
395 {
396 System.Drawing.Point p = new Point(x,y);
397 if (this.myView.IsObjectSelected())
398 this.myPopupObject.Show(this, p);
399 else
400 this.myPopup.Show(this, p);
401 }
402
403 private void Form2_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
404 {
405 switch(e.Button)
406 {
407 case MouseButtons.Left:
408 if (myCurrentPressedKey==CurrentPressedKey.CurPressedKey_Ctrl)
409 return;
410 switch(myCurrentMode)
411 {
412 case CurrentAction3d.CurAction3d_Nothing:
413 if( e.X==myXmin && e.Y==myYmin)
414 {
415 myXmax=e.X; myYmax=e.Y;
416 if (myCurrentPressedKey==CurrentPressedKey.CurPressedKey_Shift)
417 MultiInputEvent(myXmax, myYmax);
418 else
419 InputEvent(myXmax, myYmax);
420 }
421 else
422 {
423 myXmax=e.X; myYmax=e.Y;
424 DrawRectangle(false);
425 if (myCurrentPressedKey==CurrentPressedKey.CurPressedKey_Shift)
426 MultiDragEvent(myXmax, myYmax, 1);
427 else
428 DragEvent(myXmax, myYmax, 1);
429 }
430 break;
431 case CurrentAction3d.CurAction3d_DynamicZooming:
432 myCurrentMode=CurrentAction3d.CurAction3d_Nothing;
433 break;
434 case CurrentAction3d.CurAction3d_WindowZooming:
435 myXmax=e.X; myYmax=e.Y;
436 DrawRectangle(false);
437 int ValZWMin = 1;
438 if (Math.Abs(myXmax-myXmin)>ValZWMin && Math.Abs(myXmax-myYmax)>ValZWMin)
439 myView.WindowFitAll(myXmin, myYmin, myXmax, myYmax);
440 this.Cursor=System.Windows.Forms.Cursors.Default;
441 IE.Form1 f = (IE.Form1)this.ParentForm;
442 f.SelectionChanged();
443 myCurrentMode=CurrentAction3d.CurAction3d_Nothing;
444 break;
445 case CurrentAction3d.CurAction3d_DynamicPanning:
446 myCurrentMode=CurrentAction3d.CurAction3d_Nothing;
447 break;
448 case CurrentAction3d.CurAction3d_GlobalPanning:
449 myView.Place(e.X, e.Y, myCurZoom);
450 myCurrentMode=CurrentAction3d.CurAction3d_Nothing;
451 break;
452 case CurrentAction3d.CurAction3d_DynamicRotation:
453 myCurrentMode=CurrentAction3d.CurAction3d_Nothing;
454 if (!myDegenerateModeIsOn)
455 {
456 myView.SetDegenerateModeOff();
457 myDegenerateModeIsOn=false;
458 }
459 else
460 {
461 myView.SetDegenerateModeOn();
462 myDegenerateModeIsOn=true;
463 }
464 break;
465 default:
466 break;
467
468 }
469 break;
470 case MouseButtons.Right:
471 if (!myDegenerateModeIsOn)
472 {
473 myView.SetDegenerateModeOff();
474 myDegenerateModeIsOn=false;
475 }
476 else
477 {
478 myView.SetDegenerateModeOn();
479 myDegenerateModeIsOn=true;
480 }
481 break;
482 default:
483 break;
484 }
485
486 IE.Form1 parent = (IE.Form1)this.ParentForm;
487 parent.SelectionChanged();
488 }
489
490 protected void MultiInputEvent(int x, int y)
491 {
492 myView.ShiftSelect();
493 }
494
495 protected void InputEvent(int x, int y)
496 {
497 myView.Select();
498 }
499
500 private void DrawRectangle(bool draw)
501 {
502 Graphics gr = Graphics.FromHwnd(this.Handle);
503 System.Drawing.Pen p = null;
504 if (this.IsRectVisible ||(!draw))//erase the rect
505 {
506 int r=myView.GetBGColR();
507 int g=myView.GetBGColG();
508 int b=myView.GetBGColB();
509 p = new Pen(System.Drawing.Color.FromArgb( r,g, b));
510 this.IsRectVisible=false;
511 this.myView.UpdateView();
512 }
513 else if (draw)
514 {
515 p = new Pen(System.Drawing.Color.White);
516 this.IsRectVisible=true;
517 }
518 if ( p == null )
519 return;
520 int x=Math.Min(this.myXmin, this.myXmax);
521 int y=Math.Min(this.myYmin, this.myYmax);
522 gr.DrawRectangle(p, x, y, Math.Abs(myXmax-myXmin), Math.Abs(myYmax - myYmin));
523 this.theRectDownX=Math.Max(this.myXmin, this.myXmax);
524 this.theRectDownY=Math.Max(this.myYmin, this.myYmax);
525 }
526
527 private void Form2_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
528 {
529 if (e.Button == MouseButtons.Left) //left button is pressed
530 {
531 if (myCurrentPressedKey==CurrentPressedKey.CurPressedKey_Ctrl)
532 {
533 myView.Zoom(myXmax, myYmax, e.X, e.Y);
534 myXmax=e.X; myYmax=e.Y;
535 }
536 else
537 {
538 switch (myCurrentMode)
539 {
540 case CurrentAction3d.CurAction3d_Nothing:
541 DrawRectangle(false);
542 myXmax=e.X; myYmax=e.Y;
543 DrawRectangle(true);
544 break;
545 case CurrentAction3d.CurAction3d_DynamicZooming:
546 myView.Zoom(myXmax, myYmax, e.X, e.Y);
547 myXmax=e.X; myYmax=e.Y;
548 break;
549 case CurrentAction3d.CurAction3d_WindowZooming:
550 DrawRectangle(false);
551 myXmax=e.X; myYmax=e.Y;
552 DrawRectangle(true);//add brush here
553 break;
554 case CurrentAction3d.CurAction3d_DynamicPanning:
555 myView.Pan(e.X-myXmax, myYmax - e.Y);
556 myXmax=e.X; myYmax=e.Y;
557 break;
558 case CurrentAction3d.CurAction3d_GlobalPanning:
559 break;
560 case CurrentAction3d.CurAction3d_DynamicRotation:
561 myView.Rotation(e.X, e.Y);
562 myView.RedrawView();
563 break;
564 default:
565 break;
566 }
567 }
568 } // e.Button == MouseButtons.Left
569 else if (e.Button==MouseButtons.Middle)
570 {
571 if (myCurrentPressedKey==CurrentPressedKey.CurPressedKey_Ctrl)
572 {
573 myView.Pan(e.X-myXmax, myYmax - e.Y);
574 myXmax=e.X; myYmax=e.Y;
575 }
576 }//e.Button=MouseButtons.Middle
577 else if (e.Button==MouseButtons.Right) //right button is pressed
578 {
579 if (myCurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl)
580 myView.Rotation(e.X, e.Y);
581 }
582 else // no buttons are pressed
583 {
584 myXmax=e.X; myYmax=e.Y;
585 if (myCurrentPressedKey==CurrentPressedKey.CurPressedKey_Shift)
586 MultiMoveEvent(e.X, e.Y);
587 else
588 MoveEvent(e.X, e.Y);
589 }
590
591
592 }
593
594 protected void MultiMoveEvent(int x, int y)
595 {
596 myView.MoveTo(x, y);
597 }
598
599 protected void MoveEvent(int x, int y)
600 {
601 myView.MoveTo(x, y);
602 }
603
604 public void SetDisplayMode(int aMode)
605 {
606 myView.SetDisplayMode(aMode);
607 }
608
609 public void ChangeColor(bool IsObjectColor)
610 {
611 int r, g, b;
612 if (IsObjectColor)
613 {
614 r=myView.GetObjColR();
615 g=myView.GetObjColG();
616 b=myView.GetObjColB();
617 }
618 else
619 {
620 r=myView.GetBGColR();
621 g=myView.GetBGColG();
622 b=myView.GetBGColB();
623 }
624 System.Windows.Forms.ColorDialog ColDlg = new ColorDialog();
625 ColDlg.Color=System.Drawing.Color.FromArgb(r, g, b);
626 if (ColDlg.ShowDialog() == DialogResult.OK)
627 {
628 Color c = ColDlg.Color;
629 r=c.R;
630 g=c.G;
631 b=c.B;
632 if (IsObjectColor)
633 myView.SetColor(r, g, b);
634 else
635 myView.SetBackgroundColor(r, g, b);
636 }
637 this.myView.UpdateCurrentViewer();
638
639 }
640
641 public void DeleteObjects()
642 {
643 myView.EraseObjects();
644 }
645 public void ImportModel(IE.ModelFormat format)
646 {
647 int theformat=10;
648 System.Windows.Forms.OpenFileDialog openDialog = new OpenFileDialog();
649
650 string DataDir=((Environment.GetEnvironmentVariable("CASROOT")) + "\\..\\data");
651
652 string filter="";
653
654 switch (format)
655 {
656 case ModelFormat.BREP:
657 openDialog.InitialDirectory = (DataDir + "\\occ");
658 theformat=0;
659 filter= "BREP Files (*.brep *.rle)|*.brep; *.rle";
660 break;
661 case ModelFormat.CSFDB:
662 theformat=1;
663 filter= "CSFDB Files (*.csfdb)|*.csfdb";
664 break;
665 case IE.ModelFormat.STEP:
666 openDialog.InitialDirectory = (DataDir + "\\step");
667 theformat=2;
668 filter="STEP Files (*.stp *.step)|*.stp; *.step";
669 break;
670 case IE.ModelFormat.IGES:
671 openDialog.InitialDirectory = (DataDir + "\\iges");
672 theformat=3;
673 filter="IGES Files (*.igs *.iges)|*.igs; *.iges";
674 break;
675 default:
676 break;
677 }
678 openDialog.Filter = filter+"|All files (*.*)|*.*" ;
679 if(openDialog.ShowDialog() == DialogResult.OK)
680 {
681 string filename = openDialog.FileName;
682 if ( filename=="")
683 return;
684 this.Cursor=System.Windows.Forms.Cursors.WaitCursor;
685 if (!myView.TranslateModel(filename, theformat, true))
686 MessageBox.Show("Cann't read this file", "Error!",
687 MessageBoxButtons.OK, MessageBoxIcon.Warning);
688 this.Cursor=System.Windows.Forms.Cursors.Default;
689 }
690 this.myView.ZoomAllView();
691 }
692
693 public void ExportModel(ModelFormat format)
694 {
695 int theformat=10;
696 System.Windows.Forms.SaveFileDialog saveDialog = new SaveFileDialog();
697 string DataDir=((Environment.GetEnvironmentVariable("CASROOT")) + "\\..\\data");
698 string filter="";
699 switch (format)
700 {
701 case IE.ModelFormat.BREP:
702 saveDialog.InitialDirectory = (DataDir + "\\occ");
703 theformat=0;
704 filter= "BREP Files (*.brep *.rle)|*.brep; *.rle";
705 break;
706 case IE.ModelFormat.CSFDB:
707 theformat=1;
708 filter= "CSFDB Files (*.csfdb)|*.csfdb";
709 break;
710 case IE.ModelFormat.STEP:
711 saveDialog.InitialDirectory = (DataDir + "\\step");
712 theformat=2;
713 filter="STEP Files (*.stp *.step)|*.step; *.stp";
714 break;
715 case IE.ModelFormat.IGES:
716 saveDialog.InitialDirectory = (DataDir + "\\iges");
717 theformat=3;
718 filter="IGES Files (*.igs *.iges)| *.iges; *.igs";
719 break;
720 case IE.ModelFormat.VRML:
721 saveDialog.InitialDirectory = (DataDir + "\\vrml");
722 theformat=4;
723 filter="VRML Files (*.vrml)|*.vrml";
724 break;
725 case IE.ModelFormat.STL:
726 saveDialog.InitialDirectory = (DataDir + "\\stl");
727 theformat=5;
728 filter="STL Files (*.stl)|*.stl";
729 break;
730 case IE.ModelFormat.IMAGE:
731 saveDialog.InitialDirectory = (DataDir + "\\images");
732 theformat=6;
733 filter="Images Files (*.bmp *.gif *.xwd)| *.bmp; *.gif; *.xwd";
734 break;
735 default:
736 break;
737 }
738 saveDialog.Filter = filter;
739 if(saveDialog.ShowDialog() == DialogResult.OK)
740 {
741 string filename = saveDialog.FileName;
742 if ( filename=="")
743 return;
744 this.Cursor=System.Windows.Forms.Cursors.WaitCursor;
745 if (!myView.TranslateModel(filename, theformat, false))
746 MessageBox.Show("Cann't write this file", "Error!",
747 MessageBoxButtons.OK, MessageBoxIcon.Warning);
748 this.Cursor=System.Windows.Forms.Cursors.Default;
749 }
750 }
751
752 private void ContextColor_Click(object sender, System.EventArgs e)
753 {
754 this.ChangeColor(true);
755 }
756
757 private void menuItem1_Click(object sender, System.EventArgs e)
758 {
759 this.myView.UpdateCurrentViewer();
760 this.ChangeColor(false);
761 }
762
763 private void ContextWireframe_Click(object sender, System.EventArgs e)
764 {
765 this.SetDisplayMode(0);
766 this.myView.UpdateCurrentViewer();
767 IE.Form1 parent=(IE.Form1)this.ParentForm;
768 parent.SelectionChanged();
769 }
770
771 private void ContextShading_Click(object sender, System.EventArgs e)
772 {
773 this.SetDisplayMode(1);
774 this.myView.UpdateCurrentViewer();
775 IE.Form1 parent=(IE.Form1)this.ParentForm;
776 parent.SelectionChanged();
777 }
778
779 private void ContMenTranc_Click(object sender, System.EventArgs e)
780 {
781 IE.TransparencyDialog dlg = new TransparencyDialog();
782 dlg.View=this.myView;
783 dlg.ShowDialog(this);
784 }
785
786 private void ContMenDelete_Click(object sender, System.EventArgs e)
787 {
788 this.DeleteObjects();
789 }
790
791 private void ContMatBrass_Click(object sender, System.EventArgs e)
792 {
793 this.myView.UpdateCurrentViewer();
794 this.myView.SetMaterial(0);
795 }
796
797 private void ContMenBronze_Click(object sender, System.EventArgs e)
798 {
799 this.myView.UpdateCurrentViewer();
800 this.myView.SetMaterial(1);
801 }
802
803 private void ContMenCopper_Click(object sender, System.EventArgs e)
804 {
805 this.myView.UpdateCurrentViewer();
806 this.myView.SetMaterial(2);
807 }
808
809 private void ContMenGold_Click(object sender, System.EventArgs e)
810 {
811 this.myView.UpdateCurrentViewer();
812 this.myView.SetMaterial(3);
813 }
814
815 private void ContMenPewt_Click(object sender, System.EventArgs e)
816 {
817 this.myView.UpdateCurrentViewer();
818 this.myView.SetMaterial(4);
819 }
820
821 private void ContMenPlaster_Click(object sender, System.EventArgs e)
822 {
823 this.myView.UpdateCurrentViewer();
824 this.myView.SetMaterial(5);
825 }
826
827 private void ContMenPlastic_Click(object sender, System.EventArgs e)
828 {
829 this.myView.UpdateCurrentViewer();
830 this.myView.SetMaterial(6);
831 }
832
833 private void ContMenSilver_Click(object sender, System.EventArgs e)
834 {
835 this.myView.UpdateCurrentViewer();
836 this.myView.SetMaterial(7);
837 }
838
839 private void toolBar1_MouseHover(object sender, System.EventArgs e)
840 {
841 IE.Form1 parent=(IE.Form1)this.ParentForm;
842 parent.StatusBar.Text="View toolbar";
843
844 }
845
846 private void toolBar1_MouseLeave(object sender, System.EventArgs e)
847 {
848 IE.Form1 parent=(IE.Form1)this.ParentForm;
849 parent.StatusBar.Text="";
850 }
851
852 private void myPopupObject_Popup(object sender, System.EventArgs e)
853 {
854 int mode=this.myView.DisplayMode();
855 switch (mode)
856 {
857 case -1:
858 break;
859 case 0:
860 this.ContextWireframe.Enabled=false;
861 this.ContextShading.Enabled=true;
862 this.ContMenTranc.Enabled=false;
863 break;
864 case 1:
865 this.ContextShading.Enabled=false;
866 this.ContextWireframe.Enabled=true;
867 this.ContMenTranc.Enabled=true;
868 break;
869 case 10:
870 this.ContextShading.Enabled=true;;
871 this.ContextWireframe.Enabled=true;
872 this.ContMenTranc.Enabled=true;
873 break;
874 default:
875 break;
876
877 }
878 }
879
880 public shell View
881 {
882 get
883 {
884 return this.myView;
885 }
886 set
887 {
888 this.myView=value;
889 }
890 }
891
892 public void InitView()
893 {
894 this.myView.InitOCCViewer();
895 }
896
897 public void SetContext(shell View)
898 {
899 this.myView.SetAISContext(View);
900 }
901
902 private void Form2_Closed(object sender, System.EventArgs e)
903 {
904 IE.Form1 parent = (IE.Form1) this.ParentForm;
905 parent.OnFileClose();
906 }
907
908 public CurrentAction3d Mode
909 {
910 get
911 {
912 return this.myCurrentMode;
913 }
914 set
915 {
916 this.myCurrentMode=value;
917 }
918 }
919
920 public float Zoom
921 {
922 set
923 {
924 this.myCurZoom=value;
925 }
926 }
927
928 public bool DegenerateMode
929 {
930 get
931 {
932 return this.myDegenerateModeIsOn;
933 }
934 set
935 {
936 this.myDegenerateModeIsOn=value;
937 }
938 }
939
940 }
941
942}