Mesh: modernize C++: use range-based for loop

This commit is contained in:
wmayer
2023-08-15 10:55:05 +02:00
committed by wwmayer
parent 452aee7c6f
commit 7f49080952
52 changed files with 1293 additions and 1329 deletions

View File

@@ -503,10 +503,10 @@ App::PropertyColorList* ViewProviderMesh::getColorProperty() const
if (pcObject) {
std::map<std::string,App::Property*> Map;
pcObject->getPropertyMap(Map);
for (std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it) {
Base::Type type = it->second->getTypeId();
for (const auto & it : Map) {
Base::Type type = it.second->getTypeId();
if (type == App::PropertyColorList::getClassTypeId()) {
App::PropertyColorList* colors = static_cast<App::PropertyColorList*>(it->second);
App::PropertyColorList* colors = static_cast<App::PropertyColorList*>(it.second);
return colors;
}
}
@@ -599,8 +599,8 @@ void ViewProviderMesh::setColorField(const std::vector<App::Color>& val, SoMFCol
SbColor* col = field.startEditing();
std::size_t i=0;
for (std::vector<App::Color>::const_iterator it = val.begin(); it != val.end(); ++it) {
col[i++].setValue(it->r, it->g, it->b);
for (auto it : val) {
col[i++].setValue(it.r, it.g, it.b);
}
field.finishEditing();
@@ -631,10 +631,10 @@ Mesh::PropertyMaterial* ViewProviderMesh::getMaterialProperty() const
if (pcObject) {
std::map<std::string,App::Property*> Map;
pcObject->getPropertyMap(Map);
for (std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it) {
Base::Type type = it->second->getTypeId();
for (const auto & it : Map) {
Base::Type type = it.second->getTypeId();
if (type == Mesh::PropertyMaterial::getClassTypeId()) {
Mesh::PropertyMaterial* material = static_cast<Mesh::PropertyMaterial*>(it->second);
Mesh::PropertyMaterial* material = static_cast<Mesh::PropertyMaterial*>(it.second);
return material;
}
}
@@ -872,11 +872,11 @@ bool ViewProviderMesh::createToolMesh(const std::vector<SbVec2f>& rclPoly, const
bool ok = cTria.TriangulatePolygon();
std::vector<MeshFacet> faces = cTria.GetFacets();
for (std::vector<MeshFacet>::iterator itF = faces.begin(); itF != faces.end(); ++itF) {
for (const auto & face : faces) {
MeshGeomFacet topFacet;
topFacet._aclPoints[0] = top[itF->_aulPoints[0]];
topFacet._aclPoints[1] = top[itF->_aulPoints[1]];
topFacet._aclPoints[2] = top[itF->_aulPoints[2]];
topFacet._aclPoints[0] = top[face._aulPoints[0]];
topFacet._aclPoints[1] = top[face._aulPoints[1]];
topFacet._aclPoints[2] = top[face._aulPoints[2]];
if (topFacet.GetNormal() * rcNormal < 0) {
std::swap(topFacet._aclPoints[1], topFacet._aclPoints[2]);
topFacet.CalcNormal();
@@ -884,9 +884,9 @@ bool ViewProviderMesh::createToolMesh(const std::vector<SbVec2f>& rclPoly, const
aFaces.push_back(topFacet);
MeshGeomFacet botFacet;
botFacet._aclPoints[0] = bottom[itF->_aulPoints[0]];
botFacet._aclPoints[1] = bottom[itF->_aulPoints[1]];
botFacet._aclPoints[2] = bottom[itF->_aulPoints[2]];
botFacet._aclPoints[0] = bottom[face._aulPoints[0]];
botFacet._aclPoints[1] = bottom[face._aulPoints[1]];
botFacet._aclPoints[2] = bottom[face._aulPoints[2]];
if (botFacet.GetNormal() * rcNormal > 0) {
std::swap(botFacet._aclPoints[1], botFacet._aclPoints[2]);
botFacet.CalcNormal();
@@ -976,8 +976,8 @@ void ViewProviderMesh::clipMeshCallback(void * ud, SoEventCallback * n)
if (!views.empty()) {
Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Cut"));
bool commitCommand = false;
for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
ViewProviderMesh* self = static_cast<ViewProviderMesh*>(*it);
for (auto it : views) {
ViewProviderMesh* self = static_cast<ViewProviderMesh*>(it);
if (self->getEditingMode() > -1) {
self->finishEditing();
SoCamera* cam = view->getSoRenderManager()->getCamera();
@@ -1039,8 +1039,8 @@ void ViewProviderMesh::trimMeshCallback(void * ud, SoEventCallback * n)
if (!views.empty()) {
Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Trim"));
bool commitCommand = false;
for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
ViewProviderMesh* self = static_cast<ViewProviderMesh*>(*it);
for (auto it : views) {
ViewProviderMesh* self = static_cast<ViewProviderMesh*>(it);
if (self->getEditingMode() > -1) {
self->finishEditing();
SoCamera* cam = view->getSoRenderManager()->getCamera();
@@ -1120,8 +1120,8 @@ void ViewProviderMesh::partMeshCallback(void * ud, SoEventCallback * cb)
try {
std::vector<Gui::ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
ViewProviderMesh* that = static_cast<ViewProviderMesh*>(*it);
for (auto view : views) {
ViewProviderMesh* that = static_cast<ViewProviderMesh*>(view);
if (that->getEditingMode() > -1) {
that->finishEditing();
Base::Placement plm = static_cast<Mesh::Feature*>(that->getObject())->Placement.getValue();
@@ -1184,8 +1184,8 @@ void ViewProviderMesh::segmMeshCallback(void * ud, SoEventCallback * cb)
try {
std::vector<Gui::ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
ViewProviderMesh* that = static_cast<ViewProviderMesh*>(*it);
for (auto view : views) {
ViewProviderMesh* that = static_cast<ViewProviderMesh*>(view);
if (that->getEditingMode() > -1) {
that->finishEditing();
Base::Placement plm = static_cast<Mesh::Feature*>(that->getObject())->Placement.getValue();
@@ -1249,8 +1249,8 @@ void ViewProviderMesh::selectGLCallback(void * ud, SoEventCallback * n)
std::vector<Gui::ViewProvider*> views;
views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
ViewProviderMesh* that = static_cast<ViewProviderMesh*>(*it);
for (auto it : views) {
ViewProviderMesh* that = static_cast<ViewProviderMesh*>(it);
if (that->getEditingMode() > -1) {
that->finishEditing();
that->selectArea(x, y, w, h, view->getSoRenderManager()->getViewportRegion(), view->getSoRenderManager()->getCamera());
@@ -1267,8 +1267,8 @@ void ViewProviderMesh::getFacetsFromPolygon(const std::vector<SbVec2f>& picked,
{
const bool ok = true;
Base::Polygon2d polygon;
for (std::vector<SbVec2f>::const_iterator it = picked.begin(); it != picked.end(); ++it)
polygon.Add(Base::Vector2d((*it)[0],(*it)[1]));
for (auto it : picked)
polygon.Add(Base::Vector2d(it[0],it[1]));
// Get the attached mesh property
Mesh::PropertyMeshKernel& meshProp = static_cast<Mesh::Feature*>(pcObject)->Mesh;
@@ -1495,8 +1495,8 @@ void ViewProviderMesh::trimMesh(const std::vector<SbVec2f>& polygon,
Mesh::MeshObject* mesh = static_cast<Mesh::Feature*>(pcObject)->Mesh.startEditing();
Base::Polygon2d polygon2d;
for (std::vector<SbVec2f>::const_iterator it = polygon.begin(); it != polygon.end(); ++it)
polygon2d.Add(Base::Vector2d((*it)[0],(*it)[1]));
for (auto it : polygon)
polygon2d.Add(Base::Vector2d(it[0],it[1]));
Mesh::MeshObject::CutType type = inner ?
Mesh::MeshObject::INNER :
@@ -1584,9 +1584,9 @@ void ViewProviderMesh::faceInfoCallback(void * ud, SoEventCallback * n)
view->getWidget()->setCursor(QCursor(Qt::ArrowCursor));
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), faceInfoCallback,ud);
std::list<Gui::GLGraphicsItem*> glItems = view->getGraphicsItemsOfType(Gui::GLFlagWindow::getClassTypeId());
for (std::list<Gui::GLGraphicsItem*>::iterator it = glItems.begin(); it != glItems.end(); ++it) {
view->removeGraphicsItem(*it);
delete *it;
for (auto glItem : glItems) {
view->removeGraphicsItem(glItem);
delete glItem;
}
// See comment below
@@ -1715,21 +1715,21 @@ void ViewProviderMesh::markPartCallback(void * ud, SoEventCallback * n)
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), markPartCallback,ud);
std::vector<ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
for (std::vector<ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
static_cast<ViewProviderMesh*>(*it)->clearSelection();
for (auto view : views) {
static_cast<ViewProviderMesh*>(view)->clearSelection();
}
}
else if (cf == id) {
std::vector<ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
for (std::vector<ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
static_cast<ViewProviderMesh*>(*it)->clearSelection();
for (auto view : views) {
static_cast<ViewProviderMesh*>(view)->clearSelection();
}
}
else if (rm == id) {
Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Delete"));
std::vector<ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
for (std::vector<ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
static_cast<ViewProviderMesh*>(*it)->deleteSelection();
for (auto view : views) {
static_cast<ViewProviderMesh*>(view)->deleteSelection();
}
view->redraw();
Gui::Application::Instance->activeDocument()->commitCommand();
@@ -1799,10 +1799,10 @@ void ViewProviderMesh::fillHole(Mesh::FacetIndex uFacet)
std::vector<MeshCore::MeshFacet> newFacets;
std::vector<Base::Vector3f> newPoints;
unsigned long numberOfOldPoints = rKernel.CountPoints();
for (std::list<std::vector<Mesh::PointIndex> >::iterator it = boundaries.begin(); it != boundaries.end(); ++it) {
if (it->size() < 3/* || it->size() > 200*/)
for (const auto & it : boundaries) {
if (it.size() < 3/* || it->size() > 200*/)
continue;
boundary = *it;
boundary = it;
MeshCore::MeshFacetArray faces;
MeshCore::MeshPointArray points;
MeshCore::QuasiDelaunayTriangulator cTria/*(0.05f)*/;
@@ -1820,11 +1820,11 @@ void ViewProviderMesh::fillHole(Mesh::FacetIndex uFacet)
newPoints.push_back(*pt);
}
}
for (MeshCore::MeshFacetArray::_TIterator kt = faces.begin(); kt != faces.end(); ++kt ) {
kt->_aulPoints[0] = boundary[kt->_aulPoints[0]];
kt->_aulPoints[1] = boundary[kt->_aulPoints[1]];
kt->_aulPoints[2] = boundary[kt->_aulPoints[2]];
newFacets.push_back(*kt);
for (auto & face : faces) {
face._aulPoints[0] = boundary[face._aulPoints[0]];
face._aulPoints[1] = boundary[face._aulPoints[1]];
face._aulPoints[2] = boundary[face._aulPoints[2]];
newFacets.push_back(face);
}
}
}
@@ -2134,8 +2134,8 @@ void ViewProviderMesh::highlightSelection()
SbColor* cols = pcShapeMaterial->diffuseColor.startEditing();
for (int i=0; i<uCtFacets; i++)
cols[i].setValue(c.r,c.g,c.b);
for (std::vector<Mesh::FacetIndex>::iterator it = selection.begin(); it != selection.end(); ++it)
cols[*it].setValue(1.0f,0.0f,0.0f);
for (Mesh::FacetIndex it : selection)
cols[it].setValue(1.0f,0.0f,0.0f);
pcShapeMaterial->diffuseColor.finishEditing();
}
@@ -2170,13 +2170,13 @@ void ViewProviderMesh::highlightComponents()
pcShapeMaterial->diffuseColor.setNum(uCtFacets);
SbColor* cols = pcShapeMaterial->diffuseColor.startEditing();
for (std::vector<std::vector<Mesh::FacetIndex> >::iterator it = comps.begin(); it != comps.end(); ++it) {
for (const auto & comp : comps) {
float fMax = (float)RAND_MAX;
float fRed = (float)rand()/fMax;
float fGrn = (float)rand()/fMax;
float fBlu = (float)rand()/fMax;
for (std::vector<Mesh::FacetIndex>::iterator jt = it->begin(); jt != it->end(); ++jt) {
cols[*jt].setValue(fRed,fGrn,fBlu);
for (Mesh::FacetIndex jt : comp) {
cols[jt].setValue(fRed,fGrn,fBlu);
}
}
pcShapeMaterial->diffuseColor.finishEditing();
@@ -2226,8 +2226,8 @@ void ViewProviderMesh::highlightSegments(const std::vector<App::Color>& colors)
float fRed = colors[i].r;
float fGrn = colors[i].g;
float fBlu = colors[i].b;
for (std::vector<Mesh::FacetIndex>::iterator it = segm.begin(); it != segm.end(); ++it) {
cols[*it].setValue(fRed,fGrn,fBlu);
for (Mesh::FacetIndex it : segm) {
cols[it].setValue(fRed,fGrn,fBlu);
}
}
pcShapeMaterial->diffuseColor.finishEditing();
@@ -2364,11 +2364,11 @@ void ViewProviderIndexedFaceSet::showOpenEdges(bool show)
int index=0;
const MeshCore::MeshKernel& rMesh = static_cast<Mesh::Feature*>(pcObject)->Mesh.getValue().getKernel();
const MeshCore::MeshFacetArray& rFaces = rMesh.GetFacets();
for (MeshCore::MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it) {
for (const auto & rFace : rFaces) {
for (int i=0; i<3; i++) {
if (it->_aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) {
lines->coordIndex.set1Value(index++,it->_aulPoints[i]);
lines->coordIndex.set1Value(index++,it->_aulPoints[(i+1)%3]);
if (rFace._aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) {
lines->coordIndex.set1Value(index++,rFace._aulPoints[i]);
lines->coordIndex.set1Value(index++,rFace._aulPoints[(i+1)%3]);
lines->coordIndex.set1Value(index++,SO_END_LINE_INDEX);
}
}