Commit aaac2a89 authored by Emmanuel Promayon's avatar Emmanuel Promayon

UPDATED modernize using the new range-based loops in C++11 (improve readibility)

parent 7a029f9f
......@@ -88,8 +88,8 @@ int main ( int argc, char** argv ) {
double bary[3];
for ( int i = 0; i < 3; i++ ) {
bary[i] = 0.0;
for (double & value : bary) {
value = 0.0;
}
double pos[3];
......
......@@ -274,10 +274,10 @@ double Loads::getFirstEventDate() {
bool foundOne = false;
ValueEvent* ev;
for (unsigned int i = 0; i < loads.size(); i++) {
for (auto & load : loads) {
// as events are sorted by date, test only the first event
// of each load
ev = loads[i]->getValueEvent (0);
ev = load->getValueEvent (0);
if (ev && ( (foundOne && ev->getDate() < dateMin) || !foundOne)) {
dateMin = ev->getDate();
foundOne = true;
......@@ -298,10 +298,10 @@ double Loads::getLastEventDate() {
double dateMax = -1.0;
ValueEvent* ev;
for (unsigned int i = 0; i < loads.size(); i++) {
for (auto & load : loads) {
// as events are sorted by date, test only the last event
// of each load
ev = loads[i]->getValueEvent (loads[i]->numberOfValueEvents() - 1);
ev = load->getValueEvent (load->numberOfValueEvents() - 1);
if (ev && ev->getDate() > dateMax) {
dateMax = ev->getDate();
}
......
......@@ -215,8 +215,8 @@ void Cell::xmlPrint (std::ostream& o, const StructuralComponent* sc) {
void Cell::deleteAllStructures() {
// here the list elements (i.e. atoms) are NOT deleted
// but the list is cleared and cell removed from sc list of atoms
for (unsigned int i = 0; i < structures.size(); i++) {
Atom* a = (Atom*) structures[i];
for (auto & structure : structures) {
Atom* a = (Atom*) structure;
a->removeStructuralComponent (this);
}
structures.clear();
......
......@@ -51,13 +51,13 @@ void Component::removeFromParents() {
std::vector <MultiComponent*> parentMultiComponentsCopy;
parentMultiComponentsCopy.reserve(parentMultiComponentList.size());
//std::copy(parentMultiComponentList.begin(), parentMultiComponentList.end(), parentMultiComponentsCopy.begin());
for (unsigned int i = 0 ; i < parentMultiComponentList.size(); i++) {
parentMultiComponentsCopy.push_back(parentMultiComponentList[i]);
for (auto parent : parentMultiComponentList) {
parentMultiComponentsCopy.push_back(parent);
}
for (unsigned int i = 0; i < parentMultiComponentsCopy.size(); i++) {
parentMultiComponentsCopy[i]->removeSubComponent(this);
for (auto & parent : parentMultiComponentsCopy) {
parent->removeSubComponent(this);
}
// here assert parentMultiComponentList.size()==0
......
......@@ -46,8 +46,8 @@ MultiComponent::~MultiComponent() {
// ------------------ deleteAllSubComponents ---------------------
void MultiComponent::deleteAllSubComponents() {
for (unsigned int i = 0 ; i < components.size() ; i++) {
delete components[i];
for (auto & component : components) {
delete component;
}
components.clear();
}
......@@ -66,8 +66,8 @@ void MultiComponent::xmlPrint(std::ostream& o) const {
}
o << ">" << std::endl;
for (unsigned int i = 0; i < components.size(); i++) {
components[i]->xmlPrint(o);
for (auto component : components) {
component->xmlPrint(o);
}
o << "</multiComponent>" << std::endl;
}
......@@ -78,8 +78,8 @@ unsigned int MultiComponent::getNumberOfCells() const {
unsigned int nrOfCells = 0;
// add all the cells of all the sub components
for (unsigned int i = 0; i < components.size(); i++) {
nrOfCells += components[i]->getNumberOfCells();
for (auto component : components) {
nrOfCells += component->getNumberOfCells();
}
return nrOfCells;
......@@ -122,15 +122,15 @@ bool MultiComponent::isVisible(const RenderingMode::Mode mode) const {
// --------------- isVisible ---------------
void MultiComponent::setVisible(const RenderingMode::Mode mode, const bool b) {
// set all subcomponents
for (unsigned int i = 0; i < components.size(); i++) {
components[i]->setVisible(mode, b);
for (auto & component : components) {
component->setVisible(mode, b);
}
}
// --------------- setPhysicalModel ---------------
void MultiComponent::setPhysicalModel(PhysicalModel* pm) {
Component::setPhysicalModel(pm);
for (unsigned int i = 0; i < components.size(); i++) {
components[i]->setPhysicalModel(pm);
for (auto & component : components) {
component->setPhysicalModel(pm);
}
}
......@@ -516,16 +516,16 @@ MultiComponent* PMLTransform::generateExternalSurface(StructuralComponent* sc) {
// just add in a new SC all the one that are used only once
StructuralComponent* facet = new StructuralComponent(nullptr, "extern");
for (auto it = allFacets.begin(); it != allFacets.end(); it++) {
for (auto & aFacet : allFacets) {
//(*it)->debug();
if ((*it)->getUsed() == 1) { // used only once
facet->addStructure((*it)->getCell(sc->getPhysicalModel()));
if (aFacet->getUsed() == 1) { // used only once
facet->addStructure(aFacet->getCell(sc->getPhysicalModel()));
}
}
// delete all facets
for (auto it = allFacets.begin(); it != allFacets.end(); it++) {
delete (*it);
for (auto & aFacet : allFacets) {
delete aFacet;
}
// create the enclosed volume
......
......@@ -42,20 +42,19 @@ Properties::Properties(PhysicalModel* p, const std::string n) {
}
// ---------------- domToFields -----------------
void Properties::xmlToFields(xsd::cxx::tree::attribute_set<char> attrs) {
void Properties::xmlToFields(xsd::cxx::tree::attribute_set<char> allAttributes) {
for (xsd::cxx::tree::attribute_set<char>::iterator i = attrs.begin(); i != attrs.end(); i++) {
xercesc::DOMAttr& unknownAttr = (*i);
for (auto & attribute : allAttributes) {
std::string unknownAttrName, unknownAttrValue;
char* buffer;
// use transcoding util to transform the XML name, value from XMLString to std::string
// name
buffer = xercesc::XMLString::transcode(unknownAttr.getName());
buffer = xercesc::XMLString::transcode(attribute.getName());
unknownAttrName = buffer;
xercesc::XMLString::release(&buffer);
// value
buffer = xercesc::XMLString::transcode(unknownAttr.getValue());
buffer = xercesc::XMLString::transcode(attribute.getValue());
unknownAttrValue = buffer;
xercesc::XMLString::release(&buffer);
......
......@@ -172,8 +172,8 @@ void StructuralComponent::xmlPrint(std::ostream& o) const {
o << "<nrOfStructures value=\"" << structures.size() << "\"/>" << std::endl;
// print out all the structures
for (unsigned int i = 0; i < structures.size(); i++) {
structures[i]->xmlPrint(o, this);
for (auto structure : structures) {
structure->xmlPrint(o, this);
}
o << "</structuralComponent>" << std::endl;
}
......@@ -184,8 +184,8 @@ unsigned int StructuralComponent::getNumberOfCells() const {
unsigned int nrOfCells = 0;
// add all the cells of all the sub components
for (unsigned int i = 0; i < structures.size(); i++) {
if (structures[i]->isInstanceOf("Cell")) {
for (auto structure : structures) {
if (structure->isInstanceOf("Cell")) {
nrOfCells++;
}
}
......
......@@ -124,8 +124,8 @@ Action::ApplyStatus MeshPicking::apply() {
}
// divide by the number of accumulation
for (unsigned int i = 0; i < 3; i++) {
cellBarycenter[i] /= pickedCell->GetNumberOfPoints();
for (double & value : cellBarycenter) {
value /= pickedCell->GetNumberOfPoints();
}
// add information
......
......@@ -98,8 +98,8 @@ ActionExtensionGenerator::~ActionExtensionGenerator() {
void ActionExtensionGenerator::generateActionOrComponent(QString directory) {
// C generate actions
for (QVector<ActionGenerator*>::iterator it = actions.begin(); it != actions.end(); it++) {
(*it)->generateFiles(directory);
for (auto & action : actions) {
action->generateFiles(directory);
}
}
......
......@@ -237,9 +237,9 @@ void ActionGenerator::writeCFile(QString directoryName) {
// Additional includes needed by parameter types
QSet<QString> additionalIncludes;
// here we use a QSet to avoid the repetion of includes
for (QVector<ParameterGenerator*>::const_iterator it = actionParameters.begin(); it != actionParameters.end(); it++) {
if ((*it)->needsAdditionalInclude()) {
additionalIncludes.insert((*it)->getAdditionalInclude());
for (auto actionParameter : actionParameters) {
if (actionParameter->needsAdditionalInclude()) {
additionalIncludes.insert(actionParameter->getAdditionalInclude());
}
}
......@@ -408,9 +408,7 @@ void ActionGenerator::writeCFile(QString directoryName) {
QStringList addTheProps;
while (! text.contains(QRegExp("@END_ADDPROPERTIES@")) &&
! text.contains(QRegExp("@ELSE_ADDPROPERTIES@"))) {
for (QVector<ParameterGenerator*>::const_iterator it = actionParameters.begin();
it != actionParameters.end(); it++) {
ParameterGenerator* param = (*it);
for (auto param : actionParameters) {
QString textTmp = text;
textTmp.replace(QRegExp("@PROPERTY_TYPE@"), param->getType());
......
......@@ -73,8 +73,8 @@ CepGenerator::CepGenerator(std::unique_ptr< cepcoreschema::Cep > domCep, QString
CepGenerator::~CepGenerator() {
std::cout << "inside CepGenerator destructor..." << std::endl;
for (QVector<ExtensionGenerator*>::iterator i = extensions.begin(); i != extensions.end(); i++) {
delete(*i);
for (auto & extension : extensions) {
delete extension;
}
}
......@@ -456,8 +456,8 @@ void CepGenerator::generateExtensions() {
std::cout << "inside generateExtension" << std::endl;
// Component and Action extensions genration
for (QVector<ExtensionGenerator*>::iterator c = extensions.begin(); c != extensions.end(); c++) {
(*c)->generateExtension();
for (auto & extension : extensions) {
extension->generateExtension();
}
}
......
......@@ -99,8 +99,8 @@ ComponentExtensionGenerator::~ComponentExtensionGenerator() {
void ComponentExtensionGenerator::generateActionOrComponent(QString directory) {
// C generate actions
for (QVector<ComponentGenerator*>::iterator it = components.begin(); it != components.end(); it++) {
(*it)->generateFiles(directory);
for (auto & component : components) {
component->generateFiles(directory);
}
}
......
......@@ -193,9 +193,9 @@ void ComponentGenerator::writeCFile(QString directoryName) {
// Additional includes needed by parameter types
QSet<QString> additionalIncludes;
// here we use a QSet to avoid the repetion of includes
for (QVector<ParameterGenerator*>::const_iterator it = componentProperties.begin(); it != componentProperties.end(); it++) {
if ((*it)->needsAdditionalInclude()) {
additionalIncludes.insert((*it)->getAdditionalInclude());
for (auto componentProperty : componentProperties) {
if (componentProperty->needsAdditionalInclude()) {
additionalIncludes.insert(componentProperty->getAdditionalInclude());
}
}
......@@ -301,8 +301,7 @@ void ComponentGenerator::writeCFile(QString directoryName) {
text = in.readLine();
if (componentProperties.size() > 0) {
QStringList addTheProps;
for (QVector<ParameterGenerator*>::const_iterator it = componentProperties.begin(); it != componentProperties.end(); it++) {
ParameterGenerator* param = (*it);
for (auto param : componentProperties) {
QString textTmp = text;
textTmp.replace(QRegExp("@PROPERTY_TYPE@"), param->getType());
......
......@@ -416,8 +416,8 @@ void Geometry::updateLabel() {
position[j] += pos[j];
}
}
for (unsigned j = 0; j < 3; j++) {
position[j] /= pointSet->GetNumberOfPoints();
for (double & value : position) {
value /= pointSet->GetNumberOfPoints();
}
position[1] += glyphSize;
......
......@@ -343,13 +343,13 @@ void ObjectControllerPrivate::updateDynamicProperties ( const QObject* edited )
QList<QByteArray> dynProp = edited->dynamicPropertyNames();
for ( int idx = 0; idx < dynProp.size(); ++idx ) {
QString pName = QString ( dynProp.at ( idx ) );
int type = edited->property ( dynProp.at ( idx ) ).userType();
QtVariantProperty* subProperty = m_indexToDynamicProperty[idx];
for ( int i = 0; i < dynProp.size(); ++i ) {
QString pName = QString ( dynProp.at ( i ) );
int type = edited->property ( dynProp.at ( i ) ).userType();
QtVariantProperty* subProperty = m_indexToDynamicProperty[i];
if ( m_manager->isPropertyTypeSupported ( type ) ) {
subProperty->setValue ( edited->property ( dynProp.at ( idx ) ) );
subProperty->setValue ( edited->property ( dynProp.at ( i ) ) );
}
else {
subProperty->setValue ( QLatin1String ( "< Unknown Type >" ) );
......@@ -364,7 +364,7 @@ void ObjectControllerPrivate::addDynamicProperties ( QObject* edited ) {
QList<QByteArray> dynProp = edited->dynamicPropertyNames();
// loop on all dynamic properties
for ( int idx = 0; idx < dynProp.size(); ++idx ) {
for ( int idx = 0; idx < dynProp.size(); ++idx ) {
QString pName = QString ( dynProp.at ( idx ) );
QVariant pValue = edited->property ( dynProp.at ( idx ) );
QtVariantProperty* subProperty = 0;
......
......@@ -108,19 +108,18 @@ void PlaneC::setVisuActivePlaneOff() {
//--------------------Reset the Plane of the View---------------------
void PlaneC::clear() {
for (int i = 0; i < 3; i++) {
transfor[i] = 0;
for (double & value : transformation) {
value = 0.0;
}
translat = 0;
angle1 = 0; // no angle when I start
angle2 = 0;
translation1 = 0;// no angle when I start
translation = 0.0;
angle1 = 0.0; // no angle when I start
angle2 = 0.0;
translation1 = 0.0;
// Initialization by default
plane->SetOrigin(0.0, 0.0, 0.0);
plane->SetPoint1(0.0, 1.0, 0.0);
plane->SetPoint2(0.0, 0.0, 1.0);
}
//--------------------getActor----------
......@@ -177,55 +176,55 @@ void PlaneC::init(PlaneC::PlaneCType type, double* bounds) {
//--------------------Translate the Plane on Xaxis---------------------
void PlaneC::translatePlaneX() {
vtkSmartPointer<vtkTransform> translation = vtkSmartPointer<vtkTransform>::New();
auto a = double(translat - translation1);
translation1 = translat;
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
double a = (translation - translation1);
translation1 = translation;
translation->Translate(a, 0, 0);
t->Translate(a, 0, 0);
double tab[3];
plane->GetCenter(tab);
//change the coordinates of the Plane center and all the plane is translated
translation->TransformPoint(tab, tab);
t->TransformPoint(tab, tab);
plane->SetCenter(tab);
translation->Update();
t->Update();
}
//--------------------Translate the Plane on Yaxis---------------------
void PlaneC::translatePlaneY() {
vtkSmartPointer<vtkTransform> translation = vtkSmartPointer<vtkTransform>::New();
auto a = double(translat - translation1);
translation1 = translat;
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
double a = translation - translation1;
translation1 = translation;
translation->Translate(0, a, 0);
t->Translate(0, a, 0);
double tab[3];
plane->GetCenter(tab);
//change the coordinates of the Plane center and all the plane is translated
translation->TransformPoint(tab, tab);
t->TransformPoint(tab, tab);
plane->SetCenter(tab);
translation->Update();
t->Update();
}
//--------------------Translate the Plane on Zaxis---------------------
void PlaneC::translatePlaneZ() {
vtkSmartPointer<vtkTransform> translation = vtkSmartPointer<vtkTransform>::New();
auto a = double(translat - translation1);
translation1 = translat;
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
double a = translation - translation1;
translation1 = translation;
translation->Translate(0, 0, a);
t->Translate(0, 0, a);
double tab[3];
plane->GetCenter(tab);
//change the coordinates of the Plane center and all the plane is translated
translation->TransformPoint(tab, tab);
t->TransformPoint(tab, tab);
plane->SetCenter(tab);
translation->Update();
t->Update();
}
......@@ -254,7 +253,7 @@ void PlaneC ::rotationAxe1() {
// rotate with the difference between what I want (ang) and the current angle (angle1)
double differenceAngle = transfor[1] - angle1;
double differenceAngle = transformation[1] - angle1;
// if this rotation is not too small
if (fabs(differenceAngle) > 0.5) {
......@@ -264,7 +263,7 @@ void PlaneC ::rotationAxe1() {
transfo->RotateWXYZ(double(differenceAngle), tab);
// record the new angle
angle1 = transfor[1];
angle1 = transformation[1];
//Apply the rotation to the normal and all the plane will rotate
transfo->TransformPoint(tabN, tabN);
......@@ -302,7 +301,7 @@ void PlaneC ::rotationAxe2() {
}
// rotate with the difference between what I want (ang) and the current angle (angle2)
double differenceAngle = (double)transfor[2] - (double)angle2;
double differenceAngle = (double)transformation[2] - (double)angle2;
// if this rotation is not too small
if (fabs(differenceAngle) > 0.5) {
......@@ -311,7 +310,7 @@ void PlaneC ::rotationAxe2() {
transfo->RotateWXYZ(differenceAngle, tab);
// record the new angle
angle2 = transfor[2];
angle2 = transformation[2];
//Apply the rotation to the normal and all the plane will rotate
transfo->TransformPoint(tabN, tabN);
......@@ -325,22 +324,22 @@ void PlaneC ::rotationAxe2() {
//--------------------Set the transformation---------------------
void PlaneC ::setTransfoPercentToRealValue(double* tab, double min, double max) {
for (int i = 0; i < 3; i++) {
transfor[i] = tab[i];
transformation[i] = tab[i];
}
translat = transfor[0] * (max - min) / 100;
translation = transformation[0] * (max - min) / 100;
}
//--------------------Get the transformation---------------------
void PlaneC::getTransformationInPercent(double* t, double* r1, double* r2) {
*t = transfor[0];
*r1 = transfor[1];
*r2 = transfor[2];
*t = transformation[0];
*r1 = transformation[1];
*r2 = transformation[2];
}
//--------------------Set the translation---------------------
void PlaneC::setTranslationMaxInPercent(double trans) {
translat = trans;
transfor[0] = 100;
translation = trans;
transformation[0] = 100;
}
//--------------------Get the origin---------------------
......
......@@ -122,14 +122,13 @@ private:
vtkSmartPointer<vtkProperty> aProp;
///store the transformation
double transfor[3];
double transformation[3];
///store the translation in percentage
double translat;
double translation;
/// difference between current and initial position
double angle1;
double angle2;
double translation1;
};
}
......
......@@ -337,8 +337,8 @@ void Explorer::selectionChanged() {
Application::clearSelectedComponents();
// create the new list
ComponentList selectedComponent;
for (int i = 0; i < selectedItems.size(); i++) {
selectedComponent.append((Component*)itemComponentMap.value(selectedItems[i]));
for (auto selectedItem : selectedItems) {
selectedComponent.append((Component*)itemComponentMap.value(selectedItem));
}
// add everything to the selection and update the views
Viewer::selectionChanged(selectedComponent);
......
......@@ -604,8 +604,8 @@ RendererWidget::RendererWidget(QWidget* parent, ControlMode mode) : QVTKWidget2(
orientationDecorationActors[1]->GetPositionCoordinate()->SetValue(0.95, 0.5);
// Left
orientationDecorationActors[0]->GetPositionCoordinate()->SetValue(0.05, 0.5);
for (int i = 0; i < 4; i++) {
addProp(orientationDecorationActors[i]);
for (const auto & orientationDecorationActor : orientationDecorationActors) {
addProp(orientationDecorationActor);
}
......@@ -1118,8 +1118,8 @@ void RendererWidget::updateAxes() {
// ----------------------- toogleOrientationDecorations ---------
void RendererWidget::toggleOrientationDecorations(bool f) {
for (int i = 0; i < 4; i++) {
orientationDecorationActors[i]->SetVisibility(f);
for (auto & orientationDecorationActor : orientationDecorationActors) {
orientationDecorationActor->SetVisibility(f);
}
}
......
......@@ -172,9 +172,9 @@ void DirectShaker::randomDisplacement ( float* position, unsigned int nrOfPoints
double randomDisplacement[3];
double factor = 0.0;
for ( unsigned int j = 0; j < 3; j++ ) {
randomDisplacement[j] = -1. + 2.0 * ( ( double ) rand() ) / ( ( double ) RAND_MAX );
factor += randomDisplacement[j] * randomDisplacement[j];
for (double & value : randomDisplacement) {
value = -1. + 2.0 * ( ( double ) rand() ) / ( ( double ) RAND_MAX );
factor += value * value;
}
// scale up to max
......
......@@ -35,9 +35,9 @@ void ShakerLib::randomDisplacement(float* pos, unsigned int nrOfPoints, double m
float randomDisplacement[3];
float factor = 0.0;
for (unsigned int j = 0; j < 3; j++) {
randomDisplacement[j] = -1. + 2.0 * ((double) rand()) / ((double) RAND_MAX);
factor += randomDisplacement[j] * randomDisplacement[j];
for (float & value : randomDisplacement) {
value = -1. + 2.0 * ((double) rand()) / ((double) RAND_MAX);
factor += value * value;
}
// scale up to max
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment