Sync res/resource.h from src/resource.h
[occt.git] / samples / CSharp / WPF_WinForms / OCCViewer.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows.Forms;
6
7 namespace IE_WPF_WinForms
8 {
9     public enum CurrentAction3d
10     {
11         CurAction3d_Nothing,
12         CurAction3d_DynamicZooming,
13         CurAction3d_WindowZooming,
14         CurAction3d_DynamicPanning,
15         CurAction3d_GlobalPanning,
16         CurAction3d_DynamicRotation
17     }
18     public enum CurrentPressedKey
19     {
20         CurPressedKey_Nothing,
21         CurPressedKey_Ctrl,
22         CurPressedKey_Shift
23     }
24     public enum ModelFormat
25     {
26         BREP,
27         CSFDB,
28         STEP,
29         IGES,
30         VRML,
31         STL,
32         IMAGE
33     }
34
35     public enum DisplayMode
36     {
37         Wireframe,
38         Shading
39     }
40
41     public class OCCViewer : System.Windows.Forms.Form
42     {
43         public event EventHandler ZoomingFinished;
44         protected void RaiseZoomingFinished()
45         {
46             if ( ZoomingFinished != null )
47             {
48                 ZoomingFinished( this, EventArgs.Empty );
49             }
50         }
51
52         public event EventHandler AvaliabiltyOfOperationsChanged;
53         protected void RaiseAvaliabiltyOfOperationsChanged()
54         {
55             if ( AvaliabiltyOfOperationsChanged != null )
56             {
57                 AvaliabiltyOfOperationsChanged( this, EventArgs.Empty );
58             }
59         }
60
61         public OCCTProxy View { get; private set; }
62         public CurrentAction3d CurrentMode { get; private set; }
63         private CurrentPressedKey CurrentPressedKey { get; set; }
64         private bool IsRectVisible { get; set; }
65         public bool DegenerateMode { get; private set; }
66
67         public bool IsWireframeEnabled { get; private set; }
68         public bool IsShadingEnabled { get; private set; }
69         public bool IsTransparencyEnabled { get; private set; }
70         public bool IsColorEnabled { get; private set; }
71         public bool IsMaterialEnabled { get; private set; }
72         public bool IsDeleteEnabled { get; private set; }
73
74         private float myCurZoom;// ~ Quantity_Factor
75         private int myXmin;
76         private int myYmin;
77         private int myXmax;
78         private int myYmax;
79         private int myRectDownX;
80         private int myRectDownY;
81         private int myButtonDownX;
82         private int myButtonDownY;
83
84         private ContextMenu Popup { get; set; }
85         private MenuItem ContextWireframe;
86         private MenuItem ContextShading;
87         private MenuItem ContextColor;
88         private MenuItem ContextMaterial;
89         private MenuItem ContextDelete;
90         private MenuItem ContextBackground;
91         private MenuItem ContextTransparency;
92
93
94         public OCCViewer()
95         {
96             InitializeComponent();
97
98             View = new OCCTProxy();
99             View.InitOCCTProxy();
100             if ( !View.InitViewer( this.Handle ) )
101             {
102                 MessageBox.Show( "Fatal Error during the graphic initialisation", "Error!" );
103             }
104
105             CurrentMode = CurrentAction3d.CurAction3d_Nothing;
106             CurrentPressedKey = CurrentPressedKey.CurPressedKey_Nothing;
107             IsRectVisible = false;
108             DegenerateMode = true;
109         }
110
111         private void InitializeComponent()
112         {
113             ControlBox = false;
114             TopLevel = false;
115
116             this.ImeMode = System.Windows.Forms.ImeMode.NoControl;
117
118             SizeChanged += new System.EventHandler( OnSizeChanged );
119             Paint += new System.Windows.Forms.PaintEventHandler( OnPaint );
120
121             MouseDown += new System.Windows.Forms.MouseEventHandler( OnMouseDown );
122             MouseUp += new System.Windows.Forms.MouseEventHandler( OnMouseUp );
123             MouseMove += new System.Windows.Forms.MouseEventHandler( OnMouseMove );
124
125             Popup = new ContextMenu();
126             ContextWireframe = new MenuItem();
127             ContextShading = new MenuItem();
128             ContextColor = new MenuItem();
129             ContextMaterial = new MenuItem();
130             ContextTransparency = new MenuItem();
131             ContextDelete = new MenuItem();
132             ContextBackground = new MenuItem();
133
134             ContextWireframe.Text = "Wireframe";
135             ContextShading.Text = "Shading";
136             ContextColor.Text = "Color";
137             ContextMaterial.Text = "Material";
138             ContextTransparency.Text = "Transparency";
139             ContextDelete.Text = "Delete";
140             ContextBackground.Text = "Background";
141
142             ContextWireframe.Click += new System.EventHandler( ContextWireframe_Click );
143             ContextShading.Click += new System.EventHandler( ContextShading_Click );
144             ContextColor.Click += new System.EventHandler( ContextColor_Click );
145             ContextMaterial.Click += new System.EventHandler( ContextMaterial_Click );
146             ContextTransparency.Click += new System.EventHandler( ContextTransparency_Click );
147             ContextDelete.Click += new System.EventHandler( ContextDelete_Click );
148             ContextBackground.Click += new System.EventHandler( ContextBackground_Click );
149
150             Popup.MenuItems.AddRange( new MenuItem[] { ContextWireframe,
151                                                            ContextShading,
152                                                            ContextColor,
153                                                            ContextMaterial,
154                                                            ContextTransparency,
155                                                            ContextDelete,
156                                                        ContextBackground } );
157             Popup.Popup += new System.EventHandler( OnPopup );
158         }
159
160         private void OnPaint(object sender, System.Windows.Forms.PaintEventArgs e)
161         {
162             View.RedrawView();
163             View.UpdateView();
164         }
165
166         private void OnSizeChanged(object sender, System.EventArgs e)
167         {
168             View.UpdateView();
169         }
170
171         public void ImportModel( ModelFormat theFormat )
172         {
173             int aFormat = 10;
174             OpenFileDialog anOpenDialog = new OpenFileDialog();
175             string aDataDir = ( (Environment.GetEnvironmentVariable("CASROOT")) + "\\..\\data" );
176             string aFilter = "";
177
178             switch ( theFormat )
179             {
180                 case ModelFormat.BREP:
181                     anOpenDialog.InitialDirectory = (aDataDir + "\\occ");
182                     aFormat = 0;
183                     aFilter = "BREP Files (*.brep *.rle)|*.brep; *.rle";
184                     break;
185                 case ModelFormat.CSFDB:
186                     aFormat = 1;
187                     aFilter = "CSFDB Files (*.csfdb)|*.csfdb";
188                     break;
189                 case ModelFormat.STEP:
190                     anOpenDialog.InitialDirectory = (aDataDir + "\\step");
191                     aFormat = 2;
192                     aFilter = "STEP Files (*.stp *.step)|*.stp; *.step";
193                     break;
194                 case ModelFormat.IGES:
195                     anOpenDialog.InitialDirectory = (aDataDir + "\\iges");
196                     aFormat = 3;
197                     aFilter = "IGES Files (*.igs *.iges)|*.igs; *.iges";
198                     break;
199                 default:
200                     break;
201             }
202
203             anOpenDialog.Filter = aFilter + "|All files (*.*)|*.*";
204             if (anOpenDialog.ShowDialog() == DialogResult.OK)
205             {
206                 string aFileName = anOpenDialog.FileName;
207                 if (aFileName == "")
208                 {
209                     return;
210                 }
211
212                 Cursor = System.Windows.Forms.Cursors.WaitCursor;
213                 if ( !View.TranslateModel( aFileName, aFormat, true ) )
214                 {
215                     MessageBox.Show( "Cann't read this file", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning );
216                 }
217                 Cursor = System.Windows.Forms.Cursors.Default;
218             }
219             View.ZoomAllView();
220         }
221
222         public void ExportModel( ModelFormat theFormat )
223         {
224             int aFormat = 10;
225             SaveFileDialog saveDialog = new SaveFileDialog();
226             string aDataDir = ( (Environment.GetEnvironmentVariable("CASROOT") ) + "\\..\\data" );
227             string aFilter = "";
228
229             switch ( theFormat )
230             {
231                 case ModelFormat.BREP:
232                     saveDialog.InitialDirectory = ( aDataDir + "\\occ" );
233                     aFormat = 0;
234                     aFilter = "BREP Files (*.brep *.rle)|*.brep; *.rle";
235                     break;
236                 case ModelFormat.CSFDB:
237                     aFormat = 1;
238                     aFilter = "CSFDB Files (*.csfdb)|*.csfdb";
239                     break;
240                 case ModelFormat.STEP:
241                     saveDialog.InitialDirectory = ( aDataDir + "\\step" );
242                     aFormat = 2;
243                     aFilter = "STEP Files (*.stp *.step)|*.step; *.stp";
244                     break;
245                 case ModelFormat.IGES:
246                     saveDialog.InitialDirectory = ( aDataDir + "\\iges" );
247                     aFormat = 3;
248                     aFilter = "IGES Files (*.igs *.iges)| *.iges; *.igs";
249                     break;
250                 case ModelFormat.VRML:
251                     saveDialog.InitialDirectory = ( aDataDir + "\\vrml" );
252                     aFormat = 4;
253                     aFilter = "VRML Files (*.vrml)|*.vrml";
254                     break;
255                 case ModelFormat.STL:
256                     saveDialog.InitialDirectory = ( aDataDir + "\\stl" );
257                     aFormat = 5;
258                     aFilter = "STL Files (*.stl)|*.stl";
259                     break;
260                 case ModelFormat.IMAGE:
261                     saveDialog.InitialDirectory = ( aDataDir + "\\images" );
262                     aFormat = 6;
263                     aFilter = "Images Files (*.bmp)|*.bmp";
264                     break;
265                 default:
266                     break;
267             }
268
269             saveDialog.Filter = aFilter;
270             if ( saveDialog.ShowDialog() == DialogResult.OK )
271             {
272                 string aFileName = saveDialog.FileName;
273                 if ( aFileName == "" )
274                 {
275                     return;
276                 }
277
278                 Cursor = System.Windows.Forms.Cursors.WaitCursor;
279                 if ( !View.TranslateModel( aFileName, aFormat, false ) )
280                 {
281                     MessageBox.Show( "Can not write this file", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning );
282                 }
283                 Cursor = System.Windows.Forms.Cursors.Default;
284             }
285         }
286
287         public void FitAll()
288         {
289             View.ZoomAllView();
290         }
291
292         public void ZoomWindow()
293         {
294             CurrentMode = CurrentAction3d.CurAction3d_WindowZooming;
295         }
296
297         public void DynamicZooming()
298         {
299             CurrentMode = CurrentAction3d.CurAction3d_DynamicZooming;
300         }
301
302         public void DynamicPanning()
303         {
304             CurrentMode = CurrentAction3d.CurAction3d_DynamicPanning;
305         }
306
307         public void GlobalPanning()
308         {
309             myCurZoom = View.Scale();
310             CurrentMode = CurrentAction3d.CurAction3d_GlobalPanning;
311         }
312
313         public void AxoView()
314         {
315             View.AxoView();
316         }
317
318         public void FrontView()
319         {
320             View.FrontView();
321         }
322
323         public void TopView()
324         {
325             View.TopView();
326         }
327
328         public void LeftView()
329         {
330             View.LeftView();
331         }
332
333         public void BackView()
334         {
335             View.BackView();
336         }
337
338         public void RightView()
339         {
340             View.RightView();
341         }
342
343         public void Reset()
344         {
345             View.Reset();
346         }
347
348         public void BottomView()
349         {
350             View.BottomView();
351         }
352
353         public void HiddenOff()
354         {
355             View.SetDegenerateModeOff();
356             DegenerateMode = false;
357         }
358
359         public void HiddenOn()
360         {
361             View.SetDegenerateModeOn();
362             DegenerateMode = true;
363         }
364
365         public void DynamicRotation()
366         {
367             CurrentMode = CurrentAction3d.CurAction3d_DynamicRotation;
368         }
369
370         public void SelectionChanged()
371         {
372             switch ( View.DisplayMode() )
373             {
374                 case -1:
375                     IsShadingEnabled = false;
376                     IsWireframeEnabled = false;
377                     break;
378                 case 0:
379                     IsWireframeEnabled = false;
380                     IsShadingEnabled = true;
381                     IsTransparencyEnabled = false;
382                     break;
383                 case 1:
384                     IsWireframeEnabled = true;
385                     IsShadingEnabled = false;
386                     IsTransparencyEnabled = true;
387                     break;
388                 case 10:
389                     IsWireframeEnabled = true;
390                     IsShadingEnabled = true;
391                     IsTransparencyEnabled = true;
392                     break;
393                 default:
394                     break;
395             }
396
397             if ( View.IsObjectSelected() )
398             {
399                 IsColorEnabled = true;
400                 IsMaterialEnabled = true;
401                 IsDeleteEnabled = true;
402             }
403             else
404             {
405                 IsColorEnabled = false;
406                 IsMaterialEnabled = false;
407                 IsTransparencyEnabled = false;
408                 IsDeleteEnabled = false;
409             }
410
411             RaiseAvaliabiltyOfOperationsChanged();
412         }
413
414         public void ChangeColor( bool IsObjectColor )
415         {
416             int r, g, b;
417             if ( IsObjectColor )
418             {
419                 r = View.GetObjColR();
420                 g = View.GetObjColG();
421                 b = View.GetObjColB();
422             }
423             else
424             {
425                 r = View.GetBGColR();
426                 g = View.GetBGColG();
427                 b = View.GetBGColB();
428             }
429             System.Windows.Forms.ColorDialog ColDlg = new System.Windows.Forms.ColorDialog();
430             ColDlg.Color = System.Drawing.Color.FromArgb( r, g, b );
431             if ( ColDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK )
432             {
433                 System.Drawing.Color c = ColDlg.Color;
434                 r = c.R;
435                 g = c.G;
436                 b = c.B;
437                 if ( IsObjectColor )
438                 {
439                     View.SetColor( r, g, b );
440                 }
441                 else
442                 {
443                     View.SetBackgroundColor( r, g, b );
444                 }
445             }
446             View.UpdateCurrentViewer();
447         }
448
449         public void Wireframe()
450         {
451             View.SetDisplayMode( (int)DisplayMode.Wireframe );
452             View.UpdateCurrentViewer();
453
454             SelectionChanged();
455             RaiseZoomingFinished();
456         }
457
458         public void Shading()
459         {
460             View.SetDisplayMode( (int)DisplayMode.Shading );
461             View.UpdateCurrentViewer();
462
463             SelectionChanged();
464             RaiseZoomingFinished();
465         }
466
467         public void Color()
468         {
469             ChangeColor( true );
470         }
471
472         public void Background()
473         {
474             ChangeColor( false );
475         }
476
477         public void Material()
478         {
479             MaterialDlg aDlg = new MaterialDlg( View );
480             aDlg.ShowDialog();
481         }
482
483         public void Transparency()
484         {
485             TransparencyDialog dlg = new TransparencyDialog();
486             dlg.View = View;
487             dlg.ShowDialog( this );
488         }
489
490         public void Delete()
491         {
492             View.EraseObjects();
493         }
494
495         public void OnKeyDown( System.Windows.Input.Key theKey )
496         {
497             if ( theKey == System.Windows.Input.Key.LeftShift ||
498                  theKey == System.Windows.Input.Key.RightShift )
499             {
500                 CurrentPressedKey = CurrentPressedKey.CurPressedKey_Shift;
501             }
502             else if (theKey == System.Windows.Input.Key.LeftCtrl ||
503                      theKey == System.Windows.Input.Key.RightCtrl )
504             {
505                 CurrentPressedKey = CurrentPressedKey.CurPressedKey_Ctrl;
506             }
507         }
508
509         public void OnKeyUp()
510         {
511             CurrentPressedKey = CurrentPressedKey.CurPressedKey_Nothing;
512         }
513
514         protected void MultiDragEvent( int x, int y, int theState )
515         {
516             if ( theState == -1 ) //mouse is down
517             {
518                 myButtonDownX = x;
519                 myButtonDownY = y;
520             }
521             else if ( theState ==  1) //mouse is up
522             {
523                 View.ShiftSelect( Math.Min( myButtonDownX, x ), Math.Min( myButtonDownY, y ),
524                                   Math.Max( myButtonDownX, x ), Math.Max( myButtonDownY, y ) );
525             }
526         }
527
528         protected void DragEvent( int x, int y, int theState )
529         {
530             if ( theState == -1 ) //mouse is down
531             {
532                 myButtonDownX = x;
533                 myButtonDownY = y;
534             }
535             else if ( theState == 1 ) //mouse is up
536             {
537                 View.Select( Math.Min( myButtonDownX, x ), Math.Min( myButtonDownY, y ),
538                              Math.Max( myButtonDownX, x ), Math.Max( myButtonDownY, y ) );
539             }
540         }
541
542         private void DrawRectangle( bool draw )
543         {
544             System.Drawing.Graphics gr = System.Drawing.Graphics.FromHwnd(Handle);
545             System.Drawing.Pen p = null;
546             if ( IsRectVisible || !draw )//erase the rect
547             {
548                 int r = View.GetBGColR();
549                 int g = View.GetBGColG();
550                 int b = View.GetBGColB();
551                 p = new System.Drawing.Pen( System.Drawing.Color.FromArgb(r, g, b) );
552                 IsRectVisible = false;
553                 View.UpdateView();
554             }
555             else if ( draw )
556             {
557                 p = new System.Drawing.Pen( System.Drawing.Color.White );
558                 IsRectVisible = true;
559             }
560             if ( p == null )
561             {
562                 return;
563             }
564             int x = Math.Min( myXmin, myXmax );
565             int y = Math.Min( myYmin, myYmax );
566             gr.DrawRectangle( p, x, y, Math.Abs(myXmax - myXmin), Math.Abs(myYmax - myYmin) );
567             myRectDownX = Math.Max( myXmin, myXmax );
568             myRectDownY = Math.Max( myYmin, myYmax );
569         }
570
571         private void OnMouseDown( object sender, System.Windows.Forms.MouseEventArgs e )
572         {
573             if ( e.Button == MouseButtons.Left )
574             {
575                 myXmin = e.X;
576                 myXmax = e.X;
577                 myYmin = e.Y;
578                 myYmax = e.Y;
579                 if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl )
580                 {
581                     // start the dinamic zooming....
582                     CurrentMode = CurrentAction3d.CurAction3d_DynamicZooming;
583                 }
584                 else
585                 {
586                     switch ( CurrentMode )
587                     {
588                         case CurrentAction3d.CurAction3d_Nothing:
589                             if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Shift )
590                             {
591                                 MultiDragEvent( myXmax, myYmax, -1 );
592                             }
593                             else
594                             {
595                                 DragEvent( myXmax, myYmax, -1 );
596                             }
597                             break;
598                         case CurrentAction3d.CurAction3d_DynamicRotation:
599                             if ( !DegenerateMode )
600                             {
601                                 View.SetDegenerateModeOn();
602                             }
603                             View.StartRotation( e.X, e.Y );
604                             break;
605                         case CurrentAction3d.CurAction3d_WindowZooming:
606                             Cursor = Cursors.Hand;
607                             break;
608                         default:
609                             break;
610                     }
611                 }
612             }
613             else if ( e.Button == MouseButtons.Right )
614             {
615                 if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl )
616                 {
617                     if ( !DegenerateMode )
618                     {
619                         View.SetDegenerateModeOn();
620                     }
621                     View.StartRotation( e.X, e.Y );
622                 }
623                 else
624                 {
625                     Popup.Show( this, new System.Drawing.Point( e.X, e.Y ) );
626                 }
627             }
628         }
629
630         private void OnMouseUp( object sender, System.Windows.Forms.MouseEventArgs e ) 
631         {
632             if ( e.Button == MouseButtons.Left )
633             {
634                 if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl )
635                 {
636                     return;
637                 }
638                 switch ( CurrentMode )
639                 {
640                     case CurrentAction3d.CurAction3d_Nothing:
641                         if ( e.X == myXmin && e.Y == myYmin )
642                         {
643                             myXmax = e.X;
644                             myYmax = e.Y;
645                             if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Shift )
646                             {
647                                 View.ShiftSelect();
648                             }
649                             else
650                             {
651                                 View.Select();
652                             }
653                         }
654                         else
655                         {
656                             myXmax = e.X;
657                             myYmax = e.Y;
658                             DrawRectangle( false );
659                             if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Shift )
660                             {
661                                 MultiDragEvent( myXmax, myYmax, 1 );
662                             }
663                             else
664                             {
665                                 DragEvent( myXmax, myYmax, 1 );
666                             }
667                         }
668                         break;
669                     case CurrentAction3d.CurAction3d_DynamicZooming:
670                         CurrentMode = CurrentAction3d.CurAction3d_Nothing;
671                         break;
672                     case CurrentAction3d.CurAction3d_WindowZooming:
673                         myXmax = e.X;
674                         myYmax = e.Y;
675                         DrawRectangle( false );
676                         int ValZWMin = 1;
677                         if ( Math.Abs(myXmax - myXmin) > ValZWMin && 
678                              Math.Abs(myXmax - myYmax) > ValZWMin )
679                         {
680                             View.WindowFitAll( myXmin, myYmin, myXmax, myYmax );
681                         }
682                         Cursor = Cursors.Arrow;
683                         RaiseZoomingFinished();
684                         CurrentMode = CurrentAction3d.CurAction3d_Nothing;
685                         break;
686                     case CurrentAction3d.CurAction3d_DynamicPanning:
687                         CurrentMode = CurrentAction3d.CurAction3d_Nothing;
688                         break;
689                     case CurrentAction3d.CurAction3d_GlobalPanning:
690                         View.Place( e.X, e.Y, myCurZoom );
691                         CurrentMode = CurrentAction3d.CurAction3d_Nothing;
692                         break;
693                     case CurrentAction3d.CurAction3d_DynamicRotation:
694                         CurrentMode = CurrentAction3d.CurAction3d_Nothing;
695                         if ( !DegenerateMode )
696                         {
697                             View.SetDegenerateModeOff();
698                         }
699                         else
700                         {
701                             View.SetDegenerateModeOn();
702                         }
703                         break;
704                     default:
705                         break;
706                 }
707             }
708             else if ( e.Button == MouseButtons.Right )
709             {
710                 if ( !DegenerateMode )
711                 {
712                     View.SetDegenerateModeOff();
713                 }
714                 else
715                 {
716                     View.SetDegenerateModeOn();
717                 }
718             }
719
720             SelectionChanged();
721         }
722
723         private void OnMouseMove( object sender, System.Windows.Forms.MouseEventArgs e )
724         {
725             if ( e.Button == MouseButtons.Left ) //left button is pressed
726             {
727                 if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl )
728                 {
729                     View.Zoom(myXmax, myYmax, e.X, e.Y);
730                     myXmax = e.X;
731                     myYmax = e.Y;
732                 }
733                 else
734                 {
735                     switch ( CurrentMode )
736                     {
737                         case CurrentAction3d.CurAction3d_Nothing:
738                             DrawRectangle( false );
739                             myXmax = e.X;
740                             myYmax = e.Y;
741                             DrawRectangle( true );
742                             break;
743                         case CurrentAction3d.CurAction3d_DynamicZooming:
744                             View.Zoom( myXmax, myYmax, e.X, e.Y );
745                             myXmax = e.X;
746                             myYmax = e.Y;
747                             break;
748                         case CurrentAction3d.CurAction3d_WindowZooming:
749                             DrawRectangle( false );
750                             myXmax = e.X;
751                             myYmax = e.Y;
752                             DrawRectangle( true );//add brush here
753                             break;
754                         case CurrentAction3d.CurAction3d_DynamicPanning:
755                             View.Pan( e.X - myXmax, myYmax - e.Y );
756                             myXmax = e.X;
757                             myYmax = e.Y;
758                             break;
759                         case CurrentAction3d.CurAction3d_GlobalPanning:
760                             break;
761                         case CurrentAction3d.CurAction3d_DynamicRotation:
762                             View.Rotation( e.X, e.Y );
763                             View.RedrawView();
764                             break;
765                         default:
766                             break;
767                     }
768                 }
769             }
770             else if ( e.Button == MouseButtons.Middle ) //middle button is pressed
771             {
772                 if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl )
773                 {
774                     View.Pan( e.X - myXmax, myYmax - e.Y );
775                     myXmax = e.X;
776                     myYmax = e.Y;
777                 }
778             }
779             else if ( e.Button == MouseButtons.Right ) //right button is pressed
780             {
781                 if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl) 
782                 {
783                     View.Rotation( e.X, e.Y );
784                 }
785             }
786             else // no buttons are pressed
787             {
788                 myXmax = e.X;
789                 myYmax = e.Y;
790                 View.MoveTo( e.X, e.Y );
791             }
792         }
793
794         private void OnPopup( object sender, System.EventArgs e )
795         {
796             ContextWireframe.Enabled = IsWireframeEnabled;
797             ContextShading.Enabled = IsShadingEnabled;
798             ContextColor.Enabled = IsColorEnabled;
799             ContextMaterial.Enabled = IsMaterialEnabled;
800             ContextDelete.Enabled = IsDeleteEnabled;
801             ContextTransparency.Enabled = IsTransparencyEnabled;
802             ContextBackground.Enabled = true;
803         }
804
805         private void ContextWireframe_Click( object sender, System.EventArgs e )
806         {
807             Wireframe();
808         }
809
810         private void ContextShading_Click( object sender, System.EventArgs e )
811         {
812             Shading();
813         }
814
815         private void ContextColor_Click( object sender, System.EventArgs e )
816         {
817             Color();
818         }
819
820         private void ContextMaterial_Click( object sender, System.EventArgs e )
821         {
822             Material();
823         }
824
825         private void ContextTransparency_Click( object sender, System.EventArgs e )
826         {
827             Transparency();
828         }
829
830         private void ContextDelete_Click( object sender, System.EventArgs e )
831         {
832             Delete();
833         }
834
835         private void ContextBackground_Click( object sender, System.EventArgs e )
836         {
837             Background();
838         }
839     }
840 }