physicsLab 1.4.8__tar.gz → 1.4.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {physicslab-1.4.8 → physicslab-1.4.10}/PKG-INFO +2 -1
- {physicslab-1.4.8 → physicslab-1.4.10}/README.md +6 -2
- physicslab-1.4.10/physicsLab/__init__.py +47 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/circuit/elementXYZ.py +6 -6
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/circuit/elements/_elementBase.py +7 -5
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/circuit/elements/artificialCircuit.py +5 -5
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/circuit/elements/basicCircuit.py +3 -3
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/circuit/elements/logicCircuit.py +77 -55
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/circuit/elements/otherCircuit.py +39 -38
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/circuit/wire.py +5 -5
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/electromagnetism/elements.py +2 -2
- physicslab-1.4.10/physicsLab/enums.py +52 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/errors.py +33 -3
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/experiment.py +104 -67
- physicslab-1.4.10/physicsLab/lib/__init__.py +5 -0
- physicslab-1.4.10/physicsLab/lib/edge_trigger.py +72 -0
- physicslab-1.4.10/physicsLab/lib/simple_logic.py +643 -0
- physicslab-1.4.10/physicsLab/lib/wires.py +64 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/music/music.py +193 -127
- physicslab-1.4.10/physicsLab/plAR.py +32 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/savTemplate.py +1 -2
- physicslab-1.4.10/physicsLab/web.py +195 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab.egg-info/PKG-INFO +2 -1
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab.egg-info/SOURCES.txt +8 -4
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab.egg-info/requires.txt +1 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/setup.py +2 -2
- physicslab-1.4.10/test/test_physicsLab.py +348 -0
- physicslab-1.4.10/test/test_pl_web.py +19 -0
- physicslab-1.4.8/physicsLab/__init__.py +0 -103
- physicslab-1.4.8/physicsLab/experimentType.py +0 -12
- physicslab-1.4.8/physicsLab/lib/__init__.py +0 -4
- physicslab-1.4.8/physicsLab/lib/_unionClassHead.py +0 -66
- physicslab-1.4.8/physicsLab/lib/logic.py +0 -557
- physicslab-1.4.8/physicsLab/lib/wires.py +0 -62
- {physicslab-1.4.8 → physicslab-1.4.10}/LICENSE +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/_colorUtils.py +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/_tools.py +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/celestial/__init__.py +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/celestial/elementsClass.py +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/circuit/__init__.py +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/circuit/elements/__init__.py +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/electromagnetism/__init__.py +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/element.py +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/elementBase.py +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/music/__init__.py +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab/typehint.py +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab.egg-info/dependency_links.txt +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/physicsLab.egg-info/top_level.txt +0 -0
- {physicslab-1.4.8 → physicslab-1.4.10}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: physicsLab
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.10
|
|
4
4
|
Summary: Python API for Physics-Lab-AR
|
|
5
5
|
Home-page: https://gitee.com/script2000/physicsLab
|
|
6
6
|
Author: Goodenough
|
|
@@ -15,5 +15,6 @@ Description-Content-Type: text/markdown
|
|
|
15
15
|
License-File: LICENSE
|
|
16
16
|
Requires-Dist: mido
|
|
17
17
|
Requires-Dist: typing-extensions
|
|
18
|
+
Requires-Dist: requests
|
|
18
19
|
|
|
19
20
|
click "[there](https://gitee.com/script2000/physicsLab)" to show more information
|
|
@@ -4,8 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](https://github.com/GoodenoughPhysicsLab/physicsLab/actions)
|
|
9
|
+

|
|
10
|
+
|
|
7
11
|
## Introduction
|
|
8
|
-
|
|
12
|
+
In physics laboratories, we often struggle with organizing components, repeatedly setting up circuits for testing, and the inconvenience of components not being able to float. These issues can be easily addressed by modifying save files! However, manual modification of save files is cumbersome and prone to errors. That's why I created `physicsLab`, a package that encapsulates commonly used functionalities, allowing you to easily conduct experiments in the physics lab using Python, **without even knowing where the save files are stored on your computer!**
|
|
9
13
|
|
|
10
14
|
## Installation Tutorial
|
|
11
15
|
1. Please ensure that your computer has [Python](https://www.python.org) (greater than or equal to 3.6) and [Physics Laboratory PC Version](https://www.turtlesim.com) (You can also contact developer [Jone Chen](https://gitee.com/civitasjohn))
|
|
@@ -13,7 +17,7 @@ When conducting experiments in the physics laboratory, we may be troubled by iss
|
|
|
13
17
|
```
|
|
14
18
|
pip install physicsLab
|
|
15
19
|
```
|
|
16
|
-
If you can
|
|
20
|
+
If you can't wait to use some new features, the beta version can usually be found on Gitee
|
|
17
21
|
|
|
18
22
|
## Development environment
|
|
19
23
|
Python 3.7.8, win7
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import os
|
|
3
|
+
import platform
|
|
4
|
+
|
|
5
|
+
# 颜色打印
|
|
6
|
+
from ._colorUtils import close_color_print
|
|
7
|
+
# 操作实验
|
|
8
|
+
from .experiment import Experiment, experiment, search_Experiment, get_Experiment
|
|
9
|
+
# 实验, 标签类型
|
|
10
|
+
from .enums import *
|
|
11
|
+
# 电学实验
|
|
12
|
+
from .circuit import *
|
|
13
|
+
# 天体物理实验
|
|
14
|
+
from .celestial import *
|
|
15
|
+
# 电与磁实验
|
|
16
|
+
from .electromagnetism import *
|
|
17
|
+
# 操作元件
|
|
18
|
+
from .element import crt_Element, del_Element, count_Elements, get_Element, clear_Elements
|
|
19
|
+
# `physicsLab`自定义异常类
|
|
20
|
+
from .errors import *
|
|
21
|
+
|
|
22
|
+
from .lib.wires import crt_Wires, del_Wires
|
|
23
|
+
|
|
24
|
+
from physicsLab.plAR import *
|
|
25
|
+
|
|
26
|
+
from physicsLab.web import *
|
|
27
|
+
|
|
28
|
+
from physicsLab import lib
|
|
29
|
+
from physicsLab import music
|
|
30
|
+
|
|
31
|
+
# 检测操作系统
|
|
32
|
+
# Win: 若存档对应文件夹不存在直接报错
|
|
33
|
+
if platform.system() == "Windows":
|
|
34
|
+
if not os.path.exists(Experiment.FILE_HEAD):
|
|
35
|
+
raise RuntimeError("The folder does not exist, try launching Physics-Lab-AR and try it out")
|
|
36
|
+
else:
|
|
37
|
+
if not os.path.exists(Experiment.FILE_HEAD):
|
|
38
|
+
os.mkdir(Experiment.FILE_HEAD)
|
|
39
|
+
|
|
40
|
+
plAR_version = get_plAR_version()
|
|
41
|
+
if plAR_version is not None:
|
|
42
|
+
_, mid, small = eval(f"({plAR_version.replace('.', ',')})")
|
|
43
|
+
if mid < 4 or mid == 4 and small < 7:
|
|
44
|
+
warning("the version of Physics-Lab-AR is less than v2.4.7")
|
|
45
|
+
|
|
46
|
+
del os
|
|
47
|
+
del platform
|
|
@@ -8,11 +8,11 @@ from physicsLab import errors
|
|
|
8
8
|
from physicsLab._tools import position
|
|
9
9
|
from physicsLab.typehint import numType
|
|
10
10
|
from physicsLab.experiment import get_Experiment
|
|
11
|
-
from physicsLab.
|
|
11
|
+
from physicsLab.enums import ExperimentType
|
|
12
12
|
|
|
13
13
|
# 是否将全局设置为元件坐标系
|
|
14
14
|
def set_elementXYZ(boolen: bool) -> None:
|
|
15
|
-
if get_Experiment().
|
|
15
|
+
if get_Experiment().experiment_type != ExperimentType.Circuit:
|
|
16
16
|
raise errors.ExperimentTypeError
|
|
17
17
|
if not isinstance(boolen, bool):
|
|
18
18
|
raise TypeError
|
|
@@ -31,8 +31,8 @@ _Z_UNIT: float = 0.1
|
|
|
31
31
|
_Y_AMEND = 0.045
|
|
32
32
|
|
|
33
33
|
def xyzTranslate(x: numType, y: numType, z: numType, is_bigElement: bool = False):
|
|
34
|
-
'''
|
|
35
|
-
if get_Experiment().
|
|
34
|
+
''' 将元件坐标系转换为物实的坐标系 '''
|
|
35
|
+
if get_Experiment().experiment_type != ExperimentType.Circuit:
|
|
36
36
|
raise errors.ExperimentTypeError
|
|
37
37
|
|
|
38
38
|
_xOrigin, _yOrigin, _zOrigin = get_OriginPosition()
|
|
@@ -49,8 +49,8 @@ def xyzTranslate(x: numType, y: numType, z: numType, is_bigElement: bool = False
|
|
|
49
49
|
return x, y, z
|
|
50
50
|
|
|
51
51
|
def translateXYZ(x: numType, y: numType, z: numType, is_bigElement: bool = False):
|
|
52
|
-
'''
|
|
53
|
-
if get_Experiment().
|
|
52
|
+
''' 将物实的坐标系转换为元件坐标系 '''
|
|
53
|
+
if get_Experiment().experiment_type != ExperimentType.Circuit:
|
|
54
54
|
raise errors.ExperimentTypeError
|
|
55
55
|
|
|
56
56
|
_xOrigin, _yOrigin, _zOrigin = get_OriginPosition()
|
|
@@ -7,7 +7,7 @@ from physicsLab.circuit import wire
|
|
|
7
7
|
from physicsLab.elementBase import ElementBase
|
|
8
8
|
import physicsLab.circuit.elementXYZ as _elementXYZ
|
|
9
9
|
|
|
10
|
-
from physicsLab.
|
|
10
|
+
from physicsLab.enums import ExperimentType
|
|
11
11
|
from physicsLab.typehint import Optional, Self, numType
|
|
12
12
|
from physicsLab._tools import roundData, randString
|
|
13
13
|
from physicsLab.experiment import Experiment, stack_Experiment
|
|
@@ -25,13 +25,15 @@ class CircuitMeta(type):
|
|
|
25
25
|
if not (
|
|
26
26
|
isinstance(x, (float, int)) and
|
|
27
27
|
isinstance(y, (float, int)) and
|
|
28
|
-
isinstance(z, (float, int))
|
|
28
|
+
isinstance(z, (float, int)) and
|
|
29
|
+
(elementXYZ is None or isinstance(elementXYZ, bool))
|
|
29
30
|
):
|
|
30
|
-
raise TypeError
|
|
31
|
+
raise TypeError
|
|
32
|
+
|
|
31
33
|
_Expe: Experiment = stack_Experiment.top()
|
|
32
34
|
self.experiment = _Expe
|
|
33
35
|
|
|
34
|
-
if _Expe.
|
|
36
|
+
if _Expe.experiment_type != ExperimentType.Circuit:
|
|
35
37
|
raise errors.ExperimentTypeError
|
|
36
38
|
|
|
37
39
|
self.is_elementXYZ = False # 元件坐标系
|
|
@@ -71,8 +73,8 @@ class CircuitBase(ElementBase, metaclass=CircuitMeta):
|
|
|
71
73
|
return f"{self.__class__.__name__}" \
|
|
72
74
|
f"({self._position.x}, {self._position.y}, {self._position.z}, {self.is_elementXYZ})"
|
|
73
75
|
|
|
74
|
-
# 设置原件的角度
|
|
75
76
|
def set_Rotation(self, xRotation: numType = 0, yRotation: numType = 0, zRotation: numType = 180) -> Self:
|
|
77
|
+
''' 设置原件的角度 '''
|
|
76
78
|
if not (
|
|
77
79
|
isinstance(xRotation, (int, float)) and
|
|
78
80
|
isinstance(yRotation, (int, float)) and
|
|
@@ -380,29 +380,29 @@ class _source_electricity(TwoPinMixIn):
|
|
|
380
380
|
# 正弦波发生器
|
|
381
381
|
class Sinewave_Source(_source_electricity):
|
|
382
382
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
383
|
-
super(
|
|
383
|
+
super().__init__(x, y, z, elementXYZ)
|
|
384
384
|
self._arguments["ModelID"] = "Sinewave Source"
|
|
385
385
|
|
|
386
386
|
# 方波发生器
|
|
387
387
|
class Square_Source(_source_electricity):
|
|
388
388
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
389
|
-
super(
|
|
389
|
+
super().__init__(x, y, z, elementXYZ)
|
|
390
390
|
self._arguments["ModelID"] = "Square Source"
|
|
391
391
|
|
|
392
392
|
# 三角波发生器
|
|
393
393
|
class Triangle_Source(_source_electricity):
|
|
394
394
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
395
|
-
super(
|
|
395
|
+
super().__init__(x, y, z, elementXYZ)
|
|
396
396
|
self._arguments["ModelID"] = "Triangle Source"
|
|
397
397
|
|
|
398
398
|
# 锯齿波发生器
|
|
399
399
|
class Sawtooth_Source(_source_electricity):
|
|
400
400
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
401
|
-
super(
|
|
401
|
+
super().__init__(x, y, z, elementXYZ)
|
|
402
402
|
self._arguments["ModelID"] = "Sawtooth Source"
|
|
403
403
|
|
|
404
404
|
# 尖峰波发生器
|
|
405
405
|
class Pulse_Source(_source_electricity):
|
|
406
406
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
407
|
-
super(
|
|
407
|
+
super().__init__(x, y, z, elementXYZ)
|
|
408
408
|
self._arguments["ModelID"] = "Pulse Source"
|
|
@@ -23,7 +23,7 @@ class _switch_Base(CircuitBase):
|
|
|
23
23
|
# 简单开关
|
|
24
24
|
class Simple_Switch(_switch_Base, TwoPinMixIn):
|
|
25
25
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
26
|
-
super(
|
|
26
|
+
super().__init__(x, y, z, elementXYZ)
|
|
27
27
|
self._arguments["ModelID"] = "Simple Switch"
|
|
28
28
|
|
|
29
29
|
def __repr__(self) -> str:
|
|
@@ -42,7 +42,7 @@ class Simple_Switch(_switch_Base, TwoPinMixIn):
|
|
|
42
42
|
# 单刀双掷开关
|
|
43
43
|
class SPDT_Switch(_switch_Base):
|
|
44
44
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
45
|
-
super(
|
|
45
|
+
super().__init__(x, y, z, elementXYZ)
|
|
46
46
|
self._arguments["ModelID"] = "SPDT Switch"
|
|
47
47
|
|
|
48
48
|
def __repr__(self) -> str:
|
|
@@ -80,7 +80,7 @@ class SPDT_Switch(_switch_Base):
|
|
|
80
80
|
# 双刀双掷开关
|
|
81
81
|
class DPDT_Switch(_switch_Base):
|
|
82
82
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
83
|
-
super(
|
|
83
|
+
super().__init__(x, y, z, elementXYZ)
|
|
84
84
|
self._arguments["ModelID"] = "DPDT Switch"
|
|
85
85
|
|
|
86
86
|
def __repr__(self) -> str:
|
|
@@ -6,36 +6,36 @@ from physicsLab.savTemplate import Generate
|
|
|
6
6
|
from physicsLab.typehint import Optional, Self
|
|
7
7
|
|
|
8
8
|
class _logicBase(CircuitBase):
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
def set_HighLevelValue(self, num: numType) -> Self:
|
|
10
|
+
''' 设置高电平的值 '''
|
|
11
11
|
if not isinstance(num, (int, float)):
|
|
12
12
|
raise TypeError("illegal argument")
|
|
13
|
-
if num < self.
|
|
13
|
+
if num < self.get_LowLevelValue():
|
|
14
14
|
raise TypeError("illegal range")
|
|
15
15
|
self._arguments["Properties"]["高电平"] = num # type: ignore -> subclass must has attr _arguments
|
|
16
16
|
|
|
17
17
|
return self
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
def get_HighLevelValue(self) -> numType:
|
|
20
|
+
''' 获取高电平的值 '''
|
|
21
21
|
return self._arguments["Properties"]["高电平"] # type: ignore -> subclass must has attr _arguments
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
def set_LowLevelValue(self, num: numType) -> Self:
|
|
24
|
+
''' 设置低电平的值 '''
|
|
25
25
|
if not isinstance(num, (int, float)):
|
|
26
26
|
raise TypeError("illegal argument")
|
|
27
|
-
if num > self.
|
|
27
|
+
if num > self.get_HighLevelValue():
|
|
28
28
|
raise TypeError("illegal range")
|
|
29
29
|
self._arguments["Properties"]["低电平"] = num # type: ignore -> subclass must has attr _arguments
|
|
30
30
|
|
|
31
31
|
return self
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
def get_LowLevelValue(self):
|
|
34
|
+
''' 获取低电平的值 '''
|
|
35
35
|
return self._arguments["Properties"]["低电平"] # type: ignore -> subclass must has attr _arguments
|
|
36
36
|
|
|
37
|
-
# 逻辑输入
|
|
38
37
|
class Logic_Input(_logicBase):
|
|
38
|
+
''' 逻辑输入 '''
|
|
39
39
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
40
40
|
self._arguments = {"ModelID": "Logic Input", "Identifier": Generate,
|
|
41
41
|
"IsBroken": False, "IsLocked": False,
|
|
@@ -53,8 +53,8 @@ class Logic_Input(_logicBase):
|
|
|
53
53
|
res += ".set_highLevel()"
|
|
54
54
|
return res
|
|
55
55
|
|
|
56
|
-
# 将逻辑输入的状态设置为1
|
|
57
56
|
def set_highLevel(self) -> "Logic_Input":
|
|
57
|
+
''' 将逻辑输入的状态设置为1 '''
|
|
58
58
|
self._arguments["Properties"]["开关"] = 1.0
|
|
59
59
|
return self
|
|
60
60
|
|
|
@@ -62,8 +62,8 @@ class Logic_Input(_logicBase):
|
|
|
62
62
|
def o(self) -> OutputPin:
|
|
63
63
|
return OutputPin(self, 0)
|
|
64
64
|
|
|
65
|
-
# 逻辑输出
|
|
66
65
|
class Logic_Output(_logicBase):
|
|
66
|
+
''' 逻辑输出 '''
|
|
67
67
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
68
68
|
self._arguments = {"ModelID": "Logic Output", "Identifier": Generate,
|
|
69
69
|
"IsBroken": False, "IsLocked": False,
|
|
@@ -76,8 +76,8 @@ class Logic_Output(_logicBase):
|
|
|
76
76
|
def i(self) -> InputPin:
|
|
77
77
|
return InputPin(self, 0)
|
|
78
78
|
|
|
79
|
-
# 2引脚门电路
|
|
80
79
|
class _2_pin_Gate(_logicBase):
|
|
80
|
+
''' 2引脚门电路基类 '''
|
|
81
81
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
82
82
|
self._arguments = {"ModelID": Generate, "Identifier": Generate, "IsBroken": False, "IsLocked": False,
|
|
83
83
|
"Properties": {"高电平": 3.0, "低电平": 0.0, "最大电流": 0.1, "锁定": 1.0},
|
|
@@ -93,20 +93,20 @@ class _2_pin_Gate(_logicBase):
|
|
|
93
93
|
def o(self) -> OutputPin:
|
|
94
94
|
return OutputPin(self, 1)
|
|
95
95
|
|
|
96
|
-
# 是门
|
|
97
96
|
class Yes_Gate(_2_pin_Gate):
|
|
97
|
+
''' 是门 '''
|
|
98
98
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
99
|
-
super(
|
|
99
|
+
super().__init__(x, y, z, elementXYZ)
|
|
100
100
|
self._arguments["ModelID"] = "Yes Gate"
|
|
101
101
|
|
|
102
|
-
# 非门
|
|
103
102
|
class No_Gate(_2_pin_Gate):
|
|
103
|
+
''' 非门 '''
|
|
104
104
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
105
|
-
super(
|
|
105
|
+
super().__init__(x, y, z, elementXYZ)
|
|
106
106
|
self._arguments["ModelID"] = "No Gate"
|
|
107
107
|
|
|
108
|
-
# 3引脚门电路
|
|
109
108
|
class _3_pin_Gate(_logicBase):
|
|
109
|
+
''' 3引脚门电路基类 '''
|
|
110
110
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
111
111
|
self._arguments = {"ModelID": "", "Identifier": Generate, "IsBroken": False, "IsLocked": False,
|
|
112
112
|
"Properties": {"高电平": 3.0, "低电平": 0.0, "最大电流": 0.1, "锁定": 1.0},
|
|
@@ -126,56 +126,56 @@ class _3_pin_Gate(_logicBase):
|
|
|
126
126
|
def o(self) -> OutputPin:
|
|
127
127
|
return OutputPin(self, 2)
|
|
128
128
|
|
|
129
|
-
# 或门
|
|
130
129
|
class Or_Gate(_3_pin_Gate):
|
|
130
|
+
''' 或门 '''
|
|
131
131
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
132
|
-
super(
|
|
132
|
+
super().__init__(x, y, z, elementXYZ)
|
|
133
133
|
self._arguments["ModelID"] = "Or Gate"
|
|
134
134
|
|
|
135
|
-
# 与门
|
|
136
135
|
class And_Gate(_3_pin_Gate):
|
|
136
|
+
''' 与门 '''
|
|
137
137
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
138
|
-
super(
|
|
138
|
+
super().__init__(x, y, z, elementXYZ)
|
|
139
139
|
self._arguments["ModelID"] = "And Gate"
|
|
140
140
|
|
|
141
|
-
# 或非门
|
|
142
141
|
class Nor_Gate(_3_pin_Gate):
|
|
142
|
+
''' 或非门 '''
|
|
143
143
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
144
|
-
super(
|
|
144
|
+
super().__init__(x, y, z, elementXYZ)
|
|
145
145
|
self._arguments["ModelID"] = "Nor Gate"
|
|
146
146
|
|
|
147
|
-
# 与非门
|
|
148
147
|
class Nand_Gate(_3_pin_Gate):
|
|
148
|
+
''' 与非门 '''
|
|
149
149
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
150
|
-
super(
|
|
150
|
+
super().__init__(x, y, z, elementXYZ)
|
|
151
151
|
self._arguments["ModelID"] = "Nand Gate"
|
|
152
152
|
|
|
153
|
-
# 异或门
|
|
154
153
|
class Xor_Gate(_3_pin_Gate):
|
|
154
|
+
''' 异或门 '''
|
|
155
155
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
156
|
-
super(
|
|
156
|
+
super().__init__(x, y, z, elementXYZ)
|
|
157
157
|
self._arguments["ModelID"] = "Xor Gate"
|
|
158
158
|
|
|
159
|
-
# 同或门
|
|
160
159
|
class Xnor_Gate(_3_pin_Gate):
|
|
160
|
+
''' 同或门 '''
|
|
161
161
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
162
|
-
super(
|
|
162
|
+
super().__init__(x, y, z, elementXYZ)
|
|
163
163
|
self._arguments["ModelID"] = "Xnor Gate"
|
|
164
164
|
|
|
165
|
-
# 蕴含门
|
|
166
165
|
class Imp_Gate(_3_pin_Gate):
|
|
166
|
+
''' 蕴含门 '''
|
|
167
167
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
168
|
-
super(
|
|
168
|
+
super().__init__(x, y, z, elementXYZ)
|
|
169
169
|
self._arguments["ModelID"] = "Imp Gate"
|
|
170
170
|
|
|
171
|
-
# 蕴含非门
|
|
172
171
|
class Nimp_Gate(_3_pin_Gate):
|
|
172
|
+
''' 蕴含非门 '''
|
|
173
173
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
174
|
-
super(
|
|
174
|
+
super().__init__(x, y, z, elementXYZ)
|
|
175
175
|
self._arguments["ModelID"] = "Nimp Gate"
|
|
176
176
|
|
|
177
|
-
# 2体积元件父类
|
|
178
177
|
class _big_element(_logicBase):
|
|
178
|
+
''' 2体积元件父类 '''
|
|
179
179
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
180
180
|
self._arguments = {"ModelID": "", "Identifier": Generate, "IsBroken": False,
|
|
181
181
|
"IsLocked": False, "Properties": {"高电平": 3.0, "低电平": 0.0, "锁定": 1.0},
|
|
@@ -187,10 +187,10 @@ class _big_element(_logicBase):
|
|
|
187
187
|
def is_bigElement(self):
|
|
188
188
|
return True
|
|
189
189
|
|
|
190
|
-
# 半加器
|
|
191
190
|
class Half_Adder(_big_element):
|
|
191
|
+
''' 半加器 '''
|
|
192
192
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
193
|
-
super(
|
|
193
|
+
super().__init__(x, y, z, elementXYZ)
|
|
194
194
|
self._arguments["ModelID"] = "Half Adder"
|
|
195
195
|
|
|
196
196
|
@property
|
|
@@ -209,10 +209,10 @@ class Half_Adder(_big_element):
|
|
|
209
209
|
def o_low(self) -> OutputPin:
|
|
210
210
|
return OutputPin(self, 1)
|
|
211
211
|
|
|
212
|
-
# 全加器
|
|
213
212
|
class Full_Adder(_big_element):
|
|
213
|
+
''' 全加器 '''
|
|
214
214
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
215
|
-
super(
|
|
215
|
+
super().__init__(x, y, z, elementXYZ)
|
|
216
216
|
self._arguments["ModelID"] = "Full Adder"
|
|
217
217
|
|
|
218
218
|
@property
|
|
@@ -235,10 +235,10 @@ class Full_Adder(_big_element):
|
|
|
235
235
|
def o_low(self) -> OutputPin:
|
|
236
236
|
return OutputPin(self, 1)
|
|
237
237
|
|
|
238
|
-
# 二位乘法器
|
|
239
238
|
class Multiplier(_big_element):
|
|
239
|
+
''' 二位乘法器 '''
|
|
240
240
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
241
|
-
super(
|
|
241
|
+
super().__init__(x, y, z, elementXYZ)
|
|
242
242
|
self._arguments["ModelID"] = "Multiplier"
|
|
243
243
|
|
|
244
244
|
@property
|
|
@@ -273,10 +273,10 @@ class Multiplier(_big_element):
|
|
|
273
273
|
def o_low(self) -> OutputPin:
|
|
274
274
|
return OutputPin(self, 3)
|
|
275
275
|
|
|
276
|
-
# D触发器
|
|
277
276
|
class D_Flipflop(_big_element):
|
|
277
|
+
''' D触发器 '''
|
|
278
278
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
279
|
-
super(
|
|
279
|
+
super().__init__(x, y, z, elementXYZ)
|
|
280
280
|
self._arguments["ModelID"] = "D Flipflop"
|
|
281
281
|
|
|
282
282
|
@property
|
|
@@ -295,10 +295,10 @@ class D_Flipflop(_big_element):
|
|
|
295
295
|
def o_low(self) -> OutputPin:
|
|
296
296
|
return OutputPin(self, 1)
|
|
297
297
|
|
|
298
|
-
# T触发器
|
|
299
298
|
class T_Flipflop(_big_element):
|
|
299
|
+
''' T'触发器 '''
|
|
300
300
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
301
|
-
super(
|
|
301
|
+
super().__init__(x, y, z, elementXYZ)
|
|
302
302
|
self._arguments["ModelID"] = "T Flipflop"
|
|
303
303
|
|
|
304
304
|
@property
|
|
@@ -317,10 +317,32 @@ class T_Flipflop(_big_element):
|
|
|
317
317
|
def o_low(self) -> OutputPin:
|
|
318
318
|
return OutputPin(self, 1)
|
|
319
319
|
|
|
320
|
-
|
|
320
|
+
class Real_T_Flipflop(_big_element):
|
|
321
|
+
''' T触发器 '''
|
|
322
|
+
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
323
|
+
super().__init__(x, y, z, elementXYZ)
|
|
324
|
+
self._arguments["ModelID"] = "Real-T Flipflop"
|
|
325
|
+
|
|
326
|
+
@property
|
|
327
|
+
def i_up(self) -> InputPin:
|
|
328
|
+
return InputPin(self, 2)
|
|
329
|
+
|
|
330
|
+
@property
|
|
331
|
+
def i_low(self) -> InputPin:
|
|
332
|
+
return InputPin(self, 3)
|
|
333
|
+
|
|
334
|
+
@property
|
|
335
|
+
def o_up(self) -> OutputPin:
|
|
336
|
+
return OutputPin(self, 0)
|
|
337
|
+
|
|
338
|
+
@property
|
|
339
|
+
def o_low(self) -> OutputPin:
|
|
340
|
+
return OutputPin(self, 1)
|
|
341
|
+
|
|
321
342
|
class JK_Flipflop(_big_element):
|
|
343
|
+
''' JK触发器 '''
|
|
322
344
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
323
|
-
super(
|
|
345
|
+
super().__init__(x, y, z, elementXYZ)
|
|
324
346
|
self._arguments["ModelID"] = "JK Flipflop"
|
|
325
347
|
|
|
326
348
|
@property
|
|
@@ -343,10 +365,10 @@ class JK_Flipflop(_big_element):
|
|
|
343
365
|
def o_low(self) -> OutputPin:
|
|
344
366
|
return OutputPin(self, 1)
|
|
345
367
|
|
|
346
|
-
# 计数器
|
|
347
368
|
class Counter(_big_element):
|
|
369
|
+
''' 计数器 '''
|
|
348
370
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
349
|
-
super(
|
|
371
|
+
super().__init__(x, y, z, elementXYZ)
|
|
350
372
|
self._arguments["ModelID"] = "Counter"
|
|
351
373
|
|
|
352
374
|
@property
|
|
@@ -373,10 +395,10 @@ class Counter(_big_element):
|
|
|
373
395
|
def o_low(self) -> OutputPin:
|
|
374
396
|
return OutputPin(self, 3)
|
|
375
397
|
|
|
376
|
-
# 随机数发生器
|
|
377
398
|
class Random_Generator(_big_element):
|
|
399
|
+
''' 随机数发生器 '''
|
|
378
400
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
379
|
-
super(
|
|
401
|
+
super().__init__(x, y, z, elementXYZ)
|
|
380
402
|
self._arguments["ModelID"] = "Random Generator"
|
|
381
403
|
|
|
382
404
|
@property
|
|
@@ -403,8 +425,8 @@ class Random_Generator(_big_element):
|
|
|
403
425
|
def o_low(self) -> OutputPin:
|
|
404
426
|
return OutputPin(self, 3)
|
|
405
427
|
|
|
406
|
-
# 8位输入器
|
|
407
428
|
class eight_bit_Input(_logicBase):
|
|
429
|
+
''' 8位输入器 '''
|
|
408
430
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
409
431
|
self._arguments = {"ModelID": "8bit Input", "Identifier": Generate,
|
|
410
432
|
"IsBroken": False, "IsLocked": False,
|
|
@@ -463,8 +485,8 @@ class eight_bit_Input(_logicBase):
|
|
|
463
485
|
def o_low(self) -> OutputPin:
|
|
464
486
|
return OutputPin(self, 7)
|
|
465
487
|
|
|
466
|
-
# 8位显示器
|
|
467
488
|
class eight_bit_Display(_logicBase):
|
|
489
|
+
''' 8位显示器 '''
|
|
468
490
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
469
491
|
self._arguments = {"ModelID": "8bit Display", "Identifier": Generate,
|
|
470
492
|
"IsBroken": False, "IsLocked": False,
|
|
@@ -510,8 +532,8 @@ class eight_bit_Display(_logicBase):
|
|
|
510
532
|
def o_low(self) -> OutputPin:
|
|
511
533
|
return OutputPin(self, 7)
|
|
512
534
|
|
|
513
|
-
# 施密特触发器
|
|
514
535
|
class Schmitt_Trigger(CircuitBase):
|
|
536
|
+
''' 施密特触发器 '''
|
|
515
537
|
def __init__(self, x: numType = 0, y: numType = 0, z: numType = 0, elementXYZ: Optional[bool] = None):
|
|
516
538
|
self._arguments = {"ModelID": "Schmitt Trigger", "Identifier": Generate,
|
|
517
539
|
"IsBroken": False, "IsLocked": False,
|
|
@@ -268,52 +268,53 @@ class Simple_Instrument(TwoPinMixIn):
|
|
|
268
268
|
def get_instrument(self) -> int:
|
|
269
269
|
return self._arguments["Properties"]["乐器"]
|
|
270
270
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
"""
|
|
274
|
-
输入格式:
|
|
271
|
+
def set_Tonality(self, pitch: Union[int, str], rising_falling: Optional[bool] = None) -> "Simple_Instrument":
|
|
272
|
+
''' 输入格式:
|
|
275
273
|
tonality: C4, A5 ...
|
|
276
|
-
rising_falling = True
|
|
274
|
+
rising_falling = True 时, 为升调, 为 False 时降调
|
|
275
|
+
'''
|
|
277
276
|
|
|
278
|
-
输入范围:
|
|
279
|
-
C0 ~ C8
|
|
280
|
-
注: C0: 24, C1: 36, C2: 48, C3: 60, ..., C8: 120
|
|
281
|
-
"""
|
|
282
|
-
def majorSet_Tonality(self,
|
|
283
|
-
tonality: str = "C3",
|
|
284
|
-
rising_falling: Optional[bool] = None
|
|
285
|
-
) -> None:
|
|
286
|
-
if (not isinstance(tonality, str) or
|
|
287
|
-
len(tonality) != 2 or
|
|
288
|
-
tonality.upper()[0] not in "ABCDEFG" or
|
|
289
|
-
tonality[1] not in "012345678" or
|
|
290
|
-
not (isinstance(rising_falling, bool) or rising_falling is None)
|
|
291
|
-
):
|
|
292
|
-
raise TypeError
|
|
293
|
-
|
|
294
|
-
var = 1 if rising_falling is True else 0 if rising_falling is None else -1
|
|
295
|
-
|
|
296
|
-
pitch = {
|
|
297
|
-
'A': 22,
|
|
298
|
-
'B': 23,
|
|
299
|
-
'C': 24,
|
|
300
|
-
'D': 25,
|
|
301
|
-
'E': 26,
|
|
302
|
-
'F': 27,
|
|
303
|
-
'G': 28
|
|
304
|
-
}[tonality.upper()[0]] + 12 * int(tonality[1]) + var
|
|
305
|
-
|
|
306
|
-
self._arguments["Properties"]["音高"] = pitch
|
|
307
|
-
|
|
308
|
-
# main
|
|
309
277
|
if isinstance(pitch, int):
|
|
310
278
|
if 0 <= pitch < 128:
|
|
311
279
|
self._arguments["Properties"]["音高"] = pitch
|
|
312
280
|
else:
|
|
313
281
|
raise TypeError("Input number out of range")
|
|
314
282
|
elif isinstance(pitch, str):
|
|
315
|
-
majorSet_Tonality(
|
|
283
|
+
self._arguments["Properties"]["音高"] = majorSet_Tonality(pitch, rising_falling)
|
|
316
284
|
else:
|
|
317
285
|
raise TypeError
|
|
318
286
|
|
|
319
|
-
return self
|
|
287
|
+
return self
|
|
288
|
+
|
|
289
|
+
def majorSet_Tonality(pitch: str,
|
|
290
|
+
rising_falling: Optional[bool] = None
|
|
291
|
+
) -> int:
|
|
292
|
+
""" 输入格式:
|
|
293
|
+
tonality: C4, A5 ...
|
|
294
|
+
rising_falling = True 时,为升调,为 False 时降调
|
|
295
|
+
|
|
296
|
+
输入范围:
|
|
297
|
+
C0 ~ C8
|
|
298
|
+
注: C0: 24, C1: 36, C2: 48, C3: 60, ..., C8: 120
|
|
299
|
+
"""
|
|
300
|
+
if (not isinstance(pitch, str) or
|
|
301
|
+
len(pitch) != 2 or
|
|
302
|
+
pitch.upper()[0] not in "ABCDEFG" or
|
|
303
|
+
pitch[1] not in "012345678" or
|
|
304
|
+
not (isinstance(rising_falling, bool) or rising_falling is None)
|
|
305
|
+
):
|
|
306
|
+
raise TypeError
|
|
307
|
+
|
|
308
|
+
var = 1 if rising_falling is True else 0 if rising_falling is None else -1
|
|
309
|
+
|
|
310
|
+
pitch = {
|
|
311
|
+
'A': 22,
|
|
312
|
+
'B': 23,
|
|
313
|
+
'C': 24,
|
|
314
|
+
'D': 25,
|
|
315
|
+
'E': 26,
|
|
316
|
+
'F': 27,
|
|
317
|
+
'G': 28
|
|
318
|
+
}[pitch.upper()[0]] + 12 * int(pitch[1]) + var
|
|
319
|
+
|
|
320
|
+
return pitch
|