DigiPara Liftdesigner LDX API
Loading...
Searching...
No Matches
CalculateModelBarrier

API method: ILDXDocument5.CalculateModelBarrierRelease

5 code examples follow.

Example 1: Deferred CalculateModel: 1. No change

 ' from Samples/Src/LDXAPIExamples/Example_LDXDocument.vb


 ' *********************************************************
 ' A common problem with the classic LDXDocument.CalculateModel()-Function and the 
 ' LDXSheet(Frame).Build(Sheet)()-Function for UI and client code is this:
 ' When do you call it? Do you call it after every change? Do you call it before you need updated
 ' values or drawings? Doing any of that gives correct results, but leads to too many
 ' update calls and low performance. Really, you need to call CalculateModel() sometime
 ' between the data change and the time you need the updated data or drawing. To
 ' find that point in the code can be quite tricky and require extra plumbing you do not want.
 ' 
 ' Therefore, now Document, Sheet and SheetFrame have each a pair of functions:
 ' After a change that requires a rebuild/recalc, you call CalculateModelBarrierRelease()
 ' Before you need updated values/drawings, you call CalculateModelBarrierAcquire()
 ' (The names are taken from multithreaded programming using atomics; there you also
 ' release a barrier after writing a value and acquire a barrier before reading)
 ' Internally, we will then call the appropriate CalculateModel() and Build() functions
 ' in CalculateModelBarrierAcquire(), having noted from the previous calls to 
 ' CalculateModelBarrierRelease() which parts need updating.
 '
 ' On to the samples:
 ' *********************************************************

 ' helper function, do BarrierAcquire and make notes of results
 Private Shared Function DocumentAcquire(ldxDocument As DigiPara.LDX.LDXDocument) As String
     Dim start As System.DateTime = System.DateTime.Now
     Dim log As String = ""

     ' this makes sure the document is up to date.
     ' the return value of the Acquire() functions indicates whether work was done.
     If ldxDocument.CalculateModelBarrierAcquire() Then
         log &= "Model calculated." & vbCrLf
     End If

     ' this makes sure the current sheet is up to date.
     ' note: normally, if you're going to call this, you do not need the ldxDocument.CalculateModelBarrierAcquire() call above,
     ' it is implicitly contained in this. Likewise, if you ONLY are interested in model changes right now, omit the 
     ' LDXSheet.CalculateModelBarrierAcquire() call.
     If ldxDocument.Sheets.ActiveSheet.CalculateModelBarrierAcquire() Then
         log &= "Sheet rebuilt." & vbCrLf
     End If

     Dim duration = System.DateTime.Now - start
     log &= String.Format("CalculateModelBarrierAcquire Duration: {0} ms" & vbCrLf, duration.TotalMilliseconds)
     DocumentAcquire = log
 End Function

 ' helper function, do a BarrierAcquire requesting only a bare minimal recalc (single pass, no RefModel) for speed.
 ' if you're doing 'just in case we need them' updates to the whole document in your RefModel code, this
 ' would be the way to do them.
 Private Shared Function DocumentAcquireMinimal(ldxDocument As DigiPara.LDX.LDXDocument) As String
     Dim start As System.DateTime = System.DateTime.Now
     Dim log As String = ""

     ' this makes sure the document is up to date, requesting minimal updates only.
     ' the return value of the Acquire() functions indicates whether work was done.
     If ldxDocument.CalculateModelBarrierAcquire(DigiPara.LDX.CalculateModelBarrierModes.cmbmDefaultReleaseModelChangeLDXOnlyQuick) Then
         log &= "Model calculated." & vbCrLf
     End If

     Dim duration = System.DateTime.Now - start
     log &= String.Format("CalculateModelBarrierAcquire Duration: {0} ms" & vbCrLf, duration.TotalMilliseconds)
     DocumentAcquireMinimal = log
 End Function

 ' helper function, do a model change
 Private Shared Sub DocumentReleaseModelChange(ldxDocument As DigiPara.LDX.LDXDocument)
     Dim start As System.DateTime = System.DateTime.Now

     ' do some change to the document that requires a CalculateModel
     With ldxDocument.Shaft.Car
         If .CD < 3000 Then
             .CD = .CD + 1000
         Else
             .CD = .CD - 700
         End If
     End With

     ' this informs the document that it should do a CalculateModel and drawing update at some later time
     ldxDocument.CalculateModelBarrierRelease()
 End Sub

 <APIHelpAttribute(APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXDoc}, "", "LDXDocument~CalculateModelBarrierRelease", "Deferred CalculateModel: 1. No change")>
 Public Shared Sub CalculateModelBarrierNoChange(ldxDocument As DigiPara.LDX.LDXDocument)
     If ldxDocument Is Nothing Then
         MsgBox("Active document not found!")
         Exit Sub
     End If

     Dim message As String = "When nothing is changed:" & vbCrLf
     message &= DocumentAcquire(ldxDocument)

     If message.Contains("Sheet") Then
         message &= "(The sheet rebuild likely only happened because the document was" & vbCrLf & "freshly loaded, rerun the sample and it should not happen again.)"
     End If

     MsgBox(message)
 End Sub

Example 2: Deferred CalculateModel: 2. Model change

 ' from Samples/Src/LDXAPIExamples/Example_LDXDocument.vb

    <APIHelpAttribute(APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXDoc}, "", "LDXDocument~CalculateModelBarrierRelease", "Deferred CalculateModel: 2. Model change")>
 Public Shared Sub CalculateModelBarrierModelChange(ldxDocument As DigiPara.LDX.LDXDocument)
     If ldxDocument Is Nothing Then
         MsgBox("Active document not found!")
         Exit Sub
     End If

     DocumentReleaseModelChange(ldxDocument)

     Dim message As String = "When model data is changed:" & vbCrLf
     message &= DocumentAcquire(ldxDocument)

     MsgBox(message)
 End Sub

Example 3: Deferred CalculateModel: 3. Drawing change

 ' from Samples/Src/LDXAPIExamples/Example_LDXDocument.vb

    <APIHelpAttribute(APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXDoc}, "", "LDXDocument~CalculateModelBarrierRelease", "Deferred CalculateModel: 3. Drawing change")>
 Public Shared Sub CalculateModelBarrierDrawingChange(ldxDocument As DigiPara.LDX.LDXDocument)
     If ldxDocument Is Nothing Then
         MsgBox("Active document not found!")
         Exit Sub
     End If

     ' activate the right sheet frame (for the default document)
     ldxDocument.Sheets.Item(1)?.Activate()
     ldxDocument.Sheets.Item(1)?.Item(1)?.Activate()

     With ldxDocument.Sheets.ActiveSheet.ActiveSheetFrame
         ' do some change to the drawing: toggle cars, doors and car frame
         .VisibleProductGroups = .VisibleProductGroups Xor DigiPara.LDX.SheetFrameProductGroups.shfpCarAndDoors Xor DigiPara.LDX.SheetFrameProductGroups.shfpCarFrame

         ' note that the drawing needs a rebuild from the change
         .CalculateModelBarrierRelease()
     End With

     Dim message As String = "When drawing parameters are changed:" & vbCrLf
     message &= DocumentAcquire(ldxDocument)

     MsgBox(message)
 End Sub

Example 4: Deferred CalculateModel: 4. Model change, no acquire

 ' from Samples/Src/LDXAPIExamples/Example_LDXDocument.vb

    <APIHelpAttribute(APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXDoc}, "", "LDXDocument~CalculateModelBarrierRelease", "Deferred CalculateModel: 4. Model change, no acquire")>
 Public Shared Sub CalculateModelBarrierModelChangeNoAcquire(ldxDocument As DigiPara.LDX.LDXDocument)
     If ldxDocument Is Nothing Then
         MsgBox("Active document not found!")
         Exit Sub
     End If

     DocumentReleaseModelChange(ldxDocument)

     Dim message As String = "We changed the model, but did not call CalculateModelBarrierRelease()."
     message &= vbCrLf & "No model or drawing update has happened until now."
     message &= vbCrLf & "But the drawing display code is calling CalculateModelBarrierRelease(), so you should see"
     message &= "the update take effect as soon as the drawing view gets refreshed."
     MsgBox(message)
 End Sub

Example 5: Deferred CalculateModel: 5. Model change, minimal recalc

 ' from Samples/Src/LDXAPIExamples/Example_LDXDocument.vb

    <APIHelpAttribute(APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXDoc}, "", "LDXDocument~CalculateModelBarrierRelease", "Deferred CalculateModel: 5. Model change, minimal recalc")>
 Public Shared Sub CalculateModelBarrierModelChangeMinimal(ldxDocument As DigiPara.LDX.LDXDocument)
     If ldxDocument Is Nothing Then
         MsgBox("Active document not found!")
         Exit Sub
     End If

     DocumentReleaseModelChange(ldxDocument)

     Dim message As String = "When model data is changed and only a minimal recalc is requested:" & vbCrLf
     message &= DocumentAcquireMinimal(ldxDocument)

     MsgBox(message)

     ' but we do want the drawings to update as well before we leave
     ldxDocument.Sheets.ActiveSheet.CalculateModelBarrierAcquire()
 End Sub