1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/***************************************************************************
Loads.cpp - description
-------------------
begin : mar f�v 4 2003
copyright : (C) 2003 by Emmanuel Promayon
email : Emmanuel.Promayon@imag.fr
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "Loads.h"
#include "ValueEvent.h"
#include "XMLLoads.h"
#include "LoadsVersion.h"
// ------------------ constructor ------------------
Loads::Loads(std::string fileName) {
XMLLoads xmlReader(fileName, this);
}
// ------------------ destructor ------------------
Loads::~Loads() {
// std::vector method clear() does not delete each elements individually
// this has to be done manually...
// ... so here it is...
// clear all elements from the array
for(std::vector<Load*>::iterator it=loads.begin(); it!=loads.end(); it++)
delete *it; // free the element from memory
// finally, clear all elements from the array
loads.clear();
}
// ------------------ xmlPrint ------------------
/// print the prolog of the xml file
void Loads::xmlPrint(std::ostream & o) const {
o << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
o << "<!-- physical model load file -->" << std::endl;
o << "<loads xmlns='http://www-timc.imag.fr/load'" << std::endl;
o << " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
unsigned int i;
Load * currentL;
for (i=0; i<numberOfLoads(); i++) {
currentL = getLoad(i);
currentL->xmlPrint(o); // o << (*currentL) doesn't work !!!;
o << std::endl;
}
o << "</loads>" << std::endl;
}
// ------------------ ansysPrint ------------------
// Print an ansys translation of the load list (not everything is implemented)
void Loads::ansysPrint(std::ostream & o) const {
o << "! -------------------------------------------- " << std::endl;
o << "! translated from an physical model load file " << std::endl;
o << "! -------------------------------------------- " << std::endl << std::endl;
unsigned int i;
Load * currentL;
for (i=0; i<numberOfLoads(); i++) {
currentL = getLoad(i);
o << "! -- Load #" << i << " (" << currentL->getType() << ")" << std::endl;
currentL->ansysPrint(o);
o << std::endl;
}
o << "! --- end of all selections ---" << std::endl;
o << "ALLSEL" << std::endl;
}
// ------------------ operator << ------------------
std::ostream & operator << (std::ostream & o , const Loads l) {
o << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
o << "<!-- physical model load file -->" << std::endl;
o << "<loads xmlns='http://www-timc.imag.fr/load'" << std::endl;
o << " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
unsigned int i;
Load * currentL;
for (i=0; i<l.numberOfLoads(); i++) {
currentL = l.getLoad(i);
o << (* currentL) << std::endl;
}
o << "</loads>" << std::endl;
return o;
}
// ------------------ addLoad ------------------
void Loads::addLoad(Load *ld) {
loads.push_back(ld);
}
// ------------------ getLoad ------------------
Load * Loads::getLoad(const unsigned int i) const {
if (i<loads.size())
return loads[i];
else
return NULL;
}
// ------------------ numberOfLoads ------------------
unsigned int Loads::numberOfLoads() const {
return loads.size();
}
// ------------------ deleteLoad ------------------
void Loads::deleteLoad(const unsigned int index) {
std::vector <Load *>::iterator it;
it = loads.begin()+index;
loads.erase(it);
}
// ------------------ getFirstEventDate ------------------
/// get the first event date present in the list of loads
double Loads::getFirstEventDate() {
double dateMin = -1.0;
bool foundOne = false;
ValueEvent *ev;
for (unsigned int i=0; i<loads.size(); i++) {
// as events are sorted by date, test only the first event
// of each load
ev = loads[i]->getValueEvent(0);
if (ev && ((foundOne && ev->getDate()<dateMin) || !foundOne)) {
dateMin = ev->getDate();
foundOne=true;
}
}
if (foundOne)
return dateMin;
else
return -1.0;
}
// ------------------ getLastEventDate ------------------
/// get the last event date present in the list of loads
double Loads::getLastEventDate() {
double dateMax = -1.0;
ValueEvent *ev;
for (unsigned int i=0; i<loads.size(); i++) {
// as events are sorted by date, test only the last event
// of each load
ev = loads[i]->getValueEvent(loads[i]->numberOfValueEvents()-1);
if (ev && ev->getDate()>dateMax)
dateMax = ev->getDate();
}
return dateMax;
}
|