diff options
-rw-r--r-- | src/gui/Makefile | 2 | ||||
-rw-r--r-- | src/main/Accelerator.cc | 55 | ||||
-rw-r--r-- | src/main/Accelerator.h | 6 | ||||
-rw-r--r-- | src/main/CompositeElement.cc | 18 | ||||
-rw-r--r-- | src/main/CompositeElement.h | 25 | ||||
-rw-r--r-- | src/main/Element.h | 1 |
6 files changed, 56 insertions, 51 deletions
diff --git a/src/gui/Makefile b/src/gui/Makefile index 75975e6..dca1daf 100644 --- a/src/gui/Makefile +++ b/src/gui/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: $(BINDIR)/gui/gui -# Generated by qmake (2.01a) (Qt 4.7.0) on: Tue Apr 12 19:39:44 2011 +# Generated by qmake (2.01a) (Qt 4.7.0) on: Tue Apr 12 19:57:02 2011 # Project: gui.pro # Template: app # Command: /usr/bin/qmake -o Makefile gui.pro diff --git a/src/main/Accelerator.cc b/src/main/Accelerator.cc index ddc2d81..01f4f90 100644 --- a/src/main/Accelerator.cc +++ b/src/main/Accelerator.cc @@ -8,33 +8,36 @@ #include "Accelerator.h" namespace vhc { - /** Cf. Accelerator.h */ - std::string Accelerator::toString() const { - std::stringstream s; - if (elementCollec.size()==0) { - s<<"This accelerator doesn't contain anything."<<"\n"; - }else if (elementCollec.size()==1) { - s<<"This accelerator is made of the following element :"<<"\n"; - s<<elementCollec[0]->toString()<<"\n"; - }else{ - s<<"This accelerator is made of the "<<elementCollec.size()<<" following elements :"<<"\n"; - for (int i(1); elementCollec.size(); ++i){ - s<<elementCollec[i-1]->toString()<<"\n"; - } - } +/** Cf. Accelerator.h */ +std::string Accelerator::toString() const { - if (elementCollec.size()!=0 || particleCollec.size()==0) { - s<<"This accelerator doesn't contain any particle."<<"\n"; - }else if (particleCollec.size()==1) { - s<<"This accelerator contains the following particle :"<<"\n"; - s<<particleCollec[0]->toString()<<"\n"; - }else{ - s<<"This accelerator contains the "<<particleCollec.size()<<" following particles :"<<"\n"; - for (int i(1); particleCollec.size(); ++i){ - s<<particleCollec[i-1]->toString()<<"\n"; - } - } - return s.str(); + std::stringstream s; + if (elementCollec.size() == 0) { + s << "This accelerator doesn't contain anything."<<"\n"; + } else if (elementCollec.size()==1) { + s << "This accelerator is made of the following element :" << "\n"; + s << elementCollec[0]->toString()<<"\n"; + } else { + s << "This accelerator is made of the " << elementCollec.size() << " following elements :" << "\n"; + for (int i(0); i < elementCollec.size(); ++i){ + s << elementCollec[i]->toString() << "\n"; + } + } + + + if (particleCollec.size() == 0) { + s << "This accelerator doesn't contain any particle." << "\n"; + } else if (particleCollec.size() == 1) { + s << "This accelerator contains the following particle :" << "\n"; + s << particleCollec[0]->toString() << "\n"; + }else{ + s << "This accelerator contains the " << particleCollec.size() << " following particles :"<<"\n"; + for (int i(0); i < particleCollec.size(); ++i){ + s << particleCollec[i]->toString() << "\n"; + } + } + + return s.str(); }; } diff --git a/src/main/Accelerator.h b/src/main/Accelerator.h index 48125da..788fa74 100644 --- a/src/main/Accelerator.h +++ b/src/main/Accelerator.h @@ -22,7 +22,7 @@ private : Accelerator (Accelerator const& autre) {} /** Opérateur '=' ne faisant rien. */ - bool operator= (Accelerator const& autre) const {} + void operator= (Accelerator const& autre) const {} protected: @@ -42,12 +42,12 @@ public: /* Retourne un pointeur sur un élément de l'accélérateur, * il n'y a pas besoin d'avoir l'élément lui-même. * Question : où mettre le 'delete' ? */ - Element* getElement (int rank) const { return elementCollec[rank-1]; } + Element* getElement(int rank) const { return elementCollec[rank]; } /* Retourne un pointeur sur une particule de l'accélérateur, * il n'y a pas besoin d'avoir la particule elle-même. * Question : où mettre le 'delete' ? */ - Particle* getParticle(int rank) const { return particleCollec[rank-1]; rank} + Particle* getParticle(int rank) const { return particleCollec[rank];} /** Retourne une représentation en chaîne de caractères de cet accélérateur. */ virtual std::string toString() const; diff --git a/src/main/CompositeElement.cc b/src/main/CompositeElement.cc index dace10d..44714ea 100644 --- a/src/main/CompositeElement.cc +++ b/src/main/CompositeElement.cc @@ -9,5 +9,23 @@ namespace vhc { +CompositeElement::CompositeElement(const Vector3D& entry, const Vector3D& exit, double sectionRadius, Element* next): + Element(entry, exit, sectionRadius, next), + elements(0) {}; + +CompositeElement::~CompositeElement() {}; + +bool CompositeElement::isOutside(const Particle& particle) const { + for (int i(0); i < elements.size(); ++i) { + if (elements[i]->isOutside(particle)) return true; + } + return false; +} + +bool CompositeElement::isPast(const Particle& particle) const { + if (elements[elements.size() - 1]->isPast(particle)) return true; + else return false; +} + } diff --git a/src/main/CompositeElement.h b/src/main/CompositeElement.h index b2fbd5a..90cb6a5 100644 --- a/src/main/CompositeElement.h +++ b/src/main/CompositeElement.h @@ -29,31 +29,14 @@ protected: public: - CompositeElement(const Vector3D& entry, const Vector3D& exit, double sectionRadius, Element* next = NULL): - Element(entry, exit, sectionRadius, next), - elements(0) {}; - - - virtual ~CompositeElement() {}; - - /*for (int i(0); i < elements.size(); ++i) { - delete elements[i]; - elements[i] = NULL; - };*/ + CompositeElement(const Vector3D& entry, const Vector3D& exit, double sectionRadius, Element* next = NULL); + virtual ~CompositeElement(); /** Determine si une particule a heurte le bord de cet element, donc d'un des elements composants. */ - virtual bool isOutside(const Particle& particle) const { - for (int i(0); i < elements.size(); ++i) { - if (elements[i]->isOutside(particle)) return true; - } - return false; - } + virtual bool isOutside(const Particle& particle) const; /** Determine si une particule a passe cet element, donc passe le dernier element composant. */ - virtual bool isPast(const Particle& particle) const { - if (elements[elements.size() - 1]->isPast(particle)) return true; - else return false; - } + virtual bool isPast(const Particle& particle) const; virtual Vector3D magneticFieldAt(const Vector3D& position) const { Vector3D b = Vector3D::Null; diff --git a/src/main/Element.h b/src/main/Element.h index 1a8ea44..8e491ad 100644 --- a/src/main/Element.h +++ b/src/main/Element.h @@ -67,6 +67,7 @@ public: virtual ~Element() {}; /** Copie l'element sur le heap et renvoye un pointeur sur la copie. + * En copiant un element, le pointeur sur l'element suivant est remis a zero. * ATTENTION: La delocation de memoire est sous la responsabilite de l'appelant. */ //virtual Element* copy() const = 0; |