| 1 | #include <QApplication>
|
|---|
| 2 | #include <QLineEdit>
|
|---|
| 3 |
|
|---|
| 4 | #include "gemc_MainGui.h"
|
|---|
| 5 | #include "icons.h"
|
|---|
| 6 |
|
|---|
| 7 | #include <iostream>
|
|---|
| 8 | #include <string>
|
|---|
| 9 | using namespace std;
|
|---|
| 10 |
|
|---|
| 11 | gemcMainWidget::gemcMainWidget(G4RunManager *RM, G4VisManager *VM, G4UImanager* UIM)
|
|---|
| 12 | {
|
|---|
| 13 | runManager = RM;
|
|---|
| 14 | visManager = VM;
|
|---|
| 15 | UImanager = UIM;
|
|---|
| 16 | DTree = NULL;
|
|---|
| 17 |
|
|---|
| 18 | setGeometry(100, 100, 700, 500);
|
|---|
| 19 | //setMaximumSize(700, 300);
|
|---|
| 20 | //setMinimumSize(700, 300);
|
|---|
| 21 | setFont( QFont( "lucida", 8) );
|
|---|
| 22 |
|
|---|
| 23 | // %%%%%%%
|
|---|
| 24 | // Buttons
|
|---|
| 25 | // %%%%%%%
|
|---|
| 26 | QWidget *MButtonW = new QWidget(this);
|
|---|
| 27 | MButtonW->setGeometry(10, 10, 180, 320);
|
|---|
| 28 |
|
|---|
| 29 | VMainButtons = new QVBoxLayout();
|
|---|
| 30 | string buttons[8] = {
|
|---|
| 31 | "Run Control",
|
|---|
| 32 | "Physics List Manager",
|
|---|
| 33 | "Materials Manager",
|
|---|
| 34 | "Beam On",
|
|---|
| 35 | "Hit Manager",
|
|---|
| 36 | "Geometry Manager",
|
|---|
| 37 | "Verbosity Manager",
|
|---|
| 38 | "Exit"
|
|---|
| 39 | };
|
|---|
| 40 |
|
|---|
| 41 | for(int i=0; i<8; i++)
|
|---|
| 42 | {
|
|---|
| 43 | MainButtons[i] = new QPushButton(buttons[i].c_str(), this);
|
|---|
| 44 | VMainButtons->addWidget(MainButtons[i]);
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | MButtonW ->setLayout(VMainButtons);
|
|---|
| 48 | MButtonW->show();
|
|---|
| 49 |
|
|---|
| 50 | connect(MainButtons[7], SIGNAL(clicked()), qApp, SLOT(quit()));
|
|---|
| 51 | connect(MainButtons[5], SIGNAL(clicked()), this, SLOT(Build_DTree()));
|
|---|
| 52 | connect(MainButtons[3], SIGNAL(clicked()), this, SLOT(beamOn()));
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | // %%%%%%%%%%%%%%%
|
|---|
| 57 | // Transformation
|
|---|
| 58 | // %%%%%%%%%%%%%%%
|
|---|
| 59 | theta_hall = phi_hall = 0; // initial angles
|
|---|
| 60 | zoom_value = 1; //initial zoom
|
|---|
| 61 |
|
|---|
| 62 | QGroupBox *mainGroup = new QGroupBox(this);
|
|---|
| 63 | mainGroup->setFixedWidth(320);
|
|---|
| 64 | mainGroup->setFixedHeight(450);
|
|---|
| 65 | mainGroup->setTitle("Transformations");
|
|---|
| 66 |
|
|---|
| 67 | string slider_names[3] = {
|
|---|
| 68 | "Theta",
|
|---|
| 69 | "Phi",
|
|---|
| 70 | "Zoom"
|
|---|
| 71 | };
|
|---|
| 72 |
|
|---|
| 73 | int slider_mins[3] = {0, 0, -30};
|
|---|
| 74 | int slider_maxs[3] = {180, 360, 150};
|
|---|
| 75 |
|
|---|
| 76 | for(int l=0; l<3; l++)
|
|---|
| 77 | {
|
|---|
| 78 | TransfGro[l] = new QGroupBox(mainGroup);
|
|---|
| 79 | TransfGro[l]->setTitle(slider_names[l].c_str());
|
|---|
| 80 | TransfLay[l] = new QVBoxLayout(TransfGro[l]);
|
|---|
| 81 | TransfSli[l] = new QSlider(Qt::Horizontal, TransfGro[l]);
|
|---|
| 82 | TransfSli[l]->setTickInterval(1);
|
|---|
| 83 | TransfSli[l]->setRange(slider_mins[l], slider_maxs[l]);
|
|---|
| 84 | TransfLay[l]->addWidget(TransfSli[l]);
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | Theta_V = new QLCDNumber(this);
|
|---|
| 88 | Theta_V->setFont(QFont("Helvetica", 32, QFont::Bold));
|
|---|
| 89 | Theta_V->setMaximumSize(45, 45);
|
|---|
| 90 | Theta_V->setSegmentStyle(QLCDNumber::Flat);
|
|---|
| 91 | Phi_V = new QLCDNumber(this);
|
|---|
| 92 | Phi_V->setMaximumSize(45, 45);
|
|---|
| 93 | Phi_V->setSegmentStyle(QLCDNumber::Flat);
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 | // Theta Combo
|
|---|
| 97 | for(int t=0; t<=180; t+=30)
|
|---|
| 98 | {
|
|---|
| 99 | char tmp[100];
|
|---|
| 100 | sprintf(tmp, "%d", t);
|
|---|
| 101 | ThetaSet.push_back(tmp);
|
|---|
| 102 | }
|
|---|
| 103 | ThetaCombo = new QComboBox;
|
|---|
| 104 | for(int i=0; i<ThetaSet.size(); i++) ThetaCombo->addItem(tr(ThetaSet[i].c_str()));
|
|---|
| 105 | ThetaCombo->setMaximumSize(60, 45);
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 | // Phi Combo
|
|---|
| 109 | for(int t=0; t<=360; t+=30)
|
|---|
| 110 | {
|
|---|
| 111 | char tmp[100];
|
|---|
| 112 | sprintf(tmp, "%d", t);
|
|---|
| 113 | PhiSet.push_back(tmp);
|
|---|
| 114 | }
|
|---|
| 115 | PhiCombo = new QComboBox;
|
|---|
| 116 | for(int i=0; i<PhiSet.size(); i++) PhiCombo->addItem(tr(PhiSet[i].c_str()));
|
|---|
| 117 | PhiCombo->setMaximumSize(60, 45);
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 | // Panning Buttons
|
|---|
| 121 | TransfGro[3] = new QGroupBox(mainGroup);
|
|---|
| 122 | // TransfGro[3]->setFixedWidth(270);
|
|---|
| 123 | TransfGro[3]->setTitle("Panning");
|
|---|
| 124 |
|
|---|
| 125 | PanButtons[0] = new QPushButton("Up", this);
|
|---|
| 126 | PanButtons[1] = new QPushButton("Left", this);
|
|---|
| 127 | PanButtons[2] = new QPushButton("Right", this);
|
|---|
| 128 | PanButtons[3] = new QPushButton("Down", this);
|
|---|
| 129 | for(int b=0; b<4; b++)
|
|---|
| 130 | PanButtons[b]->setAutoRepeat ( TRUE );
|
|---|
| 131 | PanFactorSl = new QSlider(Qt::Horizontal, TransfGro[3]);
|
|---|
| 132 | PanFactorSl->setRange(0, 25);
|
|---|
| 133 | PanFactorSl->setValue(4);
|
|---|
| 134 |
|
|---|
| 135 | QGridLayout *panlayout = new QGridLayout;
|
|---|
| 136 | panlayout->addWidget(PanButtons[0],0,1,1,1);
|
|---|
| 137 | panlayout->addWidget(PanButtons[1],1,0,1,1);
|
|---|
| 138 | panlayout->addWidget(PanButtons[2],1,2,1,1);
|
|---|
| 139 | panlayout->addWidget(PanButtons[3],2,1,1,1);
|
|---|
| 140 | panlayout->addWidget(PanFactorSl, 1,1,1,1);
|
|---|
| 141 |
|
|---|
| 142 | TransfGro[3]->setLayout(panlayout);
|
|---|
| 143 |
|
|---|
| 144 | // Manual command box
|
|---|
| 145 | TransfGro[4] = new QGroupBox(mainGroup);
|
|---|
| 146 | TransfGro[4]->setTitle("G4 UI Command Line");
|
|---|
| 147 | TransfLay[4] = new QVBoxLayout(TransfGro[4]);
|
|---|
| 148 | ManualCommandQLineEdit = new QLineEdit();
|
|---|
| 149 | ManualCommandQLineEdit->setMaxLength(100);
|
|---|
| 150 | ManualCommandBox = new QComboBox();
|
|---|
| 151 | ManualCommandBox->setProperty("minimumContentsLength", 50);
|
|---|
| 152 | ManualCommandBox->setLineEdit(ManualCommandQLineEdit);
|
|---|
| 153 | TransfLay[4]->addWidget(ManualCommandBox);
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 | // Build the grid
|
|---|
| 157 | // Layout constructor:
|
|---|
| 158 | // addWidget ( QWidget * widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment = 0 )
|
|---|
| 159 | QGridLayout *layout = new QGridLayout;
|
|---|
| 160 |
|
|---|
| 161 | layout->addWidget(TransfGro[0], 0, 0, 1, 1);
|
|---|
| 162 | layout->addWidget(Theta_V, 0, 1, 1, 1);
|
|---|
| 163 | layout->addWidget(ThetaCombo, 0, 2, 1, 1);
|
|---|
| 164 |
|
|---|
| 165 | layout->addWidget(TransfGro[1], 1, 0, 1, 1);
|
|---|
| 166 | layout->addWidget(Phi_V, 1, 1, 1, 1);
|
|---|
| 167 | layout->addWidget(PhiCombo, 1, 2, 1, 1);
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 | layout->addWidget(TransfGro[3], 2, 0, 2, 2);
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 | layout->addWidget(TransfGro[2], 4, 0, 1, 3);
|
|---|
| 174 |
|
|---|
| 175 | layout->addWidget(TransfGro[4], 5, 0, 1, 3);
|
|---|
| 176 |
|
|---|
| 177 | mainGroup->setLayout(layout);
|
|---|
| 178 |
|
|---|
| 179 | // Timer to udate angles
|
|---|
| 180 | timer = new QTimer(this);
|
|---|
| 181 | // connect(timer, SIGNAL(timeout()), this, SLOT(update_angles()));
|
|---|
| 182 | // timer->start(100);
|
|---|
| 183 |
|
|---|
| 184 | // Sliders
|
|---|
| 185 | connect ( TransfSli[0] , SIGNAL( valueChanged (int) ), this, SLOT( change_theta(int) ) );
|
|---|
| 186 | connect ( TransfSli[0] , SIGNAL( valueChanged (int) ), Theta_V, SLOT( display(int) ) );
|
|---|
| 187 | connect ( ThetaCombo , SIGNAL( currentIndexChanged (int) ), this, SLOT( set_theta(int) ) );
|
|---|
| 188 |
|
|---|
| 189 | connect ( TransfSli[1] , SIGNAL( valueChanged(int) ), this, SLOT( change_phi(int) ) );
|
|---|
| 190 | connect ( TransfSli[1] , SIGNAL( valueChanged(int) ), Phi_V, SLOT( display(int) ) );
|
|---|
| 191 | connect ( PhiCombo , SIGNAL( currentIndexChanged (int) ), this, SLOT( set_phi(int) ) );
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 | connect ( TransfSli[2] , SIGNAL( valueChanged(int) ), this, SLOT( zoom(int) ) );
|
|---|
| 195 |
|
|---|
| 196 | // Panning Buttons
|
|---|
| 197 | connect(PanButtons[0], SIGNAL(pressed()), this, SLOT( clickpan_up() ) );
|
|---|
| 198 | connect(PanButtons[1], SIGNAL(pressed()), this, SLOT( clickpan_left() ) );
|
|---|
| 199 | connect(PanButtons[2], SIGNAL(pressed()), this, SLOT( clickpan_right() ) );
|
|---|
| 200 | connect(PanButtons[3], SIGNAL(pressed()), this, SLOT( clickpan_down() ) );
|
|---|
| 201 |
|
|---|
| 202 | // Command box
|
|---|
| 203 | connect ( ManualCommandQLineEdit, SIGNAL( returnPressed() ), this, SLOT( RunManualCommand() ) );
|
|---|
| 204 |
|
|---|
| 205 | // Overall Layout
|
|---|
| 206 | QHBoxLayout *viewLayout = new QHBoxLayout(this);
|
|---|
| 207 | viewLayout->addWidget(MButtonW);
|
|---|
| 208 | viewLayout->addWidget(mainGroup);
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | void gemcMainWidget::Build_DTree()
|
|---|
| 215 | {
|
|---|
| 216 | string hd_msg = gemcOpt.args["LOG_MSG"].args;
|
|---|
| 217 | double VERB = gemcOpt.args["GEO_VERBOSITY"].arg ;
|
|---|
| 218 |
|
|---|
| 219 | if(DTree != NULL)
|
|---|
| 220 | {
|
|---|
| 221 | delete DTree;
|
|---|
| 222 | if(VERB>3)
|
|---|
| 223 | cout << hd_msg << " Detector Widget Tree Already Present." << endl;
|
|---|
| 224 | }
|
|---|
| 225 | DTree = new detector_tree(Hall_Map, gemcOpt, runManager, visManager, UImanager, *MMats);
|
|---|
| 226 | DTree->show();
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 | gemcMainWidget::~gemcMainWidget()
|
|---|
| 231 | {
|
|---|
| 232 | string hd_msg = gemcOpt.args["LOG_MSG"].args;
|
|---|
| 233 |
|
|---|
| 234 | if(DTree != NULL)
|
|---|
| 235 | delete DTree;
|
|---|
| 236 |
|
|---|
| 237 | for(int i=0; i<8; i++)
|
|---|
| 238 | delete MainButtons[i];
|
|---|
| 239 | for(int i=0; i<4; i++)
|
|---|
| 240 | delete PanButtons[i];
|
|---|
| 241 |
|
|---|
| 242 | cout << endl;
|
|---|
| 243 | delete VMainButtons;
|
|---|
| 244 | delete runManager;
|
|---|
| 245 | cout << hd_msg << " Run Manager deleted." << endl;
|
|---|
| 246 | delete visManager;
|
|---|
| 247 | cout << hd_msg << " Vis Manager deleted." << endl;
|
|---|
| 248 |
|
|---|
| 249 | cout << endl;
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|