11 #include <top/dbobjects/TOPGeoBarSegment.h>
12 #include <framework/gearbox/Unit.h>
13 #include <framework/logging/Logger.h>
25 bool TOPGeoBarSegment::isConsistent()
const
27 if (m_width <= 0)
return false;
28 if (m_thickness <= 0)
return false;
29 if (m_length <= 0)
return false;
30 if (m_material.empty())
return false;
31 if (m_glueThickness <= 0)
return false;
32 if (m_glueMaterial.empty())
return false;
33 if (m_surface.getName().empty() and !m_surface.hasProperties())
return false;
34 if (m_sigmaAlpha < 0)
return false;
35 if (m_brokenFraction > 0 and m_brokenGlueMaterial.empty())
return false;
40 void TOPGeoBarSegment::print(
const std::string& title)
const
42 TOPGeoBase::print(title);
43 cout <<
" Vendor: " << getVendor() <<
", serial number: " << getSerialNumber() << endl;
44 cout <<
" Dimensions: " << getWidth() <<
" X " << getThickness() <<
" X " << getLength()
45 <<
" " << s_unitName << endl;
46 cout <<
" Material: " << getMaterial() << endl;
47 cout <<
" Glue: " << getGlueMaterial() <<
", thickness = " << getGlueThickness()
49 cout <<
", broken fraction = " << getBrokenGlueFraction();
50 if (getBrokenGlueFraction() > 0) {
51 cout <<
", angle = " << getBrokenGlueAngle() / Unit::deg <<
" deg";
52 cout <<
", material = " << getBrokenGlueMaterial();
55 printSurface(m_surface);
56 cout <<
" - sigmaAlpha: " << getSigmaAlpha() << endl;
59 typedef std::pair<double, double>
Pair;
61 std::vector<std::pair<double, double> > TOPGeoBarSegment::getBrokenGlueContour()
const
64 std::vector<Pair> contour;
65 constructContour(getWidth() / 2, getThickness() / 2, m_brokenFraction, m_brokenAngle,
72 void TOPGeoBarSegment::constructContour(
double A,
double B,
double fraction,
double angle,
73 std::vector<Pair>& contour)
const
79 contour.push_back(
Pair(-A, B));
80 contour.push_back(
Pair(A, B));
81 contour.push_back(
Pair(A, -B));
82 contour.push_back(
Pair(-A, -B));
86 double alpha0 = atan(B / A);
87 double halfPi = alpha0 > 0 ? M_PI / 2 : -M_PI / 2;
89 while (fabs(angle) > alpha0) {
91 alpha0 = M_PI / 2 - alpha0;
97 quadrant = quadrant % 4;
98 if (halfPi < 0) quadrant = (4 - quadrant) % 4;
100 double tanAngle = tan(fabs(angle));
101 double S0 = A / B * tanAngle / 2;
102 if (fraction <= S0) {
103 double x = sqrt(8 * A * B * fraction / tanAngle);
104 double y = x * tanAngle;
106 contour.push_back(
Pair(-A, B - y));
107 contour.push_back(
Pair(-A, B));
108 contour.push_back(
Pair(-A + x, B));
110 contour.push_back(
Pair(A, B - y));
111 contour.push_back(
Pair(A - x, B));
112 contour.push_back(
Pair(A, B));
114 }
else if (1 - fraction <= S0) {
115 double x = sqrt(8 * A * B * (1 - fraction) / tanAngle);
116 double y = x * tanAngle;
118 contour.push_back(
Pair(A, -B + y));
119 contour.push_back(
Pair(A - x, -B));
120 contour.push_back(
Pair(-A, -B));
121 contour.push_back(
Pair(-A, B));
122 contour.push_back(
Pair(A, B));
124 contour.push_back(
Pair(-A + x, -B));
125 contour.push_back(
Pair(-A, -B + y));
126 contour.push_back(
Pair(-A, B));
127 contour.push_back(
Pair(A, B));
128 contour.push_back(
Pair(A, -B));
131 double y = (1 - 2 * fraction) * B;
132 double dy = angle > 0 ? A * tanAngle : -A * tanAngle;
133 contour.push_back(
Pair(-A, y - dy));
134 contour.push_back(
Pair(-A, B));
135 contour.push_back(
Pair(A, B));
136 contour.push_back(
Pair(A, y + dy));
143 for (
auto& point : contour) {
144 double x = -point.second;
145 double y = point.first;
151 for (
auto& point : contour) {
152 double x = -point.first;
153 double y = -point.second;
159 for (
auto& point : contour) {
160 double x = point.second;
161 double y = -point.first;
167 B2ERROR(
"TOPGeoBarSegment::constructContour: bug!");