Example #1
0
        /// <summary>
        /// Creates a new joint
        /// </summary>
        /// <param name="path">Path to this joint in the StorageModel</param>
        /// <param name="owner">The Link that owns this joint (child Link in the joint)</param>
        public Joint(string path, Link parent, Link child)
        {
            this.swApp = RobotInfo.SwApp;
            this.asmDoc = RobotInfo.AssemDoc;
            this.modelDoc = RobotInfo.ModelDoc;
            this.swData = RobotInfo.SwData;
            this.path = path;
            this.robot = RobotInfo.Robot;
            this.Parent = parent;
            Parent.ChildJoints.Add(this);
            this.Child = child;
            this.Selected = false;
            this.Type = JointFactory.DefaultJointType;

            RobotInfo.WriteToLogFile("Getting Joint Specifics (Joint)");
            jointSpecifics = JointFactory.GetSpecificJoint(Type,path,this);
            RobotInfo.WriteToLogFile("Successfully created Joint Specifics (Joint)");

            if (swData.GetDouble(path) == 0)
            {
                swData.SetDouble(path, 1);
            }
        }
Example #2
0
 /// <summary>
 /// Loads a joint that has already been created
 /// </summary>
 /// <param name="swApp">Solidworks app</param>
 /// <param name="asm">Assembly document this joint and its robot belong to</param>
 /// <param name="swData">StorageModel that this joint is tored in</param>
 /// <param name="path">Path to this joint in the StorageModel</param>
 /// <param name="robot">The Robot model that the joint is in</param>
 public Joint(string path)
 {
     this.swApp = RobotInfo.SwApp;
     this.asmDoc = RobotInfo.AssemDoc;
     this.modelDoc = RobotInfo.ModelDoc;
     this.swData = RobotInfo.SwData;
     this.path = path;
     this.robot = RobotInfo.Robot;
     this.Parent = robot.GetLink(parentId);
     Parent.ChildJoints.Add(this);
     this.Child = robot.GetLink(childId);
     this.Selected = false;
     if(this.Type == null || this.Type.Equals(""))
         this.Type = JointFactory.DefaultJointType;
     RobotInfo.WriteToLogFile("Loading existing joint (Joint)");
     jointSpecifics = JointFactory.GetSpecificJoint(Type, path, this);
     if (swData.GetDouble(path) == 0)
     {
         swData.SetDouble(path, 1);
     }
 }
Example #3
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);
        }
Example #4
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 };
        }