File size: 5,203 Bytes
a5ffdcd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | /*
* ********************************************************************************
* This file is part of the LibreCAD project, a 2D CAD program
*
* Copyright (C) 2025 LibreCAD.org
* Copyright (C) 2025 sand1024
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* ********************************************************************************
*/
#include "lc_ellipsepropertieseditingwidget.h"
#include "rs_debug.h"
#include "rs_ellipse.h"
#include "ui_lc_ellipsepropertieseditingwidget.h"
LC_EllipsePropertiesEditingWidget::LC_EllipsePropertiesEditingWidget(QWidget *parent)
: LC_EntityPropertiesEditorWidget(parent)
, ui(new Ui::LC_EllipsePropertiesEditingWidget){
ui->setupUi(this);
connect(ui->leCenterX, &QLineEdit::editingFinished, this, &LC_EllipsePropertiesEditingWidget::onCenterEditingFinished);
connect(ui->leCenterY, &QLineEdit::editingFinished, this, &LC_EllipsePropertiesEditingWidget::onCenterEditingFinished);
connect(ui->leMajor, &QLineEdit::editingFinished, this, &LC_EllipsePropertiesEditingWidget::onMajorEditingFinished);
connect(ui->leMinor, &QLineEdit::editingFinished, this, &LC_EllipsePropertiesEditingWidget::onMinorEditingFinished);
connect(ui->leRotation, &QLineEdit::editingFinished, this, &LC_EllipsePropertiesEditingWidget::onRotationEditingFinished);
connect(ui->leAngle1, &QLineEdit::editingFinished, this, &LC_EllipsePropertiesEditingWidget::onAngle1EditingFinished);
connect(ui->leAngle2, &QLineEdit::editingFinished, this, &LC_EllipsePropertiesEditingWidget::onAngle2EditingFinished);
connect(ui->cbReversed, &QCheckBox::toggled, this, &LC_EllipsePropertiesEditingWidget::onReversedToggled);
}
LC_EllipsePropertiesEditingWidget::~LC_EllipsePropertiesEditingWidget(){
delete ui;
}
void LC_EllipsePropertiesEditingWidget::setEntity(RS_Entity* entity) {
m_entity = static_cast<RS_Ellipse*>(entity);
toUI(m_entity->getCenter(), ui->leCenterX, ui->leCenterY);
double majorAxisLen = m_entity->getMajorRadius();
double minorAxisLen = m_entity->getMinorRadius();
toUIValue(majorAxisLen, ui->leMajor);
toUIValue(minorAxisLen, ui->leMinor);
double wcsMajorAngle = m_entity->getMajorP().angle();
toUIAngleDeg(wcsMajorAngle, ui->leRotation);
// fixme - sand - for ellipse arc, internal angles are used (assuming that major angle = 0). Rework this for the consistency over the entire UI - use ucs angle like RS_ARC!!
toUIAngleDegRaw(m_entity->getAngle1(), ui->leAngle1);
toUIAngleDegRaw(m_entity->getAngle2(), ui->leAngle2);
toUIBool(m_entity->isReversed(), ui->cbReversed);
}
void LC_EllipsePropertiesEditingWidget::onCenterEditingFinished() {
m_entity->setCenter(toWCS(ui->leCenterX, ui->leCenterY, m_entity->getCenter()));
}
bool LC_EllipsePropertiesEditingWidget::updateEllipseGeometry() {
double major = toWCSValue(ui->leMajor, m_entity->getMajorRadius());
if (major < RS_TOLERANCE) {
LC_ERR << __func__<<"(): invalid ellipse major radius: "<< major<<", ellipse not modified";
return true;
}
double minor = toWCSValue(ui->leMinor, m_entity->getMinorRadius());
double rotation = toWCSAngle(ui->leRotation, m_entity->getMajorP().angle());
m_entity->setMajorP(RS_Vector::polar(major, rotation));
m_entity->setRatio(minor/major);
return false;
}
void LC_EllipsePropertiesEditingWidget::onMajorEditingFinished() {
updateEllipseGeometry();
}
void LC_EllipsePropertiesEditingWidget::onMinorEditingFinished() {
updateEllipseGeometry();
}
void LC_EllipsePropertiesEditingWidget::onRotationEditingFinished() {
updateEllipseGeometry();
}
void LC_EllipsePropertiesEditingWidget::onAngle1EditingFinished() {
toRawAngleValue(ui->leAngle1, m_entity->getAngle1());
}
void LC_EllipsePropertiesEditingWidget::onAngle2EditingFinished() {
toRawAngleValue(ui->leAngle1, m_entity->getAngle1());
}
void LC_EllipsePropertiesEditingWidget::onReversedToggled([[maybe_unused]]bool checked) {
m_entity->setReversed(ui->cbReversed->isChecked());
}
void LC_EllipsePropertiesEditingWidget::setupInteractiveInputWidgets() {
pickPointSetup(ui->wPickPointCenter, "center", ui->leCenterX, ui->leCenterY);
pickDistanceSetup(ui->tbPickMajor, "major", ui->leMajor);
pickDistanceSetup(ui->tbPickMajor, "minor", ui->leMinor);
pickAngleSetup(ui->tbPickRotation, "rotation", ui->leRotation);
pickAngleSetup(ui->tbPickStartAngle, "angle1", ui->leAngle1);
pickAngleSetup(ui->tbPickEndAngle, "angle2", ui->leAngle2);
}
|