home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / tcadapp.cs < prev    next >
Encoding:
Text File  |  2004-07-15  |  7.8 KB  |  325 lines

  1. //******************************************************************'
  2. //*                                                                *'
  3. //*                      TurboCAD for Windows                      *'
  4. //*                   Copyright (c) 1993 - 2004                    *'
  5. //*             International Microcomputer Software, Inc.         *'
  6. //*                            (IMSI)                              *'
  7. //*                      All rights reserved.                      *'
  8. //*                                                                *'
  9. //******************************************************************'
  10.  
  11. using System;
  12. using System.Windows.Forms;
  13. using System.Drawing;
  14. using IMSIGX;
  15. using GXMPSLib;
  16. namespace TCADClientTest
  17. {
  18.     /// <summary>
  19.     /// Summary description for TCADApp.
  20.     /// </summary>
  21.     public struct DPoint 
  22.     {
  23.         public double x, y;
  24.  
  25.         public DPoint(double p1, double p2) 
  26.         {
  27.             x = p1;
  28.             y = p2;    
  29.         }
  30.     }
  31.     public struct DRect 
  32.     {
  33.         public double Left, Top, Heigth, Width;
  34.  
  35.         public DRect(double p1, double p2, double p3, double p4) 
  36.         {
  37.             Left = p1;
  38.             Top = p2;
  39.             Heigth = p3;
  40.             Width = p4;
  41.         }
  42.     }
  43.  
  44.     public class TCADApp
  45.     {
  46.         public TCADApp()
  47.         {
  48.             //
  49.             // TODO: Add constructor logic here
  50.             //
  51.         }
  52.  
  53.         public IMSIGX.XApplication  gxApp = null;
  54.         public IMSIGX.XDrawing gxDrawing = null;
  55.         public IMSIGX.View   gxView = null;
  56.  
  57.         public bool InitTCApp()
  58.         {
  59.             gxApp = new IMSIGX.XApplication ();
  60.             return true;
  61.         }
  62.  
  63.         public void AddView(int hWnd)
  64.         {
  65.             object missing = null;
  66.             object h;
  67.             h = hWnd;
  68.             gxView = gxDrawing.Views.Add ( ref h, ref missing);
  69.             gxView.Update = false;
  70.             gxView.MappingMode = 1;
  71.             gxView.FixedAspectRatio = true;
  72.         }
  73.         public void OpenDrawing()
  74.         {
  75.             object missing = null;
  76.             string sFileName = "";
  77.             if (gxDrawing != null)
  78.             {
  79.                 gxDrawing.Close (ref missing, ref missing, ref missing);
  80.                 gxDrawing = null;
  81.                 if (gxView != null)
  82.                 {
  83.                     gxView.Delete ();
  84.                     gxView = null;
  85.                 }
  86.             }
  87.             sFileName = gxApp.GetOpenFilename (ref missing, ref missing, ref missing, ref missing);
  88.             gxDrawing = (IMSIGX.XDrawing) gxApp.Drawings.Open (sFileName, ref missing, ref missing);
  89. //            frmMain.ActiveForm.Text = Form1.ActiveForm.Text + sFileName;
  90.             
  91.         }
  92.  
  93.         public void OpenDrawing(System.Windows.Forms.TabControl    tctrl)
  94.         {
  95.             TabPage tabPage1;
  96.  
  97.             object missing = null;
  98.             string sFileName = "";
  99.             string sName = "";
  100.             string sNameActive = "";
  101.             int i, n;
  102.             i = n = 0;
  103.             
  104.             if (gxDrawing != null)
  105.             {
  106.                 gxDrawing.Close (ref missing, ref missing, ref missing);
  107.                 gxDrawing = null;
  108.                 if (gxView != null)
  109.                 {
  110.                     gxView.Delete ();
  111.                     gxView = null;
  112.                 }
  113.             }
  114.             tctrl.TabPages.Clear ();
  115.             sFileName = null;
  116.             sFileName = gxApp.GetOpenFilename (ref missing, ref missing, ref missing, ref missing);
  117.             if (sFileName == null)
  118.             {
  119.                 return;
  120.             }
  121.             gxDrawing = (IMSIGX.XDrawing) gxApp.Drawings.Open (sFileName, ref missing, ref missing);
  122.             GXMPSLib.PaperSpaces pPss = null;
  123.             GXMPSLib.PaperSpace pPs = null;
  124.             pPss = (GXMPSLib.PaperSpaces) gxDrawing.PaperSpaces;
  125.             n = pPss.Count;
  126.             System.Collections.IEnumerator pN;
  127.             
  128.             sName = "Model" ;
  129.             tabPage1 = new TabPage(sName);
  130.             tctrl.TabPages.Add (tabPage1);
  131.             pN = pPss.GetEnumerator ();
  132.             pN.MoveNext() ;
  133.             for (i = 0; i < n ; i++)
  134.             {
  135.                 pPs = (GXMPSLib.PaperSpace)pN.Current;
  136.                 sName = pPs.Name ;
  137.                 tabPage1 = new TabPage(sName);
  138.                 tctrl.TabPages.Add (tabPage1);
  139.                 if (pPs.Active == true)
  140.                 {
  141.                     sNameActive = sName;
  142.                     tabPage1.Select ();
  143.                 }
  144.                 pN.MoveNext() ;
  145.             }
  146.             pN = tctrl.TabPages.GetEnumerator ();
  147.             pN.Reset ();
  148.             pN.MoveNext() ;
  149.             n = tctrl.TabPages.Count;
  150.  
  151.             for (i = 0; i < n ; i++)
  152.             {
  153.                 tabPage1 = (TabPage)pN.Current;
  154.                 if (sNameActive == tabPage1.Text )
  155.                 {
  156.                     tctrl.SelectedTab = tabPage1;
  157.                     break;
  158.                 }
  159.                 pN.MoveNext() ;
  160.             }
  161.  
  162.             this.AddView ((int)tabPage1.Handle );
  163.     
  164.         }
  165.         public void SetView(IMSIGX.View pView, int iViewType)
  166.         {
  167.             double dxPos, dyPos, dzPos, dxLook, dyLook, dzLook, dxUp, dyUp, dzUp;
  168.             IMSIGX.XCamera pCam = null;
  169.             IMSIGX.XVertex pvPos, pvLook, pvUp;
  170.  
  171.             dxPos = 0;    dyPos = 0;    dzPos = 1;
  172.             dxLook = 0;    dyLook = 0;    dzLook = 0;
  173.             dxUp = 0;    dyUp = 1;    dzUp = 0;
  174.             
  175.             switch (iViewType)
  176.             {
  177.                     
  178.                 case 0://TC_VPLAN:
  179.                     dxPos = 0;    dyPos = 0;    dzPos = 1;
  180.                     dxLook = 0;    dyLook = 0;    dzLook = 0;
  181.                     dxUp = 0;    dyUp = 1;    dzUp = 0;
  182.                     break;
  183.                 case 1://TC_VLEFT:
  184.                     dxPos = -1;    dyPos = 0;    dzPos = 0;
  185.                     dxLook = 0;    dyLook = 0;    dzLook = 0;
  186.                     dxUp = 0;    dyUp = 0;    dzUp = 1;
  187.                     break;
  188.                 case 2://TC_VRIGHT:
  189.                     dxPos = 1;    dyPos = 0;    dzPos = 0;
  190.                     dxLook = 0;    dyLook = 0;    dzLook = 0;
  191.                     dxUp = 0;    dyUp = 0;    dzUp = 1;
  192.                     break;
  193.                 case 3://TC_VFRONT:
  194.                     dxPos = 0;    dyPos = -1;    dzPos = 0;
  195.                     dxLook = 0;    dyLook = 0;    dzLook = 0;
  196.                     dxUp = 0;    dyUp = 0;    dzUp = 1;
  197.                     break;
  198.                 case 4://TC_VBOTTOM:
  199.                     dxPos = 0;    dyPos = 0;    dzPos = 1;
  200.                     dxLook = 0;    dyLook = 0;    dzLook = 0;
  201.                     dxUp = 0;    dyUp = -1;    dzUp = 0;
  202.                     break;
  203.                 case 5://TC_VISO_SE:
  204.                     dxPos = 1;    dyPos = -1;    dzPos = 1;
  205.                     dxLook = 0;    dyLook = 0;    dzLook = 0;
  206.                     dxUp = 0;    dyUp = 0;    dzUp = 1;
  207.                     break;
  208.                 case 6://TC_VISO_SW:
  209.                     dxPos = -1;    dyPos = -1;    dzPos = 1;
  210.                     dxLook = 0;    dyLook = 0;    dzLook = 0;
  211.                     dxUp = 0;    dyUp = 0;    dzUp = 1;
  212.                     break;
  213.                 case 7://TC_VISO_NE:
  214.                     dxPos = 1;    dyPos = 1;    dzPos = 1;
  215.                     dxLook = 0;    dyLook = 0;    dzLook = 0;
  216.                     dxUp = 0;    dyUp = 0;    dzUp = 1;
  217.                     break;
  218.                 case 8://TC_VISO_NW:
  219.                     dxPos = -1;    dyPos = 1;    dzPos = 1;
  220.                     dxLook = 0;    dyLook = 0;    dzLook = 0;
  221.                     dxUp = 0;    dyUp = 0;    dzUp = 1;
  222.                     break;
  223.             
  224.                 default:
  225.                     break;
  226.             }
  227.             
  228.             pCam = (IMSIGX.XCamera)pView.Camera ;
  229.             pvPos = (IMSIGX.XVertex)pCam.Location;
  230.             pvLook = (IMSIGX.XVertex)pCam.LookAt;
  231.             pvUp = (IMSIGX.XVertex)pCam.Up;
  232.             
  233.             pvPos.X = dxPos;
  234.             pvPos.Y = dyPos;
  235.             pvPos.Z = dzPos;
  236.             pvLook.X = dxLook;
  237.             pvLook.Y = dyLook;
  238.             pvLook.Z = dzLook;
  239.  
  240.             pvUp.X = dxUp;
  241.             pvUp.Y = dyUp;
  242.             pvUp.Z = dzUp;
  243.             pView.AutoRedraw = false;
  244.             pCam.CameraSetSpaceParameters (pvPos, pvLook, pvUp);
  245.             pView.ZoomToExtents ();
  246.             pView.AutoRedraw = true;
  247.  
  248.         }
  249.  
  250.         public void Zoom(IMSIGX.View pView, double zoomfactor)
  251.         {
  252.             
  253.             if (zoomfactor != 0)
  254.             {
  255.                 try
  256.                 {
  257.                     pView.Camera.Zoom (zoomfactor);
  258.                 }
  259.                 catch  // in case of paper space (not possible to get camera object in paperSpace) or unexpected error in model space
  260.                 {
  261.                     double xC = 0;    double yC = 0;
  262.                     double w = 0;    double h = 0;
  263.     
  264.                     //On Error GoTo Err
  265.                     w = pView.ViewWidth;
  266.                     h = pView.ViewHeight;
  267.     
  268.                     xC = pView.ViewLeft + w / 2;
  269.                     yC = pView.ViewTop - h / 2;
  270.                     w = w * zoomfactor;
  271.                     h = h * zoomfactor;
  272.                     pView.Update = false;
  273.         
  274.                     pView.ViewLeft = xC - w / 2;
  275.                     pView.ViewTop = yC + h / 2;
  276.                     pView.ViewWidth = w;
  277.                     pView.ViewHeight = h;
  278.                 }
  279.             }
  280.             else
  281.             {
  282.                 pView.ZoomToExtents ();
  283.             }
  284.         }
  285.         
  286.         public void Scroll (double val)
  287.         {
  288.             IMSIGX.XCamera gxCam = null;
  289.             if (this.gxApp != null)
  290.             {
  291.                 if (this.gxView != null)
  292.                 {
  293.                     if (this.gxView.SpaceMode == IMSIGX.ImsiSpaceModeType.imsiModelSpace ) // if model space
  294.                     {
  295.                         gxCam = (IMSIGX.XCamera )this.gxView.Camera;
  296.                         if (gxCam != null)
  297.                         {
  298.                             this.gxView.Update = false;
  299.                             gxCam.Slide (0, val/10);
  300.                             this.gxView.Update = true;
  301.                         }
  302.                     }
  303.                     else // if paper space
  304.                     {
  305.                                     
  306.                     }
  307.                 }
  308.             }
  309.         
  310.         }
  311.  
  312.         public DPoint ScrollLast;
  313.         public void ViewScrollBy(double DeltaX, double DeltaY)
  314.         {
  315.             if (DeltaX == 0 && DeltaY == 0)
  316.             {
  317.                 return;
  318.             }
  319.             gxView.ViewLeft = gxView.ViewLeft + DeltaX;
  320.             gxView.ViewTop = gxView.ViewTop + DeltaY;
  321.         }
  322.  
  323.     }
  324. }
  325.