Ejemplo n.º 1
0
def add_multi_field(
    layout,
    location: Vec3,
    values: List[float],
    color=FILL_COLOR,
    *,
    size=1.0,
    layer="0",
):
    # make n strips with explicit transparency values
    width = size / len(values)
    height = size
    offset = Vec3(width, 0)
    pos = location
    for transparency in values:
        layout.add_solid(
            solid_vertices(pos, width, height),
            dxfattribs={
                "color": color,
                "layer": layer,
                "transparency": colors.float2transparency(transparency),
            },
        )
        pos += offset
    add_frame(layout, location, size, size)
Ejemplo n.º 2
0
 def items(self, default_values=False) -> List[Tuple[str, Any]]:
     """Returns the DXF attributes as list of name, value pairs, returns
     also the default values if argument `default_values` is ``True``.
     The true_color and transparency attributes do not have default values,
     the absence of these attributes is the default value.
     """
     data: List[Tuple[str, Any]] = []
     if default_values or self._layer != DEFAULT_LAYER:
         data.append(("layer", self._layer))
     if default_values or self._aci_color != DEFAULT_ACI_COLOR:
         data.append(("color", self._aci_color))
     if self._true_color is not None:
         # absence is the default value
         data.append(("true_color", colors.rgb2int(self._true_color)))
     if default_values or self._linetype != DEFAULT_LINETYPE:
         data.append(("linetype", self._linetype))
     if default_values or self._lineweight != DEFAULT_LINEWEIGHT:
         data.append(("lineweight", self.lineweight))
     if self._transparency is not None:
         # absence is the default value
         if self._transparency == TRANSPARENCY_BYBLOCK:
             data.append(("transparency", colors.TRANSPARENCY_BYBLOCK))
         else:
             data.append(
                 (
                     "transparency",
                     colors.float2transparency(self._transparency),
                 )
             )
     if default_values or self._ltscale != DEFAULT_LTSCALE:
         data.append(("ltscale", self._ltscale))
     return data
Ejemplo n.º 3
0
 def transparency(self, value: float) -> None:
     # create AppID table entry if not present
     if self.doc and AcCmTransparency not in self.doc.appids:
         self.doc.appids.new(AcCmTransparency)
     if 0 <= value <= 1:
         self.discard_xdata(AcCmTransparency)
         self.set_xdata(AcCmTransparency,
                        [(1071, clr.float2transparency(value))])
     else:
         raise ValueError('Value out of range (0 .. 1).')
Ejemplo n.º 4
0
 def transparency(self, transparency: float) -> None:
     """ Set transparency as float value between 0 and 1, 0 is opaque and 1
     is 100% transparent (invisible).
     """
     self.dxf.set('transparency', clr.float2transparency(transparency))
Ejemplo n.º 5
0
 def test_transparency_descriptor_exists(self, entities: EntityQuery):
     assert (len(entities.transparency == colors.float2transparency(0)) == 0
             ), "has no default value"
Ejemplo n.º 6
0
def test_float_to_transparency(t_int, t_float):
    assert colors.float2transparency(t_float) == t_int