Package com.eteks.sweethome3d.model

Examples of com.eteks.sweethome3d.model.HomeFurnitureGroup


    assertEquals("Home doesn't contain 1 piece", 1, pieces.size());
    assertEquals("Home doesn't contain 1 selected item", 1, this.home.getSelectedItems().size());
    assertFalse("Home still contains first added piece", pieces.contains(piece1));
    assertFalse("Home still contains scond added piece", pieces.contains(piece2));
    assertGroupActionsEnabled(false, true);
    HomeFurnitureGroup group = (HomeFurnitureGroup)pieces.get(0);
    // Compare surrounding rectangles
    Rectangle2D piecesRectangle = getSurroundingRectangle(piece1);
    piecesRectangle.add(getSurroundingRectangle(piece2));
    Rectangle2D groupRectangle = getSurroundingRectangle(group);
    assertEquals("Surrounding rectangle is incorrect", piecesRectangle, groupRectangle);
    // Compare elevation and height
    assertEquals("Wrong elevation", Math.min(piece1.getElevation(), piece2.getElevation()), group.getElevation());
    assertEquals("Wrong height",
        Math.max(piece1.getElevation() + piece1.getHeight(), piece2.getElevation() + piece2.getHeight())
        - Math.min(piece1.getElevation(), piece2.getElevation()), group.getHeight());
   
    // 3. Rotate group
    float angle = (float)(Math.PI / 2);
    group.setAngle(angle);
    // Check pieces rotation
    assertEquals("Piece angle is wrong", angle, piece1.getAngle());
    assertEquals("Piece angle is wrong", angle, piece2.getAngle());
    assertEquals("Group angle is wrong", angle, group.getAngle());
    // Check surrounding rectangles
    Rectangle2D rotatedGroupRectangle = new GeneralPath(groupRectangle).createTransformedShape(
        AffineTransform.getRotateInstance(angle, groupRectangle.getCenterX(), groupRectangle.getCenterY())).getBounds2D();
    groupRectangle = getSurroundingRectangle(group);
    assertEquals("Surrounding rectangle is incorrect", rotatedGroupRectangle, groupRectangle);
    piecesRectangle = getSurroundingRectangle(piece1);
    piecesRectangle.add(getSurroundingRectangle(piece2));
    assertEquals("Surrounding rectangle is incorrect", piecesRectangle.getWidth(), groupRectangle.getWidth());
    assertEquals("Surrounding rectangle is incorrect", piecesRectangle.getHeight(), groupRectangle.getHeight());
   
    // 4. Undo / Redo
    assertActionsEnabled(true, true, true, false);
    runAction(HomePane.ActionType.UNDO);
    pieces = this.home.getFurniture();
    assertEquals("Home doesn't contain 2 pieces", 2, pieces.size());
    assertEquals("Home doesn't contain 2 selected items", 2, this.home.getSelectedItems().size());
    assertFalse("Home contains group", pieces.contains(group));
    assertGroupActionsEnabled(true, false);

    assertActionsEnabled(true, true, true, true);
    runAction(HomePane.ActionType.REDO);
    pieces = this.home.getFurniture();
    assertEquals("Home doesn't contain 1 piece", 1, pieces.size());
    assertEquals("Home doesn't contain 1 selected item", 1, this.home.getSelectedItems().size());
    assertTrue("Home doesn't contain group", pieces.contains(group));
    assertGroupActionsEnabled(false, true);
   
    // 5. Add one more piece to home
    catalogPieces = Arrays.asList(new CatalogPieceOfFurniture [] {firstCategory.getFurniture().get(0)});
    this.homeController.getFurnitureCatalogController().setSelectedFurniture(catalogPieces);
    runAction(HomePane.ActionType.ADD_HOME_FURNITURE);
    pieces = this.home.getFurniture();
    // Check home contains two pieces with one selected
    assertEquals("Home doesn't contain 2 pieces", 2, pieces.size());
    assertEquals("Home doesn't contain 1 selected item", 1, this.home.getSelectedItems().size());
    assertGroupActionsEnabled(false, false);
   
    // 6. Group it with the other group
    HomePieceOfFurniture piece3 = pieces.get(1);
    this.home.setSelectedItems(Arrays.asList(new Selectable [] {group, piece3}));
    assertEquals("Home doesn't contain 2 selected items", 2, this.home.getSelectedItems().size());
    assertGroupActionsEnabled(true, true);
    runAction(HomePane.ActionType.GROUP_FURNITURE);
    pieces = this.home.getFurniture();
    assertEquals("Home doesn't contain 1 piece", 1, pieces.size());
    assertEquals("Home doesn't contain 1 selected item", 1, this.home.getSelectedItems().size());
    HomeFurnitureGroup group2 = (HomeFurnitureGroup)pieces.get(0);
    assertFalse("Home doesn't contain a different group", group == group2);
    assertGroupActionsEnabled(false, true);
   
    // 7. Ungroup furniture
    runAction(HomePane.ActionType.UNGROUP_FURNITURE);
View Full Code Here


      }
    }

    public void reset() {
      super.reset();
      HomeFurnitureGroup group = (HomeFurnitureGroup)getPieceOfFurniture();
      List<HomePieceOfFurniture> groupFurniture = getGroupFurniture(group);
      for (int i = 0; i < groupFurniture.size(); i++) {
        HomePieceOfFurniture groupPiece = groupFurniture.get(i);
        if (group.isResizable()) {
          // Restore group furniture location and size because resizing a group isn't reversible
          groupPiece.setX(this.groupFurnitureX [i]);
          groupPiece.setY(this.groupFurnitureY [i]);
          groupPiece.setWidth(this.groupFurnitureWidth [i]);
          groupPiece.setDepth(this.groupFurnitureDepth [i]);
View Full Code Here

        groupPiecesVisible [i++] = pieceEntry.getValue().isVisible();
      }

      String furnitureGroupName = this.preferences.getLocalizedString(
          FurnitureController.class, "groupName", getFurnitureGroupCount(homeFurniture) + 1);
      final HomeFurnitureGroup furnitureGroup = new HomeFurnitureGroup(selectedFurniture, furnitureGroupName);
      final int furnitureGroupIndex = homeFurniture.size() - groupPieces.length;
      final boolean movable = furnitureGroup.isMovable();
     
      doGroupFurniture(groupPieces, new HomeFurnitureGroup [] {furnitureGroup},
          new int [] {furnitureGroupIndex}, basePlanLocked);
      if (this.undoSupport != null) {
        UndoableEdit undoableEdit = new AbstractUndoableEdit() {
            @Override
            public void undo() throws CannotUndoException {
              super.undo();
              doUngroupFurniture(groupPieces, groupPiecesIndex,
                  new HomeFurnitureGroup [] {furnitureGroup}, basePlanLocked);
              for (int i = 0; i < groupPieces.length; i++) {
                groupPieces [i].setMovable(groupPiecesMovable [i]);
                groupPieces [i].setVisible(groupPiecesVisible [i]);
              }
              home.setSelectedItems(oldSelection);
            }
           
            @Override
            public void redo() throws CannotRedoException {
              super.redo();
              doGroupFurniture(groupPieces, new HomeFurnitureGroup [] {furnitureGroup},
                  new int [] {furnitureGroupIndex}, basePlanLocked);
              furnitureGroup.setMovable(movable);
              furnitureGroup.setVisible(true);
            }
           
            @Override
            public String getPresentationName() {
              return preferences.getLocalizedString(FurnitureController.class, "undoGroupName");
View Full Code Here

   */
  public void ungroupSelectedFurniture() {
    List<HomeFurnitureGroup> movableSelectedFurnitureGroups = new ArrayList<HomeFurnitureGroup>();
    for (Selectable item : this.home.getSelectedItems()) {
      if (item instanceof HomeFurnitureGroup) {
        HomeFurnitureGroup group = (HomeFurnitureGroup)item;
        if (isPieceOfFurnitureMovable(group)) {
          movableSelectedFurnitureGroups.add(group);
        }
      }
    } 
View Full Code Here

TOP

Related Classes of com.eteks.sweethome3d.model.HomeFurnitureGroup

Copyright © 2018 www.massapicom. 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.