예제 #1
0
        private byte[] ProcessBallJoint(RigidBodyJoint ballJoint)
        {
            try
            {
                List <byte> ballJointBytes = new List <byte>();

                //Adds ID to signify that it's a rotational joint
                ushort ID          = 4;
                byte[] ballJointID = BitConverter.GetBytes(ID);
                ballJointBytes.AddRange(ballJointID);

                foreach (AssemblyJoint joint in ballJoint.Joints)
                {
                    //Adds the ID of the parent STL to the output array
                    STLData parentSTL = new STLData();
                    STLDictionary.TryGetValue(NameFilter(joint.OccurrenceOne.Name), out parentSTL);
                    byte[] parentIDBytes = BitConverter.GetBytes((uint)(parentSTL.getID()));
                    ballJointBytes.AddRange(parentIDBytes);
                    //Adds the ID of the child STL to the output array
                    STLData childSTL = new STLData();
                    STLDictionary.TryGetValue(NameFilter(joint.OccurrenceTwo.Name), out childSTL);
                    byte[] childIDBytes = BitConverter.GetBytes((uint)(childSTL.getID()));
                    ballJointBytes.AddRange(childIDBytes);
                    //Adds the vector parallel to the movement onto the array of bytes
                    ballJoint.GetJointData(out object GeometryOne, out object GeometryTwo, out NameValueMap nameMap);
                    Circle vectorCircle    = (Circle)GeometryTwo;
                    byte[] vectorJointData = new byte[12];
                    BitConverter.GetBytes((float)vectorCircle.Center.X).CopyTo(vectorJointData, 0);
                    BitConverter.GetBytes((float)vectorCircle.Center.Y).CopyTo(vectorJointData, 4);
                    BitConverter.GetBytes((float)vectorCircle.Center.Z).CopyTo(vectorJointData, 8);
                    ballJointBytes.AddRange(vectorJointData);
                    //Adds the point of connection relative to the parent part
                    byte[] transJointData             = new byte[12];
                    AssemblyJointDefinition jointData = joint.Definition;
                    BitConverter.GetBytes((float)jointData.OriginTwo.Point.X).CopyTo(transJointData, 0);
                    BitConverter.GetBytes((float)jointData.OriginTwo.Point.Y).CopyTo(transJointData, 4);
                    BitConverter.GetBytes((float)jointData.OriginTwo.Point.Z).CopyTo(transJointData, 8);
                    ballJointBytes.AddRange(transJointData);
                    //Adds the degrees of freedom
                    byte[]         freedomData       = new byte[8];
                    ModelParameter positionData      = (ModelParameter)jointData.AngularPosition;
                    double         relataivePosition = positionData._Value;
                    if (jointData.HasLinearPositionEndLimit)
                    {
                        positionData = (ModelParameter)jointData.AngularPositionEndLimit;
                        BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))).CopyTo(freedomData, 0);
                    }
                    positionData = (ModelParameter)jointData.AngularPositionStartLimit;
                    BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))).CopyTo(freedomData, 4);
                    ballJointBytes.AddRange(freedomData);
                }
                return(ballJointBytes.ToArray());
            }
            catch (Exception e)
            {
                //catches problems
                MessageBox.Show(e.Message + "\n\n\n" + e.StackTrace);
                return(null);
            }
        }
예제 #2
0
 private Vector3D GetNormalOrDirection(AssemblyJointDefinition assemblyJointDefinition)
 {
     try { return(GetVector3D(GetNormDirFromGeometry(assemblyJointDefinition.OriginOne))); } catch {}
     try { return(GetVector3D(GetNormDirFromGeometry(assemblyJointDefinition.OriginTwo))); } catch {}
     warnings.Add("No joint axis found for joint " + assemblyJointDefinition.Parent.Name);
     return(new Vector3D());
 }
예제 #3
0
        // public bool childIsTheOne;


        public SkeletalJoint(CustomRigidGroup parent, CustomRigidJoint rigidJoint)
        {
            if (rigidJoint.joints.Count != 1)
            {
                throw new Exception("Not a proper joint");
            }

            asmJoint           = rigidJoint.joints[0].Definition;
            asmJointOccurrence = rigidJoint.joints[0];
            childGroup         = null;
            parentGroup        = parent;
            this.rigidJoint    = rigidJoint;
            if (rigidJoint.groupOne.Equals(parent))
            {
                childGroup = rigidJoint.groupTwo;
            }
            else if (rigidJoint.groupTwo.Equals(parent))
            {
                childGroup = rigidJoint.groupOne;
            }
            else
            {
                throw new Exception("Couldn't match parent group");
            }
            if (childGroup == null)
            {
                throw new Exception("Not a proper joint: No child joint found");
            }

            /*childIsTheOne = childGroup.Contains(asmJointOccurrence.AffectedOccurrenceOne);
             * if (!childIsTheOne && !childGroup.Contains(asmJointOccurrence.AffectedOccurrenceTwo))
             * {
             * throw new Exception("Expected child not found inside assembly joint.");
             * }*/
        }
예제 #4
0
        private BallJointMotion GetBallJointMotion(AssemblyJointDefinition assemblyJointDefinition)
        {
            var protoJointMotion = new BallJointMotion();

            warnings.Add("Limits not implemented for ball joints! Joint: " + assemblyJointDefinition.Parent.Name);
            // TODO
            return(protoJointMotion);
        }
예제 #5
0
 private double GetLinearPosition(AssemblyJointDefinition assemblyJointDefinition)
 {
     if (assemblyJointDefinition.LinearPosition != null)
     {
         return(assemblyJointDefinition.LinearPosition.Value);
     }
     return(0);
 }
예제 #6
0
 private Vector3D GetCenterOrRoot(AssemblyJointDefinition assemblyJointDefinition)
 {
     // TODO: The point returned from getCenter is very often wrong...
     try { return(GetVector3DConvertUnits(GetCenterFromGeometry(assemblyJointDefinition.OriginTwo))); } catch {}
     try { return(GetVector3DConvertUnits(GetCenterFromGeometry(assemblyJointDefinition.OriginOne))); } catch {}
     warnings.Add("No joint center found for joint " + assemblyJointDefinition.Parent.Name);
     throw new Exception();
 }
예제 #7
0
    //Соединение кручение
    public void Rotate()
    {
        GeometryIntent          OriginOne = assDefinition.CreateGeometryIntent(assDefinition.Occurrences[1].SurfaceBodies[1].Faces[2].Edges[1]);
        GeometryIntent          OriginTwo = assDefinition.CreateGeometryIntent(assDefinition.Occurrences[2].SurfaceBodies[1].Faces[3].Edges[2]);
        AssemblyJointDefinition jointDef  = assDefinition.Joints.CreateAssemblyJointDefinition(AssemblyJointTypeEnum.kRotationalJointType, OriginTwo, OriginOne);

        joints = assDefinition.Joints;
        joints.Add(jointDef);
    }
예제 #8
0
        private SliderJointMotion GetSliderJointMotion(AssemblyJointDefinition assemblyJointDefinition)
        {
            var protoJointMotion = new SliderJointMotion();

            protoJointMotion.SlideDirectionVector = GetNormalOrDirection(assemblyJointDefinition);
            protoJointMotion.SlideValue           = GetLinearPosition(assemblyJointDefinition);
            protoJointMotion.SlideLimits          = GetLinearLimits(assemblyJointDefinition);
            return(protoJointMotion);
        }
예제 #9
0
        private RevoluteJointMotion GetRevoluteJointMotion(AssemblyJointDefinition assemblyJointDefinition)
        {
            var protoJointMotion = new RevoluteJointMotion();

            protoJointMotion.RotationAxisVector = GetNormalOrDirection(assemblyJointDefinition);
            protoJointMotion.RotationValue      = GetAngularPosition(assemblyJointDefinition);
            protoJointMotion.RotationLimits     = GetAngularLimits(assemblyJointDefinition);
            return(protoJointMotion);
        }
예제 #10
0
 public static bool IsPlanarJoint(CustomRigidJoint jointI)
 {
     if (jointI.joints.Count == 1)
     {
         AssemblyJointDefinition joint = jointI.joints[0].Definition;
         return(joint.JointType == AssemblyJointTypeEnum.kPlanarJointType);
     }
     return(false);
 }
예제 #11
0
 public static bool IsBallJoint(CustomRigidJoint jointI)
 {
     if (jointI.joints.Count == 1)
     {
         AssemblyJointDefinition joint = jointI.joints[0].Definition;
         //Checks if there is no linear motion allowed.
         return(joint.JointType == AssemblyJointTypeEnum.kBallJointType);
     }
     return(false);
 }
예제 #12
0
 public static bool IsCylindricalJoint(CustomRigidJoint jointI)
 {
     // kMateLineLineJoint
     if (jointI.joints.Count == 1)
     {
         AssemblyJointDefinition joint = jointI.joints[0].Definition;
         return(joint.JointType == AssemblyJointTypeEnum.kCylindricalJointType);
     }
     return(false);
 }
예제 #13
0
        private CylindricalJointMotion GetCylindricalJointMotion(AssemblyJointDefinition assemblyJointDefinition)
        {
            var protoJointMotion = new CylindricalJointMotion();

            protoJointMotion.RotationAxisVector = GetNormalOrDirection(assemblyJointDefinition);
            protoJointMotion.RotationValue      = GetAngularPosition(assemblyJointDefinition);
            protoJointMotion.RotationLimits     = GetAngularLimits(assemblyJointDefinition);

            protoJointMotion.SlideValue  = GetLinearPosition(assemblyJointDefinition);
            protoJointMotion.SlideLimits = GetLinearLimits(assemblyJointDefinition);
            return(protoJointMotion);
        }
예제 #14
0
 public static bool IsLinearJoint(CustomRigidJoint jointI)
 {
     // kTranslationalJoint
     if (jointI.joints.Count == 1)
     {
         AssemblyJointDefinition joint = jointI.joints[0].Definition;
         //Cylindrical joints with no rotaion are effectively sliding joints.
         return(joint.JointType == AssemblyJointTypeEnum.kSlideJointType ||
                (joint.JointType == AssemblyJointTypeEnum.kCylindricalJointType &&
                 joint.HasAngularPositionLimits && joint.AngularPositionStartLimit.Value == joint.AngularPositionEndLimit.Value));
     }
     return(false);
 }
예제 #15
0
 public static bool IsRotationalJoint(CustomRigidJoint jointI)
 {
     // RigidBodyJointType = kConcentricCircleCircleJoint
     if (jointI.jointBased && jointI.joints.Count == 1)
     {
         AssemblyJointDefinition joint = jointI.joints[0].Definition;
         //Checks if there is no linear motion allowed.
         return(joint.JointType == AssemblyJointTypeEnum.kRotationalJointType ||
                (joint.JointType == AssemblyJointTypeEnum.kCylindricalJointType &&
                 joint.HasLinearPositionStartLimit && joint.HasLinearPositionEndLimit &&
                 joint.LinearPositionStartLimit.Value == joint.LinearPositionEndLimit.Value));
     }
     return(false);
 }
예제 #16
0
        private JointLimits GetLinearLimits(AssemblyJointDefinition assemblyJointDefinition)
        {
            var limits = new JointLimits();

            limits.IsMaximumValueEnabled = assemblyJointDefinition.HasLinearPositionEndLimit;
            limits.IsMinimumValueEnabled = assemblyJointDefinition.HasLinearPositionStartLimit;
            limits.IsRestValueEnabled    = false;
            if (limits.IsMaximumValueEnabled)
            {
                limits.MaximumValue = assemblyJointDefinition.LinearPositionEndLimit.Value;
            }
            if (limits.IsMinimumValueEnabled)
            {
                limits.MinimumValue = assemblyJointDefinition.LinearPositionStartLimit.Value;
            }
            // limits.RestValue = assemblyJointDefinition.LinearPosition;
            return(limits);
        }
예제 #17
0
        public void AssemblyJoint()
        {
            #region inventor öffnen

            Application inventorApp = null;
            Document    inventordoc = null;
            // Enable error handling.
            try
            {
                // Try to connect to a running instance of Inventor.
                inventorApp = (Application)Marshal.GetActiveObject("Inventor.Application");
            }
            catch (Exception ex)
            {
                // Connecting to a running instance failed so try to start Inventor.
                try
                {
                    inventorApp = (Application)Activator.CreateInstance(Type.GetTypeFromProgID("Inventor.Application"), true);

                    inventorApp.Visible = true;
                }
                catch (Exception ex2)
                {
                    // Unable to start Inventor.
                    Console.WriteLine("Unable to connect to or start Inventor.");
                    return;
                }
            }
            //System.Threading.Thread.Sleep(5000);
            //inventordoc = inventorApp.Documents.Add(Inventor.DocumentTypeEnum.kPartDocumentObject, "C:\\Users\\Public\\Documents\\Autodesk\\Inventor 2017\\Templates\\English\\Sheet Metal (in).ipt", true);


            #endregion



            #region Create a new assembly document.
            AssemblyDocument asmDoc =
                (AssemblyDocument)inventorApp.Documents.Add
                    (DocumentTypeEnum.kAssemblyDocumentObject,
                    inventorApp.FileManager.GetTemplateFile
                        (DocumentTypeEnum.kAssemblyDocumentObject));

            AssemblyComponentDefinition asmDef =
                asmDoc.ComponentDefinition;

            Matrix trans =
                inventorApp.TransientGeometry.CreateMatrix();
            #endregion


            #region die Bauelemente
            // Place an occurrence into the assembly.
            ComponentOccurrence occ1 =
                asmDef.Occurrences.Add
                    ("Pfad or element like c\\:...",
                    trans);

            // Place a second occurrence with the matrix
            //adjusted so it fits correctly with the
            //first occurrence.
            trans.Cell[1, 4] = 6 * 2.54;
            ComponentOccurrence occ2 =
                asmDef.Occurrences.Add
                    ("Pfad or element like c\\:...",
                    trans);
            #endregion



            // Get Face 1 from occ1 and
            // create a FaceProxy.
            Face face1 =
                (Face)GetNamedEntity(occ1, "Face1");

            // Get Face 2 from occ2 and
            // create a FaceProxy.
            Face face2 =
                (Face)GetNamedEntity(occ2, "Face2");

            // Get Edge 1 from occ2 and
            // create an EdgeProxy.
            Edge Edge1 =
                (Edge)GetNamedEntity(occ2, "Edge1");

            // Get Edge 3 from occ1 and
            // create an EdgeProxy.
            Edge Edge3 =
                (Edge)GetNamedEntity(occ1, "Edge3");



            // Create an intent to the
            // center of Edge1.
            GeometryIntent edge1Intent =
                asmDef.CreateGeometryIntent
                    (Edge1, PointIntentEnum.kMidPointIntent);

            // Create an intent to the center of Edge3.
            GeometryIntent edge3Intent =
                asmDef.CreateGeometryIntent
                    (Edge3, PointIntentEnum.kMidPointIntent);

            // Create two intents to define
            // the geometry for the joint.
            GeometryIntent intentOne =
                asmDef.CreateGeometryIntent
                    (face2, edge1Intent);
            GeometryIntent intentTwo =
                asmDef.CreateGeometryIntent
                    (face1, edge3Intent);

            // Create a rotation joint between the two parts.
            AssemblyJointDefinition jointDef =
                asmDef.Joints.CreateAssemblyJointDefinition
                    (AssemblyJointTypeEnum.kRotationalJointType,
                    intentOne, intentTwo);

            jointDef.FlipAlignmentDirection = false;
            jointDef.FlipOriginDirection    = true;
            AssemblyJoint joint =
                asmDef.Joints.Add(jointDef);

            // Make the joint visible.
            joint.Visible = true;

            // Drive the joint to animate it.
            joint.DriveSettings.StartValue = "0 deg";
            joint.DriveSettings.EndValue   = "180 deg";
            joint.DriveSettings.GoToStart();
            joint.DriveSettings.PlayForward();
            joint.DriveSettings.PlayReverse();
        }
예제 #18
0
        private RigidJointMotion GetRigidJointMotion(AssemblyJointDefinition assemblyJointDefinition)
        {
            var protoJointMotion = new RigidJointMotion();

            return(protoJointMotion);
        }
예제 #19
0
        private byte[] ProcessLinearJoint(RigidBodyJoint linearJoint, JointData jointDataObject)
        {
            try {
                ArrayList linearJointBytes = new ArrayList();

                //Adds ID to signify that it's a linear joint
                ushort ID            = 1;
                byte[] linearJointID = BitConverter.GetBytes(ID);
                linearJointBytes.Add(linearJointID);

                foreach (AssemblyJoint joint in linearJoint.Joints)
                {
                    //Adds the ID of the parent STL to the output array
                    STLData parentSTL = new STLData();
                    STLDictionary.TryGetValue(NameFilter(joint.OccurrenceOne.Name), out parentSTL);
                    byte[] parentIDBytes = BitConverter.GetBytes((uint)(parentSTL.getID()));
                    linearJointBytes.Add(parentIDBytes);
                    //Adds the ID of the child STL to the output array
                    STLData childSTL = new STLData();
                    STLDictionary.TryGetValue(NameFilter(joint.OccurrenceTwo.Name), out childSTL);
                    byte[] childIDBytes = BitConverter.GetBytes((uint)(childSTL.getID()));
                    linearJointBytes.Add(childIDBytes);
                    //Adds the vector parallel to the movement onto the array of bytes
                    object       GeometryOne, GeometryTwo;
                    NameValueMap nameMap;
                    linearJoint.GetJointData(out GeometryOne, out GeometryTwo, out nameMap);
                    Line   vectorLine      = (Line)GeometryTwo;
                    byte[] vectorJointData = new byte[12];
                    BitConverter.GetBytes(vectorLine.RootPoint.X).CopyTo(vectorJointData, 0);
                    BitConverter.GetBytes(vectorLine.RootPoint.Y).CopyTo(vectorJointData, 4);
                    BitConverter.GetBytes(vectorLine.RootPoint.Z).CopyTo(vectorJointData, 8);
                    linearJointBytes.Add(vectorJointData);
                    //Adds the point of connection relative to the parent part
                    byte[] transJointData             = new byte[12];
                    AssemblyJointDefinition jointData = joint.Definition;
                    BitConverter.GetBytes(jointData.OriginTwo.Point.X).CopyTo(transJointData, 0);
                    BitConverter.GetBytes(jointData.OriginTwo.Point.Y).CopyTo(transJointData, 4);
                    BitConverter.GetBytes(jointData.OriginTwo.Point.Z).CopyTo(transJointData, 8);
                    linearJointBytes.Add(transJointData);
                    //Adds the degrees of freedom
                    byte[]         freedomData       = new byte[8];
                    ModelParameter positionData      = (ModelParameter)jointData.LinearPosition;
                    double         relataivePosition = positionData._Value;
                    positionData = (ModelParameter)jointData.LinearPositionEndLimit;
                    BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))).CopyTo(freedomData, 0);
                    positionData = (ModelParameter)jointData.LinearPositionStartLimit;
                    BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))).CopyTo(freedomData, 4);
                    linearJointBytes.Add(freedomData);
                    linearJointBytes.Add(processJointAttributes(jointDataObject));
                }
                object[] tempArray     = linearJointBytes.ToArray();
                byte[]   returnedArray = new byte[tempArray.Length];
                tempArray.CopyTo(returnedArray, 0);
                return(returnedArray);
            }
            catch (Exception e) {
                //catches problems
                MessageBox.Show(e.Message + "\n\n\n" + e.StackTrace);
                return(null);
            }
        }
예제 #20
0
        private byte[] ProcessCylindricalJoint(RigidBodyJoint cylindricalJoint)
        {
            try
            {
                List <byte> cylindricalJointBytes = new List <byte>();

                //Adds ID to signify that it's a cylindrical joint
                cylindricalJointBytes.AddRange(BitConverter.GetBytes((ushort)2));

                foreach (AssemblyJoint joint in cylindricalJoint.Joints)
                {
                    //Adds the ID of the parent STL to the output array
                    STLData parentSTL = new STLData();
                    STLDictionary.TryGetValue(NameFilter(joint.OccurrenceOne.Name), out parentSTL);
                    byte[] parentIDBytes = BitConverter.GetBytes((uint)(parentSTL.getID()));
                    cylindricalJointBytes.AddRange(parentIDBytes);
                    //Adds the ID of the child STL to the output array
                    STLData childSTL = new STLData();
                    STLDictionary.TryGetValue(NameFilter(joint.OccurrenceTwo.Name), out childSTL);
                    byte[] childIDBytes = BitConverter.GetBytes((uint)(childSTL.getID()));
                    cylindricalJointBytes.AddRange(childIDBytes);
                    //Adds the vector normal to the plane of rotation
                    cylindricalJoint.GetJointData(out object GeometryOne, out object GeometryTwo, out NameValueMap nameMap);

                    /* Circle vectorCircle = (Circle)GeometryTwo;
                     * byte[] vectorJointData = new byte[12];
                     * BitConverter.GetBytes((float)vectorCircle.Center.X).CopyTo(vectorJointData, 0);
                     * BitConverter.GetBytes((float)vectorCircle.Center.Y).CopyTo(vectorJointData, 4);
                     * BitConverter.GetBytes((float)vectorCircle.Center.Z).CopyTo(vectorJointData, 8);
                     * cylindricalJointBytes.AddRange(vectorJointData);
                     *///Adds the vector parallel to the movement
                    MessageBox.Show(GeometryTwo.GetType().ToString());
                    //Adds the vector parallel to movement
                    Line   vectorLine      = (Line)GeometryTwo;
                    byte[] vectorJointData = new byte[12];
                    BitConverter.GetBytes((float)vectorLine.RootPoint.X).CopyTo(vectorJointData, 0);
                    BitConverter.GetBytes((float)vectorLine.RootPoint.Y).CopyTo(vectorJointData, 4);
                    BitConverter.GetBytes((float)vectorLine.RootPoint.Z).CopyTo(vectorJointData, 8);
                    cylindricalJointBytes.AddRange(vectorJointData);
                    //Adds the point of connection relative to the parent part
                    byte[] transJointData             = new byte[12];
                    AssemblyJointDefinition jointData = joint.Definition;
                    BitConverter.GetBytes((float)jointData.OriginTwo.Point.X).CopyTo(transJointData, 0);
                    BitConverter.GetBytes((float)jointData.OriginTwo.Point.Y).CopyTo(transJointData, 4);
                    BitConverter.GetBytes((float)jointData.OriginTwo.Point.Z).CopyTo(transJointData, 8);
                    cylindricalJointBytes.AddRange(transJointData);
                    //Adds the degrees of freedom
                    List <byte>    freedomData       = new List <byte>();
                    ModelParameter positionData      = (ModelParameter)jointData.AngularPosition;
                    double         relataivePosition = positionData._Value;
                    if (jointData.HasLinearPositionEndLimit)
                    {
                        positionData = (ModelParameter)jointData.LinearPositionEndLimit;
                        freedomData.AddRange(BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))));
                    }
                    if (jointData.HasLinearPositionStartLimit)
                    {
                        positionData = (ModelParameter)jointData.LinearPositionStartLimit;
                        freedomData.AddRange(BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))));
                    }
                    if (jointData.HasAngularPositionLimits)
                    {
                        positionData = (ModelParameter)jointData.AngularPositionEndLimit;
                        freedomData.AddRange(BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))));
                        positionData = (ModelParameter)jointData.AngularPositionStartLimit;
                        freedomData.AddRange(BitConverter.GetBytes((float)(Math.Abs(relataivePosition) - Math.Abs(positionData._Value))));
                    }
                    if (freedomData != null)
                    {
                        cylindricalJointBytes.AddRange(freedomData);
                    }
                }
                return(cylindricalJointBytes.ToArray());
            }
            catch (Exception e)
            {
                //catches problems
                MessageBox.Show(e.Message + "\n\n\n" + e.StackTrace);
                return(null);
            }
        }