Enable edges and datum lines as rotation axis for Groove and Revolution features
This commit is contained in:
committed by
Stefan Tröger
parent
999b1c028b
commit
75dc92fd90
@@ -39,9 +39,12 @@
|
||||
#include <Base/Console.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Mod/PartDesign/App/DatumLine.h>
|
||||
#include <Mod/PartDesign/App/FeatureRevolution.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
#include <Mod/PartDesign/App/Body.h>
|
||||
#include "ReferenceSelection.h"
|
||||
#include "TaskSketchBasedParameters.h"
|
||||
#include "Workbench.h"
|
||||
|
||||
|
||||
@@ -84,40 +87,14 @@ TaskRevolutionParameters::TaskRevolutionParameters(ViewProviderRevolution *Revol
|
||||
bool reversed = pcRevolution->Reversed.getValue();
|
||||
|
||||
ui->revolveAngle->setValue(l);
|
||||
|
||||
int count=pcRevolution->getSketchAxisCount();
|
||||
|
||||
for (int i=ui->axis->count()-1; i >= count+2; i--)
|
||||
ui->axis->removeItem(i);
|
||||
for (int i=ui->axis->count(); i < count+2; i++)
|
||||
ui->axis->addItem(QString::fromLatin1("Sketch axis %1").arg(i-2));
|
||||
|
||||
int pos=-1;
|
||||
|
||||
App::DocumentObject *pcReferenceAxis = pcRevolution->ReferenceAxis.getValue();
|
||||
const std::vector<std::string> &subReferenceAxis = pcRevolution->ReferenceAxis.getSubValues();
|
||||
if (pcReferenceAxis && pcReferenceAxis == pcRevolution->Sketch.getValue()) {
|
||||
assert(subReferenceAxis.size()==1);
|
||||
if (subReferenceAxis[0] == "V_Axis")
|
||||
pos = 0;
|
||||
else if (subReferenceAxis[0] == "H_Axis")
|
||||
pos = 1;
|
||||
else if (subReferenceAxis[0].size() > 4 && subReferenceAxis[0].substr(0,4) == "Axis")
|
||||
pos = 2 + std::atoi(subReferenceAxis[0].substr(4,4000).c_str());
|
||||
}
|
||||
|
||||
if (pos < 0 || pos >= ui->axis->count()) {
|
||||
ui->axis->addItem(tr("Undefined"));
|
||||
pos = ui->axis->count()-1;
|
||||
}
|
||||
|
||||
ui->axis->setCurrentIndex(pos);
|
||||
blockUpdate = false;
|
||||
updateUI();
|
||||
|
||||
ui->checkBoxMidplane->setChecked(mirrored);
|
||||
ui->checkBoxReversed->setChecked(reversed);
|
||||
ui->revolveAngle->bind(pcRevolution->Angle);
|
||||
|
||||
ui->revolveAngle->blockSignals(false);
|
||||
ui->doubleSpinBox->blockSignals(false);
|
||||
ui->axis->blockSignals(false);
|
||||
ui->checkBoxMidplane->blockSignals(false);
|
||||
ui->checkBoxReversed->blockSignals(false);
|
||||
@@ -125,16 +102,100 @@ TaskRevolutionParameters::TaskRevolutionParameters(ViewProviderRevolution *Revol
|
||||
setFocus ();
|
||||
}
|
||||
|
||||
void TaskRevolutionParameters::updateUI()
|
||||
{
|
||||
if (blockUpdate)
|
||||
return;
|
||||
blockUpdate = true;
|
||||
|
||||
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
|
||||
|
||||
App::DocumentObject* pcReferenceAxis = pcRevolution->ReferenceAxis.getValue();
|
||||
std::vector<std::string> sub = pcRevolution->ReferenceAxis.getSubValues();
|
||||
|
||||
// Add user-defined sketch axes to the reference selection combo box
|
||||
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
|
||||
int maxcount=2;
|
||||
if (pcSketch)
|
||||
maxcount += pcSketch->getAxisCount();
|
||||
|
||||
for (int i=ui->axis->count()-1; i >= 2; i--)
|
||||
ui->axis->removeItem(i);
|
||||
for (int i=ui->axis->count(); i < maxcount; i++)
|
||||
ui->axis->addItem(QString::fromAscii("Sketch axis %1").arg(i-5));
|
||||
|
||||
bool undefined = false;
|
||||
if (pcReferenceAxis != NULL && !sub.empty()) {
|
||||
if (sub.front() == "H_Axis")
|
||||
ui->axis->setCurrentIndex(0);
|
||||
else if (sub.front() == "V_Axis")
|
||||
ui->axis->setCurrentIndex(1);
|
||||
else if (sub.front().size() > 4 && sub.front().substr(0,4) == "Axis") {
|
||||
int pos = 2 + std::atoi(sub.front().substr(4,4000).c_str());
|
||||
if (pos <= maxcount)
|
||||
ui->axis->setCurrentIndex(pos);
|
||||
else
|
||||
undefined = true;
|
||||
} else {
|
||||
ui->axis->addItem(getRefStr(pcReferenceAxis, sub));
|
||||
ui->axis->setCurrentIndex(maxcount);
|
||||
}
|
||||
} else {
|
||||
undefined = true;
|
||||
}
|
||||
|
||||
ui->axis->addItem(tr("Select reference..."));
|
||||
|
||||
blockUpdate = false;
|
||||
}
|
||||
|
||||
void TaskRevolutionParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
{
|
||||
if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
||||
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
|
||||
|
||||
exitSelectionMode();
|
||||
if (!blockUpdate) {
|
||||
std::vector<std::string> axis;
|
||||
App::DocumentObject* selObj;
|
||||
getReferencedSelection(pcRevolution, msg, selObj, axis);
|
||||
pcRevolution->ReferenceAxis.setValue(selObj, axis);
|
||||
|
||||
|
||||
recomputeFeature();
|
||||
updateUI();
|
||||
}
|
||||
else {
|
||||
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
|
||||
int maxcount=2;
|
||||
if (pcSketch)
|
||||
maxcount += pcSketch->getAxisCount();
|
||||
for (int i=ui->axis->count()-1; i >= maxcount; i--)
|
||||
ui->axis->removeItem(i);
|
||||
|
||||
std::vector<std::string> sub;
|
||||
App::DocumentObject* selObj;
|
||||
getReferencedSelection(pcRevolution, msg, selObj, sub);
|
||||
ui->axis->addItem(getRefStr(selObj, sub));
|
||||
ui->axis->setCurrentIndex(maxcount);
|
||||
ui->axis->addItem(tr("Select reference..."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TaskRevolutionParameters::onAngleChanged(double len)
|
||||
{
|
||||
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
|
||||
pcRevolution->Angle.setValue(len);
|
||||
if (updateView())
|
||||
pcRevolution->getDocument()->recomputeFeature(pcRevolution);
|
||||
exitSelectionMode();
|
||||
recomputeFeature();
|
||||
}
|
||||
|
||||
void TaskRevolutionParameters::onAxisChanged(int num)
|
||||
{
|
||||
if (blockUpdate)
|
||||
return;
|
||||
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
|
||||
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
|
||||
if (pcSketch) {
|
||||
@@ -142,20 +203,26 @@ void TaskRevolutionParameters::onAxisChanged(int num)
|
||||
std::vector<std::string> oldSubRefAxis = pcRevolution->ReferenceAxis.getSubValues();
|
||||
|
||||
int maxcount = pcSketch->getAxisCount()+2;
|
||||
if (num == 0)
|
||||
pcRevolution->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,"V_Axis"));
|
||||
else if (num == 1)
|
||||
if (num == 0) {
|
||||
pcRevolution->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,"H_Axis"));
|
||||
else if (num >= 2 && num < maxcount) {
|
||||
exitSelectionMode();
|
||||
} else if (num == 1) {
|
||||
pcRevolution->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,"V_Axis"));
|
||||
exitSelectionMode();
|
||||
} else if (num >= 2 && num < maxcount) {
|
||||
QString buf = QString::fromUtf8("Axis%1").arg(num-2);
|
||||
std::string str = buf.toStdString();
|
||||
pcRevolution->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,str));
|
||||
}
|
||||
if (num < maxcount && ui->axis->count() > maxcount)
|
||||
ui->axis->setMaxCount(maxcount);
|
||||
exitSelectionMode();
|
||||
} else if (num == ui->axis->count() - 1) {
|
||||
// enter reference selection mode
|
||||
TaskSketchBasedParameters::onSelectReference(true, true, false, true);
|
||||
} else if (num == maxcount)
|
||||
exitSelectionMode();
|
||||
|
||||
App::DocumentObject *newRefAxis = pcRevolution->ReferenceAxis.getValue();
|
||||
const std::vector<std::string> &newSubRefAxis = pcRevolution->ReferenceAxis.getSubValues();
|
||||
if (oldRefAxis != pcSketch ||
|
||||
if (oldRefAxis != newRefAxis ||
|
||||
oldSubRefAxis.size() != newSubRefAxis.size() ||
|
||||
oldSubRefAxis[0] != newSubRefAxis[0]) {
|
||||
bool reversed = pcRevolution->suggestReversed();
|
||||
@@ -167,24 +234,23 @@ void TaskRevolutionParameters::onAxisChanged(int num)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (updateView())
|
||||
pcRevolution->getDocument()->recomputeFeature(pcRevolution);
|
||||
|
||||
updateUI();
|
||||
recomputeFeature();
|
||||
}
|
||||
|
||||
void TaskRevolutionParameters::onMidplane(bool on)
|
||||
{
|
||||
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
|
||||
pcRevolution->Midplane.setValue(on);
|
||||
if (updateView())
|
||||
pcRevolution->getDocument()->recomputeFeature(pcRevolution);
|
||||
recomputeFeature();
|
||||
}
|
||||
|
||||
void TaskRevolutionParameters::onReversed(bool on)
|
||||
{
|
||||
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
|
||||
pcRevolution->Reversed.setValue(on);
|
||||
if (updateView())
|
||||
pcRevolution->getDocument()->recomputeFeature(pcRevolution);
|
||||
recomputeFeature();
|
||||
}
|
||||
|
||||
double TaskRevolutionParameters::getAngle(void) const
|
||||
@@ -192,29 +258,36 @@ double TaskRevolutionParameters::getAngle(void) const
|
||||
return ui->revolveAngle->value().getValue();
|
||||
}
|
||||
|
||||
QString TaskRevolutionParameters::getReferenceAxis(void) const
|
||||
void TaskRevolutionParameters::getReferenceAxis(App::DocumentObject*& obj, std::vector<std::string>& sub) const
|
||||
{
|
||||
// get the support and Sketch
|
||||
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
|
||||
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
|
||||
obj = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
|
||||
sub = std::vector<std::string>(1,"");
|
||||
int maxcount=2;
|
||||
if (obj)
|
||||
maxcount += static_cast<Part::Part2DObject*>(obj)->getAxisCount();
|
||||
|
||||
QString buf;
|
||||
if (pcSketch) {
|
||||
buf = QString::fromUtf8("(App.ActiveDocument.%1,[%2])");
|
||||
buf = buf.arg(QString::fromUtf8(pcSketch->getNameInDocument()));
|
||||
if (ui->axis->currentIndex() == 0)
|
||||
buf = buf.arg(QString::fromUtf8("'V_Axis'"));
|
||||
else if (ui->axis->currentIndex() == 1)
|
||||
buf = buf.arg(QString::fromUtf8("'H_Axis'"));
|
||||
else if (ui->axis->currentIndex() >= 2) {
|
||||
buf = buf.arg(QString::fromUtf8("'Axis%1'"));
|
||||
buf = buf.arg(ui->axis->currentIndex()-2);
|
||||
if (obj) {
|
||||
int num = ui->axis->currentIndex();
|
||||
if (num == 0)
|
||||
sub[0] = "H_Axis";
|
||||
else if (num == 1)
|
||||
sub[0] = "V_Axis";
|
||||
else if (num >= 2 && num < maxcount) {
|
||||
QString buf = QString::fromUtf8("Axis%1").arg(num-2);
|
||||
sub[0] = buf.toStdString();
|
||||
} else if (num == maxcount && ui->axis->count() == maxcount + 2) {
|
||||
QStringList parts = ui->axis->currentText().split(QChar::fromAscii(':'));
|
||||
obj = vp->getObject()->getDocument()->getObject(parts[0].toStdString().c_str());
|
||||
if (parts.size() > 1)
|
||||
sub[0] = parts[1].toStdString();
|
||||
} else {
|
||||
obj = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
buf = QString::fromUtf8("''");
|
||||
|
||||
return buf;
|
||||
obj = NULL;
|
||||
}
|
||||
|
||||
bool TaskRevolutionParameters::getMidplane(void) const
|
||||
@@ -227,11 +300,6 @@ bool TaskRevolutionParameters::getReversed(void) const
|
||||
return ui->checkBoxReversed->isChecked();
|
||||
}
|
||||
|
||||
const bool TaskRevolutionParameters::updateView() const
|
||||
{
|
||||
return ui->checkBoxUpdateView->isChecked();
|
||||
}
|
||||
|
||||
TaskRevolutionParameters::~TaskRevolutionParameters()
|
||||
{
|
||||
delete ui;
|
||||
@@ -262,7 +330,10 @@ void TaskRevolutionParameters::apply()
|
||||
|
||||
//Gui::Command::openCommand("Revolution changed");
|
||||
ui->revolveAngle->apply();
|
||||
std::string axis = getReferenceAxis().toStdString();
|
||||
std::vector<std::string> sub;
|
||||
App::DocumentObject* obj;
|
||||
parameter->getReferenceAxis(obj, sub);
|
||||
std::string axis = getPythonStr(obj, sub);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.ReferenceAxis = %s",name.c_str(),axis.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Midplane = %i",name.c_str(), getMidplane() ? 1 : 0);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i",name.c_str(), getReversed() ? 1 : 0);
|
||||
|
||||
Reference in New Issue
Block a user