Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

correct file search order to give unofficial files precedence over official ones AND: correct usage of p/8 primitives folder #52

Closed
MinnieTheMoocher opened this issue Jan 6, 2014 · 13 comments
Assignees
Milestone

Comments

@MinnieTheMoocher
Copy link

Currently, import_ldraw.py reads:

paths = []
paths.append(file_directory)
paths.append(os.path.join(LDrawDir, "models"))
paths.append(os.path.join(LDrawDir, "parts"))
if HighRes:
    paths.append(os.path.join(LDrawDir, "p", "48"))
paths.append(os.path.join(LDrawDir, "p"))
paths.append(os.path.join(LDrawDir, "unofficial", "parts"))
if HighRes:
    paths.append(os.path.join(LDrawDir, "unofficial", "p", "48"))
else:
    paths.append(os.path.join(LDrawDir, "p", "8"))
paths.append(os.path.join(LDrawDir, "unofficial", "p"))

This gives official files precedence over unofficial ones.
This is not what you usually want.
Your usual usecase is that you download corrected or updated parts
from the LDRAW parts tracker to that "unofficial files" folder
and want them to take precedence over the official ones.

Thus, the above lines need to be reordered to:

paths = []
paths.append(file_directory)
paths.append(os.path.join(LDrawDir, "models"))
paths.append(os.path.join(LDrawDir, "unofficial", "parts"))
if HighRes:
    paths.append(os.path.join(LDrawDir, "unofficial", "p", "48"))
else:
    paths.append(os.path.join(LDrawDir, "p", "8"))
paths.append(os.path.join(LDrawDir, "unofficial", "p"))
paths.append(os.path.join(LDrawDir, "parts"))
if HighRes:
    paths.append(os.path.join(LDrawDir, "p", "48"))
paths.append(os.path.join(LDrawDir, "p"))

Additionally, the implementation of the p/8 folder is wrong:
(a) it must be searched both in official and unofficial files and
(b) it needs its own "LowRes" flag instead of depending on HighRes

Applying this correction, the above lines become:

paths = []
paths.append(file_directory)
paths.append(os.path.join(LDrawDir, "models"))
paths.append(os.path.join(LDrawDir, "unofficial", "parts"))
if HighRes:
    paths.append(os.path.join(LDrawDir, "unofficial", "p", "48"))
if LowRes:
    paths.append(os.path.join(LDrawDir, "unofficial", "p", "8"))
paths.append(os.path.join(LDrawDir, "unofficial", "p"))
paths.append(os.path.join(LDrawDir, "parts"))
if HighRes:
    paths.append(os.path.join(LDrawDir, "p", "48"))
if LowRes:
    paths.append(os.path.join(LDrawDir, "p", "8"))
paths.append(os.path.join(LDrawDir, "p"))

Note that in addition to the existing HighRes flag, a new flag LowRes flag needs to be introduced.

@ghost ghost assigned le717 Jan 6, 2014
le717 added a commit that referenced this issue Jan 6, 2014
gh-40 - "(b) speed: the paths[] array construction should be moved out
of the locate function. it is expensive and only needs to be done once."
@le717
Copy link
Owner

le717 commented Jan 6, 2014

Fixed in f0037a7. I should have already done this, but I'll add you to the list of authors. Do you want to go by Steffen or MinnieTheMoocher? 😉

@le717 le717 closed this as completed Jan 6, 2014
@MinnieTheMoocher
Copy link
Author

the latter, please. it's my github identity.

@MinnieTheMoocher
Copy link
Author

your f0037a7 corrects the unofficial/official files search order, but the error with the p/8 folder is still in it.

it needs to be treated like this

paths = []
paths.append(file_directory)
paths.append(os.path.join(LDrawDir, "models"))
paths.append(os.path.join(LDrawDir, "unofficial", "parts"))
if HighRes:
paths.append(os.path.join(LDrawDir, "unofficial", "p", "48"))
elif LowRes:
paths.append(os.path.join(LDrawDir, "unofficial", "p", "8"))
paths.append(os.path.join(LDrawDir, "unofficial", "p"))
paths.append(os.path.join(LDrawDir, "parts"))
if HighRes:
paths.append(os.path.join(LDrawDir, "p", "48"))
elif LowRes:
paths.append(os.path.join(LDrawDir, "p", "8"))
paths.append(os.path.join(LDrawDir, "p"))

I.e.,
"When the HighRes flag is set to true, let the p/48 folder take precedence.
ELSE
When the LowRes flag is set to true, let the p/8 folder take precedence.
ELSE
Fallback to the p/ folder
"

@le717 le717 reopened this Jan 6, 2014
@le717
Copy link
Owner

le717 commented Jan 6, 2014

There is no LowRes variable (unless you are referring to #44), so it would actually be elif not HighRes.

Is this the proper formatting? Python uses indentation levels for if/elif/else. In this, parts/ and p/ are always searched no matter the value of HighRes. Do I need to move those under elif not HighRes as well? There really is no else in this section.

paths = []
paths.append(file_directory)
paths.append(os.path.join(LDrawDir, "models"))
paths.append(os.path.join(LDrawDir, "unofficial", "parts"))
if HighRes:
    paths.append(os.path.join(LDrawDir, "unofficial", "p", "48"))
elif not HighRes:
    paths.append(os.path.join(LDrawDir, "unofficial", "p", "8"))
    paths.append(os.path.join(LDrawDir, "unofficial", "p"))
paths.append(os.path.join(LDrawDir, "parts"))
if HighRes:
    paths.append(os.path.join(LDrawDir, "p", "48"))
elif not HighRes:
    paths.append(os.path.join(LDrawDir, "p", "8"))
paths.append(os.path.join(LDrawDir, "p"))

@MinnieTheMoocher
Copy link
Author

no, "elif not HighRes" would be equal to "else" which is wrong here!:

the p/8 folder must ONLY be used if the user explicitly requests so.

the current implementation is wrong, because it always uses that folder if HighRes is NOT enabled,
which is wrong.

the fix is very simple!
just introduce a flag "LogRes" completely analogous to "HighRes", i.e., change

highResPrims = BoolProperty(
    name="Use High-Res Primitives",
    description="Replace all Primitives by Hi-Res (48ed) Primitives",
    default=False
)

to

highResPrims = BoolProperty(
    name="Use High-Res Primitives",
    description="Replace all Primitives by Hi-Res (48ed) Primitives",
    default=False
)

lowResPrims = BoolProperty(
    name="Use Low-Res Primitives",
    description="Replace all Primitives by Lo-Res (8ed) Primitives",
    default=False
)

and

    box.prop(self, "highResPrims", icon="MOD_BUILD")

to

    box.prop(self, "highResPrims", icon="MOD_BUILD")
    box.prop(self, "lowResPrims", icon="MOD_BUILD")

and

    global LDrawDir, CleanUp, GameFix, HighRes, CleanUpOpt
    LDrawDir = str(self.ldrawPath)
    HighRes = bool(self.highResPrims)

to

    global LDrawDir, CleanUp, GameFix, HighRes, LowRes, CleanUpOpt
    LDrawDir = str(self.ldrawPath)
    HighRes = bool(self.highResPrims)
    LowRes = bool(self.lowResPrims)

and

    if HighRes:
        debugPrint("High resolution bricks option selected")

to

    if HighRes:
        debugPrint("High resolution bricks option selected")
    if LowRes:
        debugPrint("Low resolution bricks option selected")

@MinnieTheMoocher
Copy link
Author

in a future refacturing, you can merge these 2 boolean flags to a simple multiple choice:

  • do no primtives replacement (default)
  • always use High-Res primitives (this currently is the flag "HighRes")
  • always use Low-Res primitives (this currently is the flag "LowRes")

@MinnieTheMoocher
Copy link
Author

to make is simple, here is the corrected file (untested):
https://gist.github.com/MinnieTheMoocher/d337bb86864befd094b8

@le717
Copy link
Owner

le717 commented Jan 6, 2014

Yikes the formatting. You might want to paste that in a Gist and edit your comment with the link.

@MinnieTheMoocher
Copy link
Author

here it is :)

@le717 le717 mentioned this issue Jan 7, 2014
10 tasks
le717 added a commit that referenced this issue Jan 7, 2014
@le717
Copy link
Owner

le717 commented Jan 7, 2014

I tested the patch and it works. However, I did edit it to make the options exclusive so both are not used (and clean up the options a bit) and to work better with your last patch. The layout looks like this now.

image1
image2
image3

You can review the changes (and the descriptions) on the highres-or-lowres branch.

@rioforce
Copy link
Collaborator

rioforce commented Jan 8, 2014

What about "normal-res" primitives? All you have is low and high.

@le717
Copy link
Owner

le717 commented Jan 15, 2014

I didn't show that option in the screenshots. ;)

le717 added a commit that referenced this issue Jan 15, 2014
Add patch from #52, rework options display
@le717
Copy link
Owner

le717 commented Jan 15, 2014

Fixed by #54, issue solved!

@le717 le717 closed this as completed Jan 15, 2014
le717 added a commit that referenced this issue Jan 17, 2014
fix bug with high-/low-res primitives not being imported properly
(builds on #50, #52, #54, use value of `isPart` directly, removed
once-used `file_directory` variable, small cleanup, update Change log
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants