diff --git a/src/boardcad/commands/BrdDeleteControlPointCommand.java b/src/boardcad/commands/BrdDeleteControlPointCommand.java index 88e2a45..48af421 100644 --- a/src/boardcad/commands/BrdDeleteControlPointCommand.java +++ b/src/boardcad/commands/BrdDeleteControlPointCommand.java @@ -5,6 +5,7 @@ import boardcad.gui.jdk.BoardEdit; import boardcad.i18n.LanguageResource; +import boardcad.settings.BoardCADSettings; import cadcore.BezierCurve; import cadcore.BezierFit; import cadcore.BezierKnot; @@ -34,49 +35,53 @@ public void doAction() ArrayList points = new ArrayList(); int steps = 1000; - BezierCurve prevCurve = mControlPoints.getCurve(mIndex-1); - for(int i = 0; i <= steps; i++) - { - double t = (double)i/(double)steps; - points.add(new Point2D.Double(prevCurve.getXValue(t),prevCurve.getYValue(t)) ); - } BezierCurve nextCurve = mControlPoints.getCurve(mIndex); - for(int i = 0; i <= steps; i++) - { - double t = (double)i/(double)steps; - points.add(new Point2D.Double(nextCurve.getXValue(t), nextCurve.getYValue(t)) ); + if(BoardCADSettings.getInstance().isUsingBezierFitOnDelete()) { + for(int i = 0; i <= steps; i++) + { + double t = (double)i/(double)steps; + points.add(new Point2D.Double(prevCurve.getXValue(t),prevCurve.getYValue(t)) ); + } + for(int i = 0; i <= steps; i++) + { + double t = (double)i/(double)steps; + points.add(new Point2D.Double(nextCurve.getXValue(t), nextCurve.getYValue(t)) ); + } } BezierKnot prev = mControlPoints.getControlPoint(mIndex-1); BezierKnot next = mControlPoints.getControlPoint(mIndex+1); mSource.mSelectedControlPoints.remove(mDeletedControlPoint); + + double l = prevCurve.getLength() + nextCurve.getLength(); super.removePoint(mDeletedControlPoint); mControlPoints.remove(mDeletedControlPoint); - - //Pass to bezierFit - BezierFit fitter = new BezierFit(); - Point2D[] ctrlPoints = fitter.bestFit(points); - System.out.printf("prev endpoint: %f, %f\n", prev.getEndPoint().getX(),prev.getEndPoint().getY()); - System.out.printf("prev tangent to next: %f, %f\n", prev.getTangentToNext().getX(),prev.getTangentToNext().getY()); - System.out.printf("next tangent to prev: %f, %f\n", next.getTangentToPrev().getX(),next.getTangentToPrev().getY()); - System.out.printf("next endpoint: %f, %f\n", next.getEndPoint().getX(),next.getEndPoint().getY()); - System.out.printf("ctrlPoints[0]: %f, %f\n", ctrlPoints[0].getX(),ctrlPoints[0].getY()); - System.out.printf("ctrlPoints[1]: %f, %f\n", ctrlPoints[1].getX(),ctrlPoints[1].getY()); - System.out.printf("ctrlPoints[2]: %f, %f\n", ctrlPoints[2].getX(),ctrlPoints[2].getY()); - System.out.printf("ctrlPoints[3]: %f, %f\n", ctrlPoints[3].getX(),ctrlPoints[3].getY()); - - //Update bezier curve - prev.setContinous(false); - prev.setControlPointLocation(ctrlPoints[0].getX(),ctrlPoints[0].getY()); - prev.setTangentToNext(ctrlPoints[1].getX(),ctrlPoints[1].getY()); - next.setContinous(false); - next.setControlPointLocation(ctrlPoints[3].getX(),ctrlPoints[3].getY()); - next.setTangentToPrev(ctrlPoints[2].getX(),ctrlPoints[2].getY()); + if(BoardCADSettings.getInstance().isUsingBezierFitOnDelete()) { + //Pass to bezierFit + BezierFit fitter = new BezierFit(); + Point2D[] ctrlPoints = fitter.bestFit(points); + + //Update bezier curve + prev.setContinous(false); + prev.setControlPointLocation(ctrlPoints[0].getX(),ctrlPoints[0].getY()); + prev.setTangentToNext(ctrlPoints[1].getX(),ctrlPoints[1].getY()); + next.setContinous(false); + next.setControlPointLocation(ctrlPoints[3].getX(),ctrlPoints[3].getY()); + next.setTangentToPrev(ctrlPoints[2].getX(),ctrlPoints[2].getY()); + } else { + for(int i = 0; i < 1000; i++) { + double newLength = prevCurve.getLength(); + if(Math.abs(newLength - l) < 0.1)break; + double factor = l / newLength; + prev.scaleTangentToNext(factor); + next.scaleTangentToPrev(factor); + } + } super.saveChanges(); } diff --git a/src/boardcad/commands/BrdEditCommand.java b/src/boardcad/commands/BrdEditCommand.java index 01a61fa..dd10289 100644 --- a/src/boardcad/commands/BrdEditCommand.java +++ b/src/boardcad/commands/BrdEditCommand.java @@ -191,8 +191,9 @@ public void onLeftMouseButtonPressed(BoardEdit source, MouseEvent event) public void onMouseDragged(BoardEdit source, MouseEvent event) { - if((event.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK) - return; + if((event.getModifiersEx() & MouseEvent.BUTTON3_DOWN_MASK) == MouseEvent.BUTTON3_DOWN_MASK) { + return; + } //Dragging points if(mIsKeyEditing) diff --git a/src/boardcad/gui/jdk/BoardCAD.java b/src/boardcad/gui/jdk/BoardCAD.java index 453db0f..96fa0cb 100644 --- a/src/boardcad/gui/jdk/BoardCAD.java +++ b/src/boardcad/gui/jdk/BoardCAD.java @@ -4211,6 +4211,7 @@ public void actionPerformed(ActionEvent arg0) { BoardInfo dialog = new BoardInfo(getCurrentBrd()); dialog.setModal(true); + dialog.setResizable(false); // dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.setVisible(true); dialog.dispose(); @@ -5518,8 +5519,7 @@ public void mouseMoved(final MouseEvent e) { mQuadViewOutlineEdit.setParentContainer(mQuadView); mQuadViewCrossSectionEdit.setParentContainer(mQuadView); mQuadViewRockerEdit.setParentContainer(mQuadView); - - mQuadViewOutlineEdit.setParentContainer(mQuadView); + mQuadView.add(mQuadViewOutlineEdit); mQuadView.add(mQuadViewCrossSectionEdit); mQuadView.add(mQuadViewRockerEdit); diff --git a/src/boardcad/gui/jdk/BoardFinsDialog.java b/src/boardcad/gui/jdk/BoardFinsDialog.java index 1b3ca85..d38e16f 100644 --- a/src/boardcad/gui/jdk/BoardFinsDialog.java +++ b/src/boardcad/gui/jdk/BoardFinsDialog.java @@ -63,7 +63,7 @@ public BoardFinsDialog(BezierBoard brd) { * */ private void initialize() { - this.setSize(new Dimension(422, 289)); + this.setSize(new Dimension(422, 310)); this.setDefaultCloseOperation(1); this.setLocationRelativeTo(null); this.setResizable(false); diff --git a/src/boardcad/gui/jdk/BoardInfo.java b/src/boardcad/gui/jdk/BoardInfo.java index 9cef1bd..f737d0b 100644 --- a/src/boardcad/gui/jdk/BoardInfo.java +++ b/src/boardcad/gui/jdk/BoardInfo.java @@ -45,14 +45,14 @@ public BoardInfo(BezierBoard brd) { * */ private void initialize() { - this.setSize(new Dimension(464, 400)); + this.setSize(new Dimension(464, 410)); this.setContentPane(getJContentPane()); this.setTitle(LanguageResource.getString("BOARDINFORTITLE_STR")); this.setLocationRelativeTo(null); - getMDesignerTextField().setText(mBrd.getDesigner()); - getMSurferTextField().setText(mBrd.getSurfer()); - getMModelTextField().setText(mBrd.getModel()); - getMCommentsTextField().setText(mBrd.getComments()); + getDesignerTextField().setText(mBrd.getDesigner()); + getSurferTextField().setText(mBrd.getSurfer()); + getModelTextField().setText(mBrd.getModel()); + getCommentsTextField().setText(mBrd.getComments()); } @@ -88,10 +88,10 @@ private JPanel getJContentPane() { jContentPane.add(jLabel1, null); jContentPane.add(jLabel2, null); jContentPane.add(jLabel3, null); - jContentPane.add(getMDesignerTextField(), null); - jContentPane.add(getMSurferTextField(), null); - jContentPane.add(getMModelTextField(), null); - jContentPane.add(getMCommentsTextField(), null); + jContentPane.add(getDesignerTextField(), null); + jContentPane.add(getSurferTextField(), null); + jContentPane.add(getModelTextField(), null); + jContentPane.add(getCommentsTextField(), null); jContentPane.add(getOkButton(), null); jContentPane.add(getCancelButton(), null); } @@ -103,7 +103,7 @@ private JPanel getJContentPane() { * * @return javax.swing.JTextField */ - private JTextField getMDesignerTextField() { + private JTextField getDesignerTextField() { if (mDesignerTextField == null) { mDesignerTextField = new JTextField(); mDesignerTextField.setBounds(new Rectangle(88, 16, 351, 20)); @@ -116,7 +116,7 @@ private JTextField getMDesignerTextField() { * * @return javax.swing.JTextField */ - private JTextField getMSurferTextField() { + private JTextField getSurferTextField() { if (mSurferTextField == null) { mSurferTextField = new JTextField(); mSurferTextField.setBounds(new Rectangle(88, 47, 351, 20)); @@ -129,7 +129,7 @@ private JTextField getMSurferTextField() { * * @return javax.swing.JTextField */ - private JTextField getMModelTextField() { + private JTextField getModelTextField() { if (mModelTextField == null) { mModelTextField = new JTextField(); mModelTextField.setBounds(new Rectangle(88, 78, 351, 20)); @@ -142,10 +142,10 @@ private JTextField getMModelTextField() { * * @return javax.swing.JTextArea */ - private JTextArea getMCommentsTextField() { + private JTextArea getCommentsTextField() { if (mCommentsTextField == null) { mCommentsTextField = new JTextArea(); - mCommentsTextField.setBounds(new Rectangle(23, 127, 407, 198)); + mCommentsTextField.setBounds(new Rectangle(23, 127, 416, 198)); mCommentsTextField.setLineWrap(true); } return mCommentsTextField; @@ -159,14 +159,14 @@ private JTextArea getMCommentsTextField() { private JButton getOkButton() { if (OkButton == null) { OkButton = new JButton(); - OkButton.setBounds(new Rectangle(190, 339, 110, 26)); + OkButton.setBounds(new Rectangle(199, 339, 110, 26)); OkButton.setText(LanguageResource.getString("OKBUTTON_STR")); OkButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { - mBrd.setDesigner(getMDesignerTextField().getText()); - mBrd.setSurfer(getMSurferTextField().getText()); - mBrd.setModel(getMModelTextField().getText()); - mBrd.setComments(getMCommentsTextField().getText()); + mBrd.setDesigner(getDesignerTextField().getText()); + mBrd.setSurfer(getSurferTextField().getText()); + mBrd.setModel(getModelTextField().getText()); + mBrd.setComments(getCommentsTextField().getText()); setVisible(false); } }); @@ -182,7 +182,7 @@ public void actionPerformed(java.awt.event.ActionEvent e) { private JButton getCancelButton() { if (CancelButton == null) { CancelButton = new JButton(); - CancelButton.setBounds(new Rectangle(320, 339, 110, 26)); + CancelButton.setBounds(new Rectangle(329, 339, 110, 26)); CancelButton.setText(LanguageResource.getString("CANCELBUTTON_STR")); CancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { diff --git a/src/boardcad/gui/jdk/Machine2DView.java b/src/boardcad/gui/jdk/Machine2DView.java index ad612c9..fb39cf3 100644 --- a/src/boardcad/gui/jdk/Machine2DView.java +++ b/src/boardcad/gui/jdk/Machine2DView.java @@ -249,12 +249,6 @@ public void paintComponent(Graphics g) { at.setToRotation(blankAngle); g2d.transform(at); - double blankX = (mBrdCoord.x / Math.cos(blankAngle)) - blankOffset.x; - double blankDeckY = -blank.getDeckAtPos(blankX); - double blankBottomY = -blank.getRockerAtPos(blankX); - line.setLine(blankX, blankDeckY * (mShowDeck ? 1 : -1), blankX, blankBottomY * (mShowDeck ? 1 : -1)); - g2d.draw(line); - g2d.setTransform(savedTransform); // Draw cross section of brd @@ -263,9 +257,17 @@ public void paintComponent(Graphics g) { double crsY = getHeight() / 6 + (-boardOffset.z + bottomY + brdX * Math.sin(boardAngle)) * crsScale; BezierBoardDrawUtil.paintSlidingCrossSection(new JavaDraw(g2d), getWidth() / 2, crsY, crsScale, 0.0, Color.RED, crsStroke, false, mShowDeck, brdX, brd); - // Draw cross section blank - double blankCrsY = getHeight() / 6 + (-blankOffset.z + blankBottomY + blankX * Math.sin(blankAngle)) * crsScale; - BezierBoardDrawUtil.paintSlidingCrossSection(new JavaDraw(g2d), getWidth() / 2, blankCrsY, crsScale, 0.0, Color.BLUE, crsStroke, false, mShowDeck, blankX, blank); + if (blank != null && !blank.isEmpty()) { + double blankX = (mBrdCoord.x / Math.cos(blankAngle)) - blankOffset.x; + double blankDeckY = -blank.getDeckAtPos(blankX); + double blankBottomY = -blank.getRockerAtPos(blankX); + line.setLine(blankX, blankDeckY * (mShowDeck ? 1 : -1), blankX, blankBottomY * (mShowDeck ? 1 : -1)); + g2d.draw(line); + + // Draw cross section blank + double blankCrsY = getHeight() / 6 + (-blankOffset.z + blankBottomY + blankX * Math.sin(blankAngle)) * crsScale; + BezierBoardDrawUtil.paintSlidingCrossSection(new JavaDraw(g2d), getWidth() / 2, blankCrsY, crsScale, 0.0, Color.BLUE, crsStroke, false, mShowDeck, blankX, blank); + } } diff --git a/src/boardcad/gui/jdk/ScaleBoardInputDialog.java b/src/boardcad/gui/jdk/ScaleBoardInputDialog.java index 5c007a5..a9d6bcc 100644 --- a/src/boardcad/gui/jdk/ScaleBoardInputDialog.java +++ b/src/boardcad/gui/jdk/ScaleBoardInputDialog.java @@ -65,7 +65,7 @@ public ScaleBoardInputDialog(Frame owner) { * @return void */ private void initialize() { - this.setSize(308, 388); //this.setSize(349, 236); + this.setSize(308, 402); this.setResizable(false); this.setContentPane(getmContentPane ()); this.setLocationRelativeTo(null); diff --git a/src/boardcad/gui/jdk/SettingDialog.java b/src/boardcad/gui/jdk/SettingDialog.java index 040f6b9..040f7e0 100644 --- a/src/boardcad/gui/jdk/SettingDialog.java +++ b/src/boardcad/gui/jdk/SettingDialog.java @@ -24,7 +24,7 @@ public class SettingDialog extends JDialog { this.setTitle(LanguageResource.getString("SETTINGSTITLE_STR")); this.setSize(new Dimension(352, 221)); this.setLayout(new BorderLayout()); - + this.setResizable(false); JButton okButton = new JButton(); okButton.setText(LanguageResource.getString("OKBUTTON_STR")); diff --git a/src/boardcad/i18n/LanguageResource.properties b/src/boardcad/i18n/LanguageResource.properties index 0225ac9..48afa02 100644 --- a/src/boardcad/i18n/LanguageResource.properties +++ b/src/boardcad/i18n/LanguageResource.properties @@ -877,4 +877,5 @@ NUM3DPROCESSES_STR=3D Processes AUTOUPDATE3DMODEL_STR=Auto update 3D model MANUALUPDATE3DMODEL_STR=Manual update RESET3DMODEL_STR=Reset 3D model -ADJUSTCROSSECTIONTHICKNESS_STR=Adjust cross section thickness (experimental) \ No newline at end of file +ADJUSTCROSSECTIONTHICKNESS_STR=Adjust cross section thickness (experimental) +USEBEZIERFITONDELETE_STR=Use Bezier curve fitting on delete point \ No newline at end of file diff --git a/src/boardcad/settings/BoardCADSettings.java b/src/boardcad/settings/BoardCADSettings.java index 77a1c9a..199a9db 100644 --- a/src/boardcad/settings/BoardCADSettings.java +++ b/src/boardcad/settings/BoardCADSettings.java @@ -74,6 +74,7 @@ public class BoardCADSettings extends CategorizedSettings static private final String OFFSETINTERPLOATION = "offsetinterpolation"; static private final String NUM3DPROCESSES = "num3Dprocesses"; static private final String ADJUSTCROSSECTIONTHICKNESS = "adjustcrossectionthickness"; + static private final String USEBEZIERFITONDELETE = "usebezierfitondelete"; static private BoardCADSettings mInstance = null; @@ -205,7 +206,7 @@ public void onSettingChanged(final Setting setting) { looks.put(lookAndFeel.getSimpleName().replace("Substance", "").replace("LookAndFeel",""), lookAndFeel.getName()); } - mMiscSettings.addObject(LOOK_AND_FEEL, mMiscSettings.new PairType("DarkNimbus", looks), + mMiscSettings.addObject(LOOK_AND_FEEL, mMiscSettings.new PairType("Windows", looks), LanguageResource.getString("LOOKANDFEEL_STR"), new Settings.SettingChangedCallback() { @Override public void onSettingChanged(Setting setting) { @@ -268,6 +269,8 @@ public void onSettingChanged(Setting setting) { mMiscSettings.addBoolean(OFFSETINTERPLOATION, true, LanguageResource.getString("OFFSETINTERPLOATION_STR")); mMiscSettings.addInteger(NUM3DPROCESSES, 8, LanguageResource.getString("NUM3DPROCESSES_STR")); + mMiscSettings.addBoolean(USEBEZIERFITONDELETE, false, LanguageResource.getString("USEBEZIERFITONDELETE_STR")); + } public void setDefaultTheme() { @@ -590,5 +593,9 @@ public double getBaseLineThickness() { public boolean getAdjustCrossectionThickness() { return mMiscSettings.getBoolean(ADJUSTCROSSECTIONTHICKNESS); } + + public boolean isUsingBezierFitOnDelete() { + return mMiscSettings.getBoolean(USEBEZIERFITONDELETE); + } };