Example #1
0
    def update_labels(self):
        Canvas = self.canvas
        try:
            Canvas.RemoveObject(self.labelGroup)
        except ValueError:
            pass
        self.labelGroup = FloatCanvas.Group()
        for room in self.sim.hospital.layout.values():
            #draw output for allocation room
            if isinstance(room, BedAllocationRoom):
                settings = ROOM_SETTINGS['room_mapping'][type(room)]
                timeToIBA = room.get_time_to_initial_bed_assignment()
                numClosedBeds = room.get_num_closed_beds_by_category()[1]
                self.labelGroup.AddObject(
                    FloatCanvas.ScaledText(
                        "t to IBA = {}({})".format(timeToIBA[0], timeToIBA[1]),
                        (room.guiCoords[0],
                         room.guiCoords[1] - settings[HEIGHT] / 2.0 -
                         ROOM_SETTINGS['name_text_size']),
                        Position="tc",
                        Size=ROOM_SETTINGS['name_text_size']))
                self.labelGroup.AddObject(
                    FloatCanvas.ScaledText(
                        "Num Closed Beds = {}".format(numClosedBeds),
                        (room.guiCoords[0],
                         room.guiCoords[1] - settings[HEIGHT] / 2.0 -
                         2 * ROOM_SETTINGS['name_text_size']),
                        Position="tc",
                        Size=ROOM_SETTINGS['name_text_size']))

        Canvas.AddObject(self.labelGroup)
        Canvas.Draw()
Example #2
0
 def test_floatcanvas_group(self):
     item1 = FloatCanvas.Circle((0, 0), 10)
     item2 = FloatCanvas.Circle((0, 5), 10)
     item3 = FloatCanvas.Circle((5, 5), 10)
     try:
         FloatCanvas.Group([item1, item2, item3])
     except AttributeError:
         self.fail(
             "Has wx/lib/floatcanvas/FCObjects.py been edited correctly?")
Example #3
0
def draw_crosshairs(dia=150, dot=False):
    """Draw the crosshairs or wafer center dot."""
    if dot:
        circ = FloatCanvas.Circle(
            (0, 0),
            2.5,
            FillColor=wm_const.wm_WAFER_CENTER_DOT_COLOR,
        )

        return FloatCanvas.Group([circ])
    else:
        # Default: use crosshairs
        rad = dia / 2
        xline = FloatCanvas.Line(
            [(rad * 1.05, 0), (-rad * 1.05, 0)],
            LineColor=wx.CYAN,
        )
        yline = FloatCanvas.Line(
            [(0, rad * 1.05), (0, -rad * 1.05)],
            LineColor=wx.CYAN,
        )

        return FloatCanvas.Group([xline, yline])
Example #4
0
    def draw_die_center(self):
        """Plot the die centers as a small dot."""
        centers = []
        for die in self.xyd:
            # Determine the die's lower-left coordinate
            lower_left_coord = wm_utils.grid_to_rect_coord(
                die[:2], self.die_size, self.grid_center)

            # then adjust back to the die center
            lower_left_coord = (lower_left_coord[0] + self.die_size[0] / 2,
                                lower_left_coord[1] + self.die_size[1] / 2)

            circ = FloatCanvas.Circle(
                lower_left_coord,
                0.5,
                FillColor=wm_const.wm_DIE_CENTER_DOT_COLOR,
            )
            centers.append(circ)

        return FloatCanvas.Group(centers)
Example #5
0
    def draw_generic_patient(self, gender, number, observedCP, patientCoords):
        settings = PATIENT_SETTINGS
        group = FloatCanvas.Group()

        if gender == MALE:
            lineColor = settings['line_color_male']
        else:
            lineColor = settings['line_color_female']

        MRSAStr = observedCP[0] and "M+" or "M-"
        VREStr = observedCP[1] and "V+" or "V-"
        group.AddObject(
            FloatCanvas.Circle(patientCoords,
                               settings['radius'] * 2,
                               LineWidth=settings['line_width'],
                               LineColor=lineColor,
                               FillStyle="Solid"))
        group.AddObject(
            FloatCanvas.ScaledText("x {0}".format(number),
                                   patientCoords,
                                   Position="cc",
                                   Size=settings['id_text_size'],
                                   Weight=wx.BOLD))
        group.AddObject(
            FloatCanvas.ScaledText(str(MRSAStr),
                                   (patientCoords[0] - settings['radius'],
                                    patientCoords[1] + settings['radius']),
                                   Position="cc",
                                   Size=settings['acuity_text_size'],
                                   Weight=wx.BOLD))
        group.AddObject(
            FloatCanvas.ScaledText(str(VREStr),
                                   (patientCoords[0] + settings['radius'],
                                    patientCoords[1] + settings['radius']),
                                   Position="cc",
                                   Size=settings['acuity_text_size'],
                                   Weight=wx.BOLD))

        return group
Example #6
0
def draw_die_gridlines(wf):
    """
    Draw the die gridlines.

    Parameters
    ----------
    wf : :class:`wm_info.WaferInfo`
        The wafer info to calculate gridlines for.

    Returns
    -------
    group : :class:`wx.lib.floatcanvas.FloatCanvas.Group`
        The collection of all die gridlines.
    """
    x_size = wf.die_size[0]
    y_size = wf.die_size[1]
    grey = wx.Colour(64, 64, 64)
    edge = (wf.dia / 2) * 1.05

    # calculate the values for the gridlines
    x_ref = math.modf(wf.center_xy[0])[0] * x_size + (x_size / 2)
    pos_vert = np.arange(x_ref, edge, x_size)
    neg_vert = np.arange(x_ref, -edge, -x_size)

    y_ref = math.modf(wf.center_xy[1])[0] * y_size + (y_size / 2)
    pos_horiz = np.arange(y_ref, edge, y_size)
    neg_horiz = np.arange(y_ref, -edge, -y_size)

    # reverse `[::-1]`, remove duplicate `[1:]`, and join
    x_values = np.concatenate((neg_vert[::-1], pos_vert[1:]))
    y_values = np.concatenate((neg_horiz[::-1], pos_horiz[1:]))

    line_coords = list([(x, -edge), (x, edge)] for x in x_values)
    line_coords.extend([(-edge, y), (edge, y)] for y in y_values)

    lines = [FloatCanvas.Line(l, LineColor=grey) for l in line_coords]

    return FloatCanvas.Group(list(lines))
Example #7
0
def draw_wafer_outline(dia=150, excl=5, flat=None):
    """
    Draw a wafer outline for a given radius, including any exclusion lines.

    Parameters
    ----------
    dia : float, optional
        The wafer diameter in mm. Defaults to `150`.
    excl : float, optional
        The exclusion distance from the edge of the wafer in mm. Defaults to
        `5`.
    flat : float, optional
        The exclusion distance from the wafer flat in mm. If ``None``, uses
        the same value as ``excl``. Defaults to ``None``.

    Returns
    -------
    :class:`wx.lib.floatcanvas.FloatCanvas.Group`
        A ``Group`` that can be added to any floatcanvas.FloatCanvas instance.
    """
    rad = float(dia) / 2.0
    if flat is None:
        flat = excl

    # Full wafer outline circle
    circ = FloatCanvas.Circle(
        (0, 0),
        dia,
        LineColor=wm_const.wm_OUTLINE_COLOR,
        LineWidth=1,
    )

    # Calculate the exclusion Radius
    exclRad = 0.5 * (dia - 2.0 * excl)

    if dia in wm_const.wm_FLAT_LENGTHS:
        # A flat is defined, so we draw it.
        flat_size = wm_const.wm_FLAT_LENGTHS[dia]
        x = flat_size / 2
        y = -math.sqrt(rad**2 - x**2)  # Wfr Flat's Y Location

        arc = FloatCanvas.Arc(
            (x, y),
            (-x, y),
            (0, 0),
            LineColor=wm_const.wm_WAFER_EDGE_COLOR,
            LineWidth=3,
        )

        # actually a wafer flat, but called notch
        notch = draw_wafer_flat(rad, wm_const.wm_FLAT_LENGTHS[dia])
        # Define the arc angle based on the flat exclusion, not the edge
        # exclusion. Find the flat exclusion X and Y coords.
        FSSflatY = y + flat
        if exclRad < abs(FSSflatY):
            # Then draw a circle with no flat
            excl_arc = FloatCanvas.Circle(
                (0, 0),
                exclRad * 2,
                LineColor=wm_const.wm_WAFER_EDGE_COLOR,
                LineWidth=3,
            )
            excl_group = FloatCanvas.Group([excl_arc])
        else:
            FSSflatX = math.sqrt(exclRad**2 - FSSflatY**2)

            # Define the wafer arc
            excl_arc = FloatCanvas.Arc(
                (FSSflatX, FSSflatY),
                (-FSSflatX, FSSflatY),
                (0, 0),
                LineColor=wm_const.wm_WAFER_EDGE_COLOR,
                LineWidth=3,
            )

            excl_notch = draw_wafer_flat(exclRad, FSSflatX * 2)
            excl_group = FloatCanvas.Group([excl_arc, excl_notch])
    else:
        # Flat not defined, so use a notch to denote wafer orientation.
        ang = 2.5
        start_xy, end_xy = calc_flat_coords(rad, ang)

        arc = FloatCanvas.Arc(
            start_xy,
            end_xy,
            (0, 0),
            LineColor=wm_const.wm_WAFER_EDGE_COLOR,
            LineWidth=3,
        )

        notch = draw_wafer_notch(rad)
        # Flat not defined, so use a notch to denote wafer orientation.
        start_xy, end_xy = calc_flat_coords(exclRad, ang)

        excl_arc = FloatCanvas.Arc(
            start_xy,
            end_xy,
            (0, 0),
            LineColor=wm_const.wm_WAFER_EDGE_COLOR,
            LineWidth=3,
        )

        excl_notch = draw_wafer_notch(exclRad)
        excl_group = FloatCanvas.Group([excl_arc, excl_notch])

    # Group the outline arc and the orientation (flat / notch) together
    group = FloatCanvas.Group([circ, arc, notch, excl_group])
    return group
Example #8
0
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.CreateStatusBar()

        # Add the Canvas
        NC = NavCanvas.NavCanvas(
            self,
            -1,
            size=(500, 500),
            ProjectionFun=None,
            Debug=0,
            BackgroundColor="DARK SLATE BLUE",
        )
        Canvas = NC.Canvas
        self.Canvas = Canvas

        self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)

        Point = (45, 40)

        ## create a few Objects:
        C = FloatCanvas.Circle((0, 0), 10, FillColor="Red")
        R = FloatCanvas.Rectangle((5, 5), (15, 8), FillColor="Blue")
        E = FloatCanvas.Ellipse((1.5, 1.5), (12, 8), FillColor="Purple")
        C2 = FloatCanvas.Circle((0, 5), 10, FillColor="cyan")
        T = FloatCanvas.Text("Group A", (5.5, 5.5),
                             Position="cc",
                             Size=16,
                             Weight=wx.BOLD,
                             Family=wx.SWISS)

        self.GroupA = FloatCanvas.Group((R, C, E))
        self.GroupA.AddObjects((C2, T))
        Canvas.AddObject(self.GroupA)

        ## create another Groups of objects

        R = FloatCanvas.Rectangle((15, 15), (10, 18), FillColor="orange")
        E = FloatCanvas.Ellipse((22, 28), (12, 8), FillColor="yellow")
        C = FloatCanvas.Circle((25, 20), 15, FillColor="Green")
        C2 = FloatCanvas.Circle((12, 22), 10, FillColor="cyan")
        T = FloatCanvas.Text("Group B", (19, 24),
                             Position="cc",
                             Size=16,
                             Weight=wx.BOLD,
                             Family=wx.SWISS)

        self.GroupB = FloatCanvas.Group((R, E, C, C2, T))
        Canvas.AddObject(self.GroupB)

        self.Groups = {"A": self.GroupA, "B": self.GroupB}

        # Add a couple of tools to the Canvas Toolbar

        tb = NC.ToolBar
        #        tb.AddSeparator()

        for Group in self.Groups:
            Button = wx.Button(tb, wx.ID_ANY, "Remove %s" % Group)
            tb.AddControl(Button)
            Button.Bind(wx.EVT_BUTTON,
                        lambda evt, group=Group: self.RemoveGroup(evt, group))
            Button = wx.Button(tb, wx.ID_ANY, "Replace%s" % Group)
            tb.AddControl(Button)
            Button.Bind(wx.EVT_BUTTON,
                        lambda evt, group=Group: self.ReplaceGroup(evt, group))
        tb.Realize()

        self.Show()
        Canvas.ZoomToBB()
Example #9
0
    def __init__(self, parent, title, sim):
        wx.Frame.__init__(self, parent, title=title, size=(950, 800))

        self.sim = sim
        self.runThread = None
        layout = self.sim.hospital.layout
        startRoomID, endRoomID = sim.hospital.validate_layout(layout)
        self.auto_layout(layout, layout[startRoomID], layout[endRoomID])

        #Menu bar
        MenuBar = wx.MenuBar()

        file_menu = wx.Menu()
        item = file_menu.Append(-1, "&Load Input File", "Load Inputs")
        self.Bind(wx.EVT_MENU, self.OnLoadInputFile, item)
        item = file_menu.Append(-1, "Load Initial &Patients", "Load")
        self.Bind(wx.EVT_MENU, self.OnLoadPatients, item)
        item = file_menu.Append(-1, "Run &Batch", "Batch")
        self.Bind(wx.EVT_MENU, self.OnRunBatch, item)
        item = file_menu.Append(-1, "Write Output File", "Write Output")
        self.Bind(wx.EVT_MENU, self.OnWriteOutput, item)

        item = file_menu.Append(-1, "&SavePNG",
                                "Save the current image as a PNG")
        self.Bind(wx.EVT_MENU, self.OnSavePNG, item)
        item = file_menu.Append(-1, "&Close", "Close this frame")
        self.Bind(wx.EVT_MENU, self.OnQuit, item)
        MenuBar.Append(file_menu, "&File")

        settings_menu = wx.Menu()
        self.matchCPMI = settings_menu.Append(
            -1,
            "&Match on CP status",
            "Match patients based on observed CP status",
            kind=wx.ITEM_CHECK)
        self.matchCPMI.Check(True)
        self.Bind(wx.EVT_MENU, self.OnMatchCP, self.matchCPMI)
        MenuBar.Append(settings_menu, "&Settings")

        self.SetMenuBar(MenuBar)
        self.CreateStatusBar()

        # Add the Canvas
        NC = NavCanvas.NavCanvas(self, Debug=0, BackgroundColor="White")
        self.canvas = NC.Canvas

        #tool bar
        tb = NC.ToolBar
        tb.AddSeparator()

        Button = wx.Button(tb, wx.ID_ANY, "Step")
        tb.AddControl(Button)
        Button.Bind(wx.EVT_BUTTON, self.OnStep)

        Button = wx.Button(tb, wx.ID_ANY, "Step 10")
        tb.AddControl(Button)
        Button.Bind(wx.EVT_BUTTON, self.OnStepMany)

        Button = wx.Button(tb, wx.ID_ANY, "Step n")
        tb.AddControl(Button)
        Button.Bind(wx.EVT_BUTTON, self.OnStepN)

        self.stepNTc = wx.TextCtrl(tb, -1, size=(60, -1))
        tb.AddControl(self.stepNTc)

        tb.Realize()

        self.patientGroup = FloatCanvas.Group()
        self.canvas.AddObject(self.patientGroup)
        self.labelGroup = FloatCanvas.Group()
        self.canvas.AddObject(self.labelGroup)
        self.draw_layout()

        #call zoom to fit seems to only work as an event
        wx.PostEvent(NC.ZoomButton, wx.PyCommandEvent(wx.EVT_BUTTON.typeId))
Example #10
0
    def draw_patient(self, patient, patientCoords):
        settings = PATIENT_SETTINGS
        group = FloatCanvas.Group()
        if isinstance(patient, CleaningPatient):
            fillColor = settings['fill_color_cleaning']
            lineWidth = settings['line_width']
            lineColor = settings['line_color_cleaning']
        else:
            if patient.gender == MALE:
                lineColor = settings['line_color_male']
            else:
                lineColor = settings['line_color_female']

            patID = patient.id
            fillColor = None
            lineWidth = patient.acuity
            if isinstance(patient, PhantomPatient):
                fillColor = settings['fill_color_phantom']
                patID = patient.realPatient.id

        group.AddObject(
            FloatCanvas.Circle(patientCoords,
                               settings['radius'] * 2,
                               LineWidth=lineWidth,
                               LineColor=lineColor,
                               FillColor=fillColor,
                               FillStyle="Solid"))

        if isinstance(patient, BasePatient):
            #id num
            group.AddObject(
                FloatCanvas.ScaledText(str(patID),
                                       patientCoords,
                                       Position="cc",
                                       Size=settings['id_text_size'],
                                       Weight=wx.BOLD))
            #acuity num
            group.AddObject(
                FloatCanvas.ScaledText(str(patient.acuity),
                                       (patientCoords[0] - settings['radius'],
                                        patientCoords[1] - settings['radius']),
                                       Position="cc",
                                       Size=settings['acuity_text_size'],
                                       Weight=wx.BOLD))
            #service
            group.AddObject(
                FloatCanvas.ScaledText(str(patient.service),
                                       (patientCoords[0] + settings['radius'],
                                        patientCoords[1] - settings['radius']),
                                       Position="cc",
                                       Size=settings['acuity_text_size'],
                                       Weight=wx.BOLD))
            #MRSA VRE
            MRSAStr = patient.has_observed_MRSA() and "M+" or "M-"
            VREStr = patient.has_observed_VRE() and "V+" or "V-"
            group.AddObject(
                FloatCanvas.ScaledText(str(MRSAStr),
                                       (patientCoords[0] - settings['radius'],
                                        patientCoords[1] + settings['radius']),
                                       Position="cc",
                                       Size=settings['acuity_text_size'],
                                       Weight=wx.BOLD))
            group.AddObject(
                FloatCanvas.ScaledText(str(VREStr),
                                       (patientCoords[0] + settings['radius'],
                                        patientCoords[1] + settings['radius']),
                                       Position="cc",
                                       Size=settings['acuity_text_size'],
                                       Weight=wx.BOLD))
        else:
            group.AddObject(
                FloatCanvas.ScaledText("C",
                                       patientCoords,
                                       Position="cc",
                                       Size=settings['id_text_size'],
                                       Weight=wx.BOLD))

        return group
Example #11
0
    def draw_patients(self):
        Canvas = self.canvas
        try:
            Canvas.RemoveObject(self.patientGroup)
        except ValueError:
            pass

        self.patientGroup = FloatCanvas.Group()

        #loop through all rooms and draw patients in each room
        for room in self.sim.hospital.layout.values():
            settings = PATIENT_SETTINGS
            roomSettings = ROOM_SETTINGS['room_mapping'][type(room)]
            roomCoords = room.guiCoords
            patientIDs = room.patients.keys()
            numPatients = len(patientIDs)
            roomWidth, roomHeight = self.get_room_dim(room)
            subRoomWidth = roomSettings[WIDTH]

            x_num = min(settings['num_per_row'], numPatients)
            y_num = (numPatients - 1) / settings['num_per_row'] + 1
            if isinstance(room, BedRoom):
                subRoomWidth = roomWidth / float(room.capacity)
                x_num, y_num = 1, 1

                #draw blocked beds
                for bed in range(len(room.beds)):
                    if room.bedsBlockedStaffing[bed]:
                        self.draw_blocked_bed(room, bed)

            avgBorderSpacing = 2
            x_spacing = (subRoomWidth - 2 * x_num *
                         (settings['radius'] + avgBorderSpacing)
                         ) / float(numPatients + 1) + 2 * (settings['radius'] +
                                                           avgBorderSpacing)
            y_spacing = (roomHeight - 2 * y_num *
                         (settings['radius'] + avgBorderSpacing)
                         ) / float(numPatients + 1) + 2 * (settings['radius'] +
                                                           avgBorderSpacing)

            if numPatients > ROOM_SETTINGS['max_display_patients']:
                from itertools import product
                patientTypes = tuple(
                    product((MALE, FEMALE), (True, False), (True, False)))
                patientTypesDict = dict([(pType, 0) for pType in patientTypes])
                for patient in room.patients.values():

                    pType = (patient.gender, patient.has_observed_MRSA(),
                             patient.has_observed_VRE())
                    patientTypesDict[pType] += 1
                #draw generic male and female icon
                for n, pType in enumerate(patientTypes):
                    num = patientTypesDict[pType]
                    i, j = n % 2, n / 2
                    x_num = 2
                    y_num = 4
                    x_spacing = (roomWidth - 2 * x_num *
                                 (settings['radius'] + avgBorderSpacing)
                                 ) / float(8 + 1) + 2 * (
                                     settings['radius'] +
                                     avgBorderSpacing) + avgBorderSpacing * 3
                    y_spacing = (roomHeight - 2 * y_num *
                                 (settings['radius'] + avgBorderSpacing)
                                 ) / float(8 + 1) + 2 * (settings['radius'] +
                                                         avgBorderSpacing)
                    self.patientGroup.AddObject(
                        self.draw_generic_patient(
                            pType[0], num, (pType[1], pType[2]),
                            (roomCoords[0] +
                             (i -
                              (x_num - 1) / 2.0) * x_spacing, roomCoords[1] +
                             (j - (y_num - 1) / 2.0) * y_spacing)))

            else:
                for n in range(numPatients):
                    patient = room.patients[patientIDs[n]]
                    i, j = n % settings['num_per_row'], n / settings[
                        'num_per_row']
                    #draw patient in correct bed
                    if isinstance(room, BedRoom):
                        bedNum = room.beds.index(patient)
                        roomCoords = (room.guiCoords[0] - roomWidth / 2.0 +
                                      subRoomWidth * (bedNum) +
                                      subRoomWidth / 2.0, room.guiCoords[1])
                        i, j = 0, 0
                    self.patientGroup.AddObject(
                        self.draw_patient(
                            patient,
                            (roomCoords[0] +
                             (i -
                              (x_num - 1) / 2.0) * x_spacing, roomCoords[1] +
                             (j - (y_num - 1) / 2.0) * y_spacing)))
        Canvas.AddObject(self.patientGroup)
        Canvas.Draw()