How to save list of placements in FCStd file?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

How to save list of placements in FCStd file?

Post by DeepSOIC »

Hi!
I need to implement a lattice object (in Python), which is basically just a list of FreeCAD.Placement's. I would like to store this list in a file. How do I do that?
I have a few options to consider:
1. Somehow make json work, I have no idea how.
2. Write the placements into a string buffer, that is to be saved as a PropertyString of the object.
3. Construct a special OCC shape, from which the array of placements can be restored (a compound of points, each point can have full Placement)
The main thing to consider is that placement list can be huge (million items, for example).
This means I need it to be pretty fast. I'm not sure if compounds are fast enough for the purpose.
On the other hand, I probably don't want Document.xml to insane size storing these million placements there.

So I ask for:
1) how to save stuff that cannot be placed as properties?
2) opinions on which of the options is the best

Thanks for reading this far ;)
Last edited by DeepSOIC on Tue Oct 20, 2015 10:42 am, edited 1 time in total.
Reason: changed the title to look like a question
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to save list of placements in FCStd file?

Post by wmayer »

The correct way is to implement a class PropertyPlacementList which inherits from PropertyLists. To see how to implement the various methods have a look to any other class that inherits from PropertyLists such as PropertyFloatList.

The most important thing is that in the Save() method you register a file name which you will fill in SaveDocFile()
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: How to save list of placements in FCStd file?

Post by DeepSOIC »

wmayer wrote:The correct way is to implement a class PropertyPlacementList which inherits from PropertyLists.
You mean, in C++? If yes, that's not an option now.
I think I will go for storage in shapes, as it is interesting in that I can potentially put the shape through an unsuspecting tool (Part Common, for example) and get a useful result. Hopefully, it isn't going to be too slow.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: How to save list of placements in FCStd file?

Post by DeepSOIC »

DeepSOIC wrote:I think I will go for storage in shapes, as it is interesting in that I can potentially put the shape through an unsuspecting tool (Part Common, for example) and get a useful result. Hopefully, it isn't going to be too slow.
I tried storing it as a compound of points, with points' placements set to what I want. It all works fine until I save and reload the file. Then, the placements are lost (reset to zero). I'll try something other than just points, but I suspect I got into a dead end (with two cool tools based on this way of storage). :|
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: How to save list of placements in FCStd file?

Post by microelly2 »

You can store information into a StringList Property and parse and apply it after loading the file with a execute method of your object.

these are my first experiments (all in pure python)
https://www.youtube.com/watch?v=VK8LF1ApNuA
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: How to save list of placements in FCStd file?

Post by DeepSOIC »

First test with more complex shape than just a point seems to go well. But anyway, I need to rethink the concept a little bit. The idea with points was very good...
User avatar
sliptonic
Veteran
Posts: 3460
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: How to save list of placements in FCStd file?

Post by sliptonic »

wmayer wrote: Tue Oct 20, 2015 12:14 pm The correct way is to implement a class PropertyPlacementList which inherits from PropertyLists. To see how to implement the various methods have a look to any other class that inherits from PropertyLists such as PropertyFloatList.

The most important thing is that in the Save() method you register a file name which you will fill in SaveDocFile()
Sorry to necro-bump the topic but has this ever been implemented? I need exactly the same thing.
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to save list of placements in FCStd file?

Post by wmayer »

There is a type called PropertyPlacementList: https://github.com/FreeCAD/FreeCAD/blob ... Geo.h#L381
Post Reply