Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: choosing industrial printer #145

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ hardware:
plane_center_y: 0
plane_center_z: 0
plane_diameter: 250
printer_type: E240
maximum_height: 240
minimum_planner_speed: 0.05
nozzle_contact_points:
Expand Down
49 changes: 35 additions & 14 deletions src/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
import vtk
from PyQt5 import QtCore
from PyQt5.QtCore import QSettings
from PyQt5.QtWidgets import QFileDialog, QInputDialog, QMessageBox
from PyQt5.QtWidgets import QFileDialog, QMessageBox

from src.window import AddNewPrinterDialog
from src import gui_utils, locales, qt_utils
from src.figure_editor import PlaneEditor, ConeEditor
from src.gui_utils import (
Expand Down Expand Up @@ -74,6 +75,7 @@ def __init__(self, view, model):
# embed calibration tool
self.calibrationPanel = calibration.CalibrationPanel(view)
self.calibrationPanel.setModal(True)
self.calibrationPanel.closedSignal.connect(self.calibration_action_closed)
self.calibrationController = calibration.CalibrationController(
self.calibrationPanel,
calibration.CalibrationModel(
Expand Down Expand Up @@ -170,6 +172,9 @@ def calibration_action_show(self):

self.calibrationPanel.show()

def calibration_action_closed(self, printer_type):
self.view.update_plane_diameter_by_printer_type(printer_type)

def current_printer_is_default(self):
if os.path.basename(sett().hardware.printer_dir) == "default":
return True
Expand All @@ -181,17 +186,11 @@ def save_planes_on_close(self):

def create_printer(self):
# query user for printer name and create directory in data/printers/<name> relative to FASP root
text, ok = QInputDialog.getText(
self.view,
locales.getLocale().AddNewPrinter,
locales.getLocale().ChoosePrinterDirectory,
)
if not ok:
dialog = AddNewPrinterDialog(self.view)
if not dialog.exec_():
return

printer_name = text.strip()
if not printer_name:
return
printer_name, printer_type = dialog.get_result()

# create directory in data/printers/<name> relative to FASP root
printer_path = path.join(settings.APP_PATH, "data", "printers", printer_name)
Expand All @@ -208,13 +207,18 @@ def create_printer(self):
default_calibration_file = path.join(
settings.APP_PATH, "data", "printers", "default", "calibration_data.csv"
)
target_calibration_file = path.join(printer_path, "calibration_data.csv")
calibration_filename = "calibration_data.csv"
calibration_filename = calibration_filename.replace(
".csv", "_{}.csv".format(printer_type)
)
target_calibration_file = path.join(printer_path, calibration_filename)

shutil.copyfile(default_calibration_file, target_calibration_file)

# update settings
self.view.update_plane_diameter_by_printer_type(printer_type)
sett().hardware.printer_dir = printer_path
sett().hardware.calibration_file = "calibration_data.csv"
sett().hardware.calibration_file = calibration_filename
save_settings()

# update label with printer path
Expand All @@ -233,6 +237,16 @@ def create_printer(self):
"Printer created successfully, please calibrate before first use"
)

def get_printer_type_from_filename(self, filename):
words = filename.split("_")

if len(words) == 3:
printer_type = filename.split("_")[2].split(".")[0]
else:
printer_type = "E240"

return printer_type

def choose_printer_path(self):
printer_path = QFileDialog.getExistingDirectory(
self.view,
Expand All @@ -242,13 +256,20 @@ def choose_printer_path(self):

if printer_path:
# check if directory contains calibration file
calibration_file = path.join(printer_path, "calibration_data.csv")
if not path.exists(calibration_file):
files = os.listdir(printer_path)
for file in files:
if file.startswith("calibration_data") and file.endswith(".csv"):
calibration_file = os.path.join(printer_path, file)
break
else:
showErrorDialog(
"Directory doesn't contain calibration file. Please choose another directory."
)
return

printer_type = self.get_printer_type_from_filename(calibration_file)
self.view.update_plane_diameter_by_printer_type(printer_type)

sett().hardware.printer_dir = printer_path
# calibration file will be at default location
sett().hardware.calibration_file = "calibration_data.csv"
Expand Down
6 changes: 4 additions & 2 deletions src/locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class Locale:
ErrorBugModule = "Bug reporting is unavailable in public"

PrinterName = "Printer name:"
ChoosePrinterDirectory = "Choose printer name"
ChoosePrinterDirectory = "Choose printer name:"
ChoosePrinterType = "Choose printer type:"
AddNewPrinter = "Add new printer"
DefaultPrinterWarn = "Be aware that you are using default printer. New data might be removed after update. We recommend to create new printer and calibrate it."
CheckUpdates = "Check for updates"
Expand Down Expand Up @@ -278,7 +279,8 @@ def __init__(self, **entries):
ErrorHardwareModule="Модуль калибровки недоступен публично",
ErrorBugModule="Модуль отправки багов недоступен публично",
PrinterName="Конфигурация принтера:",
ChoosePrinterDirectory="Выберите название принтера",
ChoosePrinterDirectory="Выберите название принтера:",
ChoosePrinterType="Выберите тип принтера:",
AddNewPrinter="Добавить новый принтер",
DefaultPrinterWarn="Будьте внимательны, Вы используете принтер по умолчанию. Данные этого принтера будут перезаписываться при обновлениях. Мы рекомендуем создать и использовать свою конфигурацию принтера.",
CheckUpdates="Проверить наличие обновлений",
Expand Down
72 changes: 72 additions & 0 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
QAbstractItemView,
QTabWidget,
QMessageBox,
QHBoxLayout,
)
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor

Expand Down Expand Up @@ -350,6 +351,26 @@ def init3d_widget(self):

return widget3d

def update_plane_diameter_by_printer_type(self, printer_type):
if printer_type == "E240":
sett().hardware.printer_type = printer_type
sett().hardware.plane_diameter = 250
sett().hardware.maximum_height = 240
elif printer_type == "M600":
sett().hardware.printer_type = printer_type
sett().hardware.plane_diameter = 600
sett().hardware.maximum_height = 600
else:
return

self.update_plane_diameter()

def update_plane_diameter(self):
self.render.RemoveActor(self.planeActor)
self.planeActor = gui_utils.createPlaneActorCircle()
self.render.AddActor(self.planeActor)
self.reload_scene()

def add_legend(self):
hackData = vtk.vtkPolyData() # it is hack to pass value to legend
hackData.SetPoints(vtk.vtkPoints())
Expand Down Expand Up @@ -1525,6 +1546,57 @@ def reset_colorize(self):
self.stlActor.ResetColorize()


class AddNewPrinterDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle(locales.getLocale().AddNewPrinter)
self.setFixedSize(350, 190)

self.printer_directory_label = QLabel(
locales.getLocale().ChoosePrinterDirectory
)
self.printer_directory = QLineEdit()

self.printer_type_label = QLabel(locales.getLocale().ChoosePrinterType)
self.printer_type = QComboBox()
self.printer_type.addItem("E240")
self.printer_type.addItem("M600")

self.continue_button = QPushButton(locales.getLocale().Continue)
self.continue_button.clicked.connect(self.accept_dialog)
self.cancel_button = QPushButton(locales.getLocale().Cancel)
self.cancel_button.clicked.connect(self.reject)

button_layout = QHBoxLayout()
button_layout.addWidget(self.continue_button)
button_layout.addWidget(self.cancel_button)

layout = QVBoxLayout()
layout.addWidget(self.printer_directory_label)
layout.addWidget(self.printer_directory)
layout.addWidget(self.printer_type_label)
layout.addWidget(self.printer_type)
layout.addLayout(button_layout)

self.setLayout(layout)

def accept_dialog(self):
self.printer_directory_text = self.printer_directory.text().strip()

if self.printer_directory_text == "":
QMessageBox.warning(
self,
locales.getLocale().AddNewPrinter,
locales.getLocale().ChoosePrinterDirectory,
)
return

self.accept()

def get_result(self):
return self.printer_directory_text, self.printer_type.currentText()


def strF(v): # cut 3 numbers after the point in float
s = str(v)
i = s.find(".")
Expand Down
Loading