home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2002 March
/
PCWMAR02.iso
/
software
/
turbocad
/
V4
/
tcw.z
/
padwiz.bas
< prev
next >
Wrap
BASIC Source File
|
1997-10-28
|
10KB
|
403 lines
' This sample program is to illustrate how to create Wizard-like dialogs for TurboCAD
'
' In this example I explore the possibilities of parametric drawing using scripts in the
' PCB disciplne.
'
' Author : Mike Cartwright, Tamara Cartwright (updated for 4.0)
' Date : 10/21/95, 02/06/97
'
' DBAPI Constants
' Global Const BrushSolid = 1
' Result is a global variable returned by each page to tell the
' state machine which button was pressed :
Global Const NextID = 1
Global Const CancelID = 2
Global Const BackID = 3
Global Const CreateID = 4
Dim Result As Long
Dim Orientation As Long
Dim PadGap As Double
Dim RowGap As Double
Dim PadSize As Double
Dim measure As Double
Dim es As Double
Dim es1 As Long
Dim Offset As Long
Dim TotalPads As Long
Dim PadShape As Long
Sub Main ()
Dim dActive As Long
dActive = TCWDrawingActive ()
measure = Abs(TCWViewExtentsGetY2() - TCWViewExtentsGetY1())/8.6
' Check for valid drawing
If dActive = 0 Then
MsgBox "Program requires active drawing. Open any drawing and try again."
' Terminate the program
Stop
End If
Orientation = 1 ' Default is Horizontal
Offset = 0 ' Default is not to offset the one row
TotalPads = 16 ' Total in each row
es1=25*measure
es=es1/100
PadGap = es ' Gap between pads in the row
RowGap = es*2 ' Gap between rows
PadSize = es*0.5 ' Diameter of pads
PadShape = 0 ' Circle is 0, Square is 1
' State is actually an index to tell which page we are currently on
Dim State As Long
Dim LastState As Long
LastState = 3
' Start on the first page
State = 0
Do
' Page "0" - Which way up Vertical or Horizontal?
If State = 0 Then
OrientationDlg
End If
' Page "1" - Total number of Pads per Row and whether offset or not
If State = 1 Then
TotalDlg
End If
' Page "2" - Inter-row gap and inter-pad gaps
If State = 2 Then
GapDlg
End If
' Page "LastState" - What shape, circle or square? What Size?
If State = LastState Then
ShapeDlg
End If
If Result = CreateID Then
CreatePads
Exit Do
End If
If Result = CancelID Then
MsgBox "The Pad Wizard was cancelled."
Exit Do
End If
If Result = NextID And State < LastState Then
State = State + 1
End If
If Result = BackID And State > 0 Then
State = State - 1
End If
Loop
TCWDeselectAll
' MsgBox "Finished"
End Sub
Sub OrientationDlg ()
Begin Dialog OrientationDialog 31, 32, 185, 96, "Pad Wizard"
PushButton 95, 79, 35, 14, "&Next>" ' Button 1
PushButton 15, 79, 35, 14, "Cancel" ' Button 2
' "<&Back"
PushButton 135, 79, 35, 14, "&Finish" ' Button 4
' GroupBox 1, 75, 183, 1, ""
GroupBox 100, 12, 72, 48, "Orientation"
OptionGroup .grp1
OptionButton 108, 24, 55, 9, "&Vertical" ' Option 0
OptionButton 108, 40, 55, 9, "&Horizontal" ' Option 1
GroupBox 10, 12, 82, 48, ""
Text 14, 18, 74, 40, "If the pads run across the page then choose Horizontal. If not, then choose vertical."
End Dialog
Dim Dlg1 As OrientationDialog
Dlg1.grp1 = Orientation
Result = Dialog(Dlg1)
if Result = 3 then
Result = 4
End If
Orientation = Dlg1.grp1
End Sub
Sub ShapeDlg ()
Begin Dialog ShapeDialog 31, 32, 185, 96, "Pad Wizard"
' "&Next>"
PushButton 15, 79, 35, 14, "Cancel" ' Button 2
PushButton 55, 79, 35, 14, "<&Back" ' Button 3
PushButton 135, 79, 35, 14, "&Finish" ' Button 4
' GroupBox 1, 75, 183, 1, ""
GroupBox 100, 12, 72, 48, "Pad Shape"
OptionGroup .grp1
OptionButton 108, 24, 55, 9, "&Circle" ' Option 0
OptionButton 108, 40, 55, 9, "&Square" ' Option 1
GroupBox 10, 12, 82, 48, "Pad Size"
Text 14, 21, 74, 30, "This is the diameter or width of each pad:"
TextBox 14, 42, 50, 12, .size
End Dialog
Dim Dlg2 As ShapeDialog
Dlg2.grp1 = PadShape
Do
Dlg2.size = PadSize
Result = Dialog(Dlg2)
Result = Result + 1
PadSize = Dlg2.size
If Result = CancelID Then
Exit Do
End If
If PadSize >es1/250 And PadSize < es1/25 Then
Exit Do
End If
MsgBox "Pad Size of " & PadSize &" is not in the range ["+Str(es1/250)+".."+Str(es1/25)+"]"
Loop
PadShape = Dlg2.grp1
End Sub
Sub TotalDlg ()
Begin Dialog TotalDialog 31, 32, 185, 96, "Pad Wizard"
PushButton 95, 79, 35, 14, "&Next>" ' Button 1
PushButton 15, 79, 35, 14, "Cancel" ' Button 2
PushButton 55, 79, 35, 14, "<&Back" ' Button 3
PushButton 135, 79, 35, 14, "&Finish" ' Button 4
' GroupBox 1, 75, 183, 1, ""
GroupBox 100, 12, 72, 48, "Offset Pads"
OptionGroup .grp1
OptionButton 108, 24, 55, 9, "DI&P - in line" ' Option 0
OptionButton 108, 40, 55, 9, "DI&N - offset" ' Option 1
GroupBox 10, 12, 82, 48, "Number of Pads"
Text 14, 21, 74, 30, "The number of pads in the longest row:"
TextBox 14, 42, 50, 12, .total
End Dialog
Dim Dlg3 As TotalDialog
Dlg3.grp1 = Offset
Do
Dlg3.total = TotalPads
Result = Dialog(Dlg3)
TotalPads = Dlg3.total
If Result = CancelID Then
Exit Do
End If
If TotalPads > 1 And TotalPads < 100 Then
Exit Do
End If
If TotalPads > 100 Then
MsgBox TotalPads &" is too many pads"
End If
If TotalPads < 2 Then
MsgBox TotalPads &" is too few pads"
End If
Loop
Offset = Dlg3.grp1
End Sub
Sub GapDlg ()
Begin Dialog GapDialog 31, 32, 185, 96, "Pad Wizard"
PushButton 95, 79, 35, 14, "&Next>" ' Button 1
PushButton 15, 79, 35, 14, "Cancel" ' Button 2
PushButton 55, 79, 35, 14, "<&Back" ' Button 3
PushButton 135, 79, 35, 14, "&Finish" ' Button 4
' GroupBox 1, 75, 183, 1, ""
GroupBox 100, 12, 76, 48, "Pad Gap"
Text 104, 21, 69, 30, "This is the space between pad centers:"
TextBox 104, 42, 50, 12, .padg
GroupBox 10, 12, 82, 48, "Row Gap"
Text 14, 21, 74, 30, "This is the space between row centers:"
TextBox 14, 42, 50, 12, .rowg
End Dialog
Dim Dlg4 As GapDialog
Do
Dlg4.rowg = RowGap
Dlg4.padg = PadGap
Result = Dialog(Dlg4)
PadGap = Dlg4.padg
RowGap = Dlg4.rowg
If Result = CancelID Then
Exit Do
End If
If PadGap > PadSize And RowGap > PadSize Then
Exit Do
End If
If PadGap <= PadSize Then
MsgBox "Pad Gap of " & PadGap & " should be greater than " & PadSize
End If
If RowGap <= PadSize Then
MsgBox "Row Gap of " & RowGap & " should be greater than " & PadSize
End If
Loop
End Sub
' Called on "Create" to actually create the graphics and add them
' to the drawing. They are left selected to make it easier to move them.
Sub CreatePads ()
Dim dActive As Long
Dim xc As Double
Dim yc As Double
Dim dx1 As Double
Dim dx2 As Double
Dim dx3 As Double
Dim dy1 As Double
Dim dy2 As Double
Dim dy3 As Double
Dim row As Long
Dim col As Long
dActive = TCWDrawingActive ()
TCWUndoRecordStart dActive, "Create Pads"
xc = (TCWViewExtentsGetX1() + TCWViewExtentsGetX2())/2.0
yc = (TCWViewExtentsGetY1() + TCWViewExtentsGetY2())/2.0
If Orientation = 1 Then ' Horizontal
dx1 = PadGap
dy1 = 0
dx2 = 0
dy2 = -RowGap
Else ' Vertical
dx1 = 0
dy1 = -PadGap
dx2 = RowGap
dy2 = 0
End If
' Move starting point
xc = xc - dx1*TotalPads/2.0 - dx2/2.0
yc = yc - dy1*TotalPads/2.0 - dy2/2.0
For row = 0 to 1
For col = 0 to TotalPads-1
' Call our function which creates a pad
MakeObject xc + col*dx1 + row*dx2, yc + col*dy1 + row*dy2
Next col
' For the offset option an extra calculation is required when
' switching rows to get the next row's start position
If Offset Then
TotalPads = TotalPads - 1
xc = xc + dx1/2.0
yc = yc + dy1/2.0
End If
Next row
TCWGroupCreate "Custom Pads"
TCWUndoRecordEnd dActive
End Sub
Sub MakeObject (ByVal x As Double, ByVal y As Double)
Dim gP As Long
Dim g1 As Long
Dim g2 As Long
Dim r As Double
r = PadSize/2.0
If PadShape = 0 Then
g1 = TCWCircleCenterAndPoint(x, y, 0#, x-2*r, y, 0# )
Else
' Create the empty rectangle graphic
g1 = TCWLineRectangle(x-r, y-r, 0#, x+r, y+r, 0#)
End If
' Color is set as R, G, B - this is black
result=0
result = TCWGraphicPropertySet(g1, "PenColor", &H00112233 )
' Fill Pattern is a style.
result = TCWGraphicPropertySet(g1, "BrushStyle", "Solid")
' Add the black background of the pad to the pad group
' Make the hole 1/3 of the size of the pad unless it is smaller
' then a minimum, in which case it is set to that minimum
r = PadSize/6.0
If r > 0.0625*measure Then
r = 0.0625*es1/25
End If
If PadShape = 0 Then
' Create the empty arc graphic
g2 = TCWCircleCenterAndPoint(x, y, 0#, x-2*r, y, 0# )
Else
' Create the empty rectangle graphic
g2 = TCWLineRectangle(x-r, y-r, 0#, x+r, y+r, 0#)
End If
' Color is set as R, G, B - this is white
result = TCWGraphicPropertySet(g2, "PenColor", &H00FFFFFF)
' Fill Pattern is a style.
result = TCWGraphicPropertySet(g2, "BrushStyle", "Solid")
result = TCWGraphicPropertySet(g1, "Selected", 1 )
result = TCWGraphicPropertySet(g2, "Selected", 1 )
End Sub