added windows interaction test

adding more variant stuff
This commit is contained in:
brentperteet
2026-02-22 13:31:14 -06:00
parent 3f0aff923d
commit ab8d5c0c14
6 changed files with 461 additions and 43 deletions

View File

@@ -116,6 +116,7 @@ def sync_variant_from_schematic(schematic_file: str, target_variant: str = None)
all_dnp_uuids = []
all_uuids = []
all_part_properties = {} # uuid -> {property_name: value}
# Process each schematic file
for sch_file in all_schematics:
@@ -130,17 +131,21 @@ def sync_variant_from_schematic(schematic_file: str, target_variant: str = None)
with open(sch_path, 'r', encoding='utf-8') as f:
content = f.read()
# Parse schematic to find DNP components
# Parse schematic to find DNP components and read properties
# Track properties: Value, MPN, Manufacturer, IPN
lines = content.split('\n')
in_symbol = False
current_uuid = None
current_ref = None
current_lib_id = None
current_properties = {} # Collect properties for this symbol
has_dnp = False
# Track line depth to know when we're at symbol level
symbol_start_indent = None
for i, line in enumerate(lines):
stripped = line.strip()
indent_level = len(line) - len(line.lstrip())
# Detect start of symbol
if stripped.startswith('(symbol'):
@@ -148,20 +153,30 @@ def sync_variant_from_schematic(schematic_file: str, target_variant: str = None)
current_uuid = None
current_ref = None
current_lib_id = None
current_properties = {}
has_dnp = False
symbol_uuid_found = False # Track if we found the main symbol UUID
symbol_start_indent = indent_level
# Detect end of symbol
elif in_symbol and stripped == ')':
# Check if this symbol block is closing (simple heuristic)
# Detect end of symbol - closing paren at same indent as symbol start
elif in_symbol and stripped == ')' and indent_level == symbol_start_indent:
# Skip power symbols
is_power = current_lib_id and 'power:' in current_lib_id
is_power = is_power or (current_ref and current_ref.startswith('#'))
if current_uuid and has_dnp and not is_power:
if current_uuid not in all_dnp_uuids:
all_dnp_uuids.append(current_uuid)
print(f" Found DNP: {current_ref if current_ref else current_uuid}")
if current_uuid and not is_power:
# Store properties for this part
if current_properties:
if current_uuid not in all_part_properties:
all_part_properties[current_uuid] = {}
all_part_properties[current_uuid].update(current_properties)
all_part_properties[current_uuid]['reference'] = current_ref # For display
# Track DNP
if has_dnp:
if current_uuid not in all_dnp_uuids:
all_dnp_uuids.append(current_uuid)
print(f" Found DNP: {current_ref if current_ref else current_uuid}")
in_symbol = False
# Extract lib_id to check for power symbols
@@ -170,22 +185,23 @@ def sync_variant_from_schematic(schematic_file: str, target_variant: str = None)
if len(lib_parts) >= 2:
current_lib_id = lib_parts[1]
# Check for DNP flag - can be (dnp), (dnp yes), or (dnp no)
# Do this before UUID extraction so we know if we need the UUID
elif in_symbol and '(dnp' in stripped and not has_dnp:
# Only set has_dnp if it's (dnp) or (dnp yes), not (dnp no)
# Check for DNP flag and extract UUID
# DNP line comes before UUID, so we look forward for the UUID
elif in_symbol and '(dnp' in stripped and not symbol_uuid_found:
# Check if DNP is set
if '(dnp yes)' in stripped or (stripped == '(dnp)'):
has_dnp = True
# Now look forward for the UUID (it comes right after DNP)
for j in range(i + 1, min(len(lines), i + 5)):
if '(uuid' in lines[j]:
# Check it's at symbol level
if '\t(uuid' in lines[j] or ' (uuid' in lines[j]:
uuid_parts = lines[j].split('"')
if len(uuid_parts) >= 2:
current_uuid = uuid_parts[1]
symbol_uuid_found = True
break
# Look forward for the UUID (it comes right after DNP)
for j in range(i + 1, min(len(lines), i + 5)):
if '(uuid' in lines[j]:
# Check it's at symbol level
if '\t(uuid' in lines[j] or ' (uuid' in lines[j]:
uuid_parts = lines[j].split('"')
if len(uuid_parts) >= 2:
current_uuid = uuid_parts[1]
symbol_uuid_found = True
break
# Extract reference designator (for logging)
elif in_symbol and '(property "Reference"' in line and not current_ref:
@@ -194,6 +210,15 @@ def sync_variant_from_schematic(schematic_file: str, target_variant: str = None)
if len(parts) >= 4:
current_ref = parts[3]
# Extract tracked properties
elif in_symbol:
for prop_name in ['Value', 'MPN', 'Manufacturer', 'IPN']:
if f'(property "{prop_name}"' in line:
parts = line.split('"')
if len(parts) >= 4:
current_properties[prop_name] = parts[3]
break
# Get all component UUIDs (excluding power symbols)
# Use same approach - look for UUID after DNP line
in_symbol = False
@@ -238,31 +263,57 @@ def sync_variant_from_schematic(schematic_file: str, target_variant: str = None)
import traceback
traceback.print_exc()
# Update variant with DNP list
# Update variant with DNP list and property changes
print(f"\nUpdating variant '{active_variant}'...")
print(f" Found {len(all_uuids)} total UUIDs")
print(f" Found {len(all_dnp_uuids)} DNP UUIDs")
print(f" Found {len(all_part_properties)} parts with tracked properties")
# Build the new DNP list directly instead of calling set_part_dnp multiple times
# This avoids multiple file saves
if active_variant in manager.variants["variants"]:
# Set the DNP list directly
manager.variants["variants"][active_variant]["dnp_parts"] = sorted(all_dnp_uuids)
# Save once at the end
manager._save_variants()
print(f" Updated DNP list with {len(all_dnp_uuids)} parts")
for uuid in all_dnp_uuids:
print(f" DNP UUID: {uuid}")
else:
if active_variant not in manager.variants["variants"]:
print(f" Error: Variant '{active_variant}' not found in variants")
return False
# Update DNP list
manager.variants["variants"][active_variant]["dnp_parts"] = sorted(all_dnp_uuids)
# Update property overrides based on schematic values
property_changes = 0
for uuid, sch_properties in all_part_properties.items():
# Get expected properties (base + variant overrides)
expected_props = manager.get_part_properties(active_variant, uuid)
# Check each tracked property
for prop_name in ['Value', 'MPN', 'Manufacturer', 'IPN']:
sch_value = sch_properties.get(prop_name, '')
expected_value = expected_props.get(prop_name, '')
# If schematic value differs from expected, update the variant
if sch_value and sch_value != expected_value:
# Check if we have a base value for this property
base_value = manager.variants.get("base_values", {}).get(uuid, {}).get(prop_name, '')
if not base_value:
# No base value exists, so set it
manager.set_base_value(uuid, prop_name, sch_value)
print(f" Set base {prop_name} for {sch_properties.get('reference', uuid)}: {sch_value}")
elif sch_value != base_value:
# Base value exists but differs - store as override
if "part_overrides" not in manager.variants["variants"][active_variant]:
manager.variants["variants"][active_variant]["part_overrides"] = {}
if uuid not in manager.variants["variants"][active_variant]["part_overrides"]:
manager.variants["variants"][active_variant]["part_overrides"][uuid] = {}
manager.variants["variants"][active_variant]["part_overrides"][uuid][prop_name] = sch_value
property_changes += 1
print(f" Override {prop_name} for {sch_properties.get('reference', uuid)}: {sch_value} (base: {base_value})")
# Save once at the end
manager._save_variants()
print(f"\nVariant '{active_variant}' updated:")
print(f" Total components: {len(all_uuids)}")
print(f" DNP components: {len(all_dnp_uuids)}")
print(f" Fitted components: {len(all_uuids) - len(all_dnp_uuids)}")
print(f" Property overrides: {property_changes}")
return True