PartDesign: Custom sketch axes as references in linear pattern and mirrored feature

This commit is contained in:
logari81
2013-02-07 21:04:00 +01:00
parent 60ccb19ddc
commit 9907c09efd
2 changed files with 112 additions and 26 deletions
@@ -128,25 +128,42 @@ void TaskMirroredParameters::updateUI()
App::DocumentObject* mirrorPlaneFeature = pcMirrored->MirrorPlane.getValue();
std::vector<std::string> mirrorPlanes = pcMirrored->MirrorPlane.getSubValues();
App::DocumentObject* sketch = getSketchObject();
int maxcount=2;
if (sketch)
maxcount += static_cast<Part::Part2DObject*>(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<Part::Part2DObject*>(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<PartDesign::Mirrored*>(getObject());
App::DocumentObject* pcSketch = getSketchObject();
int maxcount=2;
if (pcSketch)
maxcount += static_cast<Part::Part2DObject*>(pcSketch)->getAxisCount();
if (num == 0) {
pcMirrored->MirrorPlane.setValue(getSketchObject(), std::vector<std::string>(1,"H_Axis"));
pcMirrored->MirrorPlane.setValue(pcSketch, std::vector<std::string>(1,"H_Axis"));
exitSelectionMode();
}
else if (num == 1) {
pcMirrored->MirrorPlane.setValue(getSketchObject(), std::vector<std::string>(1,"V_Axis"));
pcMirrored->MirrorPlane.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();
pcMirrored->MirrorPlane.setValue(pcSketch, std::vector<std::string>(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<std::string> 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<Part::Part2DObject*>(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()));