def plot_results(self, beam_out, progressBarValue=80): if not self.view_type == 2: if ShadowGui.checkEmptyBeam(beam_out): if ShadowGui.checkGoodBeam(beam_out): self.view_type_combo.setEnabled(False) try: if self.view_type == 1: self.plot_xy_fast(beam_out, progressBarValue + 4, 1, 3, plot_canvas_index=0, title="X,Z", xtitle=r'X [$\mu$m]', ytitle=r'Z [$\mu$m]') self.plot_xy_fast(beam_out, progressBarValue + 8, 4, 6, plot_canvas_index=1, title="X',Z'", xtitle="X' [$\mu$rad]", ytitle="Z' [$\mu$rad]") self.plot_xy_fast(beam_out, progressBarValue + 12, 1, 4, plot_canvas_index=2, title="X,X'", xtitle=r'X [$\mu$m]', ytitle="X' [$\mu$rad]") self.plot_xy_fast(beam_out, progressBarValue + 16, 3, 6, plot_canvas_index=3, title="Z,Z'", xtitle=r'Z [$\mu$m]', ytitle="Z' [$\mu$rad]") self.plot_histo_fast(beam_out, progressBarValue + 20, 11, plot_canvas_index=4, title="Energy", xtitle="Energy [eV]", ytitle="Number of Rays") elif self.view_type == 0: self.plot_xy(beam_out, progressBarValue + 4, 1, 3, plot_canvas_index=0, title="X,Z", xtitle=r'X [$\mu$m]', ytitle=r'Z [$\mu$m]', xum=("X [" + u"\u03BC" + "m]"), yum=("Z [" + u"\u03BC" + "m]")) self.plot_xy(beam_out, progressBarValue + 8, 4, 6, plot_canvas_index=1, title="X',Z'", xtitle="X' [$\mu$rad]", ytitle="Z' [$\mu$rad]", xum="X' [" + u"\u03BC" + "rad]", yum="Z' [" + u"\u03BC" + "rad]") self.plot_xy(beam_out, progressBarValue + 12, 1, 4, plot_canvas_index=2, title="X,X'", xtitle=r'X [$\mu$m]', ytitle="X' [$\mu$rad]", xum=("X [" + u"\u03BC" + "m]"), yum="X' [" + u"\u03BC" + "rad]") self.plot_xy(beam_out, progressBarValue + 16, 3, 6, plot_canvas_index=3, title="Z,Z'", xtitle=r'Z [$\mu$m]', ytitle="Z' [$\mu$rad]", xum=("Z [" + u"\u03BC" + "m]"), yum="Z' [" + u"\u03BC" + "rad]") self.plot_histo(beam_out, progressBarValue + 20, 11, plot_canvas_index=4, title="Energy", xtitle="Energy [eV]", ytitle="Number of Rays", xum="[eV]") except Exception: self.view_type_combo.setEnabled(True) raise Exception("Data not plottable: No good rays or bad content") self.view_type_combo.setEnabled(True) else: raise Exception("Beam with no good rays") else: raise Exception("Empty Beam") self.plotted_beam = beam_out
def setBeam(self, beam): if ShadowGui.checkEmptyBeam(beam): if ShadowGui.checkGoodBeam(beam): sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.input_beam = beam self.sysInfo.setText("\n\n\n\n\nNot Available") optical_element_list = [] for history_element in self.input_beam.getOEHistory(): if not history_element.shadow_source_start is None: optical_element_list.append(history_element.shadow_source_start.src) elif not history_element.shadow_oe_start is None: optical_element_list.append(history_element.shadow_oe_start.oe) if not history_element.shadow_source_end is None: self.sourceInfo.append(history_element.shadow_source_end.src.sourcinfo()) elif not history_element.shadow_oe_end is None: self.mirInfo.append(history_element.shadow_oe_end.oe.mirinfo(title="O.E. #" + str(history_element.oe_number))) self.pythonScript.setText(ST.make_python_script_from_list(optical_element_list)) else: QtGui.QMessageBox.critical(self, "QMessageBox.critical()", "Data not displayable: No good rays or bad content", QtGui.QMessageBox.Ok)
def plot_histo(self, var_x, title, xtitle, ytitle, xum): beam_to_plot = self.input_beam._beam if self.image_plane == 1: new_shadow_beam = self.input_beam.duplicate(history=False) historyItem = self.input_beam.getOEHistory(oe_number=self.input_beam._oe_number) if historyItem is None: raise Exception("Calculation impossible: Beam has no history") dist = 0.0 if self.image_plane_rel_abs_position == 1: # relative image_plane = 0.0 if type(historyItem.shadow_oe_end) == ShadowOpticalElement: image_plane = historyItem.shadow_oe_end._oe.T_IMAGE elif type(historyItem.shadow_oe_end) == ShadowCompoundOpticalElement: image_plane = historyItem.shadow_oe_end._oe.list[historyItem.shadow_oe_end._oe.number_oe() - 1].T_IMAGE if self.image_plane_new_position < 0 and abs(self.image_plane_new_position) > image_plane: raise Exception("Image plane new position cannot be before the O.E.") dist = self.image_plane_new_position else: # absolute ShadowGui.checkPositiveNumber(self.image_plane_new_position, "Image Plane new Position") dist = self.image_plane_new_position - historyItem.shadow_oe_end._oe.T_IMAGE new_shadow_beam._beam.retrace(dist) beam_to_plot = new_shadow_beam._beam self.replace_fig(beam_to_plot, var_x, title, xtitle, ytitle, xum)
def __init__(self): self.setFixedWidth(400) self.setFixedHeight(220) left_box_1 = ShadowGui.widgetBox(self.controlArea, "Loop Management", addSpace=True, orientation="vertical", width=370, height=100) ShadowGui.lineEdit(left_box_1, self, "number_of_new_beams", "Number of new Beams", labelWidth=250, valueType=int, orientation="horizontal") self.le_current_new_beam = ShadowGui.lineEdit(left_box_1, self, "current_new_beam", "Current New Beam", labelWidth=250, valueType=int, orientation="horizontal") self.le_current_new_beam.setReadOnly(True) font = QtGui.QFont(self.le_current_new_beam.font()) font.setBold(True) self.le_current_new_beam.setFont(font) palette = QtGui.QPalette(self.le_current_new_beam.palette()) # make a copy of the palette palette.setColor(QtGui.QPalette.Text, QtGui.QColor('dark blue')) palette.setColor(QtGui.QPalette.Base, QtGui.QColor(243, 240, 160)) self.le_current_new_beam.setPalette(palette) button_box = gui.widgetBox(self.controlArea, "", addSpace=True, orientation="horizontal") self.start_button = gui.button(button_box, self, "Start Loop", callback=self.startLoop) self.start_button.setFixedHeight(45) stop_button = gui.button(button_box, self, "Interrupt", callback=self.stopLoop) stop_button.setFixedHeight(45) font = QtGui.QFont(stop_button.font()) font.setBold(True) stop_button.setFont(font) palette = QtGui.QPalette(stop_button.palette()) # make a copy of the palette palette.setColor(QtGui.QPalette.ButtonText, QtGui.QColor('red')) stop_button.setPalette(palette) # assign new palette gui.rubber(self.controlArea)
def setBeam(self, beam): if ShadowGui.checkEmptyBeam(beam): proceed = True if not ShadowGui.checkGoodBeam(beam): if not ConfirmDialog.confirmed(parent=self, message="Beam contains bad values, skip it?"): proceed = False if proceed: go = numpy.where(beam.beam.rays[:, 9] == 1) self.current_number_of_rays = self.current_number_of_rays + len(beam.beam.rays[go]) if self.current_number_of_rays <= self.number_of_accumulated_rays: if self.keep_go_rays == 1: beam.beam.rays = copy.deepcopy(beam.beam.rays[go]) if not self.input_beam is None: self.input_beam = ShadowBeam.mergeBeams(self.input_beam, beam) else: self.input_beam = beam self.send("Trigger", ShadowTriggerIn(new_beam=True)) else: if self.is_automatic_run: self.sendSignal() self.current_number_of_rays = 0 self.input_beam = None else: QtGui.QMessageBox.critical(self, "QMessageBox.critical()", "Number of Accumulated Rays reached, please push \'Send Signal\' button", QtGui.QMessageBox.Ok)
def traceOpticalElement(self): try: self.error(self.error_id) self.setStatusMessage("") self.progressBarInit() if ShadowGui.checkEmptyBeam(self.input_beam): if ShadowGui.checkGoodBeam(self.input_beam): sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.checkFields() shadow_oe = ShadowCompoundOpticalElement.create_compound_oe() self.populateFields(shadow_oe) self.doSpecificSetting(shadow_oe) self.progressBarSet(10) self.completeOperations(shadow_oe) else: raise Exception("Input Beam with no good rays") else: raise Exception("Empty Input Beam") except Exception as exception: QtGui.QMessageBox.critical(self, "QMessageBox.critical()", str(exception), QtGui.QMessageBox.Ok) self.error_id = self.error_id + 1 self.error(self.error_id, "Exception occurred: " + str(exception)) self.progressBarFinished()
def checkFields(self): ShadowGui.checkPositiveNumber(self.p, "Distance Source - KB center") ShadowGui.checkPositiveNumber(self.q, "Distance KB center - Image plane") ShadowGui.checkPositiveNumber(self.separation, "Separation between the Mirrors") ShadowGui.checkStrictlyPositiveNumber(self.photon_energy_ev, "Photon Energy") ShadowGui.checkFile(self.reflectivity_file) self.crystal_1_box.checkFields() self.crystal_2_box.checkFields()
def checkFields(self): ShadowGui.checkPositiveNumber(self.grazing_angles_mrad, "Grazing Angle") if self.has_finite_dimensions == 0: ShadowGui.checkStrictlyPositiveNumber(self.mirror_width, "Mirror Width") ShadowGui.checkStrictlyPositiveNumber(self.mirror_length, "Mirror Length") if self.reflectivity_kind != 0: ShadowGui.checkFile(self.reflectivity_files) if self.has_surface_error == 1: ShadowGui.checkFile(self.surface_error_files)
def runSimulation(self): try: self.error(self.error_id) self.setStatusMessage("") self.progressBarInit() if not self.beamline_parameters is None: driver = ShadowDriver() sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.setStatusMessage("Running SHADOW simulation") self.progressBarSet(50) ########################################### # TODO: TO BE ADDED JUST IN CASE OF BROKEN # ENVIRONMENT: MUST BE FOUND A PROPER WAY # TO TEST SHADOW self.fixWeirdShadowBug() ########################################### ShadowGui.checkStrictlyPositiveNumber(self.beamline_parameters._energy_min, "Energy Min") ShadowGui.checkStrictlyPositiveNumber(self.beamline_parameters._energy_max, "Energy Max") shadow_beam = driver.calculate_radiation(self.beamline_parameters._electron_beam, self.beamline_parameters._magnetic_structure, self.beamline_parameters._beamline, self.beamline_parameters._energy_min, self.beamline_parameters._energy_max) self.setStatusMessage("Plotting Results") self.plot_results(shadow_beam) self.setStatusMessage("") self.send("Beam", shadow_beam) except Exception as exception: QtGui.QMessageBox.critical(self, "QMessageBox.critical()", str(exception), QtGui.QMessageBox.Ok) self.error_id = self.error_id + 1 self.error(self.error_id, "Exception occurred: " + str(exception)) self.progressBarFinished()
def runSimulation(self): try: self.error(self.error_id) self.setStatusMessage("") self.progressBarInit() if not self.beamline_parameters is None: driver = SRWDriver() self.setStatusMessage("Running SRW simulation") self.progressBarSet(50) ShadowGui.checkStrictlyPositiveNumber(self.beamline_parameters._energy_min, "Energy Min") ShadowGui.checkStrictlyPositiveNumber(self.beamline_parameters._energy_max, "Energy Max") srw_wavefront = driver.calculate_radiation(self.beamline_parameters._electron_beam, self.beamline_parameters._magnetic_structure, self.beamline_parameters._beamline, self.beamline_parameters._energy_min, self.beamline_parameters._energy_max) intensity, dim_x, dim_y = driver.calculate_intensity(srw_wavefront) self.setStatusMessage("Calling plots with array shape: ',intensity.shape,'...") t0_main = time.time() plt.pcolormesh(dim_x,dim_y,intensity.transpose()) plt.title("Real space for infrared example") plt.colorbar() self.setStatusMessage("done in " + str(round(time.time() - t0_main)) + " s") plt.show() self.setStatusMessage("") except Exception as exception: QtGui.QMessageBox.critical(self, "QMessageBox.critical()", str(exception), QtGui.QMessageBox.Ok) self.error_id = self.error_id + 1 self.error(self.error_id, "Exception occurred: " + str(exception)) #raise exception self.progressBarFinished()
def setBeam(self, beam): self.onReceivingInput() if ShadowGui.checkEmptyBeam(beam): self.input_beam = beam if self.is_automatic_run: self.traceOpticalElement()
def __init__(self, dcm=None, parent=None, has_finite_dimensions=0, dimensions=[0.0, 0.0]): super().__init__(parent) self.setLayout(QtGui.QVBoxLayout()) self.layout().setAlignment(Qt.AlignTop) self.setFixedWidth(470) self.setFixedHeight(400) self.dcm = dcm self.has_finite_dimensions = has_finite_dimensions self.mirror_width = dimensions[0] self.mirror_length = dimensions[1] mirror_box = ShadowGui.widgetBox(self, "Crystal Input Parameters", addSpace=False, orientation="vertical", height=330, width=460) gui.comboBox(mirror_box, self, "has_finite_dimensions", label="Dimensions", labelWidth=350, items=["Finite", "Infinite"], sendSelectedValue=False, orientation="horizontal", callback=self.set_dimensions) self.dimension_box = ShadowGui.widgetBox(mirror_box, "", addSpace=False, orientation="vertical", height=50) self.dimension_box_empty = ShadowGui.widgetBox(mirror_box, "", addSpace=False, orientation="vertical", height=50) ShadowGui.lineEdit(self.dimension_box, self, "mirror_width", "Crystal Width [cm]", labelWidth=350, valueType=float, orientation="horizontal", callback=self.dcm.dump_dimensions_0) ShadowGui.lineEdit(self.dimension_box, self, "mirror_length", "Crystal Length [cm]", labelWidth=350, valueType=float, orientation="horizontal", callback=self.dcm.dump_dimensions_1) self.set_dimensions() self.is_on_init = False
def __init__(self): super().__init__() self.runaction = widget.OWAction("Run Simulation", self) self.runaction.triggered.connect(self.run_simulation) self.addAction(self.runaction) geom = QApplication.desktop().availableGeometry() self.setGeometry(QRect(round(geom.width()*0.05), round(geom.height()*0.05), round(min(geom.width()*0.5, self.MAX_WIDTH)), round(min(geom.height()*0.5, self.MAX_HEIGHT)))) label_box = ShadowGui.widgetBox(self.controlArea, "", orientation="horizontal") gui.separator(label_box, height=50) gui.label(label_box, self, " JUST A DEMO WIDGET!!!!!") gui.separator(label_box, height=50) self.left_box_1 = ShadowGui.widgetBox(self.controlArea, "Electron Beam", addSpace=True, orientation="vertical") ShadowGui.lineEdit(self.left_box_1, self, "image_plane_position", "Position on beamline", labelWidth=300, valueType=float, orientation="horizontal") button_box = ShadowGui.widgetBox(self.controlArea, "", addSpace=False, orientation="horizontal") button = gui.button(button_box, self, "Run Simulation", callback=self.run_simulation) font = QFont(button.font()) font.setBold(True) button.setFont(font) palette = QPalette(button.palette()) # make a copy of the palette palette.setColor(QPalette.ButtonText, QColor('Dark Blue')) button.setPalette(palette) # assign new palette button.setFixedHeight(45) button = gui.button(button_box, self, "Reset Fields", callback=self.callResetSettings) font = QFont(button.font()) font.setItalic(True) button.setFont(font) palette = QPalette(button.palette()) # make a copy of the palette palette.setColor(QPalette.ButtonText, QColor('Dark Red')) button.setPalette(palette) # assign new palette button.setFixedHeight(45) button.setFixedWidth(100) gui.rubber(self.controlArea)
def __init__(self): self.setFixedWidth(590) self.setFixedHeight(580) left_box_1 = ShadowGui.widgetBox(self.controlArea, "Optical Parameters", addSpace=True, orientation="vertical", width=570, height=500) figure_box = ShadowGui.widgetBox(left_box_1, "", addSpace=True, orientation="horizontal", width=550, height=350) label = QtGui.QLabel("") label.setPixmap(QtGui.QPixmap(self.image_path)) figure_box.layout().addWidget(label) ShadowGui.lineEdit(left_box_1, self, "vertical_quote", "Vertical Distance (H) [cm]", labelWidth=300, valueType=float, orientation="horizontal") ShadowGui.lineEdit(left_box_1, self, "total_distance", "First Crystal - Mirror Distance (D) [cm]", labelWidth=300, valueType=float, orientation="horizontal") ShadowGui.lineEdit(left_box_1, self, "twotheta_bragg", "First Crystal Reflection Angle [deg]", labelWidth=300, valueType=float, orientation="horizontal") gui.separator(left_box_1, height=20) le = ShadowGui.lineEdit(left_box_1, self, "d_1", "Crystal to Crystal Distance (d_1) [cm]", labelWidth=300, valueType=float, orientation="horizontal") le.setReadOnly(True) font = QtGui.QFont(le.font()) font.setBold(True) le.setFont(font) palette = QtGui.QPalette(le.palette()) # make a copy of the palette palette.setColor(QtGui.QPalette.Text, QtGui.QColor('dark blue')) palette.setColor(QtGui.QPalette.Base, QtGui.QColor(243, 240, 160)) le.setPalette(palette) le = ShadowGui.lineEdit(left_box_1, self, "d_2", "Crystal to Mirror Distance (d_2) [cm]", labelWidth=300, valueType=float, orientation="horizontal") le.setReadOnly(True) font = QtGui.QFont(le.font()) font.setBold(True) le.setFont(font) palette = QtGui.QPalette(le.palette()) # make a copy of the palette palette.setColor(QtGui.QPalette.Text, QtGui.QColor('dark blue')) palette.setColor(QtGui.QPalette.Base, QtGui.QColor(243, 240, 160)) le.setPalette(palette) button = gui.button(self.controlArea, self, "Calculate Distances", callback=self.calculate) button.setFixedHeight(45) gui.rubber(self.controlArea)
def __init__(self): super().__init__() self.runaction = widget.OWAction("Send Data to Simulators", self) self.runaction.triggered.connect(self.send_data) self.addAction(self.runaction) geom = QApplication.desktop().availableGeometry() self.setGeometry(QRect(round(geom.width()*0.05), round(geom.height()*0.05), round(min(geom.width()*0.5, self.MAX_WIDTH)), round(min(geom.height()*0.5, self.MAX_HEIGHT)))) left_box_1 = ShadowGui.widgetBox(self.controlArea, "Lens Parameters", addSpace=True, orientation="vertical") ShadowGui.lineEdit(left_box_1, self, "lens_name", "Lens Name", labelWidth=200, valueType=str, orientation="horizontal") ShadowGui.lineEdit(left_box_1, self, "lens_position", "Position on beamline", labelWidth=300, valueType=float, orientation="horizontal") ShadowGui.lineEdit(left_box_1, self, "focal_x", "Focal length (horizontal) [m]", labelWidth=300, valueType=float, orientation="horizontal") ShadowGui.lineEdit(left_box_1, self, "focal_y", "Focal length (vertical) [m]", labelWidth=300, valueType=float, orientation="horizontal") button_box = ShadowGui.widgetBox(self.controlArea, "", addSpace=False, orientation="horizontal") button = gui.button(button_box, self, "Send Data to Simulators", callback=self.send_data) font = QFont(button.font()) font.setBold(True) button.setFont(font) palette = QPalette(button.palette()) # make a copy of the palette palette.setColor(QPalette.ButtonText, QColor('Dark Blue')) button.setPalette(palette) # assign new palette button.setFixedHeight(45) button = gui.button(button_box, self, "Reset Fields", callback=self.callResetSettings) font = QFont(button.font()) font.setItalic(True) button.setFont(font) palette = QPalette(button.palette()) # make a copy of the palette palette.setColor(QPalette.ButtonText, QColor('Dark Red')) button.setPalette(palette) # assign new palette button.setFixedHeight(45) button.setFixedWidth(100) gui.rubber(self.controlArea)
def setBeam(self, beam): if ShadowGui.checkEmptyBeam(beam): if ShadowGui.checkGoodBeam(beam): if self.keep_result == 1 and not self.input_beam is None: self.input_beam = ShadowBeam.mergeBeams(self.input_beam, beam) else: self.input_beam = beam if ShadowGui.checkEmptyBeam(self.input_beam): if (self.input_beam._oe_number == 0): # IS THE SOURCE self.image_plane = 0 self.set_ImagePlane() self.image_plane_combo.setEnabled(False) if self.is_automatic_run: self.plot_results() else: QtGui.QMessageBox.critical(self, "QMessageBox.critical()", "Data not displayable: No good rays or bad content", QtGui.QMessageBox.Ok)
def __init__(self): super().__init__() self.runaction = widget.OWAction("Run Shadow/Trace", self) self.runaction.triggered.connect(self.traceOpticalElement) self.addAction(self.runaction) self.controlArea.setFixedWidth(self.CONTROL_AREA_WIDTH) tabs_setting = gui.tabWidget(self.controlArea) tab_bas = ShadowGui.createTabPage(tabs_setting, "Basic Setting") lens_box = ShadowGui.widgetBox(tab_bas, "Input Parameters", addSpace=False, orientation="vertical", height=600, width=450) self.le_source_plane_distance = ShadowGui.lineEdit(lens_box, self, "source_plane_distance", "Source Plane Distance [cm]", labelWidth=350, valueType=float, orientation="horizontal") self.le_image_plane_distance = ShadowGui.lineEdit(lens_box, self, "image_plane_distance", "Image Plane Distance [cm]", labelWidth=350, valueType=float, orientation="horizontal") gui.separator(self.controlArea) button_box = ShadowGui.widgetBox(self.controlArea, "", addSpace=False, orientation="horizontal") button = gui.button(button_box, self, "Run Shadow/trace", callback=self.traceOpticalElement) font = QFont(button.font()) font.setBold(True) button.setFont(font) palette = QPalette(button.palette()) # make a copy of the palette palette.setColor(QPalette.ButtonText, QColor('Dark Blue')) button.setPalette(palette) # assign new palette button.setFixedHeight(45) button = gui.button(button_box, self, "Reset Fields", callback=self.callResetSettings) font = QFont(button.font()) font.setItalic(True) button.setFont(font) palette = QPalette(button.palette()) # make a copy of the palette palette.setColor(QPalette.ButtonText, QColor('Dark Red')) button.setPalette(palette) # assign new palette button.setFixedHeight(45) button.setFixedWidth(100)
def __init__(self): self.setFixedWidth(590) self.setFixedHeight(150) left_box_1 = ShadowGui.widgetBox(self.controlArea, "Beam File Selection", addSpace=True, orientation="vertical", width=570, height=60) figure_box = ShadowGui.widgetBox(left_box_1, "", addSpace=True, orientation="horizontal", width=550, height=50) self.le_beam_file_name = ShadowGui.lineEdit(figure_box, self, "beam_file_name", "Beam File Name", labelWidth=100, valueType=str, orientation="horizontal") self.le_beam_file_name.setFixedWidth(350) pushButton = gui.button(figure_box, self, "...") pushButton.clicked.connect(self.selectFile) gui.separator(left_box_1, height=20) button = gui.button(self.controlArea, self, "Generate Beam", callback=self.calculate) button.setFixedHeight(45) gui.rubber(self.controlArea)
def __init__(self): super().__init__() self.setFixedWidth(500) self.setFixedHeight(300) left_box_1 = ShadowGui.widgetBox(self.controlArea, "Accumulating Loop Management", addSpace=True, orientation="vertical", height=120) ShadowGui.lineEdit(left_box_1, self, "number_of_accumulated_rays", "Number of accumulated good rays\n(before sending signal)", labelWidth=350, valueType=int, orientation="horizontal") le = ShadowGui.lineEdit(left_box_1, self, "current_number_of_rays", "Current number of good rays", labelWidth=350, valueType=int, orientation="horizontal") le.setReadOnly(True) font = QtGui.QFont(le.font()) font.setBold(True) le.setFont(font) palette = QtGui.QPalette(le.palette()) # make a copy of the palette palette.setColor(QtGui.QPalette.Text, QtGui.QColor('dark blue')) palette.setColor(QtGui.QPalette.Base, QtGui.QColor(243, 240, 160)) le.setPalette(palette) gui.comboBox(left_box_1, self, "keep_go_rays", label="Remove lost rays from beam", labelWidth=350, items=["No", "Yes"], sendSelectedValue=False, orientation="horizontal") button_box = gui.widgetBox(self.controlArea, "", addSpace=True, orientation="horizontal") self.start_button = gui.button(button_box, self, "Send Beam", callback=self.sendSignal) self.start_button.setFixedHeight(45) button = gui.button(button_box, self, "Reset Accumulation", callback=self.callResetSettings) font = QFont(button.font()) font.setItalic(True) button.setFont(font) palette = QPalette(button.palette()) # make a copy of the palette palette.setColor(QPalette.ButtonText, QColor('Dark Red')) button.setPalette(palette) # assign new palette button.setFixedHeight(45) gui.rubber(self.controlArea)
def __init__(self, show_automatic_box=True): super().__init__(show_automatic_box) view_box = ShadowGui.widgetBox(self.mainArea, "Plotting Style", addSpace=False, orientation="horizontal") view_box_1 = ShadowGui.widgetBox(view_box, "", addSpace=False, orientation="vertical", width=350) self.view_type_combo = gui.comboBox(view_box_1, self, "view_type", label="Select level of Plotting", labelWidth=220, items=["Detailed Plot", "Preview", "None"], callback=self.set_PlotQuality, sendSelectedValue=False, orientation="horizontal") self.tabs = gui.tabWidget(self.mainArea) self.initializeTabs() self.shadow_output = QtGui.QTextEdit() self.shadow_output.setReadOnly(True) out_box = gui.widgetBox(self.mainArea, "System Output", addSpace=True, orientation="horizontal") out_box.layout().addWidget(self.shadow_output) self.shadow_output.setFixedHeight(150) self.shadow_output.setFixedWidth(850)
def callResetSettings(self): if ConfirmDialog.confirmed(parent=self, message="Confirm Reset of the Fields?"): self.resetSettings() while self.tab_crystals.count() > 0: self.tab_crystals.removeTab(0) tab_first_crystal = ShadowGui.widgetBox(self.tab_crystals, addToLayout=0, margin=4) tab_second_crystal = ShadowGui.widgetBox(self.tab_crystals, addToLayout=0, margin=4) self.crystal_1_box = CrystalBox(dcm=self, parent=tab_first_crystal, has_finite_dimensions=self.has_finite_dimensions[0], dimensions=self.dimensions[0]) self.crystal_2_box = CrystalBox(dcm=self, parent=tab_second_crystal, has_finite_dimensions=self.has_finite_dimensions[1], dimensions=self.dimensions[1]) self.tab_crystals.addTab(tab_first_crystal, "First Crystal") self.tab_crystals.addTab(tab_second_crystal, "Second Crystal") self.setupUI()
def callResetSettings(self): if ConfirmDialog.confirmed(parent=self, message="Confirm Reset of the Fields?"): self.resetSettings() while self.tab_mirrors.count() > 0: self.tab_mirrors.removeTab(0) tab_vertical = ShadowGui.widgetBox(self.tab_mirrors, addToLayout=0, margin=4) tab_horizontal = ShadowGui.widgetBox(self.tab_mirrors, addToLayout=0, margin=4) self.v_box = MirrorBox(kb=self, parent=tab_vertical, grazing_angles_mrad=self.grazing_angles_mrad[0], shape=self.shape[0], has_finite_dimensions=self.has_finite_dimensions[0], dimensions=self.dimensions[0], reflectivity_kind=self.reflectivity_kind[0], reflectivity_files=self.reflectivity_files[0], has_surface_error=self.has_surface_error[0], surface_error_files=self.surface_error_files[0]) self.h_box = MirrorBox(kb=self, parent=tab_horizontal, grazing_angles_mrad=self.grazing_angles_mrad[1], shape=self.shape[1], has_finite_dimensions=self.has_finite_dimensions[1], dimensions=self.dimensions[1], reflectivity_kind=self.reflectivity_kind[1], reflectivity_files=self.reflectivity_files[1], has_surface_error=self.has_surface_error[1], surface_error_files=self.surface_error_files[1]) self.tab_mirrors.addTab(tab_vertical, "Vertical Focusing Mirror") self.tab_mirrors.addTab(tab_horizontal, "Horizontal Focusing Mirror") self.setupUI()
def crl_insert_before(self): current_index = self.tab_crls.currentIndex() if ConfirmDialog.confirmed(parent=self, message="Confirm Insertion of a new element before " + self.tab_crls.tabText(current_index) + "?"): tab_crl = ShadowGui.widgetBox(self.tab_crls, addToLayout=0, margin=4) crl_box = CRLBox(transfocator=self, parent=tab_crl) self.tab_crls.insertTab(current_index, tab_crl, "TEMP") self.crl_box_array.insert(current_index, crl_box) self.dumpSettings() for index in range(current_index, self.tab_crls.count()): self.tab_crls.setTabText(index, "C.R.L " + str(index + 1)) self.tab_crls.setCurrentIndex(current_index)
def __init__(self): super().__init__() self.runaction = widget.OWAction("Run Shadow Beamline Simulation", self) self.runaction.triggered.connect(self.runSimulation) self.addAction(self.runaction) gui.separator(self.controlArea, height=600) button_box = ShadowGui.widgetBox(self.controlArea, "", addSpace=False, orientation="horizontal") button = gui.button(button_box, self, "Run Simulation", callback=self.runSimulation) font = QFont(button.font()) font.setBold(True) button.setFont(font) palette = QPalette(button.palette()) # make a copy of the palette palette.setColor(QPalette.ButtonText, QColor('Dark Blue')) button.setPalette(palette) # assign new palette button.setFixedHeight(45)
def check_fields(self): self.number_of_points_x = ShadowGui.checkStrictlyPositiveNumber(self.number_of_points_x, "Number of Points X") self.number_of_points_y = ShadowGui.checkStrictlyPositiveNumber(self.number_of_points_y, "Number of Points Y") self.dimension_x = ShadowGui.checkStrictlyPositiveNumber(self.dimension_x, "Dimension X") self.dimension_y = ShadowGui.checkStrictlyPositiveNumber(self.dimension_y, "Dimension Y") self.estimated_slope_error = ShadowGui.checkPositiveNumber(self.estimated_slope_error, "Estimated slope error") self.montecarlo_seed = ShadowGui.checkPositiveNumber(self.montecarlo_seed, "Monte Carlo initial seed") self.harmonic_maximum_index = ShadowGui.checkPositiveNumber(self.harmonic_maximum_index, "Harmonic Maximum Index") if not self.waviness_file_name is None: self.waviness_file_name = self.waviness_file_name.strip() if self.waviness_file_name == "": raise Exception("Output File Name missing") else: raise Exception("Output File Name missing")
def callResetSettings(self): if ConfirmDialog.confirmed(parent=self, message="Confirm Reset of the Fields?\n\nWarning: C.R.L. stack will be regenerated"): self.resetSettings() while self.tab_crls.count() > 0: self.tab_crls.removeTab(0) self.crl_box_array = [] for index in range(len(self.p)): tab_crl = ShadowGui.widgetBox(self.tab_crls, addToLayout=0, margin=4) crl_box = CRLBox(transfocator=self, parent=tab_crl, nlenses=self.nlenses[index], slots_empty=self.slots_empty[index], thickness=self.thickness[index], p=self.p[index], q=self.q[index], surface_shape=self.surface_shape[index], convex_to_the_beam=self.convex_to_the_beam[index], has_finite_diameter=self.has_finite_diameter[index], diameter=self.diameter[index], is_cylinder=self.is_cylinder[index], cylinder_angle=self.cylinder_angle[index], ri_calculation_mode=self.ri_calculation_mode[index], prerefl_file=self.prerefl_file[index], refraction_index=self.refraction_index[index], attenuation_coefficient=self.attenuation_coefficient[index], radius=self.radius[index], interthickness=self.interthickness[index], use_ccc=self.use_ccc[index]) self.tab_crls.addTab(tab_crl, "C.R.L " + str(index + 1)) self.crl_box_array.append(crl_box) self.setupUI()
def __init__(self): super().__init__() # self.resetSettings() ################################# # FIX A WEIRD BEHAVIOUR AFTER DISPLAY # THE WIDGET: PROBABLY ON SIGNAL MANAGER self.dumpSettings() self.controlArea.setFixedWidth(self.CONTROL_AREA_WIDTH) tabs_setting = gui.tabWidget(self.controlArea) tabs_setting.setFixedWidth(495) tabs_setting.setFixedHeight(750) tab_bas = ShadowGui.createTabPage(tabs_setting, "Basic Setting") tab_adv = ShadowGui.createTabPage(tabs_setting, "Advanced Setting") tabs_button_box = ShadowGui.widgetBox(tab_bas, "", addSpace=False, orientation="horizontal") gui.separator(tabs_button_box) gui.button(tabs_button_box, self, "Insert C.R.L. Before", callback=self.crl_insert_before) gui.button(tabs_button_box, self, "Insert C.R.L. After", callback=self.crl_insert_after) gui.button(tabs_button_box, self, "Remove C.R.L.", callback=self.crl_remove) gui.separator(tabs_button_box) self.tab_crls = gui.tabWidget(tab_bas) self.crl_box_array = [] for index in range(len(self.p)): tab_crl = ShadowGui.createTabPage(self.tab_crls, "C.R.L. " + str(index + 1)) crl_box = CRLBox(transfocator=self, parent=tab_crl, nlenses=self.nlenses[index], slots_empty=self.slots_empty[index], thickness=self.thickness[index], p=self.p[index], q=self.q[index], surface_shape=self.surface_shape[index], convex_to_the_beam=self.convex_to_the_beam[index], has_finite_diameter=self.has_finite_diameter[index], diameter=self.diameter[index], is_cylinder=self.is_cylinder[index], cylinder_angle=self.cylinder_angle[index], ri_calculation_mode=self.ri_calculation_mode[index], prerefl_file=self.prerefl_file[index], refraction_index=self.refraction_index[index], attenuation_coefficient=self.attenuation_coefficient[index], radius=self.radius[index], interthickness=self.interthickness[index], use_ccc=self.use_ccc[index]) self.crl_box_array.append(crl_box) adv_other_box = ShadowGui.widgetBox(tab_adv, "Optional file output", addSpace=False, orientation="vertical") gui.comboBox(adv_other_box, self, "file_to_write_out", label="Files to write out", labelWidth=310, items=["All", "Mirror", "Image", "None"], sendSelectedValue=False, orientation="horizontal") button_box = ShadowGui.widgetBox(self.controlArea, "", addSpace=False, orientation="horizontal") button = gui.button(button_box, self, "Run Shadow/trace", callback=self.traceOpticalElement) font = QFont(button.font()) font.setBold(True) button.setFont(font) palette = QPalette(button.palette()) # make a copy of the palette palette.setColor(QPalette.ButtonText, QColor('Dark Blue')) button.setPalette(palette) # assign new palette button.setFixedHeight(45) button = gui.button(button_box, self, "Reset Fields", callback=self.callResetSettings) font = QFont(button.font()) font.setItalic(True) button.setFont(font) palette = QPalette(button.palette()) # make a copy of the palette palette.setColor(QPalette.ButtonText, QColor('Dark Red')) button.setPalette(palette) # assign new palette button.setFixedHeight(45) button.setFixedWidth(100)
def checkFields(self): ShadowGui.checkPositiveNumber(self.nlenses, "Number of lenses") ShadowGui.checkPositiveNumber(self.slots_empty, "Number of empty slots") ShadowGui.checkPositiveNumber(self.thickness, "Piling thickness") ShadowGui.checkPositiveNumber(self.p, "P") ShadowGui.checkPositiveNumber(self.q, "Q") if self.has_finite_diameter: ShadowGui.checkStrictlyPositiveNumber(self.diameter, "Diameter") if self.ri_calculation_mode == 1: ShadowGui.checkFile(self.prerefl_file) else: ShadowGui.checkStrictlyPositiveNumber(self.refraction_index, "Refraction Index") ShadowGui.checkStrictlyPositiveNumber(self.attenuation_coefficient, "Attenuation Coefficient") ShadowGui.checkStrictlyPositiveNumber(self.radius, "Radius") ShadowGui.checkPositiveNumber(self.interthickness, "Lens Thickness")
def __init__(self, transfocator=None, parent=None, nlenses=30, slots_empty=0, thickness=625e-4, p=0.0, q=0.0, surface_shape=1, convex_to_the_beam=1, has_finite_diameter=0, diameter=0.0, is_cylinder=1, cylinder_angle=0.0, ri_calculation_mode=0, prerefl_file=Transfocator.NONE_SPECIFIED, refraction_index=1.0, attenuation_coefficient=0.0, radius=500e-2, interthickness=0.001, use_ccc=0): super().__init__(parent) self.setLayout(QtGui.QVBoxLayout()) self.layout().setAlignment(Qt.AlignTop) self.setFixedWidth(470) self.setFixedHeight(700) self.transfocator = transfocator self.nlenses = nlenses self.slots_empty = slots_empty self.thickness = thickness self.p = p self.q = q self.surface_shape = surface_shape self.convex_to_the_beam = convex_to_the_beam self.has_finite_diameter = has_finite_diameter self.diameter = diameter self.is_cylinder = is_cylinder self.cylinder_angle = cylinder_angle self.ri_calculation_mode = ri_calculation_mode self.prerefl_file = prerefl_file self.refraction_index = refraction_index self.attenuation_coefficient = attenuation_coefficient self.radius = radius self.interthickness = interthickness self.use_ccc = use_ccc crl_box = ShadowGui.widgetBox(self, "C.R.L. Input Parameters", addSpace=False, orientation="vertical", height=100, width=460) ShadowGui.lineEdit(crl_box, self, "nlenses", "Number of lenses", labelWidth=350, valueType=int, orientation="horizontal", callback=self.transfocator.dump_nlenses) ShadowGui.lineEdit(crl_box, self, "slots_empty", "Number of empty slots", labelWidth=350, valueType=int, orientation="horizontal", callback=self.transfocator.dump_slots_empty) ShadowGui.lineEdit(crl_box, self, "thickness", "Piling thickness [cm]", labelWidth=350, valueType=float, orientation="horizontal", callback=self.transfocator.dump_thickness) lens_box = ShadowGui.widgetBox(self, "Single Lens Input Parameters", addSpace=False, orientation="vertical", height=510, width=460) ShadowGui.lineEdit(lens_box, self, "p", "Distance Source-First lens interface (P) [cm]", labelWidth=350, valueType=float, orientation="horizontal", callback=self.transfocator.dump_p) ShadowGui.lineEdit(lens_box, self, "q", "Distance Last lens interface-Image plane (Q) [cm]", labelWidth=350, valueType=float, orientation="horizontal", callback=self.transfocator.dump_q) gui.separator(lens_box) gui.comboBox(lens_box, self, "has_finite_diameter", label="Lens Diameter", labelWidth=350, items=["Finite", "Infinite"], sendSelectedValue=False, orientation="horizontal", callback=self.set_diameter) self.diameter_box = ShadowGui.widgetBox(lens_box, "", addSpace=False, orientation="vertical", height=20) self.diameter_box_empty = ShadowGui.widgetBox(lens_box, "", addSpace=False, orientation="vertical", height=20) ShadowGui.lineEdit(self.diameter_box, self, "diameter", "Lens Diameter Value [cm]", labelWidth=350, valueType=float, orientation="horizontal", callback=self.transfocator.dump_diameter) self.set_diameter() gui.separator(lens_box) gui.comboBox(lens_box, self, "surface_shape", label="Surface Shape", labelWidth=350, items=["Sphere", "Paraboloid", "Plane"], sendSelectedValue=False, orientation="horizontal", callback=self.set_surface_shape) self.surface_shape_box = ShadowGui.widgetBox(lens_box, "", addSpace=False, orientation="vertical", height=20) self.surface_shape_box_empty = ShadowGui.widgetBox(lens_box, "", addSpace=False, orientation="vertical", height=20) ShadowGui.lineEdit(self.surface_shape_box, self, "radius", "Curvature Radius [cm]", labelWidth=350, valueType=float, orientation="horizontal", callback=self.transfocator.dump_radius) self.set_surface_shape() ShadowGui.lineEdit(lens_box, self, "interthickness", "Lens Thickness [cm]", labelWidth=350, valueType=float, orientation="horizontal", callback=self.transfocator.dump_interthickness) gui.comboBox(lens_box, self, "use_ccc", label="Use C.C.C.", labelWidth=350, items=["No", "Yes"], sendSelectedValue=False, orientation="horizontal", callback=self.transfocator.dump_use_ccc) gui.comboBox(lens_box, self, "convex_to_the_beam", label="Convexity of the first interface exposed to the beam\n(the second interface has opposite convexity)", labelWidth=350, items=["No", "Yes"], sendSelectedValue=False, orientation="horizontal", callback=self.transfocator.dump_convex_to_the_beam) gui.separator(lens_box) gui.comboBox(lens_box, self, "is_cylinder", label="Cylindrical", labelWidth=350, items=["No", "Yes"], sendSelectedValue=False, orientation="horizontal", callback=self.set_cylindrical) self.box_cyl = ShadowGui.widgetBox(lens_box, "", addSpace=True, orientation="vertical", height=25) self.box_cyl_empty = ShadowGui.widgetBox(lens_box, "", addSpace=True, orientation="vertical", height=25) gui.comboBox(self.box_cyl, self, "cylinder_angle", label="Cylinder Angle (deg)", labelWidth=350, items=["0 (Meridional)", "90 (Sagittal)"], sendSelectedValue=False, orientation="horizontal", callback=self.transfocator.dump_cylinder_angle) self.set_cylindrical() gui.separator(lens_box) gui.comboBox(lens_box, self, "ri_calculation_mode", label="Refraction Index calculation mode", labelWidth=350, items=["User Parameters", "Prerefl File"], sendSelectedValue=False, orientation="horizontal", callback=self.set_ri_calculation_mode) self.calculation_mode_1 = ShadowGui.widgetBox(lens_box, "", addSpace=True, orientation="vertical", height=50) ShadowGui.lineEdit(self.calculation_mode_1, self, "refraction_index", "Refraction index", labelWidth=350, valueType=float, orientation="horizontal", callback=self.transfocator.dump_refraction_index) ShadowGui.lineEdit(self.calculation_mode_1, self, "attenuation_coefficient", "Attenuation coefficient [cm-1]", labelWidth=350, valueType=float, orientation="horizontal", callback=self.transfocator.dump_attenuation_coefficient) self.calculation_mode_2 = ShadowGui.widgetBox(lens_box, "", addSpace=True, orientation="vertical", height=50) self.le_prerefl_file = ShadowGui.lineEdit(self.calculation_mode_2, self, "prerefl_file", "File Prerefl", labelWidth=150, valueType=str, orientation="horizontal", callback=self.transfocator.dump_prerefl_file) self.set_ri_calculation_mode() self.is_on_init = False
def checkFields(self): ShadowGui.checkPositiveNumber(self.source_plane_distance, "Distance from Source") ShadowGui.checkPositiveNumber(self.image_plane_distance, "Image Plane Distance") ShadowGui.checkPositiveNumber(self.focal_x, "Focal length (horizontal)") ShadowGui.checkPositiveNumber(self.focal_y, "Focal length (vertical)")