Example #1
0
        public static BaseLink Alloc()
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BaseLink_Alloc();
            BaseLink ret = (cPtr == global::System.IntPtr.Zero) ? null : new BaseLink(cPtr, false);

            return(ret);
        }
Example #2
0
        public BaseLink GetBaseLink(int id)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BaseContainer_GetBaseLink(swigCPtr, id);
            BaseLink ret = (cPtr == global::System.IntPtr.Zero) ? null : new BaseLink(cPtr, false);

            return(ret);
        }
Example #3
0
        public BaseLink GetClone(COPYFLAGS flags, AliasTrans trn)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BaseLink_GetClone(swigCPtr, (int)flags, AliasTrans.getCPtr(trn));
            BaseLink ret = (cPtr == global::System.IntPtr.Zero) ? null : new BaseLink(cPtr, false);

            return(ret);
        }
Example #4
0
        public BaseLink GetBaseLink()
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.GeData_GetBaseLink(swigCPtr);
            BaseLink ret = (cPtr == global::System.IntPtr.Zero) ? null : new BaseLink(cPtr, false);

            return(ret);
        }
Example #5
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            dbConn = BaseLink.GetConnStr(dbType, txtUserName, txtPwd, txtHostName, txtPort, txtServerName);

            if (!BaseLink.CheckLink(dbType, dbConn))
            {
                CodeBox.Show("连接数据库失败!", this);
            }
            else
            {
                var buildLink = BaseLink.ControlsToData(dbType, txtHostName, txtUserName, txtPwd, txtPort, txtServerName, labServerName, true, txtLinkName);
                buildLink.LinkName = buildLink.LinkName == "" ? BaseLink.GetLinkName(buildLink) : buildLink.LinkName;
                buildLink.Id       = Guid.NewGuid().ToString();
                AppCache.SetLink(buildLink);

                if (FastRead.Query <Data_Source>(a => a.LinkName == buildLink.LinkName).ToCount() == 1)
                {
                    FastWrite.Update <Data_Source>(buildLink, a => a.LinkName == buildLink.LinkName,
                                                   a => new { a.Host, a.PassWord, a.Port, a.ServerName, a.Type, a.UserName });
                }
                else
                {
                    FastWrite.Add(buildLink);
                }

                CodeBox.Show("连接数据库成功!", this);
            }
        }
Example #6
0
 public PacketListener()
 {
     _baseLink = new BaseLink("COM4");
     _parser   = new Parser();
     _baseLink.PacketReceived += _parser.HandleData;
     _parser.EventReceived    += OnEvent;
     _parser.SliceReceived    += OnSlice;
 }
Example #7
0
 public void SetBaseLink(BaseLink v)
 {
     C4dApiPINVOKE.GeData_SetBaseLink(swigCPtr, BaseLink.getCPtr(v));
     if (C4dApiPINVOKE.SWIGPendingException.Pending)
     {
         throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Example #8
0
        public void Connect(string comPort)
        {
            _baseLink = new BaseLink(comPort);
            _parser   = new Parser();
            _baseLink.PacketReceived += _parser.HandleData;

            _worker = new Thread(_baseLink.StartReading);
            _worker.Start();
        }
Example #9
0
        new public void writeURDF(XmlWriter writer)
        {
            writer.WriteStartDocument();
            writer.WriteStartElement("robot");
            writer.WriteAttributeString("name", name);

            BaseLink.writeURDF(writer);

            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Close();
        }
Example #10
0
        /// <summary>
        /// 测试数据库连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Conn_Click(object sender, RoutedEventArgs e)
        {
            dbConn = BaseLink.GetConnStr(dbType, txtUserName, txtPwd, txtHostName, txtPort, txtServerName);

            if (BaseLink.CheckLink(dbType, dbConn))
            {
                CodeBox.Show("连接成功!", this);
            }
            else
            {
                CodeBox.Show("连接失败!", this);
            }
        }
        public void Connectivity_Link_And_Link_Property_Assignments()
        {
            List <string> Links = new List <string>();     //彈簧桿件

            for (int j = 0; j < Springs.Count; ++j)
            {   // Connectivity_Link
                string[] JJ = Springs[j].Split(',');
                string   XX = JJ[0].Substring(1).Replace("V", "");
                XX = XX.Replace("H", "");
                int    NN = int.Parse(XX);
                string LL = "L" + JJ[0].Substring(1);
                Links.Add($"{LL}, {NN}, {JJ[0]}");

                // Link_Property_Assignments
                float X = float.Parse(JJ[3]);
                float Z = float.Parse(JJ[6]);
                if (Z == 0)
                {
                    LinkProperty.Add($"{LL},Gap,TwoJoint,Spring-CornerH,None"); CornerHLink.Add(LL);
                }
                else
                if (Math.Abs(X) == Radius && Z == -SpringOffset)
                {
                    LinkProperty.Add($"{LL},Gap,TwoJoint,Spring-CornerV,None"); CornerVLink.Add(LL);
                }
                else
                if (Z == -SpringOffset)
                {
                    LinkProperty.Add($"{LL},Gap,TwoJoint,Spring-Base,None"); BaseLink.Add(LL);
                }
                else
                if (Math.Abs(X) == Radius + SpringOffset && Z == High)
                {
                    LinkProperty.Add($"{LL},Gap,TwoJoint,Spring-Tangent,None"); TangentLink.Add(LL);
                }
                else
                if (Math.Abs(X) == Radius + SpringOffset)
                {
                    LinkProperty.Add($"{LL},Gap,TwoJoint,Spring-Side,None"); SideLink.Add(LL);
                }
                else
                {
                    LinkProperty.Add($"{LL},Gap,TwoJoint,Spring-Vault,None"); VaultLink.Add(LL);
                }
            }
            //input.PutDataToSheet("Connectivity - Link", Links);
            //input.PutDataToSheet("Link Property Assignments", LinkProperty);
        }
Example #12
0
 internal string[] GetJointNames(bool includeFixed)
 {
     return(BaseLink.GetJointNames(includeFixed));
 }
    private GameObject CreateSensor(GameObject agent, GameObject parent, GameObject prefab, JSONNode item, BaseLink baseLink)
    {
        if (baseLink != null)
        {
            parent = parent == gameObject ? baseLink.gameObject : parent; // replace baselink with the default gameObject parent
        }
        var position = parent.transform.position;
        var rotation = parent.transform.rotation;

        var transform = item["transform"];

        if (transform != null)
        {
            position = parent.transform.TransformPoint(transform.ReadVector3());
            rotation = parent.transform.rotation * Quaternion.Euler(transform.ReadVector3("pitch", "yaw", "roll"));
        }

        var sensor = Instantiate(prefab, position, rotation, agent.transform);

        var sb = sensor.GetComponent <SensorBase>();

        sb.ParentTransform = parent.transform;

        var sbType = sb.GetType();

        foreach (var param in item["params"])
        {
            var key   = param.Key;
            var value = param.Value;

            var field = sbType.GetField(key);
            if (field == null)
            {
                throw new Exception(
                          $"Unknown {key} parameter for {item["name"].Value} sensor on {gameObject.name} vehicle");
            }

            if (field.FieldType.IsEnum)
            {
                try
                {
                    var obj = Enum.Parse(field.FieldType, value.Value);
                    field.SetValue(sb, obj);
                }
                catch (ArgumentException ex)
                {
                    throw new Exception(
                              $"Failed to set {key} field to {value.Value} enum value for {gameObject.name} vehicle, {sb.Name} sensor",
                              ex);
                }
            }
            else if (field.FieldType == typeof(Color))
            {
                if (ColorUtility.TryParseHtmlString(value.Value, out var color))
                {
                    field.SetValue(sb, color);
                }
                else
                {
                    throw new Exception(
                              $"Failed to set {key} field to {value.Value} color for {gameObject.name} vehicle, {sb.Name} sensor");
                }
            }
            else if (field.FieldType == typeof(bool))
            {
                field.SetValue(sb, value.AsBool);
            }
            else if (field.FieldType == typeof(int))
            {
                field.SetValue(sb, value.AsInt);
            }
            else if (field.FieldType == typeof(float))
            {
                field.SetValue(sb, value.AsFloat);
            }
            else if (field.FieldType == typeof(string))
            {
                field.SetValue(sb, value.Value);
            }
            else if (field.FieldType.IsGenericType && field.FieldType.GetGenericTypeDefinition() == typeof(List <>))
            {
                var  type     = field.FieldType.GetGenericArguments()[0];
                Type listType = typeof(List <>).MakeGenericType(new[] { type });
                System.Collections.IList list = (System.Collections.IList)Activator.CreateInstance(listType);

                if (type.IsEnum)
                {
                    foreach (var elemValue in value)
                    {
                        object elem;
                        try
                        {
                            elem = Enum.Parse(type, elemValue.Value);
                        }
                        catch (ArgumentException ex)
                        {
                            throw new Exception(
                                      $"Failed to set {key} field to {value.Value} enum value for {gameObject.name} vehicle, {sb.Name} sensor",
                                      ex);
                        }
                        list.Add(elem);
                    }
                }
                else if (type == typeof(float))
                {
                    foreach (var elemValue in value)
                    {
                        float elem = elemValue.Value.AsFloat;
                        list.Add(elem);
                    }
                }
                else
                {
                    foreach (var elemValue in value)
                    {
                        var elem = Activator.CreateInstance(type);

                        foreach (var elemField in type.GetFields())
                        {
                            var name = elemField.Name;

                            if (elemValue.Value[name].IsNumber)
                            {
                                elemField.SetValue(elem, elemValue.Value[name].AsFloat);
                            }
                            else if (elemValue.Value[name].IsString)
                            {
                                elemField.SetValue(elem, elemValue.Value[name].Value);
                            }
                        }

                        list.Add(elem);
                    }
                }

                field.SetValue(sb, list);
            }
            else
            {
                throw new Exception(
                          $"Unknown {field.FieldType} type for {key} field for {gameObject.name} vehicle, {sb.Name} sensor");
            }
        }

        return(sensor);
    }
    private GameObject CreateSensor(GameObject agent, GameObject parent, GameObject prefab, SensorData item, BaseLink baseLink)
    {
        if (baseLink != null)
        {
            parent = parent == gameObject ? baseLink.gameObject : parent; // replace baselink with the default gameObject parent
        }

        var position  = parent.transform.position;
        var rotation  = parent.transform.rotation;
        var transform = item.Transform;

        if (transform != null)
        {
            position = parent.transform.TransformPoint(transform.x, transform.y, transform.z);
            rotation = parent.transform.rotation * Quaternion.Euler(transform.pitch, transform.yaw, transform.roll);
        }

        var sensor = Instantiate(prefab, position, rotation, agent.transform);
        var sb     = sensor.GetComponent <SensorBase>();
        var sbType = sb.GetType();

        sb.ParentTransform = parent.transform;

        if (item.@params != null)
        {
            foreach (var param in item.@params)
            {
                // these keys do not go through camelCase modifier so we do it manually
                var key   = param.Key.First().ToString().ToUpper() + param.Key.Substring(1);
                var value = param.Value;

                var field = sbType.GetField(key);
                if (field == null)
                {
                    throw new Exception($"Unknown {key} parameter for {item.Name} sensor on {gameObject.name} vehicle");
                }

                if (field.FieldType == typeof(System.Int64) ||
                    field.FieldType == typeof(System.Int32) ||
                    field.FieldType == typeof(System.Double) ||
                    field.FieldType == typeof(System.Single) ||
                    field.FieldType == typeof(System.String) ||
                    field.FieldType == typeof(System.Boolean))
                {
                    field.SetValue(sb, Convert.ChangeType(value, field.FieldType));
                }
                else if (field.FieldType.IsEnum)
                {
                    try
                    {
                        var obj = Enum.Parse(field.FieldType, (string)value);
                        field.SetValue(sb, obj);
                    }
                    catch (ArgumentException ex)
                    {
                        throw new Exception($"Failed to set {key} field to {value} enum value for {gameObject.name} vehicle, {sb.Name} sensor", ex);
                    }
                }
                else if (field.FieldType == typeof(Color))
                {
                    if (ColorUtility.TryParseHtmlString((string)value, out var color))
                    {
                        field.SetValue(sb, color);
                    }
                    else
                    {
                        throw new Exception($"Failed to set {key} field to {value} color for {gameObject.name} vehicle, {sb.Name} sensor");
                    }
                }
                else if (field.FieldType.IsGenericType && field.FieldType.GetGenericTypeDefinition() == typeof(List <>))
                {
                    var   type     = field.FieldType.GetGenericArguments()[0];
                    Type  listType = typeof(List <>).MakeGenericType(type);
                    IList list     = (IList)Activator.CreateInstance(listType);
                    var   jarray   = (Newtonsoft.Json.Linq.JArray)value;

                    if (type.IsEnum)
                    {
                        // TODO test this branch - remove this comment when you found a sensor + config that exercises this branch
                        foreach (var elemValue in jarray.ToObject <List <string> >())
                        {
                            object elem;
                            try
                            {
                                elem = Enum.Parse(type, elemValue);
                            }
                            catch (ArgumentException ex)
                            {
                                throw new Exception($"Failed to set {key} field to {value} enum value for {gameObject.name} vehicle, {sb.Name} sensor", ex);
                            }

                            list.Add(elem);
                        }
                    }
                    else if (type == typeof(System.Single))
                    {
                        list = jarray.ToObject <List <System.Single> >();
                    }
                    else
                    {
                        // Full qualified type name used, e.g. "$_type": "Simulator.Sensors.Postprocessing.SunFlare, Simulator"
                        var jArrStr = jarray.ToString();
                        if (jArrStr.Contains("$_type"))
                        {
                            // Revert change from SensorParameter attribute (more details there)
                            jArrStr = jArrStr.Replace("$_type", "$type");

                            // If sensor's assembly is named after its type, we're loading asset bundle with renamed assembly
                            // Type was serialized before renaming - update types from that assembly to reflect this change
                            if (sbType.Assembly.GetName().Name == item.Type)
                            {
                                jArrStr = Regex.Replace(jArrStr, "(\"\\$type\"\\:[^,]*, )(Simulator.Sensors)", $"$1{item.Type}");
                            }

                            list = JsonConvert.DeserializeObject(jArrStr, typeof(List <>).MakeGenericType(type), new JsonSerializerSettings {
                                TypeNameHandling = TypeNameHandling.Auto
                            }) as IList;
                        }
                        // Shortened type name used, e.g. "type": "SunFlare"
                        else
                        {
                            List <Type> assignableTypes = null;
                            if (type.IsAbstract)
                            {
                                assignableTypes = type.Assembly.GetTypes().Where(t => t != type && type.IsAssignableFrom(t))
                                                  .ToList();
                            }

                            foreach (var jtoken in jarray)
                            {
                                object elem;
                                if (!type.IsAbstract)
                                {
                                    elem = jtoken.ToObject(type);
                                }
                                else
                                {
                                    var typeName = jtoken.Value <string>("type");
                                    if (typeName == null)
                                    {
                                        throw new Exception(
                                                  $"Type {type.Name} is abstract and does not define `type` field ({gameObject.name} vehicle, {sb.Name} sensor, {key} field)");
                                    }

                                    var elementType = assignableTypes.FirstOrDefault(t => t.Name == typeName);
                                    if (elementType == null)
                                    {
                                        throw new Exception(
                                                  $"No {typeName} type derived from {type.Name} for {key} field for {gameObject.name} vehicle, {sb.Name} sensor");
                                    }

                                    elem = jtoken.ToObject(elementType);
                                }

                                list.Add(elem);
                            }
                        }
                    }

                    field.SetValue(sb, list);
                }
                else
                {
                    var jObjStr = value.ToString();

                    // Revert change from SensorParameter attribute (more details there)
                    jObjStr = jObjStr.Replace("$_type", "$type");

                    // If sensor's assembly is named after its type, we're loading asset bundle with renamed assembly
                    // Type was serialized before renaming - update types from that assembly to reflect this change
                    if (sbType.Assembly.GetName().Name == item.Type)
                    {
                        jObjStr = Regex.Replace(jObjStr, "(\"\\$type\"\\:[^,]*, )(Simulator.Sensors)", $"$1{item.Type}");
                    }

                    var instance = JsonConvert.DeserializeObject(jObjStr, field.FieldType, new JsonSerializerSettings {
                        TypeNameHandling = TypeNameHandling.Auto
                    });
                    field.SetValue(sb, instance);
                }
            }
        }

        // Populate all fields with their default instances, if their override was not set through config
        foreach (var field in sbType.GetRuntimeFields().Where(field => field.IsDefined(typeof(SensorParameter), true)))
        {
            var attr = field.GetCustomAttribute <SensorParameter>();

            var current = field.GetValue(sb);
            if (current != null)
            {
                continue;
            }

            var defaultInstance = attr.GetDefaultInstance(sbType, field.FieldType);
            if (defaultInstance == null)
            {
                continue;
            }

            field.SetValue(sb, defaultInstance);
        }

        if (sb is CameraSensorBase cameraBase && cameraBase.Postprocessing == null && sbType.IsDefined(typeof(DefaultPostprocessingAttribute), true))
        {
            if (cameraBase.Postprocessing == null)
            {
                var attr        = sbType.GetCustomAttribute <DefaultPostprocessingAttribute>();
                var ppInstances = attr.GetDefaultInstances;
                cameraBase.Postprocessing = ppInstances;
            }
        }

        return(sensor);
    }
Example #15
0
        public bool CopyTo(BaseLink dst, COPYFLAGS flags, AliasTrans trn)
        {
            bool ret = C4dApiPINVOKE.BaseLink_CopyTo(swigCPtr, BaseLink.getCPtr(dst), (int)flags, AliasTrans.getCPtr(trn));

            return(ret);
        }
Example #16
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseLink obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
 public void Add(BaseLink baseLink)
 {
     AddLink(baseLink);
 }
 protected virtual void AddLink(BaseLink obj)
 {
     Link = obj;
     Link.AddLink(obj);
 }
Example #19
0
 /// <summary>
 /// 初始化连接信息
 /// </summary>
 private void InitLinkInfo()
 {
     BaseLink.DataToControls(AppCache.GetLink, ref txtHostName, ref txtUserName, ref txtPwd, ref txtPort, ref txtServerName, ref labServerName, ref txtLinkName);
     BaseLink.ComboBoxSelect(boxDbType, AppCache.GetLink.Type);
     BaseLink.ComboBoxSelect(dbTypeLink, AppCache.GetLink.LinkName, true);
 }
Example #20
0
 /// <summary>
 /// 数据库选择中
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Box_Selected(object sender, RoutedEventArgs e)
 {
     dbType = BaseLink.InitLink(ref txtPort, ref labServerName, boxDbType);
 }
Example #21
0
 public GeData(BaseLink n) : this(C4dApiPINVOKE.new_GeData__SWIG_15(BaseLink.getCPtr(n)), true)
 {
 }