field.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "field.h"
00023
00024 #include <core/exceptions/software.h>
00025
00026 #include <cmath>
00027 #include <cstring>
00028 #include <stdio.h>
00029
00030 using namespace fawkes;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 Field::Field(FieldLines *lines, bool manage_lines_memory)
00044 {
00045 __lines = lines;
00046 __manage_lines_memory = manage_lines_memory;
00047 }
00048
00049
00050
00051
00052 Field::~Field()
00053 {
00054 if (__manage_lines_memory) delete __lines;
00055 }
00056
00057
00058
00059
00060
00061
00062 float
00063 Field::get_field_length()const
00064 {
00065 return __lines->get_field_length();
00066 }
00067
00068
00069
00070
00071
00072
00073 float
00074 Field::get_field_width() const
00075 {
00076 return __lines->get_field_width();
00077 }
00078
00079
00080
00081
00082
00083
00084 void
00085 Field::print(bool in_mm) const
00086 {
00087 printf("Field lines (start-x -y end-x -y):\n==================================\n");
00088 for (FieldLines::const_iterator it = __lines->begin(); it != __lines->end(); ++it) {
00089 if (in_mm) printf("%d %d %d %d\n", static_cast<int>(it->start.x * 1000), static_cast<int>(it->start.y * 1000), static_cast<int>(it->end.x * 1000), static_cast<int>(it->end.y * 1000));
00090 else printf("%0.03f %0.03f %0.03f %0.03f\n", it->start.x, it->start.y, it->end.x, it->end.y);
00091 }
00092 printf("\n");
00093
00094 printf("Field circles (center-x/y radius start/end angle):\n=============================================\n");
00095 for (field_circles_t::const_iterator it = __lines->get_circles().begin(); it != __lines->get_circles().end(); ++it) {
00096 if (in_mm) printf("%d %d %d %0.03f %0.03f\n", static_cast<int>(it->center.x * 1000), static_cast<int>(it->center.y * 1000), static_cast<int>(it->radius * 1000), it->start_phi, it->end_phi);
00097 else printf("%0.03f %0.03f %0.03f %0.03f %0.03f\n", it->center.x, it->center.y, it->radius, it->start_phi, it->end_phi);
00098 }
00099 printf("\n\n");
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 Field*
00111 Field::field_for_name(std::string field_name, float field_length, float field_width)
00112 {
00113 if (field_name == "Field6x4") return new Field(new FieldLines6x4(field_length, field_width));
00114 else if (field_name == "FieldCityTower") return new Field(new FieldLinesCityTower(field_length, field_width));
00115 else if (field_name == "FieldCityTowerSeminar") return new Field(new FieldLinesCityTowerSeminar(field_length, field_width));
00116 else throw fawkes::IllegalArgumentException("Unknown field name! Please set field_name to a valid value (see field.h)");
00117 }
00118