예제 #1
0
    def deserialize(self, serializedCommands: str):
        """
        deserialize the specified commands and add them to the group

        Args:
            serializedCommands:   a string representation of the commands belonging to the group.
        """
        # define the beginning and ending token of a serialized command
        commandBegin = TOKEN_BEGIN + COMMAND_BEGIN_ID + TOKEN_END
        commandEnd = TOKEN_BEGIN + COMMAND_END_ID + TOKEN_END

        # looking for the beginning of the first command
        cStart = serializedCommands.find(commandBegin)
        self.logger.info(f'cStart: {cStart}')
        # while there is still a command beginning token we can proceed to the deserialization.
        while cStart > -1:

            # we don't need anymore of the beginning token
            cStart += len(commandBegin)
            self.logger.info(f'cStart - commandBegin: {cStart}')

            # find the ending token for this command
            cEnd = serializedCommands.find(commandEnd, cStart)

            # we work only on the useful data
            serialCommand = serializedCommands[cStart:cEnd]

            commandModuleName = getTokenValue(COMMAND_MODULE_ID, serialCommand)
            self.logger.info(f'commandModuleName: {commandModuleName}')

            # get the name of the class of the command
            commandClassName = getTokenValue(COMMAND_CLASS_ID, serialCommand)
            self.logger.info(f'commandClassName: {commandClassName}')

            # import the module which contains the command class and get the class (cls)
            moduleName = import_module(commandModuleName)
            commandClass = getattr(moduleName, commandClassName)

            # construction of an uninitialized command
            try:
                command = commandClass()
                command.setGroup(self)

                # deserialization and setup of the command
                command.deserialize(serialCommand)

                # add the command to the group
                self.addCommand(command)

                # looking for the next command beginning token
                cStart = serializedCommands.find(commandBegin, cEnd)
                self.logger.info(f'cStart - serializedCommands: {cStart}')

            except (ValueError, Exception) as e:
                self.logger.error(f'Error during deserialization: {e}')
예제 #2
0
    def deserialize(self, serialCommand):
        """
        get from the serialized command the message to display
        and init the corresponding attribute.
        @param serialCommand    :   serialized command
        """

        self._message = getTokenValue("message", serialCommand)
예제 #3
0
    def deserialize(self, serializedData):
        """
        Deserialize the data needed to undo/redo a delete command and createa shape
        Args:
            serializedData:
        """

        oglShapeClassName: str = getTokenValue("oglShapeClass", serializedData)
        oglShapeModuleName: str = getTokenValue("oglShapeModule",
                                                serializedData)
        pyutShapeClassName: str = getTokenValue("pyutShapeClass",
                                                serializedData)
        pyutShapeModuleName: str = getTokenValue("pyutShapeModule",
                                                 serializedData)

        shapeName: str = getTokenValue(
            "shapeName", serializedData)  # name of the pyutObject
        shapeId: int = eval(getTokenValue("shapeId", serializedData))

        shapePosition: Tuple[float, float] = eval(
            getTokenValue("position", serializedData))
        shapeSize: Tuple[float,
                         float] = eval(getTokenValue("size", serializedData))
        #
        # Construct the UML objects
        # import the module which contains the ogl and pyut shape classes and instantiate the classes
        # oglShapeClass = getattr(__import__(oglShapeModule), oglShapeClassName)
        # pyutShapeClass = getattr(__import__(pyutShapeModule), pyutShapeClassName)
        oglModule = import_module(oglShapeModuleName)
        oglShapeClass = getattr(oglModule, oglShapeClassName)

        pyutModule = import_module(pyutShapeModuleName)
        pyutShapeClass = getattr(pyutModule, pyutShapeClassName)
        #
        # build the pyutObject : it assumes that every parameter of the
        # constructor has a default value
        #
        self._shape = self.getGroup().getHistory().getFrame().getUmlObjectById(
            shapeId)

        if self._shape is None:

            pyutShape = pyutShapeClass(shapeName)
            pyutShape.setId(shapeId)

            # build the OglObject : it suppose that every parameter of the
            # constructor has a default value
            self._shape = oglShapeClass()
            self._shape.setPyutObject(pyutShape)
            self._shape.GetModel().SetPosition(shapePosition[0],
                                               shapePosition[1])
            self._shape.GetModel().SetSize(shapeSize[0], shapeSize[1])
예제 #4
0
    def _unserialize(self, serializedGroup):
        """
        unserialize the specified string to return a command group
        @param serialized (string)  :   string from which will be
                                        constructed the group
        @return an initialized group (CommandGroup)
        """

        # get from the string the comment/description for the group
        grpComment = getTokenValue(GROUP_COMMENT_ID, serializedGroup)

        # create an initialized group with only its comment
        group = CommandGroup.CommandGroup(grpComment)
        group.setHistory(self)

        # unserialize the commands belonging to the group
        group.deserialize(serializedGroup)

        return group
예제 #5
0
    def deserialize(self, serializedInfos):

        umlFrame = self.getGroup().getHistory().getFrame()

        self._srcPosition = eval(getTokenValue("srcPosition", serializedInfos))
        self._destPosition = eval(
            getTokenValue("destPosition", serializedInfos))

        linkTypeStr: str = getTokenValue("linkType", serializedInfos)
        self._linkType = LinkType.toEnum(linkTypeStr)

        self._linkSrcId = eval(getTokenValue("linkSrcId", serializedInfos))
        self._linkDestId = eval(getTokenValue("linkDestId", serializedInfos))
        self._linkId = eval(getTokenValue("linkId", serializedInfos))

        self._shape = umlFrame.getUmlObjectById(self._linkId)
예제 #6
0
    def deserialize(self, serializedInfo: str):
        """
        deserialize the data needed by the command to undo/redo the created link
        @param serializedInfo    :   string representation of the data needed by the command to undo redo a link
        """

        # deserialize the data common to all commands
        Command.deserialize(self, serializedInfo)
        # get the pyutId of the source OglObject of the link
        srcId = eval(getTokenValue("srcId", serializedInfo))
        # get the pyutId of the destination OglObject of the link
        dstId = eval(getTokenValue("dstId", serializedInfo))
        # get the model (MVC pattern) start position of the link
        srcPos = eval(getTokenValue("srcPos", serializedInfo))
        # get the model (MVC pattern) end position of the link
        dstPos = eval(getTokenValue("dstPos", serializedInfo))
        # get the type of the link (see OglLinkFactory)
        linkType = eval(getTokenValue("linkType", serializedInfo))
        # get the pyutId of the link
        linkId = eval(getTokenValue("linkId", serializedInfo))
        # get the frame to which belongs the link
        umlFrame = self.getGroup().getHistory().getFrame()

        # if the link has been created it already exist on the frame.
        # But if an undo has been performed, we have to rebuild the link.
        self._link = umlFrame.getUmlObjectById(linkId)
        if self._link is None:

            # get the source and destination OglObjects of the link
            src = umlFrame.getUmlObjectById(srcId)
            dst = umlFrame.getUmlObjectById(dstId)
            # create the link, but don't add it to the frame.
            # the model position is assigned to temporary to
            # view, but will be reassigned to the model, after
            # it has been added to the frame, because the zoom
            # could have change and we have to update from the
            # model (see redo() method).
            self._link = self._createLink(src, dst, linkType, srcPos, dstPos)
            # we set the pyutId that the link has at its first creation
            self._link.getPyutObject().setId(linkId)
예제 #7
0
    def deserialize(self, serializedData):
        """
        deserialize the data needed by the destroyed OglLinkedObject.

        Args:
            serializedData: serialized data needed by the command.
        """
        from org.pyut.model.PyutMethod import PyutMethod
        from org.pyut.model.PyutParam import PyutParam
        from org.pyut.model.PyutField import PyutField

        from org.pyut.model.PyutStereotype import PyutStereotype
        from org.pyut.model.PyutModifier import PyutModifier

        # deserialize the data common to all OglObjects
        DelOglLinkedObjectCommand.deserialize(self, serializedData)

        # deserialize properties of the OglClass (first level)
        classDescription = getTokenValue("classDescription", serializedData)
        classStereotypeName = getTokenValue("classStereotypeName",
                                            serializedData)
        classShowStereotype = eval(
            getTokenValue("classShowStereotype", serializedData))
        classShowMethods = eval(
            getTokenValue("classShowMethods", serializedData))
        classShowFields = eval(getTokenValue("classShowFields",
                                             serializedData))

        methods = eval(getTokenValue("methods", serializedData))
        fields = eval(getTokenValue("fields", serializedData))

        # set up the first level properties of the pyutClass
        pyutClass: PyutClass = self._shape.getPyutObject()
        pyutClass.description = classDescription

        if cmp(classStereotypeName, ""):
            pyutStereo = PyutStereotype(classStereotypeName)
            pyutClass.setStereotype(pyutStereo)

        pyutClass.setShowStereotype(classShowStereotype)
        pyutClass.showMethods = classShowMethods
        pyutClass.showFields = classShowFields

        for field in fields:

            fieldName = field[0]
            fieldType = field[1]
            fieldDefaultValue = field[2]
            fieldVisibility = field[3]
            pyutClass.addField(
                PyutField(fieldName, fieldType, fieldDefaultValue,
                          fieldVisibility))

        methodsList = []
        # deserialize methods of the pyutClass
        for methodProfile in methods:

            # construction of a method
            methodName = methodProfile[0]
            methodVisibility = methodProfile[1]
            methodReturns = methodProfile[2]
            method = PyutMethod(methodName, methodVisibility, methodReturns)

            # deserialize method's params so we get a tuple (name, Type, defaultValue)
            params = eval(methodProfile[3])
            for param in params:
                paramName = param[0]

                # construction of the type of the param
                paramType = param[1]
                # pyutType = PyutType(paramType)   Not used
                paramDefaultValue = param[2]

                # creates and add the param to the method
                method.addParam(
                    PyutParam(paramName, paramType, paramDefaultValue))

            # deserialize method's modifiers so we get a list of names
            # that we have to transform into a list of PyutModifiers.
            modifiersNames = eval(methodProfile[4])
            modifiers = []
            for modifierName in modifiersNames:
                modifiers.append(PyutModifier(modifierName))

            # add the modifiers to the method
            method.setModifiers(modifiers)
            # add the method to the list of methods
            methodsList.append(method)

        # add all the methods to the list
        pyutClass.methods = methodsList