home *** CD-ROM | disk | FTP | other *** search
- //******************************************************************'
- //* *'
- //* TurboCAD for Windows *'
- //* Copyright (c) 1993 - 2004 *'
- //* International Microcomputer Software, Inc. *'
- //* (IMSI) *'
- //* All rights reserved. *'
- //* *'
- //******************************************************************'
-
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using IMSIGX;
- using GXMPSLib;
- namespace TCADClientTest
- {
- /// <summary>
- /// Summary description for TCADApp.
- /// </summary>
- public struct DPoint
- {
- public double x, y;
-
- public DPoint(double p1, double p2)
- {
- x = p1;
- y = p2;
- }
- }
- public struct DRect
- {
- public double Left, Top, Heigth, Width;
-
- public DRect(double p1, double p2, double p3, double p4)
- {
- Left = p1;
- Top = p2;
- Heigth = p3;
- Width = p4;
- }
- }
-
- public class TCADApp
- {
- public TCADApp()
- {
- //
- // TODO: Add constructor logic here
- //
- }
-
- public IMSIGX.XApplication gxApp = null;
- public IMSIGX.XDrawing gxDrawing = null;
- public IMSIGX.View gxView = null;
-
- public bool InitTCApp()
- {
- gxApp = new IMSIGX.XApplication ();
- return true;
- }
-
- public void AddView(int hWnd)
- {
- object missing = null;
- object h;
- h = hWnd;
- gxView = gxDrawing.Views.Add ( ref h, ref missing);
- gxView.Update = false;
- gxView.MappingMode = 1;
- gxView.FixedAspectRatio = true;
- }
- public void OpenDrawing()
- {
- object missing = null;
- string sFileName = "";
- if (gxDrawing != null)
- {
- gxDrawing.Close (ref missing, ref missing, ref missing);
- gxDrawing = null;
- if (gxView != null)
- {
- gxView.Delete ();
- gxView = null;
- }
- }
- sFileName = gxApp.GetOpenFilename (ref missing, ref missing, ref missing, ref missing);
- gxDrawing = (IMSIGX.XDrawing) gxApp.Drawings.Open (sFileName, ref missing, ref missing);
- // frmMain.ActiveForm.Text = Form1.ActiveForm.Text + sFileName;
-
- }
-
- public void OpenDrawing(System.Windows.Forms.TabControl tctrl)
- {
- TabPage tabPage1;
-
- object missing = null;
- string sFileName = "";
- string sName = "";
- string sNameActive = "";
- int i, n;
- i = n = 0;
-
- if (gxDrawing != null)
- {
- gxDrawing.Close (ref missing, ref missing, ref missing);
- gxDrawing = null;
- if (gxView != null)
- {
- gxView.Delete ();
- gxView = null;
- }
- }
- tctrl.TabPages.Clear ();
- sFileName = null;
- sFileName = gxApp.GetOpenFilename (ref missing, ref missing, ref missing, ref missing);
- if (sFileName == null)
- {
- return;
- }
- gxDrawing = (IMSIGX.XDrawing) gxApp.Drawings.Open (sFileName, ref missing, ref missing);
- GXMPSLib.PaperSpaces pPss = null;
- GXMPSLib.PaperSpace pPs = null;
- pPss = (GXMPSLib.PaperSpaces) gxDrawing.PaperSpaces;
- n = pPss.Count;
- System.Collections.IEnumerator pN;
-
- sName = "Model" ;
- tabPage1 = new TabPage(sName);
- tctrl.TabPages.Add (tabPage1);
- pN = pPss.GetEnumerator ();
- pN.MoveNext() ;
- for (i = 0; i < n ; i++)
- {
- pPs = (GXMPSLib.PaperSpace)pN.Current;
- sName = pPs.Name ;
- tabPage1 = new TabPage(sName);
- tctrl.TabPages.Add (tabPage1);
- if (pPs.Active == true)
- {
- sNameActive = sName;
- tabPage1.Select ();
- }
- pN.MoveNext() ;
- }
- pN = tctrl.TabPages.GetEnumerator ();
- pN.Reset ();
- pN.MoveNext() ;
- n = tctrl.TabPages.Count;
-
- for (i = 0; i < n ; i++)
- {
- tabPage1 = (TabPage)pN.Current;
- if (sNameActive == tabPage1.Text )
- {
- tctrl.SelectedTab = tabPage1;
- break;
- }
- pN.MoveNext() ;
- }
-
- this.AddView ((int)tabPage1.Handle );
-
- }
- public void SetView(IMSIGX.View pView, int iViewType)
- {
- double dxPos, dyPos, dzPos, dxLook, dyLook, dzLook, dxUp, dyUp, dzUp;
- IMSIGX.XCamera pCam = null;
- IMSIGX.XVertex pvPos, pvLook, pvUp;
-
- dxPos = 0; dyPos = 0; dzPos = 1;
- dxLook = 0; dyLook = 0; dzLook = 0;
- dxUp = 0; dyUp = 1; dzUp = 0;
-
- switch (iViewType)
- {
-
- case 0://TC_VPLAN:
- dxPos = 0; dyPos = 0; dzPos = 1;
- dxLook = 0; dyLook = 0; dzLook = 0;
- dxUp = 0; dyUp = 1; dzUp = 0;
- break;
- case 1://TC_VLEFT:
- dxPos = -1; dyPos = 0; dzPos = 0;
- dxLook = 0; dyLook = 0; dzLook = 0;
- dxUp = 0; dyUp = 0; dzUp = 1;
- break;
- case 2://TC_VRIGHT:
- dxPos = 1; dyPos = 0; dzPos = 0;
- dxLook = 0; dyLook = 0; dzLook = 0;
- dxUp = 0; dyUp = 0; dzUp = 1;
- break;
- case 3://TC_VFRONT:
- dxPos = 0; dyPos = -1; dzPos = 0;
- dxLook = 0; dyLook = 0; dzLook = 0;
- dxUp = 0; dyUp = 0; dzUp = 1;
- break;
- case 4://TC_VBOTTOM:
- dxPos = 0; dyPos = 0; dzPos = 1;
- dxLook = 0; dyLook = 0; dzLook = 0;
- dxUp = 0; dyUp = -1; dzUp = 0;
- break;
- case 5://TC_VISO_SE:
- dxPos = 1; dyPos = -1; dzPos = 1;
- dxLook = 0; dyLook = 0; dzLook = 0;
- dxUp = 0; dyUp = 0; dzUp = 1;
- break;
- case 6://TC_VISO_SW:
- dxPos = -1; dyPos = -1; dzPos = 1;
- dxLook = 0; dyLook = 0; dzLook = 0;
- dxUp = 0; dyUp = 0; dzUp = 1;
- break;
- case 7://TC_VISO_NE:
- dxPos = 1; dyPos = 1; dzPos = 1;
- dxLook = 0; dyLook = 0; dzLook = 0;
- dxUp = 0; dyUp = 0; dzUp = 1;
- break;
- case 8://TC_VISO_NW:
- dxPos = -1; dyPos = 1; dzPos = 1;
- dxLook = 0; dyLook = 0; dzLook = 0;
- dxUp = 0; dyUp = 0; dzUp = 1;
- break;
-
- default:
- break;
- }
-
- pCam = (IMSIGX.XCamera)pView.Camera ;
- pvPos = (IMSIGX.XVertex)pCam.Location;
- pvLook = (IMSIGX.XVertex)pCam.LookAt;
- pvUp = (IMSIGX.XVertex)pCam.Up;
-
- pvPos.X = dxPos;
- pvPos.Y = dyPos;
- pvPos.Z = dzPos;
- pvLook.X = dxLook;
- pvLook.Y = dyLook;
- pvLook.Z = dzLook;
-
- pvUp.X = dxUp;
- pvUp.Y = dyUp;
- pvUp.Z = dzUp;
- pView.AutoRedraw = false;
- pCam.CameraSetSpaceParameters (pvPos, pvLook, pvUp);
- pView.ZoomToExtents ();
- pView.AutoRedraw = true;
-
- }
-
- public void Zoom(IMSIGX.View pView, double zoomfactor)
- {
-
- if (zoomfactor != 0)
- {
- try
- {
- pView.Camera.Zoom (zoomfactor);
- }
- catch // in case of paper space (not possible to get camera object in paperSpace) or unexpected error in model space
- {
- double xC = 0; double yC = 0;
- double w = 0; double h = 0;
-
- //On Error GoTo Err
- w = pView.ViewWidth;
- h = pView.ViewHeight;
-
- xC = pView.ViewLeft + w / 2;
- yC = pView.ViewTop - h / 2;
- w = w * zoomfactor;
- h = h * zoomfactor;
- pView.Update = false;
-
- pView.ViewLeft = xC - w / 2;
- pView.ViewTop = yC + h / 2;
- pView.ViewWidth = w;
- pView.ViewHeight = h;
- }
- }
- else
- {
- pView.ZoomToExtents ();
- }
- }
-
- public void Scroll (double val)
- {
- IMSIGX.XCamera gxCam = null;
- if (this.gxApp != null)
- {
- if (this.gxView != null)
- {
- if (this.gxView.SpaceMode == IMSIGX.ImsiSpaceModeType.imsiModelSpace ) // if model space
- {
- gxCam = (IMSIGX.XCamera )this.gxView.Camera;
- if (gxCam != null)
- {
- this.gxView.Update = false;
- gxCam.Slide (0, val/10);
- this.gxView.Update = true;
- }
- }
- else // if paper space
- {
-
- }
- }
- }
-
- }
-
- public DPoint ScrollLast;
- public void ViewScrollBy(double DeltaX, double DeltaY)
- {
- if (DeltaX == 0 && DeltaY == 0)
- {
- return;
- }
- gxView.ViewLeft = gxView.ViewLeft + DeltaX;
- gxView.ViewTop = gxView.ViewTop + DeltaY;
- }
-
- }
- }
-