merge: preserve main safety fixes in acrylic workspace

This commit is contained in:
阿白叔 committed 2026-10-31 14:07:20 +08:00
commit a41c6cf928
56 files changed
+2734 -169

No files matched your search

@@ -222,7 +222,7 @@ Function QPNativeCollectMode(ByRef SelectedUids, ByVal Token, ByVal Project, ByV
Count = 0
QPProgress "native_snapshot_read", 0, Components.Count
For Each Comp In Components
Uid = CStr(Comp.UID)
Uid = QPComponentIdentityKey(Comp)
If Len(Uid) = 0 Or Seen.Exists(Uid) Then QPNativeReadInvalid "duplicate or empty component UID"
Seen.Add Uid, True
If SelectedUids.Exists(Uid) Then
@@ -281,7 +281,7 @@ Function QPBuildNativeReadScript(ByVal Source, ByRef SelectedUids, ByVal Token,
"If QP_NR_Code<>0 Then QP_NR_Text=""ERROR"" & vbTab & " & QPNativeExpression(Token) & _
" & vbTab & CStr(QP_NR_Code) & vbTab & QPEncode(QP_NR_Source) & vbTab & QPEncode(QP_NR_Description) & vbCrLf" & vbCrLf & _
"QPWriteUtf8 " & QPNativeExpression(ResultPath) & ",QP_NR_Text" & vbCrLf & "On Error GoTo 0" & vbCrLf
Names = Split("QPNativeCollectMode QPNativeRequireContext QPNativeReadInvalid QPSnapshotComponent QPUntouchedComponent QPUntouchedFullState QPUntouchedIdentity QPComponentPins QPInvalidatePinIndex QPConnectionSignatureFromPins QPAddSortedSignature QPSnapshotAttribute QPOptionalAttributeField QPSortSnapshotLines QPEncode QPDecode QPProjectPath QPSheetIdentity QPCanonicalPath QPEnsureProjectAccess QPReadUtf8 QPWriteUtf8", " ")
Names = Split("QPNativeCollectMode QPNativeRequireContext QPNativeReadInvalid QPSnapshotComponent QPUntouchedComponent QPUntouchedFullState QPUntouchedIdentity QPComponentPins QPComponentIdentityKey QPInvalidatePinIndex QPConnectionSignatureFromPins QPAddSortedSignature QPSnapshotAttribute QPReadOptionalAttributeValue QPOptionalAttributeField QPSortSnapshotLines QPLog QPAppendAscii QPEncode QPDecode QPProjectPath QPSheetIdentity QPCanonicalPath QPEnsureProjectAccess QPReadUtf8 QPWriteUtf8", " ")
Pattern.Global = False
For Each Name In Names
Pattern.Pattern = "^(Function|Sub) " & Name & "\([^\n]*\n[\s\S]*?^End \1[ \t]*"
@@ -289,8 +289,7 @@ Function QPBuildNativeReadScript(ByVal Source, ByRef SelectedUids, ByVal Token,
If Matches.Count <> 1 Then QPNativeReadInvalid "missing native read routine: " & Name
Body = Body & vbCrLf & Matches(0).Value & vbCrLf
Next
Body = Body & vbCrLf & "Sub QPLog(ByVal Root,ByVal Level,ByVal Message)" & vbCrLf & "End Sub" & vbCrLf & _
"Sub QPProgress(ByVal Stage,ByVal Done,ByVal Total)" & vbCrLf & _
Body = Body & vbCrLf & "Sub QPProgress(ByVal Stage,ByVal Done,ByVal Total)" & vbCrLf & _
" Dim StopPath,Elapsed,CurrentTime,ProgressPath,Stream,SafeFlag" & vbCrLf & _
" If QP_NR_Safe And Len(QP_AttemptToken)>0 Then" & vbCrLf & _
" StopPath=QP_Fso.BuildPath(QP_Root,""monitor-"" & QP_AttemptToken & "".stop"")" & vbCrLf & _
+204 -54
View File
@@ -25,6 +25,8 @@ Dim QP_RestoreTransactionOpen
Dim QP_PinIndex
Dim QP_PinContext
Dim QP_ComponentUidIndex, QP_ComponentRefdesIndex, QP_ComponentLocationIndex
Dim QP_FallbackIdentityUsed
Dim QP_FallbackIdentityWarnings
Dim QP_ComponentIndexContext
Dim QP_NativeCallActive
Dim QP_BatchMode, QP_OwnedProject, QP_BatchState, QP_BatchCode, QP_BatchMessage
@@ -69,6 +71,8 @@ Set QP_ComponentUidIndex = Nothing
Set QP_ComponentRefdesIndex = Nothing
Set QP_ComponentLocationIndex = Nothing
QP_ComponentIndexContext = ""
QP_FallbackIdentityUsed = False
Set QP_FallbackIdentityWarnings = CreateObject("Scripting.Dictionary")
QP_CurrentJobId = ""
QP_ExitCode = 0
QP_Stage = "session_startup"
@@ -412,7 +416,7 @@ Sub QPBuildComponentIndex(ByRef Components)
Set Uids = CreateObject("Scripting.Dictionary")
Count = 0
For Each Comp In Components
QPAddComponentIndexEntry Uids, CStr(Comp.UID), Comp
QPAddComponentIndexEntry Uids, QPComponentIdentityKey(Comp), Comp
Count = Count + 1
If Count Mod 25 = 0 Then QPProgress "index_components", Count, 0
Next
@@ -478,8 +482,7 @@ Function QPComponentPins(ByVal ComponentUid)
Set AllPins = QP_App.ActiveView.Query(VDM_COMPPIN, VD_ALL)
Count = 0
For Each CmpPin In AllPins
Owner = CStr(CmpPin.Component.UID)
If Len(Owner) = 0 Then Err.Raise vbObjectError + 862, "QuickPartReplace", "pin owner UID is empty"
Owner = QPComponentIdentityKey(CmpPin.Component)
If Not LocalIndex.Exists(Owner) Then
Set Bucket = CreateObject("Scripting.Dictionary")
LocalIndex.Add Owner, Bucket
@@ -714,8 +717,8 @@ End Sub
Sub QPDiscoverInventory(ByRef Documents)
Dim Requested, Schematics, Schematic, Sheets, Sheet, Document, View
Dim Components, Comp, PartAttr, ValueAttr, PartNumber, PartKey, HitKey, Seen, Text, Count
Dim ComponentText, ValueText, ComponentMode
Dim Components, Comp, PartAttr, ValueAttr, PartNumber, PartKey, HitKey, Seen, Text, Count, Uid
Dim ComponentText, ValueText, ComponentMode, SheetRefdes, RefdesKey
Set Requested = QPReadInventoryRequest()
Set Seen = CreateObject("Scripting.Dictionary")
Text = "project_path" & vbTab & "schematic_name" & vbTab & "sheet_number" & vbTab & "old_part" & vbCrLf
@@ -739,22 +742,31 @@ Sub QPDiscoverInventory(ByRef Documents)
Err.Raise vbObjectError + 872, "QuickPartReplace.Discovery", "inventory sheet identity changed"
QP_Stage = "inventory_query " & CStr(Schematic) & ":" & CStr(Sheet)
Set Components = View.Query(VDM_COMP, VD_ALL)
Set SheetRefdes = CreateObject("Scripting.Dictionary")
SheetRefdes.CompareMode = vbTextCompare
For Each Comp In Components
QP_Stage = "inventory_read_component " & CStr(Schematic) & ":" & CStr(Sheet)
Uid = QPComponentIdentityKey(Comp)
If ComponentMode Then
RefdesKey = Trim(CStr(Comp.Refdes))
If Len(RefdesKey) > 0 Then
If SheetRefdes.Exists(RefdesKey) Then Err.Raise vbObjectError + 872, _
"QuickPartReplace.Discovery", "duplicate component Refdes: " & RefdesKey
SheetRefdes.Add RefdesKey, True
End If
End If
PartNumber = ""
Set PartAttr = QPFindCurrentAttribute(Comp, "Part Number")
If Not PartAttr Is Nothing Then PartNumber = QPEffectiveAttributeValue(PartAttr)
PartKey = LCase(CStr(PartNumber))
If Requested.Exists(PartKey) Then
If ComponentMode Then
ValueText = ""
Set ValueAttr = QPFindCurrentAttribute(Comp, "Value")
If Not ValueAttr Is Nothing Then ValueText = QPEffectiveAttributeValue(ValueAttr)
If Len(CStr(Comp.UID)) = 0 Or Len(CStr(Comp.Refdes)) = 0 Then _
ValueText = QPEffectiveComponentAttribute(Comp, "Value")
If Len(Trim(CStr(Uid))) = 0 Or Len(Trim(CStr(Comp.Refdes))) = 0 Then _
Err.Raise vbObjectError + 872, "QuickPartReplace.Discovery", "component identity is incomplete"
ComponentText = ComponentText & QPEncode(QPProjectPath()) & vbTab & _
QPEncode(CStr(Schematic)) & vbTab & QPEncode(CStr(Sheet)) & vbTab & _
QPEncode(CStr(Comp.UID)) & vbTab & QPEncode(CStr(Comp.Refdes)) & vbTab & _
QPEncode(Uid) & vbTab & QPEncode(CStr(Comp.Refdes)) & vbTab & _
QPEncode(CStr(PartNumber)) & vbTab & QPEncode(CStr(ValueText)) & vbCrLf
End If
HitKey = QPSheetKey(Schematic, Sheet) & Chr(30) & PartKey
@@ -776,6 +788,45 @@ Sub QPDiscoverInventory(ByRef Documents)
If ComponentMode Then QPWriteUtf8 QP_Fso.BuildPath(QP_Root, "components.tsv"), ComponentText
End Sub
Function QPComponentIdentityKey(ByRef Comp)
Dim Uid, Refdes, Number, Description
On Error Resume Next
Err.Clear
Uid = CStr(Comp.UID)
Number = Err.Number
Description = Err.Description
Err.Clear
On Error GoTo 0
If Number <> 0 Then Err.Raise vbObjectError + 872, "QuickPartReplace.Discovery", _
"component UID could not be read: " & Description
On Error Resume Next
Err.Clear
Refdes = CStr(Comp.Refdes)
Number = Err.Number
Description = Err.Description
Err.Clear
On Error GoTo 0
If Number <> 0 Then Err.Raise vbObjectError + 872, _
"QuickPartReplace.Discovery", "component Refdes is unreadable; operation stopped before any replacement"
If Len(Trim(CStr(Uid))) > 0 Then
QPComponentIdentityKey = Trim(CStr(Uid))
Exit Function
Else
QP_FallbackIdentityUsed = True
If Len(Trim(CStr(Refdes))) > 0 Then
QPComponentIdentityKey = "@REFDES|" & Trim(CStr(Refdes))
If Not IsObject(QP_FallbackIdentityWarnings) Then _
Set QP_FallbackIdentityWarnings = CreateObject("Scripting.Dictionary")
If Not QP_FallbackIdentityWarnings.Exists(LCase(Trim(CStr(Refdes)))) Then
QP_FallbackIdentityWarnings.Add LCase(Trim(CStr(Refdes))), True
QPLog QP_Root, "WARN", "component_uid_missing_using_refdes_fallback refdes=" & CStr(Refdes)
End If
Else
Err.Raise vbObjectError + 872, "QuickPartReplace.Discovery", "component UID and Refdes are empty"
End If
End If
End Function
Function QPReadInventoryRequest()
Dim Path, Lines, Header, Result, Index, Fields, OldPart, Key
Path = QP_Fso.BuildPath(QP_Root, "inventory-request.tsv")
@@ -963,7 +1014,7 @@ Sub QPFinishBatchItem()
For Index = 0 To Records.Item("components").Count - 1
Set Record = Records.Item("components").Item(CStr(Index))
Set Candidate = QPFindUniqueByOldLocation(Record)
If CStr(Candidate.UID) <> CStr(Record("uid")) Then _
If QPComponentIdentityKey(Candidate) <> CStr(Record("uid")) Then _
Err.Raise vbObjectError + 871, "QuickPartReplace.Batch", "saved component UID differs"
Plans.Add CStr(Index), Candidate
Next
@@ -1172,6 +1223,8 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
Dim Index
Dim Selectors, Selector, Uid, ValueAttr, ValueText, MatchedUids, UntouchedCount, NativeRead
QP_FallbackIdentityUsed = False
Set QP_FallbackIdentityWarnings = CreateObject("Scripting.Dictionary")
If StrComp(CStr(Command("old_part_number")), CStr(Command("new_part_number")), vbTextCompare) = 0 Then _
Err.Raise vbObjectError + 829, "QuickPartReplace", "source and target must differ"
QPInvalidatePinIndex
@@ -1185,13 +1238,13 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
' when restoration needs them, from fresh proxies after native mutation.
Set Selectors = QPCommandTargets(Command)
For Each Comp In Components
Uid = CStr(Comp.UID)
Uid = QPComponentIdentityKey(Comp)
If Selectors Is Nothing Then
PartNumber = QPEffectiveComponentAttribute(Comp, "Part Number")
PartNumber = QPReadableAttributeValue(Comp, "Part Number")
If StrComp(PartNumber, CStr(Command("old_part_number")), _
vbTextCompare) = 0 Then Matches.Add CStr(Matches.Count), Comp
ElseIf Selectors.Exists(Uid) Then
PartNumber = QPEffectiveComponentAttribute(Comp, "Part Number")
PartNumber = QPRequiredAttributeValue(Comp, "Part Number")
Selector = Selectors.Item(Uid)
ValueText = ""
Set ValueAttr = QPFindCurrentAttribute(Comp, "Value")
@@ -1235,10 +1288,10 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
Set MatchedUids = CreateObject("Scripting.Dictionary")
For Index = 0 To Matches.Count - 1
Set Comp = Matches.Item(CStr(Index))
MatchedUids.Add CStr(Comp.UID), True
MatchedUids.Add QPComponentIdentityKey(Comp), True
Next
Set NativeRead = Nothing
If QPUseNativeSnapshot() Then
If QPUseNativeSnapshot() And Not QP_FallbackIdentityUsed Then
QPRequireProject Command
Set NativeRead = QPNativeCapture(MatchedUids)
If Not NativeRead Is Nothing Then
@@ -1248,7 +1301,7 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
End If
For Index = 0 To Matches.Count - 1
Set Comp = Matches.Item(CStr(Index))
Uid = CStr(Comp.UID)
Uid = QPComponentIdentityKey(Comp)
QPLog QP_Root, "INFO", "stage=snapshot_component uid=" & QPLogField(Uid)
If NativeRead Is Nothing Then
Snapshot = Snapshot & QPSnapshotComponent(Comp)
@@ -1264,7 +1317,7 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
UntouchedCount = 0
If NativeRead Is Nothing Then
For Each Comp In Components
If Not MatchedUids.Exists(CStr(Comp.UID)) Then
If Not MatchedUids.Exists(QPComponentIdentityKey(Comp)) Then
QPProgress "capture_untouched", UntouchedCount, Components.Count - Matches.Count
Snapshot = Snapshot & QPUntouchedComponent(Comp)
UntouchedCount = UntouchedCount + 1
@@ -1318,6 +1371,24 @@ Function QPUseNativeSnapshot()
QPUseNativeSnapshot = True
End Function
Function QPReadableAttributeValue(ByRef Comp, ByVal Name)
Dim Attr, ErrorNumber, ErrorSource, ErrorDescription
On Error Resume Next
Err.Clear
Set Attr = Comp.FindAttribute(CStr(Name))
ErrorNumber = Err.Number
ErrorSource = Err.Source
ErrorDescription = Err.Description
Err.Clear
On Error GoTo 0
If ErrorNumber <> 0 Then Err.Raise ErrorNumber, ErrorSource, ErrorDescription
If Attr Is Nothing Then
QPReadableAttributeValue = ""
Else
QPReadableAttributeValue = QPEffectiveAttributeValue(Attr)
End If
End Function
Function QPUntouchedComponent(ByRef Comp)
Dim State, Identity, Fields
State = QPUntouchedFullState(Comp)
@@ -1360,33 +1431,65 @@ Function QPUntouchedIdentity(ByVal State)
End Function
Function QPUntouchedFullState(ByRef Comp)
Dim Point, Pins, Connections, Attr, AttributeText, Result, Uid
Uid = CStr(Comp.UID)
Dim Point, Pins, Connections, Attr, AttributeText, Result, Uid, Identity
Identity = QPComponentIdentityKey(Comp)
Set Point = Comp.GetLocation()
Set Pins = QPComponentPins(Uid)
Set Pins = QPComponentPins(Identity)
If Pins.Count = 0 Then
' A genuinely empty query is valid for annotation symbols; COM errors
' still propagate. Selected replacement symbols continue to require pins.
Connections = "NO_PINS"
Else
Connections = QPConnectionSignatureFromPins(Uid, Pins)
Connections = QPConnectionSignatureFromPins(Identity, Pins)
End If
Result = "C" & vbTab & QPEncode(Uid) & vbTab & QPEncode(CStr(Comp.Refdes)) & _
Result = "C" & vbTab & QPEncode(Identity) & vbTab & QPEncode(CStr(Comp.Refdes)) & _
vbTab & QPEncode(CStr(Point.X)) & vbTab & QPEncode(CStr(Point.Y)) & _
vbTab & QPEncode(CStr(Comp.Orientation)) & vbTab & QPEncode(CStr(Comp.Scale)) & _
vbTab & QPEncode(Connections) & vbCrLf
AttributeText = ""
For Each Attr In Comp.Attributes
AttributeText = AttributeText & QPSnapshotAttribute(Uid, Attr)
AttributeText = AttributeText & QPSnapshotAttribute(Identity, Attr)
Next
QPUntouchedFullState = Result & QPSortSnapshotLines(AttributeText)
End Function
Function QPEffectiveComponentAttribute(ByRef Comp, ByVal Name)
Dim Attr
Dim Attr, ErrorNumber, ErrorDescription
QPEffectiveComponentAttribute = ""
On Error Resume Next
Err.Clear
Set Attr = QPFindCurrentAttribute(Comp, Name)
If Not Attr Is Nothing Then QPEffectiveComponentAttribute = QPEffectiveAttributeValue(Attr)
ErrorNumber = Err.Number
ErrorDescription = Err.Description
Err.Clear
If ErrorNumber = 0 And Not Attr Is Nothing Then
QPEffectiveComponentAttribute = QPReadOptionalAttributeValue(Attr)
ElseIf ErrorNumber <> 0 Then
QPLog QP_Root, "WARN", "optional_attribute_unavailable name=" & CStr(Name) & _
" description=" & CStr(ErrorDescription)
End If
On Error GoTo 0
End Function
Function QPReadOptionalAttributeValue(ByRef Attr)
Dim Instance, Value, Number
QPReadOptionalAttributeValue = ""
On Error Resume Next
Err.Clear
Instance = CStr(Attr.InstanceValue)
Number = Err.Number
Err.Clear
If Number = 0 And Len(CStr(Instance)) > 0 Then
QPReadOptionalAttributeValue = Instance
On Error GoTo 0
Exit Function
End If
Err.Clear
Value = CStr(Attr.Value)
Number = Err.Number
Err.Clear
If Number = 0 Then QPReadOptionalAttributeValue = CStr(Value)
On Error GoTo 0
End Function
Sub QPVerifyUntouched(ByRef Records)
@@ -1400,7 +1503,7 @@ Sub QPVerifyUntouched(ByRef Records)
' Read new component/pin proxies after each native mutation, restore or reopen.
QPInvalidatePinIndex
QPInvalidateComponentIndex
If QPUseNativeSnapshot() Then
If QPUseNativeSnapshot() And Not QP_FallbackIdentityUsed Then
If QPTryNativeVerifyUntouched(Records) Then Exit Sub
End If
Set Components = QP_App.ActiveView.Query(VDM_COMP, VD_ALL)
@@ -1409,7 +1512,7 @@ Sub QPVerifyUntouched(ByRef Records)
Set Seen = CreateObject("Scripting.Dictionary")
For Each Comp In Components
Total = Total + 1
Uid = CStr(Comp.UID)
Uid = QPComponentIdentityKey(Comp)
If Seen.Exists(Uid) Then Err.Raise vbObjectError + 874, _
"QuickPartReplace.Target", "duplicate component UID"
Seen.Add Uid, True
@@ -1471,13 +1574,13 @@ Function QPSnapshotComponent(ByRef Comp)
Dim ErrorNumber
Dim ErrorSource
Dim ErrorDescription
Dim Uid, Pins
Dim Uid, Identity, Pins
Uid = CStr(Comp.UID)
Identity = QPComponentIdentityKey(Comp)
Set Point = Comp.GetLocation()
Set Pins = QPComponentPins(Uid)
Connections = QPConnectionSignatureFromPins(Uid, Pins)
Result = "C" & vbTab & QPEncode(Uid) & vbTab & _
Set Pins = QPComponentPins(Identity)
Connections = QPConnectionSignatureFromPins(Identity, Pins)
Result = "C" & vbTab & QPEncode(Identity) & vbTab & _
QPEncode(CStr(Comp.Refdes)) & vbTab & QPEncode(CStr(Point.X)) & _
vbTab & QPEncode(CStr(Point.Y)) & vbTab & _
QPEncode(CStr(Comp.Orientation)) & vbTab & QPEncode(CStr(Comp.Scale)) & _
@@ -1488,7 +1591,7 @@ Function QPSnapshotComponent(ByRef Comp)
AttributeText = ""
AttributeCount = 0
For Each Attr In Comp.Attributes
AttributeText = AttributeText & QPSnapshotAttribute(Uid, Attr)
AttributeText = AttributeText & QPSnapshotAttribute(Identity, Attr)
If Err.Number <> 0 Then Exit For
AttributeCount = AttributeCount + 1
QPProgress "snapshot_attributes", AttributeCount, 0
@@ -1530,7 +1633,7 @@ Function QPSortSnapshotLines(ByVal Text)
End Function
Function QPSnapshotAttribute(ByVal ComponentUid, ByRef Attr)
Dim Instance, Point, ErrorNumber, ErrorDescription
Dim Instance, Value, Point, ErrorNumber, ErrorDescription, Field
Dim LocationX
Dim LocationY
Dim Color
@@ -1539,24 +1642,52 @@ Function QPSnapshotAttribute(ByVal ComponentUid, ByRef Attr)
Dim Orientation
Dim Visible
Instance = Attr.InstanceValue
Instance = ""
Value = ""
On Error Resume Next
Err.Clear
Instance = CStr(Attr.InstanceValue)
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
Err.Raise vbObjectError + 836, "QuickPartReplace.Snapshot", "attribute InstanceValue unreadable; replacement blocked before mutation"
End If
Err.Clear
Value = CStr(Attr.Value)
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
Err.Raise vbObjectError + 836, "QuickPartReplace.Snapshot", "attribute Value unreadable; replacement blocked before mutation"
End If
Err.Clear
Set Point = Nothing
Set Point = Attr.GetLocation()
LocationX = CStr(Point.X)
LocationY = CStr(Point.Y)
ErrorNumber = Err.Number
ErrorDescription = Err.Description
Err.Clear
LocationX = ""
LocationY = ""
If ErrorNumber = 0 Then
If Not Point Is Nothing Then
LocationX = CStr(Point.X)
LocationY = CStr(Point.Y)
End If
End If
If Len(LocationX) = 0 Or Len(LocationY) = 0 Then
QPLog QP_Root, "WARN", "optional_display_field_unavailable field=location"
End If
Err.Clear
On Error GoTo 0
If ErrorNumber <> 0 Then Err.Raise ErrorNumber, "QuickPartReplace.Snapshot", _
"Cannot capture " & CStr(Attr.Name) & ".location: " & ErrorDescription
Color = QPOptionalAttributeField(Attr, "color")
Font = QPOptionalAttributeField(Attr, "font")
Size = QPOptionalAttributeField(Attr, "size")
Orientation = QPOptionalAttributeField(Attr, "orientation")
Visible = QPOptionalAttributeField(Attr, "visible")
For Each Field In Array(LocationX, LocationY, Color, Font, Size, Orientation, Visible)
If Len(CStr(Field)) = 0 Then Err.Raise vbObjectError + 836, _
"QuickPartReplace.Snapshot", "attribute display state unreadable; replacement blocked before mutation"
Next
QPSnapshotAttribute = "A" & vbTab & QPEncode(ComponentUid) & vbTab & _
QPEncode(CStr(Attr.Name)) & vbTab & QPEncode(CStr(Attr.Value)) & _
QPEncode(CStr(Attr.Name)) & vbTab & QPEncode(Value) & _
vbTab & QPEncode(CStr(Instance)) & vbTab & QPEncode(LocationX) & _
vbTab & QPEncode(LocationY) & vbTab & QPEncode(Color) & _
vbTab & QPEncode(Font) & vbTab & QPEncode(Size) & vbTab & _
@@ -1598,8 +1729,9 @@ Function QPOptionalAttributeField(ByRef Attr, ByVal FieldName)
Err.Clear
On Error GoTo 0
If ErrorNumber <> 0 Then
Err.Raise ErrorNumber, "QuickPartReplace.Snapshot", _
"Cannot capture " & CStr(Attr.Name) & "." & FieldName & ": " & ErrorDescription
QPOptionalAttributeField = ""
QPLog QP_Root, "WARN", "optional_display_field_unavailable field=" & CStr(FieldName) & _
" description=" & CStr(ErrorDescription)
Else
QPOptionalAttributeField = Value
End If
@@ -1636,9 +1768,9 @@ Sub QPRestoreAfterOperatorReplace(ByRef Command, ByVal SnapshotPath)
For Index = 0 To Records.Item("components").Count - 1
Set ComponentRecord = Records.Item("components").Item(CStr(Index))
Set Candidate = QPFindUniqueByOldLocation(ComponentRecord)
If Used.Exists(CStr(Candidate.UID)) Then _
If Used.Exists(QPComponentIdentityKey(Candidate)) Then _
Err.Raise vbObjectError + 831, "QuickPartReplace", "duplicate replacement association"
Used.Add CStr(Candidate.UID), True
Used.Add QPComponentIdentityKey(Candidate), True
QPRestorePreflight Candidate, ComponentRecord, Records.Item("attributes"), _
CStr(Command("new_part_number")), QPValueMode(Command)
Plans.Add CStr(Index), Candidate
@@ -1795,9 +1927,9 @@ Sub QPRecoverSavedJob(ByRef Command, ByVal SnapshotPath)
QPRequireSnapshotContext SnapshotPath
Set Record = Records.Item("components").Item(CStr(Index))
Set Candidate = QPFindUniqueByOldLocation(Record)
If CStr(Candidate.UID) <> CStr(Record("uid")) Or Used.Exists(CStr(Candidate.UID)) Then _
If QPComponentIdentityKey(Candidate) <> CStr(Record("uid")) Or Used.Exists(QPComponentIdentityKey(Candidate)) Then _
Err.Raise vbObjectError + 865, "QuickPartReplace.Recovery", "saved component UID changed or duplicated"
Used.Add CStr(Candidate.UID), True
Used.Add QPComponentIdentityKey(Candidate), True
PartNumber = QPRequiredAttributeValue(Candidate, "Part Number")
If StrComp(PartNumber, CStr(Command("old_part_number")), vbTextCompare) = 0 Then
OldCount = OldCount + 1
@@ -1904,7 +2036,7 @@ End Function
Sub QPRestorePreflight(ByRef Comp, ByRef ComponentRecord, _
ByRef Attributes, ByVal NewPartNumber, ByVal ValueMode)
Dim Index
Dim Index, Field
Dim Record
Dim LabelAttr
Dim ValueAttr
@@ -1914,7 +2046,7 @@ Sub QPRestorePreflight(ByRef Comp, ByRef ComponentRecord, _
Dim CurrentConnections
Dim SavedConnections
If CStr(Comp.UID) <> CStr(ComponentRecord("uid")) Or _
If QPComponentIdentityKey(Comp) <> CStr(ComponentRecord("uid")) Or _
CStr(Comp.Refdes) <> CStr(ComponentRecord("refdes")) Then _
Err.Raise vbObjectError + 831, "QuickPartReplace", "replacement component UID or Refdes differs from snapshot; no restoration writes allowed"
If StrComp(QPRequiredAttributeValue(Comp, "Part Number"), _
@@ -1932,6 +2064,16 @@ Sub QPRestorePreflight(ByRef Comp, ByRef ComponentRecord, _
Err.Raise vbObjectError + 804, "QuickPartReplace", _
"connection validation failed"
End If
For Index = 0 To Attributes.Count - 1
Set Record = Attributes.Item(CStr(Index))
If CStr(Record("uid")) = CStr(ComponentRecord("uid")) Then
For Each Field In Array("x", "y", "color", "font", "size", "orientation", "visible")
If Len(CStr(Record(Field))) = 0 Then Err.Raise vbObjectError + 836, _
"QuickPartReplace.Snapshot", "attribute display state unavailable field=" & CStr(Field) & _
"; uid=" & CStr(ComponentRecord("uid")) & "; no restoration writes allowed"
Next
End If
Next
If ValueMode = "preserve" Or ValueMode = "custom" Then Exit Sub
HasOldValue = False
Set ValueRecord = Nothing
@@ -2597,8 +2739,16 @@ Function QPFindCurrentAttribute(ByRef Comp, ByVal Name)
End Function
Function QPRequiredAttributeValue(ByRef Comp, ByVal Name)
Dim Attr
Set Attr = QPFindCurrentAttribute(Comp, Name)
Dim Attr, ErrorNumber, ErrorSource, ErrorDescription
On Error Resume Next
Err.Clear
Set Attr = Comp.FindAttribute(CStr(Name))
ErrorNumber = Err.Number
ErrorSource = Err.Source
ErrorDescription = Err.Description
Err.Clear
On Error GoTo 0
If ErrorNumber <> 0 Then Err.Raise ErrorNumber, ErrorSource, ErrorDescription
If Attr Is Nothing Then
Err.Raise vbObjectError + 806, "QuickPartReplace", _
"required attribute missing: " & CStr(Name)
@@ -2644,7 +2794,7 @@ End Function
Function QPConnectionSignature(ByRef Comp)
Dim Pins, Uid
Uid = CStr(Comp.UID)
Uid = QPComponentIdentityKey(Comp)
Set Pins = QPComponentPins(Uid)
QPConnectionSignature = QPConnectionSignatureFromPins(Uid, Pins)
End Function
@@ -2673,7 +2823,7 @@ Function QPConnectionSignatureFromPins(ByVal ComponentUid, ByRef Pins)
PinReadCount = 0
For Each PinIndexKey In Pins.Keys
Set CmpPin = Pins.Item(CStr(PinIndexKey))
If StrComp(CStr(CmpPin.Component.UID), ComponentUid, _
If StrComp(QPComponentIdentityKey(CmpPin.Component), ComponentUid, _
vbBinaryCompare) = 0 Then
Set Point = CmpPin.GetLocation()
PinKey = CStr(CmpPin.Number) & "|" & CStr(Point.X) & "|" & _