def flatten(self,
                single_layer=None,
                single_datatype=None,
                single_texttype=None):
        """
        Flatten all ``CellReference`` and ``CellArray`` elements in this
        cell into real polygons and labels, instead of references.

        Parameters
        ----------
        single_layer : integer or None
            If not ``None``, all polygons will be transfered to the
            layer indicated by this number.
        single_datatype : integer or None
            If not ``None``, all polygons will be transfered to the
            datatype indicated by this number.
        single_datatype : integer or None
            If not ``None``, all labels will be transfered to the
            texttype indicated by this number.

        Returns
        -------
        out : ``Cell``
            This cell.
        """
        self.labels = self.get_labels()
        if single_layer is not None:
            for lbl in self.labels:
                lbl.layer = single_layer
        if single_texttype is not None:
            for lbl in self.labels:
                lbl.texttype = single_texttype
        if single_layer is None or single_datatype is None:
            poly_dic = self.get_polygons(True)
            self.elements = []
            if single_layer is None and single_datatype is None:
                for ld in poly_dic.keys():
                    self.add(PolygonSet(poly_dic[ld], *ld, verbose=False))
            elif single_layer is None:
                for ld in poly_dic.keys():
                    self.add(
                        PolygonSet(
                            poly_dic[ld],
                            ld[0],
                            single_datatype,
                            verbose=False))
            else:
                for ld in poly_dic.keys():
                    self.add(
                        PolygonSet(
                            poly_dic[ld], single_layer, ld[1], verbose=False))
        else:
            polygons = self.get_polygons()
            self.elements = []
            self.add(
                PolygonSet(
                    polygons, single_layer, single_datatype, verbose=False))
        return self
Flatten all ``CellReference`` and ``CellArray`` elements in this
        cell into real polygons and labels, instead of references.

        Parameters
        ----------
        single_layer : integer or None
            If not ``None``, all polygons will be transfered to the
            layer indicated by this number.
        single_datatype : integer or None
            If not ``None``, all polygons will be transfered to the
            datatype indicated by this number.
        single_datatype : integer or None
            If not ``None``, all labels will be transfered to the
            texttype indicated by this number.

        Returns
        -------
        out : ``Cell``
            This cell.