public RotationalJointAxis(string path, Joint current)
     : base(path, current)
 {
     FlipVectors = new DoubleStorageArray(swData, path + "/FlipVectors");
     if (FlipVectors.Count == 0)
     {
         for (int i = 0; i < 4; i++)
             FlipVectors.AddItem(0);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Loads a robot from an assembly document, if a robot dosn't already
        /// exist one will be created
        /// </summary>
        /// <param name="asm">Assembly document containing a robot model</param>
        /// <param name="swApp">Interface for interacting with Solidworks</param>
        public RobotModel(AssemblyDoc asm, SldWorks swApp)
        {
            RobotInfo.WriteToLogFile("Robot Created (Robot)");

            var assembly = typeof(JointSpecifics).Assembly;
            Type[] types = assembly.GetTypes().Where(
                t => t.IsSubclassOf(typeof(JointSpecifics)) && !t.IsAbstract).ToArray();
            foreach (Type t in types)
            {
                System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(t.TypeHandle);
            }
            RobotInfo.WriteToLogFile("Initialized JointTypes = " + String.Join(", ",JointFactory.GetTypesList()) + " (Robot)");

            //Setup fields
            this.swApp = swApp;
            this.asmDoc = asm;
            this.modelDoc = (ModelDoc2)asm;
            swData = new StorageModel(modelDoc);
            Selected = false;

            RobotInfo.SetProperties(swApp, asmDoc, swData, this);
            RobotInfo.WriteToLogFile("Setup Fields Setup");
            //If the robot data dosn't exist yet, create it with default values
            if (swData.GetDouble("robot") == 0)
            {
                swData.SetDouble("robot", 1);
                /*PhysicalConfig = "Default";
                VisualConfig = "Default";
                CollisionConfig = "Default";*/
                Name = ((ModelDoc2)asm).GetTitle();
                RobotInfo.WriteToLogFile("Robot Data created with Default Values");
            }

            RobotInfo.WriteToLogFile("Robot Data created");

            LinkNums = new DoubleStorageArray(swData, "robot/linkNums");
            nextLinkNum = 0;
            RobotInfo.WriteToLogFile("LinkNums Storage Array Created");

            Links = new Dictionary<int,Link>();
            //Load link structure
            Link newLink;
            if (LinkNums.Count == 0)
            {
                LinkNums.AddItem(0);
                RobotInfo.WriteToLogFile("New Link added to LinkNums");
            }

            Configuration currentConfig = modelDoc.ConfigurationManager.ActiveConfiguration;

            foreach (double d in LinkNums)
            {
                newLink = new Link("robot/link" + (int)d, (int)d);
                RobotInfo.WriteToLogFile("New Link Created");
                Links.Add((int)d,newLink);
                if (d >= nextLinkNum)
                    nextLinkNum = (int)d + 1;
            }
            Links[0].isBaseLink = true;

            foreach (Link l in Links.Values.ToArray())
            {
                l.InitializeJoints();
                l.InitializeAttachments();
            }
            modelDoc.ShowConfiguration2(ConfigName);
            CalcAxisVectors();
            CalcOrigin();

            modelDoc.ShowConfiguration2(currentConfig.Name);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new link belonging to the given assembly
        /// </summary>
        /// <param name="swApp">The Solidworks App</param>
        /// <param name="asm"> The assembly that this Link is in</param>
        /// <param name="swData"> The Storage model that this Link is stored in </param>
        /// <param name="path"> The path to the StorageModel location of this link </param>
        /// <param name="baseLink"> Whether this Link is the base link of the model or not </param>
        public Link(String path, int id)
        {
            this.Selected = false;
            this.asmDoc = RobotInfo.AssemDoc;
            this.modelDoc = RobotInfo.ModelDoc;
            this.swData = RobotInfo.SwData;
            this.path = path;
            this.swApp = RobotInfo.SwApp;
            this.Id = id;
            this.robot = RobotInfo.Robot;
            attachments = new List<Attachment>();
            ParentJoints = new List<Joint>();
            ChildJoints = new List<Joint>();
            nextAttachmentNum = 0;
            nextJointNum = 0;
            isBaseLink = false;

            if (swData.GetDouble(path) == 0)
            {
                swData.SetDouble(path, 1);
                Name = "NewLink";
                this.color = DefaultColors[0];
            }

            attachmentNums = new DoubleStorageArray(swData, path + "/attachmentNums");
            parentJointNums = new DoubleStorageArray(swData, path + "/jointNums");

            ModelConfiguration physical = new ModelConfiguration(path + "/physicalComps", (int)ModelConfiguration.ModelConfigType.Physical,this);
            ModelConfiguration visual = new ModelConfiguration(path + "/visualComps", (int)ModelConfiguration.ModelConfigType.Visual,this);
            ModelConfiguration collision = new ModelConfiguration(path + "/collisionComps", (int)ModelConfiguration.ModelConfigType.Collision,this);
            LinkModels = new ModelConfiguration[] {  physical, visual, collision };
        }