Examples of HomePieceOfFurniture


Examples of com.eteks.sweethome3d.model.HomePieceOfFurniture

    csv.append(lineSeparator);
   
    // Selected values
    for (int rowIndex : getSelectedRows()) {
      TableModel model = getModel();
      HomePieceOfFurniture copiedPiece = (HomePieceOfFurniture)model.getValueAt(rowIndex, 0);
      for (int columnIndex = 0, n = this.columnModel.getColumnCount(); columnIndex < n; columnIndex++) {
        if (columnIndex > 0) {
          csv.append("\t");
        }
        TableColumn column = this.columnModel.getColumn(columnIndex);
        Object columnIdentifier = column.getIdentifier();
        if (columnIdentifier instanceof HomePieceOfFurniture.SortableProperty) {
          switch ((HomePieceOfFurniture.SortableProperty)columnIdentifier) {
            case CATALOG_ID :
              // Copy piece catalog id
              String catalogId = copiedPiece.getCatalogId();
              csv.append(catalogId != null ? catalogId : "");
              break;
            case NAME :
              // Copy piece name
              csv.append(copiedPiece.getName());
              break;
            case COLOR :
              if (copiedPiece.getColor() != null) {
                // Copy piece color at #xxxxxx format             
                csv.append("#" + Integer.toHexString(copiedPiece.getColor()).substring(2));
              }
              break;
            case TEXTURE :
              if (copiedPiece.getTexture() != null) {
                csv.append(copiedPiece.getTexture().getName());
              }
            case WIDTH :
            case DEPTH :
            case HEIGHT :
            case X :
            case Y :
            case ELEVATION :
            case ANGLE :
            case PRICE :
            case VALUE_ADDED_TAX_PERCENTAGE :
            case VALUE_ADDED_TAX :
            case PRICE_VALUE_ADDED_TAX_INCLUDED :
              // Copy numbers as they are displayed by their renderer
              csv.append(((JLabel)column.getCellRenderer().getTableCellRendererComponent(
                  this, copiedPiece, false, false, rowIndex, columnIndex)).getText());
              break;
            case MOVABLE :
              // Copy boolean as true or false
              csv.append(copiedPiece.isMovable());
              break;
            case DOOR_OR_WINDOW :
              csv.append(copiedPiece.isDoorOrWindow());
              break;
            case VISIBLE :
              csv.append(copiedPiece.isVisible());
              break;
          }
        } else {
          Component rendererComponent = column.getCellRenderer().getTableCellRendererComponent(
              this, copiedPiece, false, false, rowIndex, columnIndex);
View Full Code Here

Examples of com.eteks.sweethome3d.model.HomePieceOfFurniture

    Home home1 = new Home();
    // Add to home a wall and a piece of furniture
    Wall wall = new Wall(0, 10, 100, 80, 10);
    home1.addWall(wall);
    FurnitureCatalog catalog = new DefaultFurnitureCatalog();
    HomePieceOfFurniture piece = new HomePieceOfFurniture(
        catalog.getCategories().get(0).getFurniture().get(0));
    home1.addPieceOfFurniture(piece);
   
    // 2. Record home in a file named test.sh3d in current directory
    HomeRecorder recorder = new HomeFileRecorder();
View Full Code Here

Examples of com.eteks.sweethome3d.model.HomePieceOfFurniture

    public void enter() {
      this.widthResizeToolTipFeedback = preferences.getLocalizedString(
          PlanController.class, "widthResizeToolTipFeedback");
      this.depthResizeToolTipFeedback = preferences.getLocalizedString(
          PlanController.class, "depthResizeToolTipFeedback");
      HomePieceOfFurniture selectedPiece = (HomePieceOfFurniture)home.getSelectedItems().get(0);
      this.resizedPiece = new ResizedPieceOfFurniture(selectedPiece);
      float [][] resizedPiecePoints = selectedPiece.getPoints();
      float [] resizePoint = resizedPiecePoints [2];
      this.deltaXToResizePoint = getXLastMousePress() - resizePoint [0];
      this.deltaYToResizePoint = getYLastMousePress() - resizePoint [1];
      this.topLeftPoint = resizedPiecePoints [0];
      this.magnetismEnabled = preferences.isMagnetismEnabled()
                              ^ wasShiftDownLastMousePress();     
      PlanView planView = getView();
      planView.setResizeIndicatorVisible(true);
      planView.setToolTipFeedback(getToolTipFeedbackText(selectedPiece.getWidth(), selectedPiece.getDepth()),
          getXLastMousePress(), getYLastMousePress());
    }
View Full Code Here

Examples of com.eteks.sweethome3d.model.HomePieceOfFurniture

    @Override
    public void moveMouse(float x, float y) {
      // Compute the new location and dimension of the piece to let
      // its bottom right point be at mouse location
      PlanView planView = getView();
      HomePieceOfFurniture selectedPiece = this.resizedPiece.getPieceOfFurniture();
      float angle = selectedPiece.getAngle();
      double cos = Math.cos(angle);
      double sin = Math.sin(angle);
      float deltaX = x - this.deltaXToResizePoint - this.topLeftPoint [0];
      float deltaY = y - this.deltaYToResizePoint - this.topLeftPoint [1];
      float newWidth =  (float)(deltaY * sin + deltaX * cos);
      if (this.magnetismEnabled) {
        newWidth = preferences.getLengthUnit().getMagnetizedLength(newWidth, planView.getPixelLength());
      }
      newWidth = Math.max(newWidth, preferences.getLengthUnit().getMinimumLength());
     
      float newDepth;
      if (!this.resizedPiece.isDoorOrWindowBoundToWall()
          || !selectedPiece.isDeformable()
          || !this.magnetismEnabled) {
        // Update piece depth if it's not a door a window
        // or if it's a a door a window unbound to a wall when magnetism is enabled
        newDepth = (float)(deltaY * cos - deltaX * sin);
        if (this.magnetismEnabled) {
          newDepth = preferences.getLengthUnit().getMagnetizedLength(newDepth, planView.getPixelLength());
        }
        newDepth = Math.max(newDepth, preferences.getLengthUnit().getMinimumLength());
      } else {
        newDepth = this.resizedPiece.getDepth();
      }
     
      // Manage proportional constraint
      float newHeight = this.resizedPiece.getHeight();
      if (!selectedPiece.isDeformable()) {
        float [][] resizedPiecePoints = selectedPiece.getPoints();
        float ratio;
        if (Line2D.relativeCCW(resizedPiecePoints [0][0], resizedPiecePoints [0][1], resizedPiecePoints [2][0], resizedPiecePoints [2][1], x, y) >= 0) {
          ratio = newWidth / this.resizedPiece.getWidth();
          newDepth = this.resizedPiece.getDepth() * ratio;
        } else {
          ratio = newDepth / this.resizedPiece.getDepth();
          newWidth = this.resizedPiece.getWidth() * ratio;
        }
        newHeight = this.resizedPiece.getHeight() * ratio;
      }
     
      // Update piece new location
      float newX = (float)(this.topLeftPoint [0] + (newWidth * cos - newDepth * sin) / 2f);
      float newY = (float)(this.topLeftPoint [1] + (newWidth * sin + newDepth * cos) / 2f);
      selectedPiece.setX(newX);
      selectedPiece.setY(newY);
      // Update piece size
      selectedPiece.setWidth(newWidth);
      selectedPiece.setDepth(newDepth);
      selectedPiece.setHeight(newHeight);
      if (this.resizedPiece.isDoorOrWindowBoundToWall()) {
        // Maintain boundToWall flag
        ((HomeDoorOrWindow)selectedPiece).setBoundToWall(this.magnetismEnabled);
      }

View Full Code Here

Examples of com.eteks.sweethome3d.model.HomePieceOfFurniture

  private static List<HomePieceOfFurniture> createHomeFurnitureFromCatalog(
      FurnitureCatalog catalog) {
    List<HomePieceOfFurniture> homeFurniture = new ArrayList<HomePieceOfFurniture>();
    for (FurnitureCategory category : catalog.getCategories()) {
      for (CatalogPieceOfFurniture piece : category.getFurniture()) {
        homeFurniture.add(new HomePieceOfFurniture(piece));
      }
    }
    return homeFurniture;
  }
View Full Code Here

Examples of com.eteks.sweethome3d.model.HomePieceOfFurniture

    furnitureController.sortFurniture(HomePieceOfFurniture.SortableProperty.NAME);
    // Check table data is sorted in alphabetical descending order
    assertFurnitureIsSortedByName(table, false);
   
    // 5. Change first furniture name
    HomePieceOfFurniture firstPiece = home.getFurniture().get(0);
    firstPiece.setName("Aaaa");
    // Check table data is sorted in alphabetical descending order
    assertFurnitureIsSortedByName(table, false);
  }
View Full Code Here

Examples of com.eteks.sweethome3d.model.HomePieceOfFurniture

          return !piece.isDoorOrWindow();
        }
      });
    // Count how many doors and windows are in home
    int doorsAndWindowsCount = 0;
    HomePieceOfFurniture doorOrWindowPiece = null;
    HomePieceOfFurniture otherPiece = null;
    for (HomePieceOfFurniture piece : home.getFurniture()) {
      if (piece.isDoorOrWindow()) {
        doorsAndWindowsCount++;
        doorOrWindowPiece = piece;
      } else {
        otherPiece = piece;
      }
    }
    // Check there's no door or window in table
    int homeFurnitureCount = homeFurniture.size();
    int tableFilterRowCount = table.getRowCount();
    assertEquals("Home furniture count and row count same",
        homeFurnitureCount - doorsAndWindowsCount, tableFilterRowCount);
   
    // 3. Add a door or window to home
    home.addPieceOfFurniture(new HomePieceOfFurniture(doorOrWindowPiece));
    // Check no row were added in table
    assertEquals("Wrong furniture count in home", homeFurnitureCount + 1, home.getFurniture().size());
    assertEquals("Wrong row count in table", tableFilterRowCount, table.getRowCount());
   
    // 4. Add an other kind of piece to home
    home.addPieceOfFurniture(new HomePieceOfFurniture(otherPiece));
    // Check one row was added in table
    assertEquals("Wrong furniture count in home", homeFurnitureCount + 2, home.getFurniture().size());
    assertEquals("Wrong row count in table", tableFilterRowCount + 1, table.getRowCount());
   
    // 5. Test sort and filter internal buffer of the table
    furnitureController.sortFurniture(HomePieceOfFurniture.SortableProperty.NAME);
    // Check the alphabetical order of table data
    assertFurnitureIsSortedByName(table, true);
    // Add a door or window and an other kind of piece to home
    home.addPieceOfFurniture(new HomePieceOfFurniture(doorOrWindowPiece));
    home.addPieceOfFurniture(new HomePieceOfFurniture(otherPiece));
    // Check one row was added in sorted table
    assertEquals("Wrong furniture count in home", homeFurnitureCount + 4, home.getFurniture().size());
    assertEquals("Wrong row count in table", tableFilterRowCount + 2, table.getRowCount());
    assertFurnitureIsSortedByName(table, true);
   
View Full Code Here

Examples of com.eteks.sweethome3d.model.HomePieceOfFurniture

    assertActionsEnabled(true, false, true, false);
   
    // 5. Undo last operation
    runAction(HomePane.ActionType.UNDO);
    // Check home contains the deleted piece
    HomePieceOfFurniture firstPiece = furniture.get(0);
    assertEquals("Deleted piece isn't undeleted",
        firstPiece, home.getFurniture().get(0));
    assertEquals("Deleted piece isn't selected",
        firstPiece, home.getSelectedItems().get(0));
    //  Check all actions are enabled
View Full Code Here

Examples of com.eteks.sweethome3d.model.HomePieceOfFurniture

   * Tests zoom and alignment tools.
   */
  public void testZoomAndAligment() {
    // Add the first two pieces of catalog first category to home
    FurnitureCategory firstCategory = this.preferences.getFurnitureCatalog().getCategories().get(0);
    HomePieceOfFurniture firstPiece = new HomePieceOfFurniture(firstCategory.getFurniture().get(0));
    this.home.addPieceOfFurniture(firstPiece);
    HomePieceOfFurniture secondPiece = new HomePieceOfFurniture(firstCategory.getFurniture().get(1));
    secondPiece.setAngle(15);
    this.home.addPieceOfFurniture(secondPiece);
    // Add a wall to home
    this.home.addWall(new Wall(0, 0, 100, 0, 7));
   
    PlanController planController = this.homeController.getPlanController();
    float scale = planController.getScale();
   
    // 1. Zoom in
    runAction(HomePane.ActionType.ZOOM_IN);   
    // Check scale changed
    assertEquals("Scale is incorrect", scale * 1.5f, planController.getScale());
   
    // 2. Zoom out
    runAction(HomePane.ActionType.ZOOM_OUT);   
    // Check scale is back to its previous value
    assertEquals("Scale is incorrect", scale, planController.getScale());
   
    // 3. Select all while table has focus
    this.homeController.focusedViewChanged(this.furnitureTable);
    runAction(HomePane.ActionType.SELECT_ALL);
    // Check selection contains the two pieces
    assertEquals("Selection doesn't contain home furniture",
        this.home.getFurniture(), this.home.getSelectedItems());

    // 4. Select all while plan has focus
    this.homeController.focusedViewChanged(planController.getView());
    runAction(HomePane.ActionType.SELECT_ALL);
    // Check selection contains the two pieces, the wall and the compass
    assertEquals("Selection doesn't contain home objects",
        4, this.home.getSelectedItems().size());
   
    // 5. Select the first two pieces
    this.home.setSelectedItems(Arrays.asList(new Selectable [] {firstPiece, secondPiece}));
    float secondPieceX = secondPiece.getX();
    float secondPieceY = secondPiece.getY();
    // Align on bottom
    runAction(HomePane.ActionType.ALIGN_FURNITURE_ON_BOTTOM);
    // Check bottom of second piece equals bottom of first piece
    TestUtilities.assertEqualsWithinEpsilon("Second piece isn't aligned on bottom of first piece",
        getMaxY(firstPiece), getMaxY(secondPiece), 10E-4f);

    // 6. Align on top
    runAction(HomePane.ActionType.ALIGN_FURNITURE_ON_TOP);
    // Check bottom of second piece equals bottom of first piece
    TestUtilities.assertEqualsWithinEpsilon("Second piece isn't aligned on top of first piece",
        getMinY(firstPiece), getMinY(secondPiece), 10E-4f);
   
    // 7. Align on left
    runAction(HomePane.ActionType.ALIGN_FURNITURE_ON_LEFT);
    // Check bottom of second piece equals bottom of first piece
    TestUtilities.assertEqualsWithinEpsilon("Second piece isn't aligned on left of first piece",
        getMinX(firstPiece), getMinX(secondPiece), 10E-4f);
   
    // 8. Align on right
    runAction(HomePane.ActionType.ALIGN_FURNITURE_ON_RIGHT);
    // Check bottom of second piece equals bottom of first piece
    TestUtilities.assertEqualsWithinEpsilon("Second piece isn't aligned on right of first piece",
        getMaxX(firstPiece), getMaxX(secondPiece), 10E-4f);
    float alignedPieceX = secondPiece.getX();
    float alignedPieceY = secondPiece.getY();

    // 9. Undo alignments
    runAction(HomePane.ActionType.UNDO);
    runAction(HomePane.ActionType.UNDO);
    runAction(HomePane.ActionType.UNDO);
    runAction(HomePane.ActionType.UNDO);
    // Check second piece is back to its place
    TestUtilities.assertEqualsWithinEpsilon("Second piece abcissa is incorrect",
        secondPieceX, secondPiece.getX(), 10E-4f);
    TestUtilities.assertEqualsWithinEpsilon("Second piece ordinate is incorrect",
        secondPieceY, secondPiece.getY(), 10E-4f);

    // 10. Redo alignments
    runAction(HomePane.ActionType.REDO);
    runAction(HomePane.ActionType.REDO);
    runAction(HomePane.ActionType.REDO);
    runAction(HomePane.ActionType.REDO);
    // Check second piece is back to its place
    TestUtilities.assertEqualsWithinEpsilon("Second piece abcissa is incorrect",
        alignedPieceX, secondPiece.getX(), 10E-4f);
    TestUtilities.assertEqualsWithinEpsilon("Second piece ordinate is incorrect",
        alignedPieceY, secondPiece.getY(), 10E-4f);
  }
View Full Code Here

Examples of com.eteks.sweethome3d.model.HomePieceOfFurniture

        this.groupFurnitureY = new float [groupFurniture.size()];
        this.groupFurnitureWidth = new float [groupFurniture.size()];
        this.groupFurnitureDepth = new float [groupFurniture.size()];
        this.groupFurnitureHeight = new float [groupFurniture.size()];
        for (int i = 0; i < groupFurniture.size(); i++) {
          HomePieceOfFurniture groupPiece = groupFurniture.get(i);
          this.groupFurnitureX [i] = groupPiece.getX();
          this.groupFurnitureY [i] = groupPiece.getY();
          this.groupFurnitureWidth [i] = groupPiece.getWidth();
          this.groupFurnitureDepth [i] = groupPiece.getDepth();
          this.groupFurnitureHeight [i] = groupPiece.getHeight();
        }
      } else {
        this.groupFurnitureX = null;
        this.groupFurnitureY = null;
        this.groupFurnitureWidth = null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.