Commit 5fd1649b authored by sumpfralle's avatar sumpfralle

store the flags of a model (name, visibility) in a cache and feed it back to the model

updated some model-related TODOs


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1105 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent e7fab8b1
......@@ -19,16 +19,33 @@
<property name="vscrollbar_policy">automatic</property>
<property name="shadow_type">etched-out</property>
<child>
<object class="GtkIconView" id="ModelView">
<object class="GtkTreeView" id="ModelView">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="selection_mode">multiple</property>
<property name="model">ModelList</property>
<property name="headers_visible">False</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<property name="title">column</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererToggle" id="ModelVisibleToggle"/>
<attributes>
<attribute name="active">2</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="title">column</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
......@@ -143,12 +160,18 @@
</object>
<object class="GtkListStore" id="ModelList">
<columns>
<!-- column-name id -->
<column type="gint"/>
<!-- column-name name -->
<column type="gchararray"/>
<!-- column-name state -->
<column type="gboolean"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">Model 1</col>
<col id="0">0</col>
<col id="1" translatable="yes">Model #1</col>
<col id="2">False</col>
</row>
</data>
</object>
......
......@@ -217,14 +217,17 @@ class Camera(object):
# position the light according to the current bounding box
light_pos = range(3)
values = {}
for model in self.settings.get("models"):
for model in self.settings.get("models").get_visible():
for key in ("minx", "miny", "minz", "maxx", "maxy", "maxz"):
if not key in values:
values[key] = []
values[key].append(getattr(model, key))
light_pos[0] = 2 * max(values["maxx"]) - min(values["minx"])
light_pos[1] = 2 * max(values["maxy"]) - min(values["miny"])
light_pos[2] = 2 * max(values["maxz"]) - min(values["minz"])
if values:
light_pos[0] = 2 * max(values["maxx"]) - min(values["minx"])
light_pos[1] = 2 * max(values["maxy"]) - min(values["miny"])
light_pos[2] = 2 * max(values["maxz"]) - min(values["minz"])
else:
light_pos = (0, 0, 0)
GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, (light_pos[0], light_pos[1],
light_pos[2], 1.0))
# position the camera
......@@ -912,7 +915,7 @@ def draw_complete_model_view(settings):
and not (settings.get("show_simulation") \
and settings.get("simulation_toolpath_moves")):
GL.glColor4f(*settings.get("color_model"))
for model in settings.get("models"):
for model in settings.get("models").get_visible():
"""
min_area = abs(model.maxx - model.minx) * abs(model.maxy - model.miny) / 100
# example for coloring specific triangles
......
......@@ -438,6 +438,7 @@ class ProjectGui(object):
self.settings.register_event("model-change-after", self.update_model_type_related_controls)
self.settings.register_event("model-change-after", self.update_view)
self.settings.register_event("visual-item-updated", self.update_view)
self.settings.register_event("visual-item-updated", self.update_model_dimensions)
self.settings.set("update_progress", self.update_progress_bar)
self.settings.set("disable_progress_cancel_button", self.disable_progress_cancel_button)
self.settings.set("load_model", self.load_model)
......@@ -610,8 +611,9 @@ class ProjectGui(object):
# Calculate the "minx, ..." settings based on a (potentially) selected
# bounds setting.
def get_absolute_limit(key):
if not self.settings.get("models"):
# avoid problems if no model is loaded
models = self.settings.get("models").get_visible()
if not models:
# avoid problems if no model is visible
return 0
bounds = self.settings.get("current_bounds")
if key.startswith("min"):
......@@ -619,10 +621,10 @@ class ProjectGui(object):
else:
func = max
if bounds is None:
return func([getattr(model, key) for model in self.settings.get("models")])
return func([getattr(model, key) for model in models])
lows, highs = [], []
index = "xyz".index(key[-1])
for model in self.settings.get("models"):
for model in models:
low, high = bounds.get_absolute_limits(reference=model.get_bounds())
lows.append(low[index])
highs.append(high[index])
......@@ -1142,9 +1144,10 @@ class ProjectGui(object):
def update_model_type_related_controls(self):
# disable the lower boundary for contour models
models = self.settings.get("models")
models = self.settings.get("models").get_selected()
if not models:
return
# TODO: choose the right model
model = models[0]
is_contour = isinstance(model, pycam.Geometry.Model.ContourModel)
margin_type = self._load_bounds_settings_from_gui().get_type()
......@@ -1202,6 +1205,7 @@ class ProjectGui(object):
# for now we only store the model
if not self.settings.get("models"):
return
# TODO: store all models
self._undo_states.append(pickle.dumps(self.settings.get("models")[0]))
log.debug("Stored the current state of the model for undo")
while len(self._undo_states) > MAX_UNDO_STATES:
......@@ -1251,6 +1255,7 @@ class ProjectGui(object):
self.gui.get_object("SaveTaskSettings").set_sensitive(
bool(self.last_task_settings_uri and \
self.last_task_settings_uri.is_writable()))
# TODO: choose all models
model = self.settings.get("models") and self.settings.get("models")[0]
save_as_possible = (not model is None) and model.is_export_supported()
self.gui.get_object("SaveAsModel").set_sensitive(save_as_possible)
......@@ -1388,6 +1393,7 @@ class ProjectGui(object):
@gui_activity_guard
def adjust_bounds(self, widget, axis, change):
bounds = self.settings.get("current_bounds")
# TODO: choose the right model
model = self.settings.get("models")[0]
abs_bounds_low, abs_bounds_high = bounds.get_absolute_limits(
reference=model.get_bounds())
......@@ -1428,6 +1434,7 @@ class ProjectGui(object):
@gui_activity_guard
def switch_bounds_type(self, widget=None):
bounds = self.settings.get("current_bounds")
# TODO: choose the right model
model = self.settings.get("models")[0]
new_type = self._load_bounds_settings_from_gui().get_type()
if new_type == bounds.get_type():
......@@ -1820,7 +1827,8 @@ class ProjectGui(object):
self.clipboard.store()
def copy_model_to_clipboard(self, widget=None):
model = self.settings.get("models")[0]
# TODO: use all selected models (incl. merge?)
model = self.settings.get("models").get_selected()[0]
if not model.is_export_supported():
return
text_buffer = StringIO.StringIO()
......@@ -2376,7 +2384,7 @@ class ProjectGui(object):
# transform the model if it is selected
# keep the original center of the model
self.settings.emit_event("model-change-before")
for model in self.settings.get("models").get_selected():
for model in self.settings.get("models"):
new_x, new_y, new_z = ((model.maxx + model.minx) / 2,
(model.maxy + model.miny) / 2,
(model.maxz + model.minz) / 2)
......@@ -2471,9 +2479,8 @@ class ProjectGui(object):
def save_model(self, widget=None, filename=None, model=None,
store_filename=True):
if model is None:
models = self.settings.get("models").get_selected()
# TODO: merge multiple models
model = models[0]
model = self.settings.get("models").get_selected()[0]
if not model.is_export_supported():
log.warn(("Saving this type of model (%s) is currently not " \
+ "implemented!") % str(type(model)))
......@@ -2583,7 +2590,7 @@ class ProjectGui(object):
@gui_activity_guard
def update_model_dimensions(self, widget=None):
models = self.settings.get("models").get_selected()
models = self.settings.get("models").get_visible()
if not models:
return
# model corners in 3D view
......@@ -2866,7 +2873,8 @@ class ProjectGui(object):
def get_control(index, side):
return self.gui.get_object("boundary_%s_%s" % ("xyz"[index], side))
# disable each zero-dimension in relative margin mode
model = self.settings.get("models")[0]
# TODO: select the specific model
model = self.settings.get("models").get_visible()[0]
if current_type == Bounds.TYPE_RELATIVE_MARGIN:
model_dims = (model.maxx - model.minx,
model.maxy - model.miny,
......
......@@ -29,6 +29,7 @@ import pycam.Plugins
class Models(pycam.Plugins.ListPluginBase):
UI_FILE = "models.ui"
COLUMN_VISIBLE = 2
def setup(self):
if self.gui:
......@@ -51,20 +52,39 @@ class Models(pycam.Plugins.ListPluginBase):
(self.ACTION_CLEAR, "ModelDeleteAll")):
self.register_list_action_button(action, self._modelview,
self.gui.get_object(obj_name))
treemodel = self.gui.get_object("ModelList")
self.gui.get_object("ModelVisibleToggle").connect("toggled",
self._list_action_toggle, self.COLUMN_VISIBLE)
self._treemodel = self.gui.get_object("ModelList")
self._treemodel.clear()
def update_model():
treemodel.clear()
for index in range(len(self)):
treemodel.append((self[index], ))
# clean the model now
if not hasattr(self, "_model_cache"):
self._model_cache = {}
cache = self._model_cache
for row in self._treemodel:
cache[row[0]] = list(row)
self._treemodel.clear()
for index, item in enumerate(self):
if id(item) in cache:
self._treemodel.append(cache[id(item)])
else:
self._treemodel.append((id(item), "Model #%d" % index, True))
self.register_model_update(update_model)
#update_model()
self.core.add_item("models", lambda: self)
return True
def _list_action_toggle(self, widget, path, column):
path = int(path)
model = self._treemodel
model[path][column] = not model[path][column]
self.core.emit_event("visual-item-updated")
def get_selected(self):
return self._get_selected(self._modelview, force_list=True)
def get_visible(self):
return [self[index] for index, item in enumerate(self._treemodel)
if item[self.COLUMN_VISIBLE]]
def teardown(self):
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("ModelBox"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment