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.vb < prev    next >
Encoding:
Text File  |  2004-07-15  |  5.2 KB  |  124 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. Public Class TCEngine
  11.     Public m_gxApp As IMSIGX.XApplication
  12.     Public m_gxDrawing As IMSIGX.IDrawing
  13.     Public m_gxView As IMSIGX.View
  14.  
  15.     Public Sub New()
  16.         m_gxApp = Nothing
  17.         m_gxDrawing = Nothing
  18.         m_gxView = Nothing
  19.     End Sub
  20.     Public Sub CreateGxApp()
  21.         If m_gxApp Is Nothing Then
  22.             m_gxApp = New IMSIGX.XApplication
  23.         End If
  24.     End Sub
  25.     Public Sub CreateNewDrawing()
  26.         If m_gxApp Is Nothing Then
  27.             CreateGxApp()
  28.         End If
  29.         If Not m_gxDrawing Is Nothing Then
  30.             MsgBox("Drawing is already created !")
  31.         Else
  32.             m_gxDrawing = m_gxApp.Drawings.Add()
  33.         End If
  34.     End Sub
  35.     Public Sub CreateGxView(ByVal hWnd As Long)
  36.         ' hWnd - handle of window to which we attach the TurboCAD's view
  37.         If Not m_gxDrawing Is Nothing Then
  38.             m_gxView = m_gxDrawing.Views.Add()
  39.             m_gxView.HWND = hWnd
  40.             m_gxView.Update = False
  41.             m_gxView.MappingMode = 1
  42.             m_gxView.FixedAspectRatio = True
  43.         End If
  44.     End Sub
  45.     Public Function AddLineSingle(ByVal x1Screen As Double, ByVal y1Screen As Double, ByVal x2Screen As Double, ByVal y2Screen As Double) As IMSIGX.IGraphic
  46.  
  47.         Dim x1View As Double, y1View As Double, x2View As Double, y2View As Double, zView As Double
  48.         Dim x1World As Double, y1World As Double, x2World As Double, y2World As Double
  49.         zView = 0
  50.         Dim grRet As IMSIGX.IGraphic
  51.  
  52.         Me.m_gxView.ScreenToView(x1Screen, y1Screen, x1View, y1View)
  53.         Me.m_gxView.ScreenToView(x2Screen, y2Screen, x2View, y2View)
  54.         Me.m_gxView.ViewToWorld(x1View, y1View, zView, x1World, y1World, zView)
  55.         Me.m_gxView.ViewToWorld(x2View, y2View, zView, x2World, y2World, zView)
  56.  
  57.         grRet = Me.m_gxDrawing.Graphics.AddLineSingle(x1World, y1World, 0, x2World, y2World, 0)
  58.         Return grRet
  59.     End Function
  60.  
  61.     Public Function AddCircleCenterAndPoint(ByVal x1Screen As Double, ByVal y1Screen As Double, ByVal x2Screen As Double, ByVal y2Screen As Double) As IMSIGX.IGraphic
  62.  
  63.         Dim x1View As Double, y1View As Double, x2View As Double, y2View As Double, zView As Double
  64.         Dim x1World As Double, y1World As Double, x2World As Double, y2World As Double
  65.         zView = 0
  66.         Dim grRet As IMSIGX.IGraphic
  67.  
  68.         Me.m_gxView.ScreenToView(x1Screen, y1Screen, x1View, y1View)
  69.         Me.m_gxView.ScreenToView(x2Screen, y2Screen, x2View, y2View)
  70.         Me.m_gxView.ViewToWorld(x1View, y1View, zView, x1World, y1World, zView)
  71.         Me.m_gxView.ViewToWorld(x2View, y2View, zView, x2World, y2World, zView)
  72.  
  73.         grRet = Me.m_gxDrawing.Graphics.AddCircleCenterAndPoint(x1World, y1World, 0, x2World, y2World, 0)
  74.         Return grRet
  75.     End Function
  76.     Public Function SelectGraphic(ByVal xScreen As Double, ByVal yScreen As Double) As IMSIGX.IGraphic
  77.         Dim xView As Double, yView As Double
  78.         Dim gxPickResult As IMSIGX.PickResult
  79.         Dim gxPickEntry As IMSIGX.PickEntry
  80.         Dim grRet As IMSIGX.IGraphic
  81.         Me.m_gxView.ScreenToView(xScreen, yScreen, xView, yView)
  82.         gxPickResult = Me.m_gxView.PickPoint(xView, yView)
  83.         If (gxPickResult.Count <> 0) Then
  84.             gxPickEntry = gxPickResult.Item(0)
  85.             grRet = gxPickEntry.Graphic
  86.         Else
  87.             Me.m_gxDrawing.Graphics.Unselect()
  88.         End If
  89.         gxPickResult = Nothing
  90.         gxPickEntry = Nothing
  91.         Return grRet
  92.     End Function
  93.  
  94.     Public Sub Zoom(ByVal zoomfactor As Double)
  95.         If (zoomfactor <> 0) Then
  96.             Try
  97.                 Me.m_gxView.Camera.Zoom(zoomfactor)
  98.             Catch ex As Exception
  99.                 '// in case of paper space (not possible to get camera object in paperSpace) or unexpected error in model space
  100.                 Dim xC As Double, yC As Double, w As Double, h As Double
  101.                 xC = yC = 0
  102.                 w = h = 0
  103.  
  104.                 '    //On Error GoTo Err
  105.                 w = Me.m_gxView.ViewWidth
  106.                 h = Me.m_gxView.ViewHeight
  107.  
  108.                 xC = Me.m_gxView.ViewLeft + w / 2
  109.                 yC = Me.m_gxView.ViewTop - h / 2
  110.                 w = w * zoomfactor
  111.                 h = h * zoomfactor
  112.                 Me.m_gxView.Update = False
  113.  
  114.                 Me.m_gxView.ViewLeft = xC - w / 2
  115.                 Me.m_gxView.ViewTop = yC + h / 2
  116.                 Me.m_gxView.ViewWidth = w
  117.                 Me.m_gxView.ViewHeight = h
  118.             End Try
  119.         Else
  120.             Me.m_gxView.ZoomToExtents()
  121.         End If
  122.     End Sub
  123. End Class
  124.