Implement v1.1 target plans and project task backend
This commit is contained in:
1 parent
a7e1b9bd33
commit
235a1005e9
18 files changed
+1536
-45
No files matched your search
@@ -523,10 +523,14 @@ End Sub
|
||||
|
||||
Sub QPDiscoverInventory(ByRef Documents)
|
||||
Dim Requested, Schematics, Schematic, Sheets, Sheet, Document, View
|
||||
Dim Components, Comp, PartAttr, PartNumber, PartKey, HitKey, Seen, Text, Count
|
||||
Dim Components, Comp, PartAttr, ValueAttr, PartNumber, PartKey, HitKey, Seen, Text, Count
|
||||
Dim ComponentText, ValueText, ComponentMode
|
||||
Set Requested = QPReadInventoryRequest()
|
||||
Set Seen = CreateObject("Scripting.Dictionary")
|
||||
Text = "project_path" & vbTab & "schematic_name" & vbTab & "sheet_number" & vbTab & "old_part" & vbCrLf
|
||||
ComponentMode = QP_Fso.FileExists(QP_Fso.BuildPath(QP_Root, "component-inventory.request"))
|
||||
ComponentText = "project_path" & vbTab & "schematic_name" & vbTab & "sheet_number" & vbTab & _
|
||||
"uid" & vbTab & "refdes" & vbTab & "old_part" & vbTab & "old_value" & vbCrLf
|
||||
Count = 0
|
||||
Set Schematics = Documents.GetAvailableSchematics()
|
||||
For Each Schematic In Schematics
|
||||
@@ -548,6 +552,17 @@ Sub QPDiscoverInventory(ByRef Documents)
|
||||
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 _
|
||||
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(CStr(PartNumber)) & vbTab & QPEncode(CStr(ValueText)) & vbCrLf
|
||||
End If
|
||||
HitKey = QPSheetKey(Schematic, Sheet) & Chr(30) & PartKey
|
||||
If Not Seen.Exists(HitKey) Then
|
||||
Seen.Add HitKey, True
|
||||
@@ -563,6 +578,7 @@ Sub QPDiscoverInventory(ByRef Documents)
|
||||
Next
|
||||
Next
|
||||
QPWriteUtf8 QP_Fso.BuildPath(QP_Root, "inventory.tsv"), Text
|
||||
If ComponentMode Then QPWriteUtf8 QP_Fso.BuildPath(QP_Root, "components.tsv"), ComponentText
|
||||
End Sub
|
||||
|
||||
Function QPReadInventoryRequest()
|
||||
@@ -711,6 +727,7 @@ Sub QPFinishBatchItem()
|
||||
SnapshotPath = QPJobSnapshotPath(QP_CurrentJobId)
|
||||
QPRequireCommandSnapshot Command, SnapshotPath
|
||||
Set Records = QPReadSnapshot(SnapshotPath)
|
||||
QPVerifyUntouched Records
|
||||
Set ValueStates = CreateObject("Scripting.Dictionary")
|
||||
For Index = 0 To Records.Item("components").Count - 1
|
||||
Set Record = Records.Item("components").Item(CStr(Index))
|
||||
@@ -726,6 +743,7 @@ Sub QPFinishBatchItem()
|
||||
QPProgress "verify_saved_project", 0, 1
|
||||
QPEnsureProject QP_App, TargetPath
|
||||
QPRequireCommandSnapshot Command, SnapshotPath
|
||||
QPVerifyUntouched Records
|
||||
Set Plans = CreateObject("Scripting.Dictionary")
|
||||
For Index = 0 To Records.Item("components").Count - 1
|
||||
Set Record = Records.Item("components").Item(CStr(Index))
|
||||
@@ -848,8 +866,10 @@ Sub QPRollbackNativeReplacement(ByVal SnapshotPath)
|
||||
Lines = Split(QPReadUtf8(SnapshotPath), vbLf)
|
||||
Expected = ""
|
||||
For LineIndex = 1 To UBound(Lines)
|
||||
If Len(Replace(Lines(LineIndex), vbCr, "")) > 0 Then _
|
||||
Expected = Expected & Replace(Lines(LineIndex), vbCr, "") & vbCrLf
|
||||
If Len(Replace(Lines(LineIndex), vbCr, "")) > 0 Then
|
||||
If Left(CStr(Lines(LineIndex)), 2) <> "U" & vbTab Then _
|
||||
Expected = Expected & Replace(Lines(LineIndex), vbCr, "") & vbCrLf
|
||||
End If
|
||||
Next
|
||||
Actual = ""
|
||||
For Index = 0 To Records.Item("components").Count - 1
|
||||
@@ -858,6 +878,7 @@ Sub QPRollbackNativeReplacement(ByVal SnapshotPath)
|
||||
Actual = Actual & QPSnapshotComponent(Candidate)
|
||||
QPProgress "verify_native_rollback", Index + 1, Records.Item("components").Count
|
||||
Next
|
||||
QPVerifyUntouched Records
|
||||
If Actual <> Expected Then Err.Raise vbObjectError + 842, _
|
||||
"QuickPartReplace", "native undo does not match the original snapshot"
|
||||
QPWriteUtf8 SnapshotPath & ".native.rolled-back", _
|
||||
@@ -874,6 +895,7 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
|
||||
Dim PartAttr
|
||||
Dim Snapshot
|
||||
Dim Index
|
||||
Dim Selectors, Selector, Uid, ValueAttr, ValueText
|
||||
|
||||
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"
|
||||
@@ -884,17 +906,35 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
|
||||
QPLog QP_Root, "INFO", "stage=query_components"
|
||||
Set Components = QP_App.ActiveView.Query(VDM_COMP, VD_ALL)
|
||||
QPBuildComponentIndex Components
|
||||
Set Selectors = QPCommandTargets(Command)
|
||||
For Each Comp In Components
|
||||
PartNumber = ""
|
||||
Set PartAttr = QPFindCurrentAttribute(Comp, "Part Number")
|
||||
If Not PartAttr Is Nothing Then PartNumber = QPEffectiveAttributeValue(PartAttr)
|
||||
If StrComp(PartNumber, CStr(Command("old_part_number")), _
|
||||
vbTextCompare) = 0 Then
|
||||
Uid = CStr(Comp.UID)
|
||||
If Selectors Is Nothing Then
|
||||
If StrComp(PartNumber, CStr(Command("old_part_number")), _
|
||||
vbTextCompare) = 0 Then Matches.Add CStr(Matches.Count), Comp
|
||||
ElseIf Selectors.Exists(Uid) Then
|
||||
Selector = Selectors.Item(Uid)
|
||||
ValueText = ""
|
||||
Set ValueAttr = QPFindCurrentAttribute(Comp, "Value")
|
||||
If Not ValueAttr Is Nothing Then ValueText = QPEffectiveAttributeValue(ValueAttr)
|
||||
If CStr(Comp.Refdes) <> CStr(Selector(0)) Or _
|
||||
StrComp(PartNumber, CStr(Command("old_part_number")), vbTextCompare) <> 0 Or _
|
||||
ValueText <> CStr(Selector(1)) Then _
|
||||
Err.Raise vbObjectError + 873, "QuickPartReplace.Target", "selected component changed since inventory"
|
||||
Matches.Add CStr(Matches.Count), Comp
|
||||
End If
|
||||
QPProgress "find_components", Matches.Count, 0
|
||||
Next
|
||||
If Not Selectors Is Nothing Then
|
||||
If Matches.Count <> Selectors.Count Then _
|
||||
Err.Raise vbObjectError + 873, "QuickPartReplace.Target", "selected component is missing"
|
||||
End If
|
||||
If Matches.Count = 0 Then
|
||||
If Not Selectors Is Nothing Then _
|
||||
Err.Raise vbObjectError + 873, "QuickPartReplace.Target", "target scope is empty"
|
||||
QPWriteStatus QP_Root, CStr(Command("job_id")), "no_match", "", _
|
||||
"No components match old Part Number on the current sheet; no replacement was performed. " & _
|
||||
"Project=" & QPProjectPath() & "; sheet=" & QPSheetIdentity() & "; old_part=" & CStr(Command("old_part_number"))
|
||||
@@ -911,6 +951,8 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
|
||||
Snapshot = Snapshot & vbTab & QPEncode(QPValueMode(Command)) & _
|
||||
vbTab & QPEncode(QPCustomValue(Command)) & vbTab & _
|
||||
QPEncode(QPBooleanText(QPSyncNc(Command)))
|
||||
If Not Selectors Is Nothing Then _
|
||||
Snapshot = Snapshot & vbTab & QPEncode("targets") & vbTab & CStr(Command("target_selectors"))
|
||||
Snapshot = Snapshot & vbCrLf
|
||||
For Index = 0 To Matches.Count - 1
|
||||
Set Comp = Matches.Item(CStr(Index))
|
||||
@@ -918,6 +960,12 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
|
||||
Snapshot = Snapshot & QPSnapshotComponent(Comp)
|
||||
QPProgress "capture", Index + 1, Matches.Count
|
||||
Next
|
||||
If Not Selectors Is Nothing Then
|
||||
For Each Comp In Components
|
||||
If Not Selectors.Exists(CStr(Comp.UID)) Then _
|
||||
Snapshot = Snapshot & QPUntouchedComponent(Comp)
|
||||
Next
|
||||
End If
|
||||
QPWriteUtf8 SnapshotPath, Snapshot
|
||||
|
||||
For Each Comp In Components
|
||||
@@ -933,6 +981,77 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
|
||||
QPLog QP_Root, "INFO", "awaiting_native_replace count=" & Matches.Count
|
||||
End Sub
|
||||
|
||||
Function QPUntouchedComponent(ByRef Comp)
|
||||
QPUntouchedComponent = "U" & vbTab & QPEncode(CStr(Comp.UID)) & vbTab & _
|
||||
QPEncode(CStr(Comp.Refdes)) & vbTab & QPEncode(QPEffectiveComponentAttribute(Comp, "Part Number")) & vbTab & _
|
||||
QPEncode(QPEffectiveComponentAttribute(Comp, "Value")) & vbTab & _
|
||||
QPEncode(QPEffectiveComponentAttribute(Comp, "Part Name")) & vbTab & _
|
||||
QPEncode(QPEffectiveComponentAttribute(Comp, "Part Label")) & vbCrLf
|
||||
End Function
|
||||
|
||||
Function QPEffectiveComponentAttribute(ByRef Comp, ByVal Name)
|
||||
Dim Attr
|
||||
QPEffectiveComponentAttribute = ""
|
||||
Set Attr = QPFindCurrentAttribute(Comp, Name)
|
||||
If Not Attr Is Nothing Then QPEffectiveComponentAttribute = QPEffectiveAttributeValue(Attr)
|
||||
End Function
|
||||
|
||||
Sub QPVerifyUntouched(ByRef Records)
|
||||
Dim Baseline, Components, Comp, Uid, Actual, Matched, Total, Seen
|
||||
Set Baseline = Records.Item("untouched")
|
||||
If Baseline.Count = 0 Then Exit Sub
|
||||
Set Components = QP_App.ActiveView.Query(VDM_COMP, VD_ALL)
|
||||
Matched = 0
|
||||
Total = 0
|
||||
Set Seen = CreateObject("Scripting.Dictionary")
|
||||
For Each Comp In Components
|
||||
Total = Total + 1
|
||||
Uid = CStr(Comp.UID)
|
||||
If Seen.Exists(Uid) Then Err.Raise vbObjectError + 874, _
|
||||
"QuickPartReplace.Target", "duplicate component UID"
|
||||
Seen.Add Uid, True
|
||||
If Baseline.Exists(Uid) Then
|
||||
Matched = Matched + 1
|
||||
Actual = Replace(QPUntouchedComponent(Comp), vbCrLf, "")
|
||||
If Actual <> CStr(Baseline.Item(Uid)) Then _
|
||||
Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "unselected component changed"
|
||||
End If
|
||||
Next
|
||||
If Total <> Baseline.Count + Records.Item("components").Count Then _
|
||||
Err.Raise vbObjectError + 874, "QuickPartReplace.Target", "component count changed outside selected targets"
|
||||
If Matched <> Baseline.Count Then Err.Raise vbObjectError + 874, _
|
||||
"QuickPartReplace.Target", "unselected component is missing"
|
||||
End Sub
|
||||
|
||||
Function QPCommandTargets(ByRef Command)
|
||||
Dim Scope, Text, Entries, Entry, Fields, Result, Index
|
||||
Set QPCommandTargets = Nothing
|
||||
If Not Command.Exists("target_scope") Then Exit Function
|
||||
Scope = CStr(Command("target_scope"))
|
||||
If Scope = "all" Then
|
||||
If Len(CStr(Command("target_selectors"))) <> 0 Then _
|
||||
Err.Raise vbObjectError + 873, "QuickPartReplace.Target", "all-match scope has selectors"
|
||||
Exit Function
|
||||
End If
|
||||
If Scope <> "targets" Then Err.Raise vbObjectError + 873, _
|
||||
"QuickPartReplace.Target", "target scope is invalid"
|
||||
Text = QPDecode(CStr(Command("target_selectors")))
|
||||
If Len(Text) = 0 Then Err.Raise vbObjectError + 873, _
|
||||
"QuickPartReplace.Target", "target scope is empty"
|
||||
Set Result = CreateObject("Scripting.Dictionary")
|
||||
Entries = Split(Text, Chr(30))
|
||||
For Index = 0 To UBound(Entries)
|
||||
Fields = Split(Entries(Index), Chr(31))
|
||||
If UBound(Fields) <> 2 Or Len(CStr(Fields(0))) = 0 Or _
|
||||
Len(CStr(Fields(1))) = 0 Then Err.Raise vbObjectError + 873, _
|
||||
"QuickPartReplace.Target", "target selector is malformed"
|
||||
If Result.Exists(CStr(Fields(0))) Then Err.Raise vbObjectError + 873, _
|
||||
"QuickPartReplace.Target", "duplicate target UID"
|
||||
Result.Add CStr(Fields(0)), Array(CStr(Fields(1)), CStr(Fields(2)))
|
||||
Next
|
||||
Set QPCommandTargets = Result
|
||||
End Function
|
||||
|
||||
Function QPSnapshotComponent(ByRef Comp)
|
||||
Dim AttributeCount
|
||||
Dim Point
|
||||
@@ -1086,6 +1205,8 @@ Sub QPRestoreAfterOperatorReplace(ByRef Command, ByVal SnapshotPath)
|
||||
QP_NcSyncSummary = ""
|
||||
QPProgress "restore_preflight", 0, 0
|
||||
Set Records = QPReadSnapshot(SnapshotPath)
|
||||
QPRequireCommandSnapshot Command, SnapshotPath
|
||||
QPVerifyUntouched Records
|
||||
Set Meta = Records.Item("meta")
|
||||
If QPCanonicalPath(CStr(Meta("project_path"))) <> QPCanonicalPath(QPProjectPath()) Or _
|
||||
CStr(Meta("sheet_name")) <> QPSheetIdentity() Then _
|
||||
@@ -1232,6 +1353,7 @@ Sub QPRecoverSavedJob(ByRef Command, ByVal SnapshotPath)
|
||||
Dim OldCount, NewCount, ErrorNumber, ErrorDescription, RecoveryDocuments, RecoveryDocument, RecoveryProjectData
|
||||
QPRequireCommandSnapshot Command, SnapshotPath
|
||||
Set Records = QPReadSnapshot(SnapshotPath)
|
||||
QPVerifyUntouched Records
|
||||
Set Plans = CreateObject("Scripting.Dictionary")
|
||||
Set Used = CreateObject("Scripting.Dictionary")
|
||||
Set ValueStates = CreateObject("Scripting.Dictionary")
|
||||
@@ -1700,6 +1822,19 @@ Sub QPRequireCommandSnapshot(ByRef Command, ByVal SnapshotPath)
|
||||
If QPCustomValue(Meta) <> QPCustomValue(Command) Or _
|
||||
QPSyncNc(Meta) <> QPSyncNc(Command) Then _
|
||||
Err.Raise vbObjectError + 842, "QuickPartReplace", "snapshot Value or NC option mismatch"
|
||||
If Command.Exists("target_scope") Then
|
||||
If CStr(Command("target_scope")) = "targets" Then
|
||||
If Not Meta.Exists("target_scope") Then Err.Raise vbObjectError + 873, _
|
||||
"QuickPartReplace.Target", "target selector missing from snapshot"
|
||||
If CStr(Meta("target_scope")) <> "targets" Or _
|
||||
CStr(Meta("target_selectors")) <> CStr(Command("target_selectors")) Then _
|
||||
Err.Raise vbObjectError + 873, "QuickPartReplace.Target", "target selector changed since snapshot"
|
||||
ElseIf Meta.Exists("target_scope") Then
|
||||
Err.Raise vbObjectError + 873, "QuickPartReplace.Target", "snapshot scope changed"
|
||||
End If
|
||||
ElseIf Meta.Exists("target_scope") Then
|
||||
Err.Raise vbObjectError + 873, "QuickPartReplace.Target", "target scope missing from command"
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Function QPValueMode(ByRef Record)
|
||||
@@ -2362,6 +2497,7 @@ Function QPReadSnapshot(ByVal Path)
|
||||
Dim Result
|
||||
Dim Components
|
||||
Dim Attributes
|
||||
Dim Untouched
|
||||
Dim Fields
|
||||
Dim Index
|
||||
Dim Record
|
||||
@@ -2370,13 +2506,14 @@ Function QPReadSnapshot(ByVal Path)
|
||||
Set Result = CreateObject("Scripting.Dictionary")
|
||||
Set Components = CreateObject("Scripting.Dictionary")
|
||||
Set Attributes = CreateObject("Scripting.Dictionary")
|
||||
Set Untouched = CreateObject("Scripting.Dictionary")
|
||||
Lines = Split(QPReadUtf8(Path), vbLf)
|
||||
For Index = 0 To UBound(Lines)
|
||||
If Len(Replace(Lines(Index), vbCr, "")) > 0 Then
|
||||
Fields = Split(Replace(Lines(Index), vbCr, ""), vbTab)
|
||||
Select Case Fields(0)
|
||||
Case "M"
|
||||
If UBound(Fields) <> 4 And UBound(Fields) <> 5 And UBound(Fields) <> 7 Then Err.Raise vbObjectError + 812, _
|
||||
If UBound(Fields) <> 4 And UBound(Fields) <> 5 And UBound(Fields) <> 7 And UBound(Fields) <> 9 Then Err.Raise vbObjectError + 812, _
|
||||
"QuickPartReplace", "invalid snapshot meta"
|
||||
Set Meta = CreateObject("Scripting.Dictionary")
|
||||
Meta.Add "project_path", QPDecode(Fields(1))
|
||||
@@ -2384,11 +2521,15 @@ Function QPReadSnapshot(ByVal Path)
|
||||
Meta.Add "new_part_number", QPDecode(Fields(3))
|
||||
Meta.Add "sheet_name", QPDecode(Fields(4))
|
||||
If UBound(Fields) = 5 Then Meta.Add "value_mode", QPDecode(Fields(5))
|
||||
If UBound(Fields) = 7 Then
|
||||
If UBound(Fields) >= 7 Then
|
||||
Meta.Add "value_mode", QPDecode(Fields(5))
|
||||
Meta.Add "custom_value", QPDecode(Fields(6))
|
||||
Meta.Add "sync_nc", QPDecode(Fields(7))
|
||||
End If
|
||||
If UBound(Fields) = 9 Then
|
||||
Meta.Add "target_scope", QPDecode(Fields(8))
|
||||
Meta.Add "target_selectors", CStr(Fields(9))
|
||||
End If
|
||||
Result.Add "meta", Meta
|
||||
Case "C"
|
||||
If UBound(Fields) <> 7 Then Err.Raise vbObjectError + 813, _
|
||||
@@ -2418,6 +2559,12 @@ Function QPReadSnapshot(ByVal Path)
|
||||
Record.Add "orientation", QPDecode(Fields(10))
|
||||
Record.Add "visible", QPDecode(Fields(11))
|
||||
Attributes.Add CStr(Attributes.Count), Record
|
||||
Case "U"
|
||||
If UBound(Fields) <> 6 Then Err.Raise vbObjectError + 874, _
|
||||
"QuickPartReplace.Target", "invalid unselected component snapshot"
|
||||
If Untouched.Exists(QPDecode(Fields(1))) Then Err.Raise vbObjectError + 874, _
|
||||
"QuickPartReplace.Target", "duplicate unselected component UID"
|
||||
Untouched.Add QPDecode(Fields(1)), Replace(Lines(Index), vbCr, "")
|
||||
End Select
|
||||
End If
|
||||
Next
|
||||
@@ -2426,6 +2573,7 @@ Function QPReadSnapshot(ByVal Path)
|
||||
End If
|
||||
Result.Add "components", Components
|
||||
Result.Add "attributes", Attributes
|
||||
Result.Add "untouched", Untouched
|
||||
Set QPReadSnapshot = Result
|
||||
End Function
|
||||
|
||||
|
||||
Reference in new issue
Block a user