GEMC  2.3
Geant4 Monte-Carlo Framework
detector_editor.cc
Go to the documentation of this file.
1 // Qt headers
2 #include <QtWidgets>
3 
4 // G4 headers
5 #include "G4UnitsTable.hh"
6 
7 // gemc headers
8 #include "detector_editor.h"
9 #include "images/g4Box_xpm.h"
10 #include "images/g4Cons_xpm.h"
12 #include "images/g4Sphere_xpm.h"
13 #include "images/g4Trd_xpm.h"
14 #include "images/g4Trap_xpm.h"
15 #include "images/g4Tubs_xpm.h"
16 #include "images/g4Torus_xpm.h"
18 #include "images/g4Copy_xpm.h"
19 #include "images/g4Operation_xpm.h"
20 #include "string_utilities.h"
21 #include "utils.h"
22 
23 // C++ headers
24 #include <iostream>
25 #include <sstream>
26 using namespace std;
27 
28 // CLHEP units
29 #include "CLHEP/Units/PhysicalConstants.h"
30 using namespace CLHEP;
31 
32 
34 {
35  det = Det;
36 
37  if(det)
38  {
39  // detector name, description
40  string d_name = "Name: '" + det->name + "', daughter of '" + det->mother + "'";
41  nameLabel->setText(d_name.c_str());
42 
43  string d_desc = "Description: " + det->description ;
44  descLabel->setText(d_desc.c_str());
45 
46  // position and rotation
47  string xyzpos = "( " +
48  stringify(det->pos.getX()/mm) + ", " +
49  stringify(det->pos.getY()/mm) + ", " +
50  stringify(det->pos.getZ()/mm) + ") mm";
51 
52  placeEdit->setText(xyzpos.c_str());
53 
54 
55  string xyzrot = "( " +
56  stringify(det->rot.getPhi()/deg) + ", " +
57  stringify(det->rot.getTheta()/deg) + ", " +
58  stringify(det->rot.getPsi()/deg) + ") deg ";
59 
60  rotEdit->setText(xyzrot.c_str());
61 
62  // solid type and all dimensions
63  string typeDims = det->type.c_str();
64  vector< vector<string> > dimTypes = dimensionstype(det->type);
65  for(unsigned int i=0; i<dimTypes.size(); i++)
66  {
67  stringstream Dim;
68  string d1, d2, dtot;
69  Dim << G4BestUnit(det->dimensions[i], dimTypes[i][1]);
70  Dim >> d1 >> d2;
71  dtot = d1 + "*" + d2 ;
72  typeDims = typeDims + "\n" + dimTypes[i][0] + ": " + dtot;
73  }
74  solidType->setText(typeDims.c_str());
75  solidType->setStyleSheet("font: 12pt;");
76 
77 
78  if(det->type == "Box") solidpic = QPixmap(aBox_xpm);
79  if(det->type == "Tube") solidpic = QPixmap(aTubs_xpm);
80  if(det->type == "Cons") solidpic = QPixmap(aCons_xpm);
81  if(det->type == "G4Trap") solidpic = QPixmap(aTrap_xpm);
82  if(det->type == "ITrd") solidpic = QPixmap(aTrap_xpm);
83  if(det->type == "Trd") solidpic = QPixmap(aTrd_xpm);
84  if(det->type == "Sphere") solidpic = QPixmap(aSphere_xpm);
85  if(det->type == "Torus") solidpic = QPixmap(aTorus_xpm);
86  if(det->type == "Polycone") solidpic = QPixmap(aBREPSolidPCone_xpm);
87  if(det->type == "Ellipsoid") solidpic = QPixmap(aEllipticalTube_xpm);
88  if(det->type.find("CopyOf") != string::npos) solidpic = QPixmap(copy_xpm);
89  if(det->type.find("Operation:") != string::npos) solidpic = QPixmap(operation_xpm);
90  // the images are already scaled to 150 so no need to do this
91  // solidPicL->setPixmap(solidpic.scaledToWidth(150.0));
92  solidPicL->setPixmap(solidpic);
93 
94 
95 
96  string what;
97  // material
98  what = "Material: " + det->material;
99  matLabel->setText(what.c_str());
100 
101 
102  if(det->magfield == "no")
103  what = "Magnetic Field: inherited" ;
104  else
105  what = "Magnetic Field: " + det->magfield;
106  mgnLabel->setText(what.c_str());
107 
108  what = "Sensitivity: " + det->sensitivity + " Hit Process: " + det->hitType;
109  sensHitLabel->setText(what.c_str());
110 
111  if(det->identity.size())
112  {
113  what = "id: " ;
114  for(unsigned int i=0; i<det->identity.size(); i++)
115  what = what + det->identity[i].name + " " + stringify(det->identity[i].id) + " ";
116 
117  idLabel->setText(what.c_str());
118  }
119 
120 
121  }
122 }
123 
124 
126 {
127  // Detector = detect;
128  nameLabel = new QLabel(tr("Placeholder for Volume Name"));
129  descLabel = new QLabel(tr("Placeholder for Volume description"));
130  nameLabel->setWordWrap(true);
131  descLabel->setWordWrap(true);
132 
133  // type and dimensions
134  solidType = new QLabel("placeholder for type");
135  solidType->setFrameStyle(QFrame::Panel | QFrame::Sunken);
136  solidType->setWordWrap(true);
137  solidType->setMinimumWidth (200);
138 
139  solidpic = QPixmap(aBox_xpm);
140  solidPicL = new QLabel();
141  solidPicL->setPixmap(solidpic);
142 
143  QSplitter *splitter = new QSplitter(Qt::Horizontal);
144 
145  QWidget *leftWidget = new QWidget(splitter);
146  QVBoxLayout *leftLayout = new QVBoxLayout(leftWidget);
147  leftLayout->addWidget(solidType);
148 
149 
150  QWidget *rightWidget = new QWidget(splitter);
151  QVBoxLayout *rightLayout = new QVBoxLayout(rightWidget);
152  rightLayout->addWidget(solidPicL);
153 
154 
155  // position
156  QLabel *placeLabel = new QLabel("(X,Y,Z) Position");
157  placeEdit = new QLineEdit(tr("placeholder for (X,Y,Z) pos"));
158 
159  // rotation
160  QLabel *rotLabel = new QLabel("(phi, theta, psi) Euler rotation");
161  rotEdit = new QLineEdit("placeholder for (X,Y,Z) rot");
162 
163 
164  matLabel = new QLabel(tr("Placeholder for material "));
165  mgnLabel = new QLabel(tr("Placeholder for magnetic field"));
166  sensHitLabel = new QLabel(tr("Placeholder for sensitivity, Hit process"));
167  idLabel = new QLabel(tr("Placeholder for identifier"));
168  idLabel->setWordWrap(true);
169  idLabel->setMaximumWidth (300);
170 
171 
172 
173  // all layouts
174  QVBoxLayout *mainLayout = new QVBoxLayout;
175 
176  mainLayout->addWidget(nameLabel);
177  mainLayout->addWidget(descLabel);
178  mainLayout->addWidget(splitter);
179 
180  mainLayout->addWidget(placeLabel);
181  mainLayout->addWidget(placeEdit);
182 
183  mainLayout->addWidget(rotLabel);
184  mainLayout->addWidget(rotEdit);
185 
186  mainLayout->addWidget(matLabel);
187  mainLayout->addWidget(mgnLabel);
188  mainLayout->addWidget(sensHitLabel);
189  mainLayout->addWidget(idLabel);
190 
191  mainLayout->addStretch(10);
192 
193  setLayout(mainLayout);
194 
195  // dont connect these just yet, coordinate not set yet?
196 // connect ( placeXEdit , SIGNAL( textChanged (QString) ), this, SLOT( change_placement() ) );
197 // connect ( placeYEdit , SIGNAL( textChanged (QString) ), this, SLOT( change_placement() ) );
198 // connect ( placeZEdit , SIGNAL( textChanged (QString) ), this, SLOT( change_placement() ) );
199 }
200 
201 
202 
203 void descriptionTab::change_dimension()
204 {
205 // vector<double> newdimensions;
206 // vector< vector<string> > dimTypes = dimensionstype(det->type);
207 // for(unsigned int i=0; i<dimTypes.size(); i++)
208 // newdimensions.push_back(get_number(qs_tostring(dimTypesEdit[i]->text())));
209 // det->dimensions = newdimensions;
210 
211 }
212 
213 
214 void descriptionTab::change_placement()
215 {
216 
217 // double x = get_number(qs_tostring(placeXEdit->text()));
218 // double y = get_number(qs_tostring(placeYEdit->text()));
219 // double z = get_number(qs_tostring(placeZEdit->text()));
220 
221 // Detector->pos = G4ThreeVector(x, y, z);
222 }
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
QLineEdit * rotEdit
line editor for rotation
void update_detector(detector *Det)
change tab according to detector
QLabel * descLabel
label for description
QLabel * sensHitLabel
label for sensitivity, Hit process
STL namespace.
QLabel * mgnLabel
label for magnetic field
QLabel * nameLabel
label for name
QLabel * placeLabel
label for position
vector< vector< string > > dimensionstype(string solidtype)
Returns dimensions nomenclature for different solid type.
Definition: detector.cc:922
QLabel * matLabel
label for material
string stringify(double x)
string name
Name of the volume. Since this is the key of the STL map, it has to be unique.
Definition: detector.h:67
QLabel * rotLabel
label for rotation
QLabel * idLabel
label for identifier
QPixmap solidpic
solid pic from G4
descriptionTab(QWidget *parent=0)
Constructor.
QLabel * solidType
label for solid type
QLabel * solidPicL
container for solid pic
QLineEdit * placeEdit
line editor for position