Browse Source

Convert doxygen to rst for Cura scripts

Nino van Hooff 4 years ago
parent
commit
fe779d9501
2 changed files with 71 additions and 42 deletions
  1. 38 23
      scripts/check_gcode_buffer.py
  2. 33 19
      scripts/lionbridge_import.py

+ 38 - 23
scripts/check_gcode_buffer.py

@@ -31,16 +31,19 @@ MACHINE_MAX_JERK_E = 5
 MACHINE_MINIMUM_FEEDRATE = 0.001
 MACHINE_ACCELERATION = 3000
 
-##  Gets the code and number from the given g-code line.
+
 def get_code_and_num(gcode_line: str) -> Tuple[str, str]:
+    """Gets the code and number from the given g-code line."""
+
     gcode_line = gcode_line.strip()
     cmd_code = gcode_line[0].upper()
     cmd_num = str(gcode_line[1:])
     return cmd_code, cmd_num
 
-##  Fetches arguments such as X1 Y2 Z3 from the given part list and returns a
-#   dict.
+
 def get_value_dict(parts: List[str]) -> Dict[str, str]:
+    """Fetches arguments such as X1 Y2 Z3 from the given part list and returns a dict"""
+
     value_dict = {}
     for p in parts:
         p = p.strip()
@@ -63,39 +66,49 @@ def calc_distance(pos1, pos2):
     distance = math.sqrt(distance)
     return distance
 
-##  Given the initial speed, the target speed, and the acceleration, calculate
-#   the distance that's neede for the acceleration to finish.
+
 def calc_acceleration_distance(init_speed: float, target_speed: float, acceleration: float) -> float:
+    """Given the initial speed, the target speed, and the acceleration
+
+    calculate the distance that's neede for the acceleration to finish.
+    """
     if acceleration == 0:
         return 0.0
     return (target_speed ** 2 - init_speed ** 2) / (2 * acceleration)
 
-##  Gives the time it needs to accelerate from an initial speed to reach a final
-#   distance.
+
 def calc_acceleration_time_from_distance(initial_feedrate: float, distance: float, acceleration: float) -> float:
+    """Gives the time it needs to accelerate from an initial speed to reach a final distance."""
+
     discriminant = initial_feedrate ** 2 - 2 * acceleration * -distance
     #If the discriminant is negative, we're moving in the wrong direction.
     #Making the discriminant 0 then gives the extremum of the parabola instead of the intersection.
     discriminant = max(0, discriminant)
     return (-initial_feedrate + math.sqrt(discriminant)) / acceleration
 
-##  Calculates the point at which you must start braking.
-#
-#   This gives the distance from the start of a line at which you must start
-#   decelerating (at a rate of `-acceleration`) if you started at speed
-#   `initial_feedrate` and accelerated until this point and want to end at the
-#   `final_feedrate` after a total travel of `distance`. This can be used to
-#   compute the intersection point between acceleration and deceleration in the
-#   cases where the trapezoid has no plateau (i.e. never reaches maximum speed).
+
 def calc_intersection_distance(initial_feedrate: float, final_feedrate: float, acceleration: float, distance: float) -> float:
+    """Calculates the point at which you must start braking.
+    
+    This gives the distance from the start of a line at which you must start
+    decelerating (at a rate of `-acceleration`) if you started at speed
+    `initial_feedrate` and accelerated until this point and want to end at the
+    `final_feedrate` after a total travel of `distance`. This can be used to
+    compute the intersection point between acceleration and deceleration in the
+    cases where the trapezoid has no plateau (i.e. never reaches maximum speed).
+    """
+
     if acceleration == 0:
         return 0
     return (2 * acceleration * distance - initial_feedrate * initial_feedrate + final_feedrate * final_feedrate) / (4 * acceleration)
 
-##  Calculates the maximum speed that is allowed at this point when you must be
-#   able to reach target_velocity using the acceleration within the allotted
-#   distance.
+
 def calc_max_allowable_speed(acceleration: float, target_velocity: float, distance: float) -> float:
+    """Calculates the maximum speed that is allowed at this point when you must be
+    able to reach target_velocity using the acceleration within the allotted
+    distance.
+    """
+
     return math.sqrt(target_velocity * target_velocity - 2 * acceleration * distance)
 
 
@@ -130,10 +143,12 @@ class Command:
         self._delta = [0, 0, 0]
         self._abs_delta = [0, 0, 0]
 
-    ##  Calculate the velocity-time trapezoid function for this move.
-    #
-    #   Each move has a three-part function mapping time to velocity.
     def calculate_trapezoid(self, entry_factor, exit_factor):
+        """Calculate the velocity-time trapezoid function for this move.
+        
+        Each move has a three-part function mapping time to velocity.
+        """
+
         initial_feedrate = self._nominal_feedrate * entry_factor
         final_feedrate = self._nominal_feedrate * exit_factor
 
@@ -169,9 +184,9 @@ class Command:
 
         return self._cmd_str.strip() + " ; --- " + info + os.linesep
 
-    ##  Estimates the execution time of this command and calculates the state
-    #   after this command is executed.
     def parse(self) -> None:
+        """Estimates the execution time of this command and calculates the state after this command is executed."""
+
         line = self._cmd_str.strip()
         if not line:
             self._is_empty = True

+ 33 - 19
scripts/lionbridge_import.py

@@ -9,14 +9,16 @@ import os.path #To find files from the source and the destination path.
 cura_files = {"cura", "fdmprinter.def.json", "fdmextruder.def.json"}
 uranium_files = {"uranium"}
 
-##  Imports translation files from Lionbridge.
-#
-#   Lionbridge has a bit of a weird export feature. It exports it to the same
-#   file type as what we imported, so that's a .pot file. However this .pot file
-#   only contains the translations, so the header is completely empty. We need
-#   to merge those translations into our existing files so that the header is
-#   preserved.
 def lionbridge_import(source: str) -> None:
+    """Imports translation files from Lionbridge.
+    
+    Lionbridge has a bit of a weird export feature. It exports it to the same
+    file type as what we imported, so that's a .pot file. However this .pot file
+    only contains the translations, so the header is completely empty. We need
+    to merge those translations into our existing files so that the header is
+    preserved.
+    """
+
     print("Importing from:", source)
     print("Importing to Cura:", destination_cura())
     print("Importing to Uranium:", destination_uranium())
@@ -43,14 +45,20 @@ def lionbridge_import(source: str) -> None:
             with io.open(destination_file, "w", encoding = "utf8") as f:
                 f.write(result)
 
-##  Gets the destination path to copy the translations for Cura to.
-#   \return Destination path for Cura.
+
 def destination_cura() -> str:
+    """Gets the destination path to copy the translations for Cura to.
+    
+    :return: Destination path for Cura.
+    """
     return os.path.abspath(os.path.join(__file__, "..", "..", "resources", "i18n"))
 
-##  Gets the destination path to copy the translations for Uranium to.
-#   \return Destination path for Uranium.
+
 def destination_uranium() -> str:
+    """Gets the destination path to copy the translations for Uranium to.
+    
+    :return: Destination path for Uranium.
+    """
     try:
         import UM
     except ImportError:
@@ -64,11 +72,14 @@ def destination_uranium() -> str:
             raise Exception("Can't find Uranium. Please put UM on the PYTHONPATH or put the Uranium folder next to the Cura folder. Looked for: " + absolute_path)
     return os.path.abspath(os.path.join(UM.__file__, "..", "..", "resources", "i18n"))
 
-##  Merges translations from the source file into the destination file if they
-#   were missing in the destination file.
-#   \param source The contents of the source .po file.
-#   \param destination The contents of the destination .po file.
+
 def merge(source: str, destination: str) -> str:
+    """Merges translations from the source file into the destination file if they
+    
+    were missing in the destination file.
+    :param source: The contents of the source .po file.
+    :param destination: The contents of the destination .po file.
+    """
     result_lines = []
     last_destination = {
         "msgctxt": "\"\"\n",
@@ -119,11 +130,14 @@ def merge(source: str, destination: str) -> str:
             result_lines.append(line) #This line itself.
     return "\n".join(result_lines)
 
-##  Finds a translation in the source file.
-#   \param source The contents of the source .po file.
-#   \param msgctxt The ctxt of the translation to find.
-#   \param msgid The id of the translation to find.
+
 def find_translation(source: str, msgctxt: str, msgid: str) -> str:
+    """Finds a translation in the source file.
+    
+    :param source: The contents of the source .po file.
+    :param msgctxt: The ctxt of the translation to find.
+    :param msgid: The id of the translation to find.
+    """
     last_source = {
         "msgctxt": "\"\"\n",
         "msgid": "\"\"\n",