PartDesign: rework axis and plane comboboxes and make it work without part.
Rework combobox filling and link hadling for revolution and transformed features, in order to get rid of hard-coded item indexes and make the lists more dynamic.
This commit is contained in:
@@ -34,6 +34,8 @@
|
||||
#include "ReferenceSelection.h"
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/Part.h>
|
||||
#include <App/Plane.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
@@ -42,6 +44,7 @@
|
||||
#include <Base/Console.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/ViewProviderOrigin.h>
|
||||
#include <Mod/PartDesign/App/DatumPlane.h>
|
||||
#include <Mod/PartDesign/App/FeatureMirrored.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
@@ -118,16 +121,32 @@ void TaskMirroredParameters::setupUI()
|
||||
for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); ++i)
|
||||
{
|
||||
if ((*i) != NULL)
|
||||
<<<<<<< 9bd4990584bfddd638e710ece8d981c1d8e4cc5e
|
||||
ui->listWidgetFeatures->insertItem(0, QString::fromLatin1((*i)->getNameInDocument()));
|
||||
=======
|
||||
ui->listWidgetFeatures->addItem(QString::fromAscii((*i)->getNameInDocument()));
|
||||
>>>>>>> Fixed bugs in various features that reversed the list of selections
|
||||
ui->listWidgetFeatures->addItem(QString::fromLatin1((*i)->getNameInDocument()));
|
||||
}
|
||||
// ---------------------
|
||||
|
||||
this->planeLinks.setCombo(*(ui->comboPlane));
|
||||
ui->comboPlane->setEnabled(true);
|
||||
|
||||
|
||||
App::DocumentObject* sketch = getSketchObject();
|
||||
if (!sketch->isDerivedFrom(Part::Part2DObject::getClassTypeId()))
|
||||
sketch = 0;
|
||||
this->fillPlanesCombo(planeLinks,static_cast<Part::Part2DObject*>(sketch));
|
||||
|
||||
updateUI();
|
||||
|
||||
//show the parts coordinate system axis for selection
|
||||
App::Part* part = getPartFor(getObject(), false);
|
||||
if(part) {
|
||||
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
|
||||
if(!app_origin.empty()) {
|
||||
ViewProviderOrigin* origin;
|
||||
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0]));
|
||||
origin->setTemporaryVisibilityMode(true, Gui::Application::Instance->activeDocument());
|
||||
origin->setTemporaryVisibilityAxis(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TaskMirroredParameters::updateUI()
|
||||
@@ -138,34 +157,39 @@ void TaskMirroredParameters::updateUI()
|
||||
|
||||
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
|
||||
|
||||
<<<<<<< 05d084614fa15ead10b7283f4f36e3e587279953
|
||||
App::DocumentObject* mirrorPlaneFeature = pcMirrored->MirrorPlane.getValue();
|
||||
std::vector<std::string> mirrorPlanes = pcMirrored->MirrorPlane.getSubValues();
|
||||
|
||||
// Add user-defined sketch axes to the reference selection combo box
|
||||
App::DocumentObject* sketch = getSketchObject();
|
||||
int maxcount=5;
|
||||
if (sketch)
|
||||
int maxcount=3;
|
||||
if (sketch) {
|
||||
maxcount = 5;
|
||||
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);
|
||||
for (int i=ui->comboPlane->count(); i < maxcount; i++)
|
||||
ui->comboPlane->addItem(QString::fromLatin1("Sketch axis %1").arg(i-5));
|
||||
|
||||
bool undefined = false;
|
||||
if (mirrorPlaneFeature != NULL && !mirrorPlanes.empty()) {
|
||||
bool is_base_plane = mirrorPlaneFeature->isDerivedFrom(App::Plane::getClassTypeId());
|
||||
|
||||
if (mirrorPlanes.front() == "H_Axis")
|
||||
ui->comboPlane->setCurrentIndex(0);
|
||||
else if (mirrorPlanes.front() == "V_Axis")
|
||||
ui->comboPlane->setCurrentIndex(1);
|
||||
else if (strcmp(mirrorPlaneFeature->getNameInDocument(), PartDesignGui::BaseplaneNames[0]) == 0)
|
||||
ui->comboPlane->setCurrentIndex(2);
|
||||
else if (strcmp(mirrorPlaneFeature->getNameInDocument(), PartDesignGui::BaseplaneNames[1]) == 0)
|
||||
ui->comboPlane->setCurrentIndex(3);
|
||||
else if (strcmp(mirrorPlaneFeature->getNameInDocument(), PartDesignGui::BaseplaneNames[2]) == 0)
|
||||
ui->comboPlane->setCurrentIndex(4);
|
||||
else if (mirrorPlanes.front().size() > 4 && mirrorPlanes.front().substr(0,4) == "Axis") {
|
||||
int pos = 5 + std::atoi(mirrorPlanes.front().substr(4,4000).c_str());
|
||||
else if (is_base_plane && strcmp(static_cast<App::Plane*>(mirrorPlaneFeature)->PlaneType.getValue(), App::Part::BaseplaneTypes[0]) == 0)
|
||||
ui->comboPlane->setCurrentIndex((sketch ? 2 : 0));
|
||||
else if (is_base_plane && strcmp(static_cast<App::Plane*>(mirrorPlaneFeature)->PlaneType.getValue(), App::Part::BaseplaneTypes[1]) == 0)
|
||||
ui->comboPlane->setCurrentIndex((sketch ? 3 : 1));
|
||||
else if (is_base_plane && strcmp(static_cast<App::Plane*>(mirrorPlaneFeature)->PlaneType.getValue(), App::Part::BaseplaneTypes[2]) == 0)
|
||||
ui->comboPlane->setCurrentIndex((sketch ? 4 : 2));
|
||||
else if (mirrorPlanes.front().size() > (sketch ? 4 : 2) && mirrorPlanes.front().substr(0,4) == "Axis") {
|
||||
int pos = (sketch ? 5 : 3) + std::atoi(mirrorPlanes.front().substr(4,4000).c_str());
|
||||
if (pos <= maxcount)
|
||||
ui->comboPlane->setCurrentIndex(pos);
|
||||
else
|
||||
@@ -176,17 +200,14 @@ void TaskMirroredParameters::updateUI()
|
||||
}
|
||||
} else {
|
||||
undefined = true;
|
||||
=======
|
||||
if (planeLinks.setCurrentLink(pcMirrored->MirrorPlane) == -1){
|
||||
//failed to set current, because the link isnt in the list yet
|
||||
planeLinks.addLink(pcMirrored->MirrorPlane, getRefStr(pcMirrored->MirrorPlane.getValue(),pcMirrored->MirrorPlane.getSubValues()));
|
||||
planeLinks.setCurrentLink(pcMirrored->MirrorPlane);
|
||||
>>>>>>> PartDesign: rework axis and plane comboboxes and make it work without part.
|
||||
}
|
||||
|
||||
if (selectionMode == reference) {
|
||||
ui->comboPlane->addItem(tr("Select a face or datum plane"));
|
||||
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..."));
|
||||
|
||||
blockUpdate = false;
|
||||
}
|
||||
|
||||
@@ -196,43 +217,34 @@ void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg
|
||||
|
||||
if (originalSelected(msg)) {
|
||||
if (selectionMode == addFeature)
|
||||
<<<<<<< 9bd4990584bfddd638e710ece8d981c1d8e4cc5e
|
||||
ui->listWidgetFeatures->insertItem(0, QString::fromLatin1(msg.pObjectName));
|
||||
=======
|
||||
ui->listWidgetFeatures->addItem(QString::fromAscii(msg.pObjectName));
|
||||
>>>>>>> Fixed bugs in various features that reversed the list of selections
|
||||
ui->listWidgetFeatures->addItem(QString::fromLatin1(msg.pObjectName));
|
||||
else
|
||||
removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName);
|
||||
exitSelectionMode();
|
||||
} else if (selectionMode == reference) {
|
||||
// Note: ReferenceSelection has already checked the selection for validity
|
||||
exitSelectionMode();
|
||||
if (!blockUpdate) {
|
||||
std::vector<std::string> mirrorPlanes;
|
||||
App::DocumentObject* selObj;
|
||||
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
|
||||
getReferencedSelection(pcMirrored, msg, selObj, mirrorPlanes);
|
||||
pcMirrored->MirrorPlane.setValue(selObj, mirrorPlanes);
|
||||
|
||||
recomputeFeature();
|
||||
updateUI();
|
||||
}
|
||||
else {
|
||||
App::DocumentObject* sketch = getSketchObject();
|
||||
int maxcount=5;
|
||||
if (sketch)
|
||||
maxcount += static_cast<Part::Part2DObject*>(sketch)->getAxisCount();
|
||||
for (int i=ui->comboPlane->count()-1; i >= maxcount; i--)
|
||||
ui->comboPlane->removeItem(i);
|
||||
std::vector<std::string> mirrorPlanes;
|
||||
App::DocumentObject* selObj;
|
||||
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
|
||||
getReferencedSelection(pcMirrored, msg, selObj, mirrorPlanes);
|
||||
pcMirrored->MirrorPlane.setValue(selObj, mirrorPlanes);
|
||||
|
||||
std::vector<std::string> mirrorPlanes;
|
||||
App::DocumentObject* selObj;
|
||||
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
|
||||
getReferencedSelection(pcMirrored, msg, selObj, mirrorPlanes);
|
||||
ui->comboPlane->addItem(getRefStr(selObj, mirrorPlanes));
|
||||
ui->comboPlane->setCurrentIndex(maxcount);
|
||||
ui->comboPlane->addItem(tr("Select reference..."));
|
||||
}
|
||||
recomputeFeature();
|
||||
updateUI();
|
||||
} else if( strstr(msg.pObjectName, App::Part::BaseplaneTypes[0]) == nullptr ||
|
||||
strstr(msg.pObjectName, App::Part::BaseplaneTypes[1]) == nullptr ||
|
||||
strstr(msg.pObjectName, App::Part::BaseplaneTypes[2]) == nullptr) {
|
||||
|
||||
std::vector<std::string> planes;
|
||||
App::DocumentObject* selObj;
|
||||
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
|
||||
getReferencedSelection(pcMirrored, msg, selObj, planes);
|
||||
pcMirrored->MirrorPlane.setValue(selObj, planes);
|
||||
|
||||
recomputeFeature();
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,51 +259,21 @@ void TaskMirroredParameters::onPlaneChanged(int num) {
|
||||
if (blockUpdate)
|
||||
return;
|
||||
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
|
||||
|
||||
App::DocumentObject* pcSketch = getSketchObject();
|
||||
int maxcount=5;
|
||||
if (pcSketch)
|
||||
maxcount += static_cast<Part::Part2DObject*>(pcSketch)->getAxisCount();
|
||||
|
||||
if (num == 0) {
|
||||
pcMirrored->MirrorPlane.setValue(pcSketch, std::vector<std::string>(1,"H_Axis"));
|
||||
exitSelectionMode();
|
||||
try{
|
||||
if(planeLinks.getCurrentLink().getValue() == 0){
|
||||
// enter reference selection mode
|
||||
hideObject();
|
||||
showBase();
|
||||
selectionMode = reference;
|
||||
Gui::Selection().clearSelection();
|
||||
addReferenceSelectionGate(false, true);
|
||||
} else {
|
||||
exitSelectionMode();
|
||||
pcMirrored->MirrorPlane.Paste(planeLinks.getCurrentLink());
|
||||
}
|
||||
} catch (Base::Exception &e) {
|
||||
QMessageBox::warning(0,tr("Error"),QString::fromAscii(e.what()));
|
||||
}
|
||||
else if (num == 1) {
|
||||
pcMirrored->MirrorPlane.setValue(pcSketch, std::vector<std::string>(1,"V_Axis"));
|
||||
exitSelectionMode();
|
||||
}
|
||||
else if (num == 2) {
|
||||
pcMirrored->MirrorPlane.setValue(getObject()->getDocument()->getObject(PartDesignGui::BaseplaneNames[0]),
|
||||
std::vector<std::string>(1,""));
|
||||
exitSelectionMode();
|
||||
}
|
||||
else if (num == 3) {
|
||||
pcMirrored->MirrorPlane.setValue(getObject()->getDocument()->getObject(PartDesignGui::BaseplaneNames[1]),
|
||||
std::vector<std::string>(1,""));
|
||||
exitSelectionMode();
|
||||
}
|
||||
else if (num == 4) {
|
||||
pcMirrored->MirrorPlane.setValue(getObject()->getDocument()->getObject(PartDesignGui::BaseplaneNames[2]),
|
||||
std::vector<std::string>(1,""));
|
||||
exitSelectionMode();
|
||||
}
|
||||
else if (num >= 5 && num < maxcount) {
|
||||
QString buf = QString::fromUtf8("Axis%1").arg(num-5);
|
||||
std::string str = buf.toStdString();
|
||||
pcMirrored->MirrorPlane.setValue(pcSketch, std::vector<std::string>(1,str));
|
||||
exitSelectionMode();
|
||||
}
|
||||
else if (num == ui->comboPlane->count() - 1) {
|
||||
// enter reference selection mode
|
||||
hideObject();
|
||||
showBase();
|
||||
selectionMode = reference;
|
||||
Gui::Selection().clearSelection();
|
||||
addReferenceSelectionGate(false, true);
|
||||
}
|
||||
else if (num == maxcount)
|
||||
exitSelectionMode();
|
||||
|
||||
recomputeFeature();
|
||||
}
|
||||
@@ -322,36 +304,11 @@ void TaskMirroredParameters::onFeatureDeleted(void)
|
||||
recomputeFeature();
|
||||
}
|
||||
|
||||
void TaskMirroredParameters::getMirrorPlane(App::DocumentObject*& obj, std::vector<std::string>& sub) const
|
||||
void TaskMirroredParameters::getMirrorPlane(App::DocumentObject*& obj, std::vector<std::string> &sub) const
|
||||
{
|
||||
obj = getSketchObject();
|
||||
sub = std::vector<std::string>(1,"");
|
||||
int maxcount=5;
|
||||
if (obj)
|
||||
maxcount += static_cast<Part::Part2DObject*>(obj)->getAxisCount();
|
||||
|
||||
int num = ui->comboPlane->currentIndex();
|
||||
if (num == 0)
|
||||
sub[0] = "H_Axis";
|
||||
else if (num == 1)
|
||||
sub[0] = "V_Axis";
|
||||
else if (num == 2)
|
||||
obj = getObject()->getDocument()->getObject(PartDesignGui::BaseplaneNames[0]);
|
||||
else if (num == 3)
|
||||
obj = getObject()->getDocument()->getObject(PartDesignGui::BaseplaneNames[1]);
|
||||
else if (num == 4)
|
||||
obj = getObject()->getDocument()->getObject(PartDesignGui::BaseplaneNames[2]);
|
||||
else if (num >= 5 && num < maxcount) {
|
||||
QString buf = QString::fromUtf8("Axis%1").arg(num-5);
|
||||
sub[0] = buf.toStdString();
|
||||
} else if (num == maxcount && ui->comboPlane->count() == maxcount + 2) {
|
||||
QStringList parts = ui->comboPlane->currentText().split(QChar::fromAscii(':'));
|
||||
obj = getObject()->getDocument()->getObject(parts[0].toStdString().c_str());
|
||||
if (parts.size() > 1)
|
||||
sub[0] = parts[1].toStdString();
|
||||
} else {
|
||||
obj = NULL;
|
||||
}
|
||||
const App::PropertyLinkSub &lnk = planeLinks.getCurrentLink();
|
||||
obj = lnk.getValue();
|
||||
sub = lnk.getSubValues();
|
||||
}
|
||||
|
||||
void TaskMirroredParameters::apply()
|
||||
@@ -360,6 +317,18 @@ void TaskMirroredParameters::apply()
|
||||
|
||||
TaskMirroredParameters::~TaskMirroredParameters()
|
||||
{
|
||||
//hide the parts coordinate system axis for selection
|
||||
App::Part* part = getPartFor(getObject(), false);
|
||||
if(part) {
|
||||
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
|
||||
if(!app_origin.empty()) {
|
||||
ViewProviderOrigin* origin;
|
||||
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0]));
|
||||
origin->setTemporaryVisibilityMode(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
delete ui;
|
||||
if (proxy)
|
||||
delete proxy;
|
||||
@@ -401,10 +370,11 @@ bool TaskDlgMirroredParameters::accept()
|
||||
App::DocumentObject* obj;
|
||||
mirrorParameter->getMirrorPlane(obj, mirrorPlanes);
|
||||
std::string mirrorPlane = getPythonStr(obj, mirrorPlanes);
|
||||
if (!mirrorPlane.empty()) {
|
||||
if (!mirrorPlane.empty() && obj) {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = %s", name.c_str(), mirrorPlane.c_str());
|
||||
} else
|
||||
} else {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = None", name.c_str());
|
||||
}
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
|
||||
if (!TransformedView->getObject()->isValid())
|
||||
throw Base::Exception(TransformedView->getObject()->getStatusString());
|
||||
|
||||
Reference in New Issue
Block a user