Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
Commit V2
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Grange committed Mar 31, 2023
0 parents commit e2754bf
Show file tree
Hide file tree
Showing 16 changed files with 856 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Project exclude paths
/cmake-build-debug/
/.idea/
*.o
*/*.o
CMakeLists.txt
projet
5 changes: 5 additions & 0 deletions Constantes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
Constantes.cpp
Louis Grange et Daniel Ataide
Version 1.0
**/
30 changes: 30 additions & 0 deletions Constantes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
Constantes.h
Louis Grange et Daniel Ataide
Version 1.0
**/

#include "Shape/Shape.h"

#ifndef CONSTANTES_H
#define CONSTANTES_H

constexpr short unsigned maxF(25);

constexpr double dmax(128.);
constexpr double delta_t(0.125);
constexpr double r_spatial(16.);
constexpr double r_reparateur(2.);
constexpr double r_neutraliseur(4.);
constexpr double vtran_max(4.); // par seconde
constexpr double vrot_max(0.125); // rad/s
constexpr double epsil_alignement(0.01); // rad

constexpr double desintegration_rate(0.0002);
constexpr double risk_factor(3.);
constexpr double d_particule_min(8*epsil_zero);

constexpr unsigned max_update(600);
constexpr unsigned modulo_update(100);

#endif
60 changes: 60 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# Makefile
# Louis Grange et Daniel Ataide
# Version 1.0
#

OUT = projet
CXX = g++
CXXFLAGS = -Wall -std=c++17
LINKING = `pkg-config --cflags gtkmm-4.0`
LDLIBS = `pkg-config --libs gtkmm-4.0`
CXXFILES = Projet.cpp Simulation/Simulation.cpp \
Particule/Particule.cpp Robot/Robot.cpp Message/Message.cpp \
Shape/Shape.cpp
OFILES = Projet.o Constantes.o Simulation/Simulation.o Particule/Particule.o \
Robot/Robot.o Message/Message.o Shape/Shape.o

all: $(OUT)

$(OUT): $(OFILES)
$(CXX) $(CXXFLAGS) $(LINKING) $(OFILES) -o $@ $(LDLIBS)

depend:
@echo " *** MISE A JOUR DES DEPENDANCES ***"
@(sed '/^# DO NOT DELETE THIS LINE/q' Makefile && \
$(CXX) -MM $(CXXFLAGS) $(CXXFILES) | \
egrep -v "/usr/include" \
) >Makefile.new
@mv Makefile.new Makefile

clean:
@echo "*** MODULES OBJETS ET EXECUTABLES EFFACES ***"
@/bin/rm -f *.o */*.o $(OUT)

Projet.o: Projet.cpp Simulation/Simulation.cpp Simulation/Simulation.h
$(CXX) $(CXXFLAGS) $(LINKING) -c $< -o $@ $(LINKING)

Simulation.o: Simulation/Simulation.cpp Simulation/Simulation.h \
Simulation/../Particule/Particule.h \
Simulation/../Particule/../Shape/Shape.h \
Simulation/../Particule/../Constantes.h \
Simulation/../Particule/../Message/Message.h \
Simulation/../Robot/Robot.h Simulation/../Robot/../Message/Message.h \
Simulation/../Robot/../Shape/Shape.h \
Simulation/../Robot/../Particule/Particule.h

Particule.o: Particule/Particule.cpp Particule/Particule.h \
Particule/../Shape/Shape.h Particule/../Constantes.h \
Particule/../Message/Message.h

Robot.o: Robot/Robot.cpp Robot/Robot.h Robot/../Message/Message.h \
Robot/../Shape/Shape.h Robot/../Particule/Particule.h \
Robot/../Particule/../Shape/Shape.h Robot/../Particule/../Constantes.h \
Robot/../Particule/../Message/Message.h Robot/../Constantes.h
$(CXX) $(CXXFLAGS) $(LINKING) -c $< -o $@ $(LINKING)

Message.o: Message/Message.cpp Message/Message.h

Shape.o: Shape/Shape.cpp Shape/Shape.h
$(CXX) $(CXXFLAGS) $(LINKING) -c $< -o $@ $(LINKING)
97 changes: 97 additions & 0 deletions Message/Message.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// message.cc : fonctions pour l'affichage des messages d'erreur
// Version 1.2: fonctions supplémentaire pour indiquer le succès de la lecture
// Version 1.1: 9 fonctions de messages d'erreurs à utiliser pour le projet
//

#include "Message.h"

using namespace std;

namespace
{
void reorder_for_consistency(double & x1, double & y1, double & x2, double & y2)
{
if(x1 > x2 || (x1 == x2 && y1 > y2))
{
swap(x1, x2);
swap(y1, y2);
}
}
}

string message::particle_outside(double x, double y, double s)
{
return string("Particle at (") + to_string(x) + string(";") + to_string(y)
+ string(") of size ") + to_string(s) + string(" is outside boundaries\n");
}

string message::particle_too_small(double x, double y, double s)
{
return string("Particle at (") + to_string(x) + string(";") + to_string(y)
+ string(") of size ") + to_string(s) + string(" is too small\n");
}


string message::spatial_robot_ouside(double x, double y)
{
return string("Spatial robot at (") + to_string(x) + string(";") + to_string(y)
+ string(") is outside boundaries\n");
}

std::string message::invalid_k_update(double x, double y, int k_update, int max_update)
{
return string("A robot at (") + to_string(x) + string(";") + to_string(y)
+ string(") has a k_update of ") + to_string(k_update)
+ string(" which is greater than the maximum of ") + to_string(max_update)
+ string("\n");
}


string message::particle_superposition(double x1, double y1, double x2, double y2)
{
reorder_for_consistency(x1, y1, x2, y2);

return string("Particle at (") + to_string(x1) + string(";") + to_string(y1)
+ string(") and particle at (") + to_string(x2) + string(";") + to_string(y2)
+ string(") are in superposition\n");
}

string message::repairers_superposition(double x1, double y1, double x2, double y2)
{
reorder_for_consistency(x1, y1, x2, y2);

return string("Repairer at (") + to_string(x1) + string(";") + to_string(y1)
+ string(") and repairer at (") + to_string(x2) + string(";") + to_string(y2)
+ string(") are in superposition\n");
}

string message::neutralizers_superposition(double x1, double y1, double x2, double y2)
{
reorder_for_consistency(x1, y1, x2, y2);

return string("Neutralizer at (") + to_string(x1) + string(";") + to_string(y1)
+ string(") and neutralizer at (") + to_string(x2) + string(";")
+ to_string(y2) + string(") are in superposition\n");
}

string message::repairer_neutralizer_superposition(double xr, double yr,
double xn, double yn)
{
return string("Repairer at (") + to_string(xr) + string(";") + to_string(yr)
+ string(") and neutralizer at (") + to_string(xn) + string(";")
+ to_string(yn) + string(") are in superposition\n");
}

std::string message::particle_robot_superposition(double xp, double yp, double sp,
double xr, double yr, double rr)
{
return string("Particle at (") + to_string(xp) + string(";") + to_string(yp)
+ string(") of size ") + to_string(sp) + string(" and robot at (")
+ to_string(xr) + string(";") + to_string(yr) + string(") of radius ")
+ to_string(rr) + string(" are in superposition\n");
}

string message::success()
{
return string("Correct file\n");
}
31 changes: 31 additions & 0 deletions Message/Message.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef MESSAGE_H_INCLUDED
#define MESSAGE_H_INCLUDED

// message.h : fonctions pour l'affichage des messages d'erreur
// Version 1.2: fonctions supplémentaire pour indiquer le succès de la lecture
// Version 1.1: 9 fonctions de messages d'erreurs à utiliser pour le projet
//

#include <string>

namespace message
{
std::string particle_outside(double x, double y, double s);
std::string particle_too_small(double x, double y, double s);

std::string spatial_robot_ouside(double x, double y);
std::string invalid_k_update(double x, double y, int k_update, int max_update);

std::string particle_superposition(double x1, double y1, double x2, double y2);
std::string repairers_superposition(double x1, double y1, double x2, double y2);
std::string neutralizers_superposition(double x1, double y1, double x2, double y2);
std::string repairer_neutralizer_superposition(double xr, double yr,
double xn, double yn);
std::string particle_robot_superposition(double xp, double yp, double sp,
double xr, double yr, double rr);

// Everything went well => file reading and all validation checks
std::string success();
}

#endif // MESSAGE_H_INCLUDED
31 changes: 31 additions & 0 deletions Particule/Particule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
Particule.cpp
Louis Grange et Daniel Ataide
Version 1.0
**/

#include "Particule.h"
#include <sstream>
using namespace std;


Particule::Particule(Carre c) {
if (c.cote >= d_particule_min) {
forme_ = c;
} else {
cout << message::particle_too_small(c.centre.x, c.centre.y, c.cote);
exit(EXIT_FAILURE);
}
test_domaine(c);
}

void test_domaine(Carre c) {
if(abs(c.centre.x) >= (dmax - c.cote/2)) {
cout << message::particle_outside(c.centre.x, c.centre.y, c.cote);
exit(EXIT_FAILURE);
}
if(abs(c.centre.y) >= (dmax - c.cote/2)) {
cout << message::particle_outside(c.centre.x, c.centre.y, c.cote);
exit(EXIT_FAILURE);
}
}
25 changes: 25 additions & 0 deletions Particule/Particule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
Particule.h
Louis Grange et Daniel Ataide
Version 1.0
**/

#include <iostream>
#include "../Shape/Shape.h"
#include "../Constantes.h"
#include "../Message/Message.h"

#ifndef PARTICULE_H
#define PARTICULE_H

class Particule {
public:
Particule() = delete;
explicit Particule(Carre c);
Carre get_forme() const { return forme_; }
private:
Carre forme_;
};

void test_domaine(Carre c);
#endif
36 changes: 36 additions & 0 deletions Projet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
Projet.cpp
Louis Grange et Daniel Ataide
Version 1.0
**/

#include "Simulation/Simulation.h"
#include <iostream>
#include <gtkmm/window.h>
#include <gtkmm/application.h>
using namespace std;

class ExampleWindow : public Gtk::Window
{
public:
ExampleWindow();
};

ExampleWindow::ExampleWindow()
{
set_default_size(820, 350);
set_title("EPFL Logo");
}


int main(int argc, char *argv[]) {
S2d position;
Spatial spatial(position, 0, 0, 0, 0, 0, 0);
Simulation simulation(0, spatial);
if(argc < 1) {
exit(0);
}
simulation.lecture(argv[1]);
auto app = Gtk::Application::create();
return app->make_window_and_run<ExampleWindow>(1, argv);
}
46 changes: 46 additions & 0 deletions Robot/Robot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
Robot.cpp
Louis Grange et Daniel Ataide
Version 1.1
**/

#include "Robot.h"
#include "../Constantes.h"
using namespace std;

Neutraliseur::Neutraliseur(S2d position, double angle, int coordination, bool panne,
int k_update_panne, int nbUpdate)
: angle_(angle), panne_(panne), coordination_(coordination) {
if(k_update_panne > nbUpdate) {
cout << message::invalid_k_update(position.x, position.y, k_update_panne,
nbUpdate);
exit(EXIT_FAILURE);
}
forme_ = Cercle(position, r_neutraliseur);
}

Reparateur::Reparateur(S2d position)
: forme_(Cercle(position, r_reparateur)) {

}

Spatial::Spatial(S2d position, int nbUpdate, int nbNr, int nbNs, int nbNd,
int nbRr, int nbRs)
: nbUpdate_(nbUpdate), nbNr_(nbNr), nbNs_(nbNs), nbNd_(nbNd),
nbRr_(nbRr), nbRs_(nbRs) {
if(abs(position.x) < dmax - r_spatial
and abs(position.y) < dmax - r_spatial) {
forme_ = Cercle(position, r_spatial);
} else {
cout << message::spatial_robot_ouside(position.x, position.y);
exit(EXIT_FAILURE);
}
}

int Spatial::get_nbR_tot() const {
return (nbRr_ + nbRs_);
}

int Spatial::get_nbN_tot() const {
return (nbNr_ + nbNs_ + nbNd_);
}
Loading

0 comments on commit e2754bf

Please sign in to comment.