4 #include <QActionGroup> 5 #include <QColorDialog> 27 G4RunManager* RM, G4VisManager* VM, G4UImanager* UIM,
28 map<string, G4Material*> MMap)
36 setWindowTitle(
"Volumes Tree");
37 setGeometry(200, 200, 400, 700);
45 treeWidget =
new QTreeWidget(
this);
46 treeWidget->setGeometry(0, 0, 400, 700);
48 treeWidget->setColumnCount(1);
50 headers << tr(
"Volumes") ;
51 treeWidget->setHeaderLabels(headers);
56 treeWidget->setContextMenuPolicy( Qt::ActionsContextMenu );
57 treeWidget-> addAction( Switch_visibility );
58 treeWidget-> addAction( Switch_visibility_daughters );
59 treeWidget-> addAction( Switch_wiresolid );
60 treeWidget-> addAction( Switch_color );
61 treeWidget-> addAction( Edit_Detector );
62 treeWidget-> addAction( Write_GDML_File );
70 cout << hd_msg <<
" Detector Widget Tree Deleted." << endl;
72 delete Switch_visibility;
73 delete Switch_wiresolid;
79 string hd_msg =
gemcOpt.
args[
"LOG_MSG"].args +
" Detector Tree >> " ;
89 cout << hd_msg <<
" Building Detector Widget Tree from Geometry STL Map..." << endl << endl;
90 cout << hd_msg <<
" Experimenta Hall has " <<
Hall_Map->size() <<
" components." << endl << endl;
96 for(map<string, detector>::iterator i =
Hall_Map->begin(); i !=
Hall_Map->end(); i++)
98 item.
volume = i->second.name;
99 item.
mother = i->second.mother;
103 if(i->second.sensitivity !=
"no")
106 item.
exist = i->second.exist;
107 item.
visible = i->second.visible;
110 if(i->second.name !=
"root" && i->second.GetLogical())
112 tree_map.insert(map<string, tree_item>::value_type(i->second.name, item));
113 if(VERB > 3) cout << hd_msg <<
" Mapping Detector " << i->first << endl;
117 if(VERB > 3) cout << endl << endl;
119 ActiveGrad = QLinearGradient(QPointF(1, 100), QPointF(180, 70));
120 ActiveGrad.setColorAt(0, QColor( 80, 80, 255));
121 ActiveGrad.setColorAt(1, QColor(245, 245, 245));
123 SensitiveGrad = QLinearGradient(QPointF(1, 100), QPointF(180, 20));
127 NonActiveGrad = QLinearGradient(QPointF(1, 100), QPointF(10, 30));
131 NonVisibleGrad = QLinearGradient(QPointF(1, 100), QPointF(60, 30));
143 vector<string> relatives;
145 if(VERB > 2) cout << endl << hd_msg <<
" Reordering Tree Elements..." << endl << endl;
146 for(map<string, tree_item>::iterator i = tree_map.begin(); i != tree_map.end(); i++)
148 if(i->first !=
"" && i->first !=
"root") relatives.push_back(i->second.volume);
150 while(relatives.size() > 0 && relatives.size() < 100)
152 mom = tree_map[relatives.back()].mother;
153 kid = tree_map[relatives.back()].volume;
158 for(
unsigned int i=0; i<relatives.size()-1; i++) cout <<
"\t";
159 cout << hd_msg <<
" Checking " << kid <<
", child of " << mom
160 <<
", for a living ancestor. This Geneaology Depth is " << relatives.size() <<
"." << endl;
164 if(tree_map[kid].scanned == 0 && mom.find(
"root", 0) != string::npos)
168 for(
unsigned int i=0; i<relatives.size()-1; i++) cout <<
"\t";
169 cout << hd_msg <<
" Found: " << relatives.back()
170 <<
" has <root> as mom and it's not built yet. Building " << kid <<
"..." << endl;
172 tree_map[kid].treeItem =
new QTreeWidgetItem(motherWidget);
173 tree_map[kid].treeItem->setText(0, kid.c_str());
174 tree_map[kid].scanned = 1;
178 if(tree_map[kid].scanned == 0 && tree_map[mom].scanned == 1)
182 for(
unsigned int i=0; i<relatives.size()-1; i++) cout <<
"\t";
183 cout << hd_msg <<
" Found: " << kid
184 <<
" is not built yet but its mommie " << mom <<
" is. Building " << kid <<
"..." << endl;
187 tree_map[kid].treeItem =
new QTreeWidgetItem(tree_map[mom].treeItem);
188 tree_map[kid].treeItem->setText(0, kid.c_str());
189 tree_map[kid].scanned = 1;
193 if(tree_map[kid].scanned == 0) relatives.push_back(mom);
196 if(tree_map[kid].scanned == 1 && relatives.size())
199 cout << hd_msg <<
" " << kid <<
" is built." << endl << endl;
201 if(tree_map[kid].exist == 1) tree_map[kid].treeItem->setBackground(0,
ActiveBrush );
202 if(tree_map[kid].exist == 0) tree_map[kid].treeItem->setBackground(0,
NonActiveBrush );
203 if(tree_map[kid].visible == 1) tree_map[kid].treeItem->setBackground(0,
ActiveBrush );
204 if(tree_map[kid].sensitive == 1) tree_map[kid].treeItem->setBackground(0,
SensitiveBrush );
205 if(tree_map[kid].visible == 0) tree_map[kid].treeItem->setBackground(0,
NonVisibleBrush );
206 relatives.pop_back();
217 void detector_tree::switch_visibility()
220 QTreeWidgetItem *CurrentItem = treeWidget->currentItem();
226 sprintf(command,
"/vis/geometry/set/visibility %s 0 %d", name.c_str(),
tree_map[name].visible);
227 UImanager->ApplyCommand(command);
232 void detector_tree::switch_visibility_daughters()
234 string name =
gemc_tostring(treeWidget->currentItem()->text(0));
236 for(map<string, tree_item>::iterator it =
tree_map.begin(); it !=
tree_map.end(); it++)
237 if(it->second.mother == name)
239 it->second.visible == 1 ? it->second.visible = 0 : it->second.visible = 1;
240 it->second.visible == 1 ? it->second.treeItem->setBackground(0,
ActiveBrush )
242 vis = it->second.visible;
246 sprintf(command,
"/vis/geometry/set/daughtersInvisible %s 0 %d", name.c_str(), !vis);
247 UImanager->ApplyCommand(command);
251 void detector_tree::switch_wiresolid()
253 string name =
gemc_tostring(treeWidget->currentItem()->text(0));
257 if(
tree_map[name].wiresolid == 1) sprintf(command,
"/vis/geometry/set/forceSolid %s 0 1", name.c_str());
258 if(
tree_map[name].wiresolid == 0) sprintf(command,
"/vis/geometry/set/forceWireframe %s 0 1", name.c_str());
259 UImanager->ApplyCommand(command);
265 void detector_tree::switch_color()
268 string name =
gemc_tostring(treeWidget->currentItem()->text(0));
269 QColor color = QColorDialog::getColor(Qt::green,
this);
270 color.getRgb(&r, &g, &b);
272 sprintf(command,
"/vis/geometry/set/colour %s 0 %3.2f %3.2f %3.2f", name.c_str(), r/255.0, g/255.0, b/255.0);
273 UImanager->ApplyCommand(command);
277 void detector_tree::edit_detector()
280 string hd_msg =
gemcOpt.
args[
"LOG_MSG"].args +
" Editor >> " ;
281 string name =
gemc_tostring(treeWidget->currentItem()->text(0));
282 detector detect = (*Hall_Map)[name];
284 detector_editor.exec();
288 cout << hd_msg <<
" Old detector: " << (*Hall_Map)[name];
289 (*Hall_Map)[name] = detect;
290 cout << hd_msg <<
" New detector: " << (*Hall_Map)[name];
293 string mother = (*Hall_Map)[name].mother;
298 (*Hall_Map)[name].SetTranslation(detect.pos);
304 sprintf(command,
"/vis/geometry/set/visibility root 0 0");
306 UImanager->ApplyCommand(command);
311 void detector_tree::write_gdml_file()
313 string name =
gemc_tostring(treeWidget->currentItem()->text(0));
315 detector detect = (*Hall_Map)[name];
316 fileout.append(
".gdml");
317 struct stat stFileInfo;
318 if(stat(fileout.c_str(),&stFileInfo)==0)
320 if(
remove(fileout.c_str())){
321 cout <<
"ERROR -- Could not remove file " << fileout <<
" cannot write new one.\n";
327 parser.Write(fileout.c_str(),detect.
GetPhysical(),
false);
332 void detector_tree::createActions()
336 Switch_visibility =
new QAction(tr(
"&Switch Visibility"),
this);
337 Switch_visibility->setShortcut(tr(
"Ctrl+V"));
338 Switch_visibility->setStatusTip(tr(
"Switch Visibility"));
339 connect(Switch_visibility, SIGNAL(triggered()),
this, SLOT(switch_visibility()));
342 Switch_visibility_daughters =
new QAction(tr(
"&Switch Visibility of Daughters"),
this);
343 Switch_visibility_daughters->setShortcut(tr(
"Ctrl+D"));
344 Switch_visibility_daughters->setStatusTip(tr(
"Switch Visibility for the daughters"));
345 connect(Switch_visibility_daughters, SIGNAL(triggered()),
this, SLOT(switch_visibility_daughters()));
348 Switch_wiresolid =
new QAction(tr(
"&Switch Wireframe / Solid"),
this);
349 Switch_wiresolid->setShortcut(tr(
"Ctrl+W"));
350 Switch_wiresolid->setStatusTip(tr(
"Switch Wireframe / Solid"));
351 connect(Switch_wiresolid, SIGNAL(triggered()),
this, SLOT(switch_wiresolid()));
354 Switch_color =
new QAction(tr(
"&Pick Volume Color"),
this);
355 Switch_color->setShortcut(tr(
"Ctrl+L"));
356 Switch_color->setStatusTip(tr(
"Pick Volume Color"));
357 connect(Switch_color, SIGNAL(triggered()),
this, SLOT(switch_color()));
360 Edit_Detector =
new QAction(tr(
"&Edit Detector"),
this);
361 Edit_Detector->setShortcut(tr(
"Ctrl+E"));
362 Edit_Detector->setStatusTip(tr(
"Edit Detector"));
363 connect(Edit_Detector, SIGNAL(triggered()),
this, SLOT(edit_detector()));
366 Write_GDML_File =
new QAction(tr(
"Write GDML File"),
this);
367 Write_GDML_File->setShortcut(tr(
"Ctrl+G"));
368 Write_GDML_File->setStatusTip(tr(
"Write file name.gdml to current directory"));
369 connect(Write_GDML_File,SIGNAL(triggered()),
this, SLOT(write_gdml_file()));
map< string, tree_item > read_geometry(QTreeWidget *motherWidget)
QLinearGradient NonActiveGrad
string gemc_tostring(QString input)
QTreeWidgetItem * treeItem
map< string, tree_item > tree_map
QLinearGradient NonVisibleGrad
map< string, opts > args
Options map.
map< string, detector > * Hall_Map
G4VPhysicalVolume * GetPhysical()
Returns Physical Volume pointer.
QLinearGradient SensitiveGrad
QLinearGradient ActiveGrad
map< string, G4Material * > * MMats