|
Sweet Home 3D Forum » List all forums » » Forum: Developers » » » Thread: How to run a new class in SH3D source |
||
| Print at Dec 19, 2025, 1:42:39 AM |
|
|
| Posted by Mitsaki at Aug 19, 2011, 2:24:41 PM |
How to run a new class in SH3D sourceHello 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 ![]() |
| Posted by Puybaret at Aug 19, 2011, 8:18:39 PM |
|
Re: How to run a new class in SH3D source Sorry, but with no source code, it's just impossible to help you!!! ![]() ---------------------------------------- Emmanuel Puybaret, Sweet Home 3D creator |
| Posted by Mitsaki at Aug 20, 2011, 7:38:49 AM |
|
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) } |
| Posted by Mitsaki at Aug 20, 2011, 5:03:31 PM |
|
Re: How to run a new class in SH3D source Where should I copy paste this code... It seems not to work at all. |
| Posted by Puybaret at Aug 21, 2011, 10:44:35 AM |
|
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;Hope this will help you to start. ![]() ---------------------------------------- Emmanuel Puybaret, Sweet Home 3D creator |
| Posted by Mitsaki at Aug 21, 2011, 11:06:09 AM |
|
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... |
| Posted by Mitsaki at Aug 21, 2011, 11:07:41 AM |
|
Re: How to run a new class in SH3D source Sorry, I didn't see your reply:))) I hope it works!!! |
| Posted by Mitsaki at Aug 21, 2011, 5:37:24 PM |
Re: How to run a new class in SH3D sourceThe 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; |
| Posted by Puybaret at Aug 21, 2011, 6:10:04 PM |
|
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 |
| Posted by Mitsaki at Aug 21, 2011, 10:41:54 PM |
|
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 |
|
|
|
Current timezone is GMT Dec 19, 2025, 1:42:39 AM |