diff options
author | Jakob Odersky <jodersky@gmail.com> | 2011-04-02 19:41:50 +0000 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2011-04-02 19:41:50 +0000 |
commit | b0f200e3b07f3963d609d536e6abdde24b96ec21 (patch) | |
tree | 164a73d5eb8ad7e1d4d4d4c538e884940c40cf49 | |
parent | dbd8760e5b935dfd8d6672964075c5064159749f (diff) | |
download | vhc-b0f200e3b07f3963d609d536e6abdde24b96ec21.tar.gz vhc-b0f200e3b07f3963d609d536e6abdde24b96ec21.tar.bz2 vhc-b0f200e3b07f3963d609d536e6abdde24b96ec21.zip |
Implemente le `Visitor Pattern' pour les elements.
-rw-r--r-- | src/gui/Camera.cc | 10 | ||||
-rw-r--r-- | src/gui/Camera.h | 54 | ||||
-rw-r--r-- | src/gui/GElement.cc | 21 | ||||
-rw-r--r-- | src/gui/GElement.h | 28 | ||||
-rw-r--r-- | src/gui/GLWidget.cc | 4 | ||||
-rw-r--r-- | src/gui/Makefile | 2 | ||||
-rw-r--r-- | src/gui/graphicals.h | 35 | ||||
-rw-r--r-- | src/main/CompositeElement.h | 10 | ||||
-rw-r--r-- | src/main/CurvedElement.h | 2 | ||||
-rw-r--r-- | src/main/Dipole.h | 4 | ||||
-rw-r--r-- | src/main/Element.h | 3 | ||||
-rw-r--r-- | src/main/ElementVisitor.cc | 21 | ||||
-rw-r--r-- | src/main/ElementVisitor.h | 46 | ||||
-rw-r--r-- | src/main/Makefile | 2 | ||||
-rw-r--r-- | src/main/Quadrupole.h | 3 | ||||
-rw-r--r-- | src/main/StraightElement.h | 3 |
16 files changed, 243 insertions, 5 deletions
diff --git a/src/gui/Camera.cc b/src/gui/Camera.cc new file mode 100644 index 0000000..32f5773 --- /dev/null +++ b/src/gui/Camera.cc @@ -0,0 +1,10 @@ +/* + * Camera.cc + * + * Created on: Mar 31, 2011 + * Author: jakob + */ + +#include "Camera.h" + + diff --git a/src/gui/Camera.h b/src/gui/Camera.h new file mode 100644 index 0000000..fa17c58 --- /dev/null +++ b/src/gui/Camera.h @@ -0,0 +1,54 @@ +/* + * Camera.h + * + * Created on: Mar 31, 2011 + * Author: jakob + */ + +#ifndef CAMERA_H_ +#define CAMERA_H_ +#include <math.h> +#include "exception.h" + +class Camera { + +private: + double _x; + double _y; + double _z; + + +public: + Camera(double x, double y, double z): _x(x), _y(y), _z(z) {}; + virtual ~Camera(); + + + + static double sign(double value) {return (value > 0) - (value < 0);} + + static void toSpherical(double x, double y, double z, double& r, double&theta, double& phi) { + r = sqrt(x * x + y * y + z * z); + if (r == 0) { + theta = 0; + phi = 0; + return; + } + + theta = acos(z / r); + + if (x > 0) phi = atan(y / x); + else if (x == 0) phi = sign(y) * M_PI / 2; + else if (x < 0 && y >= 0) phi = atan(y / x) + M_PI; + else if (x < 0 && y < 0) phi = atan(y / x) - M_PI; + else throw vhc::Exception("This should not happen!"); + + } + + static void toCarthesian(double r, double theta, double phi, double& x, double& y, double& z) { + x = r * sin(theta) * cos(phi); + y = r * sin(theta) * sin(phi); + z = r * cos(theta); + } +}; + +#endif /* CAMERA_H_ */ diff --git a/src/gui/GElement.cc b/src/gui/GElement.cc new file mode 100644 index 0000000..cbb3cae --- /dev/null +++ b/src/gui/GElement.cc @@ -0,0 +1,21 @@ +/* + * GElement.cc + * + * Created on: Mar 31, 2011 + * Author: jakob + */ + +#include "GElement.h" + +namespace vhc { + +GElement::GElement() { + // TODO Auto-generated constructor stub + +} + +GElement::~GElement() { + // TODO Auto-generated destructor stub +} + +} diff --git a/src/gui/GElement.h b/src/gui/GElement.h new file mode 100644 index 0000000..a62ff74 --- /dev/null +++ b/src/gui/GElement.h @@ -0,0 +1,28 @@ +/* + * GElement.h + * + * Created on: Mar 31, 2011 + * Author: jakob + */ + +#ifndef GELEMENT_H_ +#define GELEMENT_H_ +#include "Element.h" + +namespace vhc { + +class GElement { + + Element& element; + +public: + GElement(Element& element); + + + virtual ~GElement(); + +}; + +} + +#endif /* GELEMENT_H_ */ diff --git a/src/gui/GLWidget.cc b/src/gui/GLWidget.cc index 8d91c16..ee2bb59 100644 --- a/src/gui/GLWidget.cc +++ b/src/gui/GLWidget.cc @@ -98,10 +98,12 @@ void GLWidget::paintGL () { glColor3d(0,0,1); glScaled(300,300,300); + glPolygonMode(GL_FRONT, GL_LINE); glPolygonMode(GL_BACK, GL_LINE); - torus(12, 20, 1, 0.2); + glPolygonMode(GL_FRONT, GL_FILL); + glPolygonMode(GL_BACK, GL_FILL); } void GLWidget::resizeGL (int width, int height) { diff --git a/src/gui/Makefile b/src/gui/Makefile index 3d4afd4..e1f37a2 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: Thu Mar 31 16:54:10 2011 +# Generated by qmake (2.01a) (Qt 4.7.0) on: Sat Apr 2 21:37:01 2011 # Project: gui.pro # Template: app # Command: /usr/bin/qmake -o Makefile gui.pro diff --git a/src/gui/graphicals.h b/src/gui/graphicals.h new file mode 100644 index 0000000..c944e7e --- /dev/null +++ b/src/gui/graphicals.h @@ -0,0 +1,35 @@ +/* + * graphicals.h + * + * Created on: Apr 2, 2011 + * Author: jakob + */ + +#ifndef GRAPHICALS_H_ +#define GRAPHICALS_H_ +#include "Element.h" + +namespace vhc { + +class Renderable { + +public: + + Renderable() {}; + + virtual ~Renderable() {}; + + virtual void render() const = 0; + +}; + +template <class T>; +class Graphical: public Renderable { +private: + T* element +}; + + +} + +#endif /* GRAPHICALS_H_ */ diff --git a/src/main/CompositeElement.h b/src/main/CompositeElement.h index 191e25b..a4d2cae 100644 --- a/src/main/CompositeElement.h +++ b/src/main/CompositeElement.h @@ -11,6 +11,8 @@ #include <vector> #include "Element.h" #include "Vector3D.h" +#include "ElementVisitor.h" + namespace vhc { @@ -66,7 +68,13 @@ public: for (int i(0); i < elements.size(); i++) { e = e + elements[i]->electricFieldAt(position); } - return e; + return e; + } + + virtual void accept(ElementVisitor& v) { + for (int i(0); i < elements.size(); ++i) { + elements[i]->accept(v); + } } }; diff --git a/src/main/CurvedElement.h b/src/main/CurvedElement.h index 7bbb71c..8719a68 100644 --- a/src/main/CurvedElement.h +++ b/src/main/CurvedElement.h @@ -13,6 +13,7 @@ #include "Particle.h" #include "Vector3D.h" + namespace vhc { /** Represente un element courbe. En plus de posseder les proprietes generales d'un element, @@ -69,7 +70,6 @@ public: } - }; } diff --git a/src/main/Dipole.h b/src/main/Dipole.h index 357d209..10d8062 100644 --- a/src/main/Dipole.h +++ b/src/main/Dipole.h @@ -12,6 +12,8 @@ #include <sstream> #include "CurvedElement.h" #include "Vector3D.h" +#include "ElementVisitor.h" + namespace vhc { @@ -63,6 +65,8 @@ public: return s.str(); } + virtual void accept(ElementVisitor& v) {v.visit(this);} + }; diff --git a/src/main/Element.h b/src/main/Element.h index 6840eda..1a8ea44 100644 --- a/src/main/Element.h +++ b/src/main/Element.h @@ -13,6 +13,8 @@ #include "Vector3D.h" #include "Particle.h" #include "Printable.h" +#include "ElementVisitor.h" + namespace vhc { @@ -130,6 +132,7 @@ public: return s.str(); } + virtual void accept(ElementVisitor& v) = 0; }; } diff --git a/src/main/ElementVisitor.cc b/src/main/ElementVisitor.cc new file mode 100644 index 0000000..3510f8b --- /dev/null +++ b/src/main/ElementVisitor.cc @@ -0,0 +1,21 @@ +/* + * ElementVisitor.cc + * + * Created on: Apr 2, 2011 + * Author: jakob + */ + +#include "ElementVisitor.h" + +namespace vhc { + +ElementVisitor::ElementVisitor() { + // TODO Auto-generated constructor stub + +} + +ElementVisitor::~ElementVisitor() { + // TODO Auto-generated destructor stub +} + +} diff --git a/src/main/ElementVisitor.h b/src/main/ElementVisitor.h new file mode 100644 index 0000000..0fda645 --- /dev/null +++ b/src/main/ElementVisitor.h @@ -0,0 +1,46 @@ +/* + * ElementVisitor.h + * + * Created on: Apr 2, 2011 + * Author: jakob + */ + +#ifndef ELEMENTVISITOR_H_ +#define ELEMENTVISITOR_H_ + +//#include "StraightElement.h" +//#include "Quadrupole.h" +//#include "CurvedElement.h" +//#include "Dipole.h" +//#include "CompositeElement.h" +//#include "Element.h" + +namespace vhc { + +class StraightElement; +class Quadrupole; +class CurvedElement; +class Dipole; +class CompositeElement; + + +class ElementVisitor { + +public: + ElementVisitor(); + virtual ~ElementVisitor(); + + virtual void visit(StraightElement* straight) = 0; + + virtual void visit(Quadrupole* quadrupole) = 0; + + virtual void visit(CurvedElement* curved) = 0; + + virtual void visit(Dipole* dipole) = 0; + + virtual void visit(CompositeElement* composite) = 0; +}; + +} + +#endif /* ELEMENTVISITOR_H_ */ diff --git a/src/main/Makefile b/src/main/Makefile index 759954f..1e9dca4 100644 --- a/src/main/Makefile +++ b/src/main/Makefile @@ -14,7 +14,7 @@ LOCALDIR = main # Si un objet nécessite une compilation non-standard (i.e. pas de règle du style Foo.o : Foo.cc Foo.h), rajouter # cette règle. LOCALOBJS = Vector3D.o Particle.o Printable.o Element.o CurvedElement.o StraightElement.o \ - CompositeElement.o Dipole.o Quadrupole.o FODO.o + CompositeElement.o Dipole.o Quadrupole.o FODO.o ElementVisitor.o OBJS=$(addprefix $(BINDIR)/$(LOCALDIR)/,$(LOCALOBJS)) .PHONY = all checkdirs lib diff --git a/src/main/Quadrupole.h b/src/main/Quadrupole.h index 017a543..c2ee6a5 100644 --- a/src/main/Quadrupole.h +++ b/src/main/Quadrupole.h @@ -11,6 +11,7 @@ #include <string> #include "StraightElement.h" #include "Vector3D.h" +#include "ElementVisitor.h" namespace vhc { @@ -44,6 +45,8 @@ public: } virtual std::string getType() const {return "Quadrupole";} + + virtual void accept(ElementVisitor& v) {v.visit(this);} }; } diff --git a/src/main/StraightElement.h b/src/main/StraightElement.h index d9eb5e0..eb493d0 100644 --- a/src/main/StraightElement.h +++ b/src/main/StraightElement.h @@ -11,6 +11,7 @@ #include "Vector3D.h" #include "Element.h" #include "Particle.h" +#include "ElementVisitor.h" namespace vhc { @@ -45,6 +46,8 @@ public: return s.str(); } + virtual void accept(ElementVisitor& v) {v.visit(this);} + }; } |