Sketcher: App - Clang-format

This commit is contained in:
Abdullah Tahiri
2023-05-18 19:01:34 +02:00
committed by abdullahtahiriyo
parent c33cdcd68a
commit 987b4bda2a
40 changed files with 9714 additions and 7322 deletions

View File

@@ -22,18 +22,18 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cassert>
#include <cassert>
#endif
#include <App/ExpressionParser.h>
#include <App/ObjectIdentifier.h>
#include <Base/QuantityPy.h>
#include <Base/Reader.h>
#include <Base/Writer.h>
#include <Base/Tools.h>
#include <Base/Writer.h>
#include "PropertyConstraintList.h"
#include "ConstraintPy.h"
#include "PropertyConstraintList.h"
using namespace App;
@@ -52,32 +52,32 @@ TYPESYSTEM_SOURCE(Sketcher::PropertyConstraintList, App::PropertyLists)
PropertyConstraintList::PropertyConstraintList()
: validGeometryKeys(0)
, invalidGeometry(true)
, restoreFromTransaction(false)
, invalidIndices(false)
{
}
: validGeometryKeys(0),
invalidGeometry(true),
restoreFromTransaction(false),
invalidIndices(false)
{}
PropertyConstraintList::~PropertyConstraintList()
{
for (std::vector<Constraint*>::iterator it = _lValueList.begin(); it != _lValueList.end(); ++it)
if (*it) delete *it;
if (*it)
delete *it;
}
App::ObjectIdentifier PropertyConstraintList::makeArrayPath(int idx)
{
return App::ObjectIdentifier(*this,idx);
return App::ObjectIdentifier(*this, idx);
}
App::ObjectIdentifier PropertyConstraintList::makeSimplePath(const Constraint * c)
App::ObjectIdentifier PropertyConstraintList::makeSimplePath(const Constraint* c)
{
return App::ObjectIdentifier(*this) << App::ObjectIdentifier::SimpleComponent(
App::ObjectIdentifier::String(c->Name, !ExpressionParser::isTokenAnIndentifier(c->Name)));
return App::ObjectIdentifier(*this)
<< App::ObjectIdentifier::SimpleComponent(App::ObjectIdentifier::String(
c->Name, !ExpressionParser::isTokenAnIndentifier(c->Name)));
}
App::ObjectIdentifier PropertyConstraintList::makePath(int idx, const Constraint * c)
App::ObjectIdentifier PropertyConstraintList::makePath(int idx, const Constraint* c)
{
return c->Name.empty() ? makeArrayPath(idx) : makeSimplePath(c);
}
@@ -176,13 +176,14 @@ void PropertyConstraintList::setValue(const Constraint* lValue)
void PropertyConstraintList::setValues(const std::vector<Constraint*>& lValue)
{
auto copy = lValue;
for(auto &cstr : copy)
for (auto& cstr : copy)
cstr = cstr->clone();
setValues(std::move(copy));
}
void PropertyConstraintList::setValues(std::vector<Constraint*>&& lValue) {
void PropertyConstraintList::setValues(std::vector<Constraint*>&& lValue)
{
aboutToSetValue();
applyValues(std::move(lValue));
hasSetValue();
@@ -190,18 +191,19 @@ void PropertyConstraintList::setValues(std::vector<Constraint*>&& lValue) {
void PropertyConstraintList::applyValues(std::vector<Constraint*>&& lValue)
{
std::set<Constraint*> oldVals(_lValueList.begin(),_lValueList.end());
std::set<Constraint*> oldVals(_lValueList.begin(), _lValueList.end());
std::map<App::ObjectIdentifier, App::ObjectIdentifier> renamed;
std::set<App::ObjectIdentifier> removed;
boost::unordered_map<boost::uuids::uuid, std::size_t> newValueMap;
/* Check for renames */
for (unsigned int i = 0; i < lValue.size(); i++) {
boost::unordered_map<boost::uuids::uuid, std::size_t>::const_iterator j = valueMap.find(lValue[i]->tag);
boost::unordered_map<boost::uuids::uuid, std::size_t>::const_iterator j =
valueMap.find(lValue[i]->tag);
if (j != valueMap.end()) {
if(i != j->second || _lValueList[j->second]->Name != lValue[i]->Name) {
App::ObjectIdentifier old_oid(makePath(j->second, _lValueList[j->second] ));
if (i != j->second || _lValueList[j->second]->Name != lValue[i]->Name) {
App::ObjectIdentifier old_oid(makePath(j->second, _lValueList[j->second]));
App::ObjectIdentifier new_oid(makePath(i, lValue[i]));
renamed[old_oid] = new_oid;
}
@@ -215,13 +217,14 @@ void PropertyConstraintList::applyValues(std::vector<Constraint*>&& lValue)
}
/* Collect info about removed elements */
for(auto &v : valueMap)
removed.insert(makePath(v.second,_lValueList[v.second]));
for (auto& v : valueMap)
removed.insert(makePath(v.second, _lValueList[v.second]));
/* Update value map with new tags from new array */
valueMap = std::move(newValueMap);
/* Signal removes first, in case renamed values below have the same names as some of the removed ones. */
/* Signal removes first, in case renamed values below have the same names as some of the removed
* ones. */
if (!removed.empty() && !restoreFromTransaction)
signalConstraintsRemoved(removed);
@@ -232,52 +235,54 @@ void PropertyConstraintList::applyValues(std::vector<Constraint*>&& lValue)
_lValueList = std::move(lValue);
/* Clean-up; remove old values */
for(auto &v : oldVals)
for (auto& v : oldVals)
delete v;
}
PyObject *PropertyConstraintList::getPyObject()
PyObject* PropertyConstraintList::getPyObject()
{
PyObject* list = PyList_New(getSize());
for (int i = 0; i < getSize(); i++)
PyList_SetItem( list, i, _lValueList[i]->getPyObject());
PyList_SetItem(list, i, _lValueList[i]->getPyObject());
return list;
}
bool PropertyConstraintList::getPyPathValue(const App::ObjectIdentifier &path, Py::Object &res) const {
if(path.numSubComponents()!=2 || path.getPropertyComponent(0).getName()!=getName())
bool PropertyConstraintList::getPyPathValue(const App::ObjectIdentifier& path,
Py::Object& res) const
{
if (path.numSubComponents() != 2 || path.getPropertyComponent(0).getName() != getName())
return false;
const ObjectIdentifier::Component & c1 = path.getPropertyComponent(1);
const ObjectIdentifier::Component& c1 = path.getPropertyComponent(1);
const Constraint *cstr = nullptr;
const Constraint* cstr = nullptr;
if (c1.isArray())
cstr = _lValueList[c1.getIndex(_lValueList.size())];
else if (c1.isSimple()) {
ObjectIdentifier::Component c1 = path.getPropertyComponent(1);
for(auto c : _lValueList) {
if(c->Name == c1.getName()) {
for (auto c : _lValueList) {
if (c->Name == c1.getName()) {
cstr = c;
break;
}
}
}
if(!cstr)
if (!cstr)
return false;
Quantity q = cstr->getPresentationValue();
res = new Base::QuantityPy(new Base::Quantity(q));
return true;
}
void PropertyConstraintList::setPyObject(PyObject *value)
void PropertyConstraintList::setPyObject(PyObject* value)
{
if (PyList_Check(value)) {
Py_ssize_t nSize = PyList_Size(value);
std::vector<Constraint*> values;
values.resize(nSize);
for (Py_ssize_t i=0; i < nSize; ++i) {
for (Py_ssize_t i = 0; i < nSize; ++i) {
PyObject* item = PyList_GetItem(value, i);
if (!PyObject_TypeCheck(item, &(ConstraintPy::Type))) {
std::string error = std::string("types in list must be 'Constraint', not ");
@@ -291,7 +296,7 @@ void PropertyConstraintList::setPyObject(PyObject *value)
setValues(values);
}
else if (PyObject_TypeCheck(value, &(ConstraintPy::Type))) {
ConstraintPy *pcObject = static_cast<ConstraintPy*>(value);
ConstraintPy* pcObject = static_cast<ConstraintPy*>(value);
setValue(pcObject->getConstraintPtr());
}
else {
@@ -301,17 +306,17 @@ void PropertyConstraintList::setPyObject(PyObject *value)
}
}
void PropertyConstraintList::Save(Writer &writer) const
void PropertyConstraintList::Save(Writer& writer) const
{
writer.Stream() << writer.ind() << "<ConstraintList count=\"" << getSize() <<"\">" << endl;
writer.Stream() << writer.ind() << "<ConstraintList count=\"" << getSize() << "\">" << endl;
writer.incInd();
for (int i = 0; i < getSize(); i++)
_lValueList[i]->Save(writer);
writer.decInd();
writer.Stream() << writer.ind() << "</ConstraintList>" << endl ;
writer.Stream() << writer.ind() << "</ConstraintList>" << endl;
}
void PropertyConstraintList::Restore(Base::XMLReader &reader)
void PropertyConstraintList::Restore(Base::XMLReader& reader)
{
// read my element
reader.readElement("ConstraintList");
@@ -321,7 +326,7 @@ void PropertyConstraintList::Restore(Base::XMLReader &reader)
std::vector<Constraint*> values;
values.reserve(count);
for (int i = 0; i < count; i++) {
Constraint *newC = new Constraint();
Constraint* newC = new Constraint();
newC->Restore(reader);
// To keep upward compatibility ignore unknown constraint types
if (newC->Type < Sketcher::NumConstraintTypes) {
@@ -339,15 +344,15 @@ void PropertyConstraintList::Restore(Base::XMLReader &reader)
setValues(std::move(values));
}
Property *PropertyConstraintList::Copy() const
Property* PropertyConstraintList::Copy() const
{
PropertyConstraintList *p = new PropertyConstraintList();
PropertyConstraintList* p = new PropertyConstraintList();
p->applyValidGeometryKeys(validGeometryKeys);
p->setValues(_lValueList);
return p;
}
void PropertyConstraintList::Paste(const Property &from)
void PropertyConstraintList::Paste(const Property& from)
{
Base::StateLocker lock(restoreFromTransaction, true);
const PropertyConstraintList& FromList = dynamic_cast<const PropertyConstraintList&>(from);
@@ -362,7 +367,7 @@ unsigned int PropertyConstraintList::getMemSize() const
return size;
}
void PropertyConstraintList::acceptGeometry(const std::vector<Part::Geometry *> &GeoList)
void PropertyConstraintList::acceptGeometry(const std::vector<Part::Geometry*>& GeoList)
{
aboutToSetValue();
validGeometryKeys.clear();
@@ -373,21 +378,21 @@ void PropertyConstraintList::acceptGeometry(const std::vector<Part::Geometry *>
hasSetValue();
}
void PropertyConstraintList::applyValidGeometryKeys(const std::vector<unsigned int> &keys)
void PropertyConstraintList::applyValidGeometryKeys(const std::vector<unsigned int>& keys)
{
validGeometryKeys = keys;
}
bool PropertyConstraintList::checkGeometry(const std::vector<Part::Geometry *> &GeoList)
bool PropertyConstraintList::checkGeometry(const std::vector<Part::Geometry*>& GeoList)
{
if (!scanGeometry(GeoList)) {
invalidGeometry = true;
return invalidGeometry;
}
//if we made it here, geometry is OK
// if we made it here, geometry is OK
if (invalidGeometry) {
//geometry was bad, but now it became OK.
// geometry was bad, but now it became OK.
invalidGeometry = false;
touch();
}
@@ -400,18 +405,18 @@ bool PropertyConstraintList::checkConstraintIndices(int geomax, int geomin)
int mininternalgeoid = std::numeric_limits<int>::max();
int maxinternalgeoid = GeoEnum::GeoUndef;
auto cmin = [] (int previousmin, int cindex) {
if( cindex == GeoEnum::GeoUndef )
auto cmin = [](int previousmin, int cindex) {
if (cindex == GeoEnum::GeoUndef)
return previousmin;
return ( cindex < previousmin )? cindex : previousmin;
return (cindex < previousmin) ? cindex : previousmin;
};
auto cmax = [] (int previousmax, int cindex) {
return ( cindex > previousmax )? cindex : previousmax;
auto cmax = [](int previousmax, int cindex) {
return (cindex > previousmax) ? cindex : previousmax;
};
for (const auto &v : _lValueList) {
for (const auto& v : _lValueList) {
mininternalgeoid = cmin(mininternalgeoid, v->First);
mininternalgeoid = cmin(mininternalgeoid, v->Second);
@@ -422,7 +427,7 @@ bool PropertyConstraintList::checkConstraintIndices(int geomax, int geomin)
maxinternalgeoid = cmax(maxinternalgeoid, v->Third);
}
if(maxinternalgeoid > geomax || mininternalgeoid < geomin)
if (maxinternalgeoid > geomax || mininternalgeoid < geomin)
invalidIndices = true;
else
invalidIndices = false;
@@ -436,15 +441,15 @@ bool PropertyConstraintList::checkConstraintIndices(int geomax, int geomin)
* \param GeoList - new geometry list to be checked
* \return false, if the types have changed.
*/
bool PropertyConstraintList::scanGeometry(const std::vector<Part::Geometry *> &GeoList) const
bool PropertyConstraintList::scanGeometry(const std::vector<Part::Geometry*>& GeoList) const
{
if (validGeometryKeys.size() != GeoList.size()) {
return false;
}
unsigned int i=0;
for (std::vector< Part::Geometry * >::const_iterator it=GeoList.begin();
it != GeoList.end(); ++it, i++) {
unsigned int i = 0;
for (std::vector<Part::Geometry*>::const_iterator it = GeoList.begin(); it != GeoList.end();
++it, i++) {
if (validGeometryKeys[i] != (*it)->getTypeId().getKey()) {
return false;
}
@@ -453,7 +458,7 @@ bool PropertyConstraintList::scanGeometry(const std::vector<Part::Geometry *> &G
return true;
}
string PropertyConstraintList::getConstraintName(const std::string & name, int i)
string PropertyConstraintList::getConstraintName(const std::string& name, int i)
{
if (!name.empty())
return name;
@@ -469,27 +474,27 @@ string PropertyConstraintList::getConstraintName(int i)
return str.str();
}
bool PropertyConstraintList::validConstraintName(const std::string & name)
bool PropertyConstraintList::validConstraintName(const std::string& name)
{
return !name.empty();
}
ObjectIdentifier PropertyConstraintList::createPath(int ConstrNbr) const
{
return App::ObjectIdentifier(*this,ConstrNbr);
return App::ObjectIdentifier(*this, ConstrNbr);
}
int PropertyConstraintList::getIndexFromConstraintName(const string &name)
int PropertyConstraintList::getIndexFromConstraintName(const string& name)
{
return std::atoi(name.substr(10,4000).c_str()) - 1;
return std::atoi(name.substr(10, 4000).c_str()) - 1;
}
void PropertyConstraintList::setPathValue(const ObjectIdentifier &path, const boost::any &value)
void PropertyConstraintList::setPathValue(const ObjectIdentifier& path, const boost::any& value)
{
if(path.numSubComponents()!=2 || path.getPropertyComponent(0).getName()!=getName())
FC_THROWM(Base::ValueError,"invalid constraint path " << path.toString());
if (path.numSubComponents() != 2 || path.getPropertyComponent(0).getName() != getName())
FC_THROWM(Base::ValueError, "invalid constraint path " << path.toString());
const ObjectIdentifier::Component & c1 = path.getPropertyComponent(1);
const ObjectIdentifier::Component& c1 = path.getPropertyComponent(1);
double dvalue;
if (value.type() == typeid(double))
@@ -501,18 +506,18 @@ void PropertyConstraintList::setPathValue(const ObjectIdentifier &path, const bo
else if (value.type() == typeid(int))
dvalue = App::any_cast<int>(value);
else if (value.type() == typeid(Quantity))
dvalue = (App::any_cast<const Quantity &>(value)).getValue();
dvalue = (App::any_cast<const Quantity&>(value)).getValue();
else
throw std::bad_cast();
if (c1.isArray()) {
size_t index = c1.getIndex(_lValueList.size());
switch (_lValueList[index]->Type) {
case Angle:
dvalue = Base::toRadians<double>(dvalue);
break;
default:
break;
case Angle:
dvalue = Base::toRadians<double>(dvalue);
break;
default:
break;
}
aboutToSetValue();
_lValueList[index]->setValue(dvalue);
@@ -520,16 +525,18 @@ void PropertyConstraintList::setPathValue(const ObjectIdentifier &path, const bo
return;
}
else if (c1.isSimple()) {
for (std::vector<Constraint *>::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) {
for (std::vector<Constraint*>::const_iterator it = _lValueList.begin();
it != _lValueList.end();
++it) {
int index = it - _lValueList.begin();
if ((*it)->Name == c1.getName()) {
switch (_lValueList[index]->Type) {
case Angle:
dvalue = Base::toRadians<double>(dvalue);
break;
default:
break;
case Angle:
dvalue = Base::toRadians<double>(dvalue);
break;
default:
break;
}
aboutToSetValue();
_lValueList[index]->setValue(dvalue);
@@ -538,15 +545,15 @@ void PropertyConstraintList::setPathValue(const ObjectIdentifier &path, const bo
}
}
}
FC_THROWM(Base::ValueError,"invalid constraint path " << path.toString());
FC_THROWM(Base::ValueError, "invalid constraint path " << path.toString());
}
const Constraint * PropertyConstraintList::getConstraint(const ObjectIdentifier &path) const
const Constraint* PropertyConstraintList::getConstraint(const ObjectIdentifier& path) const
{
if(path.numSubComponents()!=2 || path.getPropertyComponent(0).getName()!=getName())
FC_THROWM(Base::ValueError,"Invalid constraint path " << path.toString());
if (path.numSubComponents() != 2 || path.getPropertyComponent(0).getName() != getName())
FC_THROWM(Base::ValueError, "Invalid constraint path " << path.toString());
const ObjectIdentifier::Component & c1 = path.getPropertyComponent(1);
const ObjectIdentifier::Component& c1 = path.getPropertyComponent(1);
if (c1.isArray()) {
return _lValueList[c1.getIndex(_lValueList.size())];
@@ -554,44 +561,49 @@ const Constraint * PropertyConstraintList::getConstraint(const ObjectIdentifier
else if (c1.isSimple()) {
ObjectIdentifier::Component c1 = path.getPropertyComponent(1);
for (std::vector<Constraint *>::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) {
for (std::vector<Constraint*>::const_iterator it = _lValueList.begin();
it != _lValueList.end();
++it) {
if ((*it)->Name == c1.getName())
return *it;
}
}
FC_THROWM(Base::ValueError,"Invalid constraint path " << path.toString());
FC_THROWM(Base::ValueError, "Invalid constraint path " << path.toString());
}
const boost::any PropertyConstraintList::getPathValue(const ObjectIdentifier &path) const
const boost::any PropertyConstraintList::getPathValue(const ObjectIdentifier& path) const
{
return boost::any(getConstraint(path)->getPresentationValue());
}
ObjectIdentifier PropertyConstraintList::canonicalPath(const ObjectIdentifier &p) const
ObjectIdentifier PropertyConstraintList::canonicalPath(const ObjectIdentifier& p) const
{
if(p.numSubComponents()!=2 || p.getPropertyComponent(0).getName()!=getName())
FC_THROWM(Base::ValueError,"Invalid constraint path " << p.toString());
if (p.numSubComponents() != 2 || p.getPropertyComponent(0).getName() != getName())
FC_THROWM(Base::ValueError, "Invalid constraint path " << p.toString());
const ObjectIdentifier::Component & c1 = p.getPropertyComponent(1);
const ObjectIdentifier::Component& c1 = p.getPropertyComponent(1);
if (c1.isArray()) {
size_t idx = c1.getIndex();
if (idx < _lValueList.size() && !_lValueList[idx]->Name.empty())
return ObjectIdentifier(*this) << ObjectIdentifier::SimpleComponent(_lValueList[idx]->Name);
return ObjectIdentifier(*this)
<< ObjectIdentifier::SimpleComponent(_lValueList[idx]->Name);
return p;
}
else if (c1.isSimple()) {
return p;
}
FC_THROWM(Base::ValueError,"Invalid constraint path " << p.toString());
FC_THROWM(Base::ValueError, "Invalid constraint path " << p.toString());
}
void PropertyConstraintList::getPaths(std::vector<ObjectIdentifier> &paths) const
void PropertyConstraintList::getPaths(std::vector<ObjectIdentifier>& paths) const
{
for (std::vector<Constraint *>::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) {
for (std::vector<Constraint*>::const_iterator it = _lValueList.begin(); it != _lValueList.end();
++it) {
if (!(*it)->Name.empty())
paths.push_back(ObjectIdentifier(*this) << ObjectIdentifier::SimpleComponent((*it)->Name));
paths.push_back(ObjectIdentifier(*this)
<< ObjectIdentifier::SimpleComponent((*it)->Name));
}
}
std::vector<Constraint *> PropertyConstraintList::_emptyValueList(0);
std::vector<Constraint*> PropertyConstraintList::_emptyValueList(0);