From 9907c09efdd469dc18dc0da82ae7847b3c1a635f Mon Sep 17 00:00:00 2001 From: logari81 Date: Fri, 18 Jan 2013 09:55:59 +0100 Subject: [PATCH] PartDesign: Custom sketch axes as references in linear pattern and mirrored feature --- .../Gui/TaskLinearPatternParameters.cpp | 69 +++++++++++++++---- .../PartDesign/Gui/TaskMirroredParameters.cpp | 69 +++++++++++++++---- 2 files changed, 112 insertions(+), 26 deletions(-) diff --git a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp index 593550285..0588b2785 100644 --- a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp @@ -140,25 +140,42 @@ void TaskLinearPatternParameters::updateUI() double length = pcLinearPattern->Length.getValue(); unsigned occurrences = pcLinearPattern->Occurrences.getValue(); + App::DocumentObject* sketch = getSketchObject(); + int maxcount=2; + if (sketch) + maxcount += static_cast(sketch)->getAxisCount(); + for (int i=ui->comboDirection->count()-1; i >= 2; i--) ui->comboDirection->removeItem(i); + for (int i=ui->comboDirection->count(); i < maxcount; i++) + ui->comboDirection->addItem(QString::fromAscii("Sketch axis %1").arg(i-2)); + bool undefined = false; if (directionFeature != NULL && !directions.empty()) { if (directions.front() == "H_Axis") ui->comboDirection->setCurrentIndex(0); else if (directions.front() == "V_Axis") ui->comboDirection->setCurrentIndex(1); - else if (directionFeature != NULL && !directions.empty()) { + else if (directions.front().size() > 4 && directions.front().substr(0,4) == "Axis") { + int pos = 2 + std::atoi(directions.front().substr(4,4000).c_str()); + if (pos <= maxcount) + ui->comboDirection->setCurrentIndex(pos); + else + undefined = true; + } else if (directionFeature != NULL && !directions.empty()) { ui->comboDirection->addItem(QString::fromAscii(directions.front().c_str())); - ui->comboDirection->setCurrentIndex(2); + ui->comboDirection->setCurrentIndex(maxcount); } } else { - // Error message? + undefined = true; } if (referenceSelectionMode) { ui->comboDirection->addItem(tr("Select an edge or a face")); ui->comboDirection->setCurrentIndex(ui->comboDirection->count() - 1); + } else if (undefined) { + ui->comboDirection->addItem(tr("Undefined")); + ui->comboDirection->setCurrentIndex(ui->comboDirection->count() - 1); } else ui->comboDirection->addItem(tr("Select reference...")); @@ -198,11 +215,15 @@ void TaskLinearPatternParameters::onSelectionChanged(const Gui::SelectionChanges updateUI(); } else { - for (int i=ui->comboDirection->count()-1; i >= 2; i--) + App::DocumentObject* sketch = getSketchObject(); + int maxcount=2; + if (sketch) + maxcount += static_cast(sketch)->getAxisCount(); + for (int i=ui->comboDirection->count()-1; i >= maxcount; i--) ui->comboDirection->removeItem(i); ui->comboDirection->addItem(QString::fromAscii(subName.c_str())); - ui->comboDirection->setCurrentIndex(2); + ui->comboDirection->setCurrentIndex(maxcount); ui->comboDirection->addItem(tr("Select reference...")); } } @@ -247,14 +268,24 @@ void TaskLinearPatternParameters::onDirectionChanged(int num) { return; PartDesign::LinearPattern* pcLinearPattern = static_cast(getObject()); + App::DocumentObject* pcSketch = getSketchObject(); + int maxcount=2; + if (pcSketch) + maxcount += static_cast(pcSketch)->getAxisCount(); + if (num == 0) { - pcLinearPattern->Direction.setValue(getSketchObject(), std::vector(1,"H_Axis")); + pcLinearPattern->Direction.setValue(pcSketch, std::vector(1,"H_Axis")); exitSelectionMode(); } else if (num == 1) { - pcLinearPattern->Direction.setValue(getSketchObject(), std::vector(1,"V_Axis")); + pcLinearPattern->Direction.setValue(pcSketch, std::vector(1,"V_Axis")); exitSelectionMode(); } + else if (num >= 2 && num < maxcount) { + QString buf = QString::fromUtf8("Axis%1").arg(num-2); + std::string str = buf.toStdString(); + pcLinearPattern->Direction.setValue(pcSketch, std::vector(1,str)); + } else if (num == ui->comboDirection->count() - 1) { // enter reference selection mode hideObject(); @@ -263,7 +294,7 @@ void TaskLinearPatternParameters::onDirectionChanged(int num) { Gui::Selection().clearSelection(); addReferenceSelectionGate(true, true); } - else if (num == 2) + else if (num == maxcount) exitSelectionMode(); updateUI(); @@ -280,7 +311,8 @@ void TaskLinearPatternParameters::onUpdateView(bool on) std::string direction = getDirection(); if (!direction.empty()) { std::vector directions(1,direction); - if (direction == "H_Axis" || direction == "V_Axis") + if (direction == "H_Axis" || direction == "V_Axis" || + (direction.size() > 4 && direction.substr(0,4) == "Axis")) pcLinearPattern->Direction.setValue(getSketchObject(), directions); else pcLinearPattern->Direction.setValue(getSupportObject(), directions); @@ -297,11 +329,21 @@ void TaskLinearPatternParameters::onUpdateView(bool on) const std::string TaskLinearPatternParameters::getDirection(void) const { - if (ui->comboDirection->currentIndex() == 0) + App::DocumentObject* pcSketch = getSketchObject(); + int maxcount=2; + if (pcSketch) + maxcount += static_cast(pcSketch)->getAxisCount(); + + int num = ui->comboDirection->currentIndex(); + if (num == 0) return "H_Axis"; - else if (ui->comboDirection->currentIndex() == 1) + else if (num == 1) return "V_Axis"; - else if (ui->comboDirection->count() > 3 && ui->comboDirection->currentIndex() == 2) + else if (num >= 2 && num < maxcount) { + QString buf = QString::fromUtf8("Axis%1").arg(num-2); + return buf.toStdString(); + } else if (num == maxcount && + ui->comboDirection->count() == maxcount + 2) return ui->comboDirection->currentText().toStdString(); return std::string(""); } @@ -365,7 +407,8 @@ bool TaskDlgLinearPatternParameters::accept() std::string direction = linearpatternParameter->getDirection(); if (!direction.empty()) { QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])"); - if (direction == "H_Axis" || direction == "V_Axis") + if (direction == "H_Axis" || direction == "V_Axis" || + (direction.size() > 4 && direction.substr(0,4) == "Axis")) buf = buf.arg(QString::fromUtf8(linearpatternParameter->getSketchObject()->getNameInDocument())); else buf = buf.arg(QString::fromUtf8(linearpatternParameter->getSupportObject()->getNameInDocument())); diff --git a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp index f4945d918..59fda6d98 100644 --- a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp @@ -128,25 +128,42 @@ void TaskMirroredParameters::updateUI() App::DocumentObject* mirrorPlaneFeature = pcMirrored->MirrorPlane.getValue(); std::vector mirrorPlanes = pcMirrored->MirrorPlane.getSubValues(); + App::DocumentObject* sketch = getSketchObject(); + int maxcount=2; + if (sketch) + maxcount += static_cast(sketch)->getAxisCount(); + for (int i=ui->comboPlane->count()-1; i >= 2; i--) ui->comboPlane->removeItem(i); + for (int i=ui->comboPlane->count(); i < maxcount; i++) + ui->comboPlane->addItem(QString::fromAscii("Sketch axis %1").arg(i-2)); + bool undefined = false; if (mirrorPlaneFeature != NULL && !mirrorPlanes.empty()) { if (mirrorPlanes.front() == "H_Axis") ui->comboPlane->setCurrentIndex(0); else if (mirrorPlanes.front() == "V_Axis") ui->comboPlane->setCurrentIndex(1); - else if (mirrorPlaneFeature != NULL && !mirrorPlanes.empty()) { + else if (mirrorPlanes.front().size() > 4 && mirrorPlanes.front().substr(0,4) == "Axis") { + int pos = 2 + std::atoi(mirrorPlanes.front().substr(4,4000).c_str()); + if (pos <= maxcount) + ui->comboPlane->setCurrentIndex(pos); + else + undefined = true; + } else if (mirrorPlaneFeature != NULL && !mirrorPlanes.empty()) { ui->comboPlane->addItem(QString::fromAscii(mirrorPlanes.front().c_str())); - ui->comboPlane->setCurrentIndex(2); + ui->comboPlane->setCurrentIndex(maxcount); } } else { - // Error message? + undefined = true; } if (referenceSelectionMode) { ui->comboPlane->addItem(tr("Select a face")); ui->comboPlane->setCurrentIndex(ui->comboPlane->count() - 1); + } else if (undefined) { + ui->comboPlane->addItem(tr("Undefined")); + ui->comboPlane->setCurrentIndex(ui->comboPlane->count() - 1); } else ui->comboPlane->addItem(tr("Select reference...")); @@ -179,11 +196,15 @@ void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg updateUI(); } else { - for (int i=ui->comboPlane->count()-1; i >= 2; i--) + App::DocumentObject* sketch = getSketchObject(); + int maxcount=2; + if (sketch) + maxcount += static_cast(sketch)->getAxisCount(); + for (int i=ui->comboPlane->count()-1; i >= maxcount; i--) ui->comboPlane->removeItem(i); ui->comboPlane->addItem(QString::fromAscii(subName.c_str())); - ui->comboPlane->setCurrentIndex(2); + ui->comboPlane->setCurrentIndex(maxcount); ui->comboPlane->addItem(tr("Select reference...")); } } @@ -195,14 +216,24 @@ void TaskMirroredParameters::onPlaneChanged(int num) { return; PartDesign::Mirrored* pcMirrored = static_cast(getObject()); + App::DocumentObject* pcSketch = getSketchObject(); + int maxcount=2; + if (pcSketch) + maxcount += static_cast(pcSketch)->getAxisCount(); + if (num == 0) { - pcMirrored->MirrorPlane.setValue(getSketchObject(), std::vector(1,"H_Axis")); + pcMirrored->MirrorPlane.setValue(pcSketch, std::vector(1,"H_Axis")); exitSelectionMode(); } else if (num == 1) { - pcMirrored->MirrorPlane.setValue(getSketchObject(), std::vector(1,"V_Axis")); + pcMirrored->MirrorPlane.setValue(pcSketch, std::vector(1,"V_Axis")); exitSelectionMode(); } + else if (num >= 2 && num < maxcount) { + QString buf = QString::fromUtf8("Axis%1").arg(num-2); + std::string str = buf.toStdString(); + pcMirrored->MirrorPlane.setValue(pcSketch, std::vector(1,str)); + } else if (num == ui->comboPlane->count() - 1) { // enter reference selection mode hideObject(); @@ -211,7 +242,7 @@ void TaskMirroredParameters::onPlaneChanged(int num) { Gui::Selection().clearSelection(); addReferenceSelectionGate(false, true); } - else if (num == 2) + else if (num == maxcount) exitSelectionMode(); updateUI(); @@ -228,7 +259,8 @@ void TaskMirroredParameters::onUpdateView(bool on) std::string mirrorPlane = getMirrorPlane(); if (!mirrorPlane.empty()) { std::vector planes(1,mirrorPlane); - if (mirrorPlane == "H_Axis" || mirrorPlane == "V_Axis") + if (mirrorPlane == "H_Axis" || mirrorPlane == "V_Axis" || + (mirrorPlane.size() > 4 && mirrorPlane.substr(0,4) == "Axis")) pcMirrored->MirrorPlane.setValue(getSketchObject(),planes); else pcMirrored->MirrorPlane.setValue(getSupportObject(),planes); @@ -241,11 +273,21 @@ void TaskMirroredParameters::onUpdateView(bool on) const std::string TaskMirroredParameters::getMirrorPlane(void) const { - if (ui->comboPlane->currentIndex() == 0) + App::DocumentObject* pcSketch = getSketchObject(); + int maxcount=2; + if (pcSketch) + maxcount += static_cast(pcSketch)->getAxisCount(); + + int num = ui->comboPlane->currentIndex(); + if (num == 0) return "H_Axis"; - else if (ui->comboPlane->currentIndex() == 1) + else if (num == 1) return "V_Axis"; - else if (ui->comboPlane->count() > 3 && ui->comboPlane->currentIndex() == 2) + else if (num >= 2 && num < maxcount) { + QString buf = QString::fromUtf8("Axis%1").arg(num-2); + return buf.toStdString(); + } else if (num == maxcount && + ui->comboPlane->count() == maxcount + 2) return ui->comboPlane->currentText().toStdString(); return std::string(""); } @@ -293,7 +335,8 @@ bool TaskDlgMirroredParameters::accept() std::string mirrorPlane = mirrorParameter->getMirrorPlane(); if (!mirrorPlane.empty()) { QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])"); - if (mirrorPlane == "H_Axis" || mirrorPlane == "V_Axis") + if (mirrorPlane == "H_Axis" || mirrorPlane == "V_Axis" || + (mirrorPlane.size() > 4 && mirrorPlane.substr(0,4) == "Axis")) buf = buf.arg(QString::fromUtf8(mirrorParameter->getSketchObject()->getNameInDocument())); else buf = buf.arg(QString::fromUtf8(mirrorParameter->getSupportObject()->getNameInDocument()));