d1a2fee8 |
1 | using System; |
2 | using System.Collections.Generic; |
3 | using System.Linq; |
4 | using System.Text; |
5 | using System.Windows.Forms; |
6 | |
15534713 |
7 | namespace IE_WPF_WinForms |
d1a2fee8 |
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, |
d1a2fee8 |
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 | |
ee2be2a8 |
73 | private float myCurZoom; |
d1a2fee8 |
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(); |
4b3541c6 |
174 | string aDataDir = Environment.GetEnvironmentVariable("CSF_OCCTDataPath"); |
d1a2fee8 |
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; |
d1a2fee8 |
184 | case ModelFormat.STEP: |
185 | anOpenDialog.InitialDirectory = (aDataDir + "\\step"); |
41f03605 |
186 | aFormat = 1; |
d1a2fee8 |
187 | aFilter = "STEP Files (*.stp *.step)|*.stp; *.step"; |
188 | break; |
189 | case ModelFormat.IGES: |
190 | anOpenDialog.InitialDirectory = (aDataDir + "\\iges"); |
41f03605 |
191 | aFormat = 2; |
d1a2fee8 |
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 | { |
a110c4a3 |
210 | MessageBox.Show( "Can't read this file", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning ); |
d1a2fee8 |
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(); |
4b3541c6 |
221 | string aDataDir = Environment.GetEnvironmentVariable("CSF_OCCTDataPath"); |
d1a2fee8 |
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; |
d1a2fee8 |
231 | case ModelFormat.STEP: |
232 | saveDialog.InitialDirectory = ( aDataDir + "\\step" ); |
41f03605 |
233 | aFormat = 1; |
d1a2fee8 |
234 | aFilter = "STEP Files (*.stp *.step)|*.step; *.stp"; |
235 | break; |
236 | case ModelFormat.IGES: |
237 | saveDialog.InitialDirectory = ( aDataDir + "\\iges" ); |
41f03605 |
238 | aFormat = 2; |
d1a2fee8 |
239 | aFilter = "IGES Files (*.igs *.iges)| *.iges; *.igs"; |
240 | break; |
241 | case ModelFormat.VRML: |
242 | saveDialog.InitialDirectory = ( aDataDir + "\\vrml" ); |
41f03605 |
243 | aFormat = 3; |
d1a2fee8 |
244 | aFilter = "VRML Files (*.vrml)|*.vrml"; |
245 | break; |
246 | case ModelFormat.STL: |
247 | saveDialog.InitialDirectory = ( aDataDir + "\\stl" ); |
41f03605 |
248 | aFormat = 4; |
d1a2fee8 |
249 | aFilter = "STL Files (*.stl)|*.stl"; |
250 | break; |
251 | case ModelFormat.IMAGE: |
252 | saveDialog.InitialDirectory = ( aDataDir + "\\images" ); |
41f03605 |
253 | aFormat = 5; |
d1a2fee8 |
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(); |
4d6554d1 |
484 | SelectionChanged(); |
d1a2fee8 |
485 | } |
486 | |
487 | public void OnKeyDown( System.Windows.Input.Key theKey ) |
488 | { |
489 | if ( theKey == System.Windows.Input.Key.LeftShift || |
490 | theKey == System.Windows.Input.Key.RightShift ) |
491 | { |
492 | CurrentPressedKey = CurrentPressedKey.CurPressedKey_Shift; |
493 | } |
494 | else if (theKey == System.Windows.Input.Key.LeftCtrl || |
495 | theKey == System.Windows.Input.Key.RightCtrl ) |
496 | { |
497 | CurrentPressedKey = CurrentPressedKey.CurPressedKey_Ctrl; |
498 | } |
499 | } |
500 | |
501 | public void OnKeyUp() |
502 | { |
503 | CurrentPressedKey = CurrentPressedKey.CurPressedKey_Nothing; |
504 | } |
505 | |
506 | protected void MultiDragEvent( int x, int y, int theState ) |
507 | { |
508 | if ( theState == -1 ) //mouse is down |
509 | { |
510 | myButtonDownX = x; |
511 | myButtonDownY = y; |
512 | } |
513 | else if ( theState == 1) //mouse is up |
514 | { |
515 | View.ShiftSelect( Math.Min( myButtonDownX, x ), Math.Min( myButtonDownY, y ), |
516 | Math.Max( myButtonDownX, x ), Math.Max( myButtonDownY, y ) ); |
517 | } |
518 | } |
519 | |
520 | protected void DragEvent( int x, int y, int theState ) |
521 | { |
522 | if ( theState == -1 ) //mouse is down |
523 | { |
524 | myButtonDownX = x; |
525 | myButtonDownY = y; |
526 | } |
527 | else if ( theState == 1 ) //mouse is up |
528 | { |
529 | View.Select( Math.Min( myButtonDownX, x ), Math.Min( myButtonDownY, y ), |
530 | Math.Max( myButtonDownX, x ), Math.Max( myButtonDownY, y ) ); |
531 | } |
532 | } |
533 | |
534 | private void DrawRectangle( bool draw ) |
535 | { |
536 | System.Drawing.Graphics gr = System.Drawing.Graphics.FromHwnd(Handle); |
537 | System.Drawing.Pen p = null; |
538 | if ( IsRectVisible || !draw )//erase the rect |
539 | { |
540 | int r = View.GetBGColR(); |
541 | int g = View.GetBGColG(); |
542 | int b = View.GetBGColB(); |
543 | p = new System.Drawing.Pen( System.Drawing.Color.FromArgb(r, g, b) ); |
544 | IsRectVisible = false; |
545 | View.UpdateView(); |
546 | } |
547 | else if ( draw ) |
548 | { |
549 | p = new System.Drawing.Pen( System.Drawing.Color.White ); |
550 | IsRectVisible = true; |
551 | } |
552 | if ( p == null ) |
553 | { |
554 | return; |
555 | } |
556 | int x = Math.Min( myXmin, myXmax ); |
557 | int y = Math.Min( myYmin, myYmax ); |
558 | gr.DrawRectangle( p, x, y, Math.Abs(myXmax - myXmin), Math.Abs(myYmax - myYmin) ); |
559 | myRectDownX = Math.Max( myXmin, myXmax ); |
560 | myRectDownY = Math.Max( myYmin, myYmax ); |
561 | } |
562 | |
563 | private void OnMouseDown( object sender, System.Windows.Forms.MouseEventArgs e ) |
564 | { |
565 | if ( e.Button == MouseButtons.Left ) |
566 | { |
567 | myXmin = e.X; |
568 | myXmax = e.X; |
569 | myYmin = e.Y; |
570 | myYmax = e.Y; |
571 | if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl ) |
572 | { |
a110c4a3 |
573 | // start the dynamic zooming.... |
d1a2fee8 |
574 | CurrentMode = CurrentAction3d.CurAction3d_DynamicZooming; |
575 | } |
576 | else |
577 | { |
578 | switch ( CurrentMode ) |
579 | { |
580 | case CurrentAction3d.CurAction3d_Nothing: |
581 | if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Shift ) |
582 | { |
583 | MultiDragEvent( myXmax, myYmax, -1 ); |
584 | } |
585 | else |
586 | { |
587 | DragEvent( myXmax, myYmax, -1 ); |
588 | } |
589 | break; |
590 | case CurrentAction3d.CurAction3d_DynamicRotation: |
591 | if ( !DegenerateMode ) |
592 | { |
593 | View.SetDegenerateModeOn(); |
594 | } |
595 | View.StartRotation( e.X, e.Y ); |
596 | break; |
597 | case CurrentAction3d.CurAction3d_WindowZooming: |
598 | Cursor = Cursors.Hand; |
599 | break; |
600 | default: |
601 | break; |
602 | } |
603 | } |
604 | } |
605 | else if ( e.Button == MouseButtons.Right ) |
606 | { |
607 | if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl ) |
608 | { |
609 | if ( !DegenerateMode ) |
610 | { |
611 | View.SetDegenerateModeOn(); |
612 | } |
613 | View.StartRotation( e.X, e.Y ); |
614 | } |
615 | else |
616 | { |
617 | Popup.Show( this, new System.Drawing.Point( e.X, e.Y ) ); |
618 | } |
619 | } |
620 | } |
621 | |
622 | private void OnMouseUp( object sender, System.Windows.Forms.MouseEventArgs e ) |
623 | { |
624 | if ( e.Button == MouseButtons.Left ) |
625 | { |
626 | if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl ) |
627 | { |
628 | return; |
629 | } |
630 | switch ( CurrentMode ) |
631 | { |
632 | case CurrentAction3d.CurAction3d_Nothing: |
633 | if ( e.X == myXmin && e.Y == myYmin ) |
634 | { |
635 | myXmax = e.X; |
636 | myYmax = e.Y; |
637 | if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Shift ) |
638 | { |
639 | View.ShiftSelect(); |
640 | } |
641 | else |
642 | { |
643 | View.Select(); |
644 | } |
645 | } |
646 | else |
647 | { |
648 | myXmax = e.X; |
649 | myYmax = e.Y; |
650 | DrawRectangle( false ); |
651 | if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Shift ) |
652 | { |
653 | MultiDragEvent( myXmax, myYmax, 1 ); |
654 | } |
655 | else |
656 | { |
657 | DragEvent( myXmax, myYmax, 1 ); |
658 | } |
659 | } |
660 | break; |
661 | case CurrentAction3d.CurAction3d_DynamicZooming: |
662 | CurrentMode = CurrentAction3d.CurAction3d_Nothing; |
663 | break; |
664 | case CurrentAction3d.CurAction3d_WindowZooming: |
665 | myXmax = e.X; |
666 | myYmax = e.Y; |
667 | DrawRectangle( false ); |
668 | int ValZWMin = 1; |
669 | if ( Math.Abs(myXmax - myXmin) > ValZWMin && |
670 | Math.Abs(myXmax - myYmax) > ValZWMin ) |
671 | { |
672 | View.WindowFitAll( myXmin, myYmin, myXmax, myYmax ); |
673 | } |
674 | Cursor = Cursors.Arrow; |
675 | RaiseZoomingFinished(); |
676 | CurrentMode = CurrentAction3d.CurAction3d_Nothing; |
677 | break; |
678 | case CurrentAction3d.CurAction3d_DynamicPanning: |
679 | CurrentMode = CurrentAction3d.CurAction3d_Nothing; |
680 | break; |
681 | case CurrentAction3d.CurAction3d_GlobalPanning: |
682 | View.Place( e.X, e.Y, myCurZoom ); |
683 | CurrentMode = CurrentAction3d.CurAction3d_Nothing; |
684 | break; |
685 | case CurrentAction3d.CurAction3d_DynamicRotation: |
686 | CurrentMode = CurrentAction3d.CurAction3d_Nothing; |
687 | if ( !DegenerateMode ) |
688 | { |
689 | View.SetDegenerateModeOff(); |
690 | } |
691 | else |
692 | { |
693 | View.SetDegenerateModeOn(); |
694 | } |
695 | break; |
696 | default: |
697 | break; |
698 | } |
699 | } |
700 | else if ( e.Button == MouseButtons.Right ) |
701 | { |
702 | if ( !DegenerateMode ) |
703 | { |
704 | View.SetDegenerateModeOff(); |
705 | } |
706 | else |
707 | { |
708 | View.SetDegenerateModeOn(); |
709 | } |
710 | } |
711 | |
712 | SelectionChanged(); |
713 | } |
714 | |
715 | private void OnMouseMove( object sender, System.Windows.Forms.MouseEventArgs e ) |
716 | { |
717 | if ( e.Button == MouseButtons.Left ) //left button is pressed |
718 | { |
719 | if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl ) |
720 | { |
721 | View.Zoom(myXmax, myYmax, e.X, e.Y); |
722 | myXmax = e.X; |
723 | myYmax = e.Y; |
724 | } |
725 | else |
726 | { |
727 | switch ( CurrentMode ) |
728 | { |
729 | case CurrentAction3d.CurAction3d_Nothing: |
730 | DrawRectangle( false ); |
731 | myXmax = e.X; |
732 | myYmax = e.Y; |
733 | DrawRectangle( true ); |
734 | break; |
735 | case CurrentAction3d.CurAction3d_DynamicZooming: |
736 | View.Zoom( myXmax, myYmax, e.X, e.Y ); |
737 | myXmax = e.X; |
738 | myYmax = e.Y; |
739 | break; |
740 | case CurrentAction3d.CurAction3d_WindowZooming: |
741 | DrawRectangle( false ); |
742 | myXmax = e.X; |
743 | myYmax = e.Y; |
744 | DrawRectangle( true );//add brush here |
745 | break; |
746 | case CurrentAction3d.CurAction3d_DynamicPanning: |
747 | View.Pan( e.X - myXmax, myYmax - e.Y ); |
748 | myXmax = e.X; |
749 | myYmax = e.Y; |
750 | break; |
751 | case CurrentAction3d.CurAction3d_GlobalPanning: |
752 | break; |
753 | case CurrentAction3d.CurAction3d_DynamicRotation: |
754 | View.Rotation( e.X, e.Y ); |
755 | View.RedrawView(); |
756 | break; |
757 | default: |
758 | break; |
759 | } |
760 | } |
761 | } |
762 | else if ( e.Button == MouseButtons.Middle ) //middle button is pressed |
763 | { |
764 | if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl ) |
765 | { |
766 | View.Pan( e.X - myXmax, myYmax - e.Y ); |
767 | myXmax = e.X; |
768 | myYmax = e.Y; |
769 | } |
770 | } |
771 | else if ( e.Button == MouseButtons.Right ) //right button is pressed |
772 | { |
773 | if ( CurrentPressedKey == CurrentPressedKey.CurPressedKey_Ctrl) |
774 | { |
775 | View.Rotation( e.X, e.Y ); |
776 | } |
777 | } |
778 | else // no buttons are pressed |
779 | { |
780 | myXmax = e.X; |
781 | myYmax = e.Y; |
782 | View.MoveTo( e.X, e.Y ); |
783 | } |
784 | } |
785 | |
786 | private void OnPopup( object sender, System.EventArgs e ) |
787 | { |
788 | ContextWireframe.Enabled = IsWireframeEnabled; |
789 | ContextShading.Enabled = IsShadingEnabled; |
790 | ContextColor.Enabled = IsColorEnabled; |
791 | ContextMaterial.Enabled = IsMaterialEnabled; |
792 | ContextDelete.Enabled = IsDeleteEnabled; |
793 | ContextTransparency.Enabled = IsTransparencyEnabled; |
794 | ContextBackground.Enabled = true; |
795 | } |
796 | |
797 | private void ContextWireframe_Click( object sender, System.EventArgs e ) |
798 | { |
799 | Wireframe(); |
800 | } |
801 | |
802 | private void ContextShading_Click( object sender, System.EventArgs e ) |
803 | { |
804 | Shading(); |
805 | } |
806 | |
807 | private void ContextColor_Click( object sender, System.EventArgs e ) |
808 | { |
809 | Color(); |
810 | } |
811 | |
812 | private void ContextMaterial_Click( object sender, System.EventArgs e ) |
813 | { |
814 | Material(); |
815 | } |
816 | |
817 | private void ContextTransparency_Click( object sender, System.EventArgs e ) |
818 | { |
819 | Transparency(); |
820 | } |
821 | |
822 | private void ContextDelete_Click( object sender, System.EventArgs e ) |
823 | { |
824 | Delete(); |
825 | } |
826 | |
827 | private void ContextBackground_Click( object sender, System.EventArgs e ) |
828 | { |
829 | Background(); |
830 | } |
831 | } |
832 | } |