2 #include <QActionGroup> 3 #include <QColorDialog> 20 map<string, G4Material*> MMap) :
QWidget(parent)
24 UImanager = G4UImanager::GetUIpointer();
50 treeWidget =
new QTreeWidget();
51 treeWidget->setColumnCount(1);
53 headers << tr(
"Volumes") ;
54 treeWidget->setHeaderLabels(headers);
59 treeWidget->setContextMenuPolicy( Qt::ActionsContextMenu );
60 treeWidget-> addAction( Switch_visibility );
61 treeWidget-> addAction( Switch_visibility_daughters );
62 treeWidget-> addAction( Switch_wiresolid );
63 treeWidget-> addAction( Switch_color );
64 treeWidget-> addAction( Write_GDML_File );
65 treeWidget-> addAction( Write_WRL_File );
66 connect(treeWidget, SIGNAL(itemSelectionChanged ()),
this, SLOT(show_detector()));
72 QSplitter *splitter =
new QSplitter(Qt::Horizontal);
75 leftWidget->setMinimumWidth(300);
76 QVBoxLayout *leftLayout =
new QVBoxLayout(leftWidget);
77 leftLayout->addWidget(treeWidget);
81 QHBoxLayout *writeSingleVolumeButtons =
new QHBoxLayout();
83 writeToGDML =
new QPushButton(tr(
"detector to gdml"));
85 writeToGDML->setToolTip(
"Creates a gdml file for the highlighted detector");
86 writeToGDML->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
87 connect (
writeToGDML , SIGNAL(clicked()),
this, SLOT( set_gdml_name() ));
90 writeToWRL =
new QPushButton(tr(
"detector to wrl"));
92 writeToWRL->setToolTip(
"Creates a gdml file for the highlighted detector");
93 writeToWRL->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
94 connect (
writeToWRL , SIGNAL(clicked()),
this, SLOT( set_wrl_name() ));
95 writeSingleVolumeButtons->addWidget(
writeToWRL);
99 QHBoxLayout *writeAllVolumeButtons =
new QHBoxLayout();
101 QPushButton *writeToGDMLA =
new QPushButton(tr(
"all to gdml"));
102 writeToGDMLA->setToolTip(
"Creates a gdml file for all detectors");
103 writeToGDMLA->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
104 connect ( writeToGDMLA , SIGNAL(clicked()),
this, SLOT( set_gdml_nameAll() ));
105 writeAllVolumeButtons->addWidget(writeToGDMLA);
107 QPushButton *writeToWRLA =
new QPushButton(tr(
"all to wrl"));
108 writeToWRLA->setToolTip(
"Creates a wrl file for all detectors");
109 writeToWRLA->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
110 connect ( writeToWRLA , SIGNAL(clicked()),
this, SLOT( set_wrl_nameAll() ));
111 writeAllVolumeButtons->addWidget(writeToWRLA);
122 leftLayout->addLayout(writeSingleVolumeButtons);
123 leftLayout->addLayout(writeAllVolumeButtons);
128 QVBoxLayout *rightLayout =
new QVBoxLayout(rightWidget);
129 rightLayout->addWidget(
dTab);
133 QVBoxLayout *mainLayout =
new QVBoxLayout;
134 mainLayout->addWidget(splitter);
135 setLayout(mainLayout);
144 cout << hd_msg <<
" Detector Widget Tree Deleted." << endl;
146 delete Switch_visibility;
147 delete Switch_wiresolid;
153 string hd_msg =
gemcOpt.
optMap[
"LOG_MSG"].args +
" Detector Tree >> " ;
163 cout << hd_msg <<
" Building Detector Widget Tree from Geometry STL Map..." << endl << endl;
164 cout << hd_msg <<
" Experimenta Hall has " <<
Hall_Map->size() <<
" components." << endl << endl;
170 for(map<string, detector>::iterator i =
Hall_Map->begin(); i !=
Hall_Map->end(); i++)
172 item.
volume = i->second.name;
173 item.
mother = i->second.mother;
177 if(i->second.sensitivity !=
"no")
180 item.
exist = i->second.exist;
181 item.
visible = i->second.visible;
184 if(i->second.name !=
"root" && i->second.GetPhysical())
186 tree_map.insert(map<string, tree_item>::value_type(i->second.name, item));
187 if(VERB > 3) cout << hd_msg <<
" Mapping Detector " << i->first << endl;
191 if(VERB > 3) cout << endl << endl;
193 ActiveGrad = QLinearGradient(QPointF(1, 100), QPointF(180, 70));
194 ActiveGrad.setColorAt(0, QColor( 80, 80, 255));
195 ActiveGrad.setColorAt(1, QColor(245, 245, 245));
197 SensitiveGrad = QLinearGradient(QPointF(1, 100), QPointF(180, 20));
201 NonActiveGrad = QLinearGradient(QPointF(1, 100), QPointF(10, 30));
205 NonVisibleGrad = QLinearGradient(QPointF(1, 100), QPointF(60, 30));
217 vector<string> relatives;
219 if(VERB > 2) cout << endl << hd_msg <<
" Reordering Tree Elements..." << endl << endl;
220 for(map<string, tree_item>::iterator i = tree_map.begin(); i != tree_map.end(); i++)
222 if(i->first !=
"" && i->first !=
"root") relatives.push_back(i->second.volume);
224 while(relatives.size() > 0 && relatives.size() < 100)
226 mom = tree_map[relatives.back()].mother;
227 kid = tree_map[relatives.back()].volume;
232 for(
unsigned int i=0; i<relatives.size()-1; i++) cout <<
"\t";
233 cout << hd_msg <<
" Checking " << kid <<
", child of " << mom
234 <<
", for a living ancestor. This Geneaology Depth is " << relatives.size() <<
"." << endl;
238 if(tree_map[kid].scanned == 0 && mom.find(
"root", 0) != string::npos)
242 for(
unsigned int i=0; i<relatives.size()-1; i++) cout <<
"\t";
243 cout << hd_msg <<
" Found: " << relatives.back()
244 <<
" has <root> as mom and it's not built yet. Building " << kid <<
"..." << endl;
246 tree_map[kid].treeItem =
new QTreeWidgetItem(motherWidget);
247 tree_map[kid].treeItem->setText(0, kid.c_str());
248 tree_map[kid].scanned = 1;
253 if(tree_map[kid].scanned == 0 && tree_map[mom].scanned == 1)
257 for(
unsigned int i=0; i<relatives.size()-1; i++) cout <<
"\t";
258 cout << hd_msg <<
" Found: " << kid
259 <<
" is not built yet but its mommie " << mom <<
" is. Building " << kid <<
"..." << endl;
262 tree_map[kid].treeItem =
new QTreeWidgetItem(tree_map[mom].treeItem);
263 tree_map[kid].treeItem->setText(0, kid.c_str());
264 tree_map[kid].scanned = 1;
268 if(tree_map[kid].scanned == 0) relatives.push_back(mom);
271 if(tree_map[kid].scanned == 1 && relatives.size())
274 cout << hd_msg <<
" " << kid <<
" is built." << endl << endl;
276 if(tree_map[kid].exist == 1) tree_map[kid].treeItem->setBackground(0,
ActiveBrush );
277 if(tree_map[kid].exist == 0) tree_map[kid].treeItem->setBackground(0,
NonActiveBrush );
278 if(tree_map[kid].visible == 1) tree_map[kid].treeItem->setBackground(0,
ActiveBrush );
279 if(tree_map[kid].sensitive == 1) tree_map[kid].treeItem->setBackground(0,
SensitiveBrush );
280 if(tree_map[kid].visible == 0) tree_map[kid].treeItem->setBackground(0,
NonVisibleBrush );
281 relatives.pop_back();
290 void detector_tree::switch_visibility()
292 QTreeWidgetItem *CurrentItem = treeWidget->currentItem();
297 sprintf(command,
"/vis/geometry/set/visibility %s 0 %d", name.c_str(),
tree_map[name].visible);
298 UImanager->ApplyCommand(command);
301 void detector_tree::switch_visibility_daughters()
303 string name =
qs_tostring(treeWidget->currentItem()->text(0));
305 for(map<string, tree_item>::iterator it =
tree_map.begin(); it !=
tree_map.end(); it++)
306 if(it->second.mother == name)
308 it->second.visible == 1 ? it->second.visible = 0 : it->second.visible = 1;
309 it->second.visible == 1 ? it->second.treeItem->setBackground(0,
ActiveBrush )
311 vis = it->second.visible;
315 sprintf(command,
"/vis/geometry/set/daughtersInvisible %s 0 %d", name.c_str(), !vis);
316 UImanager->ApplyCommand(command);
319 void detector_tree::inspectDetector()
321 string name =
qs_tostring(treeWidget->currentItem()->text(0));
324 sprintf(command,
"/vis/viewer/set/lineSegmentsPerCircle 100 ");
325 UImanager->ApplyCommand(command);
326 sprintf(command,
"/vis/open OGL");
327 UImanager->ApplyCommand(command);
328 sprintf(command,
"/vis/specify %s", name.c_str());
329 UImanager->ApplyCommand(command);
330 sprintf(command,
"/vis/viewer/set/background .85 .95 .98 1");
331 UImanager->ApplyCommand(command);
338 void detector_tree::switch_wiresolid()
340 string name =
qs_tostring(treeWidget->currentItem()->text(0));
344 if(
tree_map[name].wiresolid == 1) sprintf(command,
"/vis/geometry/set/forceSolid %s 0 1", name.c_str());
345 if(
tree_map[name].wiresolid == 0) sprintf(command,
"/vis/geometry/set/forceWireframe %s 0 1", name.c_str());
346 UImanager->ApplyCommand(command);
350 void detector_tree::switch_color()
353 string name =
qs_tostring(treeWidget->currentItem()->text(0));
354 QColor color = QColorDialog::getColor(Qt::green,
this);
355 color.getRgb(&r, &g, &b);
357 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);
358 UImanager->ApplyCommand(command);
364 void detector_tree::show_detector()
366 QTreeWidgetItem *CurrentItem = treeWidget->currentItem();
369 detector detect = (*Hall_Map)[name];
380 (*Hall_Map)[name] = detect;
389 (*Hall_Map)[name].SetTranslation(detect.pos);
402 void detector_tree::set_gdml_name()
404 write_gdml_file(
qs_tostring(treeWidget->currentItem()->text(0)));
407 void detector_tree::set_gdml_nameAll()
409 write_gdml_file(
"root");
412 void detector_tree::set_wrl_name()
414 write_wrl_file(
qs_tostring(treeWidget->currentItem()->text(0)));
417 void detector_tree::set_wrl_nameAll()
419 write_wrl_file(
"root");
424 void detector_tree::write_gdml_file(
string name)
426 string fileout = name +
".gdml";
428 detector detect = (*Hall_Map)[name];
430 struct stat stFileInfo;
431 if(stat(fileout.c_str(),&stFileInfo)==0)
433 if(
remove(fileout.c_str())){
434 cout <<
"ERROR -- Could not remove file " << fileout <<
" cannot write new one.\n";
440 parser.Write(fileout.c_str(),detect.
GetPhysical(),
false);
445 void detector_tree::write_wrl_file(
string name)
451 sprintf(command,
"/vis/specify %s", name.c_str());
452 UImanager->ApplyCommand(command);
455 sprintf(command,
"/vis/open VRML2FILE");
456 UImanager->ApplyCommand(command);
458 sprintf(command,
"/vis/viewer/flush");
459 UImanager->ApplyCommand(command);
464 void detector_tree::change_placement()
466 cout <<
" YAY! " << endl;
470 void detector_tree::createActions()
473 Switch_visibility =
new QAction(tr(
"&Switch Visibility"),
this);
474 Switch_visibility->setShortcut(tr(
"Ctrl+V"));
475 Switch_visibility->setStatusTip(tr(
"Switch Visibility"));
476 connect(Switch_visibility, SIGNAL(triggered()),
this, SLOT(switch_visibility()));
479 Switch_visibility_daughters =
new QAction(tr(
"&Switch Visibility of Daughters"),
this);
480 Switch_visibility_daughters->setShortcut(tr(
"Ctrl+D"));
481 Switch_visibility_daughters->setStatusTip(tr(
"Switch Visibility for the daughters"));
482 connect(Switch_visibility_daughters, SIGNAL(triggered()),
this, SLOT(switch_visibility_daughters()));
485 Switch_wiresolid =
new QAction(tr(
"&Switch Wireframe / Solid"),
this);
486 Switch_wiresolid->setShortcut(tr(
"Ctrl+W"));
487 Switch_wiresolid->setStatusTip(tr(
"Switch Wireframe / Solid"));
488 connect(Switch_wiresolid, SIGNAL(triggered()),
this, SLOT(switch_wiresolid()));
491 Switch_color =
new QAction(tr(
"&Pick Volume Color"),
this);
492 Switch_color->setShortcut(tr(
"Ctrl+L"));
493 Switch_color->setStatusTip(tr(
"Pick Volume Color"));
494 connect(Switch_color, SIGNAL(triggered()),
this, SLOT(switch_color()));
497 Write_GDML_File =
new QAction(tr(
"Write GDML File"),
this);
498 Write_GDML_File->setShortcut(tr(
"Ctrl+G"));
499 Write_GDML_File->setStatusTip(tr(
"Write file name.gdml to current directory"));
500 connect(Write_GDML_File, SIGNAL(triggered()),
this, SLOT(set_gdml_name()));
503 Write_WRL_File =
new QAction(tr(
"Write WRL File"),
this);
504 Write_WRL_File->setShortcut(tr(
"Ctrl+R"));
505 Write_WRL_File->setStatusTip(tr(
"Write file g4_#.wrl to current directory"));
506 connect(Write_WRL_File, SIGNAL(triggered()),
this, SLOT(set_wrl_name()));
map< string, tree_item > read_geometry(QTreeWidget *motherWidget)
void update_detector(detector *Det)
change tab according to detector
QLinearGradient NonActiveGrad
QPushButton * writeToGDML
QTreeWidgetItem * treeItem
map< string, tree_item > tree_map
map< string, G4Material * > MMats
QLinearGradient NonVisibleGrad
map< string, aopt > optMap
Options map.
QPushButton * showDetInNewWindow
string qs_tostring(QString input)
map< string, detector > * Hall_Map
G4VPhysicalVolume * GetPhysical()
Returns Physical Volume pointer.
QLinearGradient SensitiveGrad
QLinearGradient ActiveGrad