本文整理汇总了Python中pycam.Utils.log.warn函数的典型用法代码示例。如果您正苦于以下问题:Python warn函数的具体用法?Python warn怎么用?Python warn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了warn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_lwpolyline
def parse_lwpolyline(self):
start_line = self.line_number
points = []
def add_point(p_array):
# fill all "None" values with zero
for index in range(len(p_array)):
if p_array[index] is None:
if (index == 0) or (index == 1):
log.debug("DXFImporter: weird LWPOLYLINE input " + \
"date in line %d: %s" % \
(self.line_number, p_array))
p_array[index] = 0
points.append(Point(p_array[0], p_array[1], p_array[2]))
current_point = [None, None, None]
key, value = self._read_key_value()
while (not key is None) and (key != self.KEYS["MARKER"]):
if key == self.KEYS["P1_X"]:
axis = 0
elif key == self.KEYS["P1_Y"]:
axis = 1
elif not self._color_as_height and (key == self.KEYS["P1_Z"]):
axis = 2
elif self._color_as_height and (key == self.KEYS["COLOR"]):
# interpret the color as the height
axis = 2
value = float(value) / 255
else:
axis = None
if not axis is None:
if current_point[axis] is None:
# The current point definition is not complete, yet.
current_point[axis] = value
else:
# The current point seems to be complete.
add_point(current_point)
current_point = [None, None, None]
current_point[axis] = value
key, value = self._read_key_value()
end_line = self.line_number
# The last lines were not used - they are just the marker for the next
# item.
if not key is None:
self._push_on_stack(key, value)
# check if there is a remaining item in "current_point"
if len(current_point) != current_point.count(None):
add_point(current_point)
if len(points) < 2:
# too few points for a polyline
log.warn("DXFImporter: Empty LWPOLYLINE definition between line " \
+ "%d and %d" % (start_line, end_line))
else:
for index in range(len(points) - 1):
point = points[index]
next_point = points[index + 1]
if point != next_point:
self.lines.append(Line(point, next_point))
else:
log.warn("DXFImporter: Ignoring zero-length LINE " \
+ "(between input line %d and %d): %s" \
% (start_line, end_line, point))
示例2: parse_arc
def parse_arc(self, circle=False):
start_line = self.line_number
# the z-level defaults to zero (for 2D models)
center = [None, None, 0]
color = None
radius = None
if circle:
angle_start = 0
angle_end = 360
else:
angle_start = None
angle_end = None
key, value = self._read_key_value()
while (not key is None) and (key != self.KEYS["MARKER"]):
if key == self.KEYS["P1_X"]:
center[0] = value
elif key == self.KEYS["P1_Y"]:
center[1] = value
elif key == self.KEYS["P1_Z"]:
center[2] = value
elif key == self.KEYS["RADIUS"]:
radius = value
elif key == self.KEYS["ANGLE_START"]:
angle_start = value
elif key == self.KEYS["ANGLE_END"]:
angle_end = value
elif key == self.KEYS["COLOR"]:
color = value
else:
pass
key, value = self._read_key_value()
end_line = self.line_number
# The last lines were not used - they are just the marker for the next
# item.
if not key is None:
self._push_on_stack(key, value)
if (None in center) or (None in (radius, angle_start, angle_end)):
log.warn("DXFImporter: Incomplete ARC definition between line " \
+ "%d and %d" % (start_line, end_line))
else:
if self._color_as_height and (not color is None):
# use the color code as the z coordinate
center[2] = float(color) / 255
center = tuple(center)
xy_point_coords = pycam.Geometry.get_points_of_arc(center, radius, angle_start, angle_end)
# Somehow the order of points seems to be the opposite of what is
# expected.
xy_point_coords.reverse()
if len(xy_point_coords) > 1:
for index in range(len(xy_point_coords) - 1):
p1 = xy_point_coords[index]
p1 = (p1[0], p1[1], center[2])
p2 = xy_point_coords[index + 1]
p2 = (p2[0], p2[1], center[2])
if p1 != p2:
self.lines.append(Line(p1, p2))
else:
log.warn("DXFImporter: Ignoring tiny ARC (between input " + \
"line %d and %d): %s / %s (%s - %s)" % (start_line,
end_line, center, radius, angle_start, angle_end))
示例3: parse_toolpath_settings
def parse_toolpath_settings(filename):
""" parse potential PyCAM settings from a given file
This is mainly useful to retrieve task settings from a GCode file.
@value filename: the name of the file to be read
@type filename: str
@returns: a dictionary (of all setting names and values) and the content
of the 'comment' section (as a single string)
@rtype: tuple(dict, str)
"""
keywords = {}
in_meta_zone = False
meta_content = []
if filename == "-":
# read from stdin, if the input filename is "-"
infile = sys.stdin
close_file = False
else:
# open the file
try:
infile = pycam.Utils.URIHandler(filename).open()
except IOError, err_msg:
log.warn("ToolpathSettingsParser: Failed to read file (%s): %s" % \
(filename, err_msg))
return None
close_file = True
示例4: close_sequence
def close_sequence(self):
start_line = self.line_number
if self._open_sequence == "POLYLINE":
self.parse_polyline(False)
else:
log.warn("DXFImporter: unexpected SEQEND found at line %d" % \
start_line)
示例5: parse_vertex
def parse_vertex(self):
start_line = self.line_number
point = [None, None, 0]
color = None
bulge = None
key, value = self._read_key_value()
while (not key is None) and (key != self.KEYS["MARKER"]):
if key == self.KEYS["P1_X"]:
point[0] = value
elif key == self.KEYS["P1_Y"]:
point[1] = value
elif key == self.KEYS["P1_Z"]:
point[2] = value
elif key == self.KEYS["COLOR"]:
color = value
elif key == self.KEYS["VERTEX_BULGE"]:
bulge = value
else:
pass
key, value = self._read_key_value()
end_line = self.line_number
if not key is None:
self._push_on_stack(key, value)
if self._color_as_height and (not color is None):
# use the color code as the z coordinate
point[2] = float(color) / 255
if None in point:
log.warn("DXFImporter: Missing attribute of VERTEX item" + \
"between line %d and %d" % (start_line, end_line))
else:
self._open_sequence_items.append(
(Point(point[0], point[1], point[2]), bulge))
示例6: parse
def parse(self, text):
text_stream = StringIO.StringIO(text)
config = ConfigParser.SafeConfigParser()
config.readfp(text_stream)
for config_dict, section in ((self.bounds, "Bounds"),
(self.tool_settings, "Tool"),
(self.process_settings, "Process")):
for key, value_type in self.SECTIONS[section].items():
value_raw = config.get(section, key, None)
if value_raw is None:
continue
elif value_type == bool:
value = value_raw.lower() in ("1", "true", "yes", "on")
elif isinstance(value_type, basestring) \
and (value_type.startswith("list_of_")):
item_type = value_type[len("list_of_"):]
if item_type == "float":
item_type = float
else:
continue
try:
value = [item_type(one_val)
for one_val in value_raw.split(",")]
except ValueError:
log.warn("Settings: Ignored invalid setting due to " \
+ "a failed list type parsing: " \
+ "(%s -> %s): %s" % (section, key, value_raw))
else:
try:
value = value_type(value_raw)
except ValueError:
log.warn("Settings: Ignored invalid setting " \
+ "(%s -> %s): %s" % (section, key, value_raw))
config_dict[key] = value
示例7: load_preferences
def load_preferences(self):
""" load all settings that are available in the Preferences window from
a file in the user's home directory """
config_filename = pycam.Gui.Settings.get_config_filename()
if config_filename is None:
# failed to create the personal preferences directory
return
config = ConfigParser.ConfigParser()
if not config.read(config_filename):
# no config file was read
return
# report any ignored (obsolete) preference keys present in the file
for item, value in config.items("DEFAULT"):
if not item in PREFERENCES_DEFAULTS.keys():
log.warn("Skipping obsolete preference item: %s" % str(item))
for item in PREFERENCES_DEFAULTS.keys():
if not config.has_option("DEFAULT", item):
# a new preference setting is missing in the (old) file
continue
value_raw = config.get("DEFAULT", item)
old_value = self.settings.get(item)
value_type = type(PREFERENCES_DEFAULTS[item])
if isinstance(value_type(), basestring):
# keep strings as they are
value = str(value_raw)
else:
# parse tuples, integers, bools, ...
value = eval(value_raw)
self.settings.set(item, value)
示例8: combine_triangles
def combine_triangles(t1, t2):
unique_vertices = []
shared_vertices = []
for point in t1.get_points():
for point2 in t2.get_points():
if point == point2:
shared_vertices.append(point)
break
else:
unique_vertices.append(point)
if len(shared_vertices) != 2:
return None
for point in t2.get_points():
for point2 in shared_vertices:
if point == point2:
break
else:
unique_vertices.append(point)
if len(unique_vertices) != 2:
log.error("Invalid number of vertices: %s" % unique_vertices)
return None
if abs(unique_vertices[0].sub(unique_vertices[1]).norm - \
shared_vertices[0].sub(shared_vertices[1]).norm) < epsilon:
try:
return Rectangle(unique_vertices[0], unique_vertices[1],
shared_vertices[0], shared_vertices[1],
normal=t1.normal)
except ValueError:
log.warn("Triangles not combined: %s, %s" % (unique_vertices,
shared_vertices))
return None
else:
return None
示例9: recommends_details_gtk
def recommends_details_gtk():
result = {}
try:
import gtk.gtkgl
result["gtkgl"] = True
result["gl"] = True
except ImportError, err_msg:
log.warn("Failed to import OpenGL for GTK (ImportError): %s" % \
str(err_msg))
result["gtkgl"] = False
示例10: get_lines_layer
def get_lines_layer(lines, z, last_z=None, step_width=None,
milling_style=MILLING_STYLE_CONVENTIONAL):
get_proj_point = lambda proj_point: (proj_point[0], proj_point[1], z)
projected_lines = []
for line in lines:
if (not last_z is None) and (last_z < line.minz):
# the line was processed before
continue
elif line.minz < z < line.maxz:
# Split the line at the point at z level and do the calculation
# for both point pairs.
factor = (z - line.p1[2]) / (line.p2[2] - line.p1[2])
plane_point = padd(line.p1, pmul(line.vector, factor))
if line.p1[2] < z:
p1 = get_proj_point(line.p1)
p2 = line.p2
else:
p1 = line.p1
p2 = get_proj_point(line.p2)
projected_lines.append(Line(p1, plane_point))
yield Line(plane_point, p2)
elif line.minz < last_z < line.maxz:
plane = Plane((0, 0, last_z), (0, 0, 1, 'v'))
cp = plane.intersect_point(line.dir, line.p1)[0]
# we can be sure that there is an intersection
if line.p1[2] > last_z:
p1, p2 = cp, line.p2
else:
p1, p2 = line.p1, cp
projected_lines.append(Line(p1, p2))
else:
if line.maxz <= z:
# the line is completely below z
projected_lines.append(Line(get_proj_point(line.p1),
get_proj_point(line.p2)))
elif line.minz >= z:
projected_lines.append(line)
else:
log.warn("Unexpected condition 'get_lines_layer': " + \
"%s / %s / %s / %s" % (line.p1, line.p2, z, last_z))
# process all projected lines
for line in projected_lines:
points = []
if step_width is None:
points.append(line.p1)
points.append(line.p2)
else:
if isiterable(step_width):
steps = step_width
else:
steps = floatrange(0.0, line.len, inc=step_width)
for step in steps:
next_point = padd(line.p1, pmul(line.dir, step))
points.append(next_point)
yield points
示例11: get_default_model
def get_default_model():
""" return a filename or a Model instance """
# try to load the default model file ("pycam" logo)
for inputdir in EXAMPLE_MODEL_LOCATIONS:
inputfile = os.path.join(inputdir, DEFAULT_MODEL_FILE)
if os.path.isfile(inputfile):
return inputfile
else:
# fall back to the simple test model
log.warn("Failed to find the default model (%s) in the " \
"following locations: %s" % (DEFAULT_MODEL_FILE,
", ".join(EXAMPLE_MODEL_LOCATIONS)))
return pycam.Importers.TestModel.get_test_model()
示例12: GenerateToolPathLinePush
def GenerateToolPathLinePush(self, pa, line, z, previous_z,
draw_callback=None):
if previous_z <= line.minz:
# the line is completely above the previous level
pass
elif line.minz < z < line.maxz:
# Split the line at the point at z level and do the calculation
# for both point pairs.
factor = (z - line.p1.z) / (line.p2.z - line.p1.z)
plane_point = line.p1.add(line.vector.mul(factor))
self.GenerateToolPathLinePush(pa, Line(line.p1, plane_point), z,
previous_z, draw_callback=draw_callback)
self.GenerateToolPathLinePush(pa, Line(plane_point, line.p2), z,
previous_z, draw_callback=draw_callback)
elif line.minz < previous_z < line.maxz:
plane = Plane(Point(0, 0, previous_z), Vector(0, 0, 1))
cp = plane.intersect_point(line.dir, line.p1)[0]
# we can be sure that there is an intersection
if line.p1.z > previous_z:
p1, p2 = cp, line.p2
else:
p1, p2 = line.p1, cp
self.GenerateToolPathLinePush(pa, Line(p1, p2), z, previous_z,
draw_callback=draw_callback)
else:
if line.maxz <= z:
# the line is completely below z
p1 = Point(line.p1.x, line.p1.y, z)
p2 = Point(line.p2.x, line.p2.y, z)
elif line.minz >= z:
p1 = line.p1
p2 = line.p2
else:
log.warn("Unexpected condition EC_GTPLP: %s / %s / %s / %s" % \
(line.p1, line.p2, z, previous_z))
return
# no model -> no possible obstacles
# model is completely below z (e.g. support bridges) -> no obstacles
relevant_models = [m for m in self.models if m.maxz >= z]
if not relevant_models:
points = [p1, p2]
elif self.physics:
points = get_free_paths_ode(self.physics, p1, p2)
else:
points = get_free_paths_triangles(relevant_models, self.cutter,
p1, p2)
if points:
for point in points:
pa.append(point)
if draw_callback:
draw_callback(tool_position=points[-1], toolpath=pa.paths)
示例13: __init__
def __init__(self, title, message):
try:
import Tkinter
except ImportError:
# tk is not installed
log.warn("Failed to show error dialog due to a missing Tkinter " \
+ "Python package.")
return
try:
root = Tkinter.Tk()
except Tkinter.TclError, err_msg:
log.info(("Failed to create error dialog window (%s). Probably " \
+ "you are running PyCAM from a terminal.") % err_msg)
return
示例14: load_model_file
def load_model_file(filename, program_locations, unit=None):
uri = pycam.Utils.URIHandler(filename)
if uri.is_local():
uri = pycam.Utils.URIHandler(os.path.expanduser(str(filename)))
if not uri.exists():
log.warn("The input file ('%s') was not found!" % uri)
return None
importer = pycam.Importers.detect_file_type(uri)[1]
model = importer(uri, program_locations=program_locations, unit=unit)
if not model:
log.warn("Failed to load the model file (%s)." % uri)
return None
else:
return model
示例15: _read_key_value
def _read_key_value(self):
if self._input_stack:
return self._input_stack.pop()
try:
line1 = self.inputstream.readline(self.MAX_CHARS_PER_LINE).strip()
line2 = self.inputstream.readline(self.MAX_CHARS_PER_LINE).strip()
except IOError:
return None, None
if not line1 and not line2:
return None, None
try:
line1 = int(line1)
except ValueError:
log.warn("DXFImporter: Invalid key in line " \
+ "%d (int expected): %s" % (self.line_number, line1))
return None, None
if line1 in [self.KEYS[key] for key in ("P1_X", "P1_Y", "P1_Z",
"P2_X", "P2_Y", "P2_Z", "RADIUS", "ANGLE_START", "ANGLE_END",
"TEXT_HEIGHT", "TEXT_WIDTH_FINAL", "TEXT_ROTATION",
"TEXT_SKEW_ANGLE", "VERTEX_BULGE")]:
try:
line2 = float(line2)
except ValueError:
log.warn("DXFImporter: Invalid input in line " \
+ "%d (float expected): %s" % (self.line_number, line2))
line1 = None
line2 = None
elif line1 in [self.KEYS[key] for key in ("COLOR", "TEXT_MIRROR_FLAGS",
"TEXT_ALIGN_HORIZONTAL", "TEXT_ALIGN_VERTICAL",
"MTEXT_ALIGNMENT", "CURVE_TYPE", "VERTEX_FLAGS")]:
try:
line2 = int(line2)
except ValueError:
log.warn("DXFImporter: Invalid input in line " \
+ "%d (int expected): %s" % (self.line_number, line2))
line1 = None
line2 = None
elif line1 in [self.KEYS[key] for key in ("DEFAULT", "TEXT_MORE")]:
# check the string for invalid characters
try:
text = unicode(line2)
except UnicodeDecodeError:
log.warn("DXFImporter: Invalid character in string in " + \
"line %d" % self.line_number)
text_chars = []
for char in line2:
try:
text_chars.append(unicode(char))
except:
pass
text = u"".join(text_chars)
line2 = _unescape_control_characters(text)
else:
line2 = line2.upper()
self.line_number += 2
return line1, line2