def load_links(self, links): # get all known transformations space = SpatialInterpolation() time = TemporalInterpolation() spatial_transformations = {i.name(): i for i in space.methods()} temporal_transformations = {i.name(): i for i in time.methods()} links_to_add = [] for link in links: # get 'from' and 'to' model attributes from_model_id = link['from_id'] from_model_item = link['from_item'] from_model_name = link['from_name'] to_model_id = link['to_id'] to_model_item = link['to_item'] to_model_name = link['to_name'] from_model = self.get_model_object_from_ID(from_model_id) to_model = self.get_model_object_from_ID(to_model_id) if from_model is None or to_model is None: elog.critical("Failed to create link between %s and %s." % (from_model_name, to_model_name)) sPrint( "Failed to create link between %s and %s." % (from_model_name, to_model_name), MessageType.CRITICAL) return sPrint('Adding link between: %s and %s... ' % (from_model_name, to_model_name)) # get the spatial and temporal transformations temporal_transformation_name = link['temporal_transformation'] spatial_transformation_name = link['spatial_transformation'] # set the transformation values temporal = temporal_transformations[ temporal_transformation_name] if temporal_transformation_name.lower( ) != 'none' else None spatial = spatial_transformations[ spatial_transformation_name] if spatial_transformation_name.lower( ) != 'none' else None # create the link engine.addLink(source_id=from_model_id, source_item=from_model_item, target_id=to_model_id, target_item=to_model_item, spatial_interpolation=spatial, temporal_interpolation=temporal) links_to_add.append([from_model, to_model]) wx.CallAfter(self.createLoadedLinks, links_to_add)
def load_links(self, links): # get all known transformations space = SpatialInterpolation() time = TemporalInterpolation() spatial_transformations = {i.name(): i for i in space.methods()} temporal_transformations = {i.name(): i for i in time.methods()} links_to_add = [] for link in links: # get 'from' and 'to' model attributes from_model_id = link['from_id'] from_model_item = link['from_item'] from_model_name = link['from_name'] to_model_id = link['to_id'] to_model_item = link['to_item'] to_model_name = link['to_name'] from_model = self.get_model_object_from_ID(from_model_id) to_model = self.get_model_object_from_ID(to_model_id) if from_model is None or to_model is None: elog.critical("Failed to create link between %s and %s." % (from_model_name, to_model_name)) sPrint("Failed to create link between %s and %s." % (from_model_name, to_model_name), MessageType.CRITICAL) return sPrint('Adding link between: %s and %s... ' % (from_model_name, to_model_name)) # get the spatial and temporal transformations temporal_transformation_name = link['temporal_transformation'] spatial_transformation_name = link['spatial_transformation'] # set the transformation values temporal = temporal_transformations[temporal_transformation_name] if temporal_transformation_name.lower() != 'none' else None spatial = spatial_transformations[spatial_transformation_name] if spatial_transformation_name.lower() != 'none' else None # create the link engine.addLink(source_id=from_model_id, source_item=from_model_item, target_id=to_model_id, target_item=to_model_item, spatial_interpolation=spatial, temporal_interpolation=temporal) links_to_add.append([from_model, to_model]) wx.CallAfter(self.createLoadedLinks, links_to_add)
def on_save(self, event): """ Saves all link objects to the engine and then closes the link creation window """ # Deleting the links that are in the delete queue for link_id in self.links_to_delete: engine.removeLinkById(link_id) if link_id in self.__links: self.__links.pop(link_id) warnings = [] errors = [] for l in self.__links.values(): if l.iei == "---" or l.oei == "--": warnings.append(l) else: try: kwargs = dict( source_id=l.source_id, source_item=l.oei, target_id=l.target_id, target_item=l.iei, spatial_interpolation=l.spatial_interpolation, temporal_interpolation=l.temporal_interpolation, uid=l.uid, ) # remove the existing link, if there is one engine.removeLinkById(l.uid) # add a new link inside the engine link_id = engine.addLink(**kwargs) if link_id: l.saved = True wx.PostEvent(self, LinkUpdatedEvent()) except: elog.error("ERROR|Could not save link: %s" % l.name) errors.append(l) if len(warnings) > 0: warning_links = "\n".join(l.name() for l in warnings) warning = wx.MessageDialog( self, "Could not save the following links because they lacking either input or output items: \n\n " + warning_links + "\n\n Would you like to discard these partial link objects?", "Question", wx.YES_NO | wx.NO_DEFAULT | wx.ICON_WARNING, ) if warning.ShowModal() == wx.ID_YES: self.remove_warning_links(warnings=warnings) self.Destroy() else: return result = self.find_link_direction() if result: # todo: these images need to be coming from config instead of hardcoded self.replace_canvas_image(image="rightArrowBlue60.png", one_way=True) elif result is False: self.replace_canvas_image(image="multiArrow.png") else: self.replace_canvas_image(image="questionMark.png") self.Destroy()
def on_save(self, event): """ Saves all link objects to the engine and then closes the link creation window """ # Deleting the links that are in the delete queue for link_id in self.links_to_delete: engine.removeLinkById(link_id) if link_id in self.__links: self.__links.pop(link_id) warnings = [] errors = [] for l in self.__links.values(): if l.iei == '---' or l.oei == '--': warnings.append(l) else: try: kwargs = dict(source_id=l.source_id, source_item=l.oei, target_id=l.target_id, target_item=l.iei, spatial_interpolation=l.spatial_interpolation, temporal_interpolation=l.temporal_interpolation, uid=l.uid) # remove the existing link, if there is one engine.removeLinkById(l.uid) # add a new link inside the engine link_id = engine.addLink(**kwargs) if link_id: l.saved = True wx.PostEvent(self, LinkUpdatedEvent()) except: elog.error('ERROR|Could not save link: %s' % l.name) errors.append(l) if len(warnings) > 0: warning_links = '\n'.join(l.name() for l in warnings) warning = wx.MessageDialog(self, "Could not save the following links because they lacking either input or output items: \n\n " + warning_links + "\n\n Would you like to discard these partial link objects?", 'Question', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_WARNING) if warning.ShowModal() == wx.ID_YES: self.remove_warning_links(warnings=warnings) self.Destroy() else: return result = self.find_link_direction() if result: # todo: these images need to be coming from config instead of hardcoded self.replace_canvas_image(image="rightArrowBlue60.png", one_way=True) elif result is False: self.replace_canvas_image(image="multiArrow.png") else: self.replace_canvas_image(image="questionMark.png") self.Destroy()