1162 lines
42 KiB
Plaintext
1162 lines
42 KiB
Plaintext
' DxDesigner 7.9.5 part replacement compatibility probe. ASCII-only source.
|
|
' Required profile invariant: "production_replace_route":"native_replace_part"
|
|
|
|
Sub DxRunPartReplaceProbe(ByVal RequestRelativePath, ByVal OutputRelativePath)
|
|
Dim DxToolsHome
|
|
Dim RequestPath
|
|
Dim OutputPath
|
|
Dim RequestText
|
|
Dim DisposableMarker
|
|
Dim OperatorConfirmation
|
|
Dim RequestValid
|
|
Dim MutatingAuthorized
|
|
Dim MutatingAttempted
|
|
Dim ApiErrors
|
|
Dim NoLocalErrors
|
|
Dim VersionValue
|
|
Dim VersionOk
|
|
Dim BuildValue
|
|
Dim BuildOk
|
|
Dim ProjectIdentity
|
|
Dim ProjectOk
|
|
Dim ActiveViewName
|
|
Dim ActiveViewOk
|
|
Dim DirtyValue
|
|
Dim DirtyOk
|
|
Dim ComponentValues
|
|
Dim ComponentCount
|
|
Dim EnumerationAvailable
|
|
Dim EnumerationStatus
|
|
Dim ComponentRecords()
|
|
Dim Component
|
|
Dim ComponentIndex
|
|
Dim Interfaces
|
|
Dim RoutesJson
|
|
Dim Profile
|
|
|
|
DxToolsHome = Scripting.GetEnvVariable("DXTOOLS_HOME")
|
|
If Len(CStr(DxToolsHome)) = 0 Then
|
|
Err.Raise vbObjectError + 795, "DxRunPartReplaceProbe", _
|
|
"DXTOOLS_HOME is not set in the injected scripting host"
|
|
End If
|
|
RequestPath = DxResolveRunPath(DxToolsHome, RequestRelativePath)
|
|
OutputPath = DxResolveRunPath(DxToolsHome, OutputRelativePath)
|
|
RequestText = DxReadUtf8(RequestPath)
|
|
DxProbeParseRequest RequestText, DisposableMarker, _
|
|
OperatorConfirmation, RequestValid
|
|
MutatingAuthorized = RequestValid And DisposableMarker And _
|
|
OperatorConfirmation
|
|
|
|
ApiErrors = ""
|
|
NoLocalErrors = ""
|
|
VersionOk = DxReadScalar(Application, "Version", _
|
|
"Application.Version", VersionValue, ApiErrors, NoLocalErrors)
|
|
BuildOk = DxReadScalar(Application, "Build", _
|
|
"Application.Build", BuildValue, ApiErrors, NoLocalErrors)
|
|
ProjectOk = DxReadScalar(Application, "ProjectPath", _
|
|
"Application.ProjectPath", ProjectIdentity, ApiErrors, NoLocalErrors)
|
|
ActiveViewOk = DxReadScalar(ActiveView, "Name", _
|
|
"ActiveView.Name", ActiveViewName, ApiErrors, NoLocalErrors)
|
|
DirtyOk = DxReadScalar(Application, "Modified", _
|
|
"Application.Modified", DirtyValue, ApiErrors, NoLocalErrors)
|
|
|
|
Set Interfaces = CreateObject("Scripting.Dictionary")
|
|
DxInitializeInterfaces Interfaces
|
|
EnumerationAvailable = DxReadCollection(Application, _
|
|
"DesignComponents", "Application.DesignComponents", ComponentValues, _
|
|
ComponentCount, ApiErrors, NoLocalErrors, EnumerationStatus)
|
|
If EnumerationAvailable Then
|
|
If ComponentCount > 0 Then ReDim ComponentRecords(ComponentCount - 1)
|
|
For ComponentIndex = 0 To ComponentCount - 1
|
|
Set Component = ComponentValues(ComponentIndex)
|
|
ComponentRecords(ComponentIndex) = DxSerializeComponent( _
|
|
Component, ComponentIndex, Interfaces, ApiErrors)
|
|
Next
|
|
If ComponentCount > 1 Then
|
|
DxSortRecords ComponentRecords, ComponentCount
|
|
End If
|
|
Else
|
|
ComponentCount = 0
|
|
End If
|
|
If ComponentCount = 0 Then DxSetAllInterfaces Interfaces, False
|
|
|
|
RoutesJson = DxProbeRoutesJson(MutatingAuthorized, MutatingAttempted, _
|
|
ApiErrors)
|
|
|
|
Profile = "{""format_version"":1"
|
|
Profile = Profile & ",""dxdesigner"":{""build"":" & _
|
|
DxScalarJson(BuildValue, BuildOk) & ",""version"":" & _
|
|
DxScalarJson(VersionValue, VersionOk) & "}"
|
|
Profile = Profile & ",""project"":{""active_view"":" & _
|
|
DxScalarJson(ActiveViewName, ActiveViewOk) & ",""dirty"":" & _
|
|
DxBooleanJson(DirtyValue, DirtyOk) & ",""identity"":" & _
|
|
DxScalarJson(ProjectIdentity, ProjectOk) & "}"
|
|
Profile = Profile & ",""enumeration"":{""available"":" & _
|
|
DxBooleanLiteral(EnumerationAvailable) & _
|
|
",""component_count"":" & DxInvariantNumber(ComponentCount) & _
|
|
",""route"":""Application.DesignComponents""}"
|
|
Profile = Profile & ",""components"":" & _
|
|
DxRecordsJson(ComponentRecords, ComponentCount)
|
|
Profile = Profile & ",""interfaces"":" & _
|
|
DxInterfacesJson(Interfaces)
|
|
Profile = Profile & _
|
|
",""production_replace_route"":""native_replace_part"""
|
|
Profile = Profile & ",""routes"":" & RoutesJson
|
|
Profile = Profile & ",""safety"":{""disposable_project_marker"":" & _
|
|
DxBooleanLiteral(DisposableMarker) & _
|
|
",""mutating_probe_attempted"":" & _
|
|
DxBooleanLiteral(MutatingAttempted) & _
|
|
",""mutating_probe_authorized"":" & _
|
|
DxBooleanLiteral(MutatingAuthorized) & _
|
|
",""operator_confirmation"":" & _
|
|
DxBooleanLiteral(OperatorConfirmation) & _
|
|
",""request_valid"":" & DxBooleanLiteral(RequestValid) & "}"
|
|
Profile = Profile & ",""api_errors"":[" & ApiErrors & "]"
|
|
Profile = Profile & _
|
|
",""live_acceptance"":{""checked"":false," & _
|
|
"""reason"":""live_795_host_not_exercised""}}" & vbLf
|
|
DxWriteUtf8Atomic OutputPath, Profile
|
|
End Sub
|
|
|
|
Sub DxProbeParseRequest(ByVal JsonText, ByRef DisposableMarker, _
|
|
ByRef OperatorConfirmation, ByRef IsValid)
|
|
Dim Prefix
|
|
Dim Middle
|
|
Dim Suffix
|
|
Dim Text
|
|
|
|
Prefix = "{""disposable_project_marker"":"
|
|
Middle = ",""format_version"":1,""operator_confirmation"":"
|
|
Suffix = "}" & vbLf
|
|
Text = CStr(JsonText)
|
|
IsValid = True
|
|
Select Case Text
|
|
Case Prefix & "false" & Middle & "false" & Suffix
|
|
DisposableMarker = False
|
|
OperatorConfirmation = False
|
|
Case Prefix & "false" & Middle & "true" & Suffix
|
|
DisposableMarker = False
|
|
OperatorConfirmation = True
|
|
Case Prefix & "true" & Middle & "false" & Suffix
|
|
DisposableMarker = True
|
|
OperatorConfirmation = False
|
|
Case Prefix & "true" & Middle & "true" & Suffix
|
|
DisposableMarker = True
|
|
OperatorConfirmation = True
|
|
Case Else
|
|
IsValid = False
|
|
DisposableMarker = False
|
|
OperatorConfirmation = False
|
|
End Select
|
|
End Sub
|
|
|
|
Function DxReadScalar(ByRef Target, ByVal FieldName, ByVal Operation, _
|
|
ByRef Value, ByRef ApiErrors, ByRef LocalErrors)
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
|
|
On Error Resume Next
|
|
Value = Eval("Target." & CStr(FieldName))
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
Value = Empty
|
|
DxAddErrorPair ApiErrors, LocalErrors, Operation, ErrorNumber, _
|
|
ErrorDescription, ErrorSource
|
|
DxReadScalar = False
|
|
Else
|
|
DxReadScalar = True
|
|
End If
|
|
End Function
|
|
|
|
Function DxReadCollection(ByRef Target, ByVal FieldName, ByVal Operation, _
|
|
ByRef Items, ByRef ItemCount, ByRef ApiErrors, ByRef LocalErrors, _
|
|
ByRef CollectionStatus)
|
|
Dim Values
|
|
Dim ItemValues
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Dim AccessOk
|
|
|
|
CollectionStatus = "unsupported"
|
|
AccessOk = False
|
|
On Error Resume Next
|
|
Set Values = Eval("Target." & CStr(FieldName))
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber = 0 Then
|
|
AccessOk = True
|
|
Else
|
|
DxMergeCollectionStatus CollectionStatus, ErrorNumber
|
|
DxAddErrorPair ApiErrors, LocalErrors, Operation & ".object", _
|
|
ErrorNumber, ErrorDescription, ErrorSource
|
|
End If
|
|
|
|
If Not AccessOk Then
|
|
On Error Resume Next
|
|
Values = Eval("Target." & CStr(FieldName))
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber = 0 Then
|
|
AccessOk = True
|
|
Else
|
|
DxMergeCollectionStatus CollectionStatus, ErrorNumber
|
|
DxAddErrorPair ApiErrors, LocalErrors, Operation & ".variant", _
|
|
ErrorNumber, ErrorDescription, ErrorSource
|
|
End If
|
|
End If
|
|
|
|
If Not AccessOk Then
|
|
ItemCount = 0
|
|
DxReadCollection = False
|
|
Exit Function
|
|
End If
|
|
DxReadCollection = DxCollectItems(Values, Operation & ".enumerate", _
|
|
Items, ItemCount, ApiErrors, LocalErrors, CollectionStatus)
|
|
If DxReadCollection Then
|
|
CollectionStatus = "supported"
|
|
Exit Function
|
|
End If
|
|
|
|
On Error Resume Next
|
|
ItemValues = Eval("Values.Items")
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxMergeCollectionStatus CollectionStatus, ErrorNumber
|
|
DxAddErrorPair ApiErrors, LocalErrors, Operation & ".Items", _
|
|
ErrorNumber, ErrorDescription, ErrorSource
|
|
ItemCount = 0
|
|
DxReadCollection = False
|
|
Exit Function
|
|
End If
|
|
DxReadCollection = DxCollectItems(ItemValues, Operation & ".Items.enumerate", _
|
|
Items, ItemCount, ApiErrors, LocalErrors, CollectionStatus)
|
|
If DxReadCollection Then CollectionStatus = "supported"
|
|
End Function
|
|
|
|
Function DxCollectItems(ByRef Values, ByVal Operation, ByRef Items, _
|
|
ByRef ItemCount, ByRef ApiErrors, ByRef LocalErrors, _
|
|
ByRef CollectionStatus)
|
|
Dim Item
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
|
|
ItemCount = 0
|
|
ReDim Items(0)
|
|
On Error Resume Next
|
|
For Each Item In Values
|
|
If ItemCount > 0 Then ReDim Preserve Items(ItemCount)
|
|
If IsObject(Item) Then
|
|
Set Items(ItemCount) = Item
|
|
Else
|
|
Items(ItemCount) = Item
|
|
End If
|
|
ItemCount = ItemCount + 1
|
|
Next
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxMergeCollectionStatus CollectionStatus, ErrorNumber
|
|
ItemCount = 0
|
|
DxAddErrorPair ApiErrors, LocalErrors, Operation, ErrorNumber, _
|
|
ErrorDescription, ErrorSource
|
|
DxCollectItems = False
|
|
Else
|
|
DxCollectItems = True
|
|
End If
|
|
End Function
|
|
|
|
Sub DxMergeCollectionStatus(ByRef CollectionStatus, ByVal ErrorNumber)
|
|
If DxProbeErrorStatus(ErrorNumber) = "read_error" Then
|
|
CollectionStatus = "read_error"
|
|
ElseIf CStr(CollectionStatus) <> "read_error" Then
|
|
CollectionStatus = "unsupported"
|
|
End If
|
|
End Sub
|
|
|
|
Sub DxInitializeInterfaces(ByRef Interfaces)
|
|
Interfaces.Add "attributes", True
|
|
Interfaces.Add "gates", True
|
|
Interfaces.Add "hierarchy", True
|
|
Interfaces.Add "logical_identity", True
|
|
Interfaces.Add "mirror", True
|
|
Interfaces.Add "nets", True
|
|
Interfaces.Add "origin_x", True
|
|
Interfaces.Add "origin_y", True
|
|
Interfaces.Add "part_number", True
|
|
Interfaces.Add "parameter_probe", True
|
|
Interfaces.Add "pins", True
|
|
Interfaces.Add "position_x", True
|
|
Interfaces.Add "position_y", True
|
|
Interfaces.Add "refdes", True
|
|
Interfaces.Add "rotation", True
|
|
Interfaces.Add "symbol_identity", True
|
|
Interfaces.Add "units", True
|
|
End Sub
|
|
|
|
Sub DxSetAllInterfaces(ByRef Interfaces, ByVal Available)
|
|
Dim Name
|
|
For Each Name In Interfaces.Keys
|
|
Interfaces(Name) = CBool(Available)
|
|
Next
|
|
End Sub
|
|
|
|
Function DxSerializeComponent(ByRef Component, ByVal ComponentIndex, _
|
|
ByRef Interfaces, ByRef ApiErrors)
|
|
Dim Prefix
|
|
Dim ComponentErrors
|
|
Dim LogicalIdentity
|
|
Dim LogicalOk
|
|
Dim Hierarchy
|
|
Dim HierarchyOk
|
|
Dim PartNumber
|
|
Dim PartNumberOk
|
|
Dim RefDes
|
|
Dim RefDesOk
|
|
Dim Units
|
|
Dim UnitsOk
|
|
Dim SymbolIdentity
|
|
Dim SymbolOk
|
|
Dim OriginX
|
|
Dim OriginXOk
|
|
Dim OriginY
|
|
Dim OriginYOk
|
|
Dim PositionX
|
|
Dim PositionXOk
|
|
Dim PositionY
|
|
Dim PositionYOk
|
|
Dim Rotation
|
|
Dim RotationOk
|
|
Dim Mirror
|
|
Dim MirrorOk
|
|
Dim GatesJson
|
|
Dim AttributesJson
|
|
Dim ParameterProbeJson
|
|
Dim PinsJson
|
|
Dim NetsJson
|
|
Dim Result
|
|
|
|
Prefix = "component[" & DxInvariantNumber(ComponentIndex) & "]"
|
|
ComponentErrors = ""
|
|
LogicalOk = DxReadScalar(Component, "LogicalIdentity", _
|
|
Prefix & ".LogicalIdentity", LogicalIdentity, ApiErrors, ComponentErrors)
|
|
DxMarkInterface Interfaces, "logical_identity", LogicalOk
|
|
HierarchyOk = DxReadScalar(Component, "Hierarchy", Prefix & ".Hierarchy", _
|
|
Hierarchy, ApiErrors, ComponentErrors)
|
|
DxMarkInterface Interfaces, "hierarchy", HierarchyOk
|
|
PartNumberOk = DxReadScalar(Component, "PartNumber", _
|
|
Prefix & ".PartNumber", PartNumber, ApiErrors, ComponentErrors)
|
|
DxMarkInterface Interfaces, "part_number", PartNumberOk
|
|
RefDesOk = DxReadScalar(Component, "RefDes", Prefix & ".RefDes", _
|
|
RefDes, ApiErrors, ComponentErrors)
|
|
DxMarkInterface Interfaces, "refdes", RefDesOk
|
|
UnitsOk = DxReadScalar(Component, "Units", Prefix & ".Units", _
|
|
Units, ApiErrors, ComponentErrors)
|
|
DxMarkInterface Interfaces, "units", UnitsOk
|
|
SymbolOk = DxReadScalar(Component, "SymbolName", Prefix & ".SymbolName", _
|
|
SymbolIdentity, ApiErrors, ComponentErrors)
|
|
DxMarkInterface Interfaces, "symbol_identity", SymbolOk
|
|
OriginXOk = DxReadScalar(Component, "OriginX", Prefix & ".OriginX", _
|
|
OriginX, ApiErrors, ComponentErrors)
|
|
DxMarkInterface Interfaces, "origin_x", OriginXOk
|
|
OriginYOk = DxReadScalar(Component, "OriginY", Prefix & ".OriginY", _
|
|
OriginY, ApiErrors, ComponentErrors)
|
|
DxMarkInterface Interfaces, "origin_y", OriginYOk
|
|
PositionXOk = DxReadScalar(Component, "X", Prefix & ".X", _
|
|
PositionX, ApiErrors, ComponentErrors)
|
|
DxMarkInterface Interfaces, "position_x", PositionXOk
|
|
PositionYOk = DxReadScalar(Component, "Y", Prefix & ".Y", _
|
|
PositionY, ApiErrors, ComponentErrors)
|
|
DxMarkInterface Interfaces, "position_y", PositionYOk
|
|
RotationOk = DxReadScalar(Component, "Rotation", Prefix & ".Rotation", _
|
|
Rotation, ApiErrors, ComponentErrors)
|
|
DxMarkInterface Interfaces, "rotation", RotationOk
|
|
MirrorOk = DxReadScalar(Component, "Mirrored", Prefix & ".Mirrored", _
|
|
Mirror, ApiErrors, ComponentErrors)
|
|
DxMarkInterface Interfaces, "mirror", MirrorOk
|
|
|
|
GatesJson = DxSerializeGates(Component, Prefix, Interfaces, ApiErrors, _
|
|
ComponentErrors)
|
|
AttributesJson = DxSerializeAttributes(Component, Prefix, Interfaces, _
|
|
ApiErrors, ComponentErrors)
|
|
ParameterProbeJson = DxSerializeParameterProbe(Component, Prefix, Interfaces, _
|
|
ApiErrors, ComponentErrors)
|
|
PinsJson = DxSerializePins(Component, Prefix, Interfaces, ApiErrors, _
|
|
ComponentErrors)
|
|
NetsJson = DxSerializeNets(Component, Prefix, Interfaces, ApiErrors, _
|
|
ComponentErrors)
|
|
|
|
Result = "{""logical_identity"":" & _
|
|
DxScalarJson(LogicalIdentity, LogicalOk)
|
|
Result = Result & ",""hierarchy"":" & _
|
|
DxScalarJson(Hierarchy, HierarchyOk)
|
|
Result = Result & ",""part_number"":" & _
|
|
DxScalarJson(PartNumber, PartNumberOk)
|
|
Result = Result & ",""refdes"":" & DxScalarJson(RefDes, RefDesOk)
|
|
Result = Result & ",""units"":" & DxNumberJson(Units, UnitsOk)
|
|
Result = Result & ",""gates"":" & GatesJson
|
|
Result = Result & ",""symbol_identity"":" & _
|
|
DxScalarJson(SymbolIdentity, SymbolOk)
|
|
Result = Result & ",""origin"":{""x"":" & _
|
|
DxNumberJson(OriginX, OriginXOk) & ",""y"":" & _
|
|
DxNumberJson(OriginY, OriginYOk) & "}"
|
|
Result = Result & ",""position"":{""x"":" & _
|
|
DxNumberJson(PositionX, PositionXOk) & ",""y"":" & _
|
|
DxNumberJson(PositionY, PositionYOk) & "}"
|
|
Result = Result & ",""rotation"":" & _
|
|
DxNumberJson(Rotation, RotationOk)
|
|
Result = Result & ",""mirror"":" & DxBooleanJson(Mirror, MirrorOk)
|
|
Result = Result & ",""attributes"":" & AttributesJson
|
|
Result = Result & ",""parameter_probe"":" & ParameterProbeJson
|
|
Result = Result & ",""pins"":" & PinsJson
|
|
Result = Result & ",""nets"":" & NetsJson
|
|
Result = Result & ",""api_errors"":[" & ComponentErrors & "]}"
|
|
DxSerializeComponent = Result
|
|
End Function
|
|
|
|
Sub DxMarkInterface(ByRef Interfaces, ByVal Name, ByVal Available)
|
|
If Not CBool(Available) Then Interfaces(CStr(Name)) = False
|
|
End Sub
|
|
|
|
Function DxSerializeGates(ByRef Component, ByVal Prefix, ByRef Interfaces, _
|
|
ByRef ApiErrors, ByRef ComponentErrors)
|
|
Dim Values
|
|
Dim Count
|
|
Dim Available
|
|
Dim CollectionStatus
|
|
Dim Records()
|
|
Dim Index
|
|
Dim Item
|
|
Dim NameValue
|
|
Dim NameOk
|
|
Dim UnitValue
|
|
Dim UnitOk
|
|
Dim Operation
|
|
|
|
Available = DxReadCollection(Component, "Gates", Prefix & ".Gates", _
|
|
Values, Count, ApiErrors, ComponentErrors, CollectionStatus)
|
|
If Not Available Then
|
|
Interfaces("gates") = False
|
|
DxSerializeGates = "null"
|
|
Exit Function
|
|
End If
|
|
If Count > 0 Then ReDim Records(Count - 1)
|
|
For Index = 0 To Count - 1
|
|
Set Item = Values(Index)
|
|
Operation = Prefix & ".Gates[" & DxInvariantNumber(Index) & "]"
|
|
NameOk = DxReadScalar(Item, "Name", Operation & ".Name", _
|
|
NameValue, ApiErrors, ComponentErrors)
|
|
UnitOk = DxReadScalar(Item, "UnitNumber", _
|
|
Operation & ".UnitNumber", UnitValue, ApiErrors, ComponentErrors)
|
|
If Not NameOk Or Not UnitOk Then Interfaces("gates") = False
|
|
Records(Index) = "{""name"":" & DxScalarJson(NameValue, NameOk) & _
|
|
",""unit_number"":" & DxNumberJson(UnitValue, UnitOk) & "}"
|
|
Next
|
|
If Count > 1 Then DxSortRecords Records, Count
|
|
DxSerializeGates = DxRecordsJson(Records, Count)
|
|
End Function
|
|
|
|
Function DxSerializeAttributes(ByRef Component, ByVal Prefix, _
|
|
ByRef Interfaces, ByRef ApiErrors, ByRef ComponentErrors)
|
|
Dim Values
|
|
Dim Count
|
|
Dim Available
|
|
Dim CollectionStatus
|
|
Dim Records()
|
|
Dim Index
|
|
Dim Item
|
|
Dim NameValue
|
|
Dim NameOk
|
|
Dim ValueValue
|
|
Dim ValueOk
|
|
Dim Operation
|
|
|
|
Available = DxReadCollection(Component, "Attributes", _
|
|
Prefix & ".Attributes", Values, Count, ApiErrors, ComponentErrors, _
|
|
CollectionStatus)
|
|
If Not Available Then
|
|
Interfaces("attributes") = False
|
|
DxSerializeAttributes = "null"
|
|
Exit Function
|
|
End If
|
|
If Count > 0 Then ReDim Records(Count - 1)
|
|
For Index = 0 To Count - 1
|
|
Set Item = Values(Index)
|
|
Operation = Prefix & ".Attributes[" & DxInvariantNumber(Index) & "]"
|
|
NameOk = DxReadScalar(Item, "Name", Operation & ".Name", _
|
|
NameValue, ApiErrors, ComponentErrors)
|
|
ValueOk = DxReadScalar(Item, "Value", Operation & ".Value", _
|
|
ValueValue, ApiErrors, ComponentErrors)
|
|
If Not NameOk Or Not ValueOk Then Interfaces("attributes") = False
|
|
Records(Index) = "{""name"":" & DxScalarJson(NameValue, NameOk) & _
|
|
",""value"":" & DxScalarJson(ValueValue, ValueOk) & "}"
|
|
Next
|
|
If Count > 1 Then DxSortRecords Records, Count
|
|
DxSerializeAttributes = DxRecordsJson(Records, Count)
|
|
End Function
|
|
|
|
Function DxSerializeParameterProbe(ByRef Component, ByVal Prefix, _
|
|
ByRef Interfaces, ByRef ApiErrors, ByRef ComponentErrors)
|
|
Dim Values
|
|
Dim Count
|
|
Dim Available
|
|
Dim CollectionStatus
|
|
Dim Records()
|
|
Dim Index
|
|
Dim Item
|
|
Dim Operation
|
|
Dim KeyQueries
|
|
|
|
Available = DxReadCollection(Component, "Attributes", _
|
|
Prefix & ".Attributes", Values, Count, ApiErrors, ComponentErrors, _
|
|
CollectionStatus)
|
|
DxMarkInterface Interfaces, "parameter_probe", Available
|
|
If Available Then
|
|
If Count > 0 Then ReDim Records(Count - 1)
|
|
For Index = 0 To Count - 1
|
|
Set Item = Values(Index)
|
|
Operation = Prefix & ".Attributes[" & DxInvariantNumber(Index) & "]"
|
|
Records(Index) = DxSerializeParameterInstance(Item, Operation, _
|
|
ApiErrors, ComponentErrors)
|
|
Next
|
|
If Count > 1 Then DxSortRecords Records, Count
|
|
KeyQueries = DxParameterAttributeKeyQueriesJson(Component, Prefix, _
|
|
ApiErrors, ComponentErrors)
|
|
DxSerializeParameterProbe = "{""enumeration"":{""count"":" & _
|
|
DxInvariantNumber(Count) & ",""route"":""component.Attributes""," & _
|
|
"""status"":""supported""},""instances"":" & _
|
|
DxRecordsJson(Records, Count) & ",""key_queries"":" & _
|
|
KeyQueries & "}"
|
|
Else
|
|
KeyQueries = DxParameterAttributeKeyQueriesJson(Component, Prefix, _
|
|
ApiErrors, ComponentErrors)
|
|
DxSerializeParameterProbe = "{""enumeration"":{""count"":0," & _
|
|
"""route"":""component.Attributes"",""status"":" & _
|
|
DxJsonString(CollectionStatus) & _
|
|
"},""instances"":[],""key_queries"":" & KeyQueries & "}"
|
|
End If
|
|
End Function
|
|
|
|
Function DxParameterAttributeKeyQueriesJson(ByRef Component, ByVal Prefix, _
|
|
ByRef ApiErrors, ByRef ComponentErrors)
|
|
Dim Values
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Dim KeySourceStatus
|
|
|
|
KeySourceStatus = "unsupported"
|
|
On Error Resume Next
|
|
Set Values = Component.Attributes
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber = 0 Then
|
|
DxParameterAttributeKeyQueriesJson = DxParameterKeyQueriesJson( _
|
|
Values, Prefix, ApiErrors, ComponentErrors)
|
|
Else
|
|
DxAddErrorPair ApiErrors, ComponentErrors, _
|
|
Prefix & ".Attributes.key_source.object", ErrorNumber, _
|
|
ErrorDescription, ErrorSource
|
|
DxMergeCollectionStatus KeySourceStatus, ErrorNumber
|
|
On Error Resume Next
|
|
Values = Component.Attributes
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber = 0 Then
|
|
DxParameterAttributeKeyQueriesJson = DxParameterKeyQueriesJson( _
|
|
Values, Prefix, ApiErrors, ComponentErrors)
|
|
Else
|
|
DxAddErrorPair ApiErrors, ComponentErrors, _
|
|
Prefix & ".Attributes.key_source.variant", ErrorNumber, _
|
|
ErrorDescription, ErrorSource
|
|
DxMergeCollectionStatus KeySourceStatus, ErrorNumber
|
|
DxParameterAttributeKeyQueriesJson = DxParameterUnavailableKeyQueriesJson( _
|
|
KeySourceStatus)
|
|
End If
|
|
End If
|
|
End Function
|
|
|
|
Function DxParameterUnavailableKeyQueriesJson(ByVal Status)
|
|
Dim Keys
|
|
Dim Index
|
|
Dim Result
|
|
|
|
Keys = Array("Value", "Value1", "Part Number", "Part Label")
|
|
Result = "{"
|
|
For Index = 0 To UBound(Keys)
|
|
If Index > 0 Then Result = Result & ","
|
|
Result = Result & DxJsonString(Keys(Index)) & _
|
|
":{""exists"":false,""item_type"":null,""status"":" & _
|
|
DxJsonString(Status) & "}"
|
|
Next
|
|
DxParameterUnavailableKeyQueriesJson = Result & "}"
|
|
End Function
|
|
|
|
Function DxSerializeParameterInstance(ByRef Item, ByVal Operation, _
|
|
ByRef ApiErrors, ByRef ComponentErrors)
|
|
Dim Result
|
|
|
|
Result = "{""name"":" & DxParameterFieldJson(Item, "Name", _
|
|
Operation & ".Name", ApiErrors, ComponentErrors)
|
|
Result = Result & ",""value"":" & DxParameterFieldJson(Item, "Value", _
|
|
Operation & ".Value", ApiErrors, ComponentErrors)
|
|
Result = Result & ",""text_string"":" & _
|
|
DxParameterFieldJson(Item, "TextString", Operation & ".TextString", _
|
|
ApiErrors, ComponentErrors)
|
|
Result = Result & ",""text_location"":" & _
|
|
DxParameterLocationJson(Item, Operation, ApiErrors, ComponentErrors)
|
|
Result = Result & ",""presentation"":{""color"":" & _
|
|
DxParameterFieldJson(Item, "Color", Operation & ".Color", _
|
|
ApiErrors, ComponentErrors)
|
|
Result = Result & ",""font"":" & DxParameterFieldJson(Item, "Font", _
|
|
Operation & ".Font", ApiErrors, ComponentErrors)
|
|
Result = Result & ",""orientation"":" & _
|
|
DxParameterFieldJson(Item, "Orientation", Operation & ".Orientation", _
|
|
ApiErrors, ComponentErrors)
|
|
Result = Result & ",""origin"":" & DxParameterFieldJson(Item, "Origin", _
|
|
Operation & ".Origin", ApiErrors, ComponentErrors)
|
|
Result = Result & ",""size"":" & DxParameterFieldJson(Item, "Size", _
|
|
Operation & ".Size", ApiErrors, ComponentErrors)
|
|
Result = Result & ",""visible"":" & DxParameterFieldJson(Item, "Visible", _
|
|
Operation & ".Visible", ApiErrors, ComponentErrors) & "}"
|
|
Result = Result & ",""parent_type"":" & DxParameterParentTypeJson(Item, _
|
|
Operation & ".Parent", ApiErrors, ComponentErrors) & "}"
|
|
DxSerializeParameterInstance = Result
|
|
End Function
|
|
|
|
Function DxParameterFieldJson(ByRef Target, ByVal FieldName, ByVal Operation, _
|
|
ByRef ApiErrors, ByRef ComponentErrors)
|
|
Dim Value
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Dim Status
|
|
|
|
On Error Resume Next
|
|
Value = Eval("Target." & CStr(FieldName))
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber = 0 Then
|
|
Status = "supported"
|
|
DxParameterFieldJson = "{""status"":""supported"",""value"":" & _
|
|
DxProbeValueJson(Value) & "}"
|
|
Else
|
|
Status = DxProbeErrorStatus(ErrorNumber)
|
|
DxAddErrorPair ApiErrors, ComponentErrors, Operation, ErrorNumber, _
|
|
ErrorDescription, ErrorSource
|
|
DxParameterFieldJson = "{""status"":" & DxJsonString(Status) & _
|
|
",""value"":null}"
|
|
End If
|
|
End Function
|
|
|
|
Function DxParameterLocationJson(ByRef Item, ByVal Operation, _
|
|
ByRef ApiErrors, ByRef ComponentErrors)
|
|
Dim Location
|
|
Dim XValue
|
|
Dim YValue
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Dim XOk
|
|
Dim YOk
|
|
Dim XStatus
|
|
Dim YStatus
|
|
Dim Status
|
|
|
|
On Error Resume Next
|
|
Set Location = Item.GetLocation
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
Status = DxProbeErrorStatus(ErrorNumber)
|
|
DxAddErrorPair ApiErrors, ComponentErrors, Operation & ".GetLocation", _
|
|
ErrorNumber, ErrorDescription, ErrorSource
|
|
DxParameterLocationJson = "{""status"":" & DxJsonString(Status) & _
|
|
",""x"":null,""y"":null}"
|
|
Exit Function
|
|
End If
|
|
XOk = DxReadParameterLocationAxis(Location, "X", _
|
|
Operation & ".GetLocation.X", XValue, XStatus, ApiErrors, ComponentErrors)
|
|
YOk = DxReadParameterLocationAxis(Location, "Y", _
|
|
Operation & ".GetLocation.Y", YValue, YStatus, ApiErrors, ComponentErrors)
|
|
If XOk And YOk Then
|
|
Status = "supported"
|
|
ElseIf XStatus = "read_error" Or YStatus = "read_error" Then
|
|
Status = "read_error"
|
|
Else
|
|
Status = "unsupported"
|
|
End If
|
|
DxParameterLocationJson = "{""status"":" & DxJsonString(Status) & _
|
|
",""x"":" & DxNumberJson(XValue, XOk) & ",""y"":" & _
|
|
DxNumberJson(YValue, YOk) & "}"
|
|
End Function
|
|
|
|
Function DxReadParameterLocationAxis(ByRef Location, ByVal AxisName, _
|
|
ByVal Operation, ByRef Value, ByRef Status, ByRef ApiErrors, _
|
|
ByRef ComponentErrors)
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
|
|
On Error Resume Next
|
|
Value = Eval("Location." & CStr(AxisName))
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber = 0 Then
|
|
Status = "supported"
|
|
DxReadParameterLocationAxis = True
|
|
Else
|
|
Value = Empty
|
|
Status = DxProbeErrorStatus(ErrorNumber)
|
|
DxAddErrorPair ApiErrors, ComponentErrors, Operation, ErrorNumber, _
|
|
ErrorDescription, ErrorSource
|
|
DxReadParameterLocationAxis = False
|
|
End If
|
|
End Function
|
|
|
|
Function DxParameterParentTypeJson(ByRef Item, ByVal Operation, _
|
|
ByRef ApiErrors, ByRef ComponentErrors)
|
|
Dim Owner
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Dim Status
|
|
|
|
On Error Resume Next
|
|
Set Owner = Item.Parent
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber = 0 Then
|
|
DxParameterParentTypeJson = "{""status"":""supported"",""value"":" & _
|
|
DxJsonString(TypeName(Owner)) & "}"
|
|
Else
|
|
Status = DxProbeErrorStatus(ErrorNumber)
|
|
DxAddErrorPair ApiErrors, ComponentErrors, Operation, ErrorNumber, _
|
|
ErrorDescription, ErrorSource
|
|
DxParameterParentTypeJson = "{""status"":" & DxJsonString(Status) & _
|
|
",""value"":null}"
|
|
End If
|
|
End Function
|
|
|
|
Function DxParameterKeyQueriesJson(ByRef Values, ByVal Prefix, _
|
|
ByRef ApiErrors, ByRef ComponentErrors)
|
|
Dim Keys
|
|
Dim Index
|
|
Dim Result
|
|
|
|
Keys = Array("Value", "Value1", "Part Number", "Part Label")
|
|
Result = "{"
|
|
For Index = 0 To UBound(Keys)
|
|
If Index > 0 Then Result = Result & ","
|
|
Result = Result & DxJsonString(Keys(Index)) & ":" & _
|
|
DxParameterKeyQueryJson(Values, Keys(Index), Prefix, ApiErrors, _
|
|
ComponentErrors)
|
|
Next
|
|
DxParameterKeyQueriesJson = Result & "}"
|
|
End Function
|
|
|
|
Function DxParameterKeyQueryJson(ByRef Values, ByVal Key, ByVal Prefix, _
|
|
ByRef ApiErrors, ByRef ComponentErrors)
|
|
Dim Item
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Dim Status
|
|
Dim Operation
|
|
|
|
Operation = Prefix & ".Attributes.key[" & CStr(Key) & "]"
|
|
On Error Resume Next
|
|
Set Item = Values.Item(CStr(Key))
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber = 0 Then
|
|
DxParameterKeyQueryJson = "{""exists"":true,""item_type"":" & _
|
|
DxJsonString(TypeName(Item)) & ",""status"":""supported""," & _
|
|
"""instance"":" & DxSerializeParameterInstance(Item, Operation, _
|
|
ApiErrors, ComponentErrors) & "}"
|
|
Else
|
|
Status = DxProbeErrorStatus(ErrorNumber)
|
|
DxAddErrorPair ApiErrors, ComponentErrors, Operation, ErrorNumber, _
|
|
ErrorDescription, ErrorSource
|
|
DxParameterKeyQueryJson = "{""exists"":false,""item_type"":null," & _
|
|
"""status"":" & DxJsonString(Status) & "}"
|
|
End If
|
|
End Function
|
|
|
|
Function DxProbeErrorStatus(ByVal ErrorNumber)
|
|
Select Case CLng(ErrorNumber)
|
|
Case 5, 9, 424, 438, 451, 3265, 32811
|
|
DxProbeErrorStatus = "unsupported"
|
|
Case Else
|
|
DxProbeErrorStatus = "read_error"
|
|
End Select
|
|
End Function
|
|
|
|
Function DxProbeValueJson(ByVal Value)
|
|
Select Case VarType(Value)
|
|
Case vbEmpty, vbNull
|
|
DxProbeValueJson = "null"
|
|
Case vbString
|
|
DxProbeValueJson = DxJsonString(Value)
|
|
Case vbBoolean
|
|
DxProbeValueJson = DxBooleanLiteral(CBool(Value))
|
|
Case vbByte, vbInteger, vbLong, vbSingle, vbDouble, vbCurrency, 14
|
|
DxProbeValueJson = DxInvariantNumber(Value)
|
|
Case Else
|
|
DxProbeValueJson = DxJsonString(Value)
|
|
End Select
|
|
End Function
|
|
|
|
Function DxSerializePins(ByRef Component, ByVal Prefix, ByRef Interfaces, _
|
|
ByRef ApiErrors, ByRef ComponentErrors)
|
|
Dim Values
|
|
Dim Count
|
|
Dim Available
|
|
Dim CollectionStatus
|
|
Dim Records()
|
|
Dim Index
|
|
Dim Item
|
|
Dim NumberValue
|
|
Dim NumberOk
|
|
Dim NameValue
|
|
Dim NameOk
|
|
Dim XValue
|
|
Dim XOk
|
|
Dim YValue
|
|
Dim YOk
|
|
Dim NetValue
|
|
Dim NetOk
|
|
Dim Operation
|
|
|
|
Available = DxReadCollection(Component, "Pins", Prefix & ".Pins", _
|
|
Values, Count, ApiErrors, ComponentErrors, CollectionStatus)
|
|
If Not Available Then
|
|
Interfaces("pins") = False
|
|
DxSerializePins = "null"
|
|
Exit Function
|
|
End If
|
|
If Count > 0 Then ReDim Records(Count - 1)
|
|
For Index = 0 To Count - 1
|
|
Set Item = Values(Index)
|
|
Operation = Prefix & ".Pins[" & DxInvariantNumber(Index) & "]"
|
|
NumberOk = DxReadScalar(Item, "Number", Operation & ".Number", _
|
|
NumberValue, ApiErrors, ComponentErrors)
|
|
NameOk = DxReadScalar(Item, "Name", Operation & ".Name", _
|
|
NameValue, ApiErrors, ComponentErrors)
|
|
XOk = DxReadScalar(Item, "X", Operation & ".X", XValue, _
|
|
ApiErrors, ComponentErrors)
|
|
YOk = DxReadScalar(Item, "Y", Operation & ".Y", YValue, _
|
|
ApiErrors, ComponentErrors)
|
|
NetOk = DxReadScalar(Item, "NetIdentity", _
|
|
Operation & ".NetIdentity", NetValue, ApiErrors, ComponentErrors)
|
|
If Not NumberOk Or Not NameOk Or Not XOk Or Not YOk Or _
|
|
Not NetOk Then Interfaces("pins") = False
|
|
Records(Index) = "{""name"":" & DxScalarJson(NameValue, NameOk) & _
|
|
",""net_identity"":" & DxScalarJson(NetValue, NetOk) & _
|
|
",""number"":" & DxScalarJson(NumberValue, NumberOk) & _
|
|
",""x"":" & DxNumberJson(XValue, XOk) & ",""y"":" & _
|
|
DxNumberJson(YValue, YOk) & "}"
|
|
Next
|
|
If Count > 1 Then DxSortRecords Records, Count
|
|
DxSerializePins = DxRecordsJson(Records, Count)
|
|
End Function
|
|
|
|
Function DxSerializeNets(ByRef Component, ByVal Prefix, ByRef Interfaces, _
|
|
ByRef ApiErrors, ByRef ComponentErrors)
|
|
Dim Values
|
|
Dim Count
|
|
Dim Available
|
|
Dim CollectionStatus
|
|
Dim Records()
|
|
Dim Index
|
|
Dim Value
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
|
|
Available = DxReadCollection(Component, "Nets", Prefix & ".Nets", _
|
|
Values, Count, ApiErrors, ComponentErrors, CollectionStatus)
|
|
If Not Available Then
|
|
Interfaces("nets") = False
|
|
DxSerializeNets = "null"
|
|
Exit Function
|
|
End If
|
|
If Count > 0 Then ReDim Records(Count - 1)
|
|
For Index = 0 To Count - 1
|
|
On Error Resume Next
|
|
Value = CStr(Values(Index))
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
Interfaces("nets") = False
|
|
DxAddErrorPair ApiErrors, ComponentErrors, Prefix & ".Nets[" & _
|
|
DxInvariantNumber(Index) & "]", ErrorNumber, _
|
|
ErrorDescription, ErrorSource
|
|
Records(Index) = "null"
|
|
Else
|
|
Records(Index) = DxJsonString(Value)
|
|
End If
|
|
Next
|
|
If Count > 1 Then DxSortRecords Records, Count
|
|
DxSerializeNets = DxRecordsJson(Records, Count)
|
|
End Function
|
|
|
|
Function DxProbeRoutesJson(ByVal Authorized, ByRef MutatingAttempted, _
|
|
ByRef ApiErrors)
|
|
Dim Result
|
|
MutatingAttempted = False
|
|
Result = "{" & DxRouteJson("exact_set_selection", _
|
|
"ActiveView.SelectExactSet", True, False, _
|
|
"operator_select_exact_group", ApiErrors, MutatingAttempted, False)
|
|
Result = Result & "," & DxRouteJson("native_replace_part", _
|
|
"Application.OpenReplacePartDialog", True, False, _
|
|
"operator_open_native_replace_part", ApiErrors, _
|
|
MutatingAttempted, False)
|
|
Result = Result & "," & DxRouteJson("completion_observation", _
|
|
"Application.ReplacePartCompleted", False, Authorized, _
|
|
"operator_confirm_then_inventory", ApiErrors, _
|
|
MutatingAttempted, False)
|
|
Result = Result & "," & DxRouteJson("undo", "Application.Undo", _
|
|
True, False, "operator_use_native_undo", ApiErrors, _
|
|
MutatingAttempted, False)
|
|
Result = Result & "," & DxRouteJson("save", "Application.Save", _
|
|
True, False, "operator_use_native_save", ApiErrors, _
|
|
MutatingAttempted, False)
|
|
Result = Result & "," & DxRouteJson("open_project", _
|
|
"Application.OpenProject", True, False, "operator_open_project", _
|
|
ApiErrors, MutatingAttempted, False)
|
|
Result = Result & "," & DxRouteJson("close_project", _
|
|
"Application.CloseProject", True, False, _
|
|
"operator_close_without_save", ApiErrors, MutatingAttempted, False)
|
|
Result = Result & "," & DxRouteJson("packager", _
|
|
"Application.RunPackager", True, False, "operator_run_packager", _
|
|
ApiErrors, MutatingAttempted, False)
|
|
Result = Result & "," & DxRouteJson("erc", "Application.RunERC", _
|
|
True, False, "operator_run_erc", ApiErrors, _
|
|
MutatingAttempted, False)
|
|
Result = Result & "," & DxRouteJson("netlist", _
|
|
"Application.RunNetlist", True, False, "operator_run_netlist", _
|
|
ApiErrors, MutatingAttempted, False)
|
|
Result = Result & "," & DxRouteJson("ccomp_research", _
|
|
"Application.CComp", True, False, "research_only", ApiErrors, _
|
|
MutatingAttempted, True)
|
|
DxProbeRoutesJson = Result & "}"
|
|
End Function
|
|
|
|
Function DxRouteJson(ByVal Name, ByVal Candidate, ByVal IsMutating, _
|
|
ByVal Authorized, ByVal ManualFallback, ByRef ApiErrors, _
|
|
ByRef MutatingAttempted, ByVal ProductionDisabled)
|
|
Dim Attempted
|
|
Dim Available
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Dim ErrorJson
|
|
Dim Operation
|
|
Dim Result
|
|
|
|
Attempted = (Not IsMutating) Or CBool(Authorized)
|
|
Available = False
|
|
ErrorJson = "null"
|
|
Operation = "route." & CStr(Name) & "." & CStr(Candidate)
|
|
If Attempted Then
|
|
If IsMutating Then MutatingAttempted = True
|
|
Available = DxInvokeRoute(Name, ErrorNumber, ErrorDescription, ErrorSource)
|
|
If Not Available Then
|
|
ErrorJson = DxErrorJson(Operation, ErrorNumber, ErrorDescription, _
|
|
ErrorSource)
|
|
DxAppendJson ApiErrors, ErrorJson
|
|
End If
|
|
End If
|
|
|
|
Result = DxJsonString(Name) & ":{""attempted"":" & _
|
|
DxBooleanLiteral(Attempted) & ",""available"":" & _
|
|
DxBooleanLiteral(Available) & ",""manual_fallback"":" & _
|
|
DxJsonString(ManualFallback) & ",""route"":" & _
|
|
DxJsonString(Candidate) & ",""attempts"":[{""route"":" & _
|
|
DxJsonString(Candidate) & ",""attempted"":" & _
|
|
DxBooleanLiteral(Attempted) & ",""available"":" & _
|
|
DxBooleanLiteral(Available) & ",""error"":" & ErrorJson & "}]"
|
|
If ProductionDisabled Then
|
|
Result = Result & ",""production_enabled"":false"
|
|
End If
|
|
DxRouteJson = Result & "}"
|
|
End Function
|
|
|
|
Function DxInvokeRoute(ByVal Name, ByRef ErrorNumber, _
|
|
ByRef ErrorDescription, ByRef ErrorSource)
|
|
Dim Ignored
|
|
On Error Resume Next
|
|
Select Case CStr(Name)
|
|
Case "completion_observation"
|
|
Ignored = Application.ReplacePartCompleted
|
|
End Select
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
DxInvokeRoute = (ErrorNumber = 0)
|
|
End Function
|
|
|
|
Sub DxAddErrorPair(ByRef ApiErrors, ByRef LocalErrors, ByVal Operation, _
|
|
ByVal ErrorNumber, ByVal ErrorDescription, ByVal ErrorSource)
|
|
Dim Record
|
|
Record = DxErrorJson(Operation, ErrorNumber, ErrorDescription, ErrorSource)
|
|
DxAppendJson ApiErrors, Record
|
|
DxAppendJson LocalErrors, Record
|
|
End Sub
|
|
|
|
Function DxErrorJson(ByVal Operation, ByVal ErrorNumber, _
|
|
ByVal ErrorDescription, ByVal ErrorSource)
|
|
DxErrorJson = "{""description"":" & DxJsonString(ErrorDescription) & _
|
|
",""number"":" & DxInvariantNumber(ErrorNumber) & _
|
|
",""operation"":" & DxJsonString(Operation) & _
|
|
",""source"":" & DxJsonString(ErrorSource) & "}"
|
|
End Function
|
|
|
|
Sub DxAppendJson(ByRef JsonItems, ByVal Record)
|
|
If Len(CStr(JsonItems)) = 0 Then
|
|
JsonItems = CStr(Record)
|
|
Else
|
|
JsonItems = CStr(JsonItems) & "," & CStr(Record)
|
|
End If
|
|
End Sub
|
|
|
|
Sub DxSortRecords(ByRef Records, ByVal Count)
|
|
Dim Index
|
|
Dim Prior
|
|
Dim Value
|
|
For Index = 1 To Count - 1
|
|
Value = Records(Index)
|
|
Prior = Index - 1
|
|
Do While Prior >= 0
|
|
If StrComp(Records(Prior), Value, vbBinaryCompare) <= 0 Then Exit Do
|
|
Records(Prior + 1) = Records(Prior)
|
|
Prior = Prior - 1
|
|
Loop
|
|
Records(Prior + 1) = Value
|
|
Next
|
|
End Sub
|
|
|
|
Function DxRecordsJson(ByRef Records, ByVal Count)
|
|
Dim Result
|
|
Dim Index
|
|
Result = "["
|
|
For Index = 0 To Count - 1
|
|
If Index > 0 Then Result = Result & ","
|
|
Result = Result & CStr(Records(Index))
|
|
Next
|
|
DxRecordsJson = Result & "]"
|
|
End Function
|
|
|
|
Function DxInterfacesJson(ByRef Interfaces)
|
|
Dim Names
|
|
Dim Routes
|
|
Dim Index
|
|
Dim Result
|
|
Names = Array("attributes", "gates", "hierarchy", "logical_identity", _
|
|
"mirror", "nets", "origin_x", "origin_y", "part_number", _
|
|
"parameter_probe", "pins", "position_x", "position_y", "refdes", _
|
|
"rotation", _
|
|
"symbol_identity", "units")
|
|
Routes = Array("component.Attributes", "component.Gates", _
|
|
"component.Hierarchy", "component.LogicalIdentity", _
|
|
"component.Mirrored", "component.Nets", "component.OriginX", _
|
|
"component.OriginY", "component.PartNumber", "component.Attributes", _
|
|
"component.Pins", "component.X", "component.Y", "component.RefDes", _
|
|
"component.Rotation", "component.SymbolName", "component.Units")
|
|
Result = "{"
|
|
For Index = 0 To UBound(Names)
|
|
If Index > 0 Then Result = Result & ","
|
|
Result = Result & DxJsonString(Names(Index)) & _
|
|
":{""available"":" & _
|
|
DxBooleanLiteral(Interfaces(Names(Index))) & _
|
|
",""route"":" & DxJsonString(Routes(Index)) & "}"
|
|
Next
|
|
DxInterfacesJson = Result & "}"
|
|
End Function
|
|
|
|
Function DxJsonString(ByVal Value)
|
|
If IsNull(Value) Then
|
|
DxJsonString = "null"
|
|
Else
|
|
DxJsonString = Chr(34) & DxJsonEscape(CStr(Value)) & Chr(34)
|
|
End If
|
|
End Function
|
|
|
|
Function DxScalarJson(ByVal Value, ByVal Available)
|
|
If Not CBool(Available) Then
|
|
DxScalarJson = "null"
|
|
Else
|
|
DxScalarJson = DxJsonString(Value)
|
|
End If
|
|
End Function
|
|
|
|
Function DxNumberJson(ByVal Value, ByVal Available)
|
|
If Not CBool(Available) Or Not IsNumeric(Value) Then
|
|
DxNumberJson = "null"
|
|
Else
|
|
DxNumberJson = DxInvariantNumber(Value)
|
|
End If
|
|
End Function
|
|
|
|
Function DxBooleanJson(ByVal Value, ByVal Available)
|
|
If Not CBool(Available) Then
|
|
DxBooleanJson = "null"
|
|
Else
|
|
DxBooleanJson = DxBooleanLiteral(CBool(Value))
|
|
End If
|
|
End Function
|
|
|
|
Function DxBooleanLiteral(ByVal Value)
|
|
If CBool(Value) Then
|
|
DxBooleanLiteral = "true"
|
|
Else
|
|
DxBooleanLiteral = "false"
|
|
End If
|
|
End Function
|