add option to placement dialog to rotate around center of mass

This commit is contained in:
wmayer 2017-03-05 18:47:34 +01:00
parent 35e8edeb08
commit db66835c63
3 changed files with 55 additions and 8 deletions

View File

@ -35,6 +35,7 @@
#include <Gui/Selection.h>
#include <Gui/ViewProvider.h>
#include <App/Document.h>
#include <App/GeoFeature.h>
#include <App/PropertyGeo.h>
#include <Base/Console.h>
#include <Base/Tools.h>
@ -263,6 +264,32 @@ void Placement::onPlacementChanged(int)
/*emit*/ placementChanged(data, incr, false);
}
void Placement::on_centerOfMass_toggled(bool on)
{
ui->xCnt->setDisabled(on);
ui->yCnt->setDisabled(on);
ui->zCnt->setDisabled(on);
if (on) {
cntOfMass.Set(0,0,0);
std::vector<App::DocumentObject*> sel = Gui::Selection().getObjectsOfType
(App::GeoFeature::getClassTypeId());
if (!sel.empty()) {
for (auto it : sel) {
const App::PropertyComplexGeoData* propgeo = static_cast<App::GeoFeature*>(it)->getPropertyOfGeometry();
const Data::ComplexGeoData* geodata = propgeo ? propgeo->getComplexData() : nullptr;
if (geodata && geodata->getCenterOfGravity(cntOfMass)) {
break;
}
}
}
ui->xCnt->setValue(cntOfMass.x);
ui->yCnt->setValue(cntOfMass.y);
ui->zCnt->setValue(cntOfMass.z);
}
}
void Placement::on_applyIncrementalPlacement_toggled(bool on)
{
if (on) {
@ -419,6 +446,15 @@ Base::Placement Placement::getPlacement() const
return p;
}
Base::Vector3d Placement::getCenterData() const
{
if (ui->centerOfMass->isChecked())
return this->cntOfMass;
return Base::Vector3d(ui->xCnt->value().getValue(),
ui->yCnt->value().getValue(),
ui->zCnt->value().getValue());
}
Base::Placement Placement::getPlacementData() const
{
int index = ui->rotationInput->currentIndex();
@ -427,7 +463,7 @@ Base::Placement Placement::getPlacementData() const
Base::Vector3d cnt;
pos = Base::Vector3d(ui->xPos->value().getValue(),ui->yPos->value().getValue(),ui->zPos->value().getValue());
cnt = Base::Vector3d(ui->xCnt->value().getValue(),ui->yCnt->value().getValue(),ui->zCnt->value().getValue());
cnt = getCenterData();
if (index == 0) {
Base::Vector3d dir = getDirection();
@ -448,6 +484,7 @@ QString Placement::getPlacementString() const
{
QString cmd;
int index = ui->rotationInput->currentIndex();
Base::Vector3d cnt = getCenterData();
if (index == 0) {
Base::Vector3d dir = getDirection();
@ -460,9 +497,9 @@ QString Placement::getPlacementString() const
.arg(dir.y)
.arg(dir.z)
.arg(ui->angle->value().getValue())
.arg(ui->xCnt->value().getValue())
.arg(ui->yCnt->value().getValue())
.arg(ui->zCnt->value().getValue());
.arg(cnt.x)
.arg(cnt.y)
.arg(cnt.z);
}
else if (index == 1) {
cmd = QString::fromLatin1(
@ -473,9 +510,9 @@ QString Placement::getPlacementString() const
.arg(ui->yawAngle->value().getValue())
.arg(ui->pitchAngle->value().getValue())
.arg(ui->rollAngle->value().getValue())
.arg(ui->xCnt->value().getValue())
.arg(ui->yCnt->value().getValue())
.arg(ui->zCnt->value().getValue());
.arg(cnt.x)
.arg(cnt.y)
.arg(cnt.z);
}
return cmd;

View File

@ -63,11 +63,13 @@ private Q_SLOTS:
void on_applyIncrementalPlacement_toggled(bool);
void onPlacementChanged(int);
void on_resetButton_clicked();
void on_centerOfMass_toggled(bool);
private:
bool onApply();
void setPlacementData(const Base::Placement&);
Base::Placement getPlacementData() const;
Base::Vector3d getCenterData() const;
QString getPlacementString() const;
void directionActivated(int);
void applyPlacement(const Base::Placement& p, bool incremental);
@ -87,6 +89,7 @@ private:
QSignalMapper* signalMapper;
Connection connectAct;
Base::Placement ref;
Base::Vector3d cntOfMass;
std::string propertyName; // the name of the placement property
std::set<std::string> documents;

View File

@ -108,7 +108,7 @@
<property name="spacing">
<number>6</number>
</property>
<item row="3" column="1">
<item row="4" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -169,6 +169,13 @@
<item row="2" column="1">
<widget class="Gui::QuantitySpinBox" name="zCnt"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="centerOfMass">
<property name="text">
<string>Use center of mass</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>