home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "mAddViewportXRefTst"
- '******************************************************************'
- '* *'
- '* TurboCAD for Windows *'
- '* Copyright (c) 1993 - 2001 *'
- '* International Microcomputer Software, Inc. *'
- '* (IMSI) *'
- '* All rights reserved. *'
- '* *'
- '******************************************************************'
-
-
- Const vpW = 3
- Const vpH = 3
-
- Const strXRef1 = "d:\tc80\bin\usa\drawings\drawing1.tcw"
- Const strXRef2 = "d:\tc80\bin\usa\drawings\drawing2.tcw"
- Const strXRef3 = "d:\tc80\bin\usa\drawings\drawing3.tcw"
- Const strXRef4 = "d:\tc80\bin\usa\drawings\drawing4.tcw"
-
- Private Sub AddXRefs()
- Dim gxBlks As Blocks
- Dim gxGrs As Graphics
- Dim gxVrt As Vertex
-
- Dim x As Double
- Dim y As Double
- Dim z As Double
-
- Dim dx As Double
- Dim dy As Double
- Dim dz As Double
-
- Dim gxGrXRef1 As Graphic
- Dim gxGrXRef2 As Graphic
- Dim gxGrXRef3 As Graphic
- Dim gxGrXRef4 As Graphic
-
- Dim gxBBox1 As BoundingBox
- Dim gxBBox2 As BoundingBox
- Dim gxBBox3 As BoundingBox
- Dim gxBBox4 As BoundingBox
-
- Set gxBlks = ActiveDrawing.Blocks
-
- gxBlks.AddXref "XRef1", strXRef1, 0, 0, 0
- gxBlks.AddXref "XRef2", strXRef2, 0, 0, 0
- gxBlks.AddXref "XRef3", strXRef3, 0, 0, 0
- gxBlks.AddXref "XRef4", strXRef4, 0, 0, 0
-
- Set gxGrs = ActiveDrawing
- Set gxGrXRef1 = gxGrs.AddBlockInsertion("XRef1", 0, 0, 0, 1, 1, 1)
- Set gxGrXRef2 = gxGrs.AddBlockInsertion("XRef2", 0, 0, 0, 1, 1, 1)
- Set gxGrXRef3 = gxGrs.AddBlockInsertion("XRef3", 0, 0, 0, 1, 1, 1)
- Set gxGrXRef4 = gxGrs.AddBlockInsertion("XRef4", 0, 0, 0, 1, 1, 1)
-
- Set gxBBox1 = gxGrXRef1.CalcBoundingBox
- Set gxBBox2 = gxGrXRef2.CalcBoundingBox
- Set gxBBox3 = gxGrXRef3.CalcBoundingBox
- Set gxBBox4 = gxGrXRef4.CalcBoundingBox
-
- y = (gxBBox1.Max.y + gxBBox1.Min.y) / 2
- dy = y - ((gxBBox2.Max.y + gxBBox2.Min.y) / 2)
-
- x = gxBBox1.Max.x + (gxBBox2.Max.x - gxBBox2.Min.x) / 2
- dx = x - (gxBBox2.Max.x + gxBBox2.Min.x) / 2 + 2
-
- z = (gxBBox1.Max.z + gxBBox1.Min.z) / 2
- dz = z - (gxBBox2.Max.z + gxBBox2.Min.z) / 2
-
- gxGrXRef2.MoveRelative dx, dy, dz
-
- x = (gxBBox1.Max.x + gxBBox1.Min.x) / 2
- dx = x - ((gxBBox3.Max.x + gxBBox3.Min.x) / 2)
-
- y = gxBBox1.Max.y + (gxBBox3.Max.y - gxBBox3.Min.y) / 2
- dy = y - (gxBBox3.Max.y + gxBBox3.Min.y) / 2 + 2
-
- z = (gxBBox1.Max.z + gxBBox1.Min.z) / 2
- dz = z - (gxBBox3.Max.z + gxBBox3.Min.z) / 2
-
- gxGrXRef3.MoveRelative dx, dy, dz
-
- Set gxBBox3 = gxGrXRef3.CalcBoundingBox
-
- y = (gxBBox3.Max.y + gxBBox3.Min.y) / 2
- dy = y - ((gxBBox4.Max.y + gxBBox4.Min.y) / 2)
-
- x = gxBBox3.Max.x + (gxBBox4.Max.x - gxBBox4.Min.x) / 2
- dx = x - (gxBBox4.Max.x + gxBBox4.Min.x) / 2 + 2
-
- z = (gxBBox3.Max.z + gxBBox3.Min.z) / 2
- dz = z - (gxBBox4.Max.z + gxBBox4.Min.z) / 2
-
- gxGrXRef4.MoveRelative dx, dy, dz
-
- ActiveDrawing.ActiveView.ZoomToExtents
-
- End Sub
-
- Private Function AddXRefNamedView(gxNVws As NamedViews, gxGr As Graphic) As Long
-
- Dim gxBBox As BoundingBox
- Dim cnt As Long
-
- cnt = 0
- If (gxGr.TypeByValue <> imsiInsert) Then
- GoTo LExit
- End If
-
- Set gxBBox = gxGr.CalcBoundingBox
-
- On Error GoTo LExit
- gxNVws.Add "View to " & gxGr.Block.Name, gxBBox.Min.x - 1, gxBBox.Min.y - 1, gxBBox.Max.x + 1, gxBBox.Max.y + 1
-
- cnt = 1
-
- LExit:
- AddXRefNamedView = cnt
-
- End Function
-
- Private Function AddXRefNamedViews(gxNVws As NamedViews) As Long
-
- Dim cnt As Long
-
- Dim gxGrs As Graphics
- Dim gxGr As Graphic
-
- Dim gxCam As Camera
-
- Dim gxVPos As Vertex
- Dim gxVLook As Vertex
- Dim gxVDir As Vertex
-
- cnt = 0
-
- AddXRefs
-
- Set gxCam = ActiveDrawing.ActiveView.Camera
-
- Set gxVPos = gxCam.Location
- Set gxVLook = gxCam.LookAt
- Set gxVDir = gxCam.Direction
-
- gxVPos.x = 0
- gxVPos.y = 0
- gxVPos.z = 1
-
- gxVLook.x = 0
- gxVLook.y = 0
- gxVLook.z = 0
-
- gxVDir.x = 0
- gxVDir.y = 1
- gxVDir.z = 0
-
- gxCam.CameraSetSpaceParameters gxVPos, gxVLook, gxVDir
-
- ActiveDrawing.ActiveView.ZoomToExtents
-
- Set gxGrs = ActiveDrawing.Graphics
-
- For Each gxGr In gxGrs
-
- cnt = cnt + AddXRefNamedView(gxNVws, gxGr)
-
- Next
-
- AddXRefNamedViews = cnt
-
- End Function
-
- Private Function AddXRefViewport(gxGrs As Graphics, gxNVw As NamedView) As Graphic
-
- Dim gxGr As Graphic
- Dim gxVrts As Vertices
- Dim gxVrt As Vertex
- Dim right As Double
- Dim bottom As Double
- Dim left As Double
- Dim top As Double
-
- Set gxGr = gxGrs.Add(imsiViewport)
- gxGr.Properties("NamedView") = gxNVw.Name
-
- Set gxVrts = gxGr.Vertices
- Set gxVrt = gxVrts(0)
- left = gxVrt.x
- top = gxVrt.y
-
- right = left + vpW
- bottom = top - vpH
-
- Set gxVrt = gxVrts(1)
- gxVrt.y = bottom
-
- Set gxVrt = gxVrts(2)
- gxVrt.y = bottom
- gxVrt.x = right
-
- Set gxVrt = gxVrts(3)
- gxVrt.x = right
-
- Set AddXRefViewport = gxGr
-
- End Function
-
- Public Sub AddXRefViewports()
-
- Dim gxNVws As NamedViews
-
- Dim gxProps As Properties
- Dim gxProp As Property
- Dim OldSpace As Long
-
- Dim gxGrs As Graphics
- Dim gxGr As Graphic
-
- Dim cnt As Long
- Dim cntCur As Long
- Dim cntOld As Long
- Dim ind As Long
-
- Dim dXY As Integer
- Dim vpX As Double
- Dim vpY As Double
-
- Set gxProps = ActiveDrawing.Properties
- Set gxProp = gxProps("TileMode")
-
- OldSpace = gxProp
-
- If (OldSpace <> 1) Then
- gxProp = 1 ' set model space
- End If
-
- Set gxProps = ActiveDrawing.Properties
- Set gxProp = gxProps("TileMode")
-
- OldSpace = gxProp
-
- If (OldSpace <> 1) Then
- gxProp = 1 ' set model space
- End If
-
- Set gxNVws = ActiveDrawing.NamedViews
- cntOld = gxNVws.Count
- cnt = AddXRefNamedViews(gxNVws)
-
- If (cnt > 0) Then
- gxProp = 0 ' set paper space
-
- Set gxGrs = ActiveDrawing.Graphics
- cntCur = gxNVws.Count
-
- vpX = vpW / 2 + 0.5
- vpY = vpH / 2 + 1
- dXY = 0
-
- For ind = cntOld To cntCur - 1
-
- Set gxGr = AddXRefViewport(gxGrs, gxNVws(ind))
-
- gxGr.MoveAbsolute vpX, vpY, 0
-
- Select Case dXY
- Case 1
- vpX = vpX + vpW + 1
- dXY = dXY + 1
- Case 0
- vpY = vpY + vpH + 1
- dXY = dXY + 1
- Case 3
- vpX = vpX - vpW - 1
- dXY = dXY + 1
- Case 2
- vpY = vpY - vpH - 1
- dXY = 0
- End Select
-
- gxGr.Draw
-
- Next ind
-
- Else
- gxProp = OldSpace
- End If
-
- End Sub
-
-