Skip to content

Commit

Permalink
Use scaling of tangents till curve length is same when as option when…
Browse files Browse the repository at this point in the history
… deleting control point

Fix some dialogs
  • Loading branch information
HavardNJ committed Nov 28, 2021
1 parent 5511cbb commit cf47ae9
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 68 deletions.
65 changes: 35 additions & 30 deletions src/boardcad/commands/BrdDeleteControlPointCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,49 +35,53 @@ public void doAction()
ArrayList<Point2D> points = new ArrayList<Point2D>();

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();
}
Expand Down
5 changes: 3 additions & 2 deletions src/boardcad/commands/BrdEditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/boardcad/gui/jdk/BoardCAD.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/boardcad/gui/jdk/BoardFinsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 20 additions & 20 deletions src/boardcad/gui/jdk/BoardInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());

}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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;
Expand All @@ -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);
}
});
Expand All @@ -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) {
Expand Down
20 changes: 11 additions & 9 deletions src/boardcad/gui/jdk/Machine2DView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

}

Expand Down
2 changes: 1 addition & 1 deletion src/boardcad/gui/jdk/ScaleBoardInputDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/boardcad/gui/jdk/SettingDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
3 changes: 2 additions & 1 deletion src/boardcad/i18n/LanguageResource.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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)
ADJUSTCROSSECTIONTHICKNESS_STR=Adjust cross section thickness (experimental)
USEBEZIERFITONDELETE_STR=Use Bezier curve fitting on delete point
9 changes: 8 additions & 1 deletion src/boardcad/settings/BoardCADSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -590,5 +593,9 @@ public double getBaseLineThickness() {
public boolean getAdjustCrossectionThickness() {
return mMiscSettings.getBoolean(ADJUSTCROSSECTIONTHICKNESS);
}

public boolean isUsingBezierFitOnDelete() {
return mMiscSettings.getBoolean(USEBEZIERFITONDELETE);
}

};

0 comments on commit cf47ae9

Please sign in to comment.