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: 12
Posts: 12   Pages: 2   [ Previous Page | 1 2 ]
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 7013 times and has 11 replies Next Thread
Daniels118
Advanced Member
Member's Avatar

Italy
Joined: Nov 17, 2021
Post Count: 399
Status: Offline
Reply to this Post  Reply with Quote 
Re: New feature: Caption

Hi Vasilij,
you're right, the wirings are just [enhanced] polylines.
To understand what it can be done and what cannot, we have to look at how SH3D works.
Each class of object is stored in a distinct list member of the Home class:
private List<HomePieceOfFurniture> furniture;
private List<Wall> walls;
private List<Room> rooms;
private List<Polyline> polylines;
private List<DimensionLine> dimensionLines;
private List<Label> labels;

The drawing is implemented in PlanComponent.paintHomeItems(...) by drawing each item of these lists:
paintRooms(g2D, selectedItems, ...);
paintWalls(g2D, selectedItems, ...);
paintFurniture(g2D, this.sortedLevelFurniture, ...);
paintPolylines(g2D, this.home.getPolylines(), ...);
paintDimensionLines(g2D, this.home.getDimensionLines(), ...);
paintLabels(g2D, this.home.getLabels(), ...);

Although the items in each list can be added or removed, there is no chance to add a new list to draw another class of objects.
This means you have to resort to the current object classes. The Wirings and 3D dimension lines plugins work by extending one of the existing object classes (i.e. the polyline), by overriding the actual drawing code for the 3D view. This required some hack thich I'm not going to explain here.
For your project I wouldn't use this approach, because basically you can use the current object classes without changing the drawing code. Let's call your new object "Caption", and let's see the difference with Wirings.
The Wiring extends the polyline by adding a 3rd dimension to each point and changing the drawing code to handle 3 dimensions.
The Caption is a collection of 2 objects: a standard Polyline and a standard Label. The caption doesn't need to draw a new type of object. It should only place a standard Polyline and a standard Label, and use event handling to enforce some rules, i.e. the polyline must always have exaclty 3 points, one attached to the furniture, and the other 2 attached to the bottom left and bottom right corners of the label; if the user moves the furniture, then the polyline and the label must translate with the furniture; if the user moves the label, then the 2 polyline points must move with the label. The offsets of the polyline and the label relative to the furniture must be saved in a custom property, so that you can keep it constant when translating. If the user tries to move a point of the polyline you should block it by forcing its position to the expected value.
So the question is: how to know which furniture the polyline and the label belong to? It's easy: when you create the polyline and the label through the plugin, you also set a custom property on both objects, which is set to the id of the selected furniture.
The text template can be stored in a custom property of the label, while the actual text of the label is computed by your plugin and updated from the template each time a change is detected in the properties of the attached furniture.
This is how the "Link selected furniture" feature is capable of updating wirings position when the linked furnitures are moved around.

You don't need to implement saving and reading of a new type, everythng you need are the custom properties which are already persisted.

If you would follow this road, I would be happy to help you. But please be aware that I would only give hints and some code snippets, I'm not going to write whole pages of code for you (that would be matter for a paid work).

You are free to copy as much code you need from the Wirings plugin as long as you respect the GPL license.

Best regards,
Daniele
[Nov 5, 2022, 8:39:50 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
keymusicman
Newbie




Joined: Oct 23, 2022
Post Count: 5
Status: Offline
Reply to this Post  Reply with Quote 
Re: New feature: Caption

Thank you for the so much details. I missed the custom properties, it seems to be very flexible!

There will be another difficulties. For example: while editing a Caption I need to edit not the Text itself but its Template. If I use a Label, it will edit a Text by default. And this is not the only problem I see. While I can heroically find some workarounds for this, I would prefer to have a clear feature in the core part of SH3D. I believe that such a feature should be important for a modeling software.

Ideally, there could be an API that allows to extend the SH3D with a new elements without modifying the core part.

Daniele, I appreciate your help very much. I will follow your advices if Emmanuel declines my changes
[Nov 6, 2022, 4:49:48 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Posts: 12   Pages: 2   [ Previous Page | 1 2 ]
[ 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