Skip to content

Commit

Permalink
+ on rename of contraint make sure that new name is different, on swa…
Browse files Browse the repository at this point in the history
…p constraint names make sure they have user-defined names
  • Loading branch information
wwmayer committed Mar 12, 2016
1 parent a17870c commit b25ef62
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Mod/Sketcher/App/PropertyConstraintList.cpp
Expand Up @@ -386,7 +386,7 @@ bool PropertyConstraintList::scanGeometry(const std::vector<Part::Geometry *> &G

string PropertyConstraintList::getConstraintName(const std::string & name, int i)
{
if (name != "")
if (!name.empty())
return name;
else
return getConstraintName(i);
Expand Down
13 changes: 8 additions & 5 deletions src/Mod/Sketcher/App/SketchObjectPyImp.cpp
Expand Up @@ -355,11 +355,14 @@ PyObject* SketchObjectPy::renameConstraint(PyObject *args)
}
}

Constraint* copy = this->getSketchObjectPtr()->Constraints[Index]->clone();
copy->Name = Name;
this->getSketchObjectPtr()->Constraints.set1Value(Index, copy);
delete copy;

// only change the constraint item if the names are different
const Constraint* item = this->getSketchObjectPtr()->Constraints[Index];
if (item->Name != Name) {
Constraint* copy = item->clone();
copy->Name = Name;
this->getSketchObjectPtr()->Constraints.set1Value(Index, copy);
delete copy;
}
Py_Return;
}

Expand Down
15 changes: 13 additions & 2 deletions src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp
Expand Up @@ -476,8 +476,19 @@ void ConstraintView::swapNamedOfSelectedItems()
std::string escapedstr1 = Base::Tools::escapedUnicodeFromUtf8(item1->sketch->Constraints[item1->ConstraintNbr]->Name.c_str());
ConstraintItem * item2 = static_cast<ConstraintItem*>(items[1]);
std::string escapedstr2 = Base::Tools::escapedUnicodeFromUtf8(item2->sketch->Constraints[item2->ConstraintNbr]->Name.c_str());
std::stringstream ss;

// In commit 67800ec8c (21 Jul 2015) the implementation of on_listWidgetConstraints_itemChanged()
// has changed ensuring that a name of a constraint cannot be reset any more.
// This leads to some inconsistencies when trying to swap "empty" names.
//
// If names are empty then nothing should be done
if (escapedstr1.empty() || escapedstr2.empty()) {
QMessageBox::warning(Gui::MainWindow::getInstance(), tr("Unnamed constraint"),
tr("Only the names of named constraints can be swapped."));
return;
}

std::stringstream ss;
ss << "DummyConstraint" << rand();
std::string tmpname = ss.str();

Expand Down Expand Up @@ -673,7 +684,7 @@ void TaskSketcherConstrains::on_listWidgetConstraints_itemChanged(QListWidgetIte
catch (const Base::Exception & e) {
Gui::Command::abortCommand();

QMessageBox::critical(Gui::MainWindow::getInstance(), QString::fromLatin1("Error"),
QMessageBox::critical(Gui::MainWindow::getInstance(), tr("Error"),
QString::fromLatin1(e.what()), QMessageBox::Ok, QMessageBox::Ok);
}
}
Expand Down

0 comments on commit b25ef62

Please sign in to comment.