use private elements of the classes HomePane and HomeController for made a plugin to export the furniture in separated obj

This topic has been viewed 5565 times and has 4 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
Post Reply New Topic
chicosRV
Posts: 14
Joined: Fri May 25, 2012 4:37 pm

use private elements of the classes HomePane and HomeController for made a plugin to export the furniture in separated obj

Post by chicosRV »

hello

i need to make a plugin to export the furniture in separated obj files, i have to use private elements of the classes HomePane and HomeController. how can i do this?????
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: use private elements of the classes HomePane and HomeController for made a plugin to export the furniture in separated obj

Post by Puybaret »

Which elements do you need?
Emmanuel Puybaret, Sweet Home 3D creator
chicosRV
Posts: 14
Joined: Fri May 25, 2012 4:37 pm

Re: use private elements of the classes HomePane and HomeController for made a plugin to export the furniture in separated obj

Post by chicosRV »

this is what i have done

i modified the original code of the methods export to obj(it originally exported everything in one obj)

but what i really need is to made that function in a plugin

when a took the code for made the pluggin there were a lot of element that get selected like error

the plugin class only have the home and the userPreferences


this is the code

class Home Controller

Code: Select all

 public void exportToOBJ() {
     final String objName = getView().showExportToOBJDialog(this.home.getName());    
     final String dir = reduceToRoot(objName);
     HomePane.dir = dir;
    
    //Count Furniture//
    
    countFurniture();
    writeXMLEden3D("ss");
    
      
      if (objName != null) {
        
        // Export 3D view in a threaded task
        Callable<Void> exportToObjTask = new Callable<Void>() {
              public Void call() throws RecorderException {
                getView().exportToOBJ(HomePane.dir);
                return null;
              }
            };
        ThreadedTaskController.ExceptionHandler exceptionHandler = 
            new ThreadedTaskController.ExceptionHandler() {
              public void handleException(Exception ex) {
                if (!(ex instanceof InterruptedRecorderException)) {
                  if (ex instanceof RecorderException) {
                    String message = preferences.getLocalizedString(
                        HomeController.class, "exportToOBJError", objName);
                    getView().showError(message);
                  } else {
                    ex.printStackTrace();
                  }
                }
              }
            };
        new ThreadedTaskController(exportToObjTask, 
            this.preferences.getLocalizedString(HomeController.class, "exportToOBJMessage"), exceptionHandler, 
            this.preferences, this.viewFactory).executeTask(getView());
      }      
     
  }





class HomePane

Code: Select all

public static void exportHomeToFile(Home home, String objFile, String header) throws RecorderException {
      OBJWriter writer = null;
      boolean exportInterrupted = false;

      String[] names = new String[HomePane.counter];
      names[0] = "Room";
      int c=1;
      for(HomePieceOfFurniture piece : home.getFurniture()) {
        if(piece.isVisible()) {
          names[c] = piece.getName();
          c++;
        }

      }



      for(int j=0 ; j < HomePane.counter; j++ ) {
        try {
          HomePane.objName = names[j];
          writer = new OBJWriter(objFile+HomePane.objName+".obj", header, -1);

          List<Selectable> emptySelection = Collections.emptyList();

          home.setSelectedItems(emptySelection);



          if (HomePane.objName.equals("Room"))
          {


            if (home.getWalls().size() > 0) {
              // Create a not alive new ground to be able to explore its coordinates without setting capabilities
              Rectangle2D homeBounds = getExportedHomeBounds(home);
              Ground3D groundNode = new Ground3D(home,
                  (float)homeBounds.getX(), (float)homeBounds.getY(),
                  (float)homeBounds.getWidth(), (float)homeBounds.getHeight(), true);
              writer.writeNode(groundNode, "ground");
            }
          }

          // Write 3D walls
          int i;


          // The first time, we want to export the only the walls and the room
          if (HomePane.objName.equals("Room"))
          {
            i = 0;

            for (Wall wall : home.getWalls()) {
              // Create a not alive new wall to be able to explore its coordinates without setting capabilities
              Wall3D wallNode = new Wall3D(wall, home, true, true);
              writer.writeNode(wallNode, "wall_" + ++i);
            }

            // Write 3D rooms
            i = 0;
            for (Room room : home.getRooms()) {

              // Create a not alive new room to be able to explore its coordinates without setting capabilities
              Room3D roomNode = new Room3D(room, home, false, true, true);
              writer.writeNode(roomNode, "room_" + ++i);
            }
          }

          i = 0;

          if (!HomePane.objName.equals("Room"))
          {

            //Write 3D furniture
            for (HomePieceOfFurniture piece : home.getFurniture()) {
              if (piece.isVisible() && HomePane.objName.equals(piece.getName())) {

                // System.out.printf(objFile + "\n");
                // Create a not alive new piece to be able to explore its coordinates without setting capabilities
                // I set as home = null
                HomePieceOfFurniture3D pieceNode = new HomePieceOfFurniture3D(piece, home, true, true);
                writer.writeNode(pieceNode);
              }
            }
          }
        }
        catch (InterruptedIOException ex) {
          exportInterrupted = true;
          throw new InterruptedRecorderException("Export to " + objFile + " interrupted");
        } catch (IOException ex) {
          throw new RecorderException("Couldn't export to OBJ in " + objFile, ex);
        } finally {
          if (writer != null) {

            try {
              writer.close();
              // Delete the file if exporting is interrupted
              if (exportInterrupted) {
                new File(objFile).delete();
              }
            } catch (IOException ex) {
              throw new RecorderException("Couldn't export to OBJ in " + objFile, ex);
            }
          }
        }  



      } 
    }
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: use private elements of the classes HomePane and HomeController for made a plugin to export the furniture in separated obj

Post by Puybaret »

I think you missed the following point:
Version 3.5 gave access to the HomeController instance from a plug-in instance. Then, from the HomeController instance you can access to the other controllers and their views if necessary.

If exportToOBJ method doesn't perform like you want, I don't see the problem to write your own method in your plug-in. But if you want to change the behavior of the existing exportToOBJ method, you'll have to create a derived version of Sweet Home 3D, not a plug-in.
Emmanuel Puybaret, Sweet Home 3D creator
chicosRV
Posts: 14
Joined: Fri May 25, 2012 4:37 pm

Re: use private elements of the classes HomePane and HomeController for made a plugin to export the furniture in separated obj

Post by chicosRV »

thanks for your help i already downloaded the 3.5 version but i could finally made the plugin for the 3.3 version(it was a very important school homework and i couldn't use other version) but at the end i could made it(i don't wanted to change the original exportToObj, i only wanted to test the method a made) my pupouse was to made a export to open it in another application

by the way the orientation of a furniture is given by an angle , respect to what axe(x,y or z) it is,beacause i need to convert that angle in a vector, it;s that posible???
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 1 guest