|
Posted by Mitsaki
at Aug 21, 2011, 5:37:24 PM
|
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; } }
|