def deserialize(self, serializedShape: str): self._oglShapeClassName = deTokenize("oglShapeClass", serializedShape) self._oglShapeModuleName = deTokenize("oglShapeModule", serializedShape) self._pyutShapeClassName = deTokenize("pyutShapeClass", serializedShape) self._pyutShapeModuleName = deTokenize("pyutShapeModule", serializedShape)
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 do not need any more 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 = deTokenize(COMMAND_MODULE_ID, serialCommand) self.logger.info(f'commandModuleName: {commandModuleName}') # get the name of the class of the command commandClassName = deTokenize(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}')
def deserialize(cls, serializedData: str, pyutObject: PyutClassCommon) -> PyutClassCommon: """ Args: serializedData: pyutObject: Returns: The updated PyutClass or PyutInterface """ classDescription = deTokenize("classDescription", serializedData) pyutObject.description = classDescription methods = eval(deTokenize("methods", serializedData)) pyutMethods: List[PyutMethod] = [] for methodProfile in methods: # construction of a method methodName: str = methodProfile[0] methodVisibility: PyutVisibilityEnum = PyutVisibilityEnum.toEnum( methodProfile[1]) methodReturns: PyutType = PyutType(value=methodProfile[2]) pyutMethod: PyutMethod = PyutMethod(name=methodName, visibility=methodVisibility, returns=methodReturns) # deserialize method's parameters; Get the tuple (name, Type, defaultValue) params = eval(methodProfile[3]) for param in params: paramName: str = param[0] paramType: PyutType = PyutType(param[1]) paramDefaultValue: str = param[2] # creates and add the param to the method pyutParam: PyutParam = PyutParam( name=paramName, parameterType=paramType, defaultValue=paramDefaultValue) pyutMethod.addParam(pyutParam) pyutMethods.append(pyutMethod) pyutObject.methods = pyutMethods return pyutObject
def deserialize(self, serialCommand): """ get from the serialized command the message to display and init the corresponding attribute. @param serialCommand : serialized command """ self._message = deTokenize("message", serialCommand)
def deserialize(self, serializedData: str): """ Deserialize the data needed to undo/redo a delete command and create shape Args: serializedData: """ oglShapeClassName: str = deTokenize("oglShapeClass", serializedData) oglShapeModuleName: str = deTokenize("oglShapeModule", serializedData) pyutShapeClassName: str = deTokenize("pyutShapeClass", serializedData) pyutShapeModuleName: str = deTokenize("pyutShapeModule", serializedData) shapeName: str = deTokenize("shapeName", serializedData) # name of the pyutObject shapeId: int = eval(deTokenize("shapeId", serializedData)) shapePosition: Tuple[float, float] = eval( deTokenize("position", serializedData)) shapeSize: Tuple[float, float] = eval(deTokenize("size", serializedData)) # # Construct the UML objects 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 # break up for testability # group = self._group history = group.getHistory() frame = history.getFrame() self._shape = frame.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])
def deserialize(self, serializedData: str): """ deserialize the data needed by the destroyed OglLinkedObject. Args: serializedData: Returns: deserialized data needed by the command. """ # deserialize the data common to all OglObjects DeleteOglObjectCommand.deserialize(self, serializedData) fileName = deTokenize("fileName", serializedData) self._shape.getPyutObject().setFilename(fileName)
def _deserialize(self, serializedGroup) -> CommandGroup: """ deserialize the specified string to return a command group Args: serializedGroup: (string) : string from which will be constructed the group Returns: an initialized group (CommandGroup) """ # get from the string the comment/description for the group grpComment = deTokenize(GROUP_COMMENT_ID, serializedGroup) # create an initialized group with only its comment group = CommandGroup(grpComment) group.setHistory(self) # deserialize the commands belonging to the group group.deserialize(serializedGroup) return group
def deserialize(self, serializedInfos): umlFrame = self.getGroup().getHistory().getFrame() self._srcPosition = eval(deTokenize("srcPosition", serializedInfos)) self._destPosition = eval(deTokenize("destPosition", serializedInfos)) linkTypeStr: str = deTokenize("linkType", serializedInfos) self._linkType = LinkType.toEnum(linkTypeStr) self._linkSrcId = eval(deTokenize("linkSrcId", serializedInfos)) self._linkDestId = eval(deTokenize("linkDestId", serializedInfos)) self._linkId = eval(deTokenize("linkId", serializedInfos)) self._shape = umlFrame.getUmlObjectById(self._linkId)
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(deTokenize("srcId", serializedInfo)) # get the pyutId of the destination OglObject of the link dstId = eval(deTokenize("dstId", serializedInfo)) # get the model (MVC pattern) start position of the link srcPos = eval(deTokenize("srcPos", serializedInfo)) # get the model (MVC pattern) end position of the link dstPos = eval(deTokenize("dstPos", serializedInfo)) # get the type of the link (see LinkType enumeration) linkValue: str = deTokenize("linkType", serializedInfo) linkType: LinkType = LinkType.toEnum(linkValue) # get the pyutId of the link linkId = eval(deTokenize("linkId", serializedInfo)) # get the frame to which belongs the link umlFrame = self.getGroup().getHistory().getFrame() # if the link has been created it already exists in the frame. # But if an undo command 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 do not add it to the frame. # the model position is assigned to a temporary to # view, but will be reassigned to the model, after # it has been added to the frame, because the zoom # could have changed, 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 pyutObject = self._link.getPyutObject() pyutObject.setId(linkId)
def deserialize(self, serializedData): """ Deserialize the data needed by the deleted OglCass 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 DeleteOglLinkedObjectCommand.deserialize(self, serializedData) # deserialize properties of the OglClass (first level) classDescription = deTokenize("classDescription", serializedData) classStereotypeName = deTokenize("classStereotypeName", serializedData) classShowStereotype = eval( deTokenize("classShowStereotype", serializedData)) classShowMethods = eval(deTokenize("classShowMethods", serializedData)) classShowFields = eval(deTokenize("classShowFields", serializedData)) methods = eval(deTokenize("methods", serializedData)) fields = eval(deTokenize("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: str = methodProfile[0] methodVisibility: PyutVisibilityEnum = PyutVisibilityEnum.toEnum( methodProfile[1]) methodReturns: PyutType = PyutType(value=methodProfile[2]) method = PyutMethod(name=methodName, visibility=methodVisibility, returns=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