TechDraw: Enable setting a custom direction. Fixes #5821
This commit is contained in:
@@ -1219,6 +1219,11 @@ void DrawProjGroup::spin(const std::string& spindirection)
|
||||
if (spindirection == "CCW")
|
||||
angle = -M_PI / 2.0;// Top -> Left -> Bottom -> Right -> Top
|
||||
|
||||
spin(angle);
|
||||
}
|
||||
|
||||
void DrawProjGroup::spin(double angle)
|
||||
{
|
||||
DrawProjGroupItem* anchor = getAnchor();
|
||||
Base::Vector3d org(0.0, 0.0, 0.0);
|
||||
Base::Vector3d curRot = anchor->getXDirection();
|
||||
|
||||
@@ -129,6 +129,7 @@ public:
|
||||
|
||||
void rotate(const std::string &rotationdirection);
|
||||
void spin(const std::string &spindirection);
|
||||
void spin(double angle);
|
||||
|
||||
void dumpISO(const char * title);
|
||||
std::vector<DrawProjGroupItem*> getViewsAsDPGI();
|
||||
|
||||
@@ -1289,6 +1289,11 @@ void DrawViewPart::spin(const std::string& spindirection)
|
||||
if (spindirection == "CCW")
|
||||
angle = -M_PI / 2.0;// Top -> Left -> Bottom -> Right -> Top
|
||||
|
||||
spin(angle);
|
||||
}
|
||||
|
||||
void DrawViewPart::spin(double angle)
|
||||
{
|
||||
Base::Vector3d org(0.0, 0.0, 0.0);
|
||||
Base::Vector3d curRot = getXDirection();
|
||||
Base::Vector3d curDir = Direction.getValue();
|
||||
|
||||
@@ -174,6 +174,7 @@ public:
|
||||
|
||||
void rotate(const std::string& rotationdirection);
|
||||
void spin(const std::string& spindirection);
|
||||
void spin(double val);
|
||||
std::pair<Base::Vector3d, Base::Vector3d> getDirsFromFront(std::string viewType);
|
||||
Base::Vector3d dir2vec(gp_Dir d);
|
||||
|
||||
|
||||
@@ -25,8 +25,20 @@
|
||||
#ifndef _PreComp_
|
||||
# include <cmath>
|
||||
# include <QMessageBox>
|
||||
# include <QGroupBox>
|
||||
# include <QVBoxLayout>
|
||||
# include <QHBoxLayout>
|
||||
# include <QLabel>
|
||||
# include <QPushButton>
|
||||
# include <QDialog>
|
||||
# include <QScreen>
|
||||
#endif // #ifndef _PreComp_
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QDialog>
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Tools.h>
|
||||
@@ -35,6 +47,7 @@
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/WaitCursor.h>
|
||||
#include <Gui/QuantitySpinBox.h>
|
||||
|
||||
#include <Mod/TechDraw/App/DrawPage.h>
|
||||
#include <Mod/TechDraw/App/DrawView.h>
|
||||
@@ -97,6 +110,8 @@ TaskProjGroup::TaskProjGroup(TechDraw::DrawView* featView, bool mode) :
|
||||
connect(ui->butFront, &QPushButton::clicked, this, &TaskProjGroup::rotateButtonClicked);
|
||||
connect(ui->butCam, &QPushButton::clicked, this, &TaskProjGroup::rotateButtonClicked);
|
||||
|
||||
connect(ui->lePrimary, &QPushButton::clicked, this, &TaskProjGroup::customDirectionClicked);
|
||||
|
||||
// //Reset button
|
||||
// connect(ui->butReset, SIGNAL(clicked()), this, SLOT(onResetClicked()));
|
||||
|
||||
@@ -289,6 +304,38 @@ void TaskProjGroup::viewToggled(bool toggle)
|
||||
wc.restoreCursor();
|
||||
}
|
||||
|
||||
void TaskProjGroup::customDirectionClicked()
|
||||
{
|
||||
auto* dirEditDlg = new DirectionEditDialog();
|
||||
|
||||
if (multiView) {
|
||||
dirEditDlg->setDirection(multiView->getAnchor()->Direction.getValue());
|
||||
dirEditDlg->setAngle(0.0);
|
||||
}
|
||||
else {
|
||||
auto* viewPart = static_cast<TechDraw::DrawViewPart*>(view);
|
||||
dirEditDlg->setDirection(viewPart->Direction.getValue());
|
||||
dirEditDlg->setAngle(0.0);
|
||||
}
|
||||
|
||||
if (dirEditDlg->exec() == QDialog::Accepted) {
|
||||
if (multiView) {
|
||||
multiView->getAnchor()->Direction.setValue(dirEditDlg->getDirection());
|
||||
multiView->spin(Base::toRadians(dirEditDlg->getAngle()));
|
||||
}
|
||||
else {
|
||||
auto* viewPart = static_cast<TechDraw::DrawViewPart*>(view);
|
||||
viewPart->Direction.setValue(dirEditDlg->getDirection());
|
||||
viewPart->spin(Base::toRadians(dirEditDlg->getAngle()));
|
||||
}
|
||||
|
||||
setUiPrimary();
|
||||
}
|
||||
|
||||
|
||||
delete dirEditDlg;
|
||||
}
|
||||
|
||||
void TaskProjGroup::rotateButtonClicked()
|
||||
{
|
||||
if ( view && ui ) {
|
||||
@@ -758,4 +805,106 @@ bool TaskDlgProjGroup::reject()
|
||||
}
|
||||
|
||||
|
||||
DirectionEditDialog::DirectionEditDialog(QWidget* parent) : QDialog(parent) {
|
||||
setWindowFlags(Qt::Popup); // Make the dialog non-intrusive
|
||||
createUI();
|
||||
}
|
||||
|
||||
void DirectionEditDialog::setDirection(const Base::Vector3d& pos) {
|
||||
xSpinBox->setValue(pos.x);
|
||||
ySpinBox->setValue(pos.y);
|
||||
zSpinBox->setValue(pos.z);
|
||||
}
|
||||
|
||||
Base::Vector3d DirectionEditDialog::getDirection() const {
|
||||
return Base::Vector3d(xSpinBox->value().getValue(), ySpinBox->value().getValue(), zSpinBox->value().getValue());
|
||||
}
|
||||
|
||||
void DirectionEditDialog::setAngle(double val) {
|
||||
angleSpinBox->setValue(val);
|
||||
}
|
||||
|
||||
double DirectionEditDialog::getAngle() const {
|
||||
return angleSpinBox->value().getValue();
|
||||
}
|
||||
|
||||
void DirectionEditDialog::showEvent(QShowEvent* event) {
|
||||
QDialog::showEvent(event);
|
||||
|
||||
// Calculate the position to ensure the dialog appears within the screen boundaries
|
||||
QPoint cursorPos = QCursor::pos();
|
||||
QSize screenSize = QApplication::primaryScreen()->size(); // Get the size of the primary screen
|
||||
int x = cursorPos.x();
|
||||
int y = cursorPos.y();
|
||||
int dialogWidth = this->width();
|
||||
int dialogHeight = this->height();
|
||||
|
||||
// Check if the dialog goes beyond the right edge of the screen
|
||||
if (x + dialogWidth > screenSize.width()) {
|
||||
x = screenSize.width() - dialogWidth;
|
||||
}
|
||||
|
||||
// Check if the dialog goes beyond the bottom edge of the screen
|
||||
if (y + dialogHeight > screenSize.height()) {
|
||||
y = screenSize.height() - dialogHeight;
|
||||
}
|
||||
|
||||
// Move the dialog to the calculated position
|
||||
this->move(x, y);
|
||||
}
|
||||
|
||||
void DirectionEditDialog::createUI() {
|
||||
auto* directionGroup = new QGroupBox(tr("Direction"));
|
||||
auto* directionLayout = new QVBoxLayout; // Use QVBoxLayout for vertical alignment
|
||||
|
||||
// Create layout and widgets for X
|
||||
auto* xLayout = new QHBoxLayout;
|
||||
auto* xLabel = new QLabel(tr("X: "));
|
||||
xSpinBox = new Gui::QuantitySpinBox;
|
||||
xSpinBox->setUnit(Base::Unit::Length);
|
||||
xLayout->addWidget(xLabel);
|
||||
xLayout->addWidget(xSpinBox);
|
||||
|
||||
// Create layout and widgets for Y
|
||||
auto* yLayout = new QHBoxLayout;
|
||||
auto* yLabel = new QLabel(tr("Y: "));
|
||||
ySpinBox = new Gui::QuantitySpinBox;
|
||||
ySpinBox->setUnit(Base::Unit::Length);
|
||||
yLayout->addWidget(yLabel);
|
||||
yLayout->addWidget(ySpinBox);
|
||||
|
||||
// Create layout and widgets for Z
|
||||
auto* zLayout = new QHBoxLayout;
|
||||
auto* zLabel = new QLabel(tr("Z: "));
|
||||
zSpinBox = new Gui::QuantitySpinBox;
|
||||
zSpinBox->setUnit(Base::Unit::Length);
|
||||
zLayout->addWidget(zLabel);
|
||||
zLayout->addWidget(zSpinBox);
|
||||
|
||||
// Add the layouts to the direction group
|
||||
directionLayout->addLayout(xLayout);
|
||||
directionLayout->addLayout(yLayout);
|
||||
directionLayout->addLayout(zLayout);
|
||||
directionGroup->setLayout(directionLayout);
|
||||
|
||||
angleSpinBox = new Gui::QuantitySpinBox;
|
||||
angleSpinBox->setUnit(Base::Unit::Angle);
|
||||
|
||||
auto* buttonsLayout = new QHBoxLayout;
|
||||
auto* okButton = new QPushButton(tr("OK"));
|
||||
auto* cancelButton = new QPushButton(tr("Cancel"));
|
||||
buttonsLayout->addWidget(okButton);
|
||||
buttonsLayout->addWidget(cancelButton);
|
||||
|
||||
auto* mainLayout = new QVBoxLayout;
|
||||
mainLayout->addWidget(directionGroup);
|
||||
mainLayout->addWidget(new QLabel(tr("Rotate by")));
|
||||
mainLayout->addWidget(angleSpinBox);
|
||||
mainLayout->addLayout(buttonsLayout);
|
||||
setLayout(mainLayout);
|
||||
|
||||
connect(okButton, &QPushButton::clicked, this, &QDialog::accept);
|
||||
connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);
|
||||
}
|
||||
|
||||
#include <Mod/TechDraw/Gui/moc_TaskProjGroup.cpp>
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
|
||||
namespace Gui {
|
||||
class QuantitySpinBox;
|
||||
}
|
||||
|
||||
namespace TechDraw {
|
||||
class DrawView;
|
||||
@@ -88,6 +91,8 @@ protected Q_SLOTS:
|
||||
/// Requests appropriate rotation of our DrawProjGroup
|
||||
void rotateButtonClicked();
|
||||
|
||||
void customDirectionClicked();
|
||||
|
||||
void projectionTypeChanged(QString qText);
|
||||
void scaleTypeChanged(int index);
|
||||
void AutoDistributeClicked(bool clicked);
|
||||
@@ -163,6 +168,31 @@ private:
|
||||
Gui::TaskView::TaskBox* taskbox;
|
||||
};
|
||||
|
||||
|
||||
class DirectionEditDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DirectionEditDialog(QWidget* parent = nullptr);
|
||||
|
||||
void setDirection(const Base::Vector3d& pos);
|
||||
Base::Vector3d getDirection() const;
|
||||
|
||||
void setAngle(double val);
|
||||
double getAngle() const;
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
|
||||
private:
|
||||
Gui::QuantitySpinBox* xSpinBox;
|
||||
Gui::QuantitySpinBox* ySpinBox;
|
||||
Gui::QuantitySpinBox* zSpinBox;
|
||||
Gui::QuantitySpinBox* angleSpinBox;
|
||||
|
||||
void createUI();
|
||||
};
|
||||
|
||||
} //namespace TechDrawGui
|
||||
|
||||
#endif // #ifndef GUI_TASKVIEW_TASKVIEWGROUP_H
|
||||
|
||||
@@ -240,10 +240,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lePrimary">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<widget class="QPushButton" name="lePrimary">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>11</pointsize>
|
||||
@@ -252,18 +249,9 @@
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Current primary view direction</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
|
||||
Reference in New Issue
Block a user