home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / tcengine.cs < prev    next >
Encoding:
Text File  |  2004-07-15  |  5.3 KB  |  197 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 IMSIGX;
  14. namespace TCGeometry
  15. {
  16.     /// <summary>
  17.     /// Summary description for TCengine.
  18.     /// </summary>
  19.     public class TCengine
  20.     {
  21.         public IMSIGX.XApplication  m_gxApp;
  22.         public IMSIGX.IDrawing  m_gxDrawing;
  23.         public IMSIGX.View  m_gxView;
  24.  
  25.         public TCengine()
  26.         {
  27.             //
  28.             // TODO: Add constructor logic here
  29.             m_gxApp = null;
  30.             m_gxDrawing = null;
  31.             m_gxView = null;
  32.             //
  33.         }
  34.  
  35.         /// <summary>
  36.         /// Creates imsigx application object
  37.         /// </summary>
  38.         public void CreategxApp()
  39.         {
  40.             try
  41.             {
  42.                 if (m_gxApp == null)
  43.                 {
  44.                     m_gxApp = new IMSIGX.XApplication();
  45.                 }
  46.             }
  47.             catch(System.Exception exc)
  48.             {
  49.                 Console.WriteLine("{0} Caught exception .", exc); 
  50.             }
  51.  
  52.  
  53.  
  54.         }
  55.         public void CreateNewDrawing()
  56.         {
  57.             object missing = null;
  58.  
  59.             try
  60.             {
  61.                 if (m_gxApp == null)
  62.                 {
  63.                     CreategxApp();
  64.                 }
  65.                 if (m_gxDrawing != null)
  66.                 {
  67.                     MessageBox.Show ("Drawing is already created !");
  68.                 }
  69.                 else
  70.                 {
  71.                     m_gxDrawing = m_gxApp.Drawings.Add(ref missing);
  72.                 }
  73.             }
  74.  
  75.             
  76.             
  77.             catch(System.Exception exc)
  78.             {
  79.                 Console.WriteLine("{0} Caught exception .", exc); 
  80.             }
  81.  
  82.         }
  83.         public void CreategxView(int hWnd)
  84.         {
  85.             object missing = null;
  86.             object h;
  87.             try
  88.             {
  89.                 h = hWnd;
  90.                 if (m_gxDrawing != null)
  91.                 {
  92.                     m_gxView = m_gxDrawing.Views.Add ( ref h, ref missing);
  93.                     m_gxView.Update = false;
  94.                     m_gxView.MappingMode = 1;
  95.                     m_gxView.FixedAspectRatio = true;
  96.                 }
  97.             }
  98.     
  99.             catch(System.Exception exc)
  100.             {
  101.                 Console.WriteLine("{0} Caught exception .", exc); 
  102.             }
  103.  
  104.         }
  105.         public IMSIGX.IGraphic AddLineSingle(double x1Screen, double y1Screen, double x2Screen, double y2Screen)
  106.         {
  107.             double x1View, y1View, x2View, y2View, zView;
  108.             double x1World, y1World, x2World, y2World;
  109.             zView = 0;
  110.             IMSIGX.IGraphic grRet;
  111.                     
  112.             this.m_gxView.ScreenToView (x1Screen, y1Screen, out x1View, out y1View);
  113.             this.m_gxView.ScreenToView (x2Screen, y2Screen,out  x2View, out y2View);
  114.             this.m_gxView.ViewToWorld (x1View, y1View,zView, out x1World, out y1World, out zView);
  115.             this.m_gxView.ViewToWorld (x2View, y2View, zView, out x2World, out y2World, out zView);
  116.                     
  117.             grRet = this.m_gxDrawing.Graphics.AddLineSingle (x1World,y1World,0,x2World,y2World,0);
  118.             return grRet;
  119.         }
  120.         public IMSIGX.IGraphic AddCircleCenterAndPoint(double x1Screen, double y1Screen, double x2Screen, double y2Screen)
  121.         {
  122.             double x1View, y1View, x2View, y2View, zView;
  123.             double x1World, y1World, x2World, y2World;
  124.             zView = 0;
  125.             IMSIGX.IGraphic grRet;
  126.                     
  127.             this.m_gxView.ScreenToView (x1Screen, y1Screen, out x1View, out y1View);
  128.             this.m_gxView.ScreenToView (x2Screen, y2Screen,out  x2View, out y2View);
  129.             this.m_gxView.ViewToWorld (x1View, y1View,zView, out x1World, out y1World, out zView);
  130.             this.m_gxView.ViewToWorld (x2View, y2View, zView, out x2World, out y2World, out zView);
  131.                     
  132.             grRet = this.m_gxDrawing.Graphics.AddCircleCenterAndPoint (x1World,y1World,0,x2World,y2World,0);
  133.             return grRet;
  134.         }
  135.     
  136.         public IMSIGX.IGraphic SelectGraphic(double xScreen, double yScreen)
  137.         {
  138.             double xView, yView;
  139.             object varVal;
  140.             object missing = null;
  141.             IMSIGX.PickResult gxPickResult;
  142.             IMSIGX.PickEntry  gxPickEntry;
  143.             IMSIGX.IGraphic gxvarGraphic = null;
  144.             this.m_gxView.ScreenToView (xScreen, yScreen, out xView, out yView);
  145.             gxPickResult = this.m_gxView.PickPoint (xView, yView,ref missing,ref missing, ref missing, ref missing,ref missing, ref missing,ref missing);
  146.             if (gxPickResult.Count != 0 )
  147.             {
  148.                 varVal = 0;
  149.                 gxPickEntry = gxPickResult.get_Item(ref varVal);
  150.                 gxvarGraphic = gxPickEntry.Graphic;
  151.             }
  152.             else
  153.             {
  154.                 this.m_gxDrawing.Graphics.Unselect ();
  155.             }
  156.             return gxvarGraphic;
  157.         }
  158.     
  159.         public void Zoom(double zoomfactor)
  160.         {
  161.             
  162.             if (zoomfactor != 0)
  163.             {
  164.                 try
  165.                 {
  166.                     this.m_gxView.Camera.Zoom (zoomfactor);
  167.                 }
  168.                 catch  // in case of paper space (not possible to get camera object in paperSpace) or unexpected error in model space
  169.                 {
  170.                     double xC = 0;    double yC = 0;
  171.                     double w = 0;    double h = 0;
  172.     
  173.                     //On Error GoTo Err
  174.                     w = this.m_gxView.ViewWidth;
  175.                     h = this.m_gxView.ViewHeight;
  176.     
  177.                     xC = this.m_gxView.ViewLeft + w / 2;
  178.                     yC = this.m_gxView.ViewTop - h / 2;
  179.                     w = w * zoomfactor;
  180.                     h = h * zoomfactor;
  181.                     this.m_gxView.Update = false;
  182.         
  183.                     this.m_gxView.ViewLeft = xC - w / 2;
  184.                     this.m_gxView.ViewTop = yC + h / 2;
  185.                     this.m_gxView.ViewWidth = w;
  186.                     this.m_gxView.ViewHeight = h;
  187.                 }
  188.             }
  189.             else
  190.             {
  191.                 this.m_gxView.ZoomToExtents ();
  192.             }
  193.         }
  194.     
  195.     }
  196. }
  197.