Guard view providers against a None ViewObject (headless support) - #2
Open
masonhensley wants to merge 1 commit into
Open
masonhensley wants to merge 1 commit into
masonhensley wants to merge 1 commit into
Conversation
Gear creation raises AttributeError under freecadcmd, where FreeCAD is
built without the Gui module and obj.ViewObject is None:
AttributeError: 'NoneType' object has no attribute 'Proxy'
The geometry code itself is headless-clean; only the unconditional view
provider attachment fails. Twelve call sites pass .ViewObject straight
into a view provider (planetary, worm, globoid x3, geneva, hypoid,
screw, non-circular, unified, gear stack), and they funnel through five
constructors, so the guard goes there rather than at each call site.
planetaryGearCreator already has a GUI_AVAILABLE flag and correctly
guards its dialog class with it; this extends the same idea to the
view providers.
No GUI behaviour change: a non-None view object takes the original
path untouched.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Any gear creation fails under
freecadcmd, which makes the workbench unusable from scripts and CI:Headless FreeCAD is built without the Gui module, so
obj.ViewObjectisNone. It works in the GUI, which is why this isn't visible in normal use.Root cause
The geometry code is already headless-clean — validators, profile math, and the PartDesign build all run fine. Only the unconditional view provider attachment fails.
Twelve call sites pass
.ViewObjectstraight into a view provider:planetaryGearCreator,wormGear,globoidWormGear,globoidWormGearV2,globoidWormGearV4,genevaWheel,hypoidGear,screwGear,nonCircularGear,unifiedGear,gearStackThey funnel through five constructors, so guarding those fixes all twelve at once rather than patching each call site:
genericGear.ViewProviderGearResult(9 of the 12)genericGear.ViewProviderGenericGeargearStack.ViewProviderGearStackunifiedGear.UnifiedSpurGearViewProvidercycloidGearCreator.ViewProviderCycloidGearBoxResultplanetaryGearCreatoralready has aGUI_AVAILABLEflag and correctly guards its dialog class with it — this extends the same idea to the view providers.Fix
Early return when the view object is
None. 20 lines, 4 files, no GUI behaviour change: a non-Noneview object takes the original path untouched.Verification
Against this branch under
freecadcmd(FreeCAD 1.1.3, macOS arm64), with no other patches or shims:Builds a complete 9:1 system — sun 480.95 mm³, three planets 6562.69 mm³ each, ring 8247.02 mm³, every shape
isValid(), tooth counts correct in the polar patterns (12 / 42). Volumes sit just below the analytic solid-disc figures, as expected once tooth spaces, bore, and keyway are removed. Onmainthe same script raises before building anything.Also re-ran a 4:1 config (15/15/45, m=1.0) as a regression check, and confirmed the GUI path is unaffected.
🤖 Generated with Claude Code