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