Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
uPesy authored Oct 13, 2023
2 parents f401e77 + 2778d44 commit 21457e2
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
python-version: "3.8"
cache: "pip"
- uses: pre-commit/[email protected]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# easyeda2kicad v0.6.3
# easyeda2kicad v0.6.5

_________________
[![PyPI version](https://badge.fury.io/py/easyeda2kicad.svg)](https://badge.fury.io/py/easyeda2kicad)
Expand Down
2 changes: 1 addition & 1 deletion easyeda2kicad/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.6.3"
__version__ = "0.6.5"
__author__ = "uPesy"
__email__ = "[email protected]"
2 changes: 1 addition & 1 deletion easyeda2kicad/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def valid_arguments(arguments: dict) -> bool:
"easyeda2kicad",
)
if not os.path.isdir(default_folder):
os.mkdir(default_folder)
os.makedirs(default_folder, exist_ok=True)

base_folder = default_folder
lib_name = "easyeda2kicad"
Expand Down
4 changes: 2 additions & 2 deletions easyeda2kicad/easyeda/easyeda_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def __init__(self, easyeda_cp_cad_data: dict):
self.output = self.extract_easyeda_data(
ee_data_str=self.input["packageDetail"]["dataStr"],
ee_data_info=self.input["packageDetail"]["dataStr"]["head"]["c_para"],
is_smd=self.input.get("SMT"),
is_smd=self.input.get("SMT")
and "-TH_" not in self.input["packageDetail"]["title"],
)

def get_footprint(self):
Expand All @@ -172,7 +173,6 @@ def extract_easyeda_data(
)

for line in ee_data_str["shape"]:

ee_designator = line.split("~")[0]
ee_fields = line.split("~")[1:]

Expand Down
104 changes: 68 additions & 36 deletions easyeda2kicad/easyeda/parameters_easyeda.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enum import Enum
from typing import List, Union

from pydantic import BaseModel, validator
from pydantic import BaseModel, field_validator

from easyeda2kicad.easyeda.svg_path_parser import parse_svg_path

Expand Down Expand Up @@ -33,19 +33,23 @@ class EeSymbolPinSettings(BaseModel):
id: str
is_locked: bool

@validator("is_displayed", pre=True)
@field_validator("is_displayed", mode="before")
@classmethod
def parse_display_field(cls, field: str) -> bool:
return True if field == "show" else field

@validator("is_locked", pre=True)
@field_validator("is_locked", mode="before")
@classmethod
def empty_str_lock(cls, is_locked: str) -> str:
return is_locked or False

@validator("rotation", pre=True)
@field_validator("rotation", mode="before")
@classmethod
def empty_str_rotation(cls, rotation: str) -> str:
return rotation or 0.0

@validator("type", pre=True)
@field_validator("type", mode="before")
@classmethod
def convert_pin_type(cls, field: str) -> str:
return (
EasyedaPinType(int(field or 0))
Expand All @@ -63,7 +67,8 @@ class EeSymbolPinPath(BaseModel):
path: str
color: str

@validator("path", pre=True)
@field_validator("path", mode="before")
@classmethod
def tune_path(cls, field: str) -> str:
return field.replace("v", "h")

Expand All @@ -78,17 +83,20 @@ class EeSymbolPinName(BaseModel):
font: str
font_size: float

@validator("font_size", pre=True)
@field_validator("font_size", mode="before")
@classmethod
def empty_str_font(cls, font_size: str) -> float:
if isinstance(font_size, str) and "pt" in font_size:
return float(font_size.replace("pt", ""))
return font_size or 7.0

@validator("is_displayed", pre=True)
@field_validator("is_displayed", mode="before")
@classmethod
def parse_display_field(cls, field: str) -> str:
return True if field == "show" else field

@validator("rotation", pre=True)
@field_validator("rotation", mode="before")
@classmethod
def empty_str_rotation(cls, rotation: str) -> str:
return rotation or 0.0

Expand All @@ -98,7 +106,8 @@ class EeSymbolPinDotBis(BaseModel):
circle_x: float
circle_y: float

@validator("is_displayed", pre=True)
@field_validator("is_displayed", mode="before")
@classmethod
def parse_display_field(cls, field: str) -> str:
return True if field == "show" else field

Expand All @@ -107,7 +116,8 @@ class EeSymbolPinClock(BaseModel):
is_displayed: bool
path: str

@validator("is_displayed", pre=True)
@field_validator("is_displayed", mode="before")
@classmethod
def parse_display_field(cls, field: str) -> str:
return True if field == "show" else field

Expand All @@ -126,8 +136,8 @@ class EeSymbolPin:
class EeSymbolRectangle(BaseModel):
pos_x: float
pos_y: float
rx: Union[float, None]
ry: Union[float, None]
rx: Union[float, None] = None
ry: Union[float, None] = None
width: float
height: float
stroke_color: str
Expand All @@ -137,7 +147,8 @@ class EeSymbolRectangle(BaseModel):
id: str
is_locked: bool

@validator("*", pre=True)
@field_validator("*", mode="before")
@classmethod
def empty_str_to_none(cls, field: str) -> str:
return field or None

Expand All @@ -154,11 +165,13 @@ class EeSymbolCircle(BaseModel):
id: str
is_locked: bool

@validator("is_locked", pre=True)
@field_validator("is_locked", mode="before")
@classmethod
def empty_str_lock(cls, field: str) -> str:
return field or False

@validator("fill_color", pre=True)
@field_validator("fill_color", mode="before")
@classmethod
def parse_background_filling(cls, fill_color: str) -> str:
return bool(fill_color and fill_color.lower() != "none")

Expand All @@ -174,15 +187,18 @@ class EeSymbolArc(BaseModel):
id: str
is_locked: bool

@validator("is_locked", pre=True)
@field_validator("is_locked", mode="before")
@classmethod
def empty_str_lock(cls, field: str) -> str:
return field or False

@validator("fill_color", pre=True)
@field_validator("fill_color", mode="before")
@classmethod
def parse_background_filling(cls, fill_color: str) -> str:
return bool(fill_color and fill_color.lower() != "none")

@validator("path", pre=True)
@field_validator("path", mode="before")
@classmethod
def convert_svg_path(cls, path: str) -> list:
return parse_svg_path(svg_path=path)

Expand All @@ -199,11 +215,13 @@ class EeSymbolEllipse(BaseModel):
id: str
is_locked: bool

@validator("is_locked", pre=True)
@field_validator("is_locked", mode="before")
@classmethod
def empty_str_lock(cls, field: str) -> str:
return field or False

@validator("fill_color", pre=True)
@field_validator("fill_color", mode="before")
@classmethod
def parse_background_filling(cls, fill_color: str) -> str:
return bool(fill_color and fill_color.lower() != "none")

Expand All @@ -218,11 +236,13 @@ class EeSymbolPolyline(BaseModel):
id: str
is_locked: bool

@validator("is_locked", pre=True)
@field_validator("is_locked", mode="before")
@classmethod
def empty_str_lock(cls, field: str) -> str:
return field or False

@validator("fill_color", pre=True)
@field_validator("fill_color", mode="before")
@classmethod
def parse_background_filling(cls, fill_color: str) -> str:
return bool(fill_color and fill_color.lower() != "none")

Expand All @@ -245,11 +265,13 @@ class EeSymbolPath(BaseModel):
id: str
is_locked: bool

@validator("is_locked", pre=True)
@field_validator("is_locked", mode="before")
@classmethod
def empty_str_lock(cls, field: str) -> str:
return field or False

@validator("fill_color", pre=True)
@field_validator("fill_color", mode="before")
@classmethod
def parse_background_filling(cls, fill_color: str) -> str:
return bool(fill_color and fill_color.lower() != "none")

Expand Down Expand Up @@ -328,11 +350,13 @@ def convert_to_mm(self) -> None:
self.hole_radius = convert_to_mm(self.hole_radius)
self.hole_length = convert_to_mm(self.hole_length)

@validator("is_locked", pre=True)
@field_validator("is_locked", mode="before")
@classmethod
def empty_str_lock(cls, field: str) -> str:
return field or False

@validator("rotation", pre=True)
@field_validator("rotation", mode="before")
@classmethod
def empty_str_rotation(cls, field: str) -> str:
return field or 0.0

Expand All @@ -345,7 +369,8 @@ class EeFootprintTrack(BaseModel):
id: str
is_locked: bool

@validator("is_locked", pre=True)
@field_validator("is_locked", mode="before")
@classmethod
def empty_str_lock(cls, field: str) -> str:
return field or False

Expand All @@ -360,7 +385,8 @@ class EeFootprintHole(BaseModel):
id: str
is_locked: bool

@validator("is_locked", pre=True)
@field_validator("is_locked", mode="before")
@classmethod
def empty_str_lock(cls, field: str) -> str:
return field or False

Expand All @@ -379,7 +405,8 @@ class EeFootprintCircle(BaseModel):
id: str
is_locked: bool

@validator("is_locked", pre=True)
@field_validator("is_locked", mode="before")
@classmethod
def empty_str_lock(cls, field: str) -> str:
return field or False

Expand All @@ -400,9 +427,10 @@ class EeFootprintRectangle(BaseModel):
layer_id: int
is_locked: bool

@validator("is_locked", pre=True)
@field_validator("is_locked", mode="before")
@classmethod
def empty_str_lock(cls, field):
return False if field == "" else field
return False if field == "" else bool(float(field))

def convert_to_mm(self):
self.x = convert_to_mm(self.x)
Expand All @@ -420,7 +448,8 @@ class EeFootprintArc(BaseModel):
id: str
is_locked: bool

@validator("is_locked", pre=True)
@field_validator("is_locked", mode="before")
@classmethod
def empty_str_lock(cls, field):
return False if field == "" else field

Expand All @@ -441,15 +470,18 @@ class EeFootprintText(BaseModel):
id: str
is_locked: bool

@validator("is_displayed", pre=True)
@field_validator("is_displayed", mode="before")
@classmethod
def empty_str_display(cls, field):
return True if field == "" else field

@validator("is_locked", pre=True)
@field_validator("is_locked", mode="before")
@classmethod
def empty_str_lock(cls, field):
return False if field == "" else field

@validator("rotation", pre=True)
@field_validator("rotation", mode="before")
@classmethod
def empty_str_rotation(cls, field):
return 0.0 if field == "" else field

Expand Down
Loading

0 comments on commit 21457e2

Please sign in to comment.