mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
add xray error warning message
This commit is contained in:
parent
b4c3703dc4
commit
643b27e160
1 changed files with 27 additions and 7 deletions
|
@ -13,6 +13,7 @@ import time
|
||||||
|
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
|
from UM.Message import Message
|
||||||
from UM.Math.Color import Color
|
from UM.Math.Color import Color
|
||||||
from UM.PluginRegistry import PluginRegistry
|
from UM.PluginRegistry import PluginRegistry
|
||||||
from UM.Platform import Platform
|
from UM.Platform import Platform
|
||||||
|
@ -21,6 +22,8 @@ from UM.Event import Event
|
||||||
from UM.View.RenderBatch import RenderBatch
|
from UM.View.RenderBatch import RenderBatch
|
||||||
from UM.View.GL.OpenGL import OpenGL
|
from UM.View.GL.OpenGL import OpenGL
|
||||||
|
|
||||||
|
from UM.i18n import i18nCatalog
|
||||||
|
|
||||||
from cura.CuraApplication import CuraApplication
|
from cura.CuraApplication import CuraApplication
|
||||||
|
|
||||||
from cura.Settings.ExtruderManager import ExtruderManager
|
from cura.Settings.ExtruderManager import ExtruderManager
|
||||||
|
@ -29,9 +32,13 @@ from cura import XRayPass
|
||||||
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
## Standard view for mesh models.
|
## Standard view for mesh models.
|
||||||
|
|
||||||
class SolidView(View):
|
class SolidView(View):
|
||||||
|
_show_xray_warning_preference = "view/show_xray_warning"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
application = Application.getInstance()
|
application = Application.getInstance()
|
||||||
|
@ -57,8 +64,15 @@ class SolidView(View):
|
||||||
self._old_composite_shader = None
|
self._old_composite_shader = None
|
||||||
self._old_layer_bindings = None
|
self._old_layer_bindings = None
|
||||||
|
|
||||||
self._last_xray_checking_time = time.time()
|
self._next_xray_checking_time = time.time()
|
||||||
self._xray_checking_update_time = 1.0 # seconds
|
self._xray_checking_update_time = 1.0 # seconds
|
||||||
|
self._xray_warning_cooldown = 1 # reshow Model error message every 10 minutes
|
||||||
|
self._xray_warning_message = Message(catalog.i18nc("@info:status", "Your model is not manifold. The highlighted areas indicate either missing or extraneous surfaces.")
|
||||||
|
, lifetime = 60 * 5 # leave message for 5 minutes
|
||||||
|
, title = catalog.i18nc("@info:title", "Model errors"),
|
||||||
|
option_text = catalog.i18nc("@info:option_text", "Do not show this message again"), option_state = False)
|
||||||
|
self._xray_warning_message.optionToggled.connect(self._onDontAskMeAgain)
|
||||||
|
CuraApplication.getInstance().getPreferences().addPreference(self._show_xray_warning_preference, True)
|
||||||
|
|
||||||
Application.getInstance().engineCreatedSignal.connect(self._onGlobalContainerChanged)
|
Application.getInstance().engineCreatedSignal.connect(self._onGlobalContainerChanged)
|
||||||
|
|
||||||
|
@ -236,19 +250,24 @@ class SolidView(View):
|
||||||
|
|
||||||
def endRendering(self):
|
def endRendering(self):
|
||||||
# check whether the xray overlay is showing badness
|
# check whether the xray overlay is showing badness
|
||||||
if time.time() > self._last_xray_checking_time + self._xray_checking_update_time:
|
if time.time() > self._next_xray_checking_time\
|
||||||
self._last_xray_checking_time = time.time()
|
and CuraApplication.getInstance().getPreferences().getValue(self._show_xray_warning_preference):
|
||||||
|
self._next_xray_checking_time = time.time() + self._xray_checking_update_time
|
||||||
|
|
||||||
xray_img = self._xray_pass.getOutput()
|
xray_img = self._xray_pass.getOutput()
|
||||||
xray_img = xray_img.convertToFormat(QImage.Format.Format_RGB888)
|
xray_img = xray_img.convertToFormat(QImage.Format.Format_RGB888)
|
||||||
|
|
||||||
ptr = xray_img.bits()
|
ptr = xray_img.bits()
|
||||||
ptr.setsize(xray_img.byteCount())
|
ptr.setsize(xray_img.byteCount())
|
||||||
reds = np.array(ptr).reshape(xray_img.height(), xray_img.width(), 3)[:,:,0] # Copies the data
|
reds = np.array(ptr).reshape(xray_img.height(), xray_img.width(), 3)[:,:,0] # Copies the data
|
||||||
|
bad_pixel_count = np.sum(np.mod(reds, 2)) # check number of pixels with an odd intersection count
|
||||||
|
|
||||||
bad_pixel_count = np.sum(np.mod(reds, 2))
|
if bad_pixel_count > 10: # allow for 10 pixels to be erroneously marked as problematic
|
||||||
|
self._next_xray_checking_time = time.time() + self._xray_warning_cooldown
|
||||||
|
self._xray_warning_message.show()
|
||||||
|
Logger.log("i", "Xray overlay found %d non-manifold pixels." % bad_pixel_count)
|
||||||
|
|
||||||
if bad_pixel_count > 0:
|
def _onDontAskMeAgain(self, checked: bool) -> None:
|
||||||
Logger.log("d", "Super bad xray, man! : %d" % bad_pixel_count)
|
CuraApplication.getInstance().getPreferences().setValue(self._show_xray_warning_preference, not checked)
|
||||||
|
|
||||||
def event(self, event):
|
def event(self, event):
|
||||||
if event.type == Event.ViewActivateEvent:
|
if event.type == Event.ViewActivateEvent:
|
||||||
|
@ -274,3 +293,4 @@ class SolidView(View):
|
||||||
self.getRenderer().removeRenderPass(self._xray_pass)
|
self.getRenderer().removeRenderPass(self._xray_pass)
|
||||||
self._composite_pass.setLayerBindings(self._old_layer_bindings)
|
self._composite_pass.setLayerBindings(self._old_layer_bindings)
|
||||||
self._composite_pass.setCompositeShader(self._old_composite_shader)
|
self._composite_pass.setCompositeShader(self._old_composite_shader)
|
||||||
|
self._xray_warning_message.hide()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue