def set_gradient( self, color1: RGB = (0, 0, 0), color2: RGB = (255, 255, 255), rotation: float = 0.0, centered: float = 0.0, one_color: int = 0, tint: float = 0.0, name: str = "LINEAR", ) -> None: """Set :class:`Hatch` and :class:`MPolygon` to gradient fill mode and removes all pattern fill related data. Gradient support requires DXF R2004+. A gradient filled hatch is also a solid filled hatch. Valid gradient type names are: - ``'LINEAR'`` - ``'CYLINDER'`` - ``'INVCYLINDER'`` - ``'SPHERICAL'`` - ``'INVSPHERICAL'`` - ``'HEMISPHERICAL'`` - ``'INVHEMISPHERICAL'`` - ``'CURVED'`` - ``'INVCURVED'`` Args: color1: (r, g, b)-tuple for first color, rgb values as int in the range [0, 255] color2: (r, g, b)-tuple for second color, rgb values as int in the range [0, 255] rotation: rotation angle in degrees centered: determines whether the gradient is centered or not one_color: 1 for gradient from `color1` to tinted `color1` tint: determines the tinted target `color1` for a one color gradient. (valid range 0.0 to 1.0) name: name of gradient type, default "LINEAR" """ if self.doc is not None and self.doc.dxfversion < const.DXF2004: raise const.DXFVersionError("Gradient support requires DXF R2004") if name and name not in const.GRADIENT_TYPES: raise const.DXFValueError(f"Invalid gradient type name: {name}") self.pattern = None self.dxf.solid_fill = 1 self.dxf.pattern_name = "SOLID" self.dxf.pattern_type = const.HATCH_TYPE_PREDEFINED gradient = Gradient() gradient.color1 = color1 gradient.color2 = color2 gradient.one_color = one_color gradient.rotation = rotation gradient.centered = centered gradient.tint = tint gradient.name = name self.gradient = gradient
def __init__(self, dxfversion=DXF2013): self.entitydb = EntityDB() target_dxfversion = dxfversion.upper() self._dxfversion: str = const.acad_release_to_dxf_version.get( target_dxfversion, target_dxfversion) if self._dxfversion not in const.versions_supported_by_new: raise const.DXFVersionError( f'Unsupported DXF version "{self.dxfversion}".') # Store original dxf version if loaded (and maybe converted R13/14) # from file. self._loaded_dxfversion: Optional[str] = None # Status flag which is True while loading content from a DXF file: self.is_loading = False self.encoding: str = "cp1252" # read/write self.filename: Optional[str] = None # Reason for using "type: ignore". # I won't use "Optional" for the following attributes because these # objects are required, just not yet! Setting up an empty DXF Document # is not necessary if the document is read from the file system, # see class-methods new() and read(). # named objects dictionary self.rootdict: "Dictionary" = None # type: ignore # DXF sections self.header: HeaderSection = None # type: ignore self.classes: ClassesSection = None # type: ignore self.tables: TablesSection = None # type: ignore self.blocks: BlocksSection = None # type: ignore self.entities: EntitySection = None # type: ignore self.objects: ObjectsSection = None # type: ignore # DXF R2013 and later self.acdsdata: AcDsDataSection = None # type: ignore self.stored_sections: List[StoredSection] = [] self.layouts: Layouts = None # type: ignore self.groups: GroupCollection = None # type: ignore self.materials: MaterialCollection = None # type: ignore self.mleader_styles: MLeaderStyleCollection = None # type: ignore self.mline_styles: MLineStyleCollection = None # type: ignore # Set to False if the generated DXF file will be incompatible to AutoCAD self._acad_compatible = True # Store reasons for AutoCAD incompatibility: self._acad_incompatibility_reason = set() # DIMENSION rendering engine can be replaced by a custom Dimension # render: see property Drawing.dimension_renderer self._dimension_renderer = DimensionRenderer() # Some fixes can't be applied while the DXF document is not fully # initialized, store this fixes as callable object: self._post_init_commands: List[Callable] = [] # Don't create any new entities here: # New created handles could collide with handles loaded from DXF file. assert len(self.entitydb) == 0
def set_gradient(self, color1: 'RGB' = (0, 0, 0), color2: 'RGB' = (255, 255, 255), rotation: float = 0., centered: float = 0., one_color: int = 0, tint: float = 0., name: str = 'LINEAR') -> None: """ Set :class:`Hatch` to gradient fill mode and removes all pattern fill related data. Gradient support requires DXF DXF R2004. A gradient filled hatch is also a solid filled hatch. Valid gradient type names are: - ``'LINEAR'`` - ``'CYLINDER'`` - ``'INVCYLINDER'`` - ``'SPHERICAL'`` - ``'INVSPHERICAL'`` - ``'HEMISPHERICAL'`` - ``'INVHEMISPHERICAL'`` - ``'CURVED'`` - ``'INVCURVED'`` Args: color1: ``(r, g, b)`` tuple for first color, rgb values as int in range 0..255 color2: ``(r, g, b)`` tuple for second color, rgb values as int in range 0..255 rotation: rotation in degrees centered: determines whether the gradient is centered or not one_color: ``1`` for gradient from `color1` to tinted `color1`` tint: determines the tinted target `color1` for a one color gradient. (valid range ``0.0`` to ``1.0``) name: name of gradient type, default ``'LINEAR'`` """ if self.doc is not None and self.drawing.dxfversion < DXF2004: raise const.DXFVersionError("Gradient support requires DXF R2004") if name not in const.GRADIENT_TYPES: raise const.DXFValueError('Invalid gradient type name: %s' % name) self.pattern = None self.dxf.solid_fill = 1 self.dxf.pattern_name = 'SOLID' self.dxf.pattern_type = const.HATCH_TYPE_PREDEFINED gradient = Gradient() gradient.color1 = color1 gradient.color2 = color2 gradient.one_color = one_color gradient.rotation = rotation gradient.centered = centered gradient.tint = tint gradient.name = name self.gradient = gradient
def _validate_dxf_version(self, version: str) -> str: version = version.upper() # translates 'R12' -> 'AC1009' version = const.acad_release_to_dxf_version.get(version, version) if version not in const.versions_supported_by_save: raise const.DXFVersionError(f'Unsupported DXF version "{version}".') if version == DXF12: if self._dxfversion > DXF12: logger.warning( f'Downgrade from DXF {self.acad_release} to R12 may create ' f'an invalid DXF file.') elif version < self._dxfversion: logger.info( f'Downgrade from DXF {self.acad_release} to ' f'{const.acad_release[version]} can cause lost of features.') return version