make transform features work with non-sketch based features

This commit is contained in:
Stefan Tröger 2015-05-11 20:32:44 +02:00
parent cf83242f5b
commit d923bebccc
8 changed files with 219 additions and 197 deletions

View File

@ -90,6 +90,9 @@ App::DocumentObject* Transformed::getSketchObject() const
if (!originals.empty() && originals.front()->getTypeId().isDerivedFrom(PartDesign::SketchBased::getClassTypeId())) { if (!originals.empty() && originals.front()->getTypeId().isDerivedFrom(PartDesign::SketchBased::getClassTypeId())) {
return (static_cast<PartDesign::SketchBased*>(originals.front()))->getVerifiedSketch(); return (static_cast<PartDesign::SketchBased*>(originals.front()))->getVerifiedSketch();
} }
else if (!originals.empty() && originals.front()->getTypeId().isDerivedFrom(PartDesign::FeatureAddSub::getClassTypeId())) {
return NULL;
}
else if (this->getTypeId().isDerivedFrom(LinearPattern::getClassTypeId())) { else if (this->getTypeId().isDerivedFrom(LinearPattern::getClassTypeId())) {
// if Originals is empty then try the linear pattern's Direction property // if Originals is empty then try the linear pattern's Direction property
const LinearPattern* pattern = static_cast<const LinearPattern*>(this); const LinearPattern* pattern = static_cast<const LinearPattern*>(this);

View File

@ -1645,10 +1645,16 @@ void CmdPartDesignMirrored::activated(int iMsg)
if (features.empty()) if (features.empty())
return; return;
Part::Part2DObject *sketch = (static_cast<PartDesign::SketchBased*>(features.front()))->getVerifiedSketch(); if(features.front()->isDerivedFrom(PartDesign::SketchBased::getClassTypeId())) {
if (sketch) Part::Part2DObject *sketch = (static_cast<PartDesign::SketchBased*>(features.front()))->getVerifiedSketch();
Gui::Command::doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"V_Axis\"])", if (sketch)
FeatName.c_str(), sketch->getNameInDocument()); Gui::Command::doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"V_Axis\"])",
FeatName.c_str(), sketch->getNameInDocument());
}
else {
doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
App::Part::BaseplaneTypes[0]);
}
finishTransformed(cmd, FeatName); finishTransformed(cmd, FeatName);
}; };
@ -1684,12 +1690,18 @@ void CmdPartDesignLinearPattern::activated(int iMsg)
auto worker = [cmd](std::string FeatName, std::vector<App::DocumentObject*> features) { auto worker = [cmd](std::string FeatName, std::vector<App::DocumentObject*> features) {
if (features.empty()) if (features.empty())
return; return;
Part::Part2DObject *sketch = (static_cast<PartDesign::SketchBased*>(features.front()))->getVerifiedSketch(); if(features.front()->isDerivedFrom(PartDesign::SketchBased::getClassTypeId())) {
if (sketch) Part::Part2DObject *sketch = (static_cast<PartDesign::SketchBased*>(features.front()))->getVerifiedSketch();
doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"H_Axis\"])", if (sketch)
FeatName.c_str(), sketch->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"H_Axis\"])",
FeatName.c_str(), sketch->getNameInDocument());
}
else {
doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
App::Part::BaselineTypes[0]);
}
doCommand(Doc,"App.activeDocument().%s.Length = 100", FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Length = 100", FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str());
@ -1728,10 +1740,17 @@ void CmdPartDesignPolarPattern::activated(int iMsg)
if (features.empty()) if (features.empty())
return; return;
Part::Part2DObject *sketch = (static_cast<PartDesign::SketchBased*>(features.front()))->getVerifiedSketch(); if(features.front()->isDerivedFrom(PartDesign::SketchBased::getClassTypeId())) {
if (sketch) Part::Part2DObject *sketch = (static_cast<PartDesign::SketchBased*>(features.front()))->getVerifiedSketch();
doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"N_Axis\"])", if (sketch)
FeatName.c_str(), sketch->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"N_Axis\"])",
FeatName.c_str(), sketch->getNameInDocument());
}
else {
doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
App::Part::BaselineTypes[0]);
}
doCommand(Doc,"App.activeDocument().%s.Angle = 360", FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Angle = 360", FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str());

View File

@ -151,6 +151,18 @@ void TaskLinearPatternParameters::setupUI()
ui->spinLength->setUnit(Base::Unit::Length); ui->spinLength->setUnit(Base::Unit::Length);
ui->spinLength->blockSignals(false); ui->spinLength->blockSignals(false);
ui->spinOccurrences->setEnabled(true); ui->spinOccurrences->setEnabled(true);
App::DocumentObject* sketch = getSketchObject();
if (sketch) {
ui->comboDirection->addItem(QString::fromAscii("Horizontal sketch axis"));
ui->comboDirection->addItem(QString::fromAscii("Vertical sketch axis"));
}
//add the base axes to the selection combo box
ui->comboDirection->addItem(QString::fromAscii("Base X axis"));
ui->comboDirection->addItem(QString::fromAscii("Base Y axis"));
ui->comboDirection->addItem(QString::fromAscii("Base Z axis"));
ui->comboDirection->addItem(QString::fromAscii("Select reference..."));
updateUI(); updateUI();
//show the parts coordinate system axis for selection //show the parts coordinate system axis for selection
@ -185,11 +197,13 @@ void TaskLinearPatternParameters::updateUI()
// Add user-defined sketch axes to the reference selection combo box // Add user-defined sketch axes to the reference selection combo box
App::DocumentObject* sketch = getSketchObject(); App::DocumentObject* sketch = getSketchObject();
int maxcount=5; int maxcount=3;
if (sketch) if (sketch) {
maxcount = 5;
maxcount += static_cast<Part::Part2DObject*>(sketch)->getAxisCount(); maxcount += static_cast<Part::Part2DObject*>(sketch)->getAxisCount();
}
for (int i=ui->comboDirection->count()-1; i >= 5; i--) for (int i=ui->comboDirection->count()-1; i >= maxcount; i--)
ui->comboDirection->removeItem(i); ui->comboDirection->removeItem(i);
for (int i=ui->comboDirection->count(); i < maxcount; i++) for (int i=ui->comboDirection->count(); i < maxcount; i++)
ui->comboDirection->addItem(QString::fromLatin1("Sketch axis %1").arg(i-5)); ui->comboDirection->addItem(QString::fromLatin1("Sketch axis %1").arg(i-5));
@ -201,13 +215,13 @@ void TaskLinearPatternParameters::updateUI()
else if (directions.front() == "V_Axis") else if (directions.front() == "V_Axis")
ui->comboDirection->setCurrentIndex(1); ui->comboDirection->setCurrentIndex(1);
else if (strcmp(directionFeature->getNameInDocument(), App::Part::BaselineTypes[0]) == 0) else if (strcmp(directionFeature->getNameInDocument(), App::Part::BaselineTypes[0]) == 0)
ui->comboDirection->setCurrentIndex(2); ui->comboDirection->setCurrentIndex( sketch ? 2 : 0);
else if (strcmp(directionFeature->getNameInDocument(), App::Part::BaselineTypes[1]) == 0) else if (strcmp(directionFeature->getNameInDocument(), App::Part::BaselineTypes[1]) == 0)
ui->comboDirection->setCurrentIndex(3); ui->comboDirection->setCurrentIndex(sketch ? 3 : 1);
else if (strcmp(directionFeature->getNameInDocument(), App::Part::BaselineTypes[2]) == 0) else if (strcmp(directionFeature->getNameInDocument(), App::Part::BaselineTypes[2]) == 0)
ui->comboDirection->setCurrentIndex(4); ui->comboDirection->setCurrentIndex(sketch ? 4 : 2);
else if (directions.front().size() > 4 && directions.front().substr(0,4) == "Axis") { else if (directions.front().size() > (sketch ? 4 : 2) && directions.front().substr(0,4) == "Axis") {
int pos = 5 + std::atoi(directions.front().substr(4,4000).c_str()); int pos = (sketch ? 5 : 3) + std::atoi(directions.front().substr(4,4000).c_str());
if (pos <= maxcount) if (pos <= maxcount)
ui->comboDirection->setCurrentIndex(pos); ui->comboDirection->setCurrentIndex(pos);
else else
@ -345,35 +359,39 @@ void TaskLinearPatternParameters::onDirectionChanged(int num) {
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject()); PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
App::DocumentObject* pcSketch = getSketchObject(); App::DocumentObject* pcSketch = getSketchObject();
int maxcount=5; int maxcount=3;
if (pcSketch) if (pcSketch) {
maxcount = 5;
maxcount += static_cast<Part::Part2DObject*>(pcSketch)->getAxisCount(); maxcount += static_cast<Part::Part2DObject*>(pcSketch)->getAxisCount();
}
if (num == 0) { if(pcSketch) {
pcLinearPattern->Direction.setValue(pcSketch, std::vector<std::string>(1,"H_Axis")); if (num == 0) {
exitSelectionMode(); pcLinearPattern->Direction.setValue(pcSketch, std::vector<std::string>(1,"H_Axis"));
exitSelectionMode();
}
else if (num == 1) {
pcLinearPattern->Direction.setValue(pcSketch, std::vector<std::string>(1,"V_Axis"));
exitSelectionMode();
}
} }
else if (num == 1) { if (num == (pcSketch ? 2 : 0)) {
pcLinearPattern->Direction.setValue(pcSketch, std::vector<std::string>(1,"V_Axis"));
exitSelectionMode();
}
else if (num == 2) {
pcLinearPattern->Direction.setValue(getObject()->getDocument()->getObject(App::Part::BaselineTypes[0]), pcLinearPattern->Direction.setValue(getObject()->getDocument()->getObject(App::Part::BaselineTypes[0]),
std::vector<std::string>(1,"")); std::vector<std::string>(1,""));
exitSelectionMode(); exitSelectionMode();
} }
else if (num == 3) { else if (num == (pcSketch ? 3 : 1)) {
pcLinearPattern->Direction.setValue(getObject()->getDocument()->getObject(App::Part::BaselineTypes[1]), pcLinearPattern->Direction.setValue(getObject()->getDocument()->getObject(App::Part::BaselineTypes[1]),
std::vector<std::string>(1,"")); std::vector<std::string>(1,""));
exitSelectionMode(); exitSelectionMode();
} }
else if (num == 4) { else if (num == (pcSketch ? 4 : 2)) {
pcLinearPattern->Direction.setValue(getObject()->getDocument()->getObject(App::Part::BaselineTypes[2]), pcLinearPattern->Direction.setValue(getObject()->getDocument()->getObject(App::Part::BaselineTypes[2]),
std::vector<std::string>(1,"")); std::vector<std::string>(1,""));
exitSelectionMode(); exitSelectionMode();
} }
else if (num >= 5 && num < maxcount) { else if (num >= (pcSketch ? 5 : 3) && num < maxcount) {
QString buf = QString::fromUtf8("Axis%1").arg(num-5); QString buf = QString::fromUtf8("Axis%1").arg(num-(pcSketch ? 5 : 3));
std::string str = buf.toStdString(); std::string str = buf.toStdString();
pcLinearPattern->Direction.setValue(pcSketch, std::vector<std::string>(1,str)); pcLinearPattern->Direction.setValue(pcSketch, std::vector<std::string>(1,str));
exitSelectionMode(); exitSelectionMode();
@ -425,23 +443,27 @@ void TaskLinearPatternParameters::getDirection(App::DocumentObject*& obj, std::v
{ {
obj = getSketchObject(); obj = getSketchObject();
sub = std::vector<std::string>(1,""); sub = std::vector<std::string>(1,"");
int maxcount=5; int maxcount=3;
if (obj) if (obj) {
maxcount = 5;
maxcount += static_cast<Part::Part2DObject*>(obj)->getAxisCount(); maxcount += static_cast<Part::Part2DObject*>(obj)->getAxisCount();
}
int num = ui->comboDirection->currentIndex(); int num = ui->comboDirection->currentIndex();
if (num == 0) if(obj) {
sub[0] = "H_Axis"; if (num == 0)
else if (num == 1) sub[0] = "H_Axis";
sub[0] = "V_Axis"; else if (num == 1)
else if (num == 2) sub[0] = "V_Axis";
}
if (num == (obj ? 2 : 0))
obj = getObject()->getDocument()->getObject(App::Part::BaselineTypes[0]); obj = getObject()->getDocument()->getObject(App::Part::BaselineTypes[0]);
else if (num == 3) else if (num == (obj ? 3 : 1))
obj = getObject()->getDocument()->getObject(App::Part::BaselineTypes[1]); obj = getObject()->getDocument()->getObject(App::Part::BaselineTypes[1]);
else if (num == 4) else if (num == (obj ? 4 : 2))
obj = getObject()->getDocument()->getObject(App::Part::BaselineTypes[2]); obj = getObject()->getDocument()->getObject(App::Part::BaselineTypes[2]);
else if (num >= 5 && num < maxcount) { else if (num >= (obj ? 5 : 3) && num < maxcount) {
QString buf = QString::fromUtf8("Axis%1").arg(num-5); QString buf = QString::fromUtf8("Axis%1").arg(num-(obj ? 5 : 3));
sub[0] = buf.toStdString(); sub[0] = buf.toStdString();
} else if (num == maxcount && ui->comboDirection->count() == maxcount + 2) { } else if (num == maxcount && ui->comboDirection->count() == maxcount + 2) {
QStringList parts = ui->comboDirection->currentText().split(QChar::fromAscii(':')); QStringList parts = ui->comboDirection->currentText().split(QChar::fromAscii(':'));

View File

@ -51,38 +51,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboDirection"> <widget class="QComboBox" name="comboDirection"/>
<item>
<property name="text">
<string>Horizontal sketch axis</string>
</property>
</item>
<item>
<property name="text">
<string>Vertical sketch axis</string>
</property>
</item>
<item>
<property name="text">
<string>Base X axis</string>
</property>
</item>
<item>
<property name="text">
<string>Base Y axis</string>
</property>
</item>
<item>
<property name="text">
<string>Base Z axis</string>
</property>
</item>
<item>
<property name="text">
<string>Select reference...</string>
</property>
</item>
</widget>
</item> </item>
</layout> </layout>
</item> </item>

View File

@ -125,6 +125,17 @@ void TaskMirroredParameters::setupUI()
// --------------------- // ---------------------
ui->comboPlane->setEnabled(true); ui->comboPlane->setEnabled(true);
App::DocumentObject* sketch = getSketchObject();
if (sketch) {
ui->comboPlane->addItem(QString::fromAscii("Horizontal sketch axis"));
ui->comboPlane->addItem(QString::fromAscii("Vertical sketch axis"));
}
//add the base axes to the selection combo box
ui->comboPlane->addItem(QString::fromAscii("Base XY axis"));
ui->comboPlane->addItem(QString::fromAscii("Base XZ axis"));
ui->comboPlane->addItem(QString::fromAscii("Base YZ axis"));
ui->comboPlane->addItem(QString::fromAscii("Select reference..."));
updateUI(); updateUI();
//show the parts coordinate system axis for selection //show the parts coordinate system axis for selection
@ -156,11 +167,13 @@ void TaskMirroredParameters::updateUI()
// Add user-defined sketch axes to the reference selection combo box // Add user-defined sketch axes to the reference selection combo box
App::DocumentObject* sketch = getSketchObject(); App::DocumentObject* sketch = getSketchObject();
int maxcount=5; int maxcount=3;
if (sketch) if (sketch) {
maxcount = 5;
maxcount += static_cast<Part::Part2DObject*>(sketch)->getAxisCount(); maxcount += static_cast<Part::Part2DObject*>(sketch)->getAxisCount();
}
for (int i=ui->comboPlane->count()-1; i >= 5; i--) for (int i=ui->comboPlane->count()-1; i >= (sketch ? 5 : 3); i--)
ui->comboPlane->removeItem(i); ui->comboPlane->removeItem(i);
for (int i=ui->comboPlane->count(); i < maxcount; i++) for (int i=ui->comboPlane->count(); i < maxcount; i++)
ui->comboPlane->addItem(QString::fromLatin1("Sketch axis %1").arg(i-5)); ui->comboPlane->addItem(QString::fromLatin1("Sketch axis %1").arg(i-5));
@ -172,13 +185,13 @@ void TaskMirroredParameters::updateUI()
else if (mirrorPlanes.front() == "V_Axis") else if (mirrorPlanes.front() == "V_Axis")
ui->comboPlane->setCurrentIndex(1); ui->comboPlane->setCurrentIndex(1);
else if (strcmp(mirrorPlaneFeature->getNameInDocument(), App::Part::BaseplaneTypes[0]) == 0) else if (strcmp(mirrorPlaneFeature->getNameInDocument(), App::Part::BaseplaneTypes[0]) == 0)
ui->comboPlane->setCurrentIndex(2); ui->comboPlane->setCurrentIndex((sketch ? 2 : 0));
else if (strcmp(mirrorPlaneFeature->getNameInDocument(), App::Part::BaseplaneTypes[1]) == 0) else if (strcmp(mirrorPlaneFeature->getNameInDocument(), App::Part::BaseplaneTypes[1]) == 0)
ui->comboPlane->setCurrentIndex(3); ui->comboPlane->setCurrentIndex((sketch ? 3 : 1));
else if (strcmp(mirrorPlaneFeature->getNameInDocument(), App::Part::BaseplaneTypes[2]) == 0) else if (strcmp(mirrorPlaneFeature->getNameInDocument(), App::Part::BaseplaneTypes[2]) == 0)
ui->comboPlane->setCurrentIndex(4); ui->comboPlane->setCurrentIndex((sketch ? 4 : 2));
else if (mirrorPlanes.front().size() > 4 && mirrorPlanes.front().substr(0,4) == "Axis") { else if (mirrorPlanes.front().size() > (sketch ? 4 : 2) && mirrorPlanes.front().substr(0,4) == "Axis") {
int pos = 5 + std::atoi(mirrorPlanes.front().substr(4,4000).c_str()); int pos = (sketch ? 5 : 3) + std::atoi(mirrorPlanes.front().substr(4,4000).c_str());
if (pos <= maxcount) if (pos <= maxcount)
ui->comboPlane->setCurrentIndex(pos); ui->comboPlane->setCurrentIndex(pos);
else else
@ -228,9 +241,11 @@ void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg
} }
else { else {
App::DocumentObject* sketch = getSketchObject(); App::DocumentObject* sketch = getSketchObject();
int maxcount=5; int maxcount=3;
if (sketch) if (sketch) {
maxcount = 5;
maxcount += static_cast<Part::Part2DObject*>(sketch)->getAxisCount(); maxcount += static_cast<Part::Part2DObject*>(sketch)->getAxisCount();
}
for (int i=ui->comboPlane->count()-1; i >= maxcount; i--) for (int i=ui->comboPlane->count()-1; i >= maxcount; i--)
ui->comboPlane->removeItem(i); ui->comboPlane->removeItem(i);
@ -270,35 +285,39 @@ void TaskMirroredParameters::onPlaneChanged(int num) {
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject()); PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
App::DocumentObject* pcSketch = getSketchObject(); App::DocumentObject* pcSketch = getSketchObject();
int maxcount=5; int maxcount=3;
if (pcSketch) if (pcSketch) {
maxcount = 5;
maxcount += static_cast<Part::Part2DObject*>(pcSketch)->getAxisCount(); maxcount += static_cast<Part::Part2DObject*>(pcSketch)->getAxisCount();
}
if (num == 0) { if(pcSketch) {
pcMirrored->MirrorPlane.setValue(pcSketch, std::vector<std::string>(1,"H_Axis")); if (num == 0) {
exitSelectionMode(); pcMirrored->MirrorPlane.setValue(pcSketch, std::vector<std::string>(1,"H_Axis"));
exitSelectionMode();
}
else if (num == 1) {
pcMirrored->MirrorPlane.setValue(pcSketch, std::vector<std::string>(1,"V_Axis"));
exitSelectionMode();
}
} }
else if (num == 1) { if (num == (pcSketch ? 2 : 0)) {
pcMirrored->MirrorPlane.setValue(pcSketch, std::vector<std::string>(1,"V_Axis"));
exitSelectionMode();
}
else if (num == 2) {
pcMirrored->MirrorPlane.setValue(getObject()->getDocument()->getObject(App::Part::BaseplaneTypes[0]), pcMirrored->MirrorPlane.setValue(getObject()->getDocument()->getObject(App::Part::BaseplaneTypes[0]),
std::vector<std::string>(1,"")); std::vector<std::string>(1,""));
exitSelectionMode(); exitSelectionMode();
} }
else if (num == 3) { else if (num == (pcSketch ? 3 : 1)) {
pcMirrored->MirrorPlane.setValue(getObject()->getDocument()->getObject(App::Part::BaseplaneTypes[1]), pcMirrored->MirrorPlane.setValue(getObject()->getDocument()->getObject(App::Part::BaseplaneTypes[1]),
std::vector<std::string>(1,"")); std::vector<std::string>(1,""));
exitSelectionMode(); exitSelectionMode();
} }
else if (num == 4) { else if (num == (pcSketch ? 4 : 2)) {
pcMirrored->MirrorPlane.setValue(getObject()->getDocument()->getObject(App::Part::BaseplaneTypes[2]), pcMirrored->MirrorPlane.setValue(getObject()->getDocument()->getObject(App::Part::BaseplaneTypes[2]),
std::vector<std::string>(1,"")); std::vector<std::string>(1,""));
exitSelectionMode(); exitSelectionMode();
} }
else if (num >= 5 && num < maxcount) { else if (num >= (pcSketch ? 5 : 3) && num < maxcount) {
QString buf = QString::fromUtf8("Axis%1").arg(num-5); QString buf = QString::fromUtf8("Axis%1").arg(num-(pcSketch ? 5 : 3));
std::string str = buf.toStdString(); std::string str = buf.toStdString();
pcMirrored->MirrorPlane.setValue(pcSketch, std::vector<std::string>(1,str)); pcMirrored->MirrorPlane.setValue(pcSketch, std::vector<std::string>(1,str));
exitSelectionMode(); exitSelectionMode();
@ -347,23 +366,27 @@ void TaskMirroredParameters::getMirrorPlane(App::DocumentObject*& obj, std::vect
{ {
obj = getSketchObject(); obj = getSketchObject();
sub = std::vector<std::string>(1,""); sub = std::vector<std::string>(1,"");
int maxcount=5; int maxcount=3;
if (obj) if (obj) {
maxcount = 5;
maxcount += static_cast<Part::Part2DObject*>(obj)->getAxisCount(); maxcount += static_cast<Part::Part2DObject*>(obj)->getAxisCount();
}
int num = ui->comboPlane->currentIndex(); int num = ui->comboPlane->currentIndex();
if (num == 0) if(obj) {
sub[0] = "H_Axis"; if (num == 0)
else if (num == 1) sub[0] = "H_Axis";
sub[0] = "V_Axis"; else if (num == 1)
else if (num == 2) sub[0] = "V_Axis";
}
if (num == (obj ? 2 : 0))
obj = getObject()->getDocument()->getObject(App::Part::BaseplaneTypes[0]); obj = getObject()->getDocument()->getObject(App::Part::BaseplaneTypes[0]);
else if (num == 3) else if (num == (obj ? 3 : 1))
obj = getObject()->getDocument()->getObject(App::Part::BaseplaneTypes[1]); obj = getObject()->getDocument()->getObject(App::Part::BaseplaneTypes[1]);
else if (num == 4) else if (num == (obj ? 4 : 2))
obj = getObject()->getDocument()->getObject(App::Part::BaseplaneTypes[2]); obj = getObject()->getDocument()->getObject(App::Part::BaseplaneTypes[2]);
else if (num >= 5 && num < maxcount) { else if (num >= (obj ? 5 : 3) && num < maxcount) {
QString buf = QString::fromUtf8("Axis%1").arg(num-5); QString buf = QString::fromUtf8("Axis%1").arg(num-(obj ? 5 : 3));
sub[0] = buf.toStdString(); sub[0] = buf.toStdString();
} else if (num == maxcount && ui->comboPlane->count() == maxcount + 2) { } else if (num == maxcount && ui->comboPlane->count() == maxcount + 2) {
QStringList parts = ui->comboPlane->currentText().split(QChar::fromAscii(':')); QStringList parts = ui->comboPlane->currentText().split(QChar::fromAscii(':'));

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>253</width> <width>253</width>
<height>235</height> <height>260</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -51,38 +51,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboPlane"> <widget class="QComboBox" name="comboPlane"/>
<item>
<property name="text">
<string>Horizontal sketch axis</string>
</property>
</item>
<item>
<property name="text">
<string>Vertical sketch axis</string>
</property>
</item>
<item>
<property name="text">
<string>Base plane XY</string>
</property>
</item>
<item>
<property name="text">
<string>Base plane XZ</string>
</property>
</item>
<item>
<property name="text">
<string>Base plane YZ</string>
</property>
</item>
<item>
<property name="text">
<string>Select reference...</string>
</property>
</item>
</widget>
</item> </item>
</layout> </layout>
</item> </item>

View File

@ -146,6 +146,16 @@ void TaskPolarPatternParameters::setupUI()
ui->checkReverse->setEnabled(true); ui->checkReverse->setEnabled(true);
ui->polarAngle->setEnabled(true); ui->polarAngle->setEnabled(true);
ui->spinOccurrences->setEnabled(true); ui->spinOccurrences->setEnabled(true);
App::DocumentObject* sketch = getSketchObject();
if (sketch) {
ui->comboAxis->addItem(QString::fromAscii("Normal sketch axis"));
}
//add the base axes to the selection combo box
ui->comboAxis->addItem(QString::fromAscii("Base X axis"));
ui->comboAxis->addItem(QString::fromAscii("Base Y axis"));
ui->comboAxis->addItem(QString::fromAscii("Base Z axis"));
ui->comboAxis->addItem(QString::fromAscii("Select reference..."));
updateUI(); updateUI();
//show the parts coordinate system axis for selection //show the parts coordinate system axis for selection
@ -180,11 +190,13 @@ void TaskPolarPatternParameters::updateUI()
// Add user-defined sketch axes to the reference selection combo box // Add user-defined sketch axes to the reference selection combo box
App::DocumentObject* sketch = getSketchObject(); App::DocumentObject* sketch = getSketchObject();
int maxcount=1; int maxcount=3;
if (sketch) if (sketch) {
maxcount = 4;
maxcount += static_cast<Part::Part2DObject*>(sketch)->getAxisCount(); maxcount += static_cast<Part::Part2DObject*>(sketch)->getAxisCount();
}
for (int i=ui->comboAxis->count()-1; i >= 1; i--) for (int i=ui->comboAxis->count()-1; i >= (sketch ? 4 : 3); i--)
ui->comboAxis->removeItem(i); ui->comboAxis->removeItem(i);
for (int i=ui->comboAxis->count(); i < maxcount; i++) for (int i=ui->comboAxis->count(); i < maxcount; i++)
ui->comboAxis->addItem(QString::fromAscii("Sketch axis %1").arg(i-1)); ui->comboAxis->addItem(QString::fromAscii("Sketch axis %1").arg(i-1));
@ -193,14 +205,14 @@ void TaskPolarPatternParameters::updateUI()
if (axisFeature != NULL && !axes.empty()) { if (axisFeature != NULL && !axes.empty()) {
if (axes.front() == "N_Axis") { if (axes.front() == "N_Axis") {
ui->comboAxis->setCurrentIndex(0); ui->comboAxis->setCurrentIndex(0);
} else if (strcmp(axes.front().c_str(), App::Part::BaselineTypes[0]) == 0) { } else if (strcmp(axisFeature->getNameInDocument(), App::Part::BaselineTypes[0]) == 0) {
ui->comboAxis->setCurrentIndex(1); ui->comboAxis->setCurrentIndex((sketch ? 1 : 0));
} else if (strcmp(axes.front().c_str(), App::Part::BaselineTypes[1]) == 0) { } else if (strcmp(axisFeature->getNameInDocument(), App::Part::BaselineTypes[1]) == 0) {
ui->comboAxis->setCurrentIndex(2); ui->comboAxis->setCurrentIndex((sketch ? 2 : 1));
} else if (strcmp(axes.front().c_str(), App::Part::BaselineTypes[2]) == 0) { } else if (strcmp(axisFeature->getNameInDocument(), App::Part::BaselineTypes[2]) == 0) {
ui->comboAxis->setCurrentIndex(3); ui->comboAxis->setCurrentIndex((sketch ? 3 : 2));
} else if (axes.front().size() > 4 && axes.front().substr(0,4) == "Axis") { } else if (axes.front().size() > (sketch ? 4 : 3) && axes.front().substr(0,4) == "Axis") {
int pos = 4 + std::atoi(axes.front().substr(4,4000).c_str()); int pos = (sketch ? 4 : 3) + std::atoi(axes.front().substr(4,4000).c_str());
if (pos <= maxcount) if (pos <= maxcount)
ui->comboAxis->setCurrentIndex(pos); ui->comboAxis->setCurrentIndex(pos);
else else
@ -338,16 +350,35 @@ void TaskPolarPatternParameters::onAxisChanged(int num) {
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject()); PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
App::DocumentObject* pcSketch = getSketchObject(); App::DocumentObject* pcSketch = getSketchObject();
int maxcount=1; int maxcount=3;
if (pcSketch) if (pcSketch) {
maxcount = 4;
maxcount += static_cast<Part::Part2DObject*>(pcSketch)->getAxisCount(); maxcount += static_cast<Part::Part2DObject*>(pcSketch)->getAxisCount();
}
if (num == 0) { if(pcSketch) {
pcPolarPattern->Axis.setValue(getSketchObject(), std::vector<std::string>(1,"N_Axis")); if (num == 0) {
pcPolarPattern->Axis.setValue(getSketchObject(), std::vector<std::string>(1,"N_Axis"));
exitSelectionMode();
}
}
if (num == (pcSketch ? 1 : 0)) {
pcPolarPattern->Axis.setValue(getObject()->getDocument()->getObject(App::Part::BaselineTypes[0]),
std::vector<std::string>(1,""));
exitSelectionMode(); exitSelectionMode();
} }
else if (num >= 1 && num < maxcount) { else if (num == (pcSketch ? 2 : 1)) {
QString buf = QString::fromUtf8("Axis%1").arg(num-1); pcPolarPattern->Axis.setValue(getObject()->getDocument()->getObject(App::Part::BaselineTypes[1]),
std::vector<std::string>(1,""));
exitSelectionMode();
}
else if (num == (pcSketch ? 3 : 2)) {
pcPolarPattern->Axis.setValue(getObject()->getDocument()->getObject(App::Part::BaselineTypes[2]),
std::vector<std::string>(1,""));
exitSelectionMode();
}
else if (num >= (pcSketch ? 4 : 3) && num < maxcount) {
QString buf = QString::fromUtf8("Axis%1").arg(num-(pcSketch ? 4 : 3));
std::string str = buf.toStdString(); std::string str = buf.toStdString();
pcPolarPattern->Axis.setValue(pcSketch, std::vector<std::string>(1,str)); pcPolarPattern->Axis.setValue(pcSketch, std::vector<std::string>(1,str));
exitSelectionMode(); exitSelectionMode();
@ -360,7 +391,7 @@ void TaskPolarPatternParameters::onAxisChanged(int num) {
Gui::Selection().clearSelection(); Gui::Selection().clearSelection();
addReferenceSelectionGate(true, false); addReferenceSelectionGate(true, false);
} }
else if (num == 1) else if (num == maxcount)
exitSelectionMode(); exitSelectionMode();
kickUpdateViewTimer(); kickUpdateViewTimer();
@ -400,16 +431,28 @@ void TaskPolarPatternParameters::getAxis(App::DocumentObject*& obj, std::vector<
obj = getSketchObject(); obj = getSketchObject();
sub = std::vector<std::string>(1,""); sub = std::vector<std::string>(1,"");
int maxcount=1; int maxcount=1;
if (obj) if (obj) {
maxcount = 4;
maxcount += static_cast<Part::Part2DObject*>(obj)->getAxisCount(); maxcount += static_cast<Part::Part2DObject*>(obj)->getAxisCount();
}
int num = ui->comboAxis->currentIndex(); int num = ui->comboAxis->currentIndex();
if (ui->comboAxis->currentIndex() == 0) { if(obj) {
sub[0] = "N_Axis"; if (ui->comboAxis->currentIndex() == 0) {
} else if (num >= 1 && num < maxcount) { sub[0] = "N_Axis";
QString buf = QString::fromUtf8("Axis%1").arg(num-1); }
}
if (num == (obj ? 1 : 0))
obj = getObject()->getDocument()->getObject(App::Part::BaselineTypes[0]);
else if (num == (obj ? 2 : 1))
obj = getObject()->getDocument()->getObject(App::Part::BaselineTypes[1]);
else if (num == (obj ? 3 : 2))
obj = getObject()->getDocument()->getObject(App::Part::BaselineTypes[2]);
else if (num >= (obj ? 4 : 3) && num < maxcount) {
QString buf = QString::fromUtf8("Axis%1").arg(num-(obj ? 4 : 3));
sub[0] = buf.toStdString(); sub[0] = buf.toStdString();
} else if (num == maxcount && ui->comboAxis->count() == maxcount + 2) { }
else if (num == maxcount && ui->comboAxis->count() == maxcount + 2) {
QStringList parts = ui->comboAxis->currentText().split(QChar::fromAscii(':')); QStringList parts = ui->comboAxis->currentText().split(QChar::fromAscii(':'));
obj = getObject()->getDocument()->getObject(parts[0].toStdString().c_str()); obj = getObject()->getDocument()->getObject(parts[0].toStdString().c_str());
if (parts.size() > 1) if (parts.size() > 1)

View File

@ -51,33 +51,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboAxis"> <widget class="QComboBox" name="comboAxis"/>
<item>
<property name="text">
<string>Normal sketch axis</string>
</property>
</item>
<item>
<property name="text">
<string>Base X axis</string>
</property>
</item>
<item>
<property name="text">
<string>Base Y axis</string>
</property>
</item>
<item>
<property name="text">
<string>Base Z axis</string>
</property>
</item>
<item>
<property name="text">
<string>Select reference...</string>
</property>
</item>
</widget>
</item> </item>
</layout> </layout>
</item> </item>