def set_transformation(self, transformation, init=False): if not transformation.__class__ == self.Transformation: # create an object of the proper type and take only the attributes # of interest. if isinstance(transformation, Translation): t = transformation.t else: t = None if isinstance(transformation, Rotation): r = transformation.r else: r = None if self.Transformation == Translation: if t is None: transformation = Translation.identity() else: transformation = Translation(t) elif self.Transformation == Rotation: if r is None: transformation = Rotation.identity() else: transformation = Rotation(r) else: # self.Transformation == Complete: if r is None: r = numpy.identity(3, float) if t is None: t = numpy.zeros(3, float) transformation = Complete(r, t) self.transformation = transformation if not init: self.invalidate_transformation_list()
def do(self): cache = context.application.cache # Translate where possible, if necessary translated_nodes = cache.translated_nodes if len(translated_nodes) > 0: if isinstance(cache.last, GLTransformationMixin) and \ isinstance(cache.last.transformation, Translation): absolute_inversion_center = cache.last.get_absolute_frame().t else: absolute_inversion_center = numpy.zeros(3, float) victims_by_parent = list_by_parent(cache.transformed_nodes) for parent, victims in victims_by_parent.iteritems(): local_inversion_center = parent.get_absolute_frame( ).inv * absolute_inversion_center for victim in victims: translation = Translation( 2 * (local_inversion_center - victim.transformation.t)) primitive.Transform(victim, translation) # Apply an inversion rotation where possible inversion = Rotation(-numpy.identity(3, float)) for victim in cache.rotated_nodes: primitive.Transform(victim, inversion, after=False)
def do(self): cache = context.application.cache rotation = Rotation(cache.node.transformation.r) CenterAlignBase.do(self, cache.parent, cache.transformed_neighbors, rotation)
def endElement(self, name): if name == "zml_file": return # now that we have gatherd all information of this tag, create an appropriate object # first find the tags involved in this operation current_tag = self.hierarchy[-1][-1] child_tags = [] if not current_tag.being_processed: current_tag = self.hierarchy[-2][-1] child_tags = self.hierarchy[-1] # do it if name == "str": current_tag.value = str(current_tag.content) elif name == "float": current_tag.value = float(current_tag.content) elif name == "int": current_tag.value = int(current_tag.content) elif name == "bool": temp = current_tag.content.lower().strip() if temp == 'true': current_tag.value = True else: current_tag.value = False elif name == "list": current_tag.value = [tag.value for tag in child_tags] elif name == "dict": current_tag.value = dict((tag.label, tag.value) for tag in child_tags) elif name == "tuple": current_tag.value = tuple(tag.value for tag in child_tags) elif name == "shape": current_tag.value = tuple(int(item) for item in current_tag.content.split()) elif name == "cells": current_tag.value = numpy.array([eval(item) for item in current_tag.content.split()]) elif name == "array": child_dict = dict((tag.name, tag.value) for tag in child_tags) current_tag.value = numpy.reshape(child_dict["cells"], child_dict["shape"]) elif name == "grid": current_tag.value = numpy.reshape(numpy.array([eval(item) for item in current_tag.content.split()]), (int(current_tag.attributes["rows"]), int(current_tag.attributes["cols"]), -1)) elif name == "binary": current_tag.value = StringIO.StringIO() current_tag.content.seek(0) base64.decode(current_tag.content, current_tag.value) elif name == "translation": current_tag.value = Translation(child_tags[0].value) elif name == "rotation": current_tag.value = Rotation(child_tags[0].value) elif name == "transformation": child_dict = dict((tag.label, tag.value) for tag in child_tags) current_tag.value = Complete( child_dict["rotation_matrix"], child_dict["translation_vector"], ) elif name == "unit_cell": child_dict = dict((tag.label, tag.value) for tag in child_tags) current_tag.value = UnitCell( child_dict["matrix"], child_dict["active"], ) elif name == "expression": current_tag.value = Expression(current_tag.content) elif name == "reference": current_tag.value = None referent_tag = self.hierarchy[-3][-1] target_ids = self.target_ids.get(referent_tag) if target_ids is None: target_ids = [] self.target_ids[referent_tag] = target_ids target_ids.append(int(current_tag.attributes["to"])) elif name == "model_object": Class = context.application.plugins.get_node(str(current_tag.attributes["class"])) current_tag.state = dict((tag.label, tag.value) for tag in child_tags) current_tag.value = Class() self.model_object_tags[int(current_tag.attributes["id"])] = current_tag else: pass # close the door current_tag.content = None current_tag.close() if len(child_tags) > 0: self.hierarchy.pop()