VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "fbPropMgr"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' This class defines the PropertyManagerPage and its controls.

Option Explicit

' The PropertyManagerPage
  Private fb_Page                 As SldWorks.PropertyManagerPage2

' The two groups that will contain the controls
  Private fb_Group1              As SldWorks.PropertyManagerPageGroup
  Private fb_Group2              As SldWorks.PropertyManagerPageGroup

' The ID's for all of the controls
  Const ID_fbGroup1               As Long = 1
  Const ID_fbBoxHeight            As Long = 2
  Const ID_fbBoxWidth             As Long = 3
  Const ID_fbBoxDepth             As Long = 4
  Const ID_fbGroup2               As Long = 5
  Const ID_fbFrameWidth           As Long = 6


' Create the page and place all of the controls on it.
Private Sub Layout()

    ' Objects needed to create the PropertyManagerPage
    Dim pageHdlr        As New fbPropMgrHdlr
    Dim swControl       As SldWorks.PropertyManagerPageControl
    
    Dim title           As String
    Dim message         As String
    Dim caption         As String
    Dim tip             As String
    Dim listItems(3)    As String
    
    Dim buttonTypes     As Long
    Dim Id              As Long
    Dim options         As Long
    Dim filterArray(1)  As Long
    Dim errors          As Long
    
    Dim controlType     As Integer
    Dim alignment       As Integer
    
    Dim bRet            As Boolean

    ' Initialize the Page Handler
    ' Pass it a reference to this PropertyManagerPage
    pageHdlr.Init Me
    
    ' Set some variables for the Page
    title = "FramedBox PMP"
    buttonTypes = swPropertyManager_CancelButton + swPropertyManagerOptions_LockedPage
   
    ' Create the PropertyManagerPage
    Set fb_Page = swApp.CreatePropertyManagerPage(title, buttonTypes, pageHdlr, errors)
    
    ' broken:
    '   SPR 154819 - "PropertyManagerPage2::SetMessage returns TRUE but message is not set"
    bRet = fb_Page.SetMessage("Some Message String", swAnnotationVisible)
    Debug.Assert bRet
    
    'Make sure that it was created properly
    If errors = swPropertyManagerPage_Okay Then
        
        'Initial set up of the dialog.
        message = "Information message that can be displayed as necessary."
        fb_Page.SetMessage message, swImportantMessageBox

        'Begin adding the required controls to the dialog.

        'GROUP BOX ------------------------------------------------------------------
        Id = ID_fbGroup1
        caption = "Box Parameters"
        options = swGroupBoxOptions_Visible + swGroupBoxOptions_Expanded
        Set fb_Group1 = fb_Page.AddGroupBox(Id, caption, options)
        If Not fb_Group1 Is Nothing Then
            'Place these controls in the first Group
            
            'CONTROL Number box - Box Height ----------------------------------------
            Id = ID_fbBoxHeight
            controlType = swControlType_Numberbox
            caption = "Box Height"
            alignment = swControlAlign_Indent
            options = swControlOptions_Visible + swControlOptions_Enabled
            tip = "Enter height of box."
            Set swControl = fb_Group1.AddControl(Id, controlType, caption, alignment, options, tip)
            If Not swControl Is Nothing Then
                Set fb_BoxHeight = swControl
                fb_BoxHeight.SetRange swNumberBox_Length, -1000#, 1000#, 0.0001, True
                fb_BoxHeight.Value = Part.Parameter("D1@Sketch1").SystemValue
            End If

            'CONTROL Number box - Box Width  ----------------------------------------
            Id = ID_fbBoxWidth
            controlType = swControlType_Numberbox
            caption = "Box Width"
            alignment = swControlAlign_Indent
            options = swControlOptions_Visible + swControlOptions_Enabled
            tip = "Enter width of box."
            Set swControl = fb_Group1.AddControl(Id, controlType, caption, alignment, options, tip)
            If Not swControl Is Nothing Then
                Set fb_BoxWidth = swControl
                fb_BoxWidth.SetRange swNumberBox_Length, -1000#, 1000#, 0.0001, True
                fb_BoxWidth.Value = Part.Parameter("D2@Sketch1").SystemValue
            End If

            'CONTROL Number box - Box Depth  ----------------------------------------
            Id = ID_fbBoxDepth
            controlType = swControlType_Numberbox
            caption = "Box Depth"
            alignment = swControlAlign_Indent
            options = swControlOptions_Visible + swControlOptions_Enabled
            tip = "Enter depth of box."
            Set swControl = fb_Group1.AddControl(Id, controlType, caption, alignment, options, tip)
            If Not swControl Is Nothing Then
                Set fb_BoxDepth = swControl
                fb_BoxDepth.SetRange swNumberBox_Length, -1000#, 1000#, 0.0001, True
                fb_BoxDepth.Value = Part.Parameter("D1@Extrude1").SystemValue
            End If

        End If
        
        'GROUP BOX ------------------------------------------------------------------
        Id = ID_fbGroup2
        caption = "Frame Parameters"
        options = swGroupBoxOptions_Visible + swGroupBoxOptions_Expanded
        Set fb_Group2 = fb_Page.AddGroupBox(Id, caption, options)
        If Not fb_Group2 Is Nothing Then
            'Place these controls in the second Group
            
            'CONTROL Number box - Frame Width ---------------------------------------
            Id = ID_fbFrameWidth
            controlType = swControlType_Numberbox
            caption = "Frame Width"
            alignment = swControlAlign_Indent
            options = swControlOptions_Visible + swControlOptions_Enabled
            tip = "Enter width of frame."
            Set swControl = fb_Group2.AddControl(Id, controlType, caption, alignment, options, tip)
            If Not swControl Is Nothing Then
                Set fb_FrameWidth = swControl
                fb_FrameWidth.SetRange swNumberBox_Length, -1000#, 1000#, 0.0001, True
                fb_FrameWidth.Value = Part.Parameter("D1@Sketch2").SystemValue
            End If

        End If
    Else
        swApp.SendMsgToUser2 "There was an error creating the Property Manager Page", swMbInformation, swMbOk
    End If
End Sub

Public Sub UpdateModel()
    ' Write new values back to model
    Dim CheckVal    As Double
    Dim Warn        As Boolean
        
    CheckVal = CDbl(fb_FrameWidth.Value * 2)
    If CheckVal >= CDbl(fb_BoxHeight.Value) Then Warn = True
    If CheckVal >= CDbl(fb_BoxWidth.Value) Then Warn = True
    If CheckVal >= CDbl(fb_BoxDepth.Value) Then Warn = True

    If Warn = False Then
        Part.Parameter("D1@Sketch1").SystemValue = fb_BoxHeight.Value
        Part.Parameter("D2@Sketch1").SystemValue = fb_BoxWidth.Value
        Part.Parameter("D1@Extrude1").SystemValue = fb_BoxDepth.Value
        Part.Parameter("D1@Sketch2").SystemValue = fb_FrameWidth.Value
        Part.Parameter("D1@Sketch3").SystemValue = fb_FrameWidth.Value
        Part.Parameter("D1@Sketch4").SystemValue = fb_FrameWidth.Value
        ' Rebuild model
        Part.ForceRebuild3 True
    '   Part.GraphicsRedraw2
    '   Part.ShowNamedView2 "*Isometric", 7
        Part.ViewZoomtofit
    Else
        MsgBox "Error in size relationship(s) between frame thickness and box dimension(s)." & Chr(13) & "Box sizes must be greater than 2x frame thickness.  Please try again.", vbExclamation
    End If
End Sub

'Display the Property Manager Page
Public Sub Show()
    Dim nRetVal             As Long
    Dim bRet                As Boolean
    
    nRetVal = fb_Page.Show
    fb_BoxHeight.Value = Part.Parameter("D1@Sketch1").SystemValue
    fb_BoxWidth.Value = Part.Parameter("D2@Sketch1").SystemValue
    fb_BoxDepth.Value = Part.Parameter("D1@Extrude1").SystemValue
    fb_FrameWidth.Value = Part.Parameter("D1@Sketch2").SystemValue
    
    ' broken:
    '   SPR 154819 - "PropertyManagerPage2::SetMessage returns TRUE but message is not set"
    bRet = fb_Page.SetMessage("Some Message String", swAnnotationVisible)
    Debug.Assert bRet
End Sub

'Generate the PropertyManagrePage and it's controls
Private Sub Class_Initialize()
    Layout
End Sub

Private Sub Class_Terminate()
    '
End Sub

'Callback that is called by PropertyManagerPage2Handler_OnButtonPress
'in the PropertyManagerPage2Handler class.
'This implementation just clears the selections.
'Public Sub OnButtonPressed(ByVal Id As Long)
'   Dim swApp                   As SldWorks.SldWorks
'   Dim swModel                 As SldWorks.ModelDoc2
'   Dim swSelMgr                As SldWorks.SelectionMgr
'   Dim nSelCount               As Long
'   Dim i                       As Long
'
'   If Id = ID_BUTTON Then
'       Set swApp = GetObject(, "SldWorks.Application")
'       Set swModel = swApp.ActiveDoc
'       Set swSelMgr = swModel.SelectionManager
'
'       nSelCount = swSelMgr.GetSelectedObjectCount
'       For i = 1 To nSelCount
'           Debug.Print "SelMark(" + Str(i) + ") =" + Str(swSelMgr.GetSelectedObjectMark(i))
'       Next i
'
'       ' this will dismiss the PMP
'       swModel.ClearSelection
'   End If
'End Sub

