Run precommit on TaskAttacher.cpp
This commit is contained in:
@@ -70,20 +70,23 @@ const QString makeRefString(const App::DocumentObject* obj, const std::string& s
|
||||
// App::Plane, Line or Datum feature
|
||||
return QString::fromLatin1(obj->getNameInDocument());
|
||||
|
||||
if ((sub.size() > 4) && (sub.substr(0,4) == "Face")) {
|
||||
if ((sub.size() > 4) && (sub.substr(0, 4) == "Face")) {
|
||||
int subId = std::atoi(&sub[4]);
|
||||
return QString::fromLatin1(obj->getNameInDocument()) + QString::fromLatin1(":") + QObject::tr("Face") + QString::number(subId);
|
||||
} else if ((sub.size() > 4) && (sub.substr(0,4) == "Edge")) {
|
||||
}
|
||||
else if ((sub.size() > 4) && (sub.substr(0, 4) == "Edge")) {
|
||||
int subId = std::atoi(&sub[4]);
|
||||
return QString::fromLatin1(obj->getNameInDocument()) + QString::fromLatin1(":") + QObject::tr("Edge") + QString::number(subId);
|
||||
} else if ((sub.size() > 6) && (sub.substr(0,6) == "Vertex")) {
|
||||
}
|
||||
else if ((sub.size() > 6) && (sub.substr(0, 6) == "Vertex")) {
|
||||
int subId = std::atoi(&sub[6]);
|
||||
return QString::fromLatin1(obj->getNameInDocument()) + QString::fromLatin1(":") + QObject::tr("Vertex") + QString::number(subId);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
//something else that face/edge/vertex. Can be empty string.
|
||||
return QString::fromLatin1(obj->getNameInDocument())
|
||||
+ (sub.length()>0 ? QString::fromLatin1(":") : QString())
|
||||
+ QString::fromLatin1(sub.c_str());
|
||||
+ (sub.length() > 0 ? QString::fromLatin1(":") : QString())
|
||||
+ QString::fromLatin1(sub.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,15 +101,16 @@ void TaskAttacher::makeRefStrings(std::vector<QString>& refstrings, std::vector<
|
||||
// for Origin or Datum features refnames is empty but we need a non-empty return value
|
||||
if (refnames[r].empty())
|
||||
refnames[r] = refs[r]->getNameInDocument();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
refstrings.push_back(QObject::tr("No reference selected"));
|
||||
refnames.emplace_back("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TaskAttacher::TaskAttacher(Gui::ViewProviderDocumentObject *ViewProvider, QWidget *parent,
|
||||
QString picture, QString text, TaskAttacher::VisibilityFunction visFunc)
|
||||
TaskAttacher::TaskAttacher(Gui::ViewProviderDocumentObject* ViewProvider, QWidget* parent,
|
||||
QString picture, QString text, TaskAttacher::VisibilityFunction visFunc)
|
||||
: TaskBox(Gui::BitmapFactory().pixmap(picture.toLatin1()), text, true, parent)
|
||||
, SelectionObserver(ViewProvider)
|
||||
, ViewProvider(ViewProvider)
|
||||
@@ -125,37 +129,37 @@ TaskAttacher::TaskAttacher(Gui::ViewProviderDocumentObject *ViewProvider, QWidge
|
||||
|
||||
// clang-format off
|
||||
connect(ui->attachmentOffsetX, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
|
||||
this, &TaskAttacher::onAttachmentOffsetXChanged);
|
||||
this, &TaskAttacher::onAttachmentOffsetXChanged);
|
||||
connect(ui->attachmentOffsetY, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
|
||||
this, &TaskAttacher::onAttachmentOffsetYChanged);
|
||||
this, &TaskAttacher::onAttachmentOffsetYChanged);
|
||||
connect(ui->attachmentOffsetZ, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
|
||||
this, &TaskAttacher::onAttachmentOffsetZChanged);
|
||||
this, &TaskAttacher::onAttachmentOffsetZChanged);
|
||||
connect(ui->attachmentOffsetYaw, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
|
||||
this, &TaskAttacher::onAttachmentOffsetYawChanged);
|
||||
this, &TaskAttacher::onAttachmentOffsetYawChanged);
|
||||
connect(ui->attachmentOffsetPitch, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
|
||||
this, &TaskAttacher::onAttachmentOffsetPitchChanged);
|
||||
this, &TaskAttacher::onAttachmentOffsetPitchChanged);
|
||||
connect(ui->attachmentOffsetRoll, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
|
||||
this, &TaskAttacher::onAttachmentOffsetRollChanged);
|
||||
this, &TaskAttacher::onAttachmentOffsetRollChanged);
|
||||
connect(ui->checkBoxFlip, &QCheckBox::toggled,
|
||||
this, &TaskAttacher::onCheckFlip);
|
||||
this, &TaskAttacher::onCheckFlip);
|
||||
connect(ui->buttonRef1, &QPushButton::clicked,
|
||||
this, &TaskAttacher::onButtonRef1);
|
||||
this, &TaskAttacher::onButtonRef1);
|
||||
connect(ui->lineRef1, &QLineEdit::textEdited,
|
||||
this, &TaskAttacher::onRefName1);
|
||||
this, &TaskAttacher::onRefName1);
|
||||
connect(ui->buttonRef2, &QPushButton::clicked,
|
||||
this, &TaskAttacher::onButtonRef2);
|
||||
this, &TaskAttacher::onButtonRef2);
|
||||
connect(ui->lineRef2, &QLineEdit::textEdited,
|
||||
this, &TaskAttacher::onRefName2);
|
||||
this, &TaskAttacher::onRefName2);
|
||||
connect(ui->buttonRef3, &QPushButton::clicked,
|
||||
this, &TaskAttacher::onButtonRef3);
|
||||
this, &TaskAttacher::onButtonRef3);
|
||||
connect(ui->lineRef3, &QLineEdit::textEdited,
|
||||
this, &TaskAttacher::onRefName3);
|
||||
this, &TaskAttacher::onRefName3);
|
||||
connect(ui->buttonRef4, &QPushButton::clicked,
|
||||
this, &TaskAttacher::onButtonRef4);
|
||||
this, &TaskAttacher::onButtonRef4);
|
||||
connect(ui->lineRef4, &QLineEdit::textEdited,
|
||||
this, &TaskAttacher::onRefName4);
|
||||
this, &TaskAttacher::onRefName4);
|
||||
connect(ui->listOfModes, &QListWidget::itemSelectionChanged,
|
||||
this, &TaskAttacher::onModeSelect);
|
||||
this, &TaskAttacher::onModeSelect);
|
||||
// clang-format on
|
||||
|
||||
this->groupLayout()->addWidget(proxy);
|
||||
@@ -205,19 +209,20 @@ TaskAttacher::TaskAttacher(Gui::ViewProviderDocumentObject *ViewProvider, QWidge
|
||||
this->iActiveRef = 0;
|
||||
else
|
||||
this->iActiveRef = -1;
|
||||
if (pcAttach->AttachmentSupport.getSize() == 0){
|
||||
if (pcAttach->AttachmentSupport.getSize() == 0) {
|
||||
autoNext = true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
autoNext = false;
|
||||
}
|
||||
|
||||
ui->attachmentOffsetX->bind(App::ObjectIdentifier::parse(ViewProvider->getObject(),std::string("AttachmentOffset.Base.x")));
|
||||
ui->attachmentOffsetY->bind(App::ObjectIdentifier::parse(ViewProvider->getObject(),std::string("AttachmentOffset.Base.y")));
|
||||
ui->attachmentOffsetZ->bind(App::ObjectIdentifier::parse(ViewProvider->getObject(),std::string("AttachmentOffset.Base.z")));
|
||||
ui->attachmentOffsetX->bind(App::ObjectIdentifier::parse(ViewProvider->getObject(), std::string("AttachmentOffset.Base.x")));
|
||||
ui->attachmentOffsetY->bind(App::ObjectIdentifier::parse(ViewProvider->getObject(), std::string("AttachmentOffset.Base.y")));
|
||||
ui->attachmentOffsetZ->bind(App::ObjectIdentifier::parse(ViewProvider->getObject(), std::string("AttachmentOffset.Base.z")));
|
||||
|
||||
ui->attachmentOffsetYaw->bind(App::ObjectIdentifier::parse(ViewProvider->getObject(),std::string("AttachmentOffset.Rotation.Yaw")));
|
||||
ui->attachmentOffsetPitch->bind(App::ObjectIdentifier::parse(ViewProvider->getObject(),std::string("AttachmentOffset.Rotation.Pitch")));
|
||||
ui->attachmentOffsetRoll->bind(App::ObjectIdentifier::parse(ViewProvider->getObject(),std::string("AttachmentOffset.Rotation.Roll")));
|
||||
ui->attachmentOffsetYaw->bind(App::ObjectIdentifier::parse(ViewProvider->getObject(), std::string("AttachmentOffset.Rotation.Yaw")));
|
||||
ui->attachmentOffsetPitch->bind(App::ObjectIdentifier::parse(ViewProvider->getObject(), std::string("AttachmentOffset.Rotation.Pitch")));
|
||||
ui->attachmentOffsetRoll->bind(App::ObjectIdentifier::parse(ViewProvider->getObject(), std::string("AttachmentOffset.Rotation.Roll")));
|
||||
|
||||
visibilityAutomation(true);
|
||||
updateAttachmentOffsetUI();
|
||||
@@ -293,10 +298,11 @@ void TaskAttacher::updateReferencesUI()
|
||||
pcAttach->attacher().suggestMapModes(this->lastSuggestResult);
|
||||
|
||||
if (this->lastSuggestResult.message != SuggestResult::srOK) {
|
||||
if(!this->lastSuggestResult.nextRefTypeHint.empty()){
|
||||
if (!this->lastSuggestResult.nextRefTypeHint.empty()) {
|
||||
//message = "Need more references";
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
completed = true;
|
||||
}
|
||||
|
||||
@@ -314,24 +320,29 @@ bool TaskAttacher::updatePreview()
|
||||
Part::AttachExtension* pcAttach = ViewProvider->getObject()->getExtensionByType<Part::AttachExtension>();
|
||||
QString errMessage;
|
||||
bool attached = false;
|
||||
try{
|
||||
try {
|
||||
attached = pcAttach->positionBySupport();
|
||||
} catch (Base::Exception &err){
|
||||
}
|
||||
catch (Base::Exception& err) {
|
||||
errMessage = QCoreApplication::translate("Exception", err.what());
|
||||
} catch (Standard_Failure &err){
|
||||
}
|
||||
catch (Standard_Failure& err) {
|
||||
errMessage = tr("OCC error: %1").arg(QString::fromLatin1(err.GetMessageString()));
|
||||
} catch (...) {
|
||||
}
|
||||
catch (...) {
|
||||
errMessage = tr("unknown error");
|
||||
}
|
||||
if (errMessage.length()>0){
|
||||
if (errMessage.length() > 0) {
|
||||
ui->message->setText(tr("Attachment mode failed: %1").arg(errMessage));
|
||||
ui->message->setStyleSheet(QString::fromLatin1("QLabel{color: red;}"));
|
||||
} else {
|
||||
if (!attached){
|
||||
}
|
||||
else {
|
||||
if (!attached) {
|
||||
ui->message->setText(tr("Not attached"));
|
||||
ui->message->setStyleSheet(QString());
|
||||
} else {
|
||||
std::vector<QString> strs = AttacherGui::getUIStrings(pcAttach->attacher().getTypeId(),eMapMode(pcAttach->MapMode.getValue()));
|
||||
}
|
||||
else {
|
||||
std::vector<QString> strs = AttacherGui::getUIStrings(pcAttach->attacher().getTypeId(), eMapMode(pcAttach->MapMode.getValue()));
|
||||
ui->message->setText(tr("Attached with mode %1").arg(strs[0]));
|
||||
ui->message->setStyleSheet(QString::fromLatin1("QLabel{color: green;}"));
|
||||
}
|
||||
@@ -345,23 +356,25 @@ bool TaskAttacher::updatePreview()
|
||||
|
||||
QLineEdit* TaskAttacher::getLine(unsigned idx)
|
||||
{
|
||||
switch(idx) {
|
||||
case 0: return ui->lineRef1;
|
||||
case 1: return ui->lineRef2;
|
||||
case 2: return ui->lineRef3;
|
||||
case 3: return ui->lineRef4;
|
||||
default: return nullptr;
|
||||
switch (idx) {
|
||||
case 0: return ui->lineRef1;
|
||||
case 1: return ui->lineRef2;
|
||||
case 2: return ui->lineRef3;
|
||||
case 3: return ui->lineRef4;
|
||||
default: return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void TaskAttacher::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
{
|
||||
if (!ViewProvider)
|
||||
if (!ViewProvider) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
||||
if (iActiveRef < 0)
|
||||
if (iActiveRef < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Note: The validity checking has already been done in ReferenceSelection.cpp
|
||||
Part::AttachExtension* pcAttach = ViewProvider->getObject()->getExtensionByType<Part::AttachExtension>();
|
||||
@@ -374,18 +387,20 @@ void TaskAttacher::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
std::string subname = msg.pSubName;
|
||||
|
||||
// Remove subname for planes and datum features
|
||||
if (selObj->isDerivedFrom<App::DatumElement>() ||
|
||||
selObj->isDerivedFrom<Part::Datum>())
|
||||
if (selObj->isDerivedFrom<App::DatumElement>() || selObj->isDerivedFrom<Part::Datum>()) {
|
||||
subname = "";
|
||||
}
|
||||
|
||||
// eliminate duplicate selections
|
||||
for (size_t r = 0; r < refs.size(); r++)
|
||||
if ((refs[r] == selObj) && (refnames[r] == subname))
|
||||
for (size_t r = 0; r < refs.size(); r++) {
|
||||
if ((refs[r] == selObj) && (refnames[r] == subname)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (autoNext && iActiveRef > 0 && iActiveRef == static_cast<int>(refnames.size())){
|
||||
if (refs[iActiveRef-1] == selObj
|
||||
&& refnames[iActiveRef-1].length() != 0 && subname.length() == 0){
|
||||
if (autoNext && iActiveRef > 0 && iActiveRef == static_cast<int>(refnames.size())) {
|
||||
if (refs[iActiveRef - 1] == selObj
|
||||
&& refnames[iActiveRef - 1].length() != 0 && subname.length() == 0) {
|
||||
//A whole object was selected by clicking it twice. Fill it
|
||||
//into previous reference, where a sub-named reference filled by
|
||||
//the first click is already stored.
|
||||
@@ -396,7 +411,8 @@ void TaskAttacher::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
if (iActiveRef < static_cast<int>(refs.size())) {
|
||||
refs[iActiveRef] = selObj;
|
||||
refnames[iActiveRef] = subname;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
refs.push_back(selObj);
|
||||
refnames.push_back(subname);
|
||||
}
|
||||
@@ -406,17 +422,18 @@ void TaskAttacher::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
pcAttach->AttachmentSupport.setValues(refs, refnames);
|
||||
updateListOfModes();
|
||||
eMapMode mmode = getActiveMapMode();//will be mmDeactivated, if selected or if no modes are available
|
||||
if(mmode == mmDeactivated){
|
||||
if (mmode == mmDeactivated) {
|
||||
//error = true;
|
||||
this->completed = false;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this->completed = true;
|
||||
}
|
||||
pcAttach->MapMode.setValue(mmode);
|
||||
selectMapMode(mmode);
|
||||
updatePreview();
|
||||
}
|
||||
catch(Base::Exception& e) {
|
||||
catch (Base::Exception& e) {
|
||||
//error = true;
|
||||
ui->message->setText(QCoreApplication::translate("Exception", e.what()));
|
||||
ui->message->setStyleSheet(QString::fromLatin1("QLabel{color: red;}"));
|
||||
@@ -431,11 +448,13 @@ void TaskAttacher::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
}
|
||||
|
||||
if (autoNext) {
|
||||
if (iActiveRef == -1){
|
||||
if (iActiveRef == -1) {
|
||||
//nothing to do
|
||||
} else if (iActiveRef == 4 || this->lastSuggestResult.nextRefTypeHint.empty()){
|
||||
}
|
||||
else if (iActiveRef == 4 || this->lastSuggestResult.nextRefTypeHint.empty()) {
|
||||
iActiveRef = -1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
iActiveRef++;
|
||||
}
|
||||
}
|
||||
@@ -462,17 +481,17 @@ void TaskAttacher::onAttachmentOffsetChanged(double /*val*/, int idx)
|
||||
if (idx == 2) {
|
||||
pos.z = ui->attachmentOffsetZ->value().getValueAs(Base::Quantity::MilliMetre);
|
||||
}
|
||||
if (idx >= 0 && idx <= 2){
|
||||
if (idx >= 0 && idx <= 2) {
|
||||
pl.setPosition(pos);
|
||||
}
|
||||
|
||||
if (idx >= 3 && idx <= 5){
|
||||
if (idx >= 3 && idx <= 5) {
|
||||
double yaw, pitch, roll;
|
||||
yaw = ui->attachmentOffsetYaw->value().getValueAs(Base::Quantity::Degree);
|
||||
pitch = ui->attachmentOffsetPitch->value().getValueAs(Base::Quantity::Degree);
|
||||
roll = ui->attachmentOffsetRoll->value().getValueAs(Base::Quantity::Degree);
|
||||
Base::Rotation rot;
|
||||
rot.setYawPitchRoll(yaw,pitch,roll);
|
||||
rot.setYawPitchRoll(yaw, pitch, roll);
|
||||
pl.setRotation(rot);
|
||||
}
|
||||
|
||||
@@ -526,7 +545,8 @@ void TaskAttacher::onButtonRef(const bool checked, unsigned idx)
|
||||
if (checked) {
|
||||
Gui::Selection().clearSelection();
|
||||
iActiveRef = idx;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
iActiveRef = -1;
|
||||
}
|
||||
updateRefButton(0);
|
||||
@@ -619,12 +639,15 @@ void TaskAttacher::onRefName(const QString& text, unsigned idx)
|
||||
if (obj->isDerivedFrom<App::Plane>()) {
|
||||
// everything is OK (we assume a Part can only have exactly 3 App::Plane objects located at the base of the feature tree)
|
||||
subElement.clear();
|
||||
} else if (obj->isDerivedFrom<App::Line>()) {
|
||||
}
|
||||
else if (obj->isDerivedFrom<App::Line>()) {
|
||||
// everything is OK (we assume a Part can only have exactly 3 App::Line objects located at the base of the feature tree)
|
||||
subElement.clear();
|
||||
} else if (obj->isDerivedFrom<Part::Datum>()) {
|
||||
}
|
||||
else if (obj->isDerivedFrom<Part::Datum>()) {
|
||||
subElement.clear();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// TODO: check validity of the text that was entered: Does subElement actually reference to an element on the obj?
|
||||
|
||||
auto getSubshapeName = [](const QString& part) -> std::string {
|
||||
@@ -672,7 +695,8 @@ void TaskAttacher::onRefName(const QString& text, unsigned idx)
|
||||
if (idx < refs.size()) {
|
||||
refs[idx] = obj;
|
||||
refnames[idx] = subElement;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
refs.push_back(obj);
|
||||
refnames.emplace_back(subElement);
|
||||
}
|
||||
@@ -690,12 +714,12 @@ void TaskAttacher::updateRefButton(int idx)
|
||||
return;
|
||||
|
||||
QAbstractButton* b;
|
||||
switch(idx){
|
||||
case 0: b = ui->buttonRef1; break;
|
||||
case 1: b = ui->buttonRef2; break;
|
||||
case 2: b = ui->buttonRef3; break;
|
||||
case 3: b = ui->buttonRef4; break;
|
||||
default: throw Base::IndexError("button index out of range");
|
||||
switch (idx) {
|
||||
case 0: b = ui->buttonRef1; break;
|
||||
case 1: b = ui->buttonRef2; break;
|
||||
case 2: b = ui->buttonRef3; break;
|
||||
case 3: b = ui->buttonRef4; break;
|
||||
default: throw Base::IndexError("button index out of range");
|
||||
}
|
||||
|
||||
Part::AttachExtension* pcAttach = ViewProvider->getObject()->getExtensionByType<Part::AttachExtension>();
|
||||
@@ -713,10 +737,12 @@ void TaskAttacher::updateRefButton(int idx)
|
||||
|
||||
if (iActiveRef == idx) {
|
||||
b->setText(tr("Selecting..."));
|
||||
} else if (idx < static_cast<int>(this->lastSuggestResult.references_Types.size())){
|
||||
}
|
||||
else if (idx < static_cast<int>(this->lastSuggestResult.references_Types.size())) {
|
||||
b->setText(AttacherGui::getShapeTypeText(this->lastSuggestResult.references_Types[idx]));
|
||||
} else {
|
||||
b->setText(tr("Reference%1").arg(idx+1));
|
||||
}
|
||||
else {
|
||||
b->setText(tr("Reference%1").arg(idx + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -740,9 +766,9 @@ void TaskAttacher::updateAttachmentOffsetUI()
|
||||
ui->attachmentOffsetPitch->blockSignals(bBlock);
|
||||
ui->attachmentOffsetRoll->blockSignals(bBlock);
|
||||
|
||||
ui->attachmentOffsetX->setValue(Base::Quantity(pos.x,Base::Unit::Length));
|
||||
ui->attachmentOffsetY->setValue(Base::Quantity(pos.y,Base::Unit::Length));
|
||||
ui->attachmentOffsetZ->setValue(Base::Quantity(pos.z,Base::Unit::Length));
|
||||
ui->attachmentOffsetX->setValue(Base::Quantity(pos.x, Base::Unit::Length));
|
||||
ui->attachmentOffsetY->setValue(Base::Quantity(pos.y, Base::Unit::Length));
|
||||
ui->attachmentOffsetZ->setValue(Base::Quantity(pos.z, Base::Unit::Length));
|
||||
ui->attachmentOffsetYaw->setValue(yaw);
|
||||
ui->attachmentOffsetPitch->setValue(pitch);
|
||||
ui->attachmentOffsetRoll->setValue(roll);
|
||||
@@ -750,13 +776,13 @@ void TaskAttacher::updateAttachmentOffsetUI()
|
||||
auto expressions = ViewProvider->getObject()->ExpressionEngine.getExpressions();
|
||||
bool bRotationBound = false;
|
||||
bRotationBound = bRotationBound ||
|
||||
expressions.find(App::ObjectIdentifier::parse(ViewProvider->getObject(),std::string("AttachmentOffset.Rotation.Angle"))) != expressions.end();
|
||||
expressions.find(App::ObjectIdentifier::parse(ViewProvider->getObject(), std::string("AttachmentOffset.Rotation.Angle"))) != expressions.end();
|
||||
bRotationBound = bRotationBound ||
|
||||
expressions.find(App::ObjectIdentifier::parse(ViewProvider->getObject(),std::string("AttachmentOffset.Rotation.Axis.x"))) != expressions.end();
|
||||
expressions.find(App::ObjectIdentifier::parse(ViewProvider->getObject(), std::string("AttachmentOffset.Rotation.Axis.x"))) != expressions.end();
|
||||
bRotationBound = bRotationBound ||
|
||||
expressions.find(App::ObjectIdentifier::parse(ViewProvider->getObject(),std::string("AttachmentOffset.Rotation.Axis.y"))) != expressions.end();
|
||||
expressions.find(App::ObjectIdentifier::parse(ViewProvider->getObject(), std::string("AttachmentOffset.Rotation.Axis.y"))) != expressions.end();
|
||||
bRotationBound = bRotationBound ||
|
||||
expressions.find(App::ObjectIdentifier::parse(ViewProvider->getObject(),std::string("AttachmentOffset.Rotation.Axis.z"))) != expressions.end();
|
||||
expressions.find(App::ObjectIdentifier::parse(ViewProvider->getObject(), std::string("AttachmentOffset.Rotation.Axis.z"))) != expressions.end();
|
||||
|
||||
ui->attachmentOffsetYaw->setEnabled(!bRotationBound);
|
||||
ui->attachmentOffsetPitch->setEnabled(!bRotationBound);
|
||||
@@ -794,22 +820,23 @@ void TaskAttacher::updateListOfModes()
|
||||
this->lastSuggestResult.bestFitMode = mmDeactivated;
|
||||
size_t lastValidModeItemIndex = mmDummy_NumberOfModes;
|
||||
|
||||
if (pcAttach->AttachmentSupport.getSize() > 0){
|
||||
if (pcAttach->AttachmentSupport.getSize() > 0) {
|
||||
pcAttach->attacher().suggestMapModes(this->lastSuggestResult);
|
||||
modesInList = this->lastSuggestResult.allApplicableModes;
|
||||
modesInList.insert(modesInList.begin(), mmDeactivated); // always have the option to choose Deactivated mode
|
||||
|
||||
//add reachable modes to the list, too, but gray them out (using lastValidModeItemIndex, later)
|
||||
lastValidModeItemIndex = modesInList.size()-1;
|
||||
for(std::pair<const eMapMode, refTypeStringList> &rm: this->lastSuggestResult.reachableModes){
|
||||
lastValidModeItemIndex = modesInList.size() - 1;
|
||||
for (std::pair<const eMapMode, refTypeStringList>& rm : this->lastSuggestResult.reachableModes) {
|
||||
modesInList.push_back(rm.first);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
//no references - display all modes
|
||||
modesInList.clear();
|
||||
modesInList.push_back(mmDeactivated);
|
||||
|
||||
for( int mmode = 0 ; mmode < mmDummy_NumberOfModes ; mmode++){
|
||||
for (int mmode = 0; mmode < mmDummy_NumberOfModes; mmode++) {
|
||||
if (pcAttach->attacher().modeEnabled[mmode])
|
||||
modesInList.push_back(eMapMode(mmode));
|
||||
}
|
||||
@@ -820,40 +847,42 @@ void TaskAttacher::updateListOfModes()
|
||||
ui->listOfModes->clear();
|
||||
QListWidgetItem* iSelect = nullptr;
|
||||
if (!modesInList.empty()) {
|
||||
for (size_t i = 0 ; i < modesInList.size() ; ++i){
|
||||
for (size_t i = 0; i < modesInList.size(); ++i) {
|
||||
eMapMode mmode = modesInList[i];
|
||||
std::vector<QString> mstr = AttacherGui::getUIStrings(pcAttach->attacher().getTypeId(),mmode);
|
||||
std::vector<QString> mstr = AttacherGui::getUIStrings(pcAttach->attacher().getTypeId(), mmode);
|
||||
ui->listOfModes->addItem(mstr[0]);
|
||||
QListWidgetItem* item = ui->listOfModes->item(i);
|
||||
QString tooltip = mstr[1];
|
||||
|
||||
if (mmode != mmDeactivated) {
|
||||
tooltip += QString::fromLatin1("\n\n%1\n%2")
|
||||
.arg(tr("Reference combinations:"),
|
||||
AttacherGui::getRefListForMode(pcAttach->attacher(),mmode).join(QString::fromLatin1("\n")));
|
||||
.arg(tr("Reference combinations:"),
|
||||
AttacherGui::getRefListForMode(pcAttach->attacher(), mmode).join(QString::fromLatin1("\n")));
|
||||
}
|
||||
item->setToolTip(tooltip);
|
||||
|
||||
if (mmode == curMode && curMode != mmDeactivated)
|
||||
iSelect = ui->listOfModes->item(i);
|
||||
if (i > lastValidModeItemIndex){
|
||||
if (i > lastValidModeItemIndex) {
|
||||
//potential mode - can be reached by selecting more stuff
|
||||
item->setFlags(item->flags() & ~(Qt::ItemFlag::ItemIsEnabled | Qt::ItemFlag::ItemIsSelectable));
|
||||
|
||||
refTypeStringList &extraRefs = this->lastSuggestResult.reachableModes[mmode];
|
||||
if (extraRefs.size() == 1){
|
||||
refTypeStringList& extraRefs = this->lastSuggestResult.reachableModes[mmode];
|
||||
if (extraRefs.size() == 1) {
|
||||
QStringList buf;
|
||||
for(eRefType rt : extraRefs[0]){
|
||||
for (eRefType rt : extraRefs[0]) {
|
||||
buf.append(AttacherGui::getShapeTypeText(rt));
|
||||
}
|
||||
item->setText(tr("%1 (add %2)").arg(
|
||||
item->text(),
|
||||
buf.join(QString::fromLatin1("+"))
|
||||
));
|
||||
} else {
|
||||
item->text(),
|
||||
buf.join(QString::fromLatin1("+"))
|
||||
));
|
||||
}
|
||||
else {
|
||||
item->setText(tr("%1 (add more references)").arg(item->text()));
|
||||
}
|
||||
} else if (mmode == this->lastSuggestResult.bestFitMode){
|
||||
}
|
||||
else if (mmode == this->lastSuggestResult.bestFitMode) {
|
||||
//suggested mode - make bold
|
||||
QFont fnt = item->font();
|
||||
fnt.setBold(true);
|
||||
@@ -873,7 +902,7 @@ void TaskAttacher::updateListOfModes()
|
||||
void TaskAttacher::selectMapMode(eMapMode mmode) {
|
||||
ui->listOfModes->blockSignals(true);
|
||||
|
||||
for (size_t i = 0; i < modesInList.size(); ++i) {
|
||||
for (size_t i = 0; i < modesInList.size(); ++i) {
|
||||
if (modesInList[i] == mmode) {
|
||||
ui->listOfModes->item(i)->setSelected(true);
|
||||
}
|
||||
@@ -910,7 +939,7 @@ void TaskAttacher::onRefName3(const QString& text)
|
||||
onRefName(text, 2);
|
||||
}
|
||||
|
||||
void TaskAttacher::onRefName4(const QString &text)
|
||||
void TaskAttacher::onRefName4(const QString& text)
|
||||
{
|
||||
onRefName(text, 3);
|
||||
}
|
||||
@@ -920,7 +949,7 @@ bool TaskAttacher::getFlip() const
|
||||
return ui->checkBoxFlip->isChecked();
|
||||
}
|
||||
|
||||
void TaskAttacher::changeEvent(QEvent *e)
|
||||
void TaskAttacher::changeEvent(QEvent* e)
|
||||
{
|
||||
TaskBox::changeEvent(e);
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
@@ -958,11 +987,11 @@ void TaskAttacher::changeEvent(QEvent *e)
|
||||
|
||||
void TaskAttacher::visibilityAutomation(bool opening_not_closing)
|
||||
{
|
||||
auto defvisfunc = [] (bool opening_not_closing,
|
||||
const std::string &postfix,
|
||||
Gui::ViewProviderDocumentObject* vp,
|
||||
App::DocumentObject *editObj,
|
||||
const std::string& editSubName) {
|
||||
auto defvisfunc = [](bool opening_not_closing,
|
||||
const std::string& postfix,
|
||||
Gui::ViewProviderDocumentObject* vp,
|
||||
App::DocumentObject* editObj,
|
||||
const std::string& editSubName) {
|
||||
if (opening_not_closing) {
|
||||
QString code = QString::fromLatin1(
|
||||
"import Show\n"
|
||||
@@ -981,19 +1010,19 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing)
|
||||
"\t\tif len(tvObj.AttachmentSupport) > 0:\n"
|
||||
"\t\t\t_tv_%4.show([lnk[0] for lnk in tvObj.AttachmentSupport])\n"
|
||||
"del(tvObj)"
|
||||
).arg(
|
||||
QString::fromLatin1(Gui::Command::getObjectCmd(vp->getObject()).c_str()),
|
||||
QString::fromLatin1(Gui::Command::getObjectCmd(editObj).c_str()),
|
||||
QString::fromLatin1(editSubName.c_str()),
|
||||
QString::fromLatin1(postfix.c_str()));
|
||||
Gui::Command::runCommand(Gui::Command::Gui,code.toLatin1().constData());
|
||||
).arg(
|
||||
QString::fromLatin1(Gui::Command::getObjectCmd(vp->getObject()).c_str()),
|
||||
QString::fromLatin1(Gui::Command::getObjectCmd(editObj).c_str()),
|
||||
QString::fromLatin1(editSubName.c_str()),
|
||||
QString::fromLatin1(postfix.c_str()));
|
||||
Gui::Command::runCommand(Gui::Command::Gui, code.toLatin1().constData());
|
||||
}
|
||||
else if (!postfix.empty()) {
|
||||
QString code = QString::fromLatin1(
|
||||
"_tv_%1.restore()\n"
|
||||
"del(_tv_%1)"
|
||||
).arg(QString::fromLatin1(postfix.c_str()));
|
||||
Gui::Command::runCommand(Gui::Command::Gui,code.toLatin1().constData());
|
||||
).arg(QString::fromLatin1(postfix.c_str()));
|
||||
Gui::Command::runCommand(Gui::Command::Gui, code.toLatin1().constData());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1009,18 +1038,19 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing)
|
||||
return;
|
||||
|
||||
auto editDoc = Gui::Application::Instance->editDocument();
|
||||
App::DocumentObject *editObj = ViewProvider->getObject();
|
||||
App::DocumentObject* editObj = ViewProvider->getObject();
|
||||
std::string editSubName;
|
||||
auto sels = Gui::Selection().getSelection(nullptr, Gui::ResolveMode::NoResolve, true);
|
||||
if(!sels.empty() && sels[0].pResolvedObject
|
||||
&& sels[0].pResolvedObject->getLinkedObject()==editObj)
|
||||
if (!sels.empty() && sels[0].pResolvedObject
|
||||
&& sels[0].pResolvedObject->getLinkedObject() == editObj)
|
||||
{
|
||||
editObj = sels[0].pObject;
|
||||
editSubName = sels[0].SubName;
|
||||
} else {
|
||||
ViewProviderDocumentObject *editVp = nullptr;
|
||||
}
|
||||
else {
|
||||
ViewProviderDocumentObject* editVp = nullptr;
|
||||
if (editDoc) {
|
||||
editDoc->getInEdit(&editVp,&editSubName);
|
||||
editDoc->getInEdit(&editVp, &editSubName);
|
||||
if (editVp)
|
||||
editObj = editVp->getObject();
|
||||
}
|
||||
@@ -1029,7 +1059,7 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing)
|
||||
try {
|
||||
visAutoFunc(opening_not_closing, ObjectName, ViewProvider, editObj, editSubName);
|
||||
}
|
||||
catch (const Base::Exception &e){
|
||||
catch (const Base::Exception& e) {
|
||||
e.ReportException();
|
||||
}
|
||||
catch (const Py::Exception&) {
|
||||
@@ -1043,7 +1073,7 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing)
|
||||
objName.swap(ObjectName);
|
||||
visAutoFunc(opening_not_closing, objName, nullptr, nullptr, std::string());
|
||||
}
|
||||
catch (Base::Exception &e) {
|
||||
catch (Base::Exception& e) {
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
@@ -1054,14 +1084,14 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing)
|
||||
// TaskDialog
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
TaskDlgAttacher::TaskDlgAttacher(Gui::ViewProviderDocumentObject *ViewProvider, bool createBox)
|
||||
: TaskDialog(),ViewProvider(ViewProvider), parameter(nullptr)
|
||||
TaskDlgAttacher::TaskDlgAttacher(Gui::ViewProviderDocumentObject* ViewProvider, bool createBox)
|
||||
: TaskDialog(), ViewProvider(ViewProvider), parameter(nullptr)
|
||||
{
|
||||
assert(ViewProvider);
|
||||
setDocumentName(ViewProvider->getDocument()->getDocument()->getName());
|
||||
|
||||
if(createBox) {
|
||||
parameter = new TaskAttacher(ViewProvider, nullptr, QString(), tr("Attachment"));
|
||||
if (createBox) {
|
||||
parameter = new TaskAttacher(ViewProvider, nullptr, QString(), tr("Attachment"));
|
||||
Content.push_back(parameter);
|
||||
}
|
||||
}
|
||||
@@ -1096,11 +1126,11 @@ bool TaskDlgAttacher::accept()
|
||||
|
||||
//DeepSOIC: changed this to heavily rely on dialog constantly updating feature properties
|
||||
//if (pcAttach->AttachmentOffset.isTouched()){
|
||||
Base::Placement plm = pcAttach->AttachmentOffset.getValue();
|
||||
double yaw, pitch, roll;
|
||||
plm.getRotation().getYawPitchRoll(yaw,pitch,roll);
|
||||
Gui::cmdAppObjectArgs(obj, "AttachmentOffset = App.Placement(App.Vector(%.10f, %.10f, %.10f), App.Rotation(%.10f, %.10f, %.10f))",
|
||||
plm.getPosition().x, plm.getPosition().y, plm.getPosition().z, yaw, pitch, roll);
|
||||
Base::Placement plm = pcAttach->AttachmentOffset.getValue();
|
||||
double yaw, pitch, roll;
|
||||
plm.getRotation().getYawPitchRoll(yaw, pitch, roll);
|
||||
Gui::cmdAppObjectArgs(obj, "AttachmentOffset = App.Placement(App.Vector(%.10f, %.10f, %.10f), App.Rotation(%.10f, %.10f, %.10f))",
|
||||
plm.getPosition().x, plm.getPosition().y, plm.getPosition().z, yaw, pitch, roll);
|
||||
//}
|
||||
|
||||
Gui::cmdAppObjectArgs(obj, "MapReversed = %s", pcAttach->MapReversed.getValue() ? "True" : "False");
|
||||
|
||||
Reference in New Issue
Block a user