Beispiel #1
0
    def serialize(self):
        """
        serialize the message to display. DON't forget to call the serialize
        method of command.
        """

        return Command.serialize(self) + tokenizeValue("message",
                                                       self._message)
Beispiel #2
0
    def serialize(self):
        """
        serialize the data needed by the command to undo/redo the created link
        """
        # serialize the data common to all commands
        serialShape = Command.serialize(self)
        # get the pyutId of the source OglObject of the link
        srcId = self._link.getSourceShape().getPyutObject().getId()
        # get the pyutId of the destination OglObject of the link
        dstId = self._link.getDestinationShape().getPyutObject().getId()
        # get the model start position of the link
        srcPos = self._link.GetSource().GetModel().GetPosition()
        # get the model end position of the link
        dstPos = self._link.GetDestination().GetModel().GetPosition()
        # get the type of the link (see OglLinkFactory)
        linkType = getLinkType(self._link)
        # get the pyutId of the link
        linkId = self._link.getPyutObject().getId()
        # serialize required data needed to undo/redo the link
        serialShape += tokenizeValue("srcId", repr(srcId))
        serialShape += tokenizeValue("dstId", repr(dstId))
        serialShape += tokenizeValue("srcPos", repr(srcPos))
        serialShape += tokenizeValue("dstPos", repr(dstPos))
        serialShape += tokenizeValue("linkType", repr(linkType))
        serialShape += tokenizeValue("linkId", repr(linkId))

        return serialShape
Beispiel #3
0
    def serialize(self) -> str:

        serializedShape: str = super().serialize()

        #
        # serialize the class and module of the ogl and pyut shape to get the
        # constructors for the deserialization
        #
        oglShapeModule: str = self._shape.__module__
        oglShapeClass: str = self._shape.__class__.__name__
        pyutShapeModule: str = self._shape.pyutObject.__module__
        pyutShapeClass: str = self._shape.pyutObject.__class__.__name__

        serializedShape += tokenizeValue("oglShapeModule", oglShapeModule)
        serializedShape += tokenizeValue("oglShapeClass", oglShapeClass)
        serializedShape += tokenizeValue("pyutShapeModule", pyutShapeModule)
        serializedShape += tokenizeValue("pyutShapeClass", pyutShapeClass)

        pyutObj = self._shape.pyutObject

        shapeId: int = pyutObj.getId()
        serializedShape += tokenizeValue("shapeId", repr(shapeId))

        shapeName: str = pyutObj.getName()
        serializedShape += tokenizeValue("shapeName", shapeName)

        methodInformation: str = MethodInformation.serialize(
            pyutClassCommon=pyutObj)
        serializedShape += methodInformation

        return serializedShape
    def serialize(self) -> str:

        serialShape: str = super().serialize()
        #
        # serialize the class and module of the ogl and pyut shape to get the
        # constructors for the deserialization
        oglShapeModule: str = self._shape.__module__
        oglShapeClass: str = self._shape.__class__.__name__
        pyutShapeModule: str = self._shape.getPyutObject().__module__
        pyutShapeClass: str = self._shape.getPyutObject().__class__.__name__

        serialShape += tokenizeValue("oglShapeModule", oglShapeModule)
        serialShape += tokenizeValue("oglShapeClass", oglShapeClass)
        serialShape += tokenizeValue("pyutShapeModule", pyutShapeModule)
        serialShape += tokenizeValue("pyutShapeClass", pyutShapeClass)
        # This is interesting:
        # serialize the shape's model size and position and NOT the Ogl(view)'s
        # ones because a zoom could be performed in between.
        #

        # TODO using the following causes 'Invalid or prematurely-freed autorelease pool 0x7fed3d8f3218.'
        # boo hoo;  no typing for me
        # from org.pyut.miniogl.RectangleShapeModel import RectangleShapeModel
        # model: RectangleShapeModel = self._shape.GetModel()
        model = self._shape.GetModel()
        pos: Tuple[int, int] = model.GetPosition()
        size: Tuple[int, int] = model.GetSize()
        serialShape += tokenizeValue("position", repr(pos))
        serialShape += tokenizeValue("size", repr(size))
        #
        # serialize the graphical links (Ogl) attached to the shape
        # and put it in the common data of the group. We have to do
        # so because the link can be rebuilt only after the
        # shape is rebuilt and so the command for link deletion
        # must be placed after this one.
        #
        from org.pyut.history.commands.DelOglLinkCommand import DelOglLinkCommand
        for link in self._shape.getLinks():
            if not link.IsSelected():
                cmd: DelOglLinkCommand = DelOglLinkCommand(link)
                self.getGroup().addCommand(cmd)

        # serialize data to initialize the associated pyutObject
        pyutObj = self._shape.getPyutObject()
        shapeId: int = pyutObj.getId()
        shapeName: str = pyutObj.getName()
        serialShape += tokenizeValue("shapeId", repr(shapeId))
        serialShape += tokenizeValue("shapeName", shapeName)

        return serialShape
Beispiel #5
0
    def serialize(self) -> str:
        """

        Serialize the module name and class name;  All command must call
        this method in their implementation

        Notes:  Use `makeValuatedToken()` from HistoryUtils for each value
        you want to serialize

        Then you can use the `getTokenValue()` to get
        back the string representation of this value for the deserialization.

        Returns:  String representation of the command in view to store it
                  in a file. This method must be full implemented in all
                  subclasses.

                `return Command.serialize + (MyCommand's serialized information)`
        """
        moduleId: str = tokenizeValue(COMMAND_MODULE_ID, str(self.__module__))
        classId: str = tokenizeValue(COMMAND_CLASS_ID,
                                     str(self.__class__.__name__))

        return f'{moduleId}{classId}'
Beispiel #6
0
    def serialize(cls, pyutClassCommon: PyutClassCommon) -> str:

        serializedInfo: str = ''

        methods = []
        for method in pyutClassCommon.methods:
            methodName: str = method.getName()
            methodVisibility: str = method.getVisibility().__str__()
            methodReturns: str = method.getReturns().__str__()

            params = []
            for param in method.getParams():
                paramName: str = param.getName()
                paramType: str = param.getType().__str__()
                paramDefaultValue: str = param.getDefaultValue()

                params.append((paramName, paramType, paramDefaultValue))

            modifiers = []
            for modifier in method.getModifiers():
                modifierName = modifier.getName()
                modifiers.append(modifierName)

            methodProfile: Tuple[str, str, str, str,
                                 str] = (methodName, methodVisibility,
                                         methodReturns, repr(params),
                                         repr(modifiers))

            methods.append(methodProfile)

        classDescription: str = pyutClassCommon.description

        serializedInfo += tokenizeValue("classDescription", classDescription)
        serializedInfo += tokenizeValue("methods", repr(methods))

        return serializedInfo
Beispiel #7
0
    def serialize(self):
        """
        Serialize the data needed by the destroyed OglLinkedObject.

        Returns: A string representation of the data needed by the command.
        """

        # serialize the common data common
        serializedShape: str = DeleteOglObjectCommand.serialize(self)

        fileName: str = self._shape.getPyutObject().getFilename()

        serializedShape += tokenizeValue("fileName", fileName)

        return serializedShape
Beispiel #8
0
    def serialize(self):
        """
        Transform all the commands belonging to the group into strings in
        view to store them in a file.
        @return a string representing the command.
        """
        # add the beginning information of the group
        serializedGroup = (tokenize(GROUP_BEGIN_ID) + tokenizeValue(GROUP_COMMENT_ID, self._comment))
        # add the beginning information and setup information of
        # each command. After that add the ending information of
        # for each command.
        for command in self._commands:
            serializedGroup += (tokenize(COMMAND_BEGIN_ID) + command.serialize() + tokenize(COMMAND_END_ID))

        # add the ending information of the group
        serializedGroup += tokenize(GROUP_END_ID)

        return serializedGroup
Beispiel #9
0
    def serialize(self):

        serialLink = Command.serialize(self)

        self._srcPosition = self._shape.GetSource().GetModel().GetPosition()
        self._destPosition = self._shape.GetDestination().GetModel(
        ).GetPosition()
        self._linkType = getLinkType(self._shape)
        self._linkSrcId = self._shape.getSourceShape().getPyutObject().getId()
        self._linkDestId = self._shape.getDestinationShape().getPyutObject(
        ).getId()
        self._linkId = self._shape.getPyutObject().getId()

        serialLink += tokenizeValue("srcPosition", repr(self._srcPosition))
        serialLink += tokenizeValue("destPosition", repr(self._destPosition))
        serialLink += tokenizeValue("linkType", repr(self._linkType))
        serialLink += tokenizeValue("linkSrcId", repr(self._linkSrcId))
        serialLink += tokenizeValue("linkDestId", repr(self._linkDestId))
        serialLink += tokenizeValue("linkId", repr(self._linkId))

        return serialLink
Beispiel #10
0
    def serialize(self) -> str:
        """
        Serialize an OglClass

        Returns:  A string representation of the data needed by the command.
        """
        # serialize the data common to all OglObjects
        serialShape = DeleteOglLinkedObjectCommand.serialize(self)

        pyutClass: PyutClass = self._shape.getPyutObject()
        classDescription = pyutClass.description

        if pyutClass.getStereotype() is not None:
            classStereotypeName = pyutClass.getStereotype().getName()
        else:
            classStereotypeName = ""

        classShowStereotype = repr(pyutClass.getShowStereotype())
        classShowMethods = repr(pyutClass.showMethods)
        classShowFields = repr(pyutClass.showFields)

        fields = []
        for field in pyutClass.fields:
            fieldName = field.getName()
            fieldType = field.getType().__str__()
            fieldDefaultValue = field.getDefaultValue()
            fieldVisibility = field.getVisibility().__str__()
            fields.append(
                (fieldName, fieldType, fieldDefaultValue, fieldVisibility))

        methods = []
        for method in pyutClass.methods:
            methodName = method.getName()
            methodVisibility = method.getVisibility().__str__()
            methodReturns = method.getReturns().__str__()

            params = []
            for param in method.getParams():
                paramName = param.getName()
                paramType = param.getType().__str__()
                paramDefaultValue = param.getDefaultValue()
                params.append((paramName, paramType, paramDefaultValue))

            modifiers = []
            for modifier in method.getModifiers():
                modifierName = modifier.getName()
                modifiers.append(modifierName)

            methodProfile = (methodName, methodVisibility, methodReturns,
                             repr(params), repr(modifiers))

            methods.append(methodProfile)

        serialShape += tokenizeValue("classDescription", classDescription)
        serialShape += tokenizeValue("classStereotypeName",
                                     classStereotypeName)
        serialShape += tokenizeValue("classShowStereotype",
                                     classShowStereotype)
        serialShape += tokenizeValue("classShowMethods", classShowMethods)
        serialShape += tokenizeValue("classShowFields", classShowFields)
        serialShape += tokenizeValue("fields", repr(fields))
        serialShape += tokenizeValue("methods", repr(methods))

        return serialShape