Exemplo n.º 1
0
def test_groupby_key(modelspace):
    result = groupby(modelspace, key=lambda e: (e.dxf.color, e.dxf.layer))
    assert len(result) == 4  # 4 different (color, layers) combinations
    assert set(result.keys()) == {
        (6, "lay_lines"),
        (7, "lay_lines"),
        (6, "lay_text"),
        (6, "lay_text2"),
    }
Exemplo n.º 2
0
def test_groupby_result(modelspace):
    result = groupby(modelspace, dxfattrib='layer')
    lines = result['lay_lines']
    assert len(lines) == 2

    text = result['lay_text']
    assert len(text) == 1

    with pytest.raises(KeyError):
        e = result['mozman']
Exemplo n.º 3
0
def test_groupby_result(modelspace):
    result = groupby(modelspace, dxfattrib="layer")
    lines = result["lay_lines"]
    assert len(lines) == 2

    text = result["lay_text"]
    assert len(text) == 1

    with pytest.raises(KeyError):
        e = result["mozman"]
Exemplo n.º 4
0
    def groupby(self, dxfattrib: str = '', key: Callable[['DXFEntity'], Hashable] = None) \
            -> Dict[Hashable, List['DXFEntity']]:
        """
        Returns a dict of entity lists, where entities are grouped by a DXF attribute or a key function.

        Args:
            dxfattrib: grouping DXF attribute as string like ``'layer'``
            key: key function, which accepts a DXFEntity as argument, returns grouping key of this entity or None for
                 ignore this object. Reason for ignoring: a queried DXF attribute is not supported by this entity

        """
        return groupby(self.entities, dxfattrib, key)
Exemplo n.º 5
0
Arquivo: base.py Projeto: hh-wu/ezdxf
    def groupby(self, dxfattrib: str = "", key: 'KeyFunc' = None) -> dict:
        """
        Returns a ``dict`` of entity lists, where entities are grouped by a `dxfattrib` or a `key` function.

        Args:
            dxfattrib: grouping by DXF attribute like ``'layer'``
            key: key function, which accepts a :class:`DXFGraphic` entity as argument and returns the grouping key of an
                 entity or ``None`` to ignore the entity. Reason for ignoring: a queried DXF attribute is not
                 supported by entity.

        """
        return groupby(iter(self), dxfattrib, key)
Exemplo n.º 6
0
    def groupby(self, dxfattrib='', key=None):
        """
        Returns a dict of entity lists, where entities are grouped by a dxfattrib or a key function.

        Args:
            dxfattrib: grouping DXF attribute like 'layer'
            key: key function, which accepts a DXFEntity as argument, returns grouping key of this entity or None for
            ignore this object. Reason for ignoring: a queried DXF attribute is not supported by this entity

        Returns: dict

        """
        return groupby(self.entities, dxfattrib, key)
Exemplo n.º 7
0
    def groupby(self,
                dxfattrib: str = "",
                key: 'KeyFunc' = None) -> Dict[Hashable, List['DXFEntity']]:
        """
        Returns a dict of entity lists, where entities are grouped by a `dxfattrib` or a `key` function.

        Args:
            dxfattrib: grouping by DXF attribute like "layer"
            key: key function, which accepts a :class:`DXFEntity` as argument, returns grouping key of this entity or
                 None to ignore this object. Reason for ignoring: a queried DXF attribute is not supported by this
                 entity.

        """
        return groupby(iter(self), dxfattrib, key)
Exemplo n.º 8
0
    def groupby(self, dxfattrib="", key=None):
        """
        Groups DXF entities of all layouts and blocks by an DXF attribute or a key function.

        Excluding the OBJECTS section!

        Args:
            dxfattrib: grouping DXF attribute like 'layer'
            key: key function, which accepts a DXFEntity as argument, returns grouping key of this entity or None for ignore
                 this object. Reason for ignoring: a queried DXF attribute is not supported by this entity

        Returns: dict

        """
        return groupby(self.chain_layouts_and_blocks(), dxfattrib, key)
Exemplo n.º 9
0
    def groupby(self, dxfattrib="", key=None) -> dict:
        """ Groups DXF entities of all layouts and blocks (excluding the
        OBJECTS section) by a DXF attribute or a key function.

        Args:
            dxfattrib: grouping DXF attribute like ``'layer'``
            key: key function, which accepts a :class:`DXFEntity` as argument
                and returns a hashable grouping key or ``None`` to ignore
                this entity.

        .. seealso::

            :func:`~ezdxf.groupby.groupby` documentation

        """
        return groupby(self.chain_layouts_and_blocks(), dxfattrib, key)
Exemplo n.º 10
0
    def __init__(self, dados: Dados, num_elems: int, tipo_malha='poligonal'):
        """Construtor.

        Args:
            dados: Objeto que manipula os dados dos arquivos do problema.
            num_elems: Número de elementos finitos que serão gerados.
            tipo_malha: Tipo de distribuição das sementes dos diagramas de Voronoi. Pode ser 'poligonal' ou 'retangular'.
        """
        self.dados = dados
        self.num_elems = num_elems
        self.tipo_malha = tipo_malha
        # Agrupamento das linhas do dxf por layer
        arquivo_dxf = self.dados.arquivo.with_suffix('.dxf').name
        self.layers: dict = groupby(
            entities=ezdxf.readfile(arquivo_dxf).modelspace(),
            dxfattrib='layer')
Exemplo n.º 11
0
    def __init__(self, dxf_path):
        '''
        loads in a dxf file and generates a frame from the file
        '''
        doc = ezdxf.readfile(dxf_path)
        layers = groupby(entities=doc.modelspace(), dxfattrib='layer')

        if len(layers['0']) != 1:
            if len(layers['0']) == 0:
                raise ValueError(
                    'Body (layer 0) does not exist, assign to layer 0')
            else:
                raise ValueError('Body (layer 0) is disjoint')

        if len(layers['1']) == 0:
            raise ValueError('No injector (layer 1)')

        if len(layers['2']) == 0:
            raise ValueError('No ground (layer 2)')

        self._extract_points(layers)
        self._gen_frame()
        self._gen_matrices_for_det()
        self._calc_ohmic_length()
Exemplo n.º 12
0
 def upload_file(self, request, pk=None):
     """upload an file/image to a userfile"""
     user_file = self.get_object()
     serializer = self.get_serializer(user_file, data=request.data)
     if request.method == 'GET':
         if serializer.is_valid():
             serializer.save()
             return Response(serializer.data, status=status.HTTP_200_OK)
     elif request.method == 'POST':
         global foo, dim
         print(
             "-------------------------this is global foo-----------------------------------"
         )
         print(foo)
         print(
             "-------------------------this is global dim-----------------------------------"
         )
         print(dim)
         foo[:] = []
         dim[:] = []
         if serializer.is_valid():
             serializer.save()
             print(serializer.data)
             print(serializer.data['file'])
             url = serializer.data['file']
             x = url.split("/", 6)
             file_name = x[6]
             print(file_name)
             # some more shady stuff about to happen look away
             # doc = ezdxf.readfile(f'/home/talha/My_Work/django/BuilderApi/app/media/uploads/user_files/{file_name}')
             doc = ezdxf.readfile(f"media/uploads/user_files/{file_name}")
             msp = doc.modelspace()
             group = groupby(entities=msp, dxfattrib='layer')
             counter = 0
             group = msp.groupby(dxfattrib='layer')
             group = msp.groupby(key=self.layer_and_color_key)
             temp = 0
             for x in foo:
                 dic = {
                     "layer": temp,
                     "start-X": x['start point'][0],
                     "end-X": x['end point'][0],
                     "start-Y": x['start point'][1],
                     "end-Y": x['end point'][1],
                     "start-Z": x['start point'][2],
                     "end-Z": x['end point'][2]
                 }
                 temp += 1
                 dim.append(dic)
             print(
                 "THIS IS FOOO-----------------------------------------------------"
             )
             print(foo)
             print(
                 "THIS IS DIM======================================================"
             )
             print(dim)
             return Response(dim, status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 13
0
 def groupby(self, dxfattrib="", key=None):
     return groupby(iter(self), dxfattrib, key)
Exemplo n.º 14
0
def test_groupby_dxfattrib():
    result = groupby(MODEL_SPACE, dxfattrib='layer')
    assert len(result) == 3  # 3 different layers
    assert set(result.keys()) == {'lay_lines', 'lay_text', 'lay_text2'}
Exemplo n.º 15
0
def test_calling_convention(modelspace):
    with pytest.raises(DXFValueError):  # if both query arguments are set
        groupby([], dxfattrib='layer', key=lambda e: e.dxf.layer)

    with pytest.raises(DXFValueError):  # if no query argument is set
        groupby([])
Exemplo n.º 16
0
def test_groupby_key():
    result = groupby(MODEL_SPACE, key=lambda e: (e.dxf.color, e.dxf.layer))
    assert len(result) == 4  # 4 different (color, layers) combinations
    assert set(result.keys()) == {(6, 'lay_lines'), (7, 'lay_lines'),
                                  (6, 'lay_text'), (6, 'lay_text2')}
Exemplo n.º 17
0
def test_groupby_not_existing_dxfattrib(modelspace):
    result = groupby(modelspace, dxfattrib='xxx')
    # no result, but does not raise an error, this is necessary, because otherwise, only DXF attributes supported by ALL
    # entities could be used, this implementation just ignores DXF entities which do not support the specified
    # dxfattrib, side effect: you can specify anything in dxfattrib.
    assert len(result) == 0
Exemplo n.º 18
0
def test_groupby_dxfattrib(modelspace):
    result = groupby(modelspace, dxfattrib='layer')
    assert len(result) == 3  # 3 different layers
    assert set(result.keys()) == {'lay_lines', 'lay_text', 'lay_text2'}
Exemplo n.º 19
0
def test_groupby_dxfattrib(modelspace):
    result = groupby(modelspace, dxfattrib="layer")
    assert len(result) == 3  # 3 different layers
    assert set(result.keys()) == {"lay_lines", "lay_text", "lay_text2"}