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: 11
Posts: 11   Pages: 2   [ 1 2 | Next Page ]
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 10947 times and has 10 replies Next Thread
anandunadkat
Newbie




Joined: Jan 15, 2013
Post Count: 17
Status: Offline
Reply to this Post  Reply with Quote 
Room size in java code

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 :(
[Jan 16, 2013, 10:38:57 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Sajmmon
Member



Poland
Joined: Nov 10, 2010
Post Count: 50
Status: Offline
Reply to this Post  Reply with Quote 
Re: Room size in java code

Adding rooms is quite simple, try:

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}}));
}}

[Jan 16, 2013, 12:55:46 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Sajmmon
Member



Poland
Joined: Nov 10, 2010
Post Count: 50
Status: Offline
Reply to this Post  Reply with Quote 
Re: Room size in java code

If your models are already imported try:


// 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);

[Jan 16, 2013, 2:10:45 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Sajmmon
Member



Poland
Joined: Nov 10, 2010
Post Count: 50
Status: Offline
Reply to this Post  Reply with Quote 
Re: Room size in java code

and last step is adding your hpof to home:

home.addPieceOfFurniture(hpof);

[Jan 16, 2013, 2:27:21 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
anandunadkat
Newbie




Joined: Jan 15, 2013
Post Count: 17
Status: Offline
Reply to this Post  Reply with Quote 
Re: Room size in java code

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
[Jan 16, 2013, 3:15:27 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Sajmmon
Member



Poland
Joined: Nov 10, 2010
Post Count: 50
Status: Offline
Reply to this Post  Reply with Quote 
Re: Room size in java code

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.
[Jan 16, 2013, 10:44:39 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
anandunadkat
Newbie




Joined: Jan 15, 2013
Post Count: 17
Status: Offline
Reply to this Post  Reply with Quote 
Re: Room size in java code

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!!
[Jan 17, 2013, 10:18:51 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Sajmmon
Member



Poland
Joined: Nov 10, 2010
Post Count: 50
Status: Offline
Reply to this Post  Reply with Quote 
Re: Room size in java code

The code below:

@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:



It would be great to hear more about your case study!
Cheers
[Jan 17, 2013, 9:12:46 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
anandunadkat
Newbie




Joined: Jan 15, 2013
Post Count: 17
Status: Offline
Reply to this Post  Reply with Quote 
sad Re: Room size in java code

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


WIndow will pop up asking for measurements




And then a template will come up.


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.
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
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!!!
[Jan 18, 2013, 9:31:17 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Sajmmon
Member



Poland
Joined: Nov 10, 2010
Post Count: 50
Status: Offline
Reply to this Post  Reply with Quote 
Re: Room size in java code

It is very interesting what you are doing. I dont know a simple answer to your question right now. I will think about it.
[Jan 18, 2013, 12:13:36 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Posts: 11   Pages: 2   [ 1 2 | Next Page ]
[ 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 2024 Space Mushrooms - All rights reserved