Print at Dec 20, 2025, 1:17:02 PM
Posted by Byron at Apr 16, 2011, 4:50:32 PM
Plugin - Creating Objects with other Properties
Dear SH3D Community,
I am a student and I am supposed to create new Objects for SweetHome3D.These Objects should be extended in terms of their properties. E.g. a field center of mass or other object specific modifiable information should be added.
(Actually the important part is to capture the joint and link configuration using unified robot description format (URDF)).

Therefore I would like to do this by writing an effective Plugin,
but I am not sure whether this is possible.

The tasks which I need are the following:

1) Reading in data from a meta-file e.g. in xml which contains
the information. (This I should be able to do without problems)
The xml will contain all information about:
joint configuration, path of the according dae-files, ...

2)Creating new Catalog-Categories and the Catalog-Object from this file and its information.

3)Being able to drag an drop this new objects to the floor plan and them being displayed in the 3D-View.
(This new object should have new property fields as Center of mass
in its property window then).

How would you advise me to proceed? Is it possible using a plugin
or not, since I might need to extend the class of PieceOfFurniture by
more property-fields.

Regards
Byron

Posted by Byron at Apr 18, 2011, 5:09:19 PM
Re: Plugin - Creating Objects with other Properties
Update:
I have figured how to use my plugin to create new Catalog-Elements.

When I drag and drop a new item on my plan,
how can I control it without changing the SH3D code?
It will be added as HomePieceOfFurniture,
but I want it to be added e.g. as a selfmade class
*** extends HomePieceOfFurniture.

Also I want to modify its properties window.

How can I access the HomeController and its View
from my plugin workspace?

Posted by alied at Apr 18, 2011, 6:33:47 PM
Re: Plugin - Creating Objects with other Properties
how can I control it without changing the SH3D code?
you can add a listener to your Home object[1], then create your custom PieceOfFurniture, delete the original, and add yours (remember either remove your listener before adding your object, or check before if it's your item, or you can get into a infinite loop)

Also I want to modify its properties window.
That will be more complicated:
You can start extending com.eteks.sweethome3d.swing.HomeFurniturePanel[2], then search in com.eteks.sweethome3d.swing.PlanComponent[3] and there should be where to change(as far as I know SH3D, you will have to modify the code) to check the selected items and show your custom dialog. Anyway, Emanuel can provide more details (and if I find something usefull, I'll tell you)

Best of luck
Alied

[1]http://www.sweethome3d.com/javadoc/com/eteks/...model.CollectionListener)
[2]http://www.sweethome3d.com/javadoc/com/eteks/...g/HomeFurniturePanel.html
[3]http://www.sweethome3d.com/javadoc/com/eteks/.../swing/PlanComponent.html

Posted by Puybaret at Apr 18, 2011, 8:01:58 PM
Re: Plugin - Creating Objects with other Properties
A plug-in doesn't let you specify the class of pieces of furniture that should be used, and even if you create a derived version of Sweet Home 3D, it won't be so easy to perform without changing code, because furniture instantiation is done at this moment in HomeController, ImportedFurnitureWizardController and FurnitureCatalogTransferHandler. Sincerely, this is something I'm not proud of, and instantiating furniture objects in only one method that could be overridden (like i did for Wall, Room and DimensionLine classes) has been on my TODO list for a while...

As for controllers and views you don't have access to them in plug-ins too, so you should probably better create a derived version of Sweet Home 3D. Creating such a version without modifying code source is completely possible, since it's the way I do it when I create customized versions of Sweet Home 3D for projects like this one. If you want more details, you know the place where you can ask questions... wink
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by Byron at Apr 20, 2011, 9:33:04 PM
Re: Plugin - Creating Objects with other Properties
Ok thanks for your input,
it is good to know what is possible and what is not.
I have started working on a derived version already,
I would have loved to somehow utilize the plugin feature
in order to not mess up the code of this nice programm.

I'll continue and will update, as soon as I have some nice results.

Posted by alied at Apr 21, 2011, 6:50:16 PM
Re: Plugin - Creating Objects with other Properties
Still, there is something you can do without messing with the code.
in your Plugin constructor, get the Home and add a listener:

getHome().addFurnitureListener(new CollectionListener<HomePieceOfFurniture>(){
void collectionChanged(CollectionEvent<HomePieceOfFurniture> ev){
//check whether it is a ADD action
//get the newly added item (which should de a HomePieceOfFurniture)
//here, either remove your listener (in which case you should not
//use a anonymous listener like here)
//or check whether it is your class or not
//if it is your class, end(remember to add your listener if you
//previously removed it)
//otherwise, create your own object from the newly added HomePieceOfFurniture
//add it to the Home
}
}


Next, create a PluginAction which shows your properties dialog (which you might extend from com.eteks.sweethome3d.swing.HomeFurniturePanel if you are interesred in) iff the selected items(s) are of your class.

I hope this can hep you.

Posted by Puybaret at Apr 21, 2011, 7:06:37 PM
Re: Plugin - Creating Objects with other Properties
alied's tip is good but I just have some doubts about classpath when opening homes with substituted objects, and how undo/redo will work when you substitute an object by an other one. At the minimum you should take care of the index of the added piece.
An other tip is to manage all your additional information with setVisualProperty/getVisualProperty methods available in Home class. It won't be a very clean architecture, but will work out of the box if you store there only standard class instances.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by Byron at Apr 23, 2011, 1:51:45 PM
Re: Plugin - Creating Objects with other Properties
Thanks for these tipps,
I have worked around the topic and have added a new HomeURDFObject class in my plugin.
Unfortunately I had to change some stuff in the code, but I tried to keep it as little as possible.
Also I added a new Panel class for that which I will simply add to
the normal property panel.
I think I will finish this work soon,
if interested I will post the steps which were important.
But the thing is, that I already worked on a extended version of SH3D.
But Ill tell you! ;)

Posted by Puybaret at Apr 23, 2011, 3:14:55 PM
Re: Plugin - Creating Objects with other Properties
Please share your findings with the community. smile
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by sicodelicos2003 at Jul 7, 2011, 12:34:08 AM
Re: Plugin - Creating Objects with other Properties
Please share your findings with the community. smile


Hello. My name is Nicolas, i'm from Argentina. I'm starting with SH3D. I have to design a furniture with some special properties. Can you share your results? This is for my undergraduate thesis (Mobile information systems).

PD: sorry my english, i don't speak the language well.
Thanks from now

Posted by Byron at Jul 8, 2011, 10:24:39 AM
Re: Plugin - Creating Objects with other Properties
Hey Nicolas,
I do not have much time at the moment,
but I think you can simply download it from a svn repository and check it yourself.
I will try to provide you some information.


@ Emanuel:
How can I obtain Width, Depth and Height from a DAE file
maybe using the DAELoader Class?

Regards
Byron

Posted by sicodelicos2003 at Jul 8, 2011, 12:17:22 PM
Re: Plugin - Creating Objects with other Properties
Thanks. I'm checking now!!
Thanks again

Posted by Byron at Jul 8, 2011, 9:22:11 PM
Re: Plugin - Creating Objects with other Properties
Here this is the repository.
https://vmi.lmt.ei.tum.de/svn/vmi-ros-pkg/trunk/sweetgazebo/sweetgazebo

You will see that there is a centre of mass added for example
and some other information.
I wrote the URDFPackage and u will find some important elements
like HomeURDFObject, CatalogURDF...
U should try to make everything somehow without changing the main code,
since you might wanna upgrade.
In this repository this is not possible anymore, since the one who was working on it before didn pay attention to that. So do not do the same mistake.

But you wont be fully able to not change main code. (Maybe u can also use Pluginfunctionality - I do that partially, but it is not contained above)

what are you trying to do?
My purpose is to import new Objects written in URDF Format (some Robot Description FOrmat) and then to export the full home as an urdf.
It almost functions.

Tell me whether u can check out the folder!

Posted by Byron at Jul 8, 2011, 9:22:44 PM
Re: Plugin - Creating Objects with other Properties
oh yeah it is a svn repository.

Posted by sicodelicos2003 at Jul 9, 2011, 6:28:38 PM
Re: Plugin - Creating Objects with other Properties
Thanks my friend. My idea is add relations between pieces and other stuff. For example, my piece of furniture have an RFID (a code) and relations with others RFID's. All this is for an application that will be used in a Mobile information system.
I'm going to read your code with in the next days.
Thank you very much for your help.

Posted by unrazzle at Jul 31, 2011, 9:46:36 AM
Re: Plugin - Creating Objects with other Properties
sicodelicos2003,

did you get anywhere reading Byron's code?

i'm new to java and eclipse and i don't understand what Byron's doing in his code.

Byron's code is hooked up with playerstage.sourceforge.net/gazebo and i don't understand how to run it to see what changes he made to SH3D.

i'm trying to add new properties to furniture objects (for example, 'door style', 'door hardware', etc.).

i appreciate any help you can give.

thanks

Posted by unrazzle at Jul 31, 2011, 9:54:57 AM
Re: Plugin - Creating Objects with other Properties
Byron,

can you give me a little better idea of what you're doing here?

i'm new to java and eclipse and i don't understand what you're doing in your code.

i can't even find any SH3D code on your svn site that i can read.

i'm trying to add new properties to furniture objects (for example, 'door style', 'door hardware', etc.).

thanks for your help.

Posted by sicodelicos2003 at Jul 31, 2011, 2:36:08 PM
Re: Plugin - Creating Objects with other Properties
Hello my friend. First, sorry my english.. Second, on Byron's code, he appends some attributes to CatalogPieceOfFurniture and HomePieceOfFurniture (some attributes about mass). And he extends HomeDoorOrWindow and other in GazeeboDoorOrWindow and HomeGazeeboDoorOrWindow, appending particular information. He modify the FileUserPreferences class.
I'm reading the swing code now. When i finish whit that i'll write here the results.

Posted by Byron at Aug 1, 2011, 10:11:04 AM
Re: Plugin - Creating Objects with other Properties
Hey unrazzle,
please specify which part of the code you do not
understand.

The Gazebo part was not my doing, but in general this does not have anything to do with SH3D, but with the robot operating system we are trying to export the home to.
This is what is meant by URDF-Export.

The import and export of URDF files is what I am working on,
but does not really have anything to do with the objects.

Posted by Byron at Aug 1, 2011, 10:17:40 AM
Re: Plugin - Creating Objects with other Properties
Another thing I want ot mention is the following.
I do not know with which version you two are working,
but in general our version cannot be upgraded anymore which is really sad.
So, if by any chance you can use plugins or talk with emanuel puybaret about your adjustments, do it and like this what you do
can be also used to just extend SH3D funcitonality for everyone.
Also you can update the program and always use the newest version of SH3D.

2nd for generating new objects:
Besides creating the classes URDFPiece, HomeURDFPiece, etc.
(same for Gazebo classes)
If you just want to change things in the objects you need to do the following:
The key classes to modify then is:
homecontroller and furniturecatalogtransferhandler(for adding furniture)
homefurniturecontroller: here u need to add properties, add setters and getters, and modifier functions
homefurniturepanel: is what will be shown on double click.
If you check svn there should be a so called class urdf-panel
which will be displayed on the bottom.
this class you can just use and create new buttons, etc.
and

Posted by unrazzle at Aug 1, 2011, 6:45:40 PM
Re: Plugin - Creating Objects with other Properties
Byron,
thanks for your reply. i spent a lot more time with your code since i posted and i was able to figure out the parts of sh3d that you changed, also thanks to help from sicodelicos2003.

you're right, making these changes prevents updates to sh3d, so it isn't the best approach. also, i need to add a much larger list of properties and i need the properties to vary by object, so your approach won't work for that reason as well.

i emailed emmanuel with the details of what i need. if he feels it's worth it to discuss those details here, i would have no objection.

Posted by Byron at Aug 5, 2011, 10:49:01 PM
Re: Plugin - Creating Objects with other Properties
So I have written a document about
"How to extent an objects functionality"
It is some sort of short manual.
Is there a possibility to upload it here?

Posted by Puybaret at Aug 6, 2011, 9:29:36 AM
Re: Plugin - Creating Objects with other Properties
I just allowed you to attach some documents to your posts (max size 2 MB).
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by Byron at Aug 6, 2011, 11:10:41 AM
Re: Plugin - Creating Objects with other Properties
So here the Manual as PDF and Word Document.
I hope it will be helpful and there might be some parts
missing especially for the case (2).

Emanuel, do you know a way how to make this process easier?
----------------------------------------
Attachment How to extent an Object in SweetHome3D.pdf (10488 bytes) (Download count: 3943) (PDF Manual for extending the standard object classes with new properties or by creating new classes by inheritance from the standard class.)

----------------------------------------
Attachment How to extent an Object in SweetHome3D.doc (35840 bytes) (Download count: 3714) (Word Manual for extending the standard object classes with new properties or by creating new classes by inheritance from the standard class)


Posted by Puybaret at Oct 1, 2011, 12:40:03 AM
Re: Plugin - Creating Objects with other Properties
Sorry if my answer comes late, but for your information, in version 3.4, furniture instantiation will be centralized in the createHomePieceOfFurniture method of the FurnitureController class, and you'll be able to override it in a derived version if you need to instantiate furniture classes of yours.

Expect more documentation about how to create a derived version of Sweet Home 3D in the coming weeks...
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by anandunadkat at Jan 23, 2013, 4:23:27 PM
Re: Plugin - Creating Objects with other Properties
Hi Bryon,
is it possible for you to share the code for how to create new catalog elements. I have to do something similar where i have to create new catalog entries, basically a new library that will be there when sweethome 3d starts.

Thanks a lot