fix: verify saved replacements through native netlist exports

This commit is contained in:
阿白叔 committed 2026-11-17 19:35:38 +08:00
1 parent d9cf6a07e9
commit d08a940afe
22 files changed
+1907 -177

No files matched your search

+187 -89
View File
@@ -29,6 +29,7 @@ Dim QP_ComponentUidIndex, QP_ComponentRefdesIndex, QP_ComponentLocationIndex
Dim QP_FallbackIdentityUsed
Dim QP_FallbackIdentityWarnings
Dim QP_ReferenceAliases
Dim QP_SavedNetlistMode
Dim QP_ComponentIndexContext
Dim QP_NativeCallActive
Dim QP_BatchMode, QP_OwnedProject, QP_BatchState, QP_BatchCode, QP_BatchMessage
@@ -162,7 +163,7 @@ WScript.Quit QP_ExitCode
Sub QPMain()
Dim Command
Dim SnapshotPath
Dim State
Dim State, ExistingRecords
If Not QP_Fso.FolderExists(QP_Root) Then
Err.Raise vbObjectError + 795, "QuickPartReplace", _
@@ -171,9 +172,11 @@ Sub QPMain()
Set Command = QPReadCommand(QP_Fso.BuildPath(QP_Root, "command.tsv"))
QP_CurrentJobId = CStr(Command("job_id"))
QPRequireProject Command
If QP_BatchMode And QP_SessionItems.Count = 0 And Not QP_Fso.FileExists(QP_Fso.BuildPath(QP_Root, "recovery.request")) Then _
QPVerifyExpectedBaselines CStr(Command("project_path"))
SnapshotPath = QPJobSnapshotPath(CStr(Command("job_id")))
QP_SavedNetlistMode = True
If QP_Fso.FileExists(SnapshotPath) Then Set ExistingRecords = QPReadSnapshot(SnapshotPath)
If Not QP_SavedNetlistMode And QP_BatchMode And QP_SessionItems.Count = 0 And Not QP_Fso.FileExists(QP_Fso.BuildPath(QP_Root, "recovery.request")) Then _
QPVerifyExpectedBaselines CStr(Command("project_path"))
State = QPReadState(QP_Fso.BuildPath(QP_Root, "status.tsv"), _
CStr(Command("job_id")))
@@ -438,7 +441,7 @@ Sub QPRequireSessionCheckpoint()
Err.Raise vbObjectError + 873, "QuickPartReplace.ProjectSession", "owned sheet set changed at checkpoint"
If CStr(View.GetName(0)) <> QP_CheckpointSchematic Or CStr(View.Block.SheetNum) <> QP_CheckpointSheet Then _
Err.Raise vbObjectError + 873, "QuickPartReplace.ProjectSession", "active sheet changed at checkpoint"
If QP_SessionSheets.Exists(QPSheetKey(QP_CheckpointSchematic, QP_CheckpointSheet)) Then _
If Not QP_SavedNetlistMode And QP_SessionSheets.Exists(QPSheetKey(QP_CheckpointSchematic, QP_CheckpointSheet)) Then _
QPRequireExpectedState QP_SessionSheets.Item(QPSheetKey(QP_CheckpointSchematic, QP_CheckpointSheet)), QPCurrentSemanticState()
End Sub
@@ -1156,6 +1159,7 @@ Sub QPVerifyFailedOriginalSnapshot()
Set Command = QPReadCommand(QP_Fso.BuildPath(QP_Root, "command.tsv"))
QPRequireCommandSnapshot Command, SnapshotPath
Set Records = QPReadSnapshot(SnapshotPath)
If QP_SavedNetlistMode Then Exit Sub
QPInvalidatePinIndex
QPInvalidateComponentIndex
For Index = 0 To Records.Item("components").Count - 1
@@ -1182,6 +1186,14 @@ Sub QPFinishBatchItem()
Set Command = QPReadCommand(QP_Fso.BuildPath(QP_Root, "command.tsv"))
QP_BatchState = FinalState
TargetPath = CStr(Command("project_path"))
If QP_SavedNetlistMode Then
If FinalState = "restored_ok" Then QPMarkBatchMutation Command
QPCloseBatchProject TargetPath, (FinalState = "restored_ok")
QP_BatchMode = False
If FinalState = "restored_ok" Then FinalState = "pending_save"
QPWriteStatus QP_Root, QP_CurrentJobId, FinalState, "project_saved", "Engineering project saved and closed; awaiting saved native data verification."
Exit Sub
End If
If FinalState = "restored_ok" Then
SnapshotPath = QPJobSnapshotPath(QP_CurrentJobId)
QPRequireCommandSnapshot Command, SnapshotPath
@@ -1273,20 +1285,23 @@ Sub QPStageSessionItem()
If FinalState = "restored_ok" Then
Set Records = QPReadSnapshot(QPJobSnapshotPath(QP_CurrentJobId))
QPRequireCommandSnapshot Command, QPJobSnapshotPath(QP_CurrentJobId)
QPVerifyUntouched Records
Set ValueStates = CreateObject("Scripting.Dictionary")
For Index = 0 To Records.Item("components").Count - 1
Set Record = Records.Item("components").Item(CStr(Index))
Set Candidate = QPFindUniqueByOldLocation(Record)
ValueStates.Add CStr(Index), QPCaptureValueState(Candidate)
QPSetRequiredNc ValueStates.Item(CStr(Index)), Record, Records.Item("attributes"), QPSyncNc(Command)
ValueStates.Item(CStr(Index)).Add "custom_value", QPCustomValue(Command)
Next
If Not QP_SavedNetlistMode Then
QPVerifyUntouched Records
Set ValueStates = CreateObject("Scripting.Dictionary")
For Index = 0 To Records.Item("components").Count - 1
Set Record = Records.Item("components").Item(CStr(Index))
Set Candidate = QPFindUniqueByOldLocation(Record)
ValueStates.Add CStr(Index), QPCaptureValueState(Candidate)
QPSetRequiredNc ValueStates.Item(CStr(Index)), Record, Records.Item("attributes"), QPSyncNc(Command)
ValueStates.Item(CStr(Index)).Add "custom_value", QPCustomValue(Command)
Next
Item.Add "value_states", ValueStates
End If
Item.Add "snapshot_path", QPJobSnapshotPath(QP_CurrentJobId)
Item.Add "value_states", ValueStates
End If
Item.Add "saved_netlist", CBool(QP_SavedNetlistMode)
QP_SessionItems.Add QP_CurrentJobId, Item
QP_SessionSheets.Item(QPSheetKey(Item("schematic"), Item("sheet"))) = QPCurrentSemanticState()
If Not QP_SavedNetlistMode Then QP_SessionSheets.Item(QPSheetKey(Item("schematic"), Item("sheet"))) = QPCurrentSemanticState()
QP_BatchMode = False
QP_NativeMutationPossible = False
QP_SessionExternalChange = False
@@ -1295,7 +1310,7 @@ Sub QPStageSessionItem()
QP_SessionWaiting = True
Code = "session_staged"
If FinalState = "no_match" Then Code = "session_staged_no_match"
QPWriteStatus QP_Root, QP_CurrentJobId, "pending_save", Code, "Verified in memory; awaiting engineering project save and readback."
QPWriteStatus QP_Root, QP_CurrentJobId, "pending_save", Code, "Writes staged; awaiting engineering project save and saved native data verification."
QPWriteUtf8 QP_Fso.BuildPath(QP_Root, "project-session-result.tsv"), _
QP_SessionToken & vbTab & QP_CurrentJobId & vbTab & "pending_save" & vbTab & Code
End Sub
@@ -1314,6 +1329,13 @@ Sub QPCommitSessionProject()
QP_SessionCommitActive = True
QP_FailureCleanupActive = True
QP_BatchMode = True
If QP_SavedNetlistMode Then
QPCommitSavedNetlistProject
QP_SessionCommitActive = False
QP_FailureCleanupActive = False
QP_BatchMode = False
Exit Sub
End If
HasChanges = False
Set VerifiedSheets = CreateObject("Scripting.Dictionary")
' Capture the final memory state once per sheet, including later replacements.
@@ -1384,6 +1406,32 @@ Sub QPCommitSessionProject()
QP_BatchMode = False
End Sub
Sub QPCommitSavedNetlistProject()
Dim Job, Item, Manifest, HasChanges, FinalState
HasChanges = False
For Each Job In QP_SessionItems.Keys
Set Item = QP_SessionItems.Item(Job)
If Not Item("saved_netlist") Then Err.Raise vbObjectError + 871, "QuickPartReplace.Batch", "mixed project validation protocols"
If Item("final_state") = "restored_ok" Then HasChanges = True
Next
QPCloseBatchProject QP_SessionProject, HasChanges
QP_SessionDocuments.RemoveAll
Manifest = QP_SessionToken & vbTab & QPEncode(QP_SessionProject) & vbTab & "project_saved" & vbCrLf
For Each Job In QP_SessionItems.Keys
Set Item = QP_SessionItems.Item(Job)
FinalState = "no_match"
If Item("final_state") = "restored_ok" Then FinalState = "pending_save"
Manifest = Manifest & CStr(Job) & vbTab & FinalState & vbCrLf
Next
QPWriteUtf8 QP_Fso.BuildPath(QP_Root, "project-commit-" & QP_SessionToken & ".tsv"), Manifest
For Each Job In QP_SessionItems.Keys
Set Item = QP_SessionItems.Item(Job)
FinalState = "no_match"
If Item("final_state") = "restored_ok" Then FinalState = "pending_save"
QPWriteStatus QP_Root, CStr(Job), FinalState, "project_saved", "Engineering project saved and closed; awaiting saved native data verification."
Next
End Sub
Function QPCurrentSemanticState()
Dim Components, Comp, State, Count
QPInvalidatePinIndex
@@ -1466,6 +1514,7 @@ Function QPComparableState(ByVal Text)
End Function
Sub QPWriteVerifiedState(ByRef Command)
If QP_SavedNetlistMode Then Exit Sub
QPWriteSemanticState Command, QPCurrentSemanticState()
End Sub
@@ -1572,7 +1621,7 @@ Sub QPAutomaticReplaceAndRestore(ByRef Command, ByVal SnapshotPath)
Err.Clear
On Error GoTo 0
If ErrorNumber <> 0 Then
If QP_NativeMutationPossible And Not QP_BatchMode Then
If QP_NativeMutationPossible And Not QP_BatchMode And Not QP_SavedNetlistMode Then
On Error Resume Next
QPRollbackNativeReplacement SnapshotPath
If Err.Number <> 0 Then
@@ -1585,6 +1634,8 @@ Sub QPAutomaticReplaceAndRestore(ByRef Command, ByVal SnapshotPath)
ErrorDescription = "Replacement validation failed; native rollback was verified and the original sheet state was restored. No replacement remains. Original failure: " & ErrorDescription
End If
On Error GoTo 0
ElseIf QP_NativeMutationPossible And QP_SavedNetlistMode Then
ErrorDescription = "Replacement writes may have been applied; persisted outcome requires saved native data verification. " & ErrorDescription
ElseIf QP_NativeMutationPossible And QP_BatchMode Then
ErrorDescription = "Replacement validation failed; batch mode kept the native result unsaved and closed the failed project. " & ErrorDescription
End If
@@ -1699,8 +1750,9 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
Dim PartNumber
Dim Snapshot
Dim Index
Dim Selectors, Selector, SelectorUid, FoundSelectors, Uid, ValueAttr, ValueText, MatchedUids, UntouchedCount, NativeRead, AlreadyTargets
Dim Selectors, Selector, SelectorUid, FoundSelectors, Uid, ValueAttr, ValueText, AlreadyTargets
QP_SavedNetlistMode = True
QP_FallbackIdentityUsed = False
Set QP_FallbackIdentityWarnings = CreateObject("Scripting.Dictionary")
If StrComp(CStr(Command("old_part_number")), CStr(Command("new_part_number")), vbTextCompare) = 0 Then _
@@ -1782,49 +1834,15 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
Snapshot = Snapshot & vbCrLf
If Len(QPTargetCell(Command)) > 0 Then _
Snapshot = Snapshot & "L" & vbTab & QPEncode(QPTargetCell(Command)) & vbCrLf
Set MatchedUids = CreateObject("Scripting.Dictionary")
For Index = 0 To Matches.Count - 1
Set Comp = Matches.Item(CStr(Index))
QPRequireUniqueAttributeNames Comp
MatchedUids.Add QPComponentIdentityKey(Comp), True
Next
Set NativeRead = Nothing
If QPUseNativeSnapshot() And Not QP_FallbackIdentityUsed Then
QPRequireProject Command
Set NativeRead = QPNativeCapture(MatchedUids)
If Not NativeRead Is Nothing Then
If NativeRead("total") <> Components.Count Then _
Err.Raise vbObjectError + 875, "QuickPartReplace.NativeRead", "component count changed during capture"
End If
End If
For Index = 0 To Matches.Count - 1
Set Comp = Matches.Item(CStr(Index))
Uid = QPComponentIdentityKey(Comp)
QPLog QP_Root, "INFO", "stage=snapshot_component uid=" & QPLogField(Uid)
If NativeRead Is Nothing Then
Snapshot = Snapshot & QPSnapshotComponent(Comp)
Else
QPRequireNativeCapturedTarget CStr(NativeRead("selected")(Uid)), Command, Uid, Selectors
Snapshot = Snapshot & CStr(NativeRead("selected")(Uid))
End If
Snapshot = Snapshot & QPSnapshotComponent(Comp)
QPProgress "capture", Index + 1, Matches.Count
Next
' U remains the seven-field native-helper identity baseline. X/G extend it
' with complete unselected state for every scope, including all-match jobs.
Snapshot = Snapshot & "X" & vbTab & "untouched_full_v1" & vbCrLf
UntouchedCount = 0
If NativeRead Is Nothing Then
For Each Comp In Components
If Not MatchedUids.Exists(QPComponentIdentityKey(Comp)) Then
QPProgress "capture_untouched", UntouchedCount, Components.Count - Matches.Count
Snapshot = Snapshot & QPUntouchedComponent(Comp)
UntouchedCount = UntouchedCount + 1
QPProgress "capture_untouched", UntouchedCount, Components.Count - Matches.Count
End If
Next
Else
Snapshot = Snapshot & CStr(NativeRead("text"))
End If
Snapshot = Snapshot & "X" & vbTab & "saved_netlist_v1" & vbCrLf
QPWriteUtf8 SnapshotPath, Snapshot
For Each Comp In Components
@@ -2110,8 +2128,12 @@ Function QPSnapshotComponent(ByRef Comp)
Identity = QPComponentIdentityKey(Comp)
Set Point = Comp.GetLocation()
Set Pins = QPComponentPins(Identity)
Connections = QPConnectionSignatureFromPins(Identity, Pins)
If QP_SavedNetlistMode Then
Connections = "NETLIST"
Else
Set Pins = QPComponentPins(Identity)
Connections = QPConnectionSignatureFromPins(Identity, Pins)
End If
Result = "C" & vbTab & QPEncode(Identity) & vbTab & _
QPEncode(CStr(Comp.Refdes)) & vbTab & QPEncode(CStr(Point.X)) & _
vbTab & QPEncode(CStr(Point.Y)) & vbTab & _
@@ -2278,10 +2300,9 @@ Sub QPRestoreAfterOperatorReplace(ByRef Command, ByVal SnapshotPath)
QPProgress "restore_preflight", 0, 0
Set Records = QPReadSnapshot(SnapshotPath)
QPRequireCommandSnapshot Command, SnapshotPath
' Owned batches perform full-page checks immediately before saving and
' after disk reopen in QPFinishBatchItem, before publishing completion.
' Manual restoration keeps full checks on both sides of its writes.
If Not QP_BatchMode Then QPVerifyUntouched Records
' Saved-native jobs validate persisted results after the engineering close.
' Legacy manual snapshots keep the original checks around restoration.
If Not QP_BatchMode And Not QP_SavedNetlistMode Then QPVerifyUntouched Records
Set Meta = Records.Item("meta")
If QPCanonicalPath(CStr(Meta("project_path"))) <> QPCanonicalPath(QPProjectPath()) Or _
CStr(Meta("sheet_name")) <> QPSheetIdentity() Then _
@@ -2359,9 +2380,14 @@ Sub QPRestoreAfterOperatorReplace(ByRef Command, ByVal SnapshotPath)
" Target Cell verified: " & QPTargetCell(Command) & "."
If Len(QP_NcSyncSummary) > 0 Then SuccessMessage = SuccessMessage & _
" NC synced: " & QP_NcSyncSummary
If Not QP_BatchMode Then QPWriteValueReadback Command, Records, Plans, "restored_ok"
If QP_SavedNetlistMode Then SuccessMessage = "Replacement and attribute writes applied; awaiting saved native data verification. Replacements: " & ReplacementSummary
If Not QP_BatchMode And Not QP_SavedNetlistMode Then QPWriteValueReadback Command, Records, Plans, "restored_ok"
QPWriteStatus QP_Root, CStr(Command("job_id")), "restored_ok", "", SuccessMessage
QPLog QP_Root, "INFO", "verified replacement count=" & Plans.Count & " value_mode=" & QPValueMode(Command)
If QP_SavedNetlistMode Then
QPLog QP_Root, "INFO", "applied replacement count=" & Plans.Count & " value_mode=" & QPValueMode(Command)
Else
QPLog QP_Root, "INFO", "verified replacement count=" & Plans.Count & " value_mode=" & QPValueMode(Command)
End If
End Sub
Function QPReplacementSummary(ByRef Records, ByRef Plans, ByVal OldPartNumber, ByVal NewPartNumber)
@@ -2389,13 +2415,18 @@ Sub QPRestorePlans(ByRef Command, ByRef Records, ByRef Plans)
ValueStates.Add CStr(Index), QPCaptureValueState(Candidate)
QPSetRequiredNc ValueStates.Item(CStr(Index)), ComponentRecord, Records.Item("attributes"), QPSyncNc(Command)
ValueStates.Item(CStr(Index)).Add "custom_value", QPCustomValue(Command)
Next
If QP_SavedNetlistMode Then QPWriteWriterExpectations Command, Records, ValueStates
For Index = 0 To Plans.Count - 1
Set ComponentRecord = Records.Item("components").Item(CStr(Index))
Set Candidate = Plans.Item(CStr(Index))
QPRestoreComponent Candidate, ComponentRecord, Records.Item("attributes"), _
QPValueMode(Command), QPCustomValue(Command), QPSyncNc(Command)
QPSetTargetCell Candidate, Command
QPProgress "restore_attributes", Index + 1, Plans.Count
Next
QPVerifyRestoredPlans Command, Records, Plans, ValueStates
If Not QP_BatchMode Then QPVerifyUntouched Records
If Not QP_SavedNetlistMode Then QPVerifyRestoredPlans Command, Records, Plans, ValueStates
If Not QP_BatchMode And Not QP_SavedNetlistMode Then QPVerifyUntouched Records
End Sub
Sub QPVerifyRestoredPlans(ByRef Command, ByRef Records, ByRef Plans, ByRef ValueStates)
@@ -2441,6 +2472,7 @@ Sub QPRecoverSavedJob(ByRef Command, ByVal SnapshotPath)
Dim Records, Plans, Used, ValueStates, Index, Record, Candidate, PartNumber
Dim OldCount, NewCount, ErrorNumber, ErrorDescription, RecoveryDocuments, RecoveryDocument, RecoveryProjectData, SourceOnly
QPRequireCommandSnapshot Command, SnapshotPath
If QP_SavedNetlistMode Then Err.Raise vbObjectError + 865, "QuickPartReplace.Recovery", "saved native snapshot requires saved database verification; no CAD replay allowed"
SourceOnly = False
If Command.Exists("recovery_source_only") Then
If CStr(Command("recovery_source_only")) <> "1" Then _
@@ -2602,15 +2634,17 @@ Sub QPRestorePreflight(ByRef Comp, ByRef ComponentRecord, _
Err.Raise vbObjectError + 800, "QuickPartReplace", _
"replacement Part Number does not equal command target"
End If
CurrentConnections = QPConnectionSignature(Comp)
SavedConnections = CStr(ComponentRecord("connections"))
If Not QPConnectionsMatch(CurrentConnections, SavedConnections) Then
QPLog QP_Root, "ERROR", "connection_mismatch uid=" & _
CStr(ComponentRecord("uid")) & " saved=" & _
QPLogField(SavedConnections) & " current=" & _
QPLogField(CurrentConnections)
Err.Raise vbObjectError + 804, "QuickPartReplace", _
"connection validation failed"
If Not QP_SavedNetlistMode Then
CurrentConnections = QPConnectionSignature(Comp)
If Not QPConnectionsMatch(CurrentConnections, SavedConnections) Then
QPLog QP_Root, "ERROR", "connection_mismatch uid=" & _
CStr(ComponentRecord("uid")) & " saved=" & _
QPLogField(SavedConnections) & " current=" & _
QPLogField(CurrentConnections)
Err.Raise vbObjectError + 804, "QuickPartReplace", _
"connection validation failed"
End If
End If
For Index = 0 To Attributes.Count - 1
Set Record = Attributes.Item(CStr(Index))
@@ -2763,9 +2797,11 @@ Sub QPRestoreComponent(ByRef Comp, ByRef ComponentRecord, ByRef Attributes, _
Comp.Scale = CDbl(ComponentRecord("scale"))
Comp.SetLocation CLng(ComponentRecord("x")), CLng(ComponentRecord("y"))
Comp.Refdes = CStr(ComponentRecord("refdes"))
If StrComp(CStr(Comp.Refdes), CStr(ComponentRecord("refdes")), _
vbBinaryCompare) <> 0 Then
Err.Raise vbObjectError + 803, "QuickPartReplace", "Refdes restore failed"
If Not QP_SavedNetlistMode Then
If StrComp(CStr(Comp.Refdes), CStr(ComponentRecord("refdes")), _
vbBinaryCompare) <> 0 Then
Err.Raise vbObjectError + 803, "QuickPartReplace", "Refdes restore failed"
End If
End If
LabelValue = ""
HasOldNc = False
@@ -2786,8 +2822,10 @@ Sub QPRestoreComponent(ByRef Comp, ByRef ComponentRecord, ByRef Attributes, _
Else
Attr.InstanceValue = CStr(Record("value"))
End If
If QPEffectiveAttributeValue(Attr) <> QPSavedEffectiveValue(Record) Then _
Err.Raise vbObjectError + 834, "QuickPartReplace", "instance attribute readback failed"
If Not QP_SavedNetlistMode Then
If QPEffectiveAttributeValue(Attr) <> QPSavedEffectiveValue(Record) Then _
Err.Raise vbObjectError + 834, "QuickPartReplace", "instance attribute readback failed"
End If
End If
If Attr Is Nothing Then
If Not QPNativeAttributeAbsenceAllowed(CStr(Record("name")), ValueMode) Then _
@@ -2879,13 +2917,14 @@ Sub QPRestoreComponent(ByRef Comp, ByRef ComponentRecord, ByRef Attributes, _
Err.Raise ErrorNumber, ErrorSource, ErrorDescription
End If
End If
If StrComp(QPEffectiveAttributeValue(ValueAttr), LabelValue, _
vbBinaryCompare) <> 0 Then
Err.Raise vbObjectError + 818, "QuickPartReplace", _
"Value readback does not equal the selected source"
If Not QP_SavedNetlistMode Then
If StrComp(QPEffectiveAttributeValue(ValueAttr), LabelValue, _
vbBinaryCompare) <> 0 Then
Err.Raise vbObjectError + 818, "QuickPartReplace", _
"Value readback does not equal the selected source"
End If
End If
If HasOldNc Then QPRecordNcSync Comp, QPSavedEffectiveValue(ValueRecord), _
QPEffectiveAttributeValue(ValueAttr)
If HasOldNc Then QPRecordNcSync Comp, QPSavedEffectiveValue(ValueRecord), LabelValue
End Sub
Function QPComponentIdentity(ByRef Comp)
@@ -3003,7 +3042,7 @@ Sub QPSetTargetCell(ByRef Comp, ByRef Command)
If Attr Is Nothing Then Err.Raise vbObjectError + 878, _
"QuickPartReplace.Cell", "replaced target has no Cell Name attribute"
Attr.InstanceValue = Value
QPVerifyTargetCell Comp, Command
If Not QP_SavedNetlistMode Then QPVerifyTargetCell Comp, Command
End Sub
Sub QPVerifyTargetCell(ByRef Comp, ByRef Command)
@@ -3063,6 +3102,40 @@ Function QPCaptureValueState(ByRef Comp)
Set QPCaptureValueState = State
End Function
Sub QPWriteWriterExpectations(ByRef Command, ByRef Records, ByRef ValueStates)
Dim Text, Index, Record, Before, ExpectedValue, ExpectedExists, Mode
Text = "W" & vbTab & "1" & vbTab & QPEncode(CStr(Command("task_id"))) & vbTab & _
QPEncode(CStr(Command("job_id"))) & vbTab & QPEncode(CStr(Command("project_path"))) & vbTab & _
QPEncode(CStr(QP_App.ActiveView.GetName(0))) & vbTab & QPEncode(CStr(QP_App.ActiveView.Block.SheetNum)) & vbTab & _
QPEncode(QPReadUtf8(QPJobSnapshotPath(Command("job_id")))) & vbCrLf
Mode = QPValueMode(Command)
For Index = 0 To Records.Item("components").Count - 1
Set Record = Records.Item("components").Item(CStr(Index))
Set Before = ValueStates.Item(CStr(Index))
ExpectedExists = True
Select Case Mode
Case "preserve"
ExpectedValue = Before("value")
ExpectedExists = Before("exists")
Case "custom"
ExpectedValue = QPCustomValue(Command)
Case "part_number"
ExpectedValue = CStr(Command("new_part_number"))
Case Else
ExpectedValue = Before("part_label")
End Select
If Before("nc_required") Then
ExpectedValue = QPAppendNcMarker(ExpectedValue)
ExpectedExists = True
End If
Text = Text & "C" & vbTab & QPEncode(CStr(Record("uid"))) & vbTab & QPEncode(CStr(Record("refdes"))) & vbTab & _
QPEncode(CStr(ExpectedValue)) & vbTab & QPBooleanText(ExpectedExists) & vbTab & _
QPEncode(CStr(Before("part_name"))) & vbTab & QPEncode(CStr(Before("part_label"))) & vbTab & _
QPEncode(CStr(Command("new_part_number"))) & vbTab & QPEncode(QPTargetCell(Command)) & vbCrLf
Next
QPWriteUtf8 QP_Fso.BuildPath(QP_Root, "writer-expectations-" & CStr(Command("job_id")) & ".tsv"), Text
End Sub
Sub QPVerifyValuePolicy(ByRef Comp, ByVal ValueMode, ByRef Before)
Dim Current, SourceName, ExpectedValue, ExpectedExists
If ValueMode = "preserve" Then
@@ -3239,7 +3312,7 @@ Sub QPRestoreDisplay(ByRef Attr, ByRef Record, ByVal Refdes)
Attr.Orientation = CLng(Record("orientation"))
Attr.Visible = CLng(Record("visible"))
Attr.SetLocation CLng(Record("x")), CLng(Record("y"))
QPVerifyDisplay Attr, Record, Refdes
If Not QP_SavedNetlistMode Then QPVerifyDisplay Attr, Record, Refdes
End Sub
Sub QPVerifyDisplay(ByRef Attr, ByRef Record, ByVal Refdes)
@@ -3744,8 +3817,11 @@ Function QPReadSnapshot(ByVal Path)
Dim Fields
Dim Index
Dim Record
Dim Meta
Dim Meta, Protocol, SelectedUids, UnknownRecord
Protocol = ""
UnknownRecord = False
QP_SavedNetlistMode = False
Set Result = CreateObject("Scripting.Dictionary")
Set Components = CreateObject("Scripting.Dictionary")
Set Attributes = CreateObject("Scripting.Dictionary")
@@ -3822,20 +3898,42 @@ Function QPReadSnapshot(ByVal Path)
QP_ReferenceAliases.Add LCase(Meta("sheet_name") & "|" & Trim(QPDecode(Fields(2)))),QPDecode(Fields(1))
End If
Case "X"
If UBound(Fields) <> 1 Or Fields(1) <> "untouched_full_v1" Then _
Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "invalid unselected-state protocol"
Result.Add "untouched_full_version", CStr(Fields(1))
If UBound(Fields) <> 1 Then Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "invalid snapshot protocol"
If Len(Protocol) > 0 Or (Fields(1) <> "untouched_full_v1" And Fields(1) <> "saved_netlist_v1") Then _
Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "invalid snapshot protocol"
Protocol = CStr(Fields(1))
If Protocol = "untouched_full_v1" Then Result.Add "untouched_full_version", Protocol
Case "G"
If UBound(Fields) <> 2 Or Len(QPDecode(Fields(1))) = 0 Or Len(QPDecode(Fields(2))) = 0 Then _
Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "invalid unselected full-state snapshot"
UntouchedFull.Add QPDecode(Fields(1)), QPDecode(Fields(2))
If Result.Exists("meta") Then QPBindSnapshotFullState Meta("sheet_name"),QPDecode(Fields(2))
Case Else
UnknownRecord = True
End Select
End If
Next
If Not Result.Exists("meta") Or Components.Count = 0 Or Attributes.Count = 0 Then
Err.Raise vbObjectError + 815, "QuickPartReplace", "incomplete snapshot"
End If
If Protocol = "saved_netlist_v1" Then
If UnknownRecord Or Untouched.Count <> 0 Or UntouchedFull.Count <> 0 Then _
Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "saved native snapshot contains unselected records"
For Each Index In Components.Keys
If Components.Item(Index)("connections") <> "NETLIST" Then _
Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "saved native snapshot has CAD connection data"
Next
Set SelectedUids = CreateObject("Scripting.Dictionary")
For Each Index In Components.Keys
SelectedUids.Add Components.Item(Index)("uid"), True
Next
For Each Index In Attributes.Keys
If Not SelectedUids.Exists(Attributes.Item(Index)("uid")) Then _
Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "saved native snapshot attribute is outside targets"
Next
QP_SavedNetlistMode = True
End If
Result.Add "saved_netlist", QP_SavedNetlistMode
Result.Add "components", Components
Result.Add "attributes", Attributes
Result.Add "untouched", Untouched