Ejemplo n.º 1
0
 def create_one_way_arrow(self, image, models):
     #  Only call this method if all the links go the same direction
     #  Draws the arrow based off the direction of the links
     if engine.getModelById(models[0].ID)["name"] == engine.getModelById(self.__links.values()[0].source_id)["name"]:
         self.parent.Parent.createLine(R1=models[0], R2=models[1], image_name=image)
     else:
         self.parent.Parent.createLine(R1=models[1], R2=models[0], image_name=image)
Ejemplo n.º 2
0
 def create_one_way_arrow(self, image, models):
     #  Only call this method if all the links go the same direction
     #  Draws the arrow based off the direction of the links
     if engine.getModelById(models[0].ID)["name"] == engine.getModelById(self.__links.values()[0].source_id)["name"]:
         self.parent.Parent.createLine(R1=models[0], R2=models[1], image_name=image)
     else:
         self.parent.Parent.createLine(R1=models[1], R2=models[0], image_name=image)
Ejemplo n.º 3
0
    def populate_grid_by_model_object(self):
        if not isinstance(self.model_object, ModelBox):
            sPrint("ModelDetails.model_object needs to by type ModelBox")
            return

        model_as_json = engineAccessors.getModelById(self.model_object.ID)

        if not isinstance(model_as_json, dict):
            sPrint("ModelDetailsCtrl.populate_grid_by_model_object.model_as_json needs to be type dictionary")
            return

        if "params" in model_as_json:
            if "path" in model_as_json["params"]:
                self._data = models.parse_json(model_as_json["params"]["path"])
                self.grid.add_data(self._data)
                return

        elif "attrib" in model_as_json:
            if "mdl" in model_as_json["attrib"]:
                self._data = models.parse_json(model_as_json["attrib"]["mdl"])
                self.grid.add_data(self._data)
                return

        self.grid.add_section("General")
        for key, value in model_as_json.iteritems():
            if isinstance(value, dict):
                self.grid.add_dictionary(value, key)
            else:
                self.grid.add_data_to_section(0, key, value)
        return
Ejemplo n.º 4
0
    def populate_grid_by_model_object(self):
        if not isinstance(self.model_object, ModelBox):
            sPrint("ModelDetails.model_object needs to by type ModelBox")
            return

        model_as_json = engineAccessors.getModelById(self.model_object.ID)

        if not isinstance(model_as_json, dict):
            sPrint(
                "ModelDetailsCtrl.populate_grid_by_model_object.model_as_json needs to be type dictionary"
            )
            return

        if "params" in model_as_json:
            if "path" in model_as_json["params"]:
                self._data = models.parse_json(model_as_json["params"]["path"])
                self.grid.add_data(self._data)
                return

        elif "attrib" in model_as_json:
            if "mdl" in model_as_json["attrib"]:
                self._data = models.parse_json(model_as_json["attrib"]["mdl"])
                self.grid.add_data(self._data)
                return

        self.grid.add_section("General")
        for key, value in model_as_json.iteritems():
            if isinstance(value, dict):
                self.grid.add_dictionary(value, key)
            else:
                self.grid.add_data_to_section(0, key, value)
        return
Ejemplo n.º 5
0
    def on_arrow_clicked(self, event):

        # get the models associated with the link
        models = self.arrows[event]

        # get r1 and r2
        r1 = models[0]
        r2 = models[1]

        # get output items from r1
        from_model = engine.getModelById(r1.ID)

        # get output items from r1
        to_model = engine.getModelById(r2.ID)

        controller = LinkCtrl(parent=self.FloatCanvas, outputs=from_model, inputs=to_model, link_obj=event)
        controller.Show()
Ejemplo n.º 6
0
    def save_simulation(self, path):

        model_list = []
        canvas_shapes = []
        for shape, modelid in self.models.iteritems():
            model_list.append(engine.getModelById(modelid))
            canvas_shapes.append(shape)
        links = engine.getAllLinks()
        model_utils.write_simulation_json(model_list, canvas_shapes, links, path)
        return
Ejemplo n.º 7
0
    def on_arrow_clicked(self, event):

        # get the models associated with the link
        models = self.arrows[event]

        # get r1 and r2
        r1 = models[0]
        r2 = models[1]

        # get output items from r1
        from_model = engine.getModelById(r1.ID)

        # get output items from r1
        to_model = engine.getModelById(r2.ID)

        controller = LinkCtrl(parent=self.FloatCanvas,
                              outputs=from_model,
                              inputs=to_model,
                              link_obj=event)
        controller.Show()
Ejemplo n.º 8
0
    def save_simulation(self, path):

        model_list = []
        canvas_shapes = []
        for shape, modelid in self.models.iteritems():
            model_list.append(engine.getModelById(modelid))
            canvas_shapes.append(shape)
        links = engine.getAllLinks()
        model_utils.write_simulation_json(model_list, canvas_shapes, links,
                                          path)
        return
Ejemplo n.º 9
0
    def find_link_direction(self):
        # returns None if no link. Show question mark
        # return true if link goes one. Show one-way arrow
        # return false if links goes two ways. Show two-way arrow
        if len(self.__links) == 0:
            return None

        items = []
        for key, value in self.__links.iteritems():
            items.append(engine.getModelById(value.source_id)["name"])

        return all_same(items)
Ejemplo n.º 10
0
    def find_link_direction(self):
        # returns None if no link. Show question mark
        # return true if link goes one. Show one-way arrow
        # return false if links goes two ways. Show two-way arrow
        if len(self.__links) == 0:
            return None

        items = []
        for key, value in self.__links.iteritems():
            items.append(engine.getModelById(value.source_id)["name"])

        return all_same(items)
Ejemplo n.º 11
0
    def remove_model(self, model_obj):
        """
        Removes a model component from the modeling canvas
        :param model_obj: model object that will be removed
        :return: None
        """

        updated_links = {}
        links_to_remove = []
        for link, models in self.links.iteritems():
            if model_obj in models:
                links_to_remove.append(link)
            elif model_obj not in models:
                updated_links[link] = models

        self.links = updated_links

        engine.removeModelById(model_obj.ID)
        # engine.removeModelById is using deprecated functions and returns None, however the link is being removed.
        # to prevent issues with the drawing the if statement makes sure the link no longer exists in the engine
        if not engine.getModelById(model_obj.ID):

            try:
                # Update models list
                self.models.pop(model_obj)

                # Remove selected model and text box from FloatCanvas
                self.FloatCanvas.RemoveObjects([model_obj])
            except Exception, e:
                msg = 'Encountered and error when removing model from canvas: %s' % e
                sPrint(msg, MessageType.ERROR)

            try:
                # Remove the model's SmoothLineWithArrow obj with builtin remove function
                for link in links_to_remove:
                    # remove the link object from the DrawList if it exists.  It may not exist in the DrawList for bidirectional links.
                    if link in self.FloatCanvas._DrawList:
                        link.Remove(self.FloatCanvas)
            except Exception, e:
                msg = 'Encountered and error when removing link from canvas: %s' % e
                sPrint(msg, MessageType.ERROR)
Ejemplo n.º 12
0
    def remove_model(self, model_obj):
        """
        Removes a model component from the modeling canvas
        :param model_obj: model object that will be removed
        :return: None
        """

        updated_links = {}
        links_to_remove = []
        for link, models in self.links.iteritems():
            if model_obj in models:
                links_to_remove.append(link)
            elif model_obj not in models:
                updated_links[link] = models

        self.links = updated_links

        engine.removeModelById(model_obj.ID)
        # engine.removeModelById is using deprecated functions and returns None, however the link is being removed.
        # to prevent issues with the drawing the if statement makes sure the link no longer exists in the engine
        if not engine.getModelById(model_obj.ID):

            try:
                # Update models list
                self.models.pop(model_obj)

                # Remove selected model and text box from FloatCanvas
                self.FloatCanvas.RemoveObjects([model_obj])
            except Exception, e:
                msg = 'Encountered and error when removing model from canvas: %s' % e
                sPrint(msg, MessageType.ERROR)

            try:
                # Remove the model's SmoothLineWithArrow obj with builtin remove function
                for link in links_to_remove:
                    # remove the link object from the DrawList if it exists.  It may not exist in the DrawList for bidirectional links.
                    if link in self.FloatCanvas._DrawList:
                        link.Remove(self.FloatCanvas)
            except Exception, e:
                msg = 'Encountered and error when removing link from canvas: %s' % e
                sPrint(msg, MessageType.ERROR)