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