haplokuon / netDxf

.net dxf Reader-Writer
MIT License
1.01k stars 411 forks source link

order paper space before renaming #167

Closed EMostafaAli closed 4 years ago

EMostafaAli commented 4 years ago

Resolves the issue #160

It happens when layouts are ordered: "paper_space0" then "paper_space", and reorder function tries to rename the first entry "*paper_space"

haplokuon commented 4 years ago

Thank you for your input; but don't worry about it, I already have a solution for this problem that you should see in the latest commit. I didn't do it earlier thinking for a cleaner solution.

A different solution, from what I did at the moment, is to take a different approach for the naming and create a global counter for the layouts, something like the dimension blocks or the unnamed groups. The things to keep in mind are, if the layout associated with the block "Paper_Space" is removed one of the existing blocks must be renamed to be the "Paper_Space" since it must always exists in the DXF; and, also, take care of the last index used when loading a DXF taken care of that the last element might not have the highest index.

On the other hand, the renaming method requires an additional iteration, besides the calling of the sort method to an integer list, that should be faster than comparing strings. Anyways, it is need only once when loading a DXF and when removing layouts something that it not done very often, and the total number of layouts should not be that many, personally I have never used them. So good enough for now.

The issue with your proposal is that it sorts the items by the name of the layout's associated block, and when sorting strings the *Paper_Space10" will take precedence over "Paper_Space2", and that will cause problems. As far as I know, there is no built in compare method in the .Net Framework that orders strings as, for example, the way Windows does now when ordering files by name, that places "2" before "10"; I think remember that Windows XP and earlier didn't do that. I would like to see a generic implementation, for an unspecified combination of letters and numbers, that could be added to the CompareTo method of the TableObject. The solution I have been thinking of is too cumbersome.