Skip to content

Commit

Permalink
allow to set user-defined standard orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jan 13, 2019
1 parent abe82e0 commit 15b854b
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Gui/DlgSettings3DView.ui
Expand Up @@ -243,6 +243,17 @@
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="newDocViewLabel">
<property name="text">
<string>New Document Camera Orientation</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboNewDocView">
</widget>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -675,6 +686,7 @@
<tabstop>comboNavigationStyle</tabstop>
<tabstop>mouseButton</tabstop>
<tabstop>comboOrbitStyle</tabstop>
<tabstop>comboNewDocView</tabstop>
<tabstop>checkBoxZoomAtCursor</tabstop>
<tabstop>spinBoxZoomStep</tabstop>
<tabstop>checkBoxInvertZoom</tabstop>
Expand Down
159 changes: 159 additions & 0 deletions src/Gui/DlgSettings3DViewImp.cpp
Expand Up @@ -25,14 +25,18 @@

#ifndef _PreComp_
# include <QApplication>
# include <QDoubleSpinBox>
# include <QRegExp>
# include <QGridLayout>
# include <QMessageBox>
# include <memory>
#endif

#include "DlgSettings3DViewImp.h"
#include "MainWindow.h"
#include "NavigationStyle.h"
#include "PrefWidgets.h"
#include "View3DInventor.h"
#include "View3DInventorViewer.h"
#include "ui_MouseButtons.h"
#include <App/Application.h>
Expand All @@ -52,6 +56,7 @@ bool DlgSettings3DViewImp::showMsg = true;
*/
DlgSettings3DViewImp::DlgSettings3DViewImp(QWidget* parent)
: PreferencePage( parent )
, q0(0), q1(0), q2(0), q3(1)
{
this->setupUi(this);
retranslate();
Expand Down Expand Up @@ -102,6 +107,16 @@ void DlgSettings3DViewImp::saveSettings()
sliderIntensity->onSave();
radioPerspective->onSave();
radioOrthographic->onSave();

QVariant camera = comboNewDocView->itemData(comboNewDocView->currentIndex(), Qt::UserRole);
hGrp->SetASCII("NewDocumentCameraOrientation", (const char*)camera.toByteArray());
if (camera == QByteArray("Custom")) {
ParameterGrp::handle hCustom = hGrp->GetGroup("Custom");
hCustom->SetFloat("Q0", q0);
hCustom->SetFloat("Q1", q1);
hCustom->SetFloat("Q2", q2);
hCustom->SetFloat("Q3", q3);
}
}

void DlgSettings3DViewImp::loadSettings()
Expand Down Expand Up @@ -153,6 +168,30 @@ void DlgSettings3DViewImp::loadSettings()
index = this->boxMarkerSize->findData(QVariant(current));
if (index < 0) index = 2;
this->boxMarkerSize->setCurrentIndex(index);

comboNewDocView->addItem(tr("Isometric"), QByteArray("Isometric"));
comboNewDocView->addItem(tr("Dimetric"), QByteArray("Dimetric"));
comboNewDocView->addItem(tr("Trimetric"), QByteArray("Trimetric"));
comboNewDocView->addItem(tr("Top"), QByteArray("Top"));
comboNewDocView->addItem(tr("Front"), QByteArray("Front"));
comboNewDocView->addItem(tr("Left"), QByteArray("Left"));
comboNewDocView->addItem(tr("Right"), QByteArray("Right"));
comboNewDocView->addItem(tr("Rear"), QByteArray("Rear"));
comboNewDocView->addItem(tr("Bottom"), QByteArray("Bottom"));
comboNewDocView->addItem(tr("Custom"), QByteArray("Custom"));
std::string camera = hGrp->GetASCII("NewDocumentCameraOrientation", "Top");
index = comboNewDocView->findData(QByteArray(camera.c_str()));
if (index > -1) comboNewDocView->setCurrentIndex(index);
if (camera == "Custom") {
ParameterGrp::handle hCustom = hGrp->GetGroup("Custom");
q0 = hCustom->GetFloat("Q0", q0);
q1 = hCustom->GetFloat("Q1", q1);
q2 = hCustom->GetFloat("Q2", q2);
q3 = hCustom->GetFloat("Q3", q3);
}

connect(comboNewDocView, SIGNAL(currentIndexChanged(int)),
this, SLOT(onNewDocViewChanged(int)));
}

void DlgSettings3DViewImp::on_mouseButton_clicked()
Expand Down Expand Up @@ -232,5 +271,125 @@ void DlgSettings3DViewImp::onAliasingChanged(int index)
}
}

void DlgSettings3DViewImp::onNewDocViewChanged(int index)
{
QVariant camera = comboNewDocView->itemData(index, Qt::UserRole);
if (camera == QByteArray("Custom")) {
CameraDialog dlg(this);
dlg.setValues(q0, q1, q2, q3);
if (dlg.exec()) {
dlg.getValues(q0, q1, q2, q3);
}
}
}

// ----------------------------------------------------------------------------

CameraDialog::CameraDialog(QWidget* parent)
: QDialog(parent)
{
this->setWindowTitle(tr("Camera settings"));

QGridLayout *gridLayout;
gridLayout = new QGridLayout(this);

QGroupBox *groupBox;
groupBox = new QGroupBox(this);
groupBox->setTitle(tr("Orientation"));
gridLayout->addWidget(groupBox, 0, 0, 1, 1);

QDialogButtonBox *buttonBox;
buttonBox = new QDialogButtonBox(this);
buttonBox->setOrientation(Qt::Horizontal);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
gridLayout->addWidget(buttonBox, 3, 0, 1, 1);

QGridLayout *layout;
layout = new QGridLayout(groupBox);

// Q0
QLabel* label0 = new QLabel(groupBox);
label0->setText(tr("Q0"));
layout->addWidget(label0, 0, 0, 1, 1);

sb0 = new QDoubleSpinBox(groupBox);
sb0->setRange(-1, 1);
sb0->setSingleStep(0.1);
layout->addWidget(sb0, 0, 1, 1, 1);

// Q1
QLabel* label1 = new QLabel(groupBox);
label1->setText(tr("Q1"));
layout->addWidget(label1, 1, 0, 1, 1);

sb1 = new QDoubleSpinBox(groupBox);
sb1->setRange(-1, 1);
sb1->setSingleStep(0.1);
layout->addWidget(sb1, 1, 1, 1, 1);

// Q2
QLabel* label2 = new QLabel(groupBox);
label2->setText(tr("Q2"));
layout->addWidget(label2, 2, 0, 1, 1);

sb2 = new QDoubleSpinBox(groupBox);
sb2->setRange(-1, 1);
sb2->setSingleStep(0.1);
layout->addWidget(sb2, 2, 1, 1, 1);

// Q3
QLabel* label3 = new QLabel(groupBox);
label3->setText(tr("Q3"));
layout->addWidget(label3, 3, 0, 1, 1);

sb3 = new QDoubleSpinBox(groupBox);
sb3->setRange(-1, 1);
sb3->setSingleStep(0.1);
layout->addWidget(sb3, 3, 1, 1, 1);

QPushButton *currentViewButton;
currentViewButton = new QPushButton(this);
currentViewButton->setText(tr("Current view"));
currentViewButton->setObjectName(QString::fromLatin1("currentView"));
layout->addWidget(currentViewButton, 4, 1, 2, 1);

QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QMetaObject::connectSlotsByName(this);
}

CameraDialog::~CameraDialog()
{
}

void CameraDialog::setValues(double q0, double q1, double q2, double q3)
{
sb0->setValue(q0);
sb1->setValue(q1);
sb2->setValue(q2);
sb3->setValue(q3);
}

void CameraDialog::getValues(double& q0, double& q1, double& q2, double& q3) const
{
q0 = sb0->value();
q1 = sb1->value();
q2 = sb2->value();
q3 = sb3->value();
}

void CameraDialog::on_currentView_clicked()
{
View3DInventor* mdi = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
if (mdi) {
SbRotation rot = mdi->getViewer()->getCameraOrientation();
sb0->setValue(rot[0]);
sb1->setValue(rot[1]);
sb2->setValue(rot[2]);
sb3->setValue(rot[3]);
}
}


#include "moc_DlgSettings3DViewImp.cpp"

23 changes: 23 additions & 0 deletions src/Gui/DlgSettings3DViewImp.h
Expand Up @@ -49,13 +49,36 @@ class DlgSettings3DViewImp : public PreferencePage, public Ui_DlgSettings3DView
private Q_SLOTS:
void on_mouseButton_clicked();
void onAliasingChanged(int);
void onNewDocViewChanged(int);

protected:
void changeEvent(QEvent *e);
void retranslate();

private:
static bool showMsg;
double q0, q1, q2, q3;
};

class CameraDialog : public QDialog
{
Q_OBJECT

public:
CameraDialog(QWidget* parent=0);
~CameraDialog();
void setValues(double q0, double q1, double q2, double q3);
void getValues(double& q0, double& q1, double& q2, double& q3) const;


private Q_SLOTS:
void on_currentView_clicked();

private:
QDoubleSpinBox* sb0;
QDoubleSpinBox* sb1;
QDoubleSpinBox* sb2;
QDoubleSpinBox* sb3;
};

} // namespace Dialog
Expand Down
8 changes: 8 additions & 0 deletions src/Gui/View3DPy.cpp
Expand Up @@ -670,6 +670,14 @@ Py::Object View3DInventorPy::viewDefaultOrientation(const Py::Tuple& args)
else if (newDocView == "Trimetric") {
rot = Camera::rotation(Camera::Trimetric);
}
else if (newDocView == "Custom") {
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View/Custom");
float q0 = static_cast<float>(hGrp->GetFloat("Q0", 0));
float q1 = static_cast<float>(hGrp->GetFloat("Q1", 0));
float q2 = static_cast<float>(hGrp->GetFloat("Q2", 0));
float q3 = static_cast<float>(hGrp->GetFloat("Q3", 1));
rot.setValue(q0, q1, q2, q3);
}

_view->getViewer()->setCameraOrientation(rot);
}
Expand Down

0 comments on commit 15b854b

Please sign in to comment.