![]() |
Home |
Download |
Online |
Gallery |
Blog |
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Plug-in developer's guideIntroduction
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Installing/uninstalling a plug-in by copying it in Sweet Home 3D plug-ins folder isn't very user-friendly. This will be probably improved In future versions of Sweet Home 3D with a pane dedicated to the management of plug-ins. |
The programming of the first plug-in showed you the big picture. Here's some additional information that will help you to go further.
Sweet Home 3D API - Javadoc
The most useful documentation to develop a new plug-in is the Sweet Home 3D API (Application Programming Interface), generated with javadoc tool.
Use only the classes of com.eteks.sweethome3d.plugin, com.eteks.sweethome3d.model and com.eteks.sweethome3d.tools packages in your plug-in if you want it to be upward compatible with future versions of Sweet Home 3D. This will be largely enough to program any plug-in that works on the home data available in Sweet Home 3D.
The packages matching the other layers of the program are included in the Javadoc for information purpose only. Don't rely on their API, as it may still change in the future with no guarantee of upward compatibility (anyway you'll see no reference to a class of com.eteks.sweethome3d.viewcontroller, com.eteks.sweethome3d.swing or com.eteks.sweethome3d.io packages in the aforementioned packages).Model classes architecture
Sweet Home 3D is based on a MVC (Model View Controller) architecture, so understanding how is organized its Model layer is essential. The figure 9 (available also at PDF format) presents almost all the classes and interfaces available in the version 1.5 of com.eteks.sweethome3d.model package that matches this Model layer.
![]()
Figure 9. UML diagram of com.eteks.sweethome3d.model package
(click on a class to view its javadoc)The central class in the Model layer is the HomeApplication class (10), the abstract super class of SweetHome3D application main class. The instance of this class gives access to the Home instances (7) currently edited, and to the UserPreferences object (11) that stores the length unit in use (12), the furniture catalog (14) and the textures catalog (15) from which the user chooses pieces of furniture (17) and textures (18).
A Home instance (7) stores all the objects the user created in the home plan:
- the list of HomePieceOfFurniture objects (13) which implement the interface PieceOfFurniture (16),
- the collection of Wall objects (9),
- the list of Room objects (5),
- the collection of DimensionLine objects (2),
- the collection of Label objects (3).
These objects implement the Selectable interface (1) as well as the ObserverCamera object (4), that stores the location of the camera in the Virtual visitor mode. All the external information managed by Model objects, like the icon and the 3D model of a piece of furniture (16), or the image of a texture (20) is accessed through the Content interface (19), implemented by the URLContent class and other classes of the com.eteks.sweethome3d.tools package.
This UML diagram should help you understand which classes are available in the Sweet Home 3D model and how you can access to them, but you'll probably notice that no constructors and no mutators (or setters if you prefer) are cited in it. It's just by lack of room but you can use them with no problem in a plug-in class. Note also that any modification of an existing object of the model will be notified to the displayed components either with PropertyChangeEvents, with CollectionEvents (8) or with SelectionEvents (6), thus allowing all changes to be reflected immediately on screen.
![]()
Sweet Home 3D model isn't thread safe for performance reasons. All modifications of an object belonging to the model should be done in the Event Dispatch Thread.
Plug-in classes architecture
The architecture of plug-in classes is much more simple to understand than the Model layer's one. The com.eteks.sweethome3d.plugin package contains only three classes among which you're supposed to use only Plugin and PluginAction classes, as shown in figure 10 (also available at PDF format).
Figure 10. UML diagram of com.eteks.sweethome3d.plugin package
(click on a class to view its javadoc)A PluginManager instance (1) is created at application launch and searchs the plug-ins installed in user's plug-ins folder. Each time a new home is edited, this manager instanciates and configures a Plugin object (3) for each plug-in found at launch time. Then, it calls the getActions method to retrieve all the actions (4) that will be added as menu items and/or tool bar buttons in the home window. Each action is an instance of PluginAction, which looks like Action class, with its execute method and its modifiable properties (2).
Note that the Plugin class gives you access to an UndoableEditSupport instance through its getUndoableEditSupport method. As soon as you modify a home or its objects (furniture, walls...) in the execute method of a PluginAction instance, you should also post an UndoableEdit object to the undoable edit support returned by getUndoableEditSupport method, otherwise users won't be able to undo/redo correctly the changes you made.
Localization
If you plan to develop a plug-in for Sweet Home 3D users community, try to localize the strings it displays either in actions name and menu or in dialogs you'll create (or at least prepare its localization). Two constructors of the PluginAction class will help you to organize the translation of actions properties with .properties files, and if you need to translate other strings in your plug-in (like the one in the dialog shown by the tested plug-in) reuse these .properties files with ResourceBundle Java class.
If you prefer to limit the number of properties files, you might even write the values of the action properties and other strings in the ApplicationPlugin.properties description file of your plug-in.If you want an example that uses this architecture, download the Export to SH3F plug-in available at http://sweethome3d.com/plugins/ExportToSH3F-1.0.sh3p, and unzip it (this plug-in file contains also the source code of the plug-in).
As described in Help forum, this plug-in creates a SH3F file that contains all the furniture you imported in the furniture catalog of Sweet Home 3D.Contributing plug-ins
You can post the plug-ins you programmed in Plug-ins Contributions Tracking System to share them with Sweet Home 3D users community.
Many features can be added to Sweet Home 3D thanks to plug-ins, from importers to exporters, but also plug-ins able to modify the data of a home like the Home Rotator Plug-in developed by Michel Mbem.
Last update : August 24, 2010
| © Copyrights 2006-2010 eTeks - All rights reserved | ||||||