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: 15
Posts: 15   Pages: 2   [ 1 2 | Next Page ]
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 16523 times and has 14 replies Next Thread
Mitsaki
Member




Joined: Jul 26, 2011
Post Count: 62
Status: Offline
Reply to this Post  Reply with Quote 
sad How to run a new class in SH3D source

Hello again,

I have started programming and I created a new package in the existing SH3D source code. In this new package I have created a class that is used to create a new Home, with walls and furniture. When I run this class, the interface of SH3D is opened but nothing is created. (I run this class using the instructions of README.txt and having as a main class com.eteks.sweethome3d.SweetHome3D).
Could you tell me what I am doing wrong??

PS. My code seems to have no mistakes.

Mitsaki sad
[Aug 19, 2011, 2:24:41 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9426
Status: Offline
Reply to this Post  Reply with Quote 
Re: How to run a new class in SH3D source

Sorry, but with no source code, it's just impossible to help you!!! sad
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
[Aug 19, 2011, 8:18: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 
Mitsaki
Member




Joined: Jul 26, 2011
Post Count: 62
Status: Offline
Reply to this Post  Reply with Quote 
Re: How to run a new class in SH3D source

package Blender;
/*
* Read_File_and_Save.java Aug 11, 2011
*
* Creation of a class that reads a text file and saves it in an array
* Afterwards, it creates a SH3D project which is according to user's preferences.
*/

/**
* @author Dimitra Micha
*/

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

//import com.eteks.sweethome3d.io.DefaultUserPreferences;
import com.eteks.sweethome3d.model.CollectionEvent;
import com.eteks.sweethome3d.model.CollectionListener;
import com.eteks.sweethome3d.model.Home;
import com.eteks.sweethome3d.model.Room;
import com.eteks.sweethome3d.model.TextureImage;
//import com.eteks.sweethome3d.model.UserPreferences;
import com.eteks.sweethome3d.model.Wall;


public class FileRead {

/** Basic external class used to create a room and import furniture in it according to user's preferences.
* @throws Exception
*
*
*/
public static void main(String args[])
{

// Maximum elements of the array:108 (200 obligatory, 88 optional)
String[] str = new String[108];

try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("/Users/dimitramicha/Desktop/SweetHome3D1.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
int i=0;
while ((strLine = br.readLine()) != null)
{
// Print the content on the console
//System.out.println (strLine);
//System.out.println(i);
str = strLine;
System.out.println(str);
i++;
// Check each line - Don't forget to make them comments afterwards!!!!!
}

//Close the input stream
in.close();
}
catch (Exception e)
{
//Catch exception if any
System.err.println("Error: " + e.getMessage());
}

String Shape_of_Room = str[2];
String Shiny_Matt = str[3];
String Right_Wall_Color = str[5];
String Right_Wall_Texture = str[6];
String Left_Wall_Color = str[7];
String Left_Wall_Texture = str[8];
String North_Wall_Color = str[9];
String North_Wall_Texture = str[10];
String South_Wall_Color = str[11];
String South_Wall_Texture = str[12];
String Ceiling_Display = str[13];
String Ceiling_Texture = str[14];
String Floor_Display = str[15];
String Floor_Texture = str[16];

// Save in another array the list of furniture. The maximum of this list is 91
// (108 values in total - 17 already mentioned above)

int j;
for (j=0;j<91;j++) {
String List_of_Furniture = (String) str[j+17];
}
//Check the Shape_of_Room
//Else - If Statement

if (Shape_of_Room == "Parallelogram") {

// Create a home and a wall listener that updates lists when notified
Home Parallelogram = new Home();

final List<Wall> addedWalls = new ArrayList<Wall>();
final List<Wall> deletedWalls = new ArrayList<Wall>();
final List<Wall> updatedWalls = new ArrayList<Wall>();
final PropertyChangeListener wallChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
updatedWalls.add((Wall)ev.getSource());
}
};

Parallelogram.addWallsListener(new CollectionListener<Wall> () {
public void collectionChanged(CollectionEvent<Wall> ev) {
switch (ev.getType()) {
case ADD :
addedWalls.add(ev.getItem());
ev.getItem().addPropertyChangeListener(wallChangeListener);
break;
case DELETE :
deletedWalls.add(ev.getItem());
ev.getItem().removePropertyChangeListener(wallChangeListener);
break;
}
}
});

//Create a Room
Room Parallelogram_Room = new Room(null);
Parallelogram_Room.addPoint(0, 0);
Parallelogram_Room.addPoint(0, 400);
Parallelogram_Room.addPoint(625, 400);
Parallelogram_Room.addPoint(625, 400);
Parallelogram_Room.addPoint(0, 0);

Parallelogram.addRoom(Parallelogram_Room);

//Creation Walls
Wall Left_Wall = new Wall(0, 0, 0, 400, (float) 7.62);
Wall North_Wall = new Wall(0, 400, 625, 400, (float) 7.62);
Wall Right_Wall = new Wall(625, 400, 625 ,0 , (float) 7.62);
Wall South_Wall = new Wall(625, 0, 0, 0, (float) 7.62);

// Add them to home
Parallelogram.addWall(Left_Wall);
Parallelogram.addWall(North_Wall);
Parallelogram.addWall(Right_Wall);
Parallelogram.addWall(South_Wall);

// Set as User Preferences the default User Preferences
//UserPreferences preferences = new DefaultUserPreferences();

// Set as Texture image the first texture that is available

//TextureImage firstTexture = preferences.getTexturesCatalog().getCategories().get(0).getTexture(0);

// Join end point of one wall to start point of the other wall (4 times - 4 walls)
Left_Wall.setWallAtEnd(North_Wall);
North_Wall.setWallAtEnd(Right_Wall);
Right_Wall.setWallAtEnd(South_Wall);
South_Wall.setWallAtEnd(Left_Wall);

if (Floor_Display == "true") {
Parallelogram_Room.setFloorVisible(true);
}

if (Shiny_Matt == "Matt") {
Left_Wall.setRightSideShininess(0);
North_Wall.setRightSideShininess(0);
Right_Wall.setRightSideShininess(0);
South_Wall.setRightSideShininess(0);
}
else if (Shiny_Matt == "Shiny") {

Left_Wall.setRightSideShininess(1);
North_Wall.setRightSideShininess(1);
Right_Wall.setRightSideShininess(1);
South_Wall.setRightSideShininess(1);
}

// http://cloford.com/resources/colours/500col.htm Color(int rgb)
// Create a string array which will be used to check the color of each wall
// Create an array of integers which includes the rgb numbers of the colors

String[] color = {"Grey","White","Red","Green","Yellow","Blue"};
int[] rgb = {13882323,16119285,6974207,10210715,9170175,15641692};

int k;

for(k=0;k<6;k++)
{
if (Left_Wall_Color == color[k]) {

Left_Wall.setRightSideColor(rgb[k]);
}
if (North_Wall_Color == color[k]) {

North_Wall.setRightSideColor(rgb[k]);
}
if (Right_Wall_Color == color[k]) {

Right_Wall.setRightSideColor(rgb[k]);
}
if (South_Wall_Color == color[k]) {

South_Wall.setRightSideColor(rgb[k]);
}

};
}
(it continues with the same code, else -if state but different objects are created)
}
[Aug 20, 2011, 7:38:49 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Mitsaki
Member




Joined: Jul 26, 2011
Post Count: 62
Status: Offline
Reply to this Post  Reply with Quote 
Re: How to run a new class in SH3D source

Where should I copy paste this code...
It seems not to work at all.
[Aug 20, 2011, 5:03:31 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9426
Status: Offline
Reply to this Post  Reply with Quote 
Re: How to run a new class in SH3D source

Ok, I think I understood what you want to do now.
If you want to display a home built by program from a derived version of Sweet Home 3D, you should:
- create a subclass of com.eteks.sweethome3d.SweetHome3D application class,
- add a main method that will instantiate and init the application from the arguments
- override the createHome method to return a com.eteks.sweethome3d.model.Home instance initialized the way you want.
Here's a base example:

import com.eteks.sweethome3d.SweetHome3D;
import com.eteks.sweethome3d.model.Home;

public class Test extends SweetHome3D {
public static void main(String [] args) {
new Test().init(args);
}

@Override
public Home createHome() {
Home home = super.createHome();
// Modify home as you wish here
return home;
}
}

Hope this will help you to start. smile
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
[Aug 21, 2011, 10:44:35 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Mitsaki
Member




Joined: Jul 26, 2011
Post Count: 62
Status: Offline
Reply to this Post  Reply with Quote 
Re: How to run a new class in SH3D source

Is there any change that I should write this into my code?

SweetHome3D Home3D = new SweetHome3D();

Home3D.addHome(Parallelogram);

Although, it still doesn't work...
[Aug 21, 2011, 11:06:09 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Mitsaki
Member




Joined: Jul 26, 2011
Post Count: 62
Status: Offline
Reply to this Post  Reply with Quote 
Re: How to run a new class in SH3D source

Sorry, I didn't see your reply:)))
I hope it works!!!
[Aug 21, 2011, 11:07:41 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Mitsaki
Member




Joined: Jul 26, 2011
Post Count: 62
Status: Offline
Reply to this Post  Reply with Quote 
confused Re: How to run a new class in SH3D source

The thing is that I was expecting to have something created, a wall, a room...
but nothing is displayed.

Here is the code, after the changes.


package com.eteks.sweethome3d;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import java.util.ArrayList;
import java.util.List;

import com.eteks.sweethome3d.model.CollectionEvent;
import com.eteks.sweethome3d.model.CollectionListener;

import com.eteks.sweethome3d.SweetHome3D;
import com.eteks.sweethome3d.model.Home;
import com.eteks.sweethome3d.model.Room;
import com.eteks.sweethome3d.model.Wall;



public class Blender extends SweetHome3D {

public static String[] str = new String[108];
public static String Shape_of_Room = str[2];
public static String Shiny_Matt = str[3];
public static String Right_Wall_Color = str[5];
public static String Right_Wall_Texture = str[6];
public static String Left_Wall_Color = str[7];
public static String Left_Wall_Texture = str[8];
public static String North_Wall_Color = str[9];
public static String North_Wall_Texture = str[10];
public static String South_Wall_Color = str[11];
public static String South_Wall_Texture = str[12];
public static String Ceiling_Display = str[13];
public static String Ceiling_Texture = str[14];
public static String Floor_Display = str[15];
public static String Floor_Texture = str[16];
public static String[] List_of_Furniture;

public static void main(String [] args) {

// First save the furniture in an array
// Maximum elements of the array:108 (91 obligatory, 88 optional)
int j;

// Declare the size of the List_of_Furniture
List_of_Furniture = new String[92];

for (j=0;j<91;j++) {
List_of_Furniture[j] = str[j+17];
}

try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("/Users/dimitramicha/Desktop/SweetHome3D1.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
// Read File Line By Line
int i=0;
while ((strLine = br.readLine()) != null)
{
// Print the content on the console
System.out.println (strLine);
System.out.println(i);
str = strLine;
System.out.println(str);
i++;
// Check each line - Don't forget to make them comments afterwards!!!!!
}

// Close the input stream
in.close();
}
catch (Exception e)
{
// Catch exception if any
System.err.println("Error: " + e.getMessage());
}

// Run the application SweetHome3D and run method createHome()
Blender blender = new Blender();
blender.init(args);
blender.createHome();

}


// The ability of a subclass to override a method allows a class to inherit from
// a superclass whose behavior is "close enough" and then to modify behavior as needed.
// The overriding method has the same name, number and type of parameters, and return type
// as the method it overrides. An overriding method can also return a subtype of the type
// returned by the overridden method.

@Override
public Home createHome() {

Home home = super.createHome();

if (Shape_of_Room=="Parallelogram")
{
// Create a home and a wall listener that updates lists when notified
Home Parallelogram = new Home();

// Create a Room - Room (float[][] points)
// Any of these numbers can be followed by "F" (or "f")
// to make it a float instead of the default double
float[][] points = {{0f,0f},{0f,400f},{625f,400f},{625f,400f},{625f,0f},{0f,0f}};
Room Parallelogram_Room = new Room(points);
Parallelogram_Room.setAreaVisible(true);

// Add new Room to Home
Parallelogram.addRoom(Parallelogram_Room);

// Notify Listeners

final List<Wall> addedWalls = new ArrayList<Wall>();
final List<Wall> deletedWalls = new ArrayList<Wall>();
final List<Wall> updatedWalls = new ArrayList<Wall>();
final PropertyChangeListener wallChangeListener = new PropertyChangeListener()
{
public void propertyChange(PropertyChangeEvent ev)
{
updatedWalls.add((Wall)ev.getSource());
}
};

Parallelogram.addWallsListener(new CollectionListener<Wall> ()
{
public void collectionChanged(CollectionEvent<Wall> ev)
{
switch (ev.getType())
{
case ADD :
addedWalls.add(ev.getItem());
ev.getItem().addPropertyChangeListener(wallChangeListener);
break;
case DELETE :
deletedWalls.add(ev.getItem());
ev.getItem().removePropertyChangeListener(wallChangeListener);
break;
}
}
});


//Creation Walls
Wall Left_Wall = new Wall(0, 0, 0, 400, (float) 7.62);
Wall North_Wall = new Wall(0, 400, 625, 400, (float) 7.62);
Wall Right_Wall = new Wall(625, 400, 625 ,0 , (float) 7.62);
Wall South_Wall = new Wall(625, 0, 0, 0, (float) 7.62);


// Add them to home
Parallelogram.addWall(Left_Wall);
Parallelogram.addWall(North_Wall);
Parallelogram.addWall(Right_Wall);
Parallelogram.addWall(South_Wall);

// Set as User Preferences the default User Preferences
//UserPreferences preferences = new DefaultUserPreferences();

// Set as Texture image the first texture that is available

//TextureImage firstTexture = preferences.getTexturesCatalog().getCategories().get(0).getTexture(0);

// Join end point of one wall to start point of the other wall (4 times - 4 walls)
Left_Wall.setWallAtEnd(North_Wall);
North_Wall.setWallAtEnd(Right_Wall);
Right_Wall.setWallAtEnd(South_Wall);
South_Wall.setWallAtEnd(Left_Wall);

};

if (Shape_of_Room == "Square") {

// Create a home and a wall listener that updates lists when notified
Home Square = new Home();

};

if (Shape_of_Room == "Trapeze-1") {

// Create a home and a wall listener that updates lists when notified
Home Trapeze_1 = new Home();

};

if (Shape_of_Room == "Trapeze-2") {

// Create a home and a wall listener that updates lists when notified
Home Trapeze_2 = new Home();

};

// Modify home as you wish here
return home;
}
}

[Aug 21, 2011, 5:37:24 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9426
Status: Offline
Reply to this Post  Reply with Quote 
Re: How to run a new class in SH3D source

You shouldn't call blender.createHome(); directly and your createHome method doesn't return the home to which you added all your walls!
Instantiate only once the Home class with super.createHome(); call and add the walls to this instance.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
[Aug 21, 2011, 6:10:04 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Mitsaki
Member




Joined: Jul 26, 2011
Post Count: 62
Status: Offline
Reply to this Post  Reply with Quote 
Re: How to run a new class in SH3D source

Well, I corrected my mistakes and I call the method with what you suggested:

new Blender().init(args);

but I don't see any results in the interface
[Aug 21, 2011, 10:41:54 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: 15   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