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