Exemple #1
0
        public override string GetTypeName(string rosTypeName, DetailedRosMessageType messageType)
        {
            if (!messageType.HasFlag(DetailedRosMessageType.Service))
            {
                return(base.GetTypeName(rosTypeName, messageType));
            }


            var baseName = base.GetTypeName(rosTypeName);

            switch (messageType)
            {
            case DetailedRosMessageType.ServiceRequest:
                return(baseName + ".Request");

            case DetailedRosMessageType.ServiceResponse:
                return(baseName + ".Response");

            case DetailedRosMessageType.Service:
                return(baseName);

            default:
                throw new NotSupportedException($"MessageType {messageType} is not supported");
            }
        }
        public virtual string GetRosTypeName(string rosTypeName, DetailedRosMessageType messageType)
        {
            switch (messageType)
            {
            case DetailedRosMessageType.None:
            case DetailedRosMessageType.Message:
            case DetailedRosMessageType.Service:
                return(rosTypeName);

            case DetailedRosMessageType.ActionGoal:
                return(rosTypeName + "Goal");

            case DetailedRosMessageType.ActionResult:
                return(rosTypeName + "Result");

            case DetailedRosMessageType.ActionFeedback:
                return(rosTypeName + "Feedback");

            case DetailedRosMessageType.ServiceRequest:
                return(rosTypeName + "Request");

            case DetailedRosMessageType.ServiceResponse:
                return(rosTypeName + "Response");

            default:
                throw new NotSupportedException($"Message type {messageType} is not supported.");
            }
        }
Exemple #3
0
        public override string GetRosTypeName(string rosTypeName, DetailedRosMessageType messageType)
        {
            switch (messageType)
            {
            case DetailedRosMessageType.ServiceRequest:
                return(rosTypeName + "__Request");

            case DetailedRosMessageType.ServiceResponse:
                return(rosTypeName + "__Response");

            default:
                return(base.GetRosTypeName(rosTypeName, messageType));
            }
        }
        public virtual string GetTypeName(string rosTypeName, DetailedRosMessageType messageType)
        {
            if (rosTypeName == null)
            {
                throw new ArgumentNullException(nameof(rosTypeName));
            }

            var typeName = rosTypeName.Trim();

            switch (messageType)
            {
            case DetailedRosMessageType.ActionGoal:
                typeName += "Goal";
                break;

            case DetailedRosMessageType.ActionResult:
                typeName += "Result";
                break;

            case DetailedRosMessageType.ActionFeedback:
                typeName += "Feedback";
                break;

            case DetailedRosMessageType.ServiceRequest:
                typeName += "Request";
                break;

            case DetailedRosMessageType.ServiceResponse:
                typeName += "Response";
                break;
            }

            if (typeName.Length > 0)
            {
                typeName = typeName.First().ToString().ToUpper() + typeName.Substring(1);
            }

            return(typeName);
        }
        private void WriteMessageInternal(RosTypeInfo rosType, DetailedRosMessageType messageType, MessageDescriptor message)
        {
            if (messageType == DetailedRosMessageType.None ||
                messageType == DetailedRosMessageType.Action ||
                messageType == DetailedRosMessageType.Service)
            {
                throw new ArgumentException($"message type is not detailed enough", nameof(messageType));
            }

            if (NameMapper.IsBuiltInType(rosType))
            {
                return;
            }

            var data = GetMessageTemplateData(rosType, messageType, message);

            SanitizeMessageTemplateData(data);

            var filePath = _directories.TempDirectory.GetFilePath($"{data.TypeName}.cs");
            var content  = _templateEngine.Format(MessageTemplateFile, data);

            WriteFile(filePath, content);
        }
Exemple #6
0
 public MessageTypeTemplateData(DetailedRosMessageType messageType)
 {
     _messageType = messageType;
 }
        protected virtual MessageTemplateData GetMessageTemplateData(RosTypeInfo rosType, DetailedRosMessageType messageType,
                                                                     MessageDescriptor message)
        {
            var fields = message.Fields
                         .Select(x => new FieldTemplateData
            {
                Index = message.Items
                        .Select((item, index) => new { Item = item, Index = index })
                        .First(f => f.Item == x)
                        .Index + 1, // Index of this field in serialized message (starting at 1)
                RosType       = x.TypeInfo,
                RosIdentifier = x.Identifier,
                Type          = new FieldTypeTemplateData(NameMapper.ResolveFullQualifiedInterfaceName(x.TypeInfo),
                                                          NameMapper.ResolveFullQualifiedTypeName(x.TypeInfo),
                                                          x.TypeInfo)
                ,
                Identifier = NameMapper.GetFieldName(x.Identifier)
            })
                         .ToList();

            var constants = message.Constants
                            .Select(c => new ConstantTemplateData
            {
                Index = message.Items
                        .Select((item, index) => new { item, index })
                        .First(x => x.item == c)
                        .index + 1,
                RosType       = c.TypeInfo,
                RosIdentifier = c.Identifier,
                TypeName      = NameMapper.ResolveFullQualifiedTypeName(c.TypeInfo),
                Identifier    = NameMapper.GetConstantName(c.Identifier),
                Value         = c.Value
            })
                            .ToList();

            var data = new MessageTemplateData
            {
                Package             = PackageTemplateData,
                RosTypeName         = NameMapper.GetRosTypeName(rosType.TypeName, messageType),
                RosAbstractTypeName = rosType.TypeName,
                TypeName            = NameMapper.GetTypeName(rosType.TypeName, messageType),
                AbstractTypeName    = NameMapper.GetTypeName(rosType.TypeName, DetailedRosMessageType.None),
                Fields      = fields,
                Constants   = constants,
                MessageType = new MessageTypeTemplateData(messageType)
            };

            return(data);
        }