Package com.eteks.sweethome3d.model

Examples of com.eteks.sweethome3d.model.Wall


    Locale.setDefault(Locale.FRANCE);
    UserPreferences preferences = new DefaultUserPreferences();
    ViewFactory viewFactory = new SwingViewFactory();
    // Create a home and add a selected wall to it
    Home home = new Home();
    Wall wall1 = new Wall(0.1f, 0.2f, 100.1f, 100.2f, 7.5f);
    home.addWall(wall1);
    wall1.setLeftSideColor(10);
    wall1.setRightSideColor(20);
    home.setSelectedItems(Arrays.asList(new Wall [] {wall1}));
   
    // 2. Create a wall panel to edit the selected wall
    WallController wallController = new WallController(home, preferences, viewFactory, null, null);
    // Check values stored by wall panel components are equal to the ones set
    assertWallControllerEquals(wall1.getXStart(), wall1.getYStart(),
        wall1.getXEnd(), wall1.getYEnd(),
        (float)Point2D.distance(wall1.getXStart(), wall1.getYStart(),
            wall1.getXEnd(), wall1.getYEnd()),
        wall1.getThickness(), home.getWallHeight(), wall1.getHeightAtEnd(),
        wall1.getLeftSideColor(), wall1.getLeftSideTexture(),
        wall1.getRightSideColor(), wall1.getRightSideTexture(), wallController);   
    // 3. Modify wall right side texture with first available texture
    TextureImage firstTexture = preferences.getTexturesCatalog().getCategories().get(0).getTexture(0);
    wall1.setRightSideColor(null);
    wall1.setRightSideTexture(new HomeTexture(firstTexture));
    wallController = new WallController(home, preferences, viewFactory, null, null);
    assertWallControllerEquals(wall1.getXStart(), wall1.getYStart(),
        wall1.getXEnd(), wall1.getYEnd(),
        (float)Point2D.distance(wall1.getXStart(), wall1.getYStart(),
            wall1.getXEnd(), wall1.getYEnd()),
        wall1.getThickness(), home.getWallHeight(), wall1.getHeightAtEnd(),
        wall1.getLeftSideColor(), wall1.getLeftSideTexture(),
        null, wall1.getRightSideTexture(), wallController);
   
    // 4. Increase length in dialog
    DialogView wallView = wallController.getView();
    JSpinner distanceToEndPointSpinner =
        (JSpinner)TestUtilities.getField(wallView, "distanceToEndPointSpinner");
    distanceToEndPointSpinner.setValue((Float)distanceToEndPointSpinner.getValue() + 20f);
    // Check wall end coordinates changed accordingly
    assertTrue("Wrong X end", Math.abs(wall1.getXEnd() + 20f * (float)Math.cos(Math.PI / 4) - wallController.getXEnd()) < 1E-5);
    assertTrue("Wrong Y end", Math.abs(wall1.getYEnd() + 20f * (float)Math.sin(Math.PI / 4) - wallController.getYEnd()) < 1E-5);
   
    // 5. Add a second selected wall to home
    Wall wall2 = new Wall(0.1f, 0.3f, 200.1f, 200.2f, 5f);
    home.addWall(wall2);
    wall2.setHeight(300f);
    wall2.setLeftSideColor(10);
    wall2.setRightSideColor(50);
    home.setSelectedItems(Arrays.asList(new Wall [] {wall1, wall2}));
    // Check if wall panel edits null values if walls thickness or colors are the same
    wallController = new WallController(home, preferences, viewFactory, null, null);
    // Check values stored by furniture panel components are equal to the ones set
    assertWallControllerEquals(0.1f, null, null,
View Full Code Here


  }

  public static void main(String [] args) {
    // Create a selected wall in a home and display it in a wall panel
    Home home = new Home();
    Wall wall1 = new Wall(0.1f, 0.2f, 100.1f, 100.2f, 7.5f);
    home.addWall(wall1);
    wall1.setLeftSideColor(null);
    wall1.setRightSideColor(0xFFFF00);
    home.setSelectedItems(Arrays.asList(new Wall [] {wall1}));
   
    DefaultUserPreferences preferences = new DefaultUserPreferences();
    new WallController(home, preferences,
          new SwingViewFactory(), new FileContentManager(preferences), null).displayView(null);
View Full Code Here

    runAction(controller, HomePane.ActionType.SELECT);
    // Check two walls were created and selected
    assertEquals("Wrong wall count in home", 2, home.getWalls().size());
    assertEquals("Wrong selected items count in home", 2, home.getSelectedItems().size());
    Iterator<Wall> iterator = home.getWalls().iterator();
    Wall wall1 = iterator.next();
    Wall wall2 = iterator.next();
    // Check walls don't use texture yet
    assertNull("Wrong texture on wall 1 left side", wall1.getLeftSideTexture());
    assertNull("Wrong texture on wall 2 left side", wall2.getLeftSideTexture());
    assertNull("Wrong texture on wall 1 right side", wall1.getRightSideTexture());
    assertNull("Wrong texture on wall 2 right side", wall2.getRightSideTexture());
   
    // 3. Edit walls
    JDialog attributesDialog = showWallPanel(preferences, controller, frame, tester);
    // Retrieve WallPanel components
    WallPanel wallPanel = (WallPanel)TestUtilities.findComponent(
        attributesDialog, WallPanel.class);
    JSpinner xStartSpinner =
        (JSpinner)TestUtilities.getField(wallPanel, "xStartSpinner");
    JSpinner xEndSpinner =
        (JSpinner)TestUtilities.getField(wallPanel, "xEndSpinner");
    TextureChoiceComponent rightSideTextureComponent =
        (TextureChoiceComponent)TestUtilities.getField(wallPanel, "rightSideTextureComponent");
    // Check xStartSpinner and xEndSpinner panels aren't visible
    assertFalse("X start spinner panel is visible", xStartSpinner.getParent().isVisible());
    assertFalse("X end spinner panel is visible", xEndSpinner.getParent().isVisible());
    // Edit right side texture
    JDialog textureDialog = showTexturePanel(preferences, rightSideTextureComponent, false, attributesDialog, tester);
    JList availableTexturesList = (JList)new BasicFinder().find(textureDialog,
        new ClassMatcher(JList.class, true));
    int textureCount = availableTexturesList.getModel().getSize();
    CatalogTexture defaultTexture = (CatalogTexture)availableTexturesList.getSelectedValue();
    // Import texture
    JDialog textureWizardDialog = showImportTextureWizard(preferences, frame, tester, false);   
    // Retrieve ImportedFurnitureWizardStepsPanel components
    ImportedTextureWizardStepsPanel panel = (ImportedTextureWizardStepsPanel)TestUtilities.findComponent(
        textureWizardDialog, ImportedTextureWizardStepsPanel.class);
    final JButton imageChoiceOrChangeButton = (JButton)TestUtilities.getField(panel, "imageChoiceOrChangeButton");
    final JTextField nameTextField = (JTextField)TestUtilities.getField(panel, "nameTextField");
    JComboBox categoryComboBox = (JComboBox)TestUtilities.getField(panel, "categoryComboBox");
    JSpinner widthSpinner = (JSpinner)TestUtilities.getField(panel, "widthSpinner");
    JSpinner heightSpinner = (JSpinner)TestUtilities.getField(panel, "heightSpinner");
   
    // Check current step is image
    tester.waitForIdle();
    assertStepShowing(panel, true, false);   
    WizardPane view = (WizardPane)TestUtilities.findComponent(textureWizardDialog, WizardPane.class);
    // Check wizard view next button is disabled
    final JButton nextFinishOptionButton = (JButton)TestUtilities.getField(view, "nextFinishOptionButton");
    assertFalse("Next button is enabled", nextFinishOptionButton.isEnabled());
   
    // 4. Choose tested image
    String imageChoiceOrChangeButtonText = imageChoiceOrChangeButton.getText();
    tester.invokeAndWait(new Runnable() {
        public void run() {
          imageChoiceOrChangeButton.doClick();
        }
      });
    // Wait 200 ms to let time to Java to load the image
    Thread.sleep(200);
    // Check choice button text changed
    assertFalse("Choice button text didn't change",
        imageChoiceOrChangeButtonText.equals(imageChoiceOrChangeButton.getText()));
    // Click on next button
    tester.invokeAndWait(new Runnable() {
        public void run() {
          nextFinishOptionButton.doClick();
        }
      });
    // Check current step is attributes
    assertStepShowing(panel, false, true);

    // 5. Check default furniture name is the presentation name proposed by content manager
    assertEquals("Wrong default name",
        contentManager.getPresentationName(testedImageName.toString(), ContentManager.ContentType.IMAGE),
        nameTextField.getText());
    // Check name text field has focus
    assertSame("Name text field doesn't have focus", nameTextField,
        KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());   
    // Check default category is user category 
    String userCategoryName = preferences.getLocalizedString(
        ImportedTextureWizardStepsPanel.class, "userCategory");
    assertEquals("Wrong default category", userCategoryName,
        ((TexturesCategory)categoryComboBox.getSelectedItem()).getName());
    // Rename texture 
    final String textureTestName = "#@" + System.currentTimeMillis() + "@#";
    tester.invokeAndWait(new Runnable() {
      public void run() {
        nameTextField.setText(textureTestName);   
      }
    });
    // Check next button is enabled again
    assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());

    // 6. Change width with a value 5 times greater
    float width = (Float)widthSpinner.getValue();
    float height = (Float)heightSpinner.getValue();
    widthSpinner.setValue(width * 5);
    // Check height is 5 times greater
    float newWidth = (Float)widthSpinner.getValue();
    float newHeight = (Float)heightSpinner.getValue();
    assertEquals("width", 5 * width, newWidth);
    assertEquals("height", 5 * height, newHeight);
   
    tester.invokeAndWait(new Runnable() {
        public void run() {
          // Click on Finish to hide dialog box in Event Dispatch Thread
          nextFinishOptionButton.doClick();
        }
      });
    assertFalse("Import texture wizard still showing", textureWizardDialog.isShowing());

    // Check the list of available textures has one more selected modifiable texture
    assertEquals("Wrong texture count in list", textureCount + 1, availableTexturesList.getModel().getSize());
    assertEquals("No selected texture in list", 1, availableTexturesList.getSelectedValues().length);
    CatalogTexture importedTexture = (CatalogTexture)availableTexturesList.getSelectedValue();
    assertNotSame("Wrong selected texture in list", defaultTexture, importedTexture);
    // Check the attributes of the new texture
    assertEquals("Wrong name", textureTestName, importedTexture.getName());
    assertEquals("Wrong category", userCategoryName, importedTexture.getCategory().getName());
    assertEquals("Wrong width", newWidth, importedTexture.getWidth());
    assertEquals("Wrong height", newHeight, importedTexture.getHeight());
    assertTrue("New texture isn't modifiable", importedTexture.isModifiable());
       
    // 7. Click on OK in texture dialog box
    doClickOnOkInDialog(textureDialog, tester);
    // Click on OK in wall dialog box
    doClickOnOkInDialog(attributesDialog, tester);   
    // Check wall attributes are modified accordingly
    assertNull("Wrong texture on wall 1 left side", wall1.getLeftSideTexture());
    assertNull("Wrong texture on wall 2 left side", wall2.getLeftSideTexture());
    assertEquals("Wrong texture on wall 1 right side", textureTestName, wall1.getRightSideTexture().getName());
    assertEquals("Wrong texture on wall 2 right side", textureTestName, wall2.getRightSideTexture().getName());
   
    // 8. Edit left side texture of first wall
    home.setSelectedItems(Arrays.asList(wall1));
    assertEquals("Wrong selected items count in home", 1, home.getSelectedItems().size());
    attributesDialog = showWallPanel(preferences, controller, frame, tester);
    // Retrieve WallPanel components
    wallPanel = (WallPanel)TestUtilities.findComponent(attributesDialog, WallPanel.class);
    xStartSpinner = (JSpinner)TestUtilities.getField(wallPanel, "xStartSpinner");
    xEndSpinner = (JSpinner)TestUtilities.getField(wallPanel, "xEndSpinner");
    TextureChoiceComponent leftSideTextureComponent =
        (TextureChoiceComponent)TestUtilities.getField(wallPanel, "leftSideTextureComponent");
    // Check xStartSpinner and xEndSpinner panels are visible
    assertTrue("X start spinner panel isn't visible", xStartSpinner.getParent().isVisible());
    assertTrue("X end spinner panel isn't visible", xEndSpinner.getParent().isVisible());
    // Edit left side texture
    textureDialog = showTexturePanel(preferences, leftSideTextureComponent, true, attributesDialog, tester);
    availableTexturesList = (JList)new BasicFinder().find(textureDialog,
        new ClassMatcher(JList.class, true));
    textureCount = availableTexturesList.getModel().getSize();
    // Select imported texture
    availableTexturesList.setSelectedValue(importedTexture, true);
    // Modify texture
    textureWizardDialog = showImportTextureWizard(preferences, frame, tester, true);   
    // Retrieve ImportedFurnitureWizardStepsPanel components
    panel = (ImportedTextureWizardStepsPanel)TestUtilities.findComponent(
        textureWizardDialog, ImportedTextureWizardStepsPanel.class);
    widthSpinner = (JSpinner)TestUtilities.getField(panel, "widthSpinner");
    final JButton nextFinishOptionButton2 = (JButton)TestUtilities.getField(
        TestUtilities.findComponent(textureWizardDialog, WizardPane.class), "nextFinishOptionButton");
    tester.invokeAndWait(new Runnable() {
        public void run() {
          nextFinishOptionButton2.doClick();
        }
      });
   
    // Change width
    widthSpinner.setValue((Float)widthSpinner.getValue() * 2);
    newWidth = (Float)widthSpinner.getValue();
    tester.invokeAndWait(new Runnable() {
        public void run() {
          // Click on Finish to hide dialog box in Event Dispatch Thread
          nextFinishOptionButton2.doClick();
        }
      });
    tester.waitForIdle();
    assertFalse("Import texture wizard still showing", textureWizardDialog.isShowing());
    // Check the list of available textures has the same texture count
    // and a new selected texture
    assertEquals("Wrong texture count in list", textureCount, availableTexturesList.getModel().getSize());
    assertEquals("No selected texture in list", 1, availableTexturesList.getSelectedValues().length);
    CatalogTexture modifiedTexture = (CatalogTexture)availableTexturesList.getSelectedValue();
    assertNotSame("Wrong selected texture in list", importedTexture, modifiedTexture);
    // Check the attributes of the new texture
    assertEquals("Wrong name", textureTestName, modifiedTexture.getName());
    assertEquals("Wrong category", userCategoryName, modifiedTexture.getCategory().getName());
    assertEquals("Wrong width", newWidth, modifiedTexture.getWidth());
    assertTrue("New texture isn't modifiable", modifiedTexture.isModifiable());

    // 9. Click on OK in texture dialog box
    doClickOnOkInDialog(textureDialog, tester);
    // Click on OK in wall dialog box
    doClickOnOkInDialog(attributesDialog, tester);   
    // Check wall attributes are modified accordingly
    assertEquals("Wrong texture on wall 1 left side", newWidth, wall1.getLeftSideTexture().getWidth());
    assertNull("Wrong texture on wall 2 left side", wall2.getLeftSideTexture());
    assertEquals("Wrong texture on wall 1 right side", newWidth / 2, wall1.getRightSideTexture().getWidth());
    assertEquals("Wrong texture on wall 2 right side", newWidth / 2, wall2.getRightSideTexture().getWidth());
   
    // 10. Open wall dialog a last time to delete the modified texture
    attributesDialog = showWallPanel(preferences, controller, frame, tester);
    // Retrieve WallPanel components
    wallPanel = (WallPanel)TestUtilities.findComponent(attributesDialog, WallPanel.class);
    leftSideTextureComponent = (TextureChoiceComponent)TestUtilities.getField(wallPanel, "leftSideTextureComponent");
    // Edit left side texture
    textureDialog = showTexturePanel(preferences, leftSideTextureComponent, true, attributesDialog, tester);
    availableTexturesList = (JList)new BasicFinder().find(textureDialog,
        new ClassMatcher(JList.class, true));
    textureCount = availableTexturesList.getModel().getSize();
    // Select modified texture
    availableTexturesList.setSelectedValue(modifiedTexture, true);
    final JButton deleteButton = (JButton)new BasicFinder().find(textureDialog,
        new Matcher() {
          public boolean matches(Component c) {
            return c instanceof JButton && ((JButton)c).getText().equals(preferences.getLocalizedString(
                TextureChoiceComponent.class, "deleteTextureButton.text"));
          }
        });
    tester.invokeAndWait(new Runnable() {
        public void run() {
          // Display confirm dialog box later in Event Dispatch Thread to avoid blocking test thread
          deleteButton.doClick();       
        }
      });
    tester.waitForIdle();
    // Wait for confirm dialog to be shown
    final String confirmDeleteSelectedCatalogTextureDialogTitle = preferences.getLocalizedString(
        TextureChoiceComponent.class, "confirmDeleteSelectedCatalogTexture.title");
    tester.waitForFrameShowing(new AWTHierarchy(), confirmDeleteSelectedCatalogTextureDialogTitle);
    // Check dialog box is displayed
    JDialog confirmDialog = (JDialog)new BasicFinder().find(textureDialog, 
        new Matcher() {
            public boolean matches(Component c) {
              return c instanceof JDialog && ((JDialog)c).getTitle().equals(
                  confirmDeleteSelectedCatalogTextureDialogTitle);
            }
          });
    assertTrue("Confirm dialog not showing", confirmDialog.isShowing());
    doClickOnOkInDialog(confirmDialog, tester);
    tester.waitForIdle();
    // Check the list of available textures has one less texture and no selected texture
    assertEquals("Wrong texture count in list", textureCount - 1, availableTexturesList.getModel().getSize());
    assertEquals("No selected texture in list", 0, availableTexturesList.getSelectedValues().length);
    // Check delete button is disabled
    assertFalse("Delete button isn't disabled", deleteButton.isEnabled());
    // Click on OK in texture dialog box
    doClickOnOkInDialog(textureDialog, tester);
    // Click on OK in wall dialog box
    doClickOnOkInDialog(attributesDialog, tester);   
    // Check wall attributes didn't change
    assertNotNull("Wrong texture on wall 1 left side", wall1.getLeftSideTexture());
    assertNull("Wrong texture on wall 2 left side", wall2.getLeftSideTexture());
    assertNotNull("Wrong texture on wall 1 right side", wall1.getRightSideTexture());
    assertNotNull("Wrong texture on wall 2 right side", wall2.getRightSideTexture());
  }
View Full Code Here

      wall.setYEnd(yStart);
      if (wall.getArcExtent() != null) {
        wall.setArcExtent(-wall.getArcExtent());
      }

      Wall wallAtStart = wall.getWallAtStart();           
      boolean joinedAtEndOfWallAtStart =
        wallAtStart != null
        && wallAtStart.getWallAtEnd() == wall;
      boolean joinedAtStartOfWallAtStart =
        wallAtStart != null
        && wallAtStart.getWallAtStart() == wall;
      Wall wallAtEnd = wall.getWallAtEnd();     
      boolean joinedAtEndOfWallAtEnd =
        wallAtEnd != null
        && wallAtEnd.getWallAtEnd() == wall;
      boolean joinedAtStartOfWallAtEnd =
        wallAtEnd != null
        && wallAtEnd.getWallAtStart() == wall;
     
      wall.setWallAtStart(wallAtEnd);
      wall.setWallAtEnd(wallAtStart);
     
      if (joinedAtEndOfWallAtStart) {
        wallAtStart.setWallAtEnd(wall);
      } else if (joinedAtStartOfWallAtStart) {
        wallAtStart.setWallAtStart(wall);
      }
     
      if (joinedAtEndOfWallAtEnd) {
        wallAtEnd.setWallAtEnd(wall);
      } else if (joinedAtStartOfWallAtEnd) {
        wallAtEnd.setWallAtStart(wall);
      }
     
      Integer rightSideColor = wall.getRightSideColor();
      HomeTexture rightSideTexture = wall.getRightSideTexture();
      float leftSideShininess = wall.getLeftSideShininess();
View Full Code Here

  public void splitSelectedWall() {
    List<Selectable> selectedItems = this.home.getSelectedItems();
    List<Wall> selectedWalls = Home.getWallsSubList(selectedItems);
    if (selectedWalls.size() == 1) {
      boolean basePlanLocked = this.home.isBasePlanLocked();
      Wall splitWall = selectedWalls.get(0);
      JoinedWall splitJoinedWall = new JoinedWall(splitWall);
      float xStart = splitWall.getXStart();
      float yStart = splitWall.getYStart();
      float xEnd = splitWall.getXEnd();
      float yEnd = splitWall.getYEnd();
      float xMiddle = (xStart + xEnd) / 2;
      float yMiddle = (yStart + yEnd) / 2;

      Wall wallAtStart = splitWall.getWallAtStart();           
      boolean joinedAtEndOfWallAtStart =
        wallAtStart != null
        && wallAtStart.getWallAtEnd() == splitWall;
      boolean joinedAtStartOfWallAtStart =
        wallAtStart != null
        && wallAtStart.getWallAtStart() == splitWall;
      Wall wallAtEnd = splitWall.getWallAtEnd();     
      boolean joinedAtEndOfWallAtEnd =
        wallAtEnd != null
        && wallAtEnd.getWallAtEnd() == splitWall;
      boolean joinedAtStartOfWallAtEnd =
        wallAtEnd != null
        && wallAtEnd.getWallAtStart() == splitWall;

      // Clone new walls to copy their characteristics
      Wall firstWall = splitWall.clone();
      this.home.addWall(firstWall);
      Wall secondWall = splitWall.clone();
      this.home.addWall(secondWall);
     
      // Change split walls end and start point
      firstWall.setXEnd(xMiddle);
      firstWall.setYEnd(yMiddle);
      secondWall.setXStart(xMiddle);
      secondWall.setYStart(yMiddle);
      if (splitWall.getHeightAtEnd() != null) {
        Float heightAtMiddle = (splitWall.getHeight() + splitWall.getHeightAtEnd()) / 2;
        firstWall.setHeightAtEnd(heightAtMiddle);
        secondWall.setHeight(heightAtMiddle);
      }
           
      firstWall.setWallAtEnd(secondWall);
      secondWall.setWallAtStart(firstWall);
     
      firstWall.setWallAtStart(wallAtStart);
      if (joinedAtEndOfWallAtStart) {
        wallAtStart.setWallAtEnd(firstWall);
      } else if (joinedAtStartOfWallAtStart) {
        wallAtStart.setWallAtStart(firstWall);
      }
     
      secondWall.setWallAtEnd(wallAtEnd);
      if (joinedAtEndOfWallAtEnd) {
        wallAtEnd.setWallAtEnd(secondWall);
      } else if (joinedAtStartOfWallAtEnd) {
        wallAtEnd.setWallAtStart(secondWall);
      }
View Full Code Here

   * Attempts to move and resize <code>piece</code> depending on the wall under the
   * point (<code>x</code>, <code>y</code>) and returns that wall it it exists.
   * @see #adjustMagnetizedPieceOfFurniture(HomePieceOfFurniture, float, float)
   */
  private Wall adjustPieceOfFurnitureOnWallAt(HomePieceOfFurniture piece, float x, float y) {
    Wall wallAtPoint = null;
    // Search if point (x, y) is contained in home walls with no margin
    for (Wall wall : this.home.getWalls()) {
      if (wall.getArcExtent() == null
          && wall.containsPoint(x, y, 0)
          && wall.getStartPointToEndPointDistance() > 0) {
        wallAtPoint = wall;
        break;
      }
    }
    if (wallAtPoint == null) {
      float margin = PIXEL_MARGIN / getScale();
      // If not found search if point (x, y) is contained in home walls with a margin
      for (Wall wall : this.home.getWalls()) {
        if (wall.getArcExtent() == null
            && wall.containsPoint(x, y, margin)
            && wall.getStartPointToEndPointDistance() > 0) {
          wallAtPoint = wall;
          break;
        }
      }
    }

    if (wallAtPoint != null) {     
      double wallAngle = Math.atan2(wallAtPoint.getYEnd() - wallAtPoint.getYStart(),
          wallAtPoint.getXEnd() - wallAtPoint.getXStart());
      boolean magnetizedAtRight = wallAngle > -Math.PI / 2 && wallAngle <= Math.PI / 2;
      double cosAngle = Math.cos(wallAngle);
      double sinAngle = Math.sin(wallAngle);
      float [][] wallPoints = wallAtPoint.getPoints();
      double distanceToLeftSide = Line2D.ptLineDist(
          wallPoints [0][0], wallPoints [0][1], wallPoints [1][0], wallPoints [1][1], x, y);
      double distanceToRightSide = Line2D.ptLineDist(
          wallPoints [2][0], wallPoints [2][1], wallPoints [3][0], wallPoints [3][1], x, y);
     
      float [][] piecePoints = piece.getPoints();
      float pieceAngle = piece.getAngle();
      double distanceToPieceLeftSide = Line2D.ptLineDist(
          piecePoints [0][0], piecePoints [0][1], piecePoints [3][0], piecePoints [3][1], x, y);
      double distanceToPieceRightSide = Line2D.ptLineDist(
          piecePoints [1][0], piecePoints [1][1], piecePoints [2][0], piecePoints [2][1], x, y);
      double distanceToPieceSide = pieceAngle > (3 * Math.PI / 2 + 1E-6) || pieceAngle < (Math.PI / 2 + 1E-6)
          ? distanceToPieceLeftSide
          : distanceToPieceRightSide;
     
      double angle;
      double xPiece;
      double yPiece;
      float halfWidth = piece.getWidth() / 2;
      final float thicknessEpsilon = 0.0002f;
      if (piece.isDoorOrWindow()) {
        float wallDistance = thicknessEpsilon / 2;
        if (piece instanceof HomeDoorOrWindow) {
          HomeDoorOrWindow doorOrWindow = (HomeDoorOrWindow) piece;
          if (piece.isResizable()
              && isItemResizable(piece)) {
            piece.setDepth(thicknessEpsilon
                + wallAtPoint.getThickness() / doorOrWindow.getWallThickness());
          }
          wallDistance += piece.getDepth() * doorOrWindow.getWallDistance();          
        }
        float halfDepth = piece.getDepth() / 2;
        if (distanceToRightSide < distanceToLeftSide) {
View Full Code Here

  protected Wall createWall(float xStart, float yStart,
                            float xEnd, float yEnd,
                            Wall wallStartAtStart,
                            Wall wallEndAtStart) {
    // Create a new wall
    Wall newWall = new Wall(xStart, yStart, xEnd, yEnd,
        this.preferences.getNewWallThickness(),
        this.preferences.getNewWallHeight());
    this.home.addWall(newWall);
    if (wallStartAtStart != null) {
      newWall.setWallAtStart(wallStartAtStart);
      wallStartAtStart.setWallAtStart(newWall);
    } else if (wallEndAtStart != null) {
      newWall.setWallAtStart(wallEndAtStart);
      wallEndAtStart.setWallAtEnd(newWall);
    }       
    return newWall;
  }
View Full Code Here

  private Wall getResizedWallStartAt(float x, float y) {
    List<Selectable> selectedItems = this.home.getSelectedItems();
    if (selectedItems.size() == 1
        && selectedItems.get(0) instanceof Wall
        && isItemResizable(selectedItems.get(0))) {
      Wall wall = (Wall)selectedItems.get(0);
      float margin = PIXEL_MARGIN / getScale();
      if (wall.containsWallStartAt(x, y, margin)) {
        return wall;
      }
    }
    return null;
  }
View Full Code Here

  private Wall getResizedWallEndAt(float x, float y) {
    List<Selectable> selectedItems = this.home.getSelectedItems();
    if (selectedItems.size() == 1
        && selectedItems.get(0) instanceof Wall
        && isItemResizable(selectedItems.get(0))) {
      Wall wall = (Wall)selectedItems.get(0);
      float margin = PIXEL_MARGIN / getScale();
      if (wall.containsWallEndAt(x, y, margin)) {
        return wall;
      }
    }
    return null;
  }
View Full Code Here

   * Moves <code>items</code> of (<code>dx</code>, <code>dy</code>) units.
   */
  public void moveItems(List<? extends Selectable> items, float dx, float dy) {
    for (Selectable item : items) {
      if (item instanceof Wall) {
        Wall wall = (Wall)item;
        moveWallStartPoint(wall,
            wall.getXStart() + dx, wall.getYStart() + dy,
            !items.contains(wall.getWallAtStart()));
        moveWallEndPoint(wall,
            wall.getXEnd() + dx, wall.getYEnd() + dy,
            !items.contains(wall.getWallAtEnd()));
      } else {
        item.move(dx, dy);
      }
    }
  }
View Full Code Here

TOP

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

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.