public void HideProperty()
 {
     swManip = null;
     triadManip = null;
     GC.Collect();
 }
        /// <summary>
        /// Toggles custom value textboxes when checkbox changes 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CustomMassValCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            currentLink.UseCustomInertial = CustomMassValCheckbox.Checked;
            PhysicalButton.Enabled = !CustomMassValCheckbox.Checked;
            toggleCOMTextboxes();

            if (CustomMassValCheckbox.Checked)
            {
                swManip = currentLink.modelDoc.ModelViewManager.CreateManipulator((int)swManipulatorType_e.swTriadManipulator, this);
                triadManip = swManip.GetSpecificManipulator();
                triadManip.DoNotShow = (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowXYRING | (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowYZRING
                                        | (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowZXRING | (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowXYPlane |
                                        (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowYZPlane | (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowZXPlane;
                triadManip.Origin = currentLink.swApp.GetMathUtility().CreatePoint(new double[] { currentLink.ComX, currentLink.ComY, currentLink.ComZ });
                startOrigin = triadManip.Origin;
                triadManip.UpdatePosition();
                swManip.Show(currentLink.modelDoc);
            }
            else
            {
                InertiaButton_Click(null, null);

                HideProperty();
            }
        }
        /// <summary>
        /// Called when this property manager page is closed
        /// </summary>
        /// <param name="Reason">Reason this page is closing</param>
        public void OnClose(int Reason)
        {
            if (PrevSelectId != null)
                OnSelectionboxFocusChanged(PrevSelectId);
            swManips = null;
            triadManip = null;
            GC.Collect();

            if (robot != null)
                SaveCurrentSelection();
            modelDoc.ClearSelection2(true);
            if (Reason != (int)swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_ParentClosed && RestoreManager != null)
                RestoreManager(robot);
        }
        /// <summary>
        /// Draws preview arrows for the coordinate system. Axes should be calculated before hand.
        /// </summary>
        public void DrawOriginPreview()
        {
            triadManip = null;
            swManips = null;
            GC.Collect();
            if (robot == null || robot.OriginPt == null || robot.Direction == null || robot.BasePlane == null)
            {
                return;
            }

            triadManip = null;
            swManips = null;
            GC.Collect();

            ModelViewManager swModViewMgr = modelDoc.ModelViewManager;
            MathPoint robotOrigin = mathUtil.CreatePoint(new double[] { robot.OriginX, robot.OriginY, robot.OriginZ });

            swManips = new Manipulator[1];
            MathVector[] axisVectors = new MathVector[3];
            axisVectors[0] = mathUtil.CreateVector(new double[] { robot.AxisX, robot.AxisY, robot.AxisZ });
            axisVectors[1] = CalcNormalVector(robot.BasePlane);                //calculate vertical axis as normal of plane
            axisVectors[2] = axisVectors[1].Cross(axisVectors[0]);  //calculate horizontal axis as cross product between plane normal and direction axis.

            swManips[0] = swModViewMgr.CreateManipulator((int)swManipulatorType_e.swTriadManipulator, this);
            triadManip = (TriadManipulator)swManips[0].GetSpecificManipulator();
            triadManip.DoNotShow = (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowXYRING | (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowYZRING
                                        | (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowZXRING | (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowXYPlane |
                                        (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowYZPlane | (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowZXPlane;
            triadManip.XAxis = axisVectors[0];
            triadManip.YAxis = axisVectors[2];
            triadManip.ZAxis = axisVectors[1];
            triadManip.Origin = robotOrigin;
            triadManip.UpdatePosition();
            swManips[0].Show(modelDoc);
        }
        /// <summary>
        /// Draws the preview triad for the origin
        /// </summary>
        private void DrawOriginPreview()
        {
            if (!inPropertyPage || groupBox.Expanded == false)
                return;
            MathVector xAxisVector = RobotInfo.mathUtil.CreateVector(new double[]{1,0,0});
            MathVector yAxisVector = RobotInfo.mathUtil.CreateVector(new double[]{0,1,0});
            MathVector zAxisVector = RobotInfo.mathUtil.CreateVector(new double[]{0,0,1});
            if (swManip == null)
            {
                swManip = modelDoc.ModelViewManager.CreateManipulator((int)swManipulatorType_e.swTriadManipulator, this);
                originTriad = swManip.GetSpecificManipulator();
            }

            if (xVector != null)
            {
                originTriad.XAxis = xVector;
                if (yVector != null)
                {
                    originTriad.YAxis = yVector;
                    originTriad.ZAxis = xVector.Cross(yVector).Normalise();
                }
                else
                {
                    MathVector tempAxis = zAxisVector.Cross(xVector);
                    if(tempAxis.GetLength() < VectorCalcs.errorVal)
                        tempAxis = yAxisVector;
                    else
                        tempAxis = tempAxis.Normalise();
                    originTriad.YAxis = tempAxis;
                    originTriad.ZAxis = xVector.Cross(tempAxis).Normalise();
                }
            }
            else
            {
                originTriad.XAxis = xAxisVector;
                originTriad.YAxis = yAxisVector;
                originTriad.ZAxis = zAxisVector;
            }

            originTriad.Origin = RobotInfo.mathUtil.CreatePoint(OriginValues.Point);
            originTriad.UpdateScale(80);
            originTriad.DoNotShow = (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowXYPlane |
                (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowXYRING |
                (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowYZPlane |
                (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowYZRING |
                (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowZXPlane |
                (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowZXRING;

            originTriad.UpdatePosition();
            if (!swManip.Visible)
            {
                swManip.Show(modelDoc);
            }
        }
 /// <summary>
 /// Clears the origin previews
 /// </summary>
 public void ClearOriginPreview()
 {
     if (swManip != null)
     {
         swManip.Visible = false;
         swManip.Remove();
         swManip = null;
         originTriad = null;
     }
 }