Improved object library with preview

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
carlopav
Posts: 1726
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Improved object library with preview

Postby carlopav » Sat Jun 05, 2021 8:37 am

ABeton wrote: Fri Jun 04, 2021 11:35 am I did all that I think, you can check if it is in the repository.
Good! I did find everything. Now, before creating a Pull Request from your github web page, you probably want to reorder a bit your commits: they will be included in the main BIM Workbench tree, so we want them to be more tidy, while at the moment you have:

Code: Select all

25ed5ba (HEAD -> bim_super_library, ABeton/bim_super_library) Naming fix (# this is a fix commit, not useful to have it in the BIM WB commit history)
d9ea66b Added save before link and link links root objects now (# this is a fix commit, not useful to have it in the BIM WB commit history)
2416c1a Bad naming fix (# this is a fix commit, not useful to have it in the BIM WB commit history)
2ac2f6b Library with preview and link. (# two different changes are contained in this commit: preview and link, better to split them)
db0017f (origin/master, origin/HEAD, ABeton/master, master) Created horizontal and vertical dimension tools (here starts the BIM Workbench tree)
82b287b Added Leader command
db39545 Updated translations
ce49e84 Updated translation scripts
You could reset the commits so you have just one or two meaningful commits:
- a commit for library preview
- a commit for the link option

if you want to try that you could check this link: https://github.com/FreeCAD/FreeCAD/pull ... -846960544
matthijskooijman wrote:Basic approach
Given that most of these changes are pretty independent, the basic workflow I would choose here is to:

Reset you branch back to the original master commit you started working from. The default "mixed" flavor of the git reset command resets your branch and the index/staging area but not the working copy, so this would put you in a position where you would have been if you had done all the coding in your checkout, but not committed any of it yet. On the commandline, this would be git reset origin/master (assuming that you origin/master still points to the commit you branched off from, if not you might need to rebase first, or replace origin/master with the SHA of the branch-off point).
Now, you can use interactive staging to select a subset of all your changes and create a new commit for that. You can do this for each commit to be created in turn. On the commandline, you would use git add -p for this, but I suspect that in kraken you can do a similar thing in e.g. a diff view where you select lines of the diff to be staged. On the commandline you can even edit the to-be-staged diff in a text editor (useful in case you need to commit one change in a line but not another, or in adjacent lines), but if Kraken doesn't support this, and you'd need it, you can always just revert one of the changes in the file manually, commit that, ^Z in your editor and commit the other change.

Note that especially the git add -p / interactive staging is IMHO a very powerful tool, which allows me to have a much improved workflow where I can (in a lot of cases) just focus on coding and making things work first, and then still be able to split the changes in proper commits at a later stage (sometimes at the end, somethings I already commit things halfway when I'm confident that a particular change is somewhat complete and will be included in the final history).
but at the moment probably you could open a PR (Pull Request) to gather yorik suggestions too...

I made changes to this, what it does now is that when you press link it first asks you to save the file("Save as") I think it is best to save the file in a folder where you are doing the project and not the library, because it would bloat the library really fast. When you save in this way, it remembers in which folder you saved last time and when you try to link consecutive times, it opens the same folder every time. If you use the "Save" option than it again saves to the library folder.
That's good to me :)
Also the "Link" command selects all the root files of a document and links them. The result is similar to "Insert" command, but the problem is that some objects can't be linked(like Groups for example).
Are you sure Groups can't be linked?
This brings me to the next point. We should establish rules that would define how should users add their objects to the library. So for example the final object can only be a Part object, or some Arch object in case of architecture objects. These is just of the top of my head, but when we agree on all the rules, we should put them in the wiki perhaps, and when someone wants to add objects to the library, they should follow those rules.
I probably agree, but take into account that this won't be easy, and since FreeCAD is "pure anarchy" I the task will be quite challenging. Expecially because also FreeCAD changes in time, so maybe a deep restructuring that fits FreeCAD 0.20 would not fit FreeCAD 0.37... In my opinion better to have a flexible way to handle different document structures... since I do not think a standardization of the library could be in the mood of Yorik, but i'd like to hear what does he thinks :)
This is also important because of the image preview that you mentioned before. The image preview works(in the Library object macro, which is another macro), but only if the users saved the thumbnail image while they were saving the file. To activate this option it is necessary to go to Edit/Preferences/General/Document and tick the "Save thumnail into project file when saving document". Also I would set the image size to 256 or even 512 so we have a good quality thumnail.
This would be useful indeed, maybe with the help of a script this can be automated for all library documents without having to do it by hand?
I study Industrial design in Bari, but I finished architecture before. If your location is correct I think we are on different ends of the country :lol:
Oh, I see, yes, indeed we are quite far away!


Edit: By the way, I was trying to open the 20ft-container from Logistics/Shipping Containers/20ftISOContainer... and it completely stuck FC... can you have a look? is it too heavy?
Aaand... where do I find the options to turn off the preview?
follow my experiments on BIM modelling for architecture design
ABeton
Posts: 146
Joined: Tue Sep 03, 2019 6:39 pm

Re: Improved object library with preview

Postby ABeton » Thu Jun 10, 2021 10:12 pm

Sorry for the late reply I went on a short vacation(right before exams start, not sure if that was smart :? )
carlopav wrote: Sat Jun 05, 2021 8:37 am You could reset the commits so you have just one or two meaningful commits:
- a commit for library preview
- a commit for the link option

if you want to try that you could check this link: https://github.com/FreeCAD/FreeCAD/pull ... -846960544
I will check out how to do this.
Are you sure Groups can't be linked?
I checked, and groups can be linked but there is an error which appears when they are linked to another document. Maybe it has something to do with how Link works.

This is the error I get:

Code: Select all

<Exception> PropertyLinkList does not support external object
I probably agree, but take into account that this won't be easy, and since FreeCAD is "pure anarchy" I the task will be quite challenging. Expecially because also FreeCAD changes in time, so maybe a deep restructuring that fits FreeCAD 0.20 would not fit FreeCAD 0.37... In my opinion better to have a flexible way to handle different document structures... since I do not think a standardization of the library could be in the mood of Yorik, but i'd like to hear what does he thinks :)
You are probably right about this, but I have a counter argument to make. When we code something and want to commit, we also need to follow some rules :lol: Joke aside, perhaps we could just have a rule that peple save their files with thumbnails 512x512 resolution, so that the preview can work nicely.
This is also important because of the image preview that you mentioned before. The image preview works(in the Library object macro, which is another macro), but only if the users saved the thumbnail image while they were saving the file. To activate this option it is necessary to go to Edit/Preferences/General/Document and tick the "Save thumnail into project file when saving document". Also I would set the image size to 256 or even 512 so we have a good quality thumnail.
This would be useful indeed, maybe with the help of a script this can be automated for all library documents without having to do it by hand?
I think I solved this problem now.
Edit: By the way, I was trying to open the 20ft-container from Logistics/Shipping Containers/20ftISOContainer... and it completely stuck FC... can you have a look? is it too heavy?
Aaand... where do I find the options to turn off the preview?
I gave it a look, it is either too heavy or the file has some kind of problem. It opened for me after 5 minutes. This can be a problem with the 3D preview I guess. But it would also be a problem if we tried importing the file anyway.

And for the second question I didn't have turn off/on option implemented at the time, forgot to mention it :oops:

Improvements

Anyway, I made some good progress with this, and a lot of problems and bugs have been solved. Try out the changes if you have time.

2D preview

I added the 2D preview now, if there is a thumbnail image in the FreeCAD file it will be shown now. Also it is possible to check an option now, which generates a thumbnail image when a file is clicked. It pretty much just saves a file before opening it, and in this way generates the image. It is necessary to have the 3D preview on, and enable "Save thumnail into project file when saving document".

3D preview

Now there is also an option to togle 3D preview.

Other things I did was mostly fixing some bugs that happened when saving a document.

Things that I have left to do. Fix the commit problem, find more bugs and fix them, perhaps improve some usability aspects, and add comments to code.

Pasted Layer #1.png
Pasted Layer #1.png (223.08 KiB) Viewed 285 times
Pasted Layer.png
Pasted Layer.png (221.89 KiB) Viewed 285 times
Pasted Layer #2.png
Pasted Layer #2.png (271.06 KiB) Viewed 285 times
paullee
Posts: 3502
Joined: Wed May 04, 2016 3:58 pm

Re: Improved object library with preview

Postby paullee » Thu Jun 10, 2021 10:36 pm

Looks good :)
carlopav
Posts: 1726
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Improved object library with preview

Postby carlopav » Fri Jun 11, 2021 3:21 pm

Very nice, I tried it and it works very good.
good if you add comments into the code.
well done!
follow my experiments on BIM modelling for architecture design
ABeton
Posts: 146
Joined: Tue Sep 03, 2019 6:39 pm

Re: Improved object library with preview

Postby ABeton » Fri Jun 11, 2021 9:04 pm

Thank you guys :D
ABeton
Posts: 146
Joined: Tue Sep 03, 2019 6:39 pm

Re: Improved object library with preview

Postby ABeton » Sun Jun 13, 2021 10:06 pm

Hello,
carlopav wrote: ping
I added some comments to the code and I reorganized the commits. I restarted the branch, then staged the code in separate parts and used force push to do it, so I hope that was the propper procedure.If you have time could you check if I did it propperly? :)
carlopav
Posts: 1726
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Improved object library with preview

Postby carlopav » Sun Jun 13, 2021 10:30 pm

Good! Open a pull request and link It here in the forum topic! By doing so you have more chances to get yorik review
follow my experiments on BIM modelling for architecture design
ABeton
Posts: 146
Joined: Tue Sep 03, 2019 6:39 pm

Re: Improved object library with preview

Postby ABeton » Sun Jun 13, 2021 10:44 pm

I did it, but not sure if I made some mistake.

https://github.com/yorikvanhavre/BIM_Workbench/pull/77