Room size in java code

This topic has been viewed 11536 times and has 10 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
anandunadkat
Posts: 17
Joined: Tue Jan 15, 2013 3:22 pm

Room size in java code

Post by anandunadkat »

Hi,

I am a beginner in this area and this is my first plugin. I am trying to develop a plugin to allow users to enter a bathroom template. There is a function where they have to enter the room size or choose automatically. how do i add size of lets say 2400mm x 2500mm into java code. Also how do i position objects into a certain area?

I really appreciate your help! please help me :(
Sajmmon
Posts: 50
Joined: Wed Nov 10, 2010 10:15 pm
Country: Warsaw, Poland
Contact:

Re: Room size in java code

Post by Sajmmon »

Adding rooms is quite simple, try:

Code: Select all

public class SimpleAction extends PluginAction{

@Override
public void execute() {

Home home=getHome();
// corners are (x,y) :: (0,0),(200,0), ... 
home.addRoom(new Room(
new float[][]{{0f,0f},{200f,0f},{200f,300f},{0f,300f}}));
}}
Sajmmon
Posts: 50
Joined: Wed Nov 10, 2010 10:15 pm
Country: Warsaw, Poland
Contact:

Re: Room size in java code

Post by Sajmmon »

If your models are already imported try:

Code: Select all

// first you need to retrieve a model e.g.
PieceOfFurniture pof =getUserPreferences()
.getFurnitureCatalog()
.getCategory(3)               // category e.g. 3
.getPieceOfFurniture(2);      // model 2 within the category

// Now you can display the model within current home
HomePieceOfFurniture hpof = new HomePieceOfFurniture(pof);

// and set locations etc.
hpof.setX(300);
hpof.setY(700);
hpof.setElevation(0);
hpof.setAngle(30);
Sajmmon
Posts: 50
Joined: Wed Nov 10, 2010 10:15 pm
Country: Warsaw, Poland
Contact:

Re: Room size in java code

Post by Sajmmon »

and last step is adding your hpof to home:
home.addPieceOfFurniture(hpof);
anandunadkat
Posts: 17
Joined: Tue Jan 15, 2013 3:22 pm

Re: Room size in java code

Post by anandunadkat »

Hi,

Thank you so much for you help. The code looks good. I understand how to get object from current library using category and number in that category. What i don't understand is how do i size my house/room to lets say 2700mm x 2500mm.

And also how to I add new piece of furniture/furnitures in the current library. Do i have to add the object to Eclipse project? if so how can i do that?

Thanks you so much i really appreciate it
Sajmmon
Posts: 50
Joined: Wed Nov 10, 2010 10:15 pm
Country: Warsaw, Poland
Contact:

Re: Room size in java code

Post by Sajmmon »

Home refers in SweetHome to an open project.
Walls are walls.
Room refers to a polygon drawn on ground/level (and the ceiling is associated with the polygon as well).

You can also create a room just by drawing walls - without floor (our Room). It might be misleading, but I am sure that after playing a bit with user interface you will understand the underlying Java classes.

Good luck.
anandunadkat
Posts: 17
Joined: Tue Jan 15, 2013 3:22 pm

Re: Room size in java code

Post by anandunadkat »

To make things easier to understand, i have pasted my code.

if (validateHouse()){

// if both house and bedroom dimension are unknown then speciry the hardcoded values.
if (cbUnknownHouseDimension.isSelected()){
bathroomLength = 1000f;
bathroomBreadth = 600f;
//bedroomLength = 250f;
//bedroomBreadth = 200f;
}

So as you can see from the code, if the user doesnt know the measurements, it clicks on the checkbox and i want the house size to appear with default values. Hope you understand what i mean.

Many thanks for your help!!
Sajmmon
Posts: 50
Joined: Wed Nov 10, 2010 10:15 pm
Country: Warsaw, Poland
Contact:

Re: Room size in java code

Post by Sajmmon »

The code below:

Code: Select all

@Override
        public void execute() {
        	Home home=getHome();
        	// display piece of furniture
        	PieceOfFurniture pof =getUserPreferences()
        	.getFurnitureCatalog()
        	.getCategory(1)               
        	.getPieceOfFurniture(1);      
        	HomePieceOfFurniture hpof = new HomePieceOfFurniture(pof);
        	home.addPieceOfFurniture(hpof);
        	// add room 
        	Room room=new Room(new float[][]{{0,120},{100,120},{100,220},{0,220}});
        	home.addRoom(room);
        	// add wall
        	Wall wall=new Wall(200,200,400,200,20,200);
        	home.addWall(wall);
        }
results in:

Image

It would be great to hear more about your case study!
Cheers
anandunadkat
Posts: 17
Joined: Tue Jan 15, 2013 3:22 pm

Re: Room size in java code

Post by anandunadkat »

Thank you so much for you help. I really do appreciate it. I will just paste a screenshot so you know what i am trying to get here.

User clicks on the option
Image

WIndow will pop up asking for measurements
Image

Image

And then a template will come up.
Image

as you can see from the screenshot, that it allows you to add railings as well. I have created a new object but it will not show up. below is code for one of them.

Code: Select all

	public static void addRightAngleRail(Home home,
			UserPreferences preferences, Float houseLength, Float houseBreadth) {
		HomePieceOfFurniture furniture;
		furniture =createFurniture(preferences,7 , 2, houseLength,houseBreadth-100);
		furniture.setColor(-255);
		furniture.setAngle(1.57f);
		home.addPieceOfFurniture(furniture);
	}
code for adding a room according to the measurements is here

Code: Select all

public class ExecuteCommand {
	
	public static void drawHouse(Home home, UserPreferences preferences, float houseLength, float houseBreadth){

		float xRef = 10;
		float yRef = 10;
		float wallThickness = 10;
		
		float wall_1_X1Start = xRef;
		float wall_1_Y1Start = yRef;
		float wall_1_X2End = xRef + houseLength;
		float wall_1_Y2End = yRef;
		
		float wall_2_X1Start = xRef + houseLength;
		float wall_2_Y1Start = yRef;
		float wall_2_X2End = xRef + houseLength;
		float wall_2_Y2End = yRef + houseBreadth;
		
		float wall_3_X1Start = xRef + houseLength;
		float wall_3_Y1Start = yRef + houseBreadth;
		float wall_3_X2End = xRef;
		float wall_3_Y2End = yRef + houseBreadth;
		
		float wall_4_X1Start = xRef;
		float wall_4_Y1Start = yRef + houseBreadth;
		float wall_4_X2End = xRef;
		float wall_4_Y2End = yRef;
		
		Wall wall_1 = new Wall(wall_1_X1Start, wall_1_Y1Start, wall_1_X2End, wall_1_Y2End,wallThickness);
		Wall wall_2 = new Wall(wall_2_X1Start, wall_2_Y1Start, wall_2_X2End, wall_2_Y2End,wallThickness);
		Wall wall_3 = new Wall(wall_3_X1Start, wall_3_Y1Start, wall_3_X2End, wall_3_Y2End,wallThickness);
		Wall wall_4 = new Wall(wall_4_X1Start, wall_4_Y1Start, wall_4_X2End, wall_4_Y2End,wallThickness); 
		
		//TextureImage firstTexture = preferences.getTexturesCatalog().getCategories().get(2).getTexture(6);
		TextureImage firstTexture = getdefaultHouseWallTexture(preferences);
		
		wall_1.setLeftSideTexture(new HomeTexture(firstTexture));
		wall_2.setLeftSideTexture(new HomeTexture(firstTexture));
		wall_3.setLeftSideTexture(new HomeTexture(firstTexture));
		wall_4.setLeftSideTexture(new HomeTexture(firstTexture));
	
		home.addWall(wall_1);
		home.addWall(wall_2);
		home.addWall(wall_3);
		home.addWall(wall_4);
So now i want to add a new furniture library so users can access those furniture without importing. And i want to arrange those object properly as you can see that they are not. Please help!!!
Sajmmon
Posts: 50
Joined: Wed Nov 10, 2010 10:15 pm
Country: Warsaw, Poland
Contact:

Re: Room size in java code

Post by Sajmmon »

It is very interesting what you are doing. I dont know a simple answer to your question right now. I will think about it.
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 1 guest