Download

Online

Gallery

Blog

  Index  | Recent Threads  | List Attachments  | Search
 Welcome Guest  |  Register  |  Login
Login Name  Password
 

Sweet Home 3D Forum



No member browsing this thread
Thread Status: Active
Total posts in this thread: 5
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 3043 times and has 4 replies Next Thread
Alex42
Newbie




Joined: Dec 22, 2011
Post Count: 7
Status: Offline
Reply to this Post  Reply with Quote 
The concept of custom properties

Hello,
I want to use SH3D to design the visualization of my home automation system. My idea was to write a plugin to be able to add some additional properties (e.g. address of lamp in automation, visual parameters, ...) to Level, Room and some PieceOfFurnitures to be able to generate the definition of my visualization.
Unfortunately I've noticed that attaching custom properties to SH3D objects is not as easy as I thought. sad

As I found other similar requests this wish seems to be common. After some walks through the code I can thought of two approaches to implement this:

1) add a Map<String, Serializable> to the classes of the model
this would be the easiest way because storing Home would also store the custom properties. On the other hand could this lead to issues if the value is of a type provided by a plugin and the plugin is not installed at the time of opening a drawing (maybe got from another person). Maybe allowing only some predefined types (String, Integer, ..., Map, List) could solve this issue.

2) store/handle custom properties "beside" the objects
if every object of the model would have a unique id (e.g. java.util.UUID) and Home would provide methods to get objects by this id the custom properties could be handled without touching the code of the model classes. An extension of HomeFileRecorder could read/write these properties to a separate file inside the SH3D zip.
Some CollectionListeners (Room, HomePieceOfFurniture, ...) could keep these properties and the model in sync.

As I'm quite new to SH3D I'm interested in your opinion. Am I wrong and missed something? confused
I think to add the concept of custom properties to SH3D could offer a lot of other possibilities, too.

Regards,
Alex
[Dec 22, 2011, 7:11:01 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9178
Status: Offline
Reply to this Post  Reply with Quote 
Re: The concept of custom properties

The only entry points in the model API you can use to store any Serializable data are the setVisualProperty / getVisualProperty methods in the Home class. It's far from perfect, but you can associate to the string key of your choice a map that will store for each object of the model the list of additional information you need.
Hope you understand what I mean... smile
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D developer
[Dec 22, 2011, 11:52:06 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Alex42
Newbie




Joined: Dec 22, 2011
Post Count: 7
Status: Offline
Reply to this Post  Reply with Quote 
Re: The concept of custom properties

Hi Emmanuel,
Ok, that' what I meant with "Have I missed something?" wink
setVisualProperty / getVisualProperty provides some mix of my approaches 1 and 2. I can use it to connect a container of additional data (approach 2) to the model and have no need for extending HomeFileRecorder to store them by myselfe but I would get the backdraw of approach 1 regarding deserialization on other machines as mentioned.

Regards,
Alex
[Dec 23, 2011, 6:11:35 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9178
Status: Offline
Reply to this Post  Reply with Quote 
Re: The concept of custom properties

Hello Alex,

Please store only instances of Java 1.5 standard Serializable classes or classes coming from Sweet Home 3D model package. Prefer a key with a name starting by your package name to help recognize its origin among others, and for unicity sake (Sweet Home 3D ones starts by "com.eteks.sweethome3d").

Will you release your plug-in once done, or is it just for personal use or study?
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D developer
[Dec 23, 2011, 7:28:23 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Alex42
Newbie




Joined: Dec 22, 2011
Post Count: 7
Status: Offline
Reply to this Post  Reply with Quote 
Re: The concept of custom properties

Hello Emmanuel,

thank you for your answer. Currently I still don't know if I'll go with approach 2 or with the combination as you proposed.
Maybe I'll try to do a minimal invasive but very universal implementation of approach 2.
Regardless of the result, I'll share it with you though you can decide if you want to add it to SH3D.

I think I'll release the plugin as open source but it will be very specific to the visualization system I'm using. But maybe it could be useful as an example for the general concept of custom properties.

Regards,
Alex
[Dec 23, 2011, 8:37:06 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread

    Get Sweet Home 3D at SourceForge.net. Fast, secure and Free Open Source software downloads
   
© Copyright 2006-2024 eTeks - All rights reserved